There are 2 views in a FrameLayout:
- SurfaceView
- View
The content of SurfaceView is drawn using OpenGL in another thread:
- Send the Surface of SurfaceView from java to c++
- Create ANativeWindow: ANativeWindow_fromSurface(env, surface);
- Create surface: eglCreateWindowSurface()
- Other preparation stuff and draw to the surface
- 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?
I was able to do it by using a surface from
ImageReader:SurfaceofImageReaderImagefromImageReader.OnImageAvailableListenerImage.getTimestamp()value, this is nano time when theImageis created. Compare it with nano time from earlier to get the corresponding position. Update the position and draw the correspondingImageto theView.Imageafter it is drawn on screen by theChoreographer.FrameCallbackafterView.onDraw.