Android6.0 显示系统(六) 图像的输出过程
Android6.0 显示系统(六) 图像的输出过程
主要就是分析这个函数,我们先看看它的代码:
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
void SurfaceFlinger::handleMessageRefresh() {
ATRACE_CALL();
static nsecs_t previousExpectedPresent = 0;
nsecs_t expectedPresent = mPrimaryDispSputeNextRefresh(0);
static bool previousFrameMissed = false;
bool frameMissed = (expectedPresent == previousExpectedPresent);
if (frameMissed != previousFrameMissed) {
ATRACE_INT("FrameMissed", static_cast(frameMissed));
}
previousFrameMissed = frameMissed;
if (CC_UNLIKELY(mDropMissedFrames && frameMissed)) {
// Latch buffers, but don't send anything to HWC, then signal another
// wakeup for the next vsync
preComposition();
repaintEverything();
} else {
preComposition();
rebuildLayerStacks();
setUpHWComposer();
doDebugFlashRegions();
doComposition();
postComposition();
}
previousExpectedPresent = mPrimaryDispSputeNextRefresh(0);
}
我们主要看下下面几个函数。
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
preComposition();
rebuildLayerStacks();
setUpHWComposer();
doDebugFlashRegions();
doComposition();
postComposition();
一、preComposition函数
我们先来看第一个函数preComposition
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
void SurfaceFlinger::preComposition()
{
bool needExtraInvalidate = false;
const LayerVector& layers(mDrawingState.layersSortedByZ);
const size_t count = layers.size();
for (size_t i=0 ; i
if (layers[i]->onPreComposition()) {
needExtraInvalidate = true;
}
}
if (needExtraInvalidate) {
signalLayerUpdate();
}
}
上面函数先是调用了mDrawingState的layersSortedByZ来得到上次绘图的Layer层列表。并不是所有的Layer都会参与屏幕图像的绘制,因此SurfaceFlinger用state对象来记录参与绘制的Layer对象。
记得在之前的博客,我们分析过createLayer函数来创建Layer,创建之后会调用addClientLayer函数。
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
status_t Surface