您的位置:首页 > 移动开发 > Android开发

UNDERSTANDING ANDROID GRAPHICS INTERNALS -SURFACEFLINGER(V)

2016-06-01 11:40 459 查看
from: https://charleszblog.wordpress.com/category/android-2/graphics-android/

This SurfaceFlinger series turns lengthy. Let’s see if we can wrap it up in this post.

FramebufferSurface and DisplayDevice

Jelly Bean supports external displays(e.g. HDMI, WiDi). Each display is represented by a DisplayDevice instance and associated
with aFramebufferSurface instance which makes the mDisplaySurface field.

FramebufferSurface subclasses both ConsumeBase and DisplaySurfaceand
wraps around a BufferQueue instance.

DisplayDevice  maintains a reference to  a vector of all sorted visible layers in mVisibleLayersSortedByZ, which
is tracked in SurfaceFlinger::mDrawingState.

SurfaceFlinger tracks all DisplayDevice in an keyed vectormDisplays.  SurfaceFlinger::readyToRun()
creates each DisplayDevicealong with FramebufferSurface
and adds each to mDisplays.

In SurfaceFlinger::doDisplayComposition(),when composition is complete and the display back frame buffer is drawn; then  DisplayDevice::swapBuffers()
is invoked for a DisplayDeviceinstance. Within the latter call, eglSwapBuffers()
is called. As a result, FramebufferSurface::onFrameAvailable() is called.

In FramebufferSurface::onFrameAvailable(), HwComposer::fbPost()
is called, in which for non HWC_DEVICE_API_VERSION_1_1,framebuffer_device_t::post in gralloc module is called to post the
back frame buffer to frame buffer device driver.

HWComposer

This class wraps framebuffer_device_t and struct
hwc_composer_device_1 and manages the vsync withHWComposer::event_control(), HWComposer::sync().

SurfaceFlinger owns an instance of HWComposer.

SurfaceFlinger

1.  Implements BnISurfaceComposer functionality

BnISurfaceComposerClient is implemented by Client class; responsible for creation of Layer instances.

2. Implements HWComposer::EventHandler

Accepts on vsync and hotplug in events from hwcomposer module; process vsync enable/disable in eventControl().

3.  Runs message queue on its own thread loop.

after initialization in readyToRun(), all handling is asynchronous and message driven.

4.  readyToRun()

Instantiates HWComposer instances, instantiates and InitializesDisplayDevice objects and corresponding FramebufferSurface objects,
initializes egl config, context, etc.

5. Maintains the current and the drawing SurfaceFlinger::State

Drawing state is the state being rendered, the current state is open for modifications. mCurrentState is copied to mDrawingState  in CommitTransaction during handling of  MessageQueue::TRANSACTION and MessageQueue::INVALIDATEmessages.

6. Several sources may trigger composition

new surface frame queued, changes in orientation and other flags, surface removal, vsync.

7. Composition and rendering

All layers are sorted by depth dimension Z, send layer state information to hwcomposer module to determine rendering by overlay or composition (by the prepare method in hwcomposer).

For layers selected for composition,  compute visible regions based on Z and alpha blending factor, and draw them to each DisplayDevice object’s back FramebufferSurface.

When composition on a display is complete, invoke eglSwapBuffers to switch back FramebufferSurface to the front and posted to frame buffer device.

In summary, SurfaceFlinger design is complex and has to deal with many usage scenarios and corner use cases.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: