Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 16 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 17 | // #define LOG_NDEBUG 0 |
| 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 19 | |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 20 | #include "RefreshRateConfigs.h" |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 21 | #include <android-base/stringprintf.h> |
| 22 | #include <utils/Trace.h> |
| 23 | #include <chrono> |
| 24 | #include <cmath> |
| 25 | |
| 26 | using namespace std::chrono_literals; |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 27 | |
| 28 | namespace android::scheduler { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 29 | |
| 30 | using AllRefreshRatesMapType = RefreshRateConfigs::AllRefreshRatesMapType; |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 31 | using RefreshRate = RefreshRateConfigs::RefreshRate; |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 32 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 33 | const RefreshRate& RefreshRateConfigs::getRefreshRateForContent( |
| 34 | const std::vector<LayerRequirement>& layers) const { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 35 | std::lock_guard lock(mLock); |
Ady Abraham | dec1a41 | 2020-01-24 10:23:50 -0800 | [diff] [blame^] | 36 | int contentFramerate = 0; |
| 37 | int explicitContentFramerate = 0; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 38 | for (const auto& layer : layers) { |
Ady Abraham | dec1a41 | 2020-01-24 10:23:50 -0800 | [diff] [blame^] | 39 | const auto desiredRefreshRateRound = round<int>(layer.desiredRefreshRate); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 40 | if (layer.vote == LayerVoteType::Explicit) { |
Ady Abraham | dec1a41 | 2020-01-24 10:23:50 -0800 | [diff] [blame^] | 41 | if (desiredRefreshRateRound > explicitContentFramerate) { |
| 42 | explicitContentFramerate = desiredRefreshRateRound; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 43 | } |
| 44 | } else { |
Ady Abraham | dec1a41 | 2020-01-24 10:23:50 -0800 | [diff] [blame^] | 45 | if (desiredRefreshRateRound > contentFramerate) { |
| 46 | contentFramerate = desiredRefreshRateRound; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
Ady Abraham | dec1a41 | 2020-01-24 10:23:50 -0800 | [diff] [blame^] | 51 | if (explicitContentFramerate != 0) { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 52 | contentFramerate = explicitContentFramerate; |
Ady Abraham | dec1a41 | 2020-01-24 10:23:50 -0800 | [diff] [blame^] | 53 | } else if (contentFramerate == 0) { |
| 54 | contentFramerate = round<int>(mMaxSupportedRefreshRate->fps); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 55 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 56 | ATRACE_INT("ContentFPS", contentFramerate); |
| 57 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 58 | // Find the appropriate refresh rate with minimal error |
| 59 | auto iter = min_element(mAvailableRefreshRates.cbegin(), mAvailableRefreshRates.cend(), |
| 60 | [contentFramerate](const auto& lhs, const auto& rhs) -> bool { |
| 61 | return std::abs(lhs->fps - contentFramerate) < |
| 62 | std::abs(rhs->fps - contentFramerate); |
| 63 | }); |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 64 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 65 | // Some content aligns better on higher refresh rate. For example for 45fps we should choose |
| 66 | // 90Hz config. However we should still prefer a lower refresh rate if the content doesn't |
| 67 | // align well with both |
| 68 | const RefreshRate* bestSoFar = *iter; |
| 69 | constexpr float MARGIN = 0.05f; |
| 70 | float ratio = (*iter)->fps / contentFramerate; |
| 71 | if (std::abs(std::round(ratio) - ratio) > MARGIN) { |
| 72 | while (iter != mAvailableRefreshRates.cend()) { |
| 73 | ratio = (*iter)->fps / contentFramerate; |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 74 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 75 | if (std::abs(std::round(ratio) - ratio) <= MARGIN) { |
| 76 | bestSoFar = *iter; |
| 77 | break; |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 78 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 79 | ++iter; |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 83 | return *bestSoFar; |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 86 | const RefreshRate& RefreshRateConfigs::getRefreshRateForContentV2( |
| 87 | const std::vector<LayerRequirement>& layers) const { |
| 88 | constexpr nsecs_t MARGIN = std::chrono::nanoseconds(800us).count(); |
| 89 | ATRACE_CALL(); |
| 90 | ALOGV("getRefreshRateForContent %zu layers", layers.size()); |
| 91 | |
| 92 | std::lock_guard lock(mLock); |
| 93 | |
| 94 | int noVoteLayers = 0; |
| 95 | int minVoteLayers = 0; |
| 96 | int maxVoteLayers = 0; |
| 97 | int explicitVoteLayers = 0; |
| 98 | for (const auto& layer : layers) { |
| 99 | if (layer.vote == LayerVoteType::NoVote) |
| 100 | noVoteLayers++; |
| 101 | else if (layer.vote == LayerVoteType::Min) |
| 102 | minVoteLayers++; |
| 103 | else if (layer.vote == LayerVoteType::Max) |
| 104 | maxVoteLayers++; |
| 105 | else if (layer.vote == LayerVoteType::Explicit) |
| 106 | explicitVoteLayers++; |
| 107 | } |
| 108 | |
| 109 | // Only if all layers want Min we should return Min |
| 110 | if (noVoteLayers + minVoteLayers == layers.size()) { |
| 111 | return *mAvailableRefreshRates.front(); |
| 112 | } |
| 113 | |
| 114 | // If we have some Max layers and no Explicit we should return Max |
| 115 | if (maxVoteLayers > 0 && explicitVoteLayers == 0) { |
| 116 | return *mAvailableRefreshRates.back(); |
| 117 | } |
| 118 | |
| 119 | // Find the best refresh rate based on score |
| 120 | std::vector<std::pair<const RefreshRate*, float>> scores; |
| 121 | scores.reserve(mAvailableRefreshRates.size()); |
| 122 | |
| 123 | for (const auto refreshRate : mAvailableRefreshRates) { |
| 124 | scores.emplace_back(refreshRate, 0.0f); |
| 125 | } |
| 126 | |
| 127 | for (const auto& layer : layers) { |
| 128 | if (layer.vote == LayerVoteType::NoVote || layer.vote == LayerVoteType::Min || |
| 129 | layer.vote == LayerVoteType::Max) { |
| 130 | continue; |
| 131 | } |
| 132 | |
| 133 | // If we have Explicit layers, ignore the Huristic ones |
| 134 | if (explicitVoteLayers > 0 && layer.vote == LayerVoteType::Heuristic) { |
| 135 | continue; |
| 136 | } |
| 137 | |
| 138 | for (auto& [refreshRate, overallScore] : scores) { |
| 139 | const auto displayPeriod = refreshRate->vsyncPeriod; |
Ady Abraham | dec1a41 | 2020-01-24 10:23:50 -0800 | [diff] [blame^] | 140 | const auto layerPeriod = round<nsecs_t>(1e9f / layer.desiredRefreshRate); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 141 | |
| 142 | // Calculate how many display vsyncs we need to present a single frame for this layer |
| 143 | auto [displayFramesQuot, displayFramesRem] = std::div(layerPeriod, displayPeriod); |
| 144 | if (displayFramesRem <= MARGIN || |
| 145 | std::abs(displayFramesRem - displayPeriod) <= MARGIN) { |
| 146 | displayFramesQuot++; |
| 147 | displayFramesRem = 0; |
| 148 | } |
| 149 | |
| 150 | float layerScore; |
| 151 | if (displayFramesRem == 0) { |
| 152 | // Layer desired refresh rate matches the display rate. |
| 153 | layerScore = layer.weight * 1.0f; |
| 154 | } else if (displayFramesQuot == 0) { |
| 155 | // Layer desired refresh rate is higher the display rate. |
| 156 | layerScore = layer.weight * layerPeriod / displayPeriod; |
| 157 | } else { |
| 158 | // Layer desired refresh rate is lower the display rate. Check how well it fits the |
| 159 | // cadence |
| 160 | auto diff = std::abs(displayFramesRem - (displayPeriod - displayFramesRem)); |
| 161 | int iter = 2; |
| 162 | static constexpr size_t MAX_ITERATOR = 10; // Stop calculating when score < 0.1 |
| 163 | while (diff > MARGIN && iter < MAX_ITERATOR) { |
| 164 | diff = diff - (displayPeriod - diff); |
| 165 | iter++; |
| 166 | } |
| 167 | |
| 168 | layerScore = layer.weight * 1.0f / iter; |
| 169 | } |
| 170 | |
| 171 | ALOGV("%s (weight %.2f) %.2fHz gives %s score of %.2f", layer.name.c_str(), |
| 172 | layer.weight, 1e9f / layerPeriod, refreshRate->name.c_str(), layerScore); |
| 173 | overallScore += layerScore; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | float max = 0; |
| 178 | const RefreshRate* bestRefreshRate = nullptr; |
| 179 | for (const auto [refreshRate, score] : scores) { |
| 180 | ALOGV("%s scores %.2f", refreshRate->name.c_str(), score); |
| 181 | |
Ady Abraham | dec1a41 | 2020-01-24 10:23:50 -0800 | [diff] [blame^] | 182 | ATRACE_INT(refreshRate->name.c_str(), round<int>(score * 100)); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 183 | |
| 184 | if (score > max) { |
| 185 | max = score; |
| 186 | bestRefreshRate = refreshRate; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | return bestRefreshRate == nullptr ? *mCurrentRefreshRate : *bestRefreshRate; |
| 191 | } |
| 192 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 193 | const AllRefreshRatesMapType& RefreshRateConfigs::getAllRefreshRates() const { |
| 194 | return mRefreshRates; |
| 195 | } |
| 196 | |
| 197 | const RefreshRate& RefreshRateConfigs::getMinRefreshRateByPolicy() const { |
| 198 | std::lock_guard lock(mLock); |
| 199 | if (!mRefreshRateSwitching) { |
| 200 | return *mCurrentRefreshRate; |
| 201 | } else { |
| 202 | return *mAvailableRefreshRates.front(); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | const RefreshRate& RefreshRateConfigs::getMaxRefreshRateByPolicy() const { |
| 207 | std::lock_guard lock(mLock); |
| 208 | if (!mRefreshRateSwitching) { |
| 209 | return *mCurrentRefreshRate; |
| 210 | } else { |
| 211 | return *mAvailableRefreshRates.back(); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | const RefreshRate& RefreshRateConfigs::getCurrentRefreshRate() const { |
| 216 | std::lock_guard lock(mLock); |
| 217 | return *mCurrentRefreshRate; |
| 218 | } |
| 219 | |
| 220 | void RefreshRateConfigs::setCurrentConfigId(HwcConfigIndexType configId) { |
| 221 | std::lock_guard lock(mLock); |
| 222 | mCurrentRefreshRate = &mRefreshRates.at(configId); |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | RefreshRateConfigs::RefreshRateConfigs(bool refreshRateSwitching, |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 226 | const std::vector<InputConfig>& configs, |
| 227 | HwcConfigIndexType currentHwcConfig) |
| 228 | : mRefreshRateSwitching(refreshRateSwitching) { |
| 229 | init(configs, currentHwcConfig); |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | RefreshRateConfigs::RefreshRateConfigs( |
| 233 | bool refreshRateSwitching, |
| 234 | const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs, |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 235 | HwcConfigIndexType currentConfigId) |
| 236 | : mRefreshRateSwitching(refreshRateSwitching) { |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 237 | std::vector<InputConfig> inputConfigs; |
Ady Abraham | dec1a41 | 2020-01-24 10:23:50 -0800 | [diff] [blame^] | 238 | for (size_t configId = 0; configId < configs.size(); ++configId) { |
| 239 | auto configGroup = HwcConfigGroupType(configs[configId]->getConfigGroup()); |
| 240 | inputConfigs.push_back({HwcConfigIndexType(static_cast<int>(configId)), configGroup, |
| 241 | configs[configId]->getVsyncPeriod()}); |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 242 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 243 | init(inputConfigs, currentConfigId); |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 246 | status_t RefreshRateConfigs::setPolicy(HwcConfigIndexType defaultConfigId, float minRefreshRate, |
| 247 | float maxRefreshRate, bool* outPolicyChanged) { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 248 | std::lock_guard lock(mLock); |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 249 | bool policyChanged = defaultConfigId != mDefaultConfig || |
| 250 | minRefreshRate != mMinRefreshRateFps || maxRefreshRate != mMaxRefreshRateFps; |
| 251 | if (outPolicyChanged) { |
| 252 | *outPolicyChanged = policyChanged; |
| 253 | } |
| 254 | if (!policyChanged) { |
| 255 | return NO_ERROR; |
| 256 | } |
| 257 | // defaultConfigId must be a valid config ID, and within the given refresh rate range. |
| 258 | if (mRefreshRates.count(defaultConfigId) == 0) { |
| 259 | return BAD_VALUE; |
| 260 | } |
| 261 | const RefreshRate& refreshRate = mRefreshRates.at(defaultConfigId); |
Ana Krulec | 72f0d6e | 2020-01-06 15:24:47 -0800 | [diff] [blame] | 262 | if (!refreshRate.inPolicy(minRefreshRate, maxRefreshRate)) { |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 263 | return BAD_VALUE; |
| 264 | } |
| 265 | mDefaultConfig = defaultConfigId; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 266 | mMinRefreshRateFps = minRefreshRate; |
| 267 | mMaxRefreshRateFps = maxRefreshRate; |
| 268 | constructAvailableRefreshRates(); |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 269 | return NO_ERROR; |
| 270 | } |
| 271 | |
| 272 | void RefreshRateConfigs::getPolicy(HwcConfigIndexType* defaultConfigId, float* minRefreshRate, |
| 273 | float* maxRefreshRate) const { |
| 274 | std::lock_guard lock(mLock); |
| 275 | *defaultConfigId = mDefaultConfig; |
| 276 | *minRefreshRate = mMinRefreshRateFps; |
| 277 | *maxRefreshRate = mMaxRefreshRateFps; |
| 278 | } |
| 279 | |
| 280 | bool RefreshRateConfigs::isConfigAllowed(HwcConfigIndexType config) const { |
| 281 | std::lock_guard lock(mLock); |
| 282 | for (const RefreshRate* refreshRate : mAvailableRefreshRates) { |
| 283 | if (refreshRate->configId == config) { |
| 284 | return true; |
| 285 | } |
| 286 | } |
| 287 | return false; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | void RefreshRateConfigs::getSortedRefreshRateList( |
| 291 | const std::function<bool(const RefreshRate&)>& shouldAddRefreshRate, |
| 292 | std::vector<const RefreshRate*>* outRefreshRates) { |
| 293 | outRefreshRates->clear(); |
| 294 | outRefreshRates->reserve(mRefreshRates.size()); |
| 295 | for (const auto& [type, refreshRate] : mRefreshRates) { |
| 296 | if (shouldAddRefreshRate(refreshRate)) { |
| 297 | ALOGV("getSortedRefreshRateList: config %d added to list policy", |
| 298 | refreshRate.configId.value()); |
| 299 | outRefreshRates->push_back(&refreshRate); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | std::sort(outRefreshRates->begin(), outRefreshRates->end(), |
| 304 | [](const auto refreshRate1, const auto refreshRate2) { |
| 305 | return refreshRate1->vsyncPeriod > refreshRate2->vsyncPeriod; |
| 306 | }); |
| 307 | } |
| 308 | |
| 309 | void RefreshRateConfigs::constructAvailableRefreshRates() { |
| 310 | // Filter configs based on current policy and sort based on vsync period |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 311 | HwcConfigGroupType group = mRefreshRates.at(mDefaultConfig).configGroup; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 312 | ALOGV("constructAvailableRefreshRates: default %d group %d min %.2f max %.2f", |
| 313 | mDefaultConfig.value(), group.value(), mMinRefreshRateFps, mMaxRefreshRateFps); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 314 | getSortedRefreshRateList( |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 315 | [&](const RefreshRate& refreshRate) REQUIRES(mLock) { |
Ana Krulec | 72f0d6e | 2020-01-06 15:24:47 -0800 | [diff] [blame] | 316 | return refreshRate.configGroup == group && |
| 317 | refreshRate.inPolicy(mMinRefreshRateFps, mMaxRefreshRateFps); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 318 | }, |
| 319 | &mAvailableRefreshRates); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 320 | |
| 321 | std::string availableRefreshRates; |
| 322 | for (const auto& refreshRate : mAvailableRefreshRates) { |
| 323 | base::StringAppendF(&availableRefreshRates, "%s ", refreshRate->name.c_str()); |
| 324 | } |
| 325 | |
| 326 | ALOGV("Available refresh rates: %s", availableRefreshRates.c_str()); |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 327 | LOG_ALWAYS_FATAL_IF(mAvailableRefreshRates.empty(), |
| 328 | "No compatible display configs for default=%d min=%.0f max=%.0f", |
| 329 | mDefaultConfig.value(), mMinRefreshRateFps, mMaxRefreshRateFps); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // NO_THREAD_SAFETY_ANALYSIS since this is called from the constructor |
| 333 | void RefreshRateConfigs::init(const std::vector<InputConfig>& configs, |
| 334 | HwcConfigIndexType currentHwcConfig) NO_THREAD_SAFETY_ANALYSIS { |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 335 | LOG_ALWAYS_FATAL_IF(configs.empty()); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 336 | LOG_ALWAYS_FATAL_IF(currentHwcConfig.value() >= configs.size()); |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 337 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 338 | auto buildRefreshRate = [&](InputConfig config) -> RefreshRate { |
| 339 | const float fps = 1e9f / config.vsyncPeriod; |
| 340 | return RefreshRate(config.configId, config.vsyncPeriod, config.configGroup, |
| 341 | base::StringPrintf("%2.ffps", fps), fps); |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 342 | }; |
| 343 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 344 | for (const auto& config : configs) { |
| 345 | mRefreshRates.emplace(config.configId, buildRefreshRate(config)); |
| 346 | if (config.configId == currentHwcConfig) { |
| 347 | mCurrentRefreshRate = &mRefreshRates.at(config.configId); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 348 | } |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 349 | } |
| 350 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 351 | std::vector<const RefreshRate*> sortedConfigs; |
| 352 | getSortedRefreshRateList([](const RefreshRate&) { return true; }, &sortedConfigs); |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 353 | mDefaultConfig = currentHwcConfig; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 354 | mMinSupportedRefreshRate = sortedConfigs.front(); |
| 355 | mMaxSupportedRefreshRate = sortedConfigs.back(); |
| 356 | constructAvailableRefreshRates(); |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 359 | } // namespace android::scheduler |