doComposeSurfaces
handleMessageRefresh -> doComposition -> doDisplayComposition -> doComposeSurfaces
1.Preparation work:
1) If GLES and hwc compositing, clear frame buffer target first
2) If GLES only, drawWarmHole first
2.Render layers to framebuffer
1) For all layers if using hwc
(1)do nothing if HWC_OVERLAY layer, display hardware will blend the layer
(2)render with opengl if HWC_FRAMEBUFFER layer, call layer->draw()
(3)set the layer’s acquireFence
2) For all layers if no hwc
(1)just render with OpenGL, call layer->draw()
(2)Now all the GLES layers are drawn on frame buffer target, waiting to
swapBuffers
JB版本开始,Android支持外部显示(HDMI和Wifi等)。每个显示设备由DisplayDevice代表,而且关联着FramebufferSurface。SurfaceFlinger会保存所有的DisplayDevice在mDisplays成员变量中。SurfaceFlinger::readyToRun() 函数中会创建所有的DisplayDevice和FramebufferSurface。
HWComposer一般会像如下定义几个显示类型:
HWC_DISPLAY_PRIMARY e.g. built-in LCD screen
HWC_DISPLAY_EXTERNAL e.g. HDMI, WiDi
HWC_DISPLAY_VIRTUAL not a real display对于每一个display type,都会以DisplayDevice对象保存在SurfaceFlinger中。
How FrameBufferSurface and eglSwapBuffers interact(??)
Back to BufferQueue, usually client application create Surface, it’s provider end of a BufferQueue, SurfaceFlinger acts as consumer of the Surface provided by client. However, SurfaceFlinger also acts as provider as regard to FrameBufferSurface, which is consumed by display.
In SurfaceFlinger::init, the mDisplaySurface in DisplayDevice comes from the same BufferQueue as EGLSurface, look at the code
bq = new BufferQueue(new GraphicBufferAlloc());
fbs = new FramebufferSurface(…, bq);
hw = new DisplayDevice(…, fbs, bq, …);
mDisplays.add(…,hw);