问题
A while ago I askedthis question which received an answer.
I have implemented an intermediary Surface
as the answer suggested, but now I've run into another problem. At some points in time during my application, my VirtualDisplay
can change resolution. So, I'd like to also update the size of my intermediary Surface
to match the change in resolution of the VirtualDisplay
. I was hoping this would be a simple call to setDefaultBufferSize
on the Surface's
underlying SurfaceTexture
, but that doesn't appear to work.
I've poked around at releasing my intermediary Surface
and SurfaceTexture
and making new ones, but then I have to set the output surface for the VirtualDisplay
to be null and do some other synchronization steps which I'd like to avoid if possible.
Is there a way to dynamically update the size of a Surface
/SurfaceTexture
after creation?
UPDATE:
I've tried calling VirtualDisplay.setSurface(null)
along with VirtualDisplay.resize(newSize.width, newSize.height)
and then sending a message to the thread which handles the callbacks for the intermediary SurfaceTexture
to resize the texture via setDefaultBufferSize
and then having the main thread poll the secondary thread until that set call is finished and then call VirtualDisplay.setSurface(surfaceFromSecondaryThread)
This works sometimes. Other times the texture is all green with a gray bar across it (which is also my glClearColor, not sure if that is related as seen here). Sometimes the current screen image is seen duplicates/smaller in my VirtualDisplay
. So, it seems like a timing issue, but what timing I should wait for, I am unsure. The documentation for setDefaultBufferSize
states:
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 the SurfaceTexture/Surface so, I have no way of destroying it. I'm assuming that the producer (VirtualDisplay
) does, but there are no public APIs for me to get at the EGLSurface.
[UPDATE 2]
So, when I see the problem (green screen with bar, corruption, perhaps because my glClearColor
is green) if I do a glReadPixels
before I call eglSwapBuffers
to write to the Surface
for the MediaCodec
, I read green pixels. This tells me that it isn't a MediaCodec
problem, that either the information written to the Surface
from the VirtualDisplay
is corrupt (and remains corrupt) or the conversion from YUV space to RGBA space when going from Surface
-> OpenGL texture is broken somehow. I'm leaning towards there being a problem with VirtualDisplay
来源:https://stackoverflow.com/questions/35209004/resize-surface-when-resizing-virtualdisplay