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

Commit dd59431d authored by Marin Shalamanov's avatar Marin Shalamanov
Browse files

SF: Complete mode change immediately if refresh is not required

Bug: 190982486
Test: atest libsurfaceflinger_unittest
Change-Id: I4be91274c6570c5e9304098d5d6c3d30c41c4e6e
parent 85b2bdfe
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -1201,6 +1201,8 @@ void SurfaceFlinger::desiredActiveModeChangeDone(const sp<DisplayDevice>& displa
void SurfaceFlinger::setActiveModeInHwcIfNeeded() {
    ATRACE_CALL();

    std::optional<PhysicalDisplayId> displayToUpdateImmediately;

    for (const auto& iter : mDisplays) {
        const auto& display = iter.second;
        if (!display || !display->isInternal()) {
@@ -1265,8 +1267,26 @@ void SurfaceFlinger::setActiveModeInHwcIfNeeded() {
        }
        mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline);

        // Scheduler will submit an empty frame to HWC if needed.
        if (outTimeline.refreshRequired) {
            // Scheduler will submit an empty frame to HWC.
            mSetActiveModePending = true;
        } else {
            // Updating the internal state should be done outside the loop,
            // because it can recreate a DisplayDevice and modify mDisplays
            // which will invalidate the iterator.
            displayToUpdateImmediately = display->getPhysicalId();
        }
    }

    if (displayToUpdateImmediately) {
        updateInternalStateWithChangedMode();

        const auto display = getDisplayDeviceLocked(*displayToUpdateImmediately);
        const auto desiredActiveMode = display->getDesiredActiveMode();
        if (desiredActiveMode &&
            display->getActiveMode()->getId() == desiredActiveMode->mode->getId()) {
            desiredActiveModeChangeDone(display);
        }
    }
}

+1 −2
Original line number Diff line number Diff line
@@ -660,8 +660,7 @@ private:
    // Sets the desired active mode bit. It obtains the lock, and sets mDesiredActiveMode.
    void setDesiredActiveMode(const ActiveModeInfo& info) REQUIRES(mStateLock);
    status_t setActiveModeFromBackdoor(const sp<IBinder>& displayToken, int id);
    // Once HWC has returned the present fence, this sets the active mode and a new refresh
    // rate in SF.
    // Sets the active mode and a new refresh rate in SF.
    void updateInternalStateWithChangedMode() REQUIRES(mStateLock);
    // Calls to setActiveMode on the main thread if there is a pending mode change
    // that needs to be applied.