summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Thierry Strudel <tstrudel@google.com> 2019-07-03 19:14:47 -0700
committer android-build-merger <android-build-merger@google.com> 2019-07-03 19:14:47 -0700
commit3f4989a062c7ad4bfa7b76e0720995998ba46c89 (patch)
tree2705ef09bdd8b1566c5d8698327b80b5ccb8f5dc
parentde39187634f2e11f3dbf01110feb43466ffb2c1f (diff)
parent9275c965d8effb03e8ccbfd16eb92f16ff6d083c (diff)
Merge "Surfaceflinger: adjust content detection fps selection" into qt-r1-dev
am: 9275c965d8 Change-Id: If337fd17b70a2608b174c373719fb069050e2ab5
-rw-r--r--services/surfaceflinger/Scheduler/Scheduler.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index 99d6faee1c..cfdbd91e35 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -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) {