//frameworks/native/services/surfaceflinger/Surfaceflinger.cpp
voidSurfaceFlinger::onComposerHalVsync(hal::HWDisplayIdhwcDisplayId,int64_ttimestamp,std::optional<hal::VsyncPeriodNanos>vsyncPeriod){conststd::stringtracePeriod=[vsyncPeriod](){if(ATRACE_ENABLED()&&vsyncPeriod){std::stringstreamss;ss<<"("<<*vsyncPeriod<<")";returnss.str();}returnstd::string();}();ATRACE_FORMAT("onComposerHalVsync%s",tracePeriod.c_str());Mutex::Autolocklock(mStateLock);constautodisplayId=getHwComposer().toPhysicalDisplayId(hwcDisplayId);if(displayId){constautotoken=getPhysicalDisplayTokenLocked(*displayId);constautodisplay=getDisplayDeviceLocked(token);display->onVsync(timestamp);}if(!getHwComposer().onVsync(hwcDisplayId,timestamp)){return;}constboolisActiveDisplay=displayId&&getPhysicalDisplayTokenLocked(*displayId)==mActiveDisplayToken;if(!isActiveDisplay){// For now, we don't do anything with non active display vsyncs.
return;}boolperiodFlushed=false;mScheduler->addResyncSample(timestamp,vsyncPeriod,&periodFlushed);if(periodFlushed){modulateVsync(&VsyncModulator::onRefreshRateChangeCompleted);}}
//frameworks/native/services/surfaceflinger/Scheduler/DispSyncSource.cpp
classDispSyncSourcefinal:publicVSyncSource{voidDispSyncSource::setDuration(std::chrono::nanosecondsworkDuration,std::chrono::nanosecondsreadyDuration){std::lock_guardlock(mVsyncMutex);mWorkDuration=workDuration;mReadyDuration=readyDuration;// If we're not enabled, we don't need to mess with the listeners
if(!mEnabled){return;}mCallbackRepeater->start(mWorkDuration,mReadyDuration);}}