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

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

SurfaceFlinger: always send event when allowed config changes

When we change config due to setAllowedDisplayConfig, we have to
send an event to notify the app about this.

Test: toggle peak refresh rate and observe events
Fixes: 129159940
Change-Id: Ibd64dd2846fecee11d0a551fe475ed667af26ea9
parent dc705b9e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ public:
    }
    ~RefreshRateConfigs() = default;

    const std::unordered_map<RefreshRateType, std::shared_ptr<RefreshRate>>& getRefreshRates() {
    const std::map<RefreshRateType, std::shared_ptr<RefreshRate>>& getRefreshRates() {
        return mRefreshRates;
    }
    std::shared_ptr<RefreshRate> getRefreshRate(RefreshRateType type) {
@@ -120,7 +120,7 @@ private:
        }
    }

    std::unordered_map<RefreshRateType, std::shared_ptr<RefreshRate>> mRefreshRates;
    std::map<RefreshRateType, std::shared_ptr<RefreshRate>> mRefreshRates;
};

} // namespace scheduler
+9 −24
Original line number Diff line number Diff line
@@ -1041,6 +1041,7 @@ bool SurfaceFlinger::performSetActiveConfig() NO_THREAD_SAFETY_ANALYSIS {
        // on both cases there is nothing left to do
        std::lock_guard<std::mutex> lock(mActiveConfigLock);
        mScheduler->pauseVsyncCallback(mAppConnectionHandle, false);
        mDesiredActiveConfig.event = Scheduler::ConfigEvent::None;
        mDesiredActiveConfigChanged = false;
        ATRACE_INT("DesiredActiveConfigChanged", mDesiredActiveConfigChanged);
        return false;
@@ -5805,34 +5806,18 @@ void SurfaceFlinger::setAllowedDisplayConfigsInternal(
        mAllowedConfigs[*displayId] = std::move(allowedConfigs);
    }

    // make sure that the current config is still allowed
    int currentConfigIndex = getHwComposer().getActiveConfigIndex(*displayId);
    if (!isConfigAllowed(*displayId, currentConfigIndex)) {
        for (const auto& [type, config] : mRefreshRateConfigs[*displayId]->getRefreshRates()) {
            if (config && isConfigAllowed(*displayId, config->configId)) {
                // TODO: we switch to the first allowed config. In the future
                // we may want to enhance this logic to pick a similar config
                // to the current one
                ALOGV("Old config is not allowed - switching to config %d", config->configId);
                setDesiredActiveConfig(displayToken, config->configId,
    // Set the highest allowed config by iterating backwards on available refresh rates
    const auto& refreshRates = mRefreshRateConfigs[*displayId]->getRefreshRates();
    for (auto iter = refreshRates.crbegin(); iter != refreshRates.crend(); ++iter) {
        if (iter->second && isConfigAllowed(*displayId, iter->second->configId)) {
            ALOGV("switching to config %d", iter->second->configId);
            setDesiredActiveConfig(displayToken, iter->second->configId,
                                   Scheduler::ConfigEvent::Changed);
            break;
        }
    }
}

    // If idle timer and fps detection are disabled and we are in RefreshRateType::DEFAULT,
    // there is no trigger to move to RefreshRateType::PERFORMANCE, even if it is an allowed.
    if (!mScheduler->isIdleTimerEnabled() && !mUseSmart90ForVideo) {
        const auto& performanceRefreshRate =
                mRefreshRateConfigs[*displayId]->getRefreshRate(RefreshRateType::PERFORMANCE);
        if (performanceRefreshRate &&
            isConfigAllowed(*displayId, performanceRefreshRate->configId)) {
            setRefreshRateTo(RefreshRateType::PERFORMANCE, Scheduler::ConfigEvent::Changed);
        }
    }
}

status_t SurfaceFlinger::setAllowedDisplayConfigs(const android::sp<android::IBinder>& displayToken,
                                                  const std::vector<int32_t>& allowedConfigs) {
    ATRACE_CALL();