1

As I mentioned in my previous post (Compiling renderscript code at runtime), I try to compile renderscript code at runtime. As suggested by Kietz I need to alter the ScriptC class from which all generated java classes derive. Making my own class that extends Script fails because I cannot invoke the constructor of this super class.

This snippet of the code

public class RuntimeScriptC extends Script {
       private static final String TAG = "RuntimeScriptC";

   protected RuntimeScriptC(int id, RenderScript rs) {            
       super(id, rs);       

   }

gives me this error:

The constructor Script(int, RenderScript) is undefined

My next idea was to add my own class to the renderscript source code and compile it to create a new .jar. I found the source code on git but have no idea how to only build the renderscript package.

Edit: I just found out that the constructor of Script.java is package private. That's why I can't access the constructor in my own class. If I can compile the renderscript sources myself I could place my own class into the package and access it.

New question: Where can I find the renderscript sources and how can I compile them?

Community
  • 1
  • 1
DeGoosseZ
  • 628
  • 5
  • 20

1 Answers1

3

RenderScript's source can be found at android.googlesource.com, along with that of the rest of Android. If you want to rebuild Android or a part of it, here is probably a good place to start.

However, that is overkill. If you can't modify ScriptC directly, just inherit from it. This is possible because the only methods you need from ScriptC are its protected constructors. For example, I wrote HackedScriptC which does nothing but forward its arguments to ScriptC():

package com.example.android.rs.extremehax;

import android.content.res.Resources;
import android.renderscript.RenderScript;
import android.renderscript.ScriptC;

public class HackedScriptC extends ScriptC {

    public HackedScriptC(RenderScript rs, Resources resources, int id) {
        // simple passthru to the only constructor that ScriptC_mono uses
        super(rs, resources, id);
    }

}

It can now be substituted for ScriptC in a glue class:

package com.example.android.rs.extremehax;
// ...     
public class ScriptC_mono extends HackedScriptC { 
    // otherwise identical glue class...

In your case, you would not invoke the super constructor ScriptC(RenderScript,Resources,int) because that invokes internalCreate, which you want to override. Instead, invoke ScriptC(int,RenderScript).

Kietz
  • 1,186
  • 11
  • 19
  • Did you end up rebuilding RenderScript? – Kietz Apr 01 '14 at 20:46
  • It's not easy to only rebuild the renderscript part. I had to compile the full android package, so that was a no go. In the internalCreate is a openRawResource function. openRawResource is a function of the Resource class, we made our own Resource class that we give to the constructor of ScriptC. The openRawResource now points to a directory of our own chosing where we can add/change the .bc file. – DeGoosseZ Apr 01 '14 at 20:52
  • Any chance you could share your source? I'm very interested in how your project turned out – Kietz Apr 11 '14 at 16:21
  • I do not know that I am allowed to share our code since it's for a thesis. I will ask the company what I may and may not do and will update you on this matter asap! – DeGoosseZ Apr 11 '14 at 16:38
  • Sorry for the long reply time. But we have released the source code on [github](https://github.com/degoossez/OVSR) with an MIT license. The project is not yet fully debugged but should be pretty stable. There will be a README soon on how to setup the renderscript compile server and how to connect the app with it. I think what you would like to see is the "src/com/denayer/ovsr/MyResources.java" file and it's implementation (RenderScriptTemplate function) in "src/com/denayer/ovsr/RsScript.java". If you would like any more information feel free to reply or mail me on the email in the license. – DeGoosseZ May 22 '14 at 17:18