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

Commit f9cc446f authored by Daniel Solomon's avatar Daniel Solomon Committed by android-build-merger
Browse files

SurfaceFlinger: Query Scheduler when updating allowed display configs

am: d916d941

Change-Id: I279ecd4fbacd6d7860e2d09c87cd10a40ccb416a
parents be9c6287 d916d941
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -567,6 +567,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)
    auto iter = min_element(mRefreshRateConfigs.getRefreshRates().cbegin(),
                            mRefreshRateConfigs.getRefreshRates().cend(),
                            [rate = mContentRefreshRate](const auto& l, const auto& r) -> bool {
@@ -596,6 +597,11 @@ Scheduler::RefreshRateType Scheduler::calculateRefreshRateType() {
    return currRefreshRateType;
}

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

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
@@ -189,6 +189,9 @@ public:
    // calls DispSync::dump() on primary disp sync
    void dumpPrimaryDispSync(std::string& result) const;

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

protected:
    virtual std::unique_ptr<EventThread> makeEventThread(
            const char* connectionName, DispSync* dispSync, nsecs_t phaseOffsetNs,
+20 −10
Original line number Diff line number Diff line
@@ -6169,6 +6169,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()) {
@@ -6190,16 +6209,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
@@ -534,6 +534,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)