androidsurfaceviewandroid-imageegltextureview

Is it possible to synchronize the content draw by OpenGL and the position of a View in Android?


There are 2 views in a FrameLayout:

The content of SurfaceView is drawn using OpenGL in another thread:

  1. Send the Surface of SurfaceView from java to c++
  2. Create ANativeWindow: ANativeWindow_fromSurface(env, surface);
  3. Create surface: eglCreateWindowSurface()
  4. Other preparation stuff and draw to the surface
  5. setLayoutParams() for the View in the main thread.

I'm trying to make the position of View align with the content of SurfaceView. E.g if I draw a moving square, I want to set the position of View to match the square when it is moving.

But when I try it, the View moves before the content of SurfaceView.

I've tried to replace SurfaceView with a TextureView or a CustomView which uses ImageReader to provide surface to native, but no luck.

Does anyone have an idea how to make it possible?


Solution

  • I was able to do it by using a surface from ImageReader: