blob: 4b7251b989d9437c5b99d487c4d186fd1e66344a [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 Abraham5b8afb5a2020-03-06 14:57:26 -080026#undef LOG_TAG
27#define LOG_TAG "RefreshRateConfigs"
28
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080029namespace android::scheduler {
Marin Shalamanov53fc11d2020-11-20 14:00:13 +010030namespace {
31std::string formatLayerInfo(const RefreshRateConfigs::LayerRequirement& layer, float weight) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +010032 return base::StringPrintf("%s (type=%s, weight=%.2f seamlessness=%s) %s", layer.name.c_str(),
Marin Shalamanov53fc11d2020-11-20 14:00:13 +010033 RefreshRateConfigs::layerVoteTypeString(layer.vote).c_str(), weight,
Marin Shalamanove8a663d2020-11-24 17:48:00 +010034 toString(layer.seamlessness).c_str(),
35 to_string(layer.desiredRefreshRate).c_str());
Marin Shalamanov53fc11d2020-11-20 14:00:13 +010036}
37} // namespace
Ady Abraham2139f732019-11-13 18:56:40 -080038
39using AllRefreshRatesMapType = RefreshRateConfigs::AllRefreshRatesMapType;
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080040using RefreshRate = RefreshRateConfigs::RefreshRate;
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -080041
Marin Shalamanov46084422020-10-13 12:33:42 +020042std::string RefreshRate::toString() const {
43 return base::StringPrintf("{id=%d, hwcId=%d, fps=%.2f, width=%d, height=%d group=%d}",
Marin Shalamanove8a663d2020-11-24 17:48:00 +010044 getConfigId().value(), hwcConfig->getId(), getFps().getValue(),
Marin Shalamanov46084422020-10-13 12:33:42 +020045 hwcConfig->getWidth(), hwcConfig->getHeight(), getConfigGroup());
46}
47
Ady Abrahama6b676e2020-05-27 14:29:09 -070048std::string RefreshRateConfigs::layerVoteTypeString(LayerVoteType vote) {
49 switch (vote) {
50 case LayerVoteType::NoVote:
51 return "NoVote";
52 case LayerVoteType::Min:
53 return "Min";
54 case LayerVoteType::Max:
55 return "Max";
56 case LayerVoteType::Heuristic:
57 return "Heuristic";
58 case LayerVoteType::ExplicitDefault:
59 return "ExplicitDefault";
60 case LayerVoteType::ExplicitExactOrMultiple:
61 return "ExplicitExactOrMultiple";
62 }
63}
64
Marin Shalamanovb6674e72020-11-06 13:05:57 +010065std::string RefreshRateConfigs::Policy::toString() const {
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020066 return base::StringPrintf("default config ID: %d, allowGroupSwitching = %d"
Marin Shalamanove8a663d2020-11-24 17:48:00 +010067 ", primary range: %s, app request range: %s",
68 defaultConfig.value(), allowGroupSwitching,
69 primaryRange.toString().c_str(), appRequestRange.toString().c_str());
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020070}
71
Ady Abraham4ccdcb42020-02-11 17:34:34 -080072std::pair<nsecs_t, nsecs_t> RefreshRateConfigs::getDisplayFrames(nsecs_t layerPeriod,
73 nsecs_t displayPeriod) const {
74 auto [displayFramesQuot, displayFramesRem] = std::div(layerPeriod, displayPeriod);
75 if (displayFramesRem <= MARGIN_FOR_PERIOD_CALCULATION ||
76 std::abs(displayFramesRem - displayPeriod) <= MARGIN_FOR_PERIOD_CALCULATION) {
77 displayFramesQuot++;
78 displayFramesRem = 0;
79 }
80
81 return {displayFramesQuot, displayFramesRem};
82}
83
Steven Thomasbb374322020-04-28 22:47:16 -070084const RefreshRate& RefreshRateConfigs::getBestRefreshRate(
Ady Abrahamdfd62162020-06-10 16:11:56 -070085 const std::vector<LayerRequirement>& layers, const GlobalSignals& globalSignals,
86 GlobalSignals* outSignalsConsidered) const {
Ady Abraham8a82ba62020-01-17 12:43:17 -080087 ATRACE_CALL();
Marin Shalamanov46084422020-10-13 12:33:42 +020088 ALOGV("getBestRefreshRate %zu layers", layers.size());
Ady Abraham8a82ba62020-01-17 12:43:17 -080089
Ady Abrahamdfd62162020-06-10 16:11:56 -070090 if (outSignalsConsidered) *outSignalsConsidered = {};
91 const auto setTouchConsidered = [&] {
92 if (outSignalsConsidered) {
93 outSignalsConsidered->touch = true;
94 }
95 };
96
97 const auto setIdleConsidered = [&] {
98 if (outSignalsConsidered) {
99 outSignalsConsidered->idle = true;
100 }
101 };
102
Ady Abraham8a82ba62020-01-17 12:43:17 -0800103 std::lock_guard lock(mLock);
104
105 int noVoteLayers = 0;
106 int minVoteLayers = 0;
107 int maxVoteLayers = 0;
Ady Abraham71c437d2020-01-31 15:56:57 -0800108 int explicitDefaultVoteLayers = 0;
109 int explicitExactOrMultipleVoteLayers = 0;
Ady Abraham6fb599b2020-03-05 13:48:22 -0800110 float maxExplicitWeight = 0;
Marin Shalamanov46084422020-10-13 12:33:42 +0200111 int seamedLayers = 0;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800112 for (const auto& layer : layers) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800113 if (layer.vote == LayerVoteType::NoVote) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800114 noVoteLayers++;
Ady Abraham6fb599b2020-03-05 13:48:22 -0800115 } else if (layer.vote == LayerVoteType::Min) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800116 minVoteLayers++;
Ady Abraham6fb599b2020-03-05 13:48:22 -0800117 } else if (layer.vote == LayerVoteType::Max) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800118 maxVoteLayers++;
Ady Abraham6fb599b2020-03-05 13:48:22 -0800119 } else if (layer.vote == LayerVoteType::ExplicitDefault) {
Ady Abraham71c437d2020-01-31 15:56:57 -0800120 explicitDefaultVoteLayers++;
Ady Abraham6fb599b2020-03-05 13:48:22 -0800121 maxExplicitWeight = std::max(maxExplicitWeight, layer.weight);
122 } else if (layer.vote == LayerVoteType::ExplicitExactOrMultiple) {
Ady Abraham71c437d2020-01-31 15:56:57 -0800123 explicitExactOrMultipleVoteLayers++;
Ady Abraham6fb599b2020-03-05 13:48:22 -0800124 maxExplicitWeight = std::max(maxExplicitWeight, layer.weight);
125 }
Marin Shalamanov46084422020-10-13 12:33:42 +0200126
Marin Shalamanov53fc11d2020-11-20 14:00:13 +0100127 if (layer.seamlessness == Seamlessness::SeamedAndSeamless) {
Marin Shalamanov46084422020-10-13 12:33:42 +0200128 seamedLayers++;
129 }
Ady Abraham6fb599b2020-03-05 13:48:22 -0800130 }
131
Alec Mouri11232a22020-05-14 18:06:25 -0700132 const bool hasExplicitVoteLayers =
133 explicitDefaultVoteLayers > 0 || explicitExactOrMultipleVoteLayers > 0;
134
Steven Thomasf734df42020-04-13 21:09:28 -0700135 // Consider the touch event if there are no Explicit* layers. Otherwise wait until after we've
136 // selected a refresh rate to see if we should apply touch boost.
Ady Abrahamdfd62162020-06-10 16:11:56 -0700137 if (globalSignals.touch && !hasExplicitVoteLayers) {
Ady Abrahama6b676e2020-05-27 14:29:09 -0700138 ALOGV("TouchBoost - choose %s", getMaxRefreshRateByPolicyLocked().getName().c_str());
Ady Abrahamdfd62162020-06-10 16:11:56 -0700139 setTouchConsidered();
Steven Thomasf734df42020-04-13 21:09:28 -0700140 return getMaxRefreshRateByPolicyLocked();
Ady Abraham8a82ba62020-01-17 12:43:17 -0800141 }
142
Alec Mouri11232a22020-05-14 18:06:25 -0700143 // If the primary range consists of a single refresh rate then we can only
144 // move out the of range if layers explicitly request a different refresh
145 // rate.
146 const Policy* policy = getCurrentPolicyLocked();
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100147 const bool primaryRangeIsSingleRate =
148 policy->primaryRange.min.equalsWithMargin(policy->primaryRange.max);
Alec Mouri11232a22020-05-14 18:06:25 -0700149
Ady Abrahamdfd62162020-06-10 16:11:56 -0700150 if (!globalSignals.touch && globalSignals.idle &&
151 !(primaryRangeIsSingleRate && hasExplicitVoteLayers)) {
Ady Abrahama6b676e2020-05-27 14:29:09 -0700152 ALOGV("Idle - choose %s", getMinRefreshRateByPolicyLocked().getName().c_str());
Ady Abrahamdfd62162020-06-10 16:11:56 -0700153 setIdleConsidered();
Steven Thomasbb374322020-04-28 22:47:16 -0700154 return getMinRefreshRateByPolicyLocked();
155 }
156
Steven Thomasdebafed2020-05-18 17:30:35 -0700157 if (layers.empty() || noVoteLayers == layers.size()) {
158 return getMaxRefreshRateByPolicyLocked();
Steven Thomasbb374322020-04-28 22:47:16 -0700159 }
160
Ady Abraham8a82ba62020-01-17 12:43:17 -0800161 // Only if all layers want Min we should return Min
162 if (noVoteLayers + minVoteLayers == layers.size()) {
Ady Abrahama6b676e2020-05-27 14:29:09 -0700163 ALOGV("all layers Min - choose %s", getMinRefreshRateByPolicyLocked().getName().c_str());
Steven Thomasf734df42020-04-13 21:09:28 -0700164 return getMinRefreshRateByPolicyLocked();
Ady Abraham8a82ba62020-01-17 12:43:17 -0800165 }
166
Ady Abraham8a82ba62020-01-17 12:43:17 -0800167 // Find the best refresh rate based on score
168 std::vector<std::pair<const RefreshRate*, float>> scores;
Steven Thomasf734df42020-04-13 21:09:28 -0700169 scores.reserve(mAppRequestRefreshRates.size());
Ady Abraham8a82ba62020-01-17 12:43:17 -0800170
Steven Thomasf734df42020-04-13 21:09:28 -0700171 for (const auto refreshRate : mAppRequestRefreshRates) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800172 scores.emplace_back(refreshRate, 0.0f);
173 }
174
Marin Shalamanov46084422020-10-13 12:33:42 +0200175 const auto& defaultConfig = mRefreshRates.at(policy->defaultConfig);
176
Ady Abraham8a82ba62020-01-17 12:43:17 -0800177 for (const auto& layer : layers) {
Ady Abrahama6b676e2020-05-27 14:29:09 -0700178 ALOGV("Calculating score for %s (%s, weight %.2f)", layer.name.c_str(),
179 layerVoteTypeString(layer.vote).c_str(), layer.weight);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800180 if (layer.vote == LayerVoteType::NoVote || layer.vote == LayerVoteType::Min) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800181 continue;
182 }
183
Ady Abraham71c437d2020-01-31 15:56:57 -0800184 auto weight = layer.weight;
Ady Abraham71c437d2020-01-31 15:56:57 -0800185
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800186 for (auto i = 0u; i < scores.size(); i++) {
Marin Shalamanov53fc11d2020-11-20 14:00:13 +0100187 const bool isSeamlessSwitch =
188 scores[i].first->getConfigGroup() == mCurrentRefreshRate->getConfigGroup();
Marin Shalamanov46084422020-10-13 12:33:42 +0200189
Marin Shalamanov53fc11d2020-11-20 14:00:13 +0100190 if (layer.seamlessness == Seamlessness::OnlySeamless && !isSeamlessSwitch) {
191 ALOGV("%s ignores %s to avoid non-seamless switch. Current config = %s",
192 formatLayerInfo(layer, weight).c_str(), scores[i].first->toString().c_str(),
193 mCurrentRefreshRate->toString().c_str());
Marin Shalamanov46084422020-10-13 12:33:42 +0200194 continue;
195 }
196
Marin Shalamanov53fc11d2020-11-20 14:00:13 +0100197 if (layer.seamlessness == Seamlessness::SeamedAndSeamless && !isSeamlessSwitch &&
198 !layer.focused) {
199 ALOGV("%s ignores %s because it's not focused and the switch is going to be seamed."
200 " Current config = %s",
201 formatLayerInfo(layer, weight).c_str(), scores[i].first->toString().c_str(),
202 mCurrentRefreshRate->toString().c_str());
203 continue;
204 }
205
206 // Layers with default seamlessness vote for the current config group if
207 // there are layers with seamlessness=SeamedAndSeamless and for the default
208 // config group otherwise. In second case, if the current config group is different
209 // from the default, this means a layer with seamlessness=SeamedAndSeamless has just
210 // disappeared.
211 const bool isInPolicyForDefault = seamedLayers > 0
212 ? scores[i].first->getConfigGroup() == mCurrentRefreshRate->getConfigGroup()
213 : scores[i].first->getConfigGroup() == defaultConfig->getConfigGroup();
214
215 if (layer.seamlessness == Seamlessness::Default && !isInPolicyForDefault &&
216 !layer.focused) {
217 ALOGV("%s ignores %s. Current config = %s", formatLayerInfo(layer, weight).c_str(),
218 scores[i].first->toString().c_str(), mCurrentRefreshRate->toString().c_str());
Marin Shalamanov46084422020-10-13 12:33:42 +0200219 continue;
220 }
221
Steven Thomasf734df42020-04-13 21:09:28 -0700222 bool inPrimaryRange =
223 scores[i].first->inPolicy(policy->primaryRange.min, policy->primaryRange.max);
Alec Mouri11232a22020-05-14 18:06:25 -0700224 if ((primaryRangeIsSingleRate || !inPrimaryRange) &&
Ady Abraham20c029c2020-07-06 12:58:05 -0700225 !(layer.focused && layer.vote == LayerVoteType::ExplicitDefault)) {
226 // Only focused layers with ExplicitDefault frame rate settings are allowed to score
Ady Abrahamaae5ed52020-06-26 09:32:43 -0700227 // refresh rates outside the primary range.
Steven Thomasf734df42020-04-13 21:09:28 -0700228 continue;
229 }
230
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800231 // If the layer wants Max, give higher score to the higher refresh rate
232 if (layer.vote == LayerVoteType::Max) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100233 const auto ratio =
234 scores[i].first->fps.getValue() / scores.back().first->fps.getValue();
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800235 // use ratio^2 to get a lower score the more we get further from peak
236 const auto layerScore = ratio * ratio;
Marin Shalamanov53fc11d2020-11-20 14:00:13 +0100237 ALOGV("%s gives %s score of %.2f", formatLayerInfo(layer, weight).c_str(),
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100238 scores[i].first->getName().c_str(), layerScore);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800239 scores[i].second += weight * layerScore;
240 continue;
Ady Abraham71c437d2020-01-31 15:56:57 -0800241 }
Ady Abraham8a82ba62020-01-17 12:43:17 -0800242
Ady Abrahamabc27602020-04-08 17:20:29 -0700243 const auto displayPeriod = scores[i].first->hwcConfig->getVsyncPeriod();
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100244 const auto layerPeriod = layer.desiredRefreshRate.getPeriodNsecs();
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800245 if (layer.vote == LayerVoteType::ExplicitDefault) {
246 const auto layerScore = [&]() {
Ady Abraham5b8afb5a2020-03-06 14:57:26 -0800247 // Find the actual rate the layer will render, assuming
248 // that layerPeriod is the minimal time to render a frame
249 auto actualLayerPeriod = displayPeriod;
250 int multiplier = 1;
251 while (layerPeriod > actualLayerPeriod + MARGIN_FOR_PERIOD_CALCULATION) {
252 multiplier++;
253 actualLayerPeriod = displayPeriod * multiplier;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800254 }
Ady Abraham5b8afb5a2020-03-06 14:57:26 -0800255 return std::min(1.0f,
256 static_cast<float>(layerPeriod) /
257 static_cast<float>(actualLayerPeriod));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800258 }();
259
Marin Shalamanov53fc11d2020-11-20 14:00:13 +0100260 ALOGV("%s gives %s score of %.2f", formatLayerInfo(layer, weight).c_str(),
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100261 scores[i].first->getName().c_str(), layerScore);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800262 scores[i].second += weight * layerScore;
263 continue;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800264 }
265
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800266 if (layer.vote == LayerVoteType::ExplicitExactOrMultiple ||
267 layer.vote == LayerVoteType::Heuristic) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700268 const auto layerScore = [&] {
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800269 // Calculate how many display vsyncs we need to present a single frame for this
270 // layer
271 const auto [displayFramesQuot, displayFramesRem] =
272 getDisplayFrames(layerPeriod, displayPeriod);
273 static constexpr size_t MAX_FRAMES_TO_FIT =
274 10; // Stop calculating when score < 0.1
275 if (displayFramesRem == 0) {
276 // Layer desired refresh rate matches the display rate.
277 return 1.0f;
278 }
Ady Abraham8a82ba62020-01-17 12:43:17 -0800279
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800280 if (displayFramesQuot == 0) {
281 // Layer desired refresh rate is higher the display rate.
282 return (static_cast<float>(layerPeriod) /
283 static_cast<float>(displayPeriod)) *
284 (1.0f / (MAX_FRAMES_TO_FIT + 1));
285 }
286
287 // Layer desired refresh rate is lower the display rate. Check how well it fits
288 // the cadence
289 auto diff = std::abs(displayFramesRem - (displayPeriod - displayFramesRem));
290 int iter = 2;
291 while (diff > MARGIN_FOR_PERIOD_CALCULATION && iter < MAX_FRAMES_TO_FIT) {
292 diff = diff - (displayPeriod - diff);
293 iter++;
294 }
295
296 return 1.0f / iter;
297 }();
Marin Shalamanov46084422020-10-13 12:33:42 +0200298 // Slightly prefer seamless switches.
299 constexpr float kSeamedSwitchPenalty = 0.95f;
300 const float seamlessness = isSeamlessSwitch ? 1.0f : kSeamedSwitchPenalty;
Marin Shalamanov53fc11d2020-11-20 14:00:13 +0100301 ALOGV("%s gives %s score of %.2f", formatLayerInfo(layer, weight).c_str(),
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100302 scores[i].first->getName().c_str(), layerScore);
Marin Shalamanov46084422020-10-13 12:33:42 +0200303 scores[i].second += weight * layerScore * seamlessness;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800304 continue;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800305 }
Ady Abraham8a82ba62020-01-17 12:43:17 -0800306 }
307 }
308
Ady Abraham34702102020-02-10 14:12:05 -0800309 // Now that we scored all the refresh rates we need to pick the one that got the highest score.
310 // In case of a tie we will pick the higher refresh rate if any of the layers wanted Max,
311 // or the lower otherwise.
312 const RefreshRate* bestRefreshRate = maxVoteLayers > 0
313 ? getBestRefreshRate(scores.rbegin(), scores.rend())
314 : getBestRefreshRate(scores.begin(), scores.end());
315
Alec Mouri11232a22020-05-14 18:06:25 -0700316 if (primaryRangeIsSingleRate) {
317 // If we never scored any layers, then choose the rate from the primary
318 // range instead of picking a random score from the app range.
319 if (std::all_of(scores.begin(), scores.end(),
320 [](std::pair<const RefreshRate*, float> p) { return p.second == 0; })) {
Ady Abrahama6b676e2020-05-27 14:29:09 -0700321 ALOGV("layers not scored - choose %s",
322 getMaxRefreshRateByPolicyLocked().getName().c_str());
Alec Mouri11232a22020-05-14 18:06:25 -0700323 return getMaxRefreshRateByPolicyLocked();
324 } else {
325 return *bestRefreshRate;
326 }
327 }
328
Steven Thomasf734df42020-04-13 21:09:28 -0700329 // Consider the touch event if there are no ExplicitDefault layers. ExplicitDefault are mostly
330 // interactive (as opposed to ExplicitExactOrMultiple) and therefore if those posted an explicit
331 // vote we should not change it if we get a touch event. Only apply touch boost if it will
332 // actually increase the refresh rate over the normal selection.
333 const RefreshRate& touchRefreshRate = getMaxRefreshRateByPolicyLocked();
Alec Mouri11232a22020-05-14 18:06:25 -0700334
Ady Abrahamdfd62162020-06-10 16:11:56 -0700335 if (globalSignals.touch && explicitDefaultVoteLayers == 0 &&
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100336 bestRefreshRate->fps.lessThanWithMargin(touchRefreshRate.fps)) {
Ady Abrahamdfd62162020-06-10 16:11:56 -0700337 setTouchConsidered();
Ady Abrahama6b676e2020-05-27 14:29:09 -0700338 ALOGV("TouchBoost - choose %s", touchRefreshRate.getName().c_str());
Steven Thomasf734df42020-04-13 21:09:28 -0700339 return touchRefreshRate;
340 }
341
Ady Abrahamde7156e2020-02-28 17:29:39 -0800342 return *bestRefreshRate;
Ady Abraham34702102020-02-10 14:12:05 -0800343}
344
345template <typename Iter>
346const RefreshRate* RefreshRateConfigs::getBestRefreshRate(Iter begin, Iter end) const {
Ady Abraham5b8afb5a2020-03-06 14:57:26 -0800347 constexpr auto EPSILON = 0.001f;
Ady Abrahamde7156e2020-02-28 17:29:39 -0800348 const RefreshRate* bestRefreshRate = begin->first;
349 float max = begin->second;
Ady Abraham34702102020-02-10 14:12:05 -0800350 for (auto i = begin; i != end; ++i) {
351 const auto [refreshRate, score] = *i;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100352 ALOGV("%s scores %.2f", refreshRate->getName().c_str(), score);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800353
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100354 ATRACE_INT(refreshRate->getName().c_str(), round<int>(score * 100));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800355
Ady Abraham5b8afb5a2020-03-06 14:57:26 -0800356 if (score > max * (1 + EPSILON)) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800357 max = score;
358 bestRefreshRate = refreshRate;
359 }
360 }
361
Ady Abraham34702102020-02-10 14:12:05 -0800362 return bestRefreshRate;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800363}
364
Ady Abraham2139f732019-11-13 18:56:40 -0800365const AllRefreshRatesMapType& RefreshRateConfigs::getAllRefreshRates() const {
366 return mRefreshRates;
367}
368
369const RefreshRate& RefreshRateConfigs::getMinRefreshRateByPolicy() const {
370 std::lock_guard lock(mLock);
Steven Thomasf734df42020-04-13 21:09:28 -0700371 return getMinRefreshRateByPolicyLocked();
372}
373
374const RefreshRate& RefreshRateConfigs::getMinRefreshRateByPolicyLocked() const {
Marin Shalamanov46084422020-10-13 12:33:42 +0200375 for (auto refreshRate : mPrimaryRefreshRates) {
376 if (mCurrentRefreshRate->getConfigGroup() == refreshRate->getConfigGroup()) {
377 return *refreshRate;
378 }
379 }
380 ALOGE("Can't find min refresh rate by policy with the same config group"
381 " as the current config %s",
382 mCurrentRefreshRate->toString().c_str());
383 // Defaulting to the lowest refresh rate
Steven Thomasf734df42020-04-13 21:09:28 -0700384 return *mPrimaryRefreshRates.front();
Ady Abraham2139f732019-11-13 18:56:40 -0800385}
386
387const RefreshRate& RefreshRateConfigs::getMaxRefreshRateByPolicy() const {
388 std::lock_guard lock(mLock);
Steven Thomasf734df42020-04-13 21:09:28 -0700389 return getMaxRefreshRateByPolicyLocked();
390}
391
392const RefreshRate& RefreshRateConfigs::getMaxRefreshRateByPolicyLocked() const {
Marin Shalamanov46084422020-10-13 12:33:42 +0200393 for (auto it = mPrimaryRefreshRates.rbegin(); it != mPrimaryRefreshRates.rend(); it++) {
394 const auto& refreshRate = (**it);
395 if (mCurrentRefreshRate->getConfigGroup() == refreshRate.getConfigGroup()) {
396 return refreshRate;
397 }
398 }
399 ALOGE("Can't find max refresh rate by policy with the same config group"
400 " as the current config %s",
401 mCurrentRefreshRate->toString().c_str());
402 // Defaulting to the highest refresh rate
Steven Thomasf734df42020-04-13 21:09:28 -0700403 return *mPrimaryRefreshRates.back();
Ady Abraham2139f732019-11-13 18:56:40 -0800404}
405
406const RefreshRate& RefreshRateConfigs::getCurrentRefreshRate() const {
407 std::lock_guard lock(mLock);
408 return *mCurrentRefreshRate;
409}
410
Ana Krulec5d477912020-02-07 12:02:38 -0800411const RefreshRate& RefreshRateConfigs::getCurrentRefreshRateByPolicy() const {
412 std::lock_guard lock(mLock);
Ana Krulec3d367c82020-02-25 15:02:01 -0800413 return getCurrentRefreshRateByPolicyLocked();
414}
415
416const RefreshRate& RefreshRateConfigs::getCurrentRefreshRateByPolicyLocked() const {
Steven Thomasf734df42020-04-13 21:09:28 -0700417 if (std::find(mAppRequestRefreshRates.begin(), mAppRequestRefreshRates.end(),
418 mCurrentRefreshRate) != mAppRequestRefreshRates.end()) {
Ana Krulec5d477912020-02-07 12:02:38 -0800419 return *mCurrentRefreshRate;
420 }
Steven Thomasd4071902020-03-24 16:02:53 -0700421 return *mRefreshRates.at(getCurrentPolicyLocked()->defaultConfig);
Ana Krulec5d477912020-02-07 12:02:38 -0800422}
423
Ady Abraham2139f732019-11-13 18:56:40 -0800424void RefreshRateConfigs::setCurrentConfigId(HwcConfigIndexType configId) {
425 std::lock_guard lock(mLock);
Ady Abraham2e1dd892020-03-05 13:48:36 -0800426 mCurrentRefreshRate = mRefreshRates.at(configId).get();
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800427}
428
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800429RefreshRateConfigs::RefreshRateConfigs(
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800430 const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700431 HwcConfigIndexType currentConfigId)
432 : mKnownFrameRates(constructKnownFrameRates(configs)) {
Ady Abrahamabc27602020-04-08 17:20:29 -0700433 LOG_ALWAYS_FATAL_IF(configs.empty());
434 LOG_ALWAYS_FATAL_IF(currentConfigId.value() >= configs.size());
435
436 for (auto configId = HwcConfigIndexType(0); configId.value() < configs.size(); configId++) {
437 const auto& config = configs.at(static_cast<size_t>(configId.value()));
Ady Abrahamabc27602020-04-08 17:20:29 -0700438 mRefreshRates.emplace(configId,
439 std::make_unique<RefreshRate>(configId, config,
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100440 Fps::fromPeriodNsecs(
441 config->getVsyncPeriod()),
Ady Abrahamabc27602020-04-08 17:20:29 -0700442 RefreshRate::ConstructorTag(0)));
443 if (configId == currentConfigId) {
444 mCurrentRefreshRate = mRefreshRates.at(configId).get();
445 }
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800446 }
Ady Abrahamabc27602020-04-08 17:20:29 -0700447
448 std::vector<const RefreshRate*> sortedConfigs;
449 getSortedRefreshRateList([](const RefreshRate&) { return true; }, &sortedConfigs);
450 mDisplayManagerPolicy.defaultConfig = currentConfigId;
451 mMinSupportedRefreshRate = sortedConfigs.front();
452 mMaxSupportedRefreshRate = sortedConfigs.back();
453 constructAvailableRefreshRates();
Ady Abrahamb4b1e0a2019-11-20 18:25:35 -0800454}
455
Steven Thomasd4071902020-03-24 16:02:53 -0700456bool RefreshRateConfigs::isPolicyValid(const Policy& policy) {
457 // defaultConfig must be a valid config, and within the given refresh rate range.
458 auto iter = mRefreshRates.find(policy.defaultConfig);
459 if (iter == mRefreshRates.end()) {
Marin Shalamanovb6674e72020-11-06 13:05:57 +0100460 ALOGE("Default config is not found.");
Steven Thomasd4071902020-03-24 16:02:53 -0700461 return false;
462 }
463 const RefreshRate& refreshRate = *iter->second;
Steven Thomasf734df42020-04-13 21:09:28 -0700464 if (!refreshRate.inPolicy(policy.primaryRange.min, policy.primaryRange.max)) {
Marin Shalamanovb6674e72020-11-06 13:05:57 +0100465 ALOGE("Default config is not in the primary range.");
Steven Thomasd4071902020-03-24 16:02:53 -0700466 return false;
467 }
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100468 return policy.appRequestRange.min.lessThanOrEqualWithMargin(policy.primaryRange.min) &&
469 policy.appRequestRange.max.greaterThanOrEqualWithMargin(policy.primaryRange.max);
Steven Thomasd4071902020-03-24 16:02:53 -0700470}
471
472status_t RefreshRateConfigs::setDisplayManagerPolicy(const Policy& policy) {
Ady Abraham2139f732019-11-13 18:56:40 -0800473 std::lock_guard lock(mLock);
Steven Thomasd4071902020-03-24 16:02:53 -0700474 if (!isPolicyValid(policy)) {
Marin Shalamanovb6674e72020-11-06 13:05:57 +0100475 ALOGE("Invalid refresh rate policy: %s", policy.toString().c_str());
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100476 return BAD_VALUE;
477 }
Steven Thomasd4071902020-03-24 16:02:53 -0700478 Policy previousPolicy = *getCurrentPolicyLocked();
479 mDisplayManagerPolicy = policy;
480 if (*getCurrentPolicyLocked() == previousPolicy) {
481 return CURRENT_POLICY_UNCHANGED;
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100482 }
Ady Abraham2139f732019-11-13 18:56:40 -0800483 constructAvailableRefreshRates();
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100484 return NO_ERROR;
485}
486
Steven Thomasd4071902020-03-24 16:02:53 -0700487status_t RefreshRateConfigs::setOverridePolicy(const std::optional<Policy>& policy) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100488 std::lock_guard lock(mLock);
Steven Thomasd4071902020-03-24 16:02:53 -0700489 if (policy && !isPolicyValid(*policy)) {
490 return BAD_VALUE;
491 }
492 Policy previousPolicy = *getCurrentPolicyLocked();
493 mOverridePolicy = policy;
494 if (*getCurrentPolicyLocked() == previousPolicy) {
495 return CURRENT_POLICY_UNCHANGED;
496 }
497 constructAvailableRefreshRates();
498 return NO_ERROR;
499}
500
501const RefreshRateConfigs::Policy* RefreshRateConfigs::getCurrentPolicyLocked() const {
502 return mOverridePolicy ? &mOverridePolicy.value() : &mDisplayManagerPolicy;
503}
504
505RefreshRateConfigs::Policy RefreshRateConfigs::getCurrentPolicy() const {
506 std::lock_guard lock(mLock);
507 return *getCurrentPolicyLocked();
508}
509
510RefreshRateConfigs::Policy RefreshRateConfigs::getDisplayManagerPolicy() const {
511 std::lock_guard lock(mLock);
512 return mDisplayManagerPolicy;
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100513}
514
515bool RefreshRateConfigs::isConfigAllowed(HwcConfigIndexType config) const {
516 std::lock_guard lock(mLock);
Steven Thomasf734df42020-04-13 21:09:28 -0700517 for (const RefreshRate* refreshRate : mAppRequestRefreshRates) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100518 if (refreshRate->configId == config) {
519 return true;
520 }
521 }
522 return false;
Ady Abraham2139f732019-11-13 18:56:40 -0800523}
524
525void RefreshRateConfigs::getSortedRefreshRateList(
526 const std::function<bool(const RefreshRate&)>& shouldAddRefreshRate,
527 std::vector<const RefreshRate*>* outRefreshRates) {
528 outRefreshRates->clear();
529 outRefreshRates->reserve(mRefreshRates.size());
530 for (const auto& [type, refreshRate] : mRefreshRates) {
Ady Abraham2e1dd892020-03-05 13:48:36 -0800531 if (shouldAddRefreshRate(*refreshRate)) {
Ady Abraham2139f732019-11-13 18:56:40 -0800532 ALOGV("getSortedRefreshRateList: config %d added to list policy",
Ady Abraham2e1dd892020-03-05 13:48:36 -0800533 refreshRate->configId.value());
534 outRefreshRates->push_back(refreshRate.get());
Ady Abraham2139f732019-11-13 18:56:40 -0800535 }
536 }
537
538 std::sort(outRefreshRates->begin(), outRefreshRates->end(),
539 [](const auto refreshRate1, const auto refreshRate2) {
Ady Abrahamabc27602020-04-08 17:20:29 -0700540 if (refreshRate1->hwcConfig->getVsyncPeriod() !=
541 refreshRate2->hwcConfig->getVsyncPeriod()) {
542 return refreshRate1->hwcConfig->getVsyncPeriod() >
543 refreshRate2->hwcConfig->getVsyncPeriod();
Steven Thomasd4071902020-03-24 16:02:53 -0700544 } else {
Ady Abrahamabc27602020-04-08 17:20:29 -0700545 return refreshRate1->hwcConfig->getConfigGroup() >
546 refreshRate2->hwcConfig->getConfigGroup();
Steven Thomasd4071902020-03-24 16:02:53 -0700547 }
Ady Abraham2139f732019-11-13 18:56:40 -0800548 });
549}
550
551void RefreshRateConfigs::constructAvailableRefreshRates() {
552 // Filter configs based on current policy and sort based on vsync period
Steven Thomasd4071902020-03-24 16:02:53 -0700553 const Policy* policy = getCurrentPolicyLocked();
Ady Abrahamabc27602020-04-08 17:20:29 -0700554 const auto& defaultConfig = mRefreshRates.at(policy->defaultConfig)->hwcConfig;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100555 ALOGV("constructAvailableRefreshRates: %s ", policy->toString().c_str());
Ady Abrahamabc27602020-04-08 17:20:29 -0700556
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100557 auto filterRefreshRates = [&](Fps min, Fps max, const char* listName,
Steven Thomasf734df42020-04-13 21:09:28 -0700558 std::vector<const RefreshRate*>* outRefreshRates) {
559 getSortedRefreshRateList(
560 [&](const RefreshRate& refreshRate) REQUIRES(mLock) {
561 const auto& hwcConfig = refreshRate.hwcConfig;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800562
Steven Thomasf734df42020-04-13 21:09:28 -0700563 return hwcConfig->getHeight() == defaultConfig->getHeight() &&
564 hwcConfig->getWidth() == defaultConfig->getWidth() &&
565 hwcConfig->getDpiX() == defaultConfig->getDpiX() &&
566 hwcConfig->getDpiY() == defaultConfig->getDpiY() &&
567 (policy->allowGroupSwitching ||
568 hwcConfig->getConfigGroup() == defaultConfig->getConfigGroup()) &&
569 refreshRate.inPolicy(min, max);
570 },
571 outRefreshRates);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800572
Steven Thomasf734df42020-04-13 21:09:28 -0700573 LOG_ALWAYS_FATAL_IF(outRefreshRates->empty(),
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100574 "No matching configs for %s range: min=%s max=%s", listName,
575 to_string(min).c_str(), to_string(max).c_str());
Steven Thomasf734df42020-04-13 21:09:28 -0700576 auto stringifyRefreshRates = [&]() -> std::string {
577 std::string str;
578 for (auto refreshRate : *outRefreshRates) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100579 base::StringAppendF(&str, "%s ", refreshRate->getName().c_str());
Steven Thomasf734df42020-04-13 21:09:28 -0700580 }
581 return str;
582 };
583 ALOGV("%s refresh rates: %s", listName, stringifyRefreshRates().c_str());
584 };
585
586 filterRefreshRates(policy->primaryRange.min, policy->primaryRange.max, "primary",
587 &mPrimaryRefreshRates);
588 filterRefreshRates(policy->appRequestRange.min, policy->appRequestRange.max, "app request",
589 &mAppRequestRefreshRates);
Ady Abraham2139f732019-11-13 18:56:40 -0800590}
591
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100592std::vector<Fps> RefreshRateConfigs::constructKnownFrameRates(
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700593 const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100594 std::vector<Fps> knownFrameRates = {Fps(24.0f), Fps(30.0f), Fps(45.0f), Fps(60.0f), Fps(72.0f)};
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700595 knownFrameRates.reserve(knownFrameRates.size() + configs.size());
596
597 // Add all supported refresh rates to the set
598 for (const auto& config : configs) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100599 const auto refreshRate = Fps::fromPeriodNsecs(config->getVsyncPeriod());
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700600 knownFrameRates.emplace_back(refreshRate);
601 }
602
603 // Sort and remove duplicates
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100604 std::sort(knownFrameRates.begin(), knownFrameRates.end(), Fps::comparesLess);
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700605 knownFrameRates.erase(std::unique(knownFrameRates.begin(), knownFrameRates.end(),
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100606 Fps::EqualsWithMargin()),
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700607 knownFrameRates.end());
608 return knownFrameRates;
609}
610
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100611Fps RefreshRateConfigs::findClosestKnownFrameRate(Fps frameRate) const {
612 if (frameRate.lessThanOrEqualWithMargin(*mKnownFrameRates.begin())) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700613 return *mKnownFrameRates.begin();
614 }
615
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100616 if (frameRate.greaterThanOrEqualWithMargin(*std::prev(mKnownFrameRates.end()))) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700617 return *std::prev(mKnownFrameRates.end());
618 }
619
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100620 auto lowerBound = std::lower_bound(mKnownFrameRates.begin(), mKnownFrameRates.end(), frameRate,
621 Fps::comparesLess);
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700622
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100623 const auto distance1 = std::abs((frameRate.getValue() - lowerBound->getValue()));
624 const auto distance2 = std::abs((frameRate.getValue() - std::prev(lowerBound)->getValue()));
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700625 return distance1 < distance2 ? *lowerBound : *std::prev(lowerBound);
626}
627
Ana Krulecb9afd792020-06-11 13:16:15 -0700628RefreshRateConfigs::KernelIdleTimerAction RefreshRateConfigs::getIdleTimerAction() const {
629 std::lock_guard lock(mLock);
630 const auto& deviceMin = getMinRefreshRate();
631 const auto& minByPolicy = getMinRefreshRateByPolicyLocked();
632 const auto& maxByPolicy = getMaxRefreshRateByPolicyLocked();
633
634 // Kernel idle timer will set the refresh rate to the device min. If DisplayManager says that
635 // the min allowed refresh rate is higher than the device min, we do not want to enable the
636 // timer.
637 if (deviceMin < minByPolicy) {
638 return RefreshRateConfigs::KernelIdleTimerAction::TurnOff;
639 }
640 if (minByPolicy == maxByPolicy) {
641 // Do not sent the call to toggle off kernel idle timer if the device min and policy min and
642 // max are all the same. This saves us extra unnecessary calls to sysprop.
643 if (deviceMin == minByPolicy) {
644 return RefreshRateConfigs::KernelIdleTimerAction::NoChange;
645 }
646 return RefreshRateConfigs::KernelIdleTimerAction::TurnOff;
647 }
648 // Turn on the timer in all other cases.
649 return RefreshRateConfigs::KernelIdleTimerAction::TurnOn;
650}
651
Ady Abraham62f216c2020-10-13 19:07:23 -0700652void RefreshRateConfigs::setPreferredRefreshRateForUid(FrameRateOverride frameRateOverride) {
653 if (frameRateOverride.frameRateHz > 0 && frameRateOverride.frameRateHz < 1) {
Ady Abraham0bb6a472020-10-12 10:22:13 -0700654 return;
655 }
656
657 std::lock_guard lock(mLock);
Ady Abraham62f216c2020-10-13 19:07:23 -0700658 if (frameRateOverride.frameRateHz != 0) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100659 mPreferredRefreshRateForUid[frameRateOverride.uid] = Fps(frameRateOverride.frameRateHz);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700660 } else {
Ady Abraham62f216c2020-10-13 19:07:23 -0700661 mPreferredRefreshRateForUid.erase(frameRateOverride.uid);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700662 }
663}
664
665int RefreshRateConfigs::getRefreshRateDividerForUid(uid_t uid) const {
Ady Abraham0bb6a472020-10-12 10:22:13 -0700666 std::lock_guard lock(mLock);
667
668 const auto iter = mPreferredRefreshRateForUid.find(uid);
669 if (iter == mPreferredRefreshRateForUid.end()) {
670 return 1;
671 }
672
Ady Abraham62f216c2020-10-13 19:07:23 -0700673 // This calculation needs to be in sync with the java code
674 // in DisplayManagerService.getDisplayInfoForFrameRateOverride
675 constexpr float kThreshold = 0.1f;
Ady Abraham0bb6a472020-10-12 10:22:13 -0700676 const auto refreshRateHz = iter->second;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100677 const auto numPeriods = mCurrentRefreshRate->getFps().getValue() / refreshRateHz.getValue();
Ady Abraham0bb6a472020-10-12 10:22:13 -0700678 const auto numPeriodsRounded = std::round(numPeriods);
679 if (std::abs(numPeriods - numPeriodsRounded) > kThreshold) {
680 return 1;
681 }
682
Ady Abraham62f216c2020-10-13 19:07:23 -0700683 return static_cast<int>(numPeriodsRounded);
684}
685
686std::vector<FrameRateOverride> RefreshRateConfigs::getFrameRateOverrides() {
687 std::lock_guard lock(mLock);
688 std::vector<FrameRateOverride> overrides;
689 overrides.reserve(mPreferredRefreshRateForUid.size());
690
691 for (const auto [uid, frameRate] : mPreferredRefreshRateForUid) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100692 overrides.emplace_back(FrameRateOverride{uid, frameRate.getValue()});
Ady Abraham62f216c2020-10-13 19:07:23 -0700693 }
694
695 return overrides;
Ady Abraham0bb6a472020-10-12 10:22:13 -0700696}
697
Marin Shalamanovba421a82020-11-10 21:49:26 +0100698void RefreshRateConfigs::dump(std::string& result) const {
699 std::lock_guard lock(mLock);
700 base::StringAppendF(&result, "DesiredDisplayConfigSpecs (DisplayManager): %s\n\n",
701 mDisplayManagerPolicy.toString().c_str());
702 scheduler::RefreshRateConfigs::Policy currentPolicy = *getCurrentPolicyLocked();
703 if (mOverridePolicy && currentPolicy != mDisplayManagerPolicy) {
704 base::StringAppendF(&result, "DesiredDisplayConfigSpecs (Override): %s\n\n",
705 currentPolicy.toString().c_str());
706 }
707
708 auto config = mCurrentRefreshRate->hwcConfig;
709 base::StringAppendF(&result, "Current config: %s\n", mCurrentRefreshRate->toString().c_str());
710
711 result.append("Refresh rates:\n");
712 for (const auto& [id, refreshRate] : mRefreshRates) {
713 config = refreshRate->hwcConfig;
714 base::StringAppendF(&result, "\t%s\n", refreshRate->toString().c_str());
715 }
716
717 result.append("\n");
718}
719
Ady Abraham2139f732019-11-13 18:56:40 -0800720} // namespace android::scheduler