Resize surface when resizing VirtualDisplay

Some time ago I asked this question , which received an answer.

I used the intermediary Surfaceas an answer, but now I am facing another problem. In some cases, during my application, mine VirtualDisplaymay change the resolution. Therefore, I would also like to update the size of my reseller Surfaceto fit the resolution change VirtualDisplay. I was hoping this would be a simple call setDefaultBufferSizein the Surface'sbelow SurfaceTexture, but this does not work.

I got out to free my middleman Surfaceand SurfaceTexturemade new ones, but then I have to set the output surface VirtualDisplayto zero and follow some other synchronization steps, d would like to avoid if possible.

Is there a way to dynamically update the size Surface/ SurfaceTextureafter creation?

UPDATE:

I tried calling VirtualDisplay.setSurface(null)along with VirtualDisplay.resize(newSize.width, newSize.height)and then sending a message to a thread that processes callbacks for the intermediate SurfaceTextureto resize the texture with setDefaultBufferSize, and then, until this final call is complete, and then callVirtualDisplay.setSurface(surfaceFromSecondaryThread)

It works sometimes. In other cases, the texture is green with a gray stripe on it (which is also my glClearColor, not sure if this is due to what we saw here ). Sometimes VirtualDisplayduplicates / less are visible in my current image on the screen. So this seems like a synchronization issue, but what time should I wait, I'm not sure. The documentation for setDefaultBufferSizestates:

For OpenGL ES, the EGLSurface should be destroyed (via eglDestroySurface), made not-current (via eglMakeCurrent), and then recreated (via eglCreateWindowSurface) to ensure that the new default size has taken effect.

The problem is that my code does not create an EGLSurface from SurfaceTexture / Surface, so I cannot destroy it. I assume that the manufacturer ( VirtualDisplay) does, but for me there are no public APIs to access EGLSurface.

[ 2] , ( , , , glClearColor ), glReadPixels, eglSwapBuffers, Surface MediaCodec, . , MediaCodec , , Surface VirtualDisplay, ( ), YUV RGBA Surface → OpenGL - . VirtualDisplay

+2

All Articles