Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d6b7349 authored by Ady Abraham's avatar Ady Abraham Committed by Android (Google) Code Review
Browse files

Merge "SurfaceFlinger: VSyncPredictor should be robust with inconsistent vsyncs"

parents 3e224977 43a3e693
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -77,8 +77,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 {
+14 −0
Original line number Diff line number Diff line
@@ -475,6 +475,20 @@ TEST_F(VSyncPredictorTest, isVSyncInPhase) {
    }
}

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