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

Commit 13a864c4 authored by Marin Shalamanov's avatar Marin Shalamanov Committed by Android (Google) Code Review
Browse files

Merge changes I101f4015,Ia236fd4a,I8a00657e into sc-dev

* changes:
  SF: Move mode caching from Scheduler to RefreshRateConfigs
  SF: Always create LayerHistory in Scheduler
  SF: Recreate display on resolution changes
parents 8e80994d 4c7831e4
Loading
Loading
Loading
Loading
+51 −2
Original line number Original line Diff line number Diff line
@@ -190,6 +190,45 @@ struct RefreshRateScore {
RefreshRate RefreshRateConfigs::getBestRefreshRate(const std::vector<LayerRequirement>& layers,
RefreshRate RefreshRateConfigs::getBestRefreshRate(const std::vector<LayerRequirement>& layers,
                                                   const GlobalSignals& globalSignals,
                                                   const GlobalSignals& globalSignals,
                                                   GlobalSignals* outSignalsConsidered) const {
                                                   GlobalSignals* outSignalsConsidered) const {
    std::lock_guard lock(mLock);

    if (auto cached = getCachedBestRefreshRate(layers, globalSignals, outSignalsConsidered)) {
        return *cached;
    }

    GlobalSignals signalsConsidered;
    RefreshRate result = getBestRefreshRateLocked(layers, globalSignals, &signalsConsidered);
    lastBestRefreshRateInvocation.emplace(
            GetBestRefreshRateInvocation{.layerRequirements = layers,
                                         .globalSignals = globalSignals,
                                         .outSignalsConsidered = signalsConsidered,
                                         .resultingBestRefreshRate = result});
    if (outSignalsConsidered) {
        *outSignalsConsidered = signalsConsidered;
    }
    return result;
}

std::optional<RefreshRate> RefreshRateConfigs::getCachedBestRefreshRate(
        const std::vector<LayerRequirement>& layers, const GlobalSignals& globalSignals,
        GlobalSignals* outSignalsConsidered) const {
    const bool sameAsLastCall = lastBestRefreshRateInvocation &&
            lastBestRefreshRateInvocation->layerRequirements == layers &&
            lastBestRefreshRateInvocation->globalSignals == globalSignals;

    if (sameAsLastCall) {
        if (outSignalsConsidered) {
            *outSignalsConsidered = lastBestRefreshRateInvocation->outSignalsConsidered;
        }
        return lastBestRefreshRateInvocation->resultingBestRefreshRate;
    }

    return {};
}

RefreshRate RefreshRateConfigs::getBestRefreshRateLocked(
        const std::vector<LayerRequirement>& layers, const GlobalSignals& globalSignals,
        GlobalSignals* outSignalsConsidered) const {
    ATRACE_CALL();
    ATRACE_CALL();
    ALOGV("getBestRefreshRate %zu layers", layers.size());
    ALOGV("getBestRefreshRate %zu layers", layers.size());


@@ -206,8 +245,6 @@ RefreshRate RefreshRateConfigs::getBestRefreshRate(const std::vector<LayerRequir
        }
        }
    };
    };


    std::lock_guard lock(mLock);

    int noVoteLayers = 0;
    int noVoteLayers = 0;
    int minVoteLayers = 0;
    int minVoteLayers = 0;
    int maxVoteLayers = 0;
    int maxVoteLayers = 0;
@@ -592,6 +629,11 @@ const RefreshRate& RefreshRateConfigs::getCurrentRefreshRateByPolicyLocked() con


void RefreshRateConfigs::setCurrentModeId(DisplayModeId modeId) {
void RefreshRateConfigs::setCurrentModeId(DisplayModeId modeId) {
    std::lock_guard lock(mLock);
    std::lock_guard lock(mLock);

    // Invalidate the cached invocation to getBestRefreshRate. This forces
    // the refresh rate to be recomputed on the next call to getBestRefreshRate.
    lastBestRefreshRateInvocation.reset();

    mCurrentRefreshRate = mRefreshRates.at(modeId).get();
    mCurrentRefreshRate = mRefreshRates.at(modeId).get();
}
}


@@ -605,11 +647,16 @@ RefreshRateConfigs::RefreshRateConfigs(const DisplayModes& modes, DisplayModeId
void RefreshRateConfigs::updateDisplayModes(const DisplayModes& modes,
void RefreshRateConfigs::updateDisplayModes(const DisplayModes& modes,
                                            DisplayModeId currentModeId) {
                                            DisplayModeId currentModeId) {
    std::lock_guard lock(mLock);
    std::lock_guard lock(mLock);

    // The current mode should be supported
    // The current mode should be supported
    LOG_ALWAYS_FATAL_IF(std::none_of(modes.begin(), modes.end(), [&](DisplayModePtr mode) {
    LOG_ALWAYS_FATAL_IF(std::none_of(modes.begin(), modes.end(), [&](DisplayModePtr mode) {
        return mode->getId() == currentModeId;
        return mode->getId() == currentModeId;
    }));
    }));


    // Invalidate the cached invocation to getBestRefreshRate. This forces
    // the refresh rate to be recomputed on the next call to getBestRefreshRate.
    lastBestRefreshRateInvocation.reset();

    mRefreshRates.clear();
    mRefreshRates.clear();
    for (const auto& mode : modes) {
    for (const auto& mode : modes) {
        const auto modeId = mode->getId();
        const auto modeId = mode->getId();
@@ -666,6 +713,7 @@ status_t RefreshRateConfigs::setDisplayManagerPolicy(const Policy& policy) {
        ALOGE("Invalid refresh rate policy: %s", policy.toString().c_str());
        ALOGE("Invalid refresh rate policy: %s", policy.toString().c_str());
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }
    lastBestRefreshRateInvocation.reset();
    Policy previousPolicy = *getCurrentPolicyLocked();
    Policy previousPolicy = *getCurrentPolicyLocked();
    mDisplayManagerPolicy = policy;
    mDisplayManagerPolicy = policy;
    if (*getCurrentPolicyLocked() == previousPolicy) {
    if (*getCurrentPolicyLocked() == previousPolicy) {
@@ -680,6 +728,7 @@ status_t RefreshRateConfigs::setOverridePolicy(const std::optional<Policy>& poli
    if (policy && !isPolicyValidLocked(*policy)) {
    if (policy && !isPolicyValidLocked(*policy)) {
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }
    lastBestRefreshRateInvocation.reset();
    Policy previousPolicy = *getCurrentPolicyLocked();
    Policy previousPolicy = *getCurrentPolicyLocked();
    mOverridePolicy = policy;
    mOverridePolicy = policy;
    if (*getCurrentPolicyLocked() == previousPolicy) {
    if (*getCurrentPolicyLocked() == previousPolicy) {
+22 −0
Original line number Original line Diff line number Diff line
@@ -250,6 +250,10 @@ public:
        bool touch = false;
        bool touch = false;
        // True if the system hasn't seen any buffers posted to layers recently.
        // True if the system hasn't seen any buffers posted to layers recently.
        bool idle = false;
        bool idle = false;

        bool operator==(const GlobalSignals& other) const {
            return touch == other.touch && idle == other.idle;
        }
    };
    };


    // Returns the refresh rate that fits best to the given layers.
    // Returns the refresh rate that fits best to the given layers.
@@ -350,6 +354,15 @@ private:
            const std::function<bool(const RefreshRate&)>& shouldAddRefreshRate,
            const std::function<bool(const RefreshRate&)>& shouldAddRefreshRate,
            std::vector<const RefreshRate*>* outRefreshRates) REQUIRES(mLock);
            std::vector<const RefreshRate*>* outRefreshRates) REQUIRES(mLock);


    std::optional<RefreshRate> getCachedBestRefreshRate(const std::vector<LayerRequirement>& layers,
                                                        const GlobalSignals& globalSignals,
                                                        GlobalSignals* outSignalsConsidered) const
            REQUIRES(mLock);

    RefreshRate getBestRefreshRateLocked(const std::vector<LayerRequirement>& layers,
                                         const GlobalSignals& globalSignals,
                                         GlobalSignals* outSignalsConsidered) const REQUIRES(mLock);

    // Returns the refresh rate with the highest score in the collection specified from begin
    // Returns the refresh rate with the highest score in the collection specified from begin
    // to end. If there are more than one with the same highest refresh rate, the first one is
    // to end. If there are more than one with the same highest refresh rate, the first one is
    // returned.
    // returned.
@@ -414,6 +427,15 @@ private:


    const bool mEnableFrameRateOverride;
    const bool mEnableFrameRateOverride;
    bool mSupportsFrameRateOverride;
    bool mSupportsFrameRateOverride;

    struct GetBestRefreshRateInvocation {
        std::vector<LayerRequirement> layerRequirements;
        GlobalSignals globalSignals;
        GlobalSignals outSignalsConsidered;
        RefreshRate resultingBestRefreshRate;
    };
    mutable std::optional<GetBestRefreshRateInvocation> lastBestRefreshRateInvocation
            GUARDED_BY(mLock);
};
};


} // namespace android::scheduler
} // namespace android::scheduler
+1 −0
Original line number Original line Diff line number Diff line
@@ -61,6 +61,7 @@ public:
        if (mCurrentRefreshRate.equalsWithMargin(currRefreshRate)) {
        if (mCurrentRefreshRate.equalsWithMargin(currRefreshRate)) {
            return;
            return;
        }
        }
        mTimeStats.incrementRefreshRateSwitches();
        flushTime();
        flushTime();
        mCurrentRefreshRate = currRefreshRate;
        mCurrentRefreshRate = currRefreshRate;
    }
    }
+7 −24
Original line number Original line Diff line number Diff line
@@ -194,8 +194,6 @@ Scheduler::VsyncSchedule Scheduler::createVsyncSchedule(bool supportKernelTimer)


std::unique_ptr<LayerHistory> Scheduler::createLayerHistory(
std::unique_ptr<LayerHistory> Scheduler::createLayerHistory(
        const scheduler::RefreshRateConfigs& configs) {
        const scheduler::RefreshRateConfigs& configs) {
    if (!configs.canSwitch()) return nullptr;

    return std::make_unique<scheduler::LayerHistory>(configs);
    return std::make_unique<scheduler::LayerHistory>(configs);
}
}


@@ -579,8 +577,6 @@ void Scheduler::setIgnorePresentFences(bool ignore) {
}
}


void Scheduler::registerLayer(Layer* layer) {
void Scheduler::registerLayer(Layer* layer) {
    if (!mLayerHistory) return;

    scheduler::LayerHistory::LayerVoteType voteType;
    scheduler::LayerHistory::LayerVoteType voteType;


    if (!mOptions.useContentDetection ||
    if (!mOptions.useContentDetection ||
@@ -600,26 +596,22 @@ void Scheduler::registerLayer(Layer* layer) {
}
}


void Scheduler::deregisterLayer(Layer* layer) {
void Scheduler::deregisterLayer(Layer* layer) {
    if (mLayerHistory) {
    mLayerHistory->deregisterLayer(layer);
    mLayerHistory->deregisterLayer(layer);
}
}
}


void Scheduler::recordLayerHistory(Layer* layer, nsecs_t presentTime,
void Scheduler::recordLayerHistory(Layer* layer, nsecs_t presentTime,
                                   LayerHistory::LayerUpdateType updateType) {
                                   LayerHistory::LayerUpdateType updateType) {
    if (mLayerHistory) {
    if (mRefreshRateConfigs.canSwitch()) {
        mLayerHistory->record(layer, presentTime, systemTime(), updateType);
        mLayerHistory->record(layer, presentTime, systemTime(), updateType);
    }
    }
}
}


void Scheduler::setModeChangePending(bool pending) {
void Scheduler::setModeChangePending(bool pending) {
    if (mLayerHistory) {
    mLayerHistory->setModeChangePending(pending);
    mLayerHistory->setModeChangePending(pending);
}
}
}


void Scheduler::chooseRefreshRateForContent() {
void Scheduler::chooseRefreshRateForContent() {
    if (!mLayerHistory) return;
    if (!mRefreshRateConfigs.canSwitch()) return;


    ATRACE_CALL();
    ATRACE_CALL();


@@ -630,9 +622,6 @@ void Scheduler::chooseRefreshRateForContent() {
    bool frameRateOverridesChanged;
    bool frameRateOverridesChanged;
    {
    {
        std::lock_guard<std::mutex> lock(mFeatureStateLock);
        std::lock_guard<std::mutex> lock(mFeatureStateLock);
        if (mFeatures.contentRequirements == summary) {
            return;
        }
        mFeatures.contentRequirements = summary;
        mFeatures.contentRequirements = summary;


        newModeId = calculateRefreshRateModeId(&consideredSignals);
        newModeId = calculateRefreshRateModeId(&consideredSignals);
@@ -691,10 +680,8 @@ void Scheduler::setDisplayPowerState(bool normal) {


    // Display Power event will boost the refresh rate to performance.
    // Display Power event will boost the refresh rate to performance.
    // Clear Layer History to get fresh FPS detection
    // Clear Layer History to get fresh FPS detection
    if (mLayerHistory) {
    mLayerHistory->clear();
    mLayerHistory->clear();
}
}
}


void Scheduler::kernelIdleTimerCallback(TimerState state) {
void Scheduler::kernelIdleTimerCallback(TimerState state) {
    ATRACE_INT("ExpiredKernelIdleTimer", static_cast<int>(state));
    ATRACE_INT("ExpiredKernelIdleTimer", static_cast<int>(state));
@@ -732,10 +719,8 @@ void Scheduler::touchTimerCallback(TimerState state) {
    // NOTE: Instead of checking all the layers, we should be checking the layer
    // NOTE: Instead of checking all the layers, we should be checking the layer
    // that is currently on top. b/142507166 will give us this capability.
    // that is currently on top. b/142507166 will give us this capability.
    if (handleTimerStateChanged(&mFeatures.touch, touch)) {
    if (handleTimerStateChanged(&mFeatures.touch, touch)) {
        if (mLayerHistory) {
        mLayerHistory->clear();
        mLayerHistory->clear();
    }
    }
    }
    ATRACE_INT("TouchState", static_cast<int>(touch));
    ATRACE_INT("TouchState", static_cast<int>(touch));
}
}


@@ -908,10 +893,8 @@ void Scheduler::onDisplayRefreshed(nsecs_t timestamp) {
}
}


void Scheduler::onPrimaryDisplayAreaChanged(uint32_t displayArea) {
void Scheduler::onPrimaryDisplayAreaChanged(uint32_t displayArea) {
    if (mLayerHistory) {
    mLayerHistory->setDisplayArea(displayArea);
    mLayerHistory->setDisplayArea(displayArea);
}
}
}


void Scheduler::setPreferredRefreshRateForUid(FrameRateOverride frameRateOverride) {
void Scheduler::setPreferredRefreshRateForUid(FrameRateOverride frameRateOverride) {
    if (frameRateOverride.frameRateHz > 0.f && frameRateOverride.frameRateHz < 1.f) {
    if (frameRateOverride.frameRateHz > 0.f && frameRateOverride.frameRateHz < 1.f) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -268,7 +268,7 @@ private:
    VsyncSchedule mVsyncSchedule;
    VsyncSchedule mVsyncSchedule;


    // Used to choose refresh rate if content detection is enabled.
    // Used to choose refresh rate if content detection is enabled.
    const std::unique_ptr<LayerHistory> mLayerHistory;
    std::unique_ptr<LayerHistory> mLayerHistory;


    // Timer that records time between requests for next vsync.
    // Timer that records time between requests for next vsync.
    std::optional<scheduler::OneShotTimer> mIdleTimer;
    std::optional<scheduler::OneShotTimer> mIdleTimer;
Loading