Android Graphic SurfaceFlinger 疑难解答
来源:互联网 发布:mac chrome plugins 编辑:程序博客网 时间:2024/05/21 08:45
参考代码:android4.4.2 aosp
名称约定:
SF : SurfaceFlinger
BQ : BufferQueue
Q:SF如何同步所有Client的合成、设置等需求?
A:mStateLock、SF中的mCurrentStates/mDrawingStates、Layer中的mCurrentStates/mDrawingStates;
mCurrentStates,mCurrentStates是相同的类型,但是在SF中和Layer中分别代表不同的结构:
Layer:
State mCurrentStates;State mDrawingStates;struct State { Geometry active; Geometry requested; uint32_t z; uint32_t layerStack; uint8_t alpha; uint8_t flags; uint8_t reserved[2]; int32_t sequence; // changes when visible regions can change Transform transform; // the transparentRegion hint is a bit special, it's latched only // when we receive a buffer -- this is because it's "content" // dependent. Region activeTransparentRegion; Region requestedTransparentRegion; };
SurfaceFlinger:
State mCurrentStates;State mDrawingStates;struct DisplayDeviceState { DisplayDeviceState(); DisplayDeviceState(DisplayDevice::DisplayType type); bool isValid() const { return type >= 0; } bool isMainDisplay() const { return type == DisplayDevice::DISPLAY_PRIMARY; } bool isVirtualDisplay() const { return type >= DisplayDevice::DISPLAY_VIRTUAL; } DisplayDevice::DisplayType type; sp<IGraphicBufferProducer> surface; uint32_t layerStack; Rect viewport; Rect frame; uint8_t orientation; String8 displayName; bool isSecure; }; struct State { LayerVector layersSortedByZ; DefaultKeyedVector< wp<IBinder>, DisplayDeviceState> displays; };
使用方法:
当Client设置完后,通过各种方法最终调用到request_vsync();当VSYNC到来后
void SurfaceFlinger::onMessageReceived(int32_t what) { ATRACE_CALL(); switch (what) { case MessageQueue::TRANSACTION: handleMessageTransaction(); break; case MessageQueue::INVALIDATE: handleMessageTransaction(); handleMessageInvalidate(); signalRefresh(); break; case MessageQueue::REFRESH: handleMessageRefresh(); break; } }SurfaceFlinger::handleMessageTransaction SurfaceFlinger::handleTransaction Mutex::Autolock _l(mStateLock)
在handleMessageTransaction函数中:
获取mStateLock,
经过一系列的处理,最终SF将mCurrentStates赋值到mDrawingStates,以for循环方式将layersSortedByZ中的layer的mCurrentStates赋值到mDrawingStates;
释放mStateLock;
在获取mStateLock后,所有Client对SF或者对Layer的操作都无法执行,因为它们也需要获取mStateLock;
在释放mStateLock后,所有Client的操作都正常了,Client可以创建新的Surface,也可以设置Surface的参数;
因为在获取释放mStateLock期间,已经将SF、Layer的状态已经保存在mDrawingStates中;而Client每次都是用的是mCurrentStates;
列出几个需要mStateLock的函数:
创建Surface或者说Layer的地方Client::createSurface SurfaceFlinger::createLayer SurfaceFlinger::addClientLayer Mutex::Autolock _l(mStateLock); mCurrentState.layersSortedByZ.add(lbc);设置Surface的各种参数SurfaceFlinger::setTransactionState Mutex::Autolock _l(mStateLock);VSYNC信号来时,SF用来处理当前状态的地方SurfaceFlinger::handleMessageTransaction SurfaceFlinger::handleTransaction Mutex::Autolock _l(mStateLock)
未完,其他问题待续。。。。。。
- Android Graphic SurfaceFlinger 疑难解答
- Android Graphic SurfaceFlinger分析
- UNDERSTANDING ANDROID GRAPHIC- SURFACEFLINGER (IV)
- Android 4.2 JellyBean Graphic Component -- SurfaceFlinger 1
- Android 4.2 JellyBean Graphic Component -- SurfaceFlinger 2
- android graphic(4)—surfaceflinger和Vsync
- android graphic(6)—surfaceflinger和MessageQueue
- android graphic(4)—surfaceflinger和Vsync
- android graphic(6)—surfaceflinger和MessageQueue
- android graphic(3)—surfaceflinger的启动流程
- android graphic(5)—surfaceflinger和Vsync (简化)
- android graphic(3)—surfaceflinger的启动流程
- android graphic(5)—surfaceflinger和Vsync (简化)
- Android 4.4 Graphic系统详解(1) SurfaceFlinger的启动过程
- Android 4.4 Graphic系统详解(1) SurfaceFlinger的启动过程
- Android 4.4 Graphic系统详解(1) SurfaceFlinger的启动过程
- Android 4.4 Graphic系统详解(1) SurfaceFlinger的启动过程
- Android 4.4 Graphic系统详解(1) SurfaceFlinger的启动过程
- BeautihulSoup的中文文档库
- fmt标签的格式化日期数字
- Redis+Spring缓存实例(windows环境,附实例源码及详解)
- Idea erlang 引入 .hrl文件中的宏,idea 显示Unresolved
- [leetcode]Longest Increasing Subsequence
- Android Graphic SurfaceFlinger 疑难解答
- SDAU 课程练习3 1024
- recyclerView导入问题
- 排序算法总结与C代码
- 线程池续
- 如何划分子网
- VI Package Manager与LABVIEW的连接问题小结
- 10.数值的整数次方(做第二遍时感觉仍有难度,第三次做就没有难度了)
- 数据结构—单链表—直接插入排序