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

Commit 22efabaa authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "SF: keep a reference vsync point before clearing timestamps" into main

parents ff9f64a5 c5d7246d
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);