diff options
author | 2019-07-03 21:36:33 -0700 | |
---|---|---|
committer | 2019-07-03 21:36:33 -0700 | |
commit | 693e7d2a34e8d9f7950fcc395ce390ad1f8fb828 (patch) | |
tree | 4b1e040b10e402a86e2f7ff9a554989f75c7cb05 | |
parent | be11c4604ce098d7aa927ff21e9456ec412cee7f (diff) | |
parent | 3f4989a062c7ad4bfa7b76e0720995998ba46c89 (diff) |
Merge "Surfaceflinger: adjust content detection fps selection" into qt-r1-dev am: 9275c965d8
am: 3f4989a062
Change-Id: I6045d2b6b4671205501386054b6ea71d5e40709d
-rw-r--r-- | services/surfaceflinger/Scheduler/Scheduler.cpp | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp index 65f0e40ffe..27f42d23a3 100644 --- a/services/surfaceflinger/Scheduler/Scheduler.cpp +++ b/services/surfaceflinger/Scheduler/Scheduler.cpp @@ -518,22 +518,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) { |