Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get ANativeWindow from a SurfaceTexture in the NDK

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+?

like image 204
Adam Avatar asked Jun 19 '14 17:06

Adam


2 Answers

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.

like image 158
fadden Avatar answered Nov 18 '22 04:11

fadden


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

like image 26
desperateLord Avatar answered Nov 18 '22 04:11

desperateLord