In my Android app I have the need to render three views with the following Z-order:
- At bottom, the output surface of a
MediaCodec
decoder covering the whole screen. I have the requirement that I have to transform the image produced byMediaCodec
(e.g. scale it) - In the middle, a
GLSurfaceView
(or other surface/view running GL shaders I define), covering the whole screen. Obviously some of the pixels in this layer will be transparent, in order to see theMediaCodec
output beneath. - On top, any other view - say an
ImageView
. Not sure if I will require transparency for these topmost views, maybe fully opaque rectangular Views are OK - they just won't cover the whole screen and will move around.
It's looking like this is impossible but maybe I'm missing something or there is a way to do it with more effort at a lower level (e.g. EGL contexts or something like that...which I currently don't understand).
The reason I haven't been able to get this to work and am worrying it is impossible is:
- For the bottom
MediaCodec
output layer (1), I have to be able to transform the image. So, the surface I give MediaCodec to render to must be from aTextureView
- In order to be able to see through the transparent pixels of the middle
GLSurfaceView
(2), I have to callGLSurfaceView.setZOrderOnTop(true)
. Otherwise the GLSurfaceView is opaque. - But calling
GLSurfaceView.setZOrderOnTop(true)
means that no other views (3) are rendered on top of theGLSurfaceView
. E.g. anImageView
will always appear behind the opaque pixels of theGLSurfaceView
.
It looks like calling GLSurfaceView.setZOrderMediaOverlay(true)
instead of GLSurfaceView.setZOrderOnTop(true)
is intended to address this and facilitate this type of Z-ordering. And it does if the bottommost MediaCodec
output layer is a SurfaceView
. But I need it to be a TextureView
so I can transform it. And GLSurfaceView.setZOrderMediaOverlay(true)
doesn't seem to work when there is a TextureView
beneath it: the TextureView
is completely obscured by the middle GLSurfaceView
layer rather than showing through the transparent pixels.
Is it correct that this Z-ordering is impossible? Or can it be accomplished by messing around with EGL and contexts, etc?