[FIXED] How do you get ANativeWindow from a SurfaceTexture in the NDK

Issue

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

Solution

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.

Answered By – fadden

Answer Checked By – Marie Seifert (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published