如何将Android中的表面传递给本机代码?

时间:2015-08-29 20:47:39

标签: android android-ndk

我想使用Native Window,所以我试图调用ANativeWindow_fromSurface,但它需要一个表面的作业。我假设最好的方法是在调用onSurfaceCreated时传递它,即:

public class RendererWrapper implements Renderer {
     @Override
     public void onSurfaceCreated(GL10 gl, EGLConfig config) {
     // (Some sort of code that would create a surface object)

     //This is a native function that will use ANativeWindow_fromSurface
     cOnSurfaceCreated(surface);
}

但我不知道我应该使用什么具体对象,也不知道如何访问它。

编辑:我正尝试在此示例中执行类似NativeWindow API的操作:https://vec.io/posts/how-to-render-image-buffer-in-android-ndk-native-code因此我可以从本机c代码直接写入屏幕。

1 个答案:

答案 0 :(得分:0)

简单地说,你需要传递一个Surface。我希望你的onSurfaceCreated()方法在创建Surface之后被称为,所以我不太了解你所展示的代码的结构。

如果您正在使用SurfaceTexture,请参阅this question的答案。