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

Commit 8efd2f3f authored by Daniel Solomon's avatar Daniel Solomon Committed by Android (Google) Code Review
Browse files

Merge "SurfaceFlinger: Query Scheduler when updating allowed display configs"

parents 3f5a0d2b 0f0ddc10
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -512,6 +512,7 @@ Scheduler::RefreshRateType Scheduler::calculateRefreshRateType() {
    }

    // Content detection is on, find the appropriate refresh rate with minimal error
    // TODO(b/139751853): Scan allowed refresh rates only (SurfaceFlinger::mAllowedDisplayConfigs)
    const float rate = static_cast<float>(mFeatures.contentRefreshRate);
    auto iter = min_element(mRefreshRateConfigs.getRefreshRates().cbegin(),
                            mRefreshRateConfigs.getRefreshRates().cend(),
@@ -541,6 +542,11 @@ Scheduler::RefreshRateType Scheduler::calculateRefreshRateType() {
    return currRefreshRateType;
}

Scheduler::RefreshRateType Scheduler::getPreferredRefreshRateType() {
    std::lock_guard<std::mutex> lock(mFeatureStateLock);
    return mFeatures.refreshRateType;
}

void Scheduler::changeRefreshRate(RefreshRateType refreshRateType, ConfigEvent configEvent) {
    std::lock_guard<std::mutex> lock(mCallbackLock);
    if (mChangeRefreshRateCallback) {
+3 −0
Original line number Diff line number Diff line
@@ -127,6 +127,9 @@ public:
    void dump(std::string&) const;
    void dump(ConnectionHandle, std::string&) const;

    // Get the appropriate refresh type for current conditions.
    RefreshRateType getPreferredRefreshRateType();

private:
    friend class TestableScheduler;

+20 −10
Original line number Diff line number Diff line
@@ -5578,6 +5578,25 @@ void SurfaceFlinger::traverseLayersInDisplay(const sp<const DisplayDevice>& disp
    }
}

void SurfaceFlinger::setPreferredDisplayConfig() {
    const auto& type = mScheduler->getPreferredRefreshRateType();
    const auto& config = mRefreshRateConfigs.getRefreshRate(type);
    if (config && isDisplayConfigAllowed(config->configId)) {
        ALOGV("switching to Scheduler preferred config %d", config->configId);
        setDesiredActiveConfig({type, config->configId, Scheduler::ConfigEvent::Changed});
    } else {
        // Set the highest allowed config by iterating backwards on available refresh rates
        const auto& refreshRates = mRefreshRateConfigs.getRefreshRates();
        for (auto iter = refreshRates.crbegin(); iter != refreshRates.crend(); ++iter) {
            if (iter->second && isDisplayConfigAllowed(iter->second->configId)) {
                ALOGV("switching to allowed config %d", iter->second->configId);
                setDesiredActiveConfig({iter->first, iter->second->configId,
                        Scheduler::ConfigEvent::Changed});
            }
        }
    }
}

void SurfaceFlinger::setAllowedDisplayConfigsInternal(const sp<DisplayDevice>& display,
                                                      const std::vector<int32_t>& allowedConfigs) {
    if (!display->isPrimary()) {
@@ -5599,16 +5618,7 @@ void SurfaceFlinger::setAllowedDisplayConfigsInternal(const sp<DisplayDevice>& d
    mScheduler->onConfigChanged(mAppConnectionHandle, display->getId()->value,
                                display->getActiveConfig());

    // Set the highest allowed config by iterating backwards on available refresh rates
    const auto& refreshRates = mRefreshRateConfigs.getRefreshRates();
    for (auto iter = refreshRates.crbegin(); iter != refreshRates.crend(); ++iter) {
        if (iter->second && isDisplayConfigAllowed(iter->second->configId)) {
            ALOGV("switching to config %d", iter->second->configId);
            setDesiredActiveConfig(
                    {iter->first, iter->second->configId, Scheduler::ConfigEvent::Changed});
            break;
        }
    }
    setPreferredDisplayConfig();
}

status_t SurfaceFlinger::setAllowedDisplayConfigs(const sp<IBinder>& displayToken,
+3 −0
Original line number Diff line number Diff line
@@ -528,6 +528,9 @@ private:
    // called on the main thread in response to setPowerMode()
    void setPowerModeInternal(const sp<DisplayDevice>& display, int mode) REQUIRES(mStateLock);

    // Query the Scheduler or allowed display configs list for a matching config, and set it
    void setPreferredDisplayConfig() REQUIRES(mStateLock);

    // called on the main thread in response to setAllowedDisplayConfigs()
    void setAllowedDisplayConfigsInternal(const sp<DisplayDevice>& display,
                                          const std::vector<int32_t>& allowedConfigs)