void SurfaceFlinger::onMessageInvalidate(int64_t vsyncId, nsecs_t expectedVSyncTime) {
...
bool refreshNeeded;
{
mTracePostComposition = mTracing.flagIsSet(SurfaceTracing::TRACE_COMPOSITION) ||
mTracing.flagIsSet(SurfaceTracing::TRACE_SYNC) ||
mTracing.flagIsSet(SurfaceTracing::TRACE_BUFFERS);
const bool tracePreComposition = mTracingEnabled && !mTracePostComposition;
ConditionalLockGuard<std::mutex> lock(mTracingLock, tracePreComposition);
mFrameTimeline->setSfWakeUp(vsyncId, frameStart, Fps::fromPeriodNsecs(stats.vsyncPeriod));
refreshNeeded = handleMessageTransaction();
refreshNeeded |= handleMessageInvalidate();
if (tracePreComposition) {
if (mVisibleRegionsDirty) {
mTracing.notifyLocked("visibleRegionsDirty");
}
}
}
该函数由 VSYNC 调用。
mPendingTransactionQueues
把有效的加入到 mCurrentState
。mDrawingState
。computeLayerBounds()
更新。 updateCursorAsync();
updateInputFlinger();
updateCursorAsync()
更新每个屏幕的光标。updateInputFlinger()
更新每个 layer 的 WindowInfo,通知给 InputFlinger/InputDispatcher。 refreshNeeded |= mRepaintEverything;
if (refreshNeeded && CC_LIKELY(mBootStage != BootStage::BOOTLOADER)) {
// Signal a refresh if a transaction modified the window state,
// a new buffer was latched, or if HWC has requested a full
// repaint
if (mFrameStartTime <= 0) {
// We should only use the time of the first invalidate
// message that signals a refresh as the beginning of the
// frame. Otherwise the real frame time will be
// underestimated.
mFrameStartTime = frameStart;
}
// Run the refresh immediately after invalidate as there is no point going thru the message
// queue again, and to ensure that we actually refresh the screen instead of handling
// other messages that were queued us already in the MessageQueue.
mRefreshPending = true;
onMessageRefresh();
}
notifyRegionSamplingThread();
}
refreshNeeded
是 true,调用 SurfaceFlinger::onMessageRefresh() 触发合成。onTransactionCompleted()
通知 client。Android 13 中改名为 commit()
。