blob: 1765d2d8f7f77f6f5d3b6f86dbeaafa13d65e0b2 [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
Ana Krulec3d367c82020-02-25 15:02:01 -0800110 // If there are not layers, there is not content detection, so return the current
111 // refresh rate.
112 if (layers.empty()) {
113 return getCurrentRefreshRateByPolicyLocked();
114 }
115
Ady Abraham8a82ba62020-01-17 12:43:17 -0800116 int noVoteLayers = 0;
117 int minVoteLayers = 0;
118 int maxVoteLayers = 0;
Ady Abraham71c437d2020-01-31 15:56:57 -0800119 int explicitDefaultVoteLayers = 0;
120 int explicitExactOrMultipleVoteLayers = 0;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800121 for (const auto& layer : layers) {
122 if (layer.vote == LayerVoteType::NoVote)
123 noVoteLayers++;
124 else if (layer.vote == LayerVoteType::Min)
125 minVoteLayers++;
126 else if (layer.vote == LayerVoteType::Max)
127 maxVoteLayers++;
Ady Abraham71c437d2020-01-31 15:56:57 -0800128 else if (layer.vote == LayerVoteType::ExplicitDefault)
129 explicitDefaultVoteLayers++;
130 else if (layer.vote == LayerVoteType::ExplicitExactOrMultiple)
131 explicitExactOrMultipleVoteLayers++;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800132 }
133
134 // Only if all layers want Min we should return Min
135 if (noVoteLayers + minVoteLayers == layers.size()) {
136 return *mAvailableRefreshRates.front();
137 }
138
Ady Abraham8a82ba62020-01-17 12:43:17 -0800139 // Find the best refresh rate based on score
140 std::vector<std::pair<const RefreshRate*, float>> scores;
141 scores.reserve(mAvailableRefreshRates.size());
142
143 for (const auto refreshRate : mAvailableRefreshRates) {
144 scores.emplace_back(refreshRate, 0.0f);
145 }
146
147 for (const auto& layer : layers) {
Ady Abrahamf6b77072020-01-30 14:22:54 -0800148 ALOGV("Calculating score for %s (type: %d)", layer.name.c_str(), layer.vote);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800149 if (layer.vote == LayerVoteType::NoVote || layer.vote == LayerVoteType::Min) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800150 continue;
151 }
152
Ady Abraham71c437d2020-01-31 15:56:57 -0800153 auto weight = layer.weight;
Ady Abraham71c437d2020-01-31 15:56:57 -0800154
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800155 for (auto i = 0u; i < scores.size(); i++) {
156 // If the layer wants Max, give higher score to the higher refresh rate
157 if (layer.vote == LayerVoteType::Max) {
158 const auto ratio = scores[i].first->fps / scores.back().first->fps;
159 // use ratio^2 to get a lower score the more we get further from peak
160 const auto layerScore = ratio * ratio;
161 ALOGV("%s (Max, weight %.2f) gives %s score of %.2f", layer.name.c_str(), weight,
162 scores[i].first->name.c_str(), layerScore);
163 scores[i].second += weight * layerScore;
164 continue;
Ady Abraham71c437d2020-01-31 15:56:57 -0800165 }
Ady Abraham8a82ba62020-01-17 12:43:17 -0800166
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800167 const auto displayPeriod = scores[i].first->vsyncPeriod;
Ady Abrahamdec1a412020-01-24 10:23:50 -0800168 const auto layerPeriod = round<nsecs_t>(1e9f / layer.desiredRefreshRate);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800169 if (layer.vote == LayerVoteType::ExplicitDefault) {
170 const auto layerScore = [&]() {
171 const auto [displayFramesQuot, displayFramesRem] =
172 getDisplayFrames(layerPeriod, displayPeriod);
173 if (displayFramesQuot == 0) {
174 // Layer desired refresh rate is higher the display rate.
175 return static_cast<float>(layerPeriod) / static_cast<float>(displayPeriod);
176 }
Ady Abraham8a82ba62020-01-17 12:43:17 -0800177
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800178 return 1.0f -
179 (static_cast<float>(displayFramesRem) /
180 static_cast<float>(layerPeriod));
181 }();
182
183 ALOGV("%s (ExplicitDefault, weight %.2f) %.2fHz gives %s score of %.2f",
184 layer.name.c_str(), weight, 1e9f / layerPeriod, scores[i].first->name.c_str(),
185 layerScore);
186 scores[i].second += weight * layerScore;
187 continue;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800188 }
189
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800190 if (layer.vote == LayerVoteType::ExplicitExactOrMultiple ||
191 layer.vote == LayerVoteType::Heuristic) {
192 const auto layerScore = [&]() {
193 // Calculate how many display vsyncs we need to present a single frame for this
194 // layer
195 const auto [displayFramesQuot, displayFramesRem] =
196 getDisplayFrames(layerPeriod, displayPeriod);
197 static constexpr size_t MAX_FRAMES_TO_FIT =
198 10; // Stop calculating when score < 0.1
199 if (displayFramesRem == 0) {
200 // Layer desired refresh rate matches the display rate.
201 return 1.0f;
202 }
Ady Abraham8a82ba62020-01-17 12:43:17 -0800203
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800204 if (displayFramesQuot == 0) {
205 // Layer desired refresh rate is higher the display rate.
206 return (static_cast<float>(layerPeriod) /
207 static_cast<float>(displayPeriod)) *
208 (1.0f / (MAX_FRAMES_TO_FIT + 1));
209 }
210
211 // Layer desired refresh rate is lower the display rate. Check how well it fits
212 // the cadence
213 auto diff = std::abs(displayFramesRem - (displayPeriod - displayFramesRem));
214 int iter = 2;
215 while (diff > MARGIN_FOR_PERIOD_CALCULATION && iter < MAX_FRAMES_TO_FIT) {
216 diff = diff - (displayPeriod - diff);
217 iter++;
218 }
219
220 return 1.0f / iter;
221 }();
222 ALOGV("%s (ExplicitExactOrMultiple, weight %.2f) %.2fHz gives %s score of %.2f",
223 layer.name.c_str(), weight, 1e9f / layerPeriod, scores[i].first->name.c_str(),
224 layerScore);
225 scores[i].second += weight * layerScore;
226 continue;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800227 }
Ady Abraham8a82ba62020-01-17 12:43:17 -0800228 }
229 }
230
Ady Abraham34702102020-02-10 14:12:05 -0800231 // Now that we scored all the refresh rates we need to pick the one that got the highest score.
232 // In case of a tie we will pick the higher refresh rate if any of the layers wanted Max,
233 // or the lower otherwise.
234 const RefreshRate* bestRefreshRate = maxVoteLayers > 0
235 ? getBestRefreshRate(scores.rbegin(), scores.rend())
236 : getBestRefreshRate(scores.begin(), scores.end());
237
238 return bestRefreshRate == nullptr ? *mCurrentRefreshRate : *bestRefreshRate;
239}
240
241template <typename Iter>
242const RefreshRate* RefreshRateConfigs::getBestRefreshRate(Iter begin, Iter end) const {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800243 const RefreshRate* bestRefreshRate = nullptr;
Ady Abraham34702102020-02-10 14:12:05 -0800244 float max = 0;
245 for (auto i = begin; i != end; ++i) {
246 const auto [refreshRate, score] = *i;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800247 ALOGV("%s scores %.2f", refreshRate->name.c_str(), score);
248
Ady Abrahamdec1a412020-01-24 10:23:50 -0800249 ATRACE_INT(refreshRate->name.c_str(), round<int>(score * 100));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800250
251 if (score > max) {
252 max = score;
253 bestRefreshRate = refreshRate;
254 }
255 }
256
Ady Abraham34702102020-02-10 14:12:05 -0800257 return bestRefreshRate;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800258}
259
Ady Abraham2139f732019-11-13 18:56:40 -0800260const AllRefreshRatesMapType& RefreshRateConfigs::getAllRefreshRates() const {
261 return mRefreshRates;
262}
263
264const RefreshRate& RefreshRateConfigs::getMinRefreshRateByPolicy() const {
265 std::lock_guard lock(mLock);
Ana Krulec3f6a2062020-01-23 15:48:01 -0800266 return *mAvailableRefreshRates.front();
Ady Abraham2139f732019-11-13 18:56:40 -0800267}
268
269const RefreshRate& RefreshRateConfigs::getMaxRefreshRateByPolicy() const {
270 std::lock_guard lock(mLock);
Ady Abraham2139f732019-11-13 18:56:40 -0800271 return *mAvailableRefreshRates.back();
Ady Abraham2139f732019-11-13 18:56:40 -0800272}
273
274const RefreshRate& RefreshRateConfigs::getCurrentRefreshRate() const {
275 std::lock_guard lock(mLock);
276 return *mCurrentRefreshRate;
277}
278
Ana Krulec5d477912020-02-07 12:02:38 -0800279const RefreshRate& RefreshRateConfigs::getCurrentRefreshRateByPolicy() const {
280 std::lock_guard lock(mLock);
Ana Krulec3d367c82020-02-25 15:02:01 -0800281 return getCurrentRefreshRateByPolicyLocked();
282}
283
284const RefreshRate& RefreshRateConfigs::getCurrentRefreshRateByPolicyLocked() const {
Ana Krulec5d477912020-02-07 12:02:38 -0800285 if (std::find(mAvailableRefreshRates.begin(), mAvailableRefreshRates.end(),
286 mCurrentRefreshRate) != mAvailableRefreshRates.end()) {
287 return *mCurrentRefreshRate;
288 }
289 return mRefreshRates.at(mDefaultConfig);
290}
291
Ady Abraham2139f732019-11-13 18:56:40 -0800292void RefreshRateConfigs::setCurrentConfigId(HwcConfigIndexType configId) {
293 std::lock_guard lock(mLock);
294 mCurrentRefreshRate = &mRefreshRates.at(configId);
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800295}
296
Ana Krulec3f6a2062020-01-23 15:48:01 -0800297RefreshRateConfigs::RefreshRateConfigs(const std::vector<InputConfig>& configs,
298 HwcConfigIndexType currentHwcConfig) {
Ady Abraham2139f732019-11-13 18:56:40 -0800299 init(configs, currentHwcConfig);
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800300}
301
302RefreshRateConfigs::RefreshRateConfigs(
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800303 const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
Ana Krulec3f6a2062020-01-23 15:48:01 -0800304 HwcConfigIndexType currentConfigId) {
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800305 std::vector<InputConfig> inputConfigs;
Ady Abrahamdec1a412020-01-24 10:23:50 -0800306 for (size_t configId = 0; configId < configs.size(); ++configId) {
307 auto configGroup = HwcConfigGroupType(configs[configId]->getConfigGroup());
308 inputConfigs.push_back({HwcConfigIndexType(static_cast<int>(configId)), configGroup,
309 configs[configId]->getVsyncPeriod()});
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800310 }
Ady Abraham2139f732019-11-13 18:56:40 -0800311 init(inputConfigs, currentConfigId);
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800312}
313
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100314status_t RefreshRateConfigs::setPolicy(HwcConfigIndexType defaultConfigId, float minRefreshRate,
315 float maxRefreshRate, bool* outPolicyChanged) {
Ady Abraham2139f732019-11-13 18:56:40 -0800316 std::lock_guard lock(mLock);
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100317 bool policyChanged = defaultConfigId != mDefaultConfig ||
318 minRefreshRate != mMinRefreshRateFps || maxRefreshRate != mMaxRefreshRateFps;
319 if (outPolicyChanged) {
320 *outPolicyChanged = policyChanged;
321 }
322 if (!policyChanged) {
323 return NO_ERROR;
324 }
325 // defaultConfigId must be a valid config ID, and within the given refresh rate range.
326 if (mRefreshRates.count(defaultConfigId) == 0) {
327 return BAD_VALUE;
328 }
329 const RefreshRate& refreshRate = mRefreshRates.at(defaultConfigId);
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800330 if (!refreshRate.inPolicy(minRefreshRate, maxRefreshRate)) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100331 return BAD_VALUE;
332 }
333 mDefaultConfig = defaultConfigId;
Ady Abraham2139f732019-11-13 18:56:40 -0800334 mMinRefreshRateFps = minRefreshRate;
335 mMaxRefreshRateFps = maxRefreshRate;
336 constructAvailableRefreshRates();
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100337 return NO_ERROR;
338}
339
340void RefreshRateConfigs::getPolicy(HwcConfigIndexType* defaultConfigId, float* minRefreshRate,
341 float* maxRefreshRate) const {
342 std::lock_guard lock(mLock);
343 *defaultConfigId = mDefaultConfig;
344 *minRefreshRate = mMinRefreshRateFps;
345 *maxRefreshRate = mMaxRefreshRateFps;
346}
347
348bool RefreshRateConfigs::isConfigAllowed(HwcConfigIndexType config) const {
349 std::lock_guard lock(mLock);
350 for (const RefreshRate* refreshRate : mAvailableRefreshRates) {
351 if (refreshRate->configId == config) {
352 return true;
353 }
354 }
355 return false;
Ady Abraham2139f732019-11-13 18:56:40 -0800356}
357
358void RefreshRateConfigs::getSortedRefreshRateList(
359 const std::function<bool(const RefreshRate&)>& shouldAddRefreshRate,
360 std::vector<const RefreshRate*>* outRefreshRates) {
361 outRefreshRates->clear();
362 outRefreshRates->reserve(mRefreshRates.size());
363 for (const auto& [type, refreshRate] : mRefreshRates) {
364 if (shouldAddRefreshRate(refreshRate)) {
365 ALOGV("getSortedRefreshRateList: config %d added to list policy",
366 refreshRate.configId.value());
367 outRefreshRates->push_back(&refreshRate);
368 }
369 }
370
371 std::sort(outRefreshRates->begin(), outRefreshRates->end(),
372 [](const auto refreshRate1, const auto refreshRate2) {
373 return refreshRate1->vsyncPeriod > refreshRate2->vsyncPeriod;
374 });
375}
376
377void RefreshRateConfigs::constructAvailableRefreshRates() {
378 // Filter configs based on current policy and sort based on vsync period
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100379 HwcConfigGroupType group = mRefreshRates.at(mDefaultConfig).configGroup;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800380 ALOGV("constructAvailableRefreshRates: default %d group %d min %.2f max %.2f",
381 mDefaultConfig.value(), group.value(), mMinRefreshRateFps, mMaxRefreshRateFps);
Ady Abraham2139f732019-11-13 18:56:40 -0800382 getSortedRefreshRateList(
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100383 [&](const RefreshRate& refreshRate) REQUIRES(mLock) {
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800384 return refreshRate.configGroup == group &&
385 refreshRate.inPolicy(mMinRefreshRateFps, mMaxRefreshRateFps);
Ady Abraham2139f732019-11-13 18:56:40 -0800386 },
387 &mAvailableRefreshRates);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800388
389 std::string availableRefreshRates;
390 for (const auto& refreshRate : mAvailableRefreshRates) {
391 base::StringAppendF(&availableRefreshRates, "%s ", refreshRate->name.c_str());
392 }
393
394 ALOGV("Available refresh rates: %s", availableRefreshRates.c_str());
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100395 LOG_ALWAYS_FATAL_IF(mAvailableRefreshRates.empty(),
396 "No compatible display configs for default=%d min=%.0f max=%.0f",
397 mDefaultConfig.value(), mMinRefreshRateFps, mMaxRefreshRateFps);
Ady Abraham2139f732019-11-13 18:56:40 -0800398}
399
400// NO_THREAD_SAFETY_ANALYSIS since this is called from the constructor
401void RefreshRateConfigs::init(const std::vector<InputConfig>& configs,
402 HwcConfigIndexType currentHwcConfig) NO_THREAD_SAFETY_ANALYSIS {
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800403 LOG_ALWAYS_FATAL_IF(configs.empty());
Ady Abraham2139f732019-11-13 18:56:40 -0800404 LOG_ALWAYS_FATAL_IF(currentHwcConfig.value() >= configs.size());
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800405
Ady Abraham2139f732019-11-13 18:56:40 -0800406 auto buildRefreshRate = [&](InputConfig config) -> RefreshRate {
407 const float fps = 1e9f / config.vsyncPeriod;
408 return RefreshRate(config.configId, config.vsyncPeriod, config.configGroup,
409 base::StringPrintf("%2.ffps", fps), fps);
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800410 };
411
Ady Abraham2139f732019-11-13 18:56:40 -0800412 for (const auto& config : configs) {
413 mRefreshRates.emplace(config.configId, buildRefreshRate(config));
414 if (config.configId == currentHwcConfig) {
415 mCurrentRefreshRate = &mRefreshRates.at(config.configId);
Ady Abraham2139f732019-11-13 18:56:40 -0800416 }
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800417 }
418
Ady Abraham2139f732019-11-13 18:56:40 -0800419 std::vector<const RefreshRate*> sortedConfigs;
420 getSortedRefreshRateList([](const RefreshRate&) { return true; }, &sortedConfigs);
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100421 mDefaultConfig = currentHwcConfig;
Ady Abraham2139f732019-11-13 18:56:40 -0800422 mMinSupportedRefreshRate = sortedConfigs.front();
423 mMaxSupportedRefreshRate = sortedConfigs.back();
424 constructAvailableRefreshRates();
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800425}
426
Ady Abraham2139f732019-11-13 18:56:40 -0800427} // namespace android::scheduler