Revert "Revert "SF: pass a render rate to VsyncTracker instead of a divisor""
This reverts commit 3d21d3afa1056efacf702b74449f9e2e7b5701f1.
Reason for revert: https://b.corp.google.com/issues/269561042#comment14
Bug: 269561042
Change-Id: Iae8d0e62be2eafb4278b64ffcb1524ece211a00c
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 {