如何从 NDK 中的 SurfaceTexture 获取 ANativeWindow [英] How do you get ANativeWindow from a SurfaceTexture in the NDK
问题描述
我有一些 OpenGL ES 代码已经渲染到 GLSurfaceView
,我目前正在修改它以使用 SurfaceView
和 TextureView
.
I've got some OpenGL ES code that has been rendering to a GLSurfaceView
, and I'm currently modifying it to work with either SurfaceView
and TextureView
.
我在本机代码中需要的共同元素是:ANativeWindow
.
The common element I need from both inside my native code is: ANativeWindow
.
对于 SurfaceView
,我通过将 Surface
传递给:
For the SurfaceView
I got it by passing Surface
to:
m_jwindow = ANativeWindow_fromSurface(env, surface);
对于TextureView
,我采用SurfaceTexture
,在API 14中我可以使用这个:
For TextureView
, I take SurfaceTexture
, and in API 14 I can use this:
m_jwindow = ANativeWindow_fromSurfaceTexture(env, surface);
但是,Jellybean 中删除了该功能.这让我想知道,如何从 API 16+ 中的 SurfaceTexture
获取 ANativeWindow
?
However, that function was removed in Jellybean. Which leaves me wondering, how can I get ANativeWindow
from a SurfaceTexture
in API 16+?
推荐答案
您需要在 API 16+ 中创建一个 Surface 对象,将 SurfaceTexture 作为参数传递给 构造函数(在 API 14 中引入).像往常一样将该 Surface 传递给 ANativeWindow_fromSurface()
.
What you need to do in API 16+ is create a Surface object, passing the SurfaceTexture as an argument to the constructor (which was introduced in API 14). Pass that Surface to ANativeWindow_fromSurface()
as usual.
这篇关于如何从 NDK 中的 SurfaceTexture 获取 ANativeWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!