blob: b876ccdc7ed0a6b28df5eb0287375eac58ee29b0 [file] [log] [blame]
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -08001/*
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 Abraham2139f732019-11-13 18:56:40 -080016
Ady Abraham8a82ba62020-01-17 12:43:17 -080017// #define LOG_NDEBUG 0
18#define ATRACE_TAG ATRACE_TAG_GRAPHICS
19
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080020#include "RefreshRateConfigs.h"
Ady Abraham8a82ba62020-01-17 12:43:17 -080021#include <android-base/stringprintf.h>
22#include <utils/Trace.h>
23#include <chrono>
24#include <cmath>
25
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080026namespace android::scheduler {
Ady Abraham2139f732019-11-13 18:56:40 -080027
28using AllRefreshRatesMapType = RefreshRateConfigs::AllRefreshRatesMapType;
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080029using RefreshRate = RefreshRateConfigs::RefreshRate;
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080030
Ady Abraham8a82ba62020-01-17 12:43:17 -080031const RefreshRate& RefreshRateConfigs::getRefreshRateForContent(
32 const std::vector<LayerRequirement>& layers) const {
Ady Abraham2139f732019-11-13 18:56:40 -080033 std::lock_guard lock(mLock);
Ady Abrahamdec1a412020-01-24 10:23:50 -080034 int contentFramerate = 0;
35 int explicitContentFramerate = 0;
Ady Abraham8a82ba62020-01-17 12:43:17 -080036 for (const auto& layer : layers) {
Ady Abrahamdec1a412020-01-24 10:23:50 -080037 const auto desiredRefreshRateRound = round<int>(layer.desiredRefreshRate);
Ady Abraham71c437d2020-01-31 15:56:57 -080038 if (layer.vote == LayerVoteType::ExplicitDefault ||
39 layer.vote == LayerVoteType::ExplicitExactOrMultiple) {
Ady Abrahamdec1a412020-01-24 10:23:50 -080040 if (desiredRefreshRateRound > explicitContentFramerate) {
41 explicitContentFramerate = desiredRefreshRateRound;
Ady Abraham8a82ba62020-01-17 12:43:17 -080042 }
43 } else {
Ady Abrahamdec1a412020-01-24 10:23:50 -080044 if (desiredRefreshRateRound > contentFramerate) {
45 contentFramerate = desiredRefreshRateRound;
Ady Abraham8a82ba62020-01-17 12:43:17 -080046 }
47 }
48 }
49
Ady Abrahamdec1a412020-01-24 10:23:50 -080050 if (explicitContentFramerate != 0) {
Ady Abraham8a82ba62020-01-17 12:43:17 -080051 contentFramerate = explicitContentFramerate;
Ady Abrahamdec1a412020-01-24 10:23:50 -080052 } else if (contentFramerate == 0) {
53 contentFramerate = round<int>(mMaxSupportedRefreshRate->fps);
Ady Abraham8a82ba62020-01-17 12:43:17 -080054 }
Ady Abraham8a82ba62020-01-17 12:43:17 -080055 ATRACE_INT("ContentFPS", contentFramerate);
56
Ady Abraham2139f732019-11-13 18:56:40 -080057 // Find the appropriate refresh rate with minimal error
58 auto iter = min_element(mAvailableRefreshRates.cbegin(), mAvailableRefreshRates.cend(),
59 [contentFramerate](const auto& lhs, const auto& rhs) -> bool {
60 return std::abs(lhs->fps - contentFramerate) <
61 std::abs(rhs->fps - contentFramerate);
62 });
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080063
Ady Abraham2139f732019-11-13 18:56:40 -080064 // Some content aligns better on higher refresh rate. For example for 45fps we should choose
65 // 90Hz config. However we should still prefer a lower refresh rate if the content doesn't
66 // align well with both
67 const RefreshRate* bestSoFar = *iter;
68 constexpr float MARGIN = 0.05f;
69 float ratio = (*iter)->fps / contentFramerate;
70 if (std::abs(std::round(ratio) - ratio) > MARGIN) {
71 while (iter != mAvailableRefreshRates.cend()) {
72 ratio = (*iter)->fps / contentFramerate;
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080073
Ady Abraham2139f732019-11-13 18:56:40 -080074 if (std::abs(std::round(ratio) - ratio) <= MARGIN) {
75 bestSoFar = *iter;
76 break;
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080077 }
Ady Abraham2139f732019-11-13 18:56:40 -080078 ++iter;
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080079 }
80 }
81
Ady Abraham2139f732019-11-13 18:56:40 -080082 return *bestSoFar;
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080083}
84
Ady Abraham4ccdcb42020-02-11 17:34:34 -080085std::pair<nsecs_t, nsecs_t> RefreshRateConfigs::getDisplayFrames(nsecs_t layerPeriod,
86 nsecs_t displayPeriod) const {
87 auto [displayFramesQuot, displayFramesRem] = std::div(layerPeriod, displayPeriod);
88 if (displayFramesRem <= MARGIN_FOR_PERIOD_CALCULATION ||
89 std::abs(displayFramesRem - displayPeriod) <= MARGIN_FOR_PERIOD_CALCULATION) {
90 displayFramesQuot++;
91 displayFramesRem = 0;
92 }
93
94 return {displayFramesQuot, displayFramesRem};
95}
96
Ady Abraham8a82ba62020-01-17 12:43:17 -080097const RefreshRate& RefreshRateConfigs::getRefreshRateForContentV2(
Ady Abraham4ccdcb42020-02-11 17:34:34 -080098 const std::vector<LayerRequirement>& layers, bool touchActive) const {
Ady Abraham8a82ba62020-01-17 12:43:17 -080099 ATRACE_CALL();
100 ALOGV("getRefreshRateForContent %zu layers", layers.size());
101
102 std::lock_guard lock(mLock);
103
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800104 // For now if the touch is active return the peak refresh rate
105 // This should be optimized to consider other layers as well.
106 if (touchActive) {
107 return *mAvailableRefreshRates.back();
108 }
109
Ady Abraham8a82ba62020-01-17 12:43:17 -0800110 int noVoteLayers = 0;
111 int minVoteLayers = 0;
112 int maxVoteLayers = 0;
Ady Abraham71c437d2020-01-31 15:56:57 -0800113 int explicitDefaultVoteLayers = 0;
114 int explicitExactOrMultipleVoteLayers = 0;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800115 for (const auto& layer : layers) {
116 if (layer.vote == LayerVoteType::NoVote)
117 noVoteLayers++;
118 else if (layer.vote == LayerVoteType::Min)
119 minVoteLayers++;
120 else if (layer.vote == LayerVoteType::Max)
121 maxVoteLayers++;
Ady Abraham71c437d2020-01-31 15:56:57 -0800122 else if (layer.vote == LayerVoteType::ExplicitDefault)
123 explicitDefaultVoteLayers++;
124 else if (layer.vote == LayerVoteType::ExplicitExactOrMultiple)
125 explicitExactOrMultipleVoteLayers++;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800126 }
127
128 // Only if all layers want Min we should return Min
129 if (noVoteLayers + minVoteLayers == layers.size()) {
130 return *mAvailableRefreshRates.front();
131 }
132
Ady Abraham8a82ba62020-01-17 12:43:17 -0800133 // Find the best refresh rate based on score
134 std::vector<std::pair<const RefreshRate*, float>> scores;
135 scores.reserve(mAvailableRefreshRates.size());
136
137 for (const auto refreshRate : mAvailableRefreshRates) {
138 scores.emplace_back(refreshRate, 0.0f);
139 }
140
141 for (const auto& layer : layers) {
Ady Abrahamf6b77072020-01-30 14:22:54 -0800142 ALOGV("Calculating score for %s (type: %d)", layer.name.c_str(), layer.vote);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800143 if (layer.vote == LayerVoteType::NoVote || layer.vote == LayerVoteType::Min) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800144 continue;
145 }
146
Ady Abraham71c437d2020-01-31 15:56:57 -0800147 auto weight = layer.weight;
Ady Abraham71c437d2020-01-31 15:56:57 -0800148
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800149 for (auto i = 0u; i < scores.size(); i++) {
150 // If the layer wants Max, give higher score to the higher refresh rate
151 if (layer.vote == LayerVoteType::Max) {
152 const auto ratio = scores[i].first->fps / scores.back().first->fps;
153 // use ratio^2 to get a lower score the more we get further from peak
154 const auto layerScore = ratio * ratio;
155 ALOGV("%s (Max, weight %.2f) gives %s score of %.2f", layer.name.c_str(), weight,
156 scores[i].first->name.c_str(), layerScore);
157 scores[i].second += weight * layerScore;
158 continue;
Ady Abraham71c437d2020-01-31 15:56:57 -0800159 }
Ady Abraham8a82ba62020-01-17 12:43:17 -0800160
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800161 const auto displayPeriod = scores[i].first->vsyncPeriod;
Ady Abrahamdec1a412020-01-24 10:23:50 -0800162 const auto layerPeriod = round<nsecs_t>(1e9f / layer.desiredRefreshRate);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800163 if (layer.vote == LayerVoteType::ExplicitDefault) {
164 const auto layerScore = [&]() {
165 const auto [displayFramesQuot, displayFramesRem] =
166 getDisplayFrames(layerPeriod, displayPeriod);
167 if (displayFramesQuot == 0) {
168 // Layer desired refresh rate is higher the display rate.
169 return static_cast<float>(layerPeriod) / static_cast<float>(displayPeriod);
170 }
Ady Abraham8a82ba62020-01-17 12:43:17 -0800171
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800172 return 1.0f -
173 (static_cast<float>(displayFramesRem) /
174 static_cast<float>(layerPeriod));
175 }();
176
177 ALOGV("%s (ExplicitDefault, weight %.2f) %.2fHz gives %s score of %.2f",
178 layer.name.c_str(), weight, 1e9f / layerPeriod, scores[i].first->name.c_str(),
179 layerScore);
180 scores[i].second += weight * layerScore;
181 continue;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800182 }
183
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800184 if (layer.vote == LayerVoteType::ExplicitExactOrMultiple ||
185 layer.vote == LayerVoteType::Heuristic) {
186 const auto layerScore = [&]() {
187 // Calculate how many display vsyncs we need to present a single frame for this
188 // layer
189 const auto [displayFramesQuot, displayFramesRem] =
190 getDisplayFrames(layerPeriod, displayPeriod);
191 static constexpr size_t MAX_FRAMES_TO_FIT =
192 10; // Stop calculating when score < 0.1
193 if (displayFramesRem == 0) {
194 // Layer desired refresh rate matches the display rate.
195 return 1.0f;
196 }
Ady Abraham8a82ba62020-01-17 12:43:17 -0800197
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800198 if (displayFramesQuot == 0) {
199 // Layer desired refresh rate is higher the display rate.
200 return (static_cast<float>(layerPeriod) /
201 static_cast<float>(displayPeriod)) *
202 (1.0f / (MAX_FRAMES_TO_FIT + 1));
203 }
204
205 // Layer desired refresh rate is lower the display rate. Check how well it fits
206 // the cadence
207 auto diff = std::abs(displayFramesRem - (displayPeriod - displayFramesRem));
208 int iter = 2;
209 while (diff > MARGIN_FOR_PERIOD_CALCULATION && iter < MAX_FRAMES_TO_FIT) {
210 diff = diff - (displayPeriod - diff);
211 iter++;
212 }
213
214 return 1.0f / iter;
215 }();
216 ALOGV("%s (ExplicitExactOrMultiple, weight %.2f) %.2fHz gives %s score of %.2f",
217 layer.name.c_str(), weight, 1e9f / layerPeriod, scores[i].first->name.c_str(),
218 layerScore);
219 scores[i].second += weight * layerScore;
220 continue;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800221 }
Ady Abraham8a82ba62020-01-17 12:43:17 -0800222 }
223 }
224
Ady Abraham34702102020-02-10 14:12:05 -0800225 // Now that we scored all the refresh rates we need to pick the one that got the highest score.
226 // In case of a tie we will pick the higher refresh rate if any of the layers wanted Max,
227 // or the lower otherwise.
228 const RefreshRate* bestRefreshRate = maxVoteLayers > 0
229 ? getBestRefreshRate(scores.rbegin(), scores.rend())
230 : getBestRefreshRate(scores.begin(), scores.end());
231
232 return bestRefreshRate == nullptr ? *mCurrentRefreshRate : *bestRefreshRate;
233}
234
235template <typename Iter>
236const RefreshRate* RefreshRateConfigs::getBestRefreshRate(Iter begin, Iter end) const {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800237 const RefreshRate* bestRefreshRate = nullptr;
Ady Abraham34702102020-02-10 14:12:05 -0800238 float max = 0;
239 for (auto i = begin; i != end; ++i) {
240 const auto [refreshRate, score] = *i;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800241 ALOGV("%s scores %.2f", refreshRate->name.c_str(), score);
242
Ady Abrahamdec1a412020-01-24 10:23:50 -0800243 ATRACE_INT(refreshRate->name.c_str(), round<int>(score * 100));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800244
245 if (score > max) {
246 max = score;
247 bestRefreshRate = refreshRate;
248 }
249 }
250
Ady Abraham34702102020-02-10 14:12:05 -0800251 return bestRefreshRate;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800252}
253
Ady Abraham2139f732019-11-13 18:56:40 -0800254const AllRefreshRatesMapType& RefreshRateConfigs::getAllRefreshRates() const {
255 return mRefreshRates;
256}
257
258const RefreshRate& RefreshRateConfigs::getMinRefreshRateByPolicy() const {
259 std::lock_guard lock(mLock);
Ana Krulec3f6a2062020-01-23 15:48:01 -0800260 return *mAvailableRefreshRates.front();
Ady Abraham2139f732019-11-13 18:56:40 -0800261}
262
263const RefreshRate& RefreshRateConfigs::getMaxRefreshRateByPolicy() const {
264 std::lock_guard lock(mLock);
Ady Abraham2139f732019-11-13 18:56:40 -0800265 return *mAvailableRefreshRates.back();
Ady Abraham2139f732019-11-13 18:56:40 -0800266}
267
268const RefreshRate& RefreshRateConfigs::getCurrentRefreshRate() const {
269 std::lock_guard lock(mLock);
270 return *mCurrentRefreshRate;
271}
272
Ana Krulec5d477912020-02-07 12:02:38 -0800273const RefreshRate& RefreshRateConfigs::getCurrentRefreshRateByPolicy() const {
274 std::lock_guard lock(mLock);
275 if (std::find(mAvailableRefreshRates.begin(), mAvailableRefreshRates.end(),
276 mCurrentRefreshRate) != mAvailableRefreshRates.end()) {
277 return *mCurrentRefreshRate;
278 }
279 return mRefreshRates.at(mDefaultConfig);
280}
281
Ady Abraham2139f732019-11-13 18:56:40 -0800282void RefreshRateConfigs::setCurrentConfigId(HwcConfigIndexType configId) {
283 std::lock_guard lock(mLock);
284 mCurrentRefreshRate = &mRefreshRates.at(configId);
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800285}
286
Ana Krulec3f6a2062020-01-23 15:48:01 -0800287RefreshRateConfigs::RefreshRateConfigs(const std::vector<InputConfig>& configs,
288 HwcConfigIndexType currentHwcConfig) {
Ady Abraham2139f732019-11-13 18:56:40 -0800289 init(configs, currentHwcConfig);
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800290}
291
292RefreshRateConfigs::RefreshRateConfigs(
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800293 const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
Ana Krulec3f6a2062020-01-23 15:48:01 -0800294 HwcConfigIndexType currentConfigId) {
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800295 std::vector<InputConfig> inputConfigs;
Ady Abrahamdec1a412020-01-24 10:23:50 -0800296 for (size_t configId = 0; configId < configs.size(); ++configId) {
297 auto configGroup = HwcConfigGroupType(configs[configId]->getConfigGroup());
298 inputConfigs.push_back({HwcConfigIndexType(static_cast<int>(configId)), configGroup,
299 configs[configId]->getVsyncPeriod()});
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800300 }
Ady Abraham2139f732019-11-13 18:56:40 -0800301 init(inputConfigs, currentConfigId);
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800302}
303
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100304status_t RefreshRateConfigs::setPolicy(HwcConfigIndexType defaultConfigId, float minRefreshRate,
305 float maxRefreshRate, bool* outPolicyChanged) {
Ady Abraham2139f732019-11-13 18:56:40 -0800306 std::lock_guard lock(mLock);
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100307 bool policyChanged = defaultConfigId != mDefaultConfig ||
308 minRefreshRate != mMinRefreshRateFps || maxRefreshRate != mMaxRefreshRateFps;
309 if (outPolicyChanged) {
310 *outPolicyChanged = policyChanged;
311 }
312 if (!policyChanged) {
313 return NO_ERROR;
314 }
315 // defaultConfigId must be a valid config ID, and within the given refresh rate range.
316 if (mRefreshRates.count(defaultConfigId) == 0) {
317 return BAD_VALUE;
318 }
319 const RefreshRate& refreshRate = mRefreshRates.at(defaultConfigId);
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800320 if (!refreshRate.inPolicy(minRefreshRate, maxRefreshRate)) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100321 return BAD_VALUE;
322 }
323 mDefaultConfig = defaultConfigId;
Ady Abraham2139f732019-11-13 18:56:40 -0800324 mMinRefreshRateFps = minRefreshRate;
325 mMaxRefreshRateFps = maxRefreshRate;
326 constructAvailableRefreshRates();
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100327 return NO_ERROR;
328}
329
330void RefreshRateConfigs::getPolicy(HwcConfigIndexType* defaultConfigId, float* minRefreshRate,
331 float* maxRefreshRate) const {
332 std::lock_guard lock(mLock);
333 *defaultConfigId = mDefaultConfig;
334 *minRefreshRate = mMinRefreshRateFps;
335 *maxRefreshRate = mMaxRefreshRateFps;
336}
337
338bool RefreshRateConfigs::isConfigAllowed(HwcConfigIndexType config) const {
339 std::lock_guard lock(mLock);
340 for (const RefreshRate* refreshRate : mAvailableRefreshRates) {
341 if (refreshRate->configId == config) {
342 return true;
343 }
344 }
345 return false;
Ady Abraham2139f732019-11-13 18:56:40 -0800346}
347
348void RefreshRateConfigs::getSortedRefreshRateList(
349 const std::function<bool(const RefreshRate&)>& shouldAddRefreshRate,
350 std::vector<const RefreshRate*>* outRefreshRates) {
351 outRefreshRates->clear();
352 outRefreshRates->reserve(mRefreshRates.size());
353 for (const auto& [type, refreshRate] : mRefreshRates) {
354 if (shouldAddRefreshRate(refreshRate)) {
355 ALOGV("getSortedRefreshRateList: config %d added to list policy",
356 refreshRate.configId.value());
357 outRefreshRates->push_back(&refreshRate);
358 }
359 }
360
361 std::sort(outRefreshRates->begin(), outRefreshRates->end(),
362 [](const auto refreshRate1, const auto refreshRate2) {
363 return refreshRate1->vsyncPeriod > refreshRate2->vsyncPeriod;
364 });
365}
366
367void RefreshRateConfigs::constructAvailableRefreshRates() {
368 // Filter configs based on current policy and sort based on vsync period
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100369 HwcConfigGroupType group = mRefreshRates.at(mDefaultConfig).configGroup;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800370 ALOGV("constructAvailableRefreshRates: default %d group %d min %.2f max %.2f",
371 mDefaultConfig.value(), group.value(), mMinRefreshRateFps, mMaxRefreshRateFps);
Ady Abraham2139f732019-11-13 18:56:40 -0800372 getSortedRefreshRateList(
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100373 [&](const RefreshRate& refreshRate) REQUIRES(mLock) {
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800374 return refreshRate.configGroup == group &&
375 refreshRate.inPolicy(mMinRefreshRateFps, mMaxRefreshRateFps);
Ady Abraham2139f732019-11-13 18:56:40 -0800376 },
377 &mAvailableRefreshRates);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800378
379 std::string availableRefreshRates;
380 for (const auto& refreshRate : mAvailableRefreshRates) {
381 base::StringAppendF(&availableRefreshRates, "%s ", refreshRate->name.c_str());
382 }
383
384 ALOGV("Available refresh rates: %s", availableRefreshRates.c_str());
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100385 LOG_ALWAYS_FATAL_IF(mAvailableRefreshRates.empty(),
386 "No compatible display configs for default=%d min=%.0f max=%.0f",
387 mDefaultConfig.value(), mMinRefreshRateFps, mMaxRefreshRateFps);
Ady Abraham2139f732019-11-13 18:56:40 -0800388}
389
390// NO_THREAD_SAFETY_ANALYSIS since this is called from the constructor
391void RefreshRateConfigs::init(const std::vector<InputConfig>& configs,
392 HwcConfigIndexType currentHwcConfig) NO_THREAD_SAFETY_ANALYSIS {
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800393 LOG_ALWAYS_FATAL_IF(configs.empty());
Ady Abraham2139f732019-11-13 18:56:40 -0800394 LOG_ALWAYS_FATAL_IF(currentHwcConfig.value() >= configs.size());
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800395
Ady Abraham2139f732019-11-13 18:56:40 -0800396 auto buildRefreshRate = [&](InputConfig config) -> RefreshRate {
397 const float fps = 1e9f / config.vsyncPeriod;
398 return RefreshRate(config.configId, config.vsyncPeriod, config.configGroup,
399 base::StringPrintf("%2.ffps", fps), fps);
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800400 };
401
Ady Abraham2139f732019-11-13 18:56:40 -0800402 for (const auto& config : configs) {
403 mRefreshRates.emplace(config.configId, buildRefreshRate(config));
404 if (config.configId == currentHwcConfig) {
405 mCurrentRefreshRate = &mRefreshRates.at(config.configId);
Ady Abraham2139f732019-11-13 18:56:40 -0800406 }
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800407 }
408
Ady Abraham2139f732019-11-13 18:56:40 -0800409 std::vector<const RefreshRate*> sortedConfigs;
410 getSortedRefreshRateList([](const RefreshRate&) { return true; }, &sortedConfigs);
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100411 mDefaultConfig = currentHwcConfig;
Ady Abraham2139f732019-11-13 18:56:40 -0800412 mMinSupportedRefreshRate = sortedConfigs.front();
413 mMaxSupportedRefreshRate = sortedConfigs.back();
414 constructAvailableRefreshRates();
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800415}
416
Ady Abraham2139f732019-11-13 18:56:40 -0800417} // namespace android::scheduler