如何在SurfaceView/View中使用RenderScript

Bao*_* Le 7 android surfaceview renderscript

最新的Android SDK(R22)已删除android.renderscript.RSSurfaceViewandroid.renderscript.RenderScriptGL类.我们如何在SurfaceView或常规Android View上直接使用RenderScript?

小智 0

简短的回答:这很复杂。

长答案: https: //github.com/googlesamples/android-HdrViewfinder

他们似乎进行了 RGBA 分配:

    Type.Builder rgbTypeBuilder = new Type.Builder(rs, Element.RGBA_8888(rs));
    rgbTypeBuilder.setX(dimensions.getWidth());
    rgbTypeBuilder.setY(dimensions.getHeight());
    mOutputAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(),
            Allocation.USAGE_IO_OUTPUT | Allocation.USAGE_SCRIPT);
Run Code Online (Sandbox Code Playgroud)

然后从 SurfaceView 持有者获取一个表面以传递给分配。然后他们在上面运行一些 rs,然后调用:

mOutputAllocation.ioSend();
Run Code Online (Sandbox Code Playgroud)

对于每一帧...检查代码,似乎存在一些陷阱。