diff options
-rw-r--r-- | services/surfaceflinger/Scheduler/VSyncPredictor.cpp | 8 | ||||
-rw-r--r-- | services/surfaceflinger/tests/unittests/VSyncPredictorTest.cpp | 14 |
2 files changed, 20 insertions, 2 deletions
diff --git a/services/surfaceflinger/Scheduler/VSyncPredictor.cpp b/services/surfaceflinger/Scheduler/VSyncPredictor.cpp index 61f3fbbdf1..708a5b87be 100644 --- a/services/surfaceflinger/Scheduler/VSyncPredictor.cpp +++ b/services/surfaceflinger/Scheduler/VSyncPredictor.cpp @@ -78,8 +78,12 @@ bool VSyncPredictor::addVsyncTimestamp(nsecs_t timestamp) { if (!validate(timestamp)) { // VSR could elect to ignore the incongruent timestamp or resetModel(). If ts is ignored, - // don't insert this ts into mTimestamps ringbuffer. - if (!mTimestamps.empty()) { + // don't insert this ts into mTimestamps ringbuffer. If we are still + // in the learning phase we should just clear all timestamps and start + // over. + if (mTimestamps.size() < kMinimumSamplesForPrediction) { + clearTimestamps(); + } else if (!mTimestamps.empty()) { mKnownTimestamp = std::max(timestamp, *std::max_element(mTimestamps.begin(), mTimestamps.end())); } else { diff --git a/services/surfaceflinger/tests/unittests/VSyncPredictorTest.cpp b/services/surfaceflinger/tests/unittests/VSyncPredictorTest.cpp index d4cd11dbe1..5e5d51c994 100644 --- a/services/surfaceflinger/tests/unittests/VSyncPredictorTest.cpp +++ b/services/surfaceflinger/tests/unittests/VSyncPredictorTest.cpp @@ -450,6 +450,20 @@ TEST_F(VSyncPredictorTest, aPhoneThatHasBeenAroundAWhileCanStillComputePeriod) { EXPECT_THAT(intercept, Eq(0)); } +TEST_F(VSyncPredictorTest, InconsistentVsyncValueIsFlushedEventually) { + EXPECT_TRUE(tracker.addVsyncTimestamp(600)); + EXPECT_TRUE(tracker.needsMoreSamples()); + + EXPECT_FALSE(tracker.addVsyncTimestamp(mNow += mPeriod)); + + for (auto i = 0u; i < kMinimumSamplesForPrediction; i++) { + EXPECT_TRUE(tracker.needsMoreSamples()); + EXPECT_TRUE(tracker.addVsyncTimestamp(mNow += mPeriod)); + } + + EXPECT_FALSE(tracker.needsMoreSamples()); +} + } // namespace android::scheduler // TODO(b/129481165): remove the #pragma below and fix conversion issues |