SF: pass a render rate to VsyncTracker instead of a divisor
passing a divisor to VsyncTracker might result in the wrong frame
rate when the vsync period is changing. The Divisor was calculated in
VsyncReactor which calculates it based on the new period, and passed
to VsyncTracker which might still be learning the new period, hence
using the old period.
Bug: 267780202
Test: SF unit tests
Change-Id: Ibb632d4ae6621a6ac0c0123e78f4c4d75699bd9e
diff --git a/services/surfaceflinger/Scheduler/VSyncPredictor.cpp b/services/surfaceflinger/Scheduler/VSyncPredictor.cpp
index 5a5afd8..de7b338 100644
--- a/services/surfaceflinger/Scheduler/VSyncPredictor.cpp
+++ b/services/surfaceflinger/Scheduler/VSyncPredictor.cpp
@@ -272,13 +272,26 @@
// update the mLastVsyncSequence for reference point
mLastVsyncSequence = getVsyncSequenceLocked(timePoint);
- const auto mod = mLastVsyncSequence->seq % mDivisor;
- if (mod == 0) {
+ const auto renderRatePhase = [&]() REQUIRES(mMutex) -> int {
+ if (!mRenderRate) return 0;
+
+ const auto divisor =
+ RefreshRateSelector::getFrameRateDivisor(Fps::fromPeriodNsecs(mIdealPeriod),
+ *mRenderRate);
+ if (divisor <= 1) return 0;
+
+ const int mod = mLastVsyncSequence->seq % divisor;
+ if (mod == 0) return 0;
+
+ return divisor - mod;
+ }();
+
+ if (renderRatePhase == 0) {
return mLastVsyncSequence->vsyncTime;
}
auto const [slope, intercept] = getVSyncPredictionModelLocked();
- const auto approximateNextVsync = mLastVsyncSequence->vsyncTime + slope * (mDivisor - mod);
+ const auto approximateNextVsync = mLastVsyncSequence->vsyncTime + slope * renderRatePhase;
return nextAnticipatedVSyncTimeFromLocked(approximateNextVsync - slope / 2);
}
@@ -317,10 +330,10 @@
return vsyncSequence.seq % divisor == 0;
}
-void VSyncPredictor::setDivisor(unsigned divisor) {
- ALOGV("%s: %d", __func__, divisor);
+void VSyncPredictor::setRenderRate(Fps fps) {
+ ALOGV("%s: %s", __func__, to_string(fps).c_str());
std::lock_guard lock(mMutex);
- mDivisor = divisor;
+ mRenderRate = fps;
}
VSyncPredictor::Model VSyncPredictor::getVSyncPredictionModel() const {