【问题标题】:How do you get ANativeWindow from a SurfaceTexture in the NDK如何从 NDK 中的 SurfaceTexture 获取 ANativeWindow
【发布时间】:2014-06-19 17:18:05
【问题描述】:

我有一些 OpenGL ES 代码已经渲染到 GLSurfaceView,我目前正在修改它以使用 SurfaceViewTextureView

我在本机代码中需要的共同元素是:ANativeWindow

对于SurfaceView,我通过将Surface 传递给:

m_jwindow = ANativeWindow_fromSurface(env, surface);

对于TextureView,我采用SurfaceTexture,在API 14中我可以使用这个:

m_jwindow = ANativeWindow_fromSurfaceTexture(env, surface);

但是,Jellybean 中删除了该功能。这让我想知道,如何从 API 16+ 中的 SurfaceTexture 获取 ANativeWindow

【问题讨论】:

    标签: android android-ndk


    【解决方案1】:

    在 API 16+ 中您需要做的是创建一个 Surface 对象,将 SurfaceTexture 作为参数传递给constructor(在 API 14 中引入)。像往常一样将该 Surface 传递给 ANativeWindow_fromSurface()

    【讨论】:

      【解决方案2】:

      我不知道有没有人可以看到这个。

      首先,包括surface_texture.h

      使用ASurfaceTexture_fromSurfaceTexture(JNIEnv *env, jobject surfacetexture) 获取ASurfaceTexture*

      然后使用ASurfaceTexture_acquireANativeWindow(ASurfaceTexture *st)得到ANativeWindow*

      确保在完成所有操作后释放它。 ASurfaceTexture_release(ASurfaceTexture *st)

      参考:https://developer.android.google.cn/ndk/reference/group/surface-texture

      【讨论】:

        猜你喜欢
        • 2016-02-10
        • 2015-02-19
        • 2016-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-30
        相关资源
        最近更新 更多