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
.
The common element I need from both inside my native code is: ANativeWindow
.
For the SurfaceView
I got it by passing Surface
to:
m_jwindow = ANativeWindow_fromSurface(env, surface);
For TextureView
, I take SurfaceTexture
, and in API 14 I can use this:
m_jwindow = ANativeWindow_fromSurfaceTexture(env, surface);
However, that function was removed in Jellybean. Which leaves me wondering, how can I get ANativeWindow
from a SurfaceTexture
in API 16+?
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.
I don't know is there anyone can see this.
first, include surface_texture.h
use ASurfaceTexture_fromSurfaceTexture(JNIEnv *env, jobject surfacetexture)
to get ASurfaceTexture*
then use ASurfaceTexture_acquireANativeWindow(ASurfaceTexture *st)
to get ANativeWindow*
make sure release it after everything done. ASurfaceTexture_release(ASurfaceTexture *st)
reference: https://developer.android.google.cn/ndk/reference/group/surface-texture
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With