Android added platform support for virtual displays in Hardware Composer
v1.3 (support can be used by Miracast). The virtual display composition is
similar to the physical display: Input layers are described in
prepare()
, SurfaceFlinger conducts GPU composition, and layers and
GPU framebuffer are provided to Hardware Composer in set()
.
Instead of the output going to the screen, it is sent to a gralloc buffer. Hardware Composer writes output to a buffer and provides the completion fence. The buffer is sent to an arbitrary consumer: video encoder, GPU, CPU, etc. Virtual displays can use 2D/blitter or overlays if the display pipeline can write to memory.
Each frame is in one of three modes after prepare()
:
Output format depends on the mode:
dequeueBuffer()
, typically RGBA8888. The consumer must be able to
accept this format.Hardware Composer v1.3 virtual displays require that
eglSwapBuffers()
does not dequeue the next buffer immediately.
Instead, it should defer dequeueing the buffer until rendering begins.
Otherwise, EGL always owns the next output buffer. SurfaceFlinger can’t get the
output buffer for Hardware Composer in MIXED/HWC mode.
If Hardware Composer always sends all virtual display layers to GPU, all frames will be in GLES mode. Although not recommended, you may use this method if you need to support Hardware Composer v1.3 for some other reason but can’t conduct virtual display composition.