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.
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.
相关文章推荐
- android 手势识别代码
- Android解决NDK not configured问题
- 初识android内存的一些解决方案
- Android动画 - Vector Animation
- Android是最牛的
- android实现仿QQ登陆界面的多账号保存
- 最近AndroidStudio遇到了好几次奇怪的问题,程序正确,调试就是运行错误
- Android开发中单用户登录的逻辑
- Android应用更新自动检测下载
- Android NDK开发之Hello-JNI!
- Android Studio 使用 OpenCV 的配置方法
- 【android】:android文件读写
- 安卓中AlarmManager结合广播的使用
- 一个Notification 进度条插件(android,NJS实现,直接就可使用)
- Android源代码编译
- macOS 下完全卸载 Android Studio
- [Android] EditText默认不弹出软键盘的方法
- Android 百分比、水波、流量剩余进度球的实现
- Android-百度地图正反向编码功能实现
- view事件分发机制