Compiling renderscript source code

半腔热情 提交于 2019-12-24 12:27:55

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/22685162/compiling-renderscript-source-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!