from SurfaceFlinger ◦ comes with a Canvas and a graphics buffer • App uses Canvas to draw the screen ◦ underlying implementations may use OpenGL or software render engine (e.g. SKIA) • SurfaceFlinger composes final screen from Surfaces ◦ get Activity status from ActivityManager ◦ get z-order information from WindowManager • Gralloc maps to the framebuffer device (fb0)
A page layout is composed of a tree of Views • Actual drawing behavior implemented in onDraw() method of each View ◦ Display List: a set of graphic commands ◦ commands can be mapped to OpenGL commands • Create DeferredDisplayList in order to optimize the rendering order ◦ analyze the overlapping… relationships ◦ minimize GPU usage
ISurfaceComposer (server) • Activity acquires Surface from SurfaceFlinger ◦ created by ISurfaceComposer • Receives activity status from ActivityManager • Receives window status (visibility, z-order) from WindowManager • Composes multiple Surfaces into a single image ◦ by HWComposer: also generates VSYNC
callback of HAL ◦ or SW source: VSyncThread • Distributed by SurfaceFlinger ◦ Client can create an event connection to SurfaceFlinger’s MessageQueue to receive the VSync event ◦ SurfaceFlinger inherits HWComposer::EventHandler to handle onVSyncRecieved() and notify listeners
to traverse the tree when ◦ App or page being launched ◦ External event: touch, key press ◦ Internal event: UI control change, View.Visibility • How to traverse ◦ Post a request to Choreographer (if no request left) ◦ Choreograpger calls perfromTraversals() when VSYNC signal triggered
controls ◦ performLayout(): calculate UI layout ◦ performDraw() • Inside performDraw() ◦ High level: draw to Canvas (based on Surface in Java level) ◦ Low level ▪ Lock Surface (native level) to dequeue a buffer from BufferQueue ▪ Render to buffer by OpenGL ES or SKIA ▪ Unlock Surface to enqueue the buffer
more Surface/Layer • Done by using ISurfaceComposerClient to connect to SurfaceFlinger’s Binder service • ISurfaceComposerClient will return a SurfaceControl, then use it to create Surface • One of two native windows in Android graphic systems (another one is for SurfaceFlinger) • OpenGL ES render to the buffer and enqueue to BufferQueue of Surface, act as a “producer”
changes (including size, z-order, alpha, add/removal…), save as mDrawingState ◦ handleMessageInvalidate(): acquire a buffer from BufferQueue if available ◦ signalRefresh() ---> call handleMessageRefresh()
layer with available buffers (mQueuedFrames > 0), signal invalidate if true ◦ rebuildLayerStacks(): by calculating opaque region, visible region, covered region and transparent region ◦ …… ◦ doComposition(): done by HWComposer or OpenGL ES ◦ Swap buffers (front/back buffer)