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

Commit c5d7246d authored by Ady Abraham's avatar Ady Abraham
Browse files

SF: keep a reference vsync point before clearing timestamps

This will keep the vsync sequence numbering in case that the
the new vsync timeline matches the old one.

Bug: 329036771
Change-Id: Ib65ec3cd4230ffb7ab12cec1757c5d3e32f0b1f9
Test: com.android.uibench.microbenchmark.UiBenchInflatingHanListViewFlingMicrobenchmark
parent c56f5c2a
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -553,10 +553,23 @@ void VSyncPredictor::clearTimestamps() {
        mLastTimestampIndex = 0;
    }

    mTimelines.clear();
    mLastCommittedVsync = TimePoint::fromNs(0);
    mIdealPeriod = Period::fromNs(idealPeriod());
    if (mTimelines.empty()) {
        mLastCommittedVsync = TimePoint::fromNs(0);
        mTimelines.emplace_back(mLastCommittedVsync, mIdealPeriod, mRenderRateOpt);
    } else {
        while (mTimelines.size() > 1) {
            mTimelines.pop_front();
        }
        mTimelines.front().setRenderRate(mRenderRateOpt);
        // set mLastCommittedVsync to a valid vsync but don't commit too much in the future
        const auto vsyncOpt = mTimelines.front().nextAnticipatedVSyncTimeFrom(
            getVSyncPredictionModelLocked(),
            /* minFramePeriodOpt */ std::nullopt,
            snapToVsync(mClock->now()), MissedVsync{},
            /* lastVsyncOpt */ std::nullopt);
        mLastCommittedVsync = *vsyncOpt;
    }
}

bool VSyncPredictor::needsMoreSamples() const {
@@ -588,6 +601,7 @@ void VSyncPredictor::purgeTimelines(android::TimePoint now) {
    if (mRenderRateOpt &&
        mLastCommittedVsync.ns() + mRenderRateOpt->getPeriodNsecs() * kEnoughFramesToBreakPhase <
                mClock->now()) {
        ATRACE_FORMAT_INSTANT("kEnoughFramesToBreakPhase");
        mTimelines.clear();
        mLastCommittedVsync = TimePoint::fromNs(0);
        mTimelines.emplace_back(mLastCommittedVsync, mIdealPeriod, mRenderRateOpt);
+2 −2
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ private:
    };

    struct MissedVsync {
        TimePoint vsync;
        TimePoint vsync = TimePoint::fromNs(0);
        Duration fixup = Duration::fromNs(0);
    };

@@ -97,7 +97,7 @@ private:
        std::optional<TimePoint> validUntil() const { return mValidUntil; }
        bool isVSyncInPhase(Model, nsecs_t vsync, Fps frameRate);
        void shiftVsyncSequence(Duration phase);
        void setRenderRate(Fps renderRate) { mRenderRateOpt = renderRate; }
        void setRenderRate(std::optional<Fps> renderRateOpt) { mRenderRateOpt = renderRateOpt; }

    private:
        nsecs_t snapToVsyncAlignedWithRenderRate(Model model, nsecs_t vsync);