Android: Is it possible to create a SurfaceTexture without a SurfaceView?

I want to create a SurfaceTexture with an OpenGL texture that I can control with a setting similar to this answer . (Quoted here :)

  • Creating textures through OpenGL
  • Pass this texture to the constructor of the new SurfaceTexture.
  • Give this new SurfaceTexture for the camera.
  • Make sure you use OES_External (see the documentation for details).

However, creating an OpenGL texture (as in step 1 of the answer) requires an EGL context that requires the EGLSurface to run as the current one, which requires a SurfaceTexture. It seems the only way to create an EGL context is to create a SurfaceView (or another view with SurfaceTexture) and use it to initialize the EGLSurface, and then make the EGLContext stream.

My goal is to create an EGLContext and make it current in the background thread, do some off-screen calculations on the camera preview image (mainly using NDK). I want to create a library and make it as independent of the user interface as possible. Two related questions:

On the Java side, can I create an EGLContext without preprocessing a SurfaceTexture?

On the NDK side, there used to be a private API call to create native windows android_createDisplaySurface() , but it no longer works, and it is a private API. Is there a way to create a surface using NDK?

I am new to using EGL and I donโ€™t understand why you need EGLSurface for EGLContext to make it relevant. In iOS, EAGLContexts are created first, and then framebuffers can be created as needed. Using EGL seems like you always need your own window.

+7
android android-ndk opengl-es egl
source share
1 answer

You can see a number of examples that affect camera output, SurfaceTexture, and EGL in Grafika . The Continuous Capture activity is one, but it uses the technique you mentioned: to avoid creating an EGLSurface, it simply takes one from a neighboring SurfaceView.

You need to have an EGLSurface, but it should not be the surface of the window. You can create a 1x1 pbuffer surface and just use it. This is done by calling eglCreatePbufferSurface() ; see the EglCore class in Grafika for an example.

These examples are in Java, but the Java implementation simply carries its own EGL / GLES calls.

android_createDisplaySurface() is an internal call that you discovered doesn't work on newer devices. Instead, find the NDK for ANativeWindow .

Update: for everyone who gets here by searching, android_createDisplaySurface() relied on an inner class called FramebufferNativeWindow , which was flagged as deprecated in Android 5.0 with this change . The internal OpenGL ES test code that used it was updated by replacing SurfaceFlinger with this change . In the original version of the test code, it was necessary to disable the Android application platform so that it could capture the frame buffer; the newer version simply requests SurfaceFlinger for a window that covers the screen and is composed on top of everything else.

+4
source share

All Articles