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

Commit 4b494ee9 authored by Wei Wang's avatar Wei Wang Committed by Ana Krulec
Browse files

Surfaceflinger: adjust content detection fps selection

Select the FPS with minimal error in the first pass and then adjust
based on ratio/margin.

The CL changes content driven FPS selection logic,
before the change, the code switch to 90hz configs
when mContentRefreshRate > 64 and with the CL it will
switch to 90hz when mContentRefreshRate > 75. The second
pass to select 90hz when mContentRefreshRate is 45fps
is kept as is. It also simplified and removed 5% margin
in the first pass.

Test: boot and take SF trace
Bug: 136472613
Change-Id: I4445386a301b7fcdd22d71bd49f45540cc414174
(cherry picked from commit 09be73f6)
Merged-In: I4445386a301b7fcdd22d71bd49f45540cc414174
parent 9f10eb9c
Loading
Loading
Loading
Loading
+9 −12
Original line number Diff line number Diff line
@@ -523,22 +523,19 @@ Scheduler::RefreshRateType Scheduler::calculateRefreshRateType() {
        return RefreshRateType::PERFORMANCE;
    }

    // Content detection is on, find the appropriate refresh rate
    // Start with the smallest refresh rate which is within a margin of the content
    RefreshRateType currRefreshRateType = RefreshRateType::PERFORMANCE;
    constexpr float MARGIN = 0.05f;
    auto iter = mRefreshRateConfigs.getRefreshRates().cbegin();
    while (iter != mRefreshRateConfigs.getRefreshRates().cend()) {
        if (iter->second->fps >= mContentRefreshRate * (1 - MARGIN)) {
            currRefreshRateType = iter->first;
            break;
        }
        ++iter;
    }
    // Content detection is on, find the appropriate refresh rate with minimal error
    auto iter = min_element(mRefreshRateConfigs.getRefreshRates().cbegin(),
                            mRefreshRateConfigs.getRefreshRates().cend(),
                            [rate = mContentRefreshRate](const auto& l, const auto& r) -> bool {
                                return std::abs(l.second->fps - static_cast<float>(rate)) <
                                        std::abs(r.second->fps - static_cast<float>(rate));
                            });
    RefreshRateType currRefreshRateType = iter->first;

    // Some content aligns better on higher refresh rate. For example for 45fps we should choose
    // 90Hz config. However we should still prefer a lower refresh rate if the content doesn't
    // align well with both
    constexpr float MARGIN = 0.05f;
    float ratio = mRefreshRateConfigs.getRefreshRate(currRefreshRateType)->fps /
            float(mContentRefreshRate);
    if (std::abs(std::round(ratio) - ratio) > MARGIN) {