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

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

SF: flush setRenderRate when changing mode

There is no point to try to syncronize changing the render rate
if the display mode changes. This would just cause more latency
to getting the next vsync.

Bug: 328140524
Test: presubmit
Change-Id: I78a82bee01ba793890d459564ab701d257851b49
parent 77b4fb1e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -565,7 +565,7 @@ void Scheduler::onHardwareVsyncRequest(PhysicalDisplayId id, bool enabled) {
            }));
}

void Scheduler::setRenderRate(PhysicalDisplayId id, Fps renderFrameRate) {
void Scheduler::setRenderRate(PhysicalDisplayId id, Fps renderFrameRate, bool applyImmediately) {
    std::scoped_lock lock(mDisplayLock);
    ftl::FakeGuard guard(kMainThreadContext);

@@ -586,7 +586,7 @@ void Scheduler::setRenderRate(PhysicalDisplayId id, Fps renderFrameRate) {
    ALOGV("%s %s (%s)", __func__, to_string(mode.fps).c_str(),
          to_string(mode.modePtr->getVsyncRate()).c_str());

    display.schedulePtr->getTracker().setRenderRate(renderFrameRate);
    display.schedulePtr->getTracker().setRenderRate(renderFrameRate, applyImmediately);
}

Fps Scheduler::getNextFrameInterval(PhysicalDisplayId id,
+1 −1
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ public:
    const VsyncConfiguration& getVsyncConfiguration() const { return *mVsyncConfiguration; }

    // Sets the render rate for the scheduler to run at.
    void setRenderRate(PhysicalDisplayId, Fps);
    void setRenderRate(PhysicalDisplayId, Fps, bool applyImmediately);

    void enableHardwareVsync(PhysicalDisplayId) REQUIRES(kMainThreadContext);
    void disableHardwareVsync(PhysicalDisplayId, bool disallow) REQUIRES(kMainThreadContext);
+8 −3
Original line number Diff line number Diff line
@@ -296,6 +296,10 @@ nsecs_t VSyncPredictor::nextAnticipatedVSyncTimeFrom(nsecs_t timePoint,
    const auto now = TimePoint::fromNs(mClock->now());
    purgeTimelines(now);

    if (lastVsyncOpt && *lastVsyncOpt > timePoint) {
        timePoint = *lastVsyncOpt;
    }

    const auto model = getVSyncPredictionModelLocked();
    const auto threshold = model.slope / 2;
    std::optional<TimePoint> vsyncOpt;
@@ -352,7 +356,7 @@ bool VSyncPredictor::isVSyncInPhase(nsecs_t timePoint, Fps frameRate) {
    return mTimelines.back().isVSyncInPhase(model, vsync, frameRate);
}

void VSyncPredictor::setRenderRate(Fps renderRate) {
void VSyncPredictor::setRenderRate(Fps renderRate, bool applyImmediately) {
    ATRACE_FORMAT("%s %s", __func__, to_string(renderRate).c_str());
    ALOGV("%s %s: RenderRate %s ", __func__, to_string(mId).c_str(), to_string(renderRate).c_str());
    std::lock_guard lock(mMutex);
@@ -360,8 +364,9 @@ void VSyncPredictor::setRenderRate(Fps renderRate) {
    mRenderRateOpt = renderRate;
    const auto renderPeriodDelta =
            prevRenderRate ? prevRenderRate->getPeriodNsecs() - renderRate.getPeriodNsecs() : 0;
    if (renderPeriodDelta > renderRate.getPeriodNsecs() &&
        mLastCommittedVsync.ns() - mClock->now() > 2 * renderRate.getPeriodNsecs()) {
    const bool newRenderRateIsHigher = renderPeriodDelta > renderRate.getPeriodNsecs() &&
            mLastCommittedVsync.ns() - mClock->now() > 2 * renderRate.getPeriodNsecs();
    if (applyImmediately || newRenderRateIsHigher) {
        mTimelines.clear();
        mLastCommittedVsync = TimePoint::fromNs(0);
    } else {
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public:

    void setDisplayModePtr(ftl::NonNull<DisplayModePtr>) final EXCLUDES(mMutex);

    void setRenderRate(Fps) final EXCLUDES(mMutex);
    void setRenderRate(Fps, bool applyImmediately) final EXCLUDES(mMutex);

    void onFrameBegin(TimePoint expectedPresentTime, TimePoint lastConfirmedPresentTime) final
            EXCLUDES(mMutex);
+3 −1
Original line number Diff line number Diff line
@@ -102,8 +102,10 @@ public:
     * when a display is running at 120Hz but the render frame rate is 60Hz.
     *
     * \param [in] Fps   The render rate the tracker should operate at.
     * \param [in] applyImmediately Whether to apply the new render rate immediately regardless of
     *                              already committed vsyncs.
     */
    virtual void setRenderRate(Fps) = 0;
    virtual void setRenderRate(Fps, bool applyImmediately) = 0;

    virtual void onFrameBegin(TimePoint expectedPresentTime,
                              TimePoint lastConfirmedPresentTime) = 0;
Loading