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

Commit ca479e9c authored by Kevin DuBois's avatar Kevin DuBois Committed by Android (Google) Code Review
Browse files

Merge "SF: VSyncTracker, clear timestamps on beginResync"

parents 6d8a276c c3e9e8ea
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ VSyncPredictor::VSyncPredictor(nsecs_t idealPeriod, size_t historySize,
        kMinimumSamplesForPrediction(minimumSamplesForPrediction),
        kOutlierTolerancePercent(std::min(outlierTolerancePercent, kMaxPercent)),
        mIdealPeriod(idealPeriod) {
    mRateMap[mIdealPeriod] = {idealPeriod, 0};
    resetModel();
}

inline size_t VSyncPredictor::next(int i) const {
@@ -203,6 +203,10 @@ void VSyncPredictor::setPeriod(nsecs_t period) {
        mRateMap[mIdealPeriod] = {period, 0};
    }

    clearTimestamps();
}

void VSyncPredictor::clearTimestamps() {
    if (!timestamps.empty()) {
        mKnownTimestamp = *std::max_element(timestamps.begin(), timestamps.end());
        timestamps.clear();
@@ -227,6 +231,12 @@ bool VSyncPredictor::needsMoreSamples(nsecs_t now) const {
    return needsMoreSamples;
}

void VSyncPredictor::resetModel() {
    std::lock_guard<std::mutex> lk(mMutex);
    mRateMap[mIdealPeriod] = {mIdealPeriod, 0};
    clearTimestamps();
}

} // namespace android::scheduler

// TODO(b/129481165): remove the #pragma below and fix conversion issues
+3 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ public:
    void addVsyncTimestamp(nsecs_t timestamp) final;
    nsecs_t nextAnticipatedVSyncTimeFrom(nsecs_t timePoint) const final;
    nsecs_t currentPeriod() const final;
    void resetModel() final;

    /*
     * Inform the model that the period is anticipated to change to a new value.
@@ -48,7 +49,7 @@ public:
     *
     * \param [in] period   The new period that should be used.
     */
    void setPeriod(nsecs_t period);
    void setPeriod(nsecs_t period) final;

    /* Query if the model is in need of more samples to make a prediction at timePoint.
     * \param [in] timePoint    The timePoint to inquire of.
@@ -61,6 +62,7 @@ public:
private:
    VSyncPredictor(VSyncPredictor const&) = delete;
    VSyncPredictor& operator=(VSyncPredictor const&) = delete;
    void clearTimestamps() REQUIRES(mMutex);

    size_t const kHistorySize;
    size_t const kMinimumSamplesForPrediction;
+3 −1
Original line number Diff line number Diff line
@@ -199,7 +199,9 @@ nsecs_t VSyncReactor::getPeriod() {
    return mTracker->currentPeriod();
}

void VSyncReactor::beginResync() {}
void VSyncReactor::beginResync() {
    mTracker->resetModel();
}

void VSyncReactor::endResync() {}

+3 −0
Original line number Diff line number Diff line
@@ -61,6 +61,9 @@ public:
     */
    virtual void setPeriod(nsecs_t period) = 0;

    /* Inform the tracker that the samples it has are not accurate for prediction. */
    virtual void resetModel() = 0;

protected:
    VSyncTracker(VSyncTracker const&) = delete;
    VSyncTracker& operator=(VSyncTracker const&) = delete;
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ public:
    nsecs_t currentPeriod() const final { return mPeriod; }

    void setPeriod(nsecs_t) final {}
    void resetModel() final {}

private:
    nsecs_t const mPeriod;
@@ -83,6 +84,7 @@ public:
    }

    void setPeriod(nsecs_t) final {}
    void resetModel() final {}

private:
    std::mutex mutable mMutex;
Loading