该函数中调用了很多 SurfaceFlingerBE 的函数,BE 可能指的是 Backend?我们先看下面的代码段。
void SurfaceFlinger::postComposition() {
const auto* display = ON_MAIN_THREAD(getDefaultDisplayDeviceLocked()).get();
...
mPreviousPresentFences[1] = mPreviousPresentFences[0];
mPreviousPresentFences[0].fence =
display ? getHwComposer().getPresentFence(display->getPhysicalId()) : Fence::NO_FENCE;
HWComposer::getPresentFence()
获取最后一个 fence,更新 mPreviousPresentFences
。 ...
for (const auto& layer: mLayersWithQueuedFrames) {
const bool frameLatched =
layer->onPostComposition(display, glCompositionDoneFenceTime,
mPreviousPresentFences[0].fenceTime, compositorTiming);
layer->releasePendingBuffer(/*dequeueReadyTime*/ now);
if (frameLatched) {
ATRACE_NAME("recordBufferingStats");
recordBufferingStats(layer->getName(), layer->getOccupancyHistory(false));
}
}
mLayersWithQueuedFrames
,它是当前显示的 layer 集合。BufferLayer::onPostComposition()
,它主要跟 FrameTracker 有关,先不看。mDrawingState
的 callbackHandles
。frameLatched
是 true,调用 recordBufferingStats()
更新 buffer 记录,好像跟双缓冲/三缓冲时间有关。 ...
mTransactionCallbackInvoker.addPresentFence(mPreviousPresentFences[0].fence);
mTransactionCallbackInvoker.sendCallbacks();
onTransactionCompleted()
。