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

Commit 6398a0a1 authored by Ady Abraham's avatar Ady Abraham
Browse files

SurfaceFlinger: call to changeRefreshRate on state change only

Check if Scheduler's idle timer / content detection changed before
calling to changeRefreshRate to avoid sending config changed events when
those are not neeed.

Test: scroll within calendar app and observe systraces
Bug: 130759239
Change-Id: If7bce0ac096630918decbf62c568baa5e17408f2
parent 8cd204d6
Loading
Loading
Loading
Loading
+24 −17
Original line number Diff line number Diff line
@@ -318,12 +318,24 @@ void Scheduler::withPrimaryDispSync(std::function<void(DispSync&)> const& fn) {

void Scheduler::updateFpsBasedOnContent() {
    uint32_t refreshRate = std::round(mLayerHistory.getDesiredRefreshRate());
    ATRACE_INT("ContentFPS", refreshRate);
    if (refreshRate > 0) {
        contentChangeRefreshRate(ContentFeatureState::CONTENT_DETECTION_ON, refreshRate);
    } else {
        contentChangeRefreshRate(ContentFeatureState::CONTENT_DETECTION_OFF, 0);
    RefreshRateType newRefreshRateType;
    {
        std::lock_guard<std::mutex> lock(mFeatureStateLock);
        if (mContentRefreshRate == refreshRate) {
            return;
        }
        mContentRefreshRate = refreshRate;
        ATRACE_INT("ContentFPS", mContentRefreshRate);

        mCurrentContentFeatureState = refreshRate > 0 ? ContentFeatureState::CONTENT_DETECTION_ON
                                                      : ContentFeatureState::CONTENT_DETECTION_OFF;
        newRefreshRateType = calculateRefreshRateType();
        if (mRefreshRateType == newRefreshRateType) {
            return;
        }
        mRefreshRateType = newRefreshRateType;
    }
    changeRefreshRate(newRefreshRateType, ConfigEvent::Changed);
}

void Scheduler::setChangeRefreshRateCallback(
@@ -365,24 +377,19 @@ std::string Scheduler::doDump() {
    return stream.str();
}

void Scheduler::contentChangeRefreshRate(ContentFeatureState contentFeatureState,
                                         uint32_t refreshRate) {
    RefreshRateType newRefreshRateType;
    {
        std::lock_guard<std::mutex> lock(mFeatureStateLock);
        mCurrentContentFeatureState = contentFeatureState;
        mContentRefreshRate = refreshRate;
        newRefreshRateType = calculateRefreshRateType();
    }
    changeRefreshRate(newRefreshRateType, ConfigEvent::Changed);
}

void Scheduler::timerChangeRefreshRate(IdleTimerState idleTimerState) {
    RefreshRateType newRefreshRateType;
    {
        std::lock_guard<std::mutex> lock(mFeatureStateLock);
        if (mCurrentIdleTimerState == idleTimerState) {
            return;
        }
        mCurrentIdleTimerState = idleTimerState;
        newRefreshRateType = calculateRefreshRateType();
        if (mRefreshRateType == newRefreshRateType) {
            return;
        }
        mRefreshRateType = newRefreshRateType;
    }
    changeRefreshRate(newRefreshRateType, ConfigEvent::None);
}
+2 −3
Original line number Diff line number Diff line
@@ -193,8 +193,6 @@ private:
    void expiredTimerCallback();
    // Sets vsync period.
    void setVsyncPeriod(const nsecs_t period);
    // Media feature's function to change the refresh rate.
    void contentChangeRefreshRate(ContentFeatureState contentFeatureState, uint32_t refreshRate);
    // Idle timer feature's function to change the refresh rate.
    void timerChangeRefreshRate(IdleTimerState idleTimerState);
    // Calculate the new refresh rate type
@@ -254,7 +252,8 @@ private:
    ContentFeatureState mCurrentContentFeatureState GUARDED_BY(mFeatureStateLock) =
            ContentFeatureState::CONTENT_DETECTION_OFF;
    IdleTimerState mCurrentIdleTimerState GUARDED_BY(mFeatureStateLock) = IdleTimerState::RESET;
    uint32_t mContentRefreshRate;
    uint32_t mContentRefreshRate GUARDED_BY(mFeatureStateLock);
    RefreshRateType mRefreshRateType GUARDED_BY(mFeatureStateLock);

    const scheduler::RefreshRateConfigs& mRefreshRateConfigs;
};
+3 −0
Original line number Diff line number Diff line
@@ -1005,6 +1005,7 @@ bool SurfaceFlinger::performSetActiveConfig() {
        // display is not valid or we are already in the requested mode
        // on both cases there is nothing left to do
        std::lock_guard<std::mutex> lock(mActiveConfigLock);
        mDesiredActiveConfig.event = Scheduler::ConfigEvent::None;
        mDesiredActiveConfigChanged = false;
        ATRACE_INT("DesiredActiveConfigChanged", mDesiredActiveConfigChanged);
        return false;
@@ -1017,6 +1018,8 @@ bool SurfaceFlinger::performSetActiveConfig() {
        std::lock_guard<std::mutex> lock(mActiveConfigLock);
        mDesiredActiveConfig.event = Scheduler::ConfigEvent::None;
        mDesiredActiveConfig.configId = display->getActiveConfig();
        mDesiredActiveConfigChanged = false;
        ATRACE_INT("DesiredActiveConfigChanged", mDesiredActiveConfigChanged);
        return false;
    }
    mUpcomingActiveConfig = desiredActiveConfig;