diff options
author | 2021-01-26 23:05:59 +0000 | |
---|---|---|
committer | 2021-01-26 23:05:59 +0000 | |
commit | 6e95c696efb5d1805bbe1c22c8f40c77cb2d609f (patch) | |
tree | be02de1a8e8d46df07bd61492a04ee45c830bfe1 | |
parent | 7dfe58cc10486fb3a06309aaf5abfc4290c6931c (diff) | |
parent | 707840a56beb522234976dbee16015acd777b415 (diff) |
Merge "SurfaceFlinger: VSyncPredictor should be robust with inconsistent vsyncs"
-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 |