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 | |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 20 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 21 | #pragma clang diagnostic push |
| 22 | #pragma clang diagnostic ignored "-Wextra" |
| 23 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 24 | #include <chrono> |
| 25 | #include <cmath> |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 26 | |
| 27 | #include <android-base/properties.h> |
| 28 | #include <android-base/stringprintf.h> |
| 29 | #include <ftl/enum.h> |
| 30 | #include <utils/Trace.h> |
| 31 | |
Ady Abraham | 4899ff8 | 2021-01-06 13:53:29 -0800 | [diff] [blame] | 32 | #include "../SurfaceFlingerProperties.h" |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 33 | #include "RefreshRateConfigs.h" |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 34 | |
Ady Abraham | 5b8afb5a | 2020-03-06 14:57:26 -0800 | [diff] [blame] | 35 | #undef LOG_TAG |
| 36 | #define LOG_TAG "RefreshRateConfigs" |
| 37 | |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 38 | namespace android::scheduler { |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 39 | namespace { |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 40 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 41 | struct RefreshRateScore { |
| 42 | DisplayModeIterator modeIt; |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 43 | float overallScore; |
| 44 | struct { |
Ady Abraham | 62f51d9 | 2022-08-24 22:20:22 +0000 | [diff] [blame^] | 45 | float modeBelowThreshold; |
| 46 | float modeAboveThreshold; |
| 47 | } fixedRateBelowThresholdLayersScore; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | template <typename Iterator> |
| 51 | const DisplayModePtr& getMaxScoreRefreshRate(Iterator begin, Iterator end) { |
| 52 | const auto it = |
| 53 | std::max_element(begin, end, [](RefreshRateScore max, RefreshRateScore current) { |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 54 | const auto& [modeIt, overallScore, _] = current; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 55 | |
| 56 | std::string name = to_string(modeIt->second->getFps()); |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 57 | ALOGV("%s scores %.2f", name.c_str(), overallScore); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 58 | |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 59 | ATRACE_INT(name.c_str(), static_cast<int>(std::round(overallScore * 100))); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 60 | |
| 61 | constexpr float kEpsilon = 0.0001f; |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 62 | return overallScore > max.overallScore * (1 + kEpsilon); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 63 | }); |
| 64 | |
| 65 | return it->modeIt->second; |
| 66 | } |
| 67 | |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 68 | constexpr RefreshRateConfigs::GlobalSignals kNoSignals; |
| 69 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 70 | std::string formatLayerInfo(const RefreshRateConfigs::LayerRequirement& layer, float weight) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 71 | return base::StringPrintf("%s (type=%s, weight=%.2f, seamlessness=%s) %s", layer.name.c_str(), |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 72 | ftl::enum_string(layer.vote).c_str(), weight, |
| 73 | ftl::enum_string(layer.seamlessness).c_str(), |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 74 | to_string(layer.desiredRefreshRate).c_str()); |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 75 | } |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 76 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 77 | std::vector<Fps> constructKnownFrameRates(const DisplayModes& modes) { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 78 | std::vector<Fps> knownFrameRates = {24_Hz, 30_Hz, 45_Hz, 60_Hz, 72_Hz}; |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 79 | knownFrameRates.reserve(knownFrameRates.size() + modes.size()); |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 80 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 81 | // Add all supported refresh rates. |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 82 | for (const auto& [id, mode] : modes) { |
| 83 | knownFrameRates.push_back(mode->getFps()); |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 86 | // Sort and remove duplicates. |
| 87 | std::sort(knownFrameRates.begin(), knownFrameRates.end(), isStrictlyLess); |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 88 | knownFrameRates.erase(std::unique(knownFrameRates.begin(), knownFrameRates.end(), |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 89 | isApproxEqual), |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 90 | knownFrameRates.end()); |
| 91 | return knownFrameRates; |
| 92 | } |
| 93 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 94 | // The Filter is a `bool(const DisplayMode&)` predicate. |
| 95 | template <typename Filter> |
| 96 | std::vector<DisplayModeIterator> sortByRefreshRate(const DisplayModes& modes, Filter&& filter) { |
| 97 | std::vector<DisplayModeIterator> sortedModes; |
| 98 | sortedModes.reserve(modes.size()); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 99 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 100 | for (auto it = modes.begin(); it != modes.end(); ++it) { |
| 101 | const auto& [id, mode] = *it; |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 102 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 103 | if (filter(*mode)) { |
| 104 | ALOGV("%s: including mode %d", __func__, id.value()); |
| 105 | sortedModes.push_back(it); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | std::sort(sortedModes.begin(), sortedModes.end(), [](auto it1, auto it2) { |
| 110 | const auto& mode1 = it1->second; |
| 111 | const auto& mode2 = it2->second; |
| 112 | |
| 113 | if (mode1->getVsyncPeriod() == mode2->getVsyncPeriod()) { |
| 114 | return mode1->getGroup() > mode2->getGroup(); |
| 115 | } |
| 116 | |
| 117 | return mode1->getVsyncPeriod() > mode2->getVsyncPeriod(); |
| 118 | }); |
| 119 | |
| 120 | return sortedModes; |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 121 | } |
| 122 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 123 | bool canModesSupportFrameRateOverride(const std::vector<DisplayModeIterator>& sortedModes) { |
| 124 | for (const auto it1 : sortedModes) { |
| 125 | const auto& mode1 = it1->second; |
| 126 | for (const auto it2 : sortedModes) { |
| 127 | const auto& mode2 = it2->second; |
| 128 | |
| 129 | if (RefreshRateConfigs::getFrameRateDivisor(mode1->getFps(), mode2->getFps()) >= 2) { |
| 130 | return true; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | } // namespace |
| 138 | |
Marin Shalamanov | b6674e7 | 2020-11-06 13:05:57 +0100 | [diff] [blame] | 139 | std::string RefreshRateConfigs::Policy::toString() const { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 140 | return base::StringPrintf("{defaultModeId=%d, allowGroupSwitching=%s" |
| 141 | ", primaryRange=%s, appRequestRange=%s}", |
| 142 | defaultMode.value(), allowGroupSwitching ? "true" : "false", |
Dominik Laskowski | 953b7fd | 2022-01-08 19:34:59 -0800 | [diff] [blame] | 143 | to_string(primaryRange).c_str(), to_string(appRequestRange).c_str()); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 146 | std::pair<nsecs_t, nsecs_t> RefreshRateConfigs::getDisplayFrames(nsecs_t layerPeriod, |
| 147 | nsecs_t displayPeriod) const { |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 148 | auto [quotient, remainder] = std::div(layerPeriod, displayPeriod); |
| 149 | if (remainder <= MARGIN_FOR_PERIOD_CALCULATION || |
| 150 | std::abs(remainder - displayPeriod) <= MARGIN_FOR_PERIOD_CALCULATION) { |
| 151 | quotient++; |
| 152 | remainder = 0; |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 155 | return {quotient, remainder}; |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 158 | float RefreshRateConfigs::calculateNonExactMatchingLayerScoreLocked(const LayerRequirement& layer, |
| 159 | Fps refreshRate) const { |
Marin Shalamanov | 15a0fc6 | 2021-08-16 18:20:21 +0200 | [diff] [blame] | 160 | constexpr float kScoreForFractionalPairs = .8f; |
| 161 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 162 | const auto displayPeriod = refreshRate.getPeriodNsecs(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 163 | const auto layerPeriod = layer.desiredRefreshRate.getPeriodNsecs(); |
| 164 | if (layer.vote == LayerVoteType::ExplicitDefault) { |
| 165 | // Find the actual rate the layer will render, assuming |
Marin Shalamanov | 15a0fc6 | 2021-08-16 18:20:21 +0200 | [diff] [blame] | 166 | // that layerPeriod is the minimal period to render a frame. |
| 167 | // For example if layerPeriod is 20ms and displayPeriod is 16ms, |
| 168 | // then the actualLayerPeriod will be 32ms, because it is the |
| 169 | // smallest multiple of the display period which is >= layerPeriod. |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 170 | auto actualLayerPeriod = displayPeriod; |
| 171 | int multiplier = 1; |
| 172 | while (layerPeriod > actualLayerPeriod + MARGIN_FOR_PERIOD_CALCULATION) { |
| 173 | multiplier++; |
| 174 | actualLayerPeriod = displayPeriod * multiplier; |
| 175 | } |
Marin Shalamanov | 15a0fc6 | 2021-08-16 18:20:21 +0200 | [diff] [blame] | 176 | |
| 177 | // Because of the threshold we used above it's possible that score is slightly |
| 178 | // above 1. |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 179 | return std::min(1.0f, |
| 180 | static_cast<float>(layerPeriod) / static_cast<float>(actualLayerPeriod)); |
| 181 | } |
| 182 | |
| 183 | if (layer.vote == LayerVoteType::ExplicitExactOrMultiple || |
| 184 | layer.vote == LayerVoteType::Heuristic) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 185 | if (isFractionalPairOrMultiple(refreshRate, layer.desiredRefreshRate)) { |
Ady Abraham | 05243be | 2021-09-16 15:58:52 -0700 | [diff] [blame] | 186 | return kScoreForFractionalPairs; |
Marin Shalamanov | 15a0fc6 | 2021-08-16 18:20:21 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 189 | // Calculate how many display vsyncs we need to present a single frame for this |
| 190 | // layer |
| 191 | const auto [displayFramesQuotient, displayFramesRemainder] = |
| 192 | getDisplayFrames(layerPeriod, displayPeriod); |
| 193 | static constexpr size_t MAX_FRAMES_TO_FIT = 10; // Stop calculating when score < 0.1 |
| 194 | if (displayFramesRemainder == 0) { |
| 195 | // Layer desired refresh rate matches the display rate. |
Ady Abraham | 05243be | 2021-09-16 15:58:52 -0700 | [diff] [blame] | 196 | return 1.0f; |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | if (displayFramesQuotient == 0) { |
| 200 | // Layer desired refresh rate is higher than the display rate. |
| 201 | return (static_cast<float>(layerPeriod) / static_cast<float>(displayPeriod)) * |
| 202 | (1.0f / (MAX_FRAMES_TO_FIT + 1)); |
| 203 | } |
| 204 | |
| 205 | // Layer desired refresh rate is lower than the display rate. Check how well it fits |
| 206 | // the cadence. |
| 207 | auto diff = std::abs(displayFramesRemainder - (displayPeriod - displayFramesRemainder)); |
| 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 | |
Ady Abraham | 05243be | 2021-09-16 15:58:52 -0700 | [diff] [blame] | 214 | return (1.0f / iter); |
| 215 | } |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 220 | float RefreshRateConfigs::calculateLayerScoreLocked(const LayerRequirement& layer, Fps refreshRate, |
Ady Abraham | 05243be | 2021-09-16 15:58:52 -0700 | [diff] [blame] | 221 | bool isSeamlessSwitch) const { |
Ady Abraham | 05243be | 2021-09-16 15:58:52 -0700 | [diff] [blame] | 222 | // Slightly prefer seamless switches. |
| 223 | constexpr float kSeamedSwitchPenalty = 0.95f; |
| 224 | const float seamlessness = isSeamlessSwitch ? 1.0f : kSeamedSwitchPenalty; |
| 225 | |
| 226 | // If the layer wants Max, give higher score to the higher refresh rate |
| 227 | if (layer.vote == LayerVoteType::Max) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 228 | const auto& maxRefreshRate = mAppRequestRefreshRates.back()->second; |
| 229 | const auto ratio = refreshRate.getValue() / maxRefreshRate->getFps().getValue(); |
Ady Abraham | 05243be | 2021-09-16 15:58:52 -0700 | [diff] [blame] | 230 | // use ratio^2 to get a lower score the more we get further from peak |
| 231 | return ratio * ratio; |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 234 | if (layer.vote == LayerVoteType::ExplicitExact) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 235 | const int divisor = getFrameRateDivisor(refreshRate, layer.desiredRefreshRate); |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 236 | if (mSupportsFrameRateOverrideByContent) { |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 237 | // Since we support frame rate override, allow refresh rates which are |
| 238 | // multiples of the layer's request, as those apps would be throttled |
| 239 | // down to run at the desired refresh rate. |
Ady Abraham | cc31549 | 2022-02-17 17:06:39 -0800 | [diff] [blame] | 240 | return divisor > 0; |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Ady Abraham | cc31549 | 2022-02-17 17:06:39 -0800 | [diff] [blame] | 243 | return divisor == 1; |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Ady Abraham | cc31549 | 2022-02-17 17:06:39 -0800 | [diff] [blame] | 246 | // If the layer frame rate is a divisor of the refresh rate it should score |
Ady Abraham | 05243be | 2021-09-16 15:58:52 -0700 | [diff] [blame] | 247 | // the highest score. |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 248 | if (getFrameRateDivisor(refreshRate, layer.desiredRefreshRate) > 0) { |
Ady Abraham | 05243be | 2021-09-16 15:58:52 -0700 | [diff] [blame] | 249 | return 1.0f * seamlessness; |
| 250 | } |
| 251 | |
Ady Abraham | cc31549 | 2022-02-17 17:06:39 -0800 | [diff] [blame] | 252 | // The layer frame rate is not a divisor of the refresh rate, |
Ady Abraham | 05243be | 2021-09-16 15:58:52 -0700 | [diff] [blame] | 253 | // there is a small penalty attached to the score to favor the frame rates |
| 254 | // the exactly matches the display refresh rate or a multiple. |
Ady Abraham | 1c59550 | 2022-01-13 21:58:32 -0800 | [diff] [blame] | 255 | constexpr float kNonExactMatchingPenalty = 0.95f; |
Ady Abraham | 05243be | 2021-09-16 15:58:52 -0700 | [diff] [blame] | 256 | return calculateNonExactMatchingLayerScoreLocked(layer, refreshRate) * seamlessness * |
| 257 | kNonExactMatchingPenalty; |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 260 | auto RefreshRateConfigs::getBestRefreshRate(const std::vector<LayerRequirement>& layers, |
| 261 | GlobalSignals signals) const |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 262 | -> std::pair<DisplayModePtr, GlobalSignals> { |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 263 | std::lock_guard lock(mLock); |
| 264 | |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 265 | if (mGetBestRefreshRateCache && |
| 266 | mGetBestRefreshRateCache->arguments == std::make_pair(layers, signals)) { |
| 267 | return mGetBestRefreshRateCache->result; |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 268 | } |
| 269 | |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 270 | const auto result = getBestRefreshRateLocked(layers, signals); |
| 271 | mGetBestRefreshRateCache = GetBestRefreshRateCache{{layers, signals}, result}; |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 272 | return result; |
| 273 | } |
| 274 | |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 275 | auto RefreshRateConfigs::getBestRefreshRateLocked(const std::vector<LayerRequirement>& layers, |
| 276 | GlobalSignals signals) const |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 277 | -> std::pair<DisplayModePtr, GlobalSignals> { |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 278 | using namespace fps_approx_ops; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 279 | ATRACE_CALL(); |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 280 | ALOGV("%s: %zu layers", __func__, layers.size()); |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 281 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 282 | int noVoteLayers = 0; |
| 283 | int minVoteLayers = 0; |
| 284 | int maxVoteLayers = 0; |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 285 | int explicitDefaultVoteLayers = 0; |
| 286 | int explicitExactOrMultipleVoteLayers = 0; |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 287 | int explicitExact = 0; |
Ady Abraham | 6fb599b | 2020-03-05 13:48:22 -0800 | [diff] [blame] | 288 | float maxExplicitWeight = 0; |
Marin Shalamanov | ae0b535 | 2021-03-24 12:56:08 +0100 | [diff] [blame] | 289 | int seamedFocusedLayers = 0; |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 290 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 291 | for (const auto& layer : layers) { |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 292 | switch (layer.vote) { |
| 293 | case LayerVoteType::NoVote: |
| 294 | noVoteLayers++; |
| 295 | break; |
| 296 | case LayerVoteType::Min: |
| 297 | minVoteLayers++; |
| 298 | break; |
| 299 | case LayerVoteType::Max: |
| 300 | maxVoteLayers++; |
| 301 | break; |
| 302 | case LayerVoteType::ExplicitDefault: |
| 303 | explicitDefaultVoteLayers++; |
| 304 | maxExplicitWeight = std::max(maxExplicitWeight, layer.weight); |
| 305 | break; |
| 306 | case LayerVoteType::ExplicitExactOrMultiple: |
| 307 | explicitExactOrMultipleVoteLayers++; |
| 308 | maxExplicitWeight = std::max(maxExplicitWeight, layer.weight); |
| 309 | break; |
| 310 | case LayerVoteType::ExplicitExact: |
| 311 | explicitExact++; |
| 312 | maxExplicitWeight = std::max(maxExplicitWeight, layer.weight); |
| 313 | break; |
| 314 | case LayerVoteType::Heuristic: |
| 315 | break; |
Ady Abraham | 6fb599b | 2020-03-05 13:48:22 -0800 | [diff] [blame] | 316 | } |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 317 | |
Marin Shalamanov | ae0b535 | 2021-03-24 12:56:08 +0100 | [diff] [blame] | 318 | if (layer.seamlessness == Seamlessness::SeamedAndSeamless && layer.focused) { |
| 319 | seamedFocusedLayers++; |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 320 | } |
Ady Abraham | 6fb599b | 2020-03-05 13:48:22 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 323 | const bool hasExplicitVoteLayers = explicitDefaultVoteLayers > 0 || |
| 324 | explicitExactOrMultipleVoteLayers > 0 || explicitExact > 0; |
Alec Mouri | 11232a2 | 2020-05-14 18:06:25 -0700 | [diff] [blame] | 325 | |
Marin Shalamanov | 8cd8a99 | 2021-09-14 23:22:49 +0200 | [diff] [blame] | 326 | const Policy* policy = getCurrentPolicyLocked(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 327 | const auto& defaultMode = mDisplayModes.get(policy->defaultMode)->get(); |
Marin Shalamanov | 8cd8a99 | 2021-09-14 23:22:49 +0200 | [diff] [blame] | 328 | // If the default mode group is different from the group of current mode, |
| 329 | // this means a layer requesting a seamed mode switch just disappeared and |
| 330 | // we should switch back to the default group. |
| 331 | // However if a seamed layer is still present we anchor around the group |
| 332 | // of the current mode, in order to prevent unnecessary seamed mode switches |
| 333 | // (e.g. when pausing a video playback). |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 334 | const auto anchorGroup = |
| 335 | seamedFocusedLayers > 0 ? mActiveModeIt->second->getGroup() : defaultMode->getGroup(); |
Marin Shalamanov | 8cd8a99 | 2021-09-14 23:22:49 +0200 | [diff] [blame] | 336 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 337 | // Consider the touch event if there are no Explicit* layers. Otherwise wait until after we've |
| 338 | // selected a refresh rate to see if we should apply touch boost. |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 339 | if (signals.touch && !hasExplicitVoteLayers) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 340 | const DisplayModePtr& max = getMaxRefreshRateByPolicyLocked(anchorGroup); |
| 341 | ALOGV("TouchBoost - choose %s", to_string(max->getFps()).c_str()); |
| 342 | return {max, GlobalSignals{.touch = true}}; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Alec Mouri | 11232a2 | 2020-05-14 18:06:25 -0700 | [diff] [blame] | 345 | // If the primary range consists of a single refresh rate then we can only |
| 346 | // move out the of range if layers explicitly request a different refresh |
| 347 | // rate. |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 348 | const bool primaryRangeIsSingleRate = |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 349 | isApproxEqual(policy->primaryRange.min, policy->primaryRange.max); |
Alec Mouri | 11232a2 | 2020-05-14 18:06:25 -0700 | [diff] [blame] | 350 | |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 351 | if (!signals.touch && signals.idle && !(primaryRangeIsSingleRate && hasExplicitVoteLayers)) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 352 | const DisplayModePtr& min = getMinRefreshRateByPolicyLocked(); |
| 353 | ALOGV("Idle - choose %s", to_string(min->getFps()).c_str()); |
| 354 | return {min, GlobalSignals{.idle = true}}; |
Steven Thomas | bb37432 | 2020-04-28 22:47:16 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Steven Thomas | debafed | 2020-05-18 17:30:35 -0700 | [diff] [blame] | 357 | if (layers.empty() || noVoteLayers == layers.size()) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 358 | const DisplayModePtr& max = getMaxRefreshRateByPolicyLocked(anchorGroup); |
| 359 | ALOGV("no layers with votes - choose %s", to_string(max->getFps()).c_str()); |
| 360 | return {max, kNoSignals}; |
Steven Thomas | bb37432 | 2020-04-28 22:47:16 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 363 | // Only if all layers want Min we should return Min |
| 364 | if (noVoteLayers + minVoteLayers == layers.size()) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 365 | const DisplayModePtr& min = getMinRefreshRateByPolicyLocked(); |
| 366 | ALOGV("all layers Min - choose %s", to_string(min->getFps()).c_str()); |
| 367 | return {min, kNoSignals}; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 370 | // Find the best refresh rate based on score |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 371 | std::vector<RefreshRateScore> scores; |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 372 | scores.reserve(mAppRequestRefreshRates.size()); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 373 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 374 | for (const DisplayModeIterator modeIt : mAppRequestRefreshRates) { |
| 375 | scores.emplace_back(RefreshRateScore{modeIt, 0.0f}); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | for (const auto& layer : layers) { |
rnlee | 3bd61066 | 2021-06-23 16:27:57 -0700 | [diff] [blame] | 379 | ALOGV("Calculating score for %s (%s, weight %.2f, desired %.2f) ", layer.name.c_str(), |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 380 | ftl::enum_string(layer.vote).c_str(), layer.weight, |
rnlee | 3bd61066 | 2021-06-23 16:27:57 -0700 | [diff] [blame] | 381 | layer.desiredRefreshRate.getValue()); |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 382 | if (layer.vote == LayerVoteType::NoVote || layer.vote == LayerVoteType::Min) { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 383 | continue; |
| 384 | } |
| 385 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 386 | const auto weight = layer.weight; |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 387 | |
Ady Abraham | 62f51d9 | 2022-08-24 22:20:22 +0000 | [diff] [blame^] | 388 | for (auto& [modeIt, overallScore, fixedRateBelowThresholdLayersScore] : scores) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 389 | const auto& [id, mode] = *modeIt; |
| 390 | const bool isSeamlessSwitch = mode->getGroup() == mActiveModeIt->second->getGroup(); |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 391 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 392 | if (layer.seamlessness == Seamlessness::OnlySeamless && !isSeamlessSwitch) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 393 | ALOGV("%s ignores %s to avoid non-seamless switch. Current mode = %s", |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 394 | formatLayerInfo(layer, weight).c_str(), to_string(*mode).c_str(), |
| 395 | to_string(*mActiveModeIt->second).c_str()); |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 396 | continue; |
| 397 | } |
| 398 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 399 | if (layer.seamlessness == Seamlessness::SeamedAndSeamless && !isSeamlessSwitch && |
| 400 | !layer.focused) { |
| 401 | ALOGV("%s ignores %s because it's not focused and the switch is going to be seamed." |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 402 | " Current mode = %s", |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 403 | formatLayerInfo(layer, weight).c_str(), to_string(*mode).c_str(), |
| 404 | to_string(*mActiveModeIt->second).c_str()); |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 405 | continue; |
| 406 | } |
| 407 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 408 | // Layers with default seamlessness vote for the current mode group if |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 409 | // there are layers with seamlessness=SeamedAndSeamless and for the default |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 410 | // mode group otherwise. In second case, if the current mode group is different |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 411 | // from the default, this means a layer with seamlessness=SeamedAndSeamless has just |
| 412 | // disappeared. |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 413 | const bool isInPolicyForDefault = mode->getGroup() == anchorGroup; |
Marin Shalamanov | ae0b535 | 2021-03-24 12:56:08 +0100 | [diff] [blame] | 414 | if (layer.seamlessness == Seamlessness::Default && !isInPolicyForDefault) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 415 | ALOGV("%s ignores %s. Current mode = %s", formatLayerInfo(layer, weight).c_str(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 416 | to_string(*mode).c_str(), to_string(*mActiveModeIt->second).c_str()); |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 417 | continue; |
| 418 | } |
| 419 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 420 | const bool inPrimaryRange = policy->primaryRange.includes(mode->getFps()); |
Alec Mouri | 11232a2 | 2020-05-14 18:06:25 -0700 | [diff] [blame] | 421 | if ((primaryRangeIsSingleRate || !inPrimaryRange) && |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 422 | !(layer.focused && |
| 423 | (layer.vote == LayerVoteType::ExplicitDefault || |
| 424 | layer.vote == LayerVoteType::ExplicitExact))) { |
Ady Abraham | 20c029c | 2020-07-06 12:58:05 -0700 | [diff] [blame] | 425 | // Only focused layers with ExplicitDefault frame rate settings are allowed to score |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 426 | // refresh rates outside the primary range. |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 427 | continue; |
| 428 | } |
| 429 | |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 430 | const float layerScore = |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 431 | calculateLayerScoreLocked(layer, mode->getFps(), isSeamlessSwitch); |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 432 | const float weightedLayerScore = weight * layerScore; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 433 | |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 434 | // Layer with fixed source has a special consideration depends on the |
| 435 | // mConfig.frameRateMultipleThreshold. We don't want these layers to score |
| 436 | // refresh rates above the threshold, but we also don't want to favor the lower |
| 437 | // ones by having a greater number of layers scoring them. Instead, we calculate |
| 438 | // the score independently for these layers and later decide which |
| 439 | // refresh rates to add it. For example, desired 24 fps with 120 Hz threshold should not |
| 440 | // score 120 Hz, but desired 60 fps should contribute to the score. |
| 441 | const bool fixedSourceLayer = [](LayerVoteType vote) { |
| 442 | switch (vote) { |
| 443 | case LayerVoteType::ExplicitExactOrMultiple: |
| 444 | case LayerVoteType::Heuristic: |
| 445 | return true; |
| 446 | case LayerVoteType::NoVote: |
| 447 | case LayerVoteType::Min: |
| 448 | case LayerVoteType::Max: |
| 449 | case LayerVoteType::ExplicitDefault: |
| 450 | case LayerVoteType::ExplicitExact: |
| 451 | return false; |
| 452 | } |
| 453 | }(layer.vote); |
Ady Abraham | 62f51d9 | 2022-08-24 22:20:22 +0000 | [diff] [blame^] | 454 | const bool layerBelowThreshold = mConfig.frameRateMultipleThreshold != 0 && |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 455 | layer.desiredRefreshRate < |
| 456 | Fps::fromValue(mConfig.frameRateMultipleThreshold / 2); |
Ady Abraham | 62f51d9 | 2022-08-24 22:20:22 +0000 | [diff] [blame^] | 457 | const bool modeAboveThreshold = layerBelowThreshold && |
| 458 | mode->getFps() >= Fps::fromValue(mConfig.frameRateMultipleThreshold); |
| 459 | if (fixedSourceLayer && layerBelowThreshold) { |
| 460 | if (modeAboveThreshold) { |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 461 | ALOGV("%s gives %s fixed source (above threshold) score of %.4f", |
| 462 | formatLayerInfo(layer, weight).c_str(), to_string(mode->getFps()).c_str(), |
| 463 | layerScore); |
Ady Abraham | 62f51d9 | 2022-08-24 22:20:22 +0000 | [diff] [blame^] | 464 | fixedRateBelowThresholdLayersScore.modeAboveThreshold += weightedLayerScore; |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 465 | } else { |
| 466 | ALOGV("%s gives %s fixed source (below threshold) score of %.4f", |
| 467 | formatLayerInfo(layer, weight).c_str(), to_string(mode->getFps()).c_str(), |
| 468 | layerScore); |
Ady Abraham | 62f51d9 | 2022-08-24 22:20:22 +0000 | [diff] [blame^] | 469 | fixedRateBelowThresholdLayersScore.modeBelowThreshold += weightedLayerScore; |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 470 | } |
| 471 | } else { |
| 472 | ALOGV("%s gives %s score of %.4f", formatLayerInfo(layer, weight).c_str(), |
| 473 | to_string(mode->getFps()).c_str(), layerScore); |
| 474 | overallScore += weightedLayerScore; |
| 475 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 479 | // We want to find the best refresh rate without the fixed source layers, |
Ady Abraham | 62f51d9 | 2022-08-24 22:20:22 +0000 | [diff] [blame^] | 480 | // so we could know whether we should add the modeAboveThreshold scores or not. |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 481 | // If the best refresh rate is already above the threshold, it means that |
| 482 | // some non-fixed source layers already scored it, so we can just add the score |
| 483 | // for all fixed source layers, even the ones that are above the threshold. |
| 484 | const bool maxScoreAboveThreshold = [&] { |
| 485 | if (mConfig.frameRateMultipleThreshold == 0 || scores.empty()) { |
| 486 | return false; |
| 487 | } |
| 488 | |
| 489 | const auto maxScoreIt = |
| 490 | std::max_element(scores.begin(), scores.end(), |
| 491 | [](RefreshRateScore max, RefreshRateScore current) { |
| 492 | const auto& [modeIt, overallScore, _] = current; |
| 493 | return overallScore > max.overallScore; |
| 494 | }); |
| 495 | ALOGV("%s is the best refresh rate without fixed source layers. It is %s the threshold for " |
| 496 | "refresh rate multiples", |
| 497 | to_string(maxScoreIt->modeIt->second->getFps()).c_str(), |
| 498 | maxScoreAboveThreshold ? "above" : "below"); |
| 499 | return maxScoreIt->modeIt->second->getFps() >= |
| 500 | Fps::fromValue(mConfig.frameRateMultipleThreshold); |
| 501 | }(); |
| 502 | |
| 503 | // Now we can add the fixed rate layers score |
Ady Abraham | 62f51d9 | 2022-08-24 22:20:22 +0000 | [diff] [blame^] | 504 | for (auto& [modeIt, overallScore, fixedRateBelowThresholdLayersScore] : scores) { |
| 505 | overallScore += fixedRateBelowThresholdLayersScore.modeBelowThreshold; |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 506 | if (maxScoreAboveThreshold) { |
Ady Abraham | 62f51d9 | 2022-08-24 22:20:22 +0000 | [diff] [blame^] | 507 | overallScore += fixedRateBelowThresholdLayersScore.modeAboveThreshold; |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 508 | } |
| 509 | ALOGV("%s adjusted overallScore is %.4f", to_string(modeIt->second->getFps()).c_str(), |
| 510 | overallScore); |
| 511 | } |
| 512 | |
| 513 | // Now that we scored all the refresh rates we need to pick the one that got the highest |
| 514 | // overallScore. In case of a tie we will pick the higher refresh rate if any of the layers |
| 515 | // wanted Max, or the lower otherwise. |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 516 | const DisplayModePtr& bestRefreshRate = maxVoteLayers > 0 |
| 517 | ? getMaxScoreRefreshRate(scores.rbegin(), scores.rend()) |
| 518 | : getMaxScoreRefreshRate(scores.begin(), scores.end()); |
Ady Abraham | 3470210 | 2020-02-10 14:12:05 -0800 | [diff] [blame] | 519 | |
Alec Mouri | 11232a2 | 2020-05-14 18:06:25 -0700 | [diff] [blame] | 520 | if (primaryRangeIsSingleRate) { |
| 521 | // If we never scored any layers, then choose the rate from the primary |
| 522 | // range instead of picking a random score from the app range. |
| 523 | if (std::all_of(scores.begin(), scores.end(), |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 524 | [](RefreshRateScore score) { return score.overallScore == 0; })) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 525 | const DisplayModePtr& max = getMaxRefreshRateByPolicyLocked(anchorGroup); |
| 526 | ALOGV("layers not scored - choose %s", to_string(max->getFps()).c_str()); |
| 527 | return {max, kNoSignals}; |
Alec Mouri | 11232a2 | 2020-05-14 18:06:25 -0700 | [diff] [blame] | 528 | } else { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 529 | return {bestRefreshRate, kNoSignals}; |
Alec Mouri | 11232a2 | 2020-05-14 18:06:25 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 533 | // Consider the touch event if there are no ExplicitDefault layers. ExplicitDefault are mostly |
| 534 | // interactive (as opposed to ExplicitExactOrMultiple) and therefore if those posted an explicit |
| 535 | // vote we should not change it if we get a touch event. Only apply touch boost if it will |
| 536 | // actually increase the refresh rate over the normal selection. |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 537 | const DisplayModePtr& touchRefreshRate = getMaxRefreshRateByPolicyLocked(anchorGroup); |
Alec Mouri | 11232a2 | 2020-05-14 18:06:25 -0700 | [diff] [blame] | 538 | |
Ady Abraham | 5e4e983 | 2021-06-14 13:40:56 -0700 | [diff] [blame] | 539 | const bool touchBoostForExplicitExact = [&] { |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 540 | if (mSupportsFrameRateOverrideByContent) { |
Ady Abraham | 5e4e983 | 2021-06-14 13:40:56 -0700 | [diff] [blame] | 541 | // Enable touch boost if there are other layers besides exact |
| 542 | return explicitExact + noVoteLayers != layers.size(); |
| 543 | } else { |
| 544 | // Enable touch boost if there are no exact layers |
| 545 | return explicitExact == 0; |
| 546 | } |
| 547 | }(); |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 548 | |
| 549 | using fps_approx_ops::operator<; |
| 550 | |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 551 | if (signals.touch && explicitDefaultVoteLayers == 0 && touchBoostForExplicitExact && |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 552 | bestRefreshRate->getFps() < touchRefreshRate->getFps()) { |
| 553 | ALOGV("TouchBoost - choose %s", to_string(touchRefreshRate->getFps()).c_str()); |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 554 | return {touchRefreshRate, GlobalSignals{.touch = true}}; |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 557 | return {bestRefreshRate, kNoSignals}; |
Ady Abraham | 3470210 | 2020-02-10 14:12:05 -0800 | [diff] [blame] | 558 | } |
| 559 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 560 | std::unordered_map<uid_t, std::vector<const RefreshRateConfigs::LayerRequirement*>> |
| 561 | groupLayersByUid(const std::vector<RefreshRateConfigs::LayerRequirement>& layers) { |
| 562 | std::unordered_map<uid_t, std::vector<const RefreshRateConfigs::LayerRequirement*>> layersByUid; |
| 563 | for (const auto& layer : layers) { |
| 564 | auto iter = layersByUid.emplace(layer.ownerUid, |
| 565 | std::vector<const RefreshRateConfigs::LayerRequirement*>()); |
| 566 | auto& layersWithSameUid = iter.first->second; |
| 567 | layersWithSameUid.push_back(&layer); |
| 568 | } |
| 569 | |
| 570 | // Remove uids that can't have a frame rate override |
| 571 | for (auto iter = layersByUid.begin(); iter != layersByUid.end();) { |
| 572 | const auto& layersWithSameUid = iter->second; |
| 573 | bool skipUid = false; |
| 574 | for (const auto& layer : layersWithSameUid) { |
| 575 | if (layer->vote == RefreshRateConfigs::LayerVoteType::Max || |
| 576 | layer->vote == RefreshRateConfigs::LayerVoteType::Heuristic) { |
| 577 | skipUid = true; |
| 578 | break; |
| 579 | } |
| 580 | } |
| 581 | if (skipUid) { |
| 582 | iter = layersByUid.erase(iter); |
| 583 | } else { |
| 584 | ++iter; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | return layersByUid; |
| 589 | } |
| 590 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 591 | RefreshRateConfigs::UidToFrameRateOverride RefreshRateConfigs::getFrameRateOverrides( |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 592 | const std::vector<LayerRequirement>& layers, Fps displayRefreshRate, |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 593 | GlobalSignals globalSignals) const { |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 594 | ATRACE_CALL(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 595 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 596 | ALOGV("%s: %zu layers", __func__, layers.size()); |
| 597 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 598 | std::lock_guard lock(mLock); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 599 | |
| 600 | std::vector<RefreshRateScore> scores; |
| 601 | scores.reserve(mDisplayModes.size()); |
| 602 | |
| 603 | for (auto it = mDisplayModes.begin(); it != mDisplayModes.end(); ++it) { |
| 604 | scores.emplace_back(RefreshRateScore{it, 0.0f}); |
| 605 | } |
| 606 | |
| 607 | std::sort(scores.begin(), scores.end(), [](const auto& lhs, const auto& rhs) { |
| 608 | const auto& mode1 = lhs.modeIt->second; |
| 609 | const auto& mode2 = rhs.modeIt->second; |
| 610 | return isStrictlyLess(mode1->getFps(), mode2->getFps()); |
| 611 | }); |
| 612 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 613 | std::unordered_map<uid_t, std::vector<const LayerRequirement*>> layersByUid = |
| 614 | groupLayersByUid(layers); |
| 615 | UidToFrameRateOverride frameRateOverrides; |
| 616 | for (const auto& [uid, layersWithSameUid] : layersByUid) { |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 617 | // Layers with ExplicitExactOrMultiple expect touch boost |
| 618 | const bool hasExplicitExactOrMultiple = |
| 619 | std::any_of(layersWithSameUid.cbegin(), layersWithSameUid.cend(), |
| 620 | [](const auto& layer) { |
| 621 | return layer->vote == LayerVoteType::ExplicitExactOrMultiple; |
| 622 | }); |
| 623 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 624 | if (globalSignals.touch && hasExplicitExactOrMultiple) { |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 625 | continue; |
| 626 | } |
| 627 | |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 628 | for (auto& [_, score, _1] : scores) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 629 | score = 0; |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | for (const auto& layer : layersWithSameUid) { |
| 633 | if (layer->vote == LayerVoteType::NoVote || layer->vote == LayerVoteType::Min) { |
| 634 | continue; |
| 635 | } |
| 636 | |
| 637 | LOG_ALWAYS_FATAL_IF(layer->vote != LayerVoteType::ExplicitDefault && |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 638 | layer->vote != LayerVoteType::ExplicitExactOrMultiple && |
| 639 | layer->vote != LayerVoteType::ExplicitExact); |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 640 | for (auto& [modeIt, score, _] : scores) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 641 | constexpr bool isSeamlessSwitch = true; |
| 642 | const auto layerScore = calculateLayerScoreLocked(*layer, modeIt->second->getFps(), |
| 643 | isSeamlessSwitch); |
| 644 | score += layer->weight * layerScore; |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
Ady Abraham | cc31549 | 2022-02-17 17:06:39 -0800 | [diff] [blame] | 648 | // We just care about the refresh rates which are a divisor of the |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 649 | // display refresh rate |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 650 | const auto it = std::remove_if(scores.begin(), scores.end(), [&](RefreshRateScore score) { |
| 651 | const auto& [id, mode] = *score.modeIt; |
| 652 | return getFrameRateDivisor(displayRefreshRate, mode->getFps()) == 0; |
| 653 | }); |
| 654 | scores.erase(it, scores.end()); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 655 | |
| 656 | // If we never scored any layers, we don't have a preferred frame rate |
| 657 | if (std::all_of(scores.begin(), scores.end(), |
Ady Abraham | ae2e3c7 | 2022-08-13 05:12:13 +0000 | [diff] [blame] | 658 | [](RefreshRateScore score) { return score.overallScore == 0; })) { |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 659 | continue; |
| 660 | } |
| 661 | |
| 662 | // Now that we scored all the refresh rates we need to pick the one that got the highest |
| 663 | // score. |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 664 | const DisplayModePtr& bestRefreshRate = |
| 665 | getMaxScoreRefreshRate(scores.begin(), scores.end()); |
| 666 | |
Ady Abraham | 5cc2e26 | 2021-03-25 13:09:17 -0700 | [diff] [blame] | 667 | frameRateOverrides.emplace(uid, bestRefreshRate->getFps()); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | return frameRateOverrides; |
| 671 | } |
| 672 | |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 673 | std::optional<Fps> RefreshRateConfigs::onKernelTimerChanged( |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 674 | std::optional<DisplayModeId> desiredActiveModeId, bool timerExpired) const { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 675 | std::lock_guard lock(mLock); |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 676 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 677 | const DisplayModePtr& current = desiredActiveModeId |
| 678 | ? mDisplayModes.get(*desiredActiveModeId)->get() |
| 679 | : mActiveModeIt->second; |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 680 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 681 | const DisplayModePtr& min = mMinRefreshRateModeIt->second; |
| 682 | if (current == min) { |
| 683 | return {}; |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 684 | } |
| 685 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 686 | const auto& mode = timerExpired ? min : current; |
| 687 | return mode->getFps(); |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 690 | const DisplayModePtr& RefreshRateConfigs::getMinRefreshRateByPolicyLocked() const { |
| 691 | for (const DisplayModeIterator modeIt : mPrimaryRefreshRates) { |
| 692 | const auto& mode = modeIt->second; |
| 693 | if (mActiveModeIt->second->getGroup() == mode->getGroup()) { |
| 694 | return mode; |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 695 | } |
| 696 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 697 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 698 | ALOGE("Can't find min refresh rate by policy with the same mode group" |
| 699 | " as the current mode %s", |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 700 | to_string(*mActiveModeIt->second).c_str()); |
| 701 | |
| 702 | // Default to the lowest refresh rate. |
| 703 | return mPrimaryRefreshRates.front()->second; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 704 | } |
| 705 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 706 | DisplayModePtr RefreshRateConfigs::getMaxRefreshRateByPolicy() const { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 707 | std::lock_guard lock(mLock); |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 708 | return getMaxRefreshRateByPolicyLocked(); |
| 709 | } |
| 710 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 711 | const DisplayModePtr& RefreshRateConfigs::getMaxRefreshRateByPolicyLocked(int anchorGroup) const { |
| 712 | for (auto it = mPrimaryRefreshRates.rbegin(); it != mPrimaryRefreshRates.rend(); ++it) { |
| 713 | const auto& mode = (*it)->second; |
| 714 | if (anchorGroup == mode->getGroup()) { |
| 715 | return mode; |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 716 | } |
| 717 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 718 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 719 | ALOGE("Can't find max refresh rate by policy with the same mode group" |
| 720 | " as the current mode %s", |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 721 | to_string(*mActiveModeIt->second).c_str()); |
| 722 | |
| 723 | // Default to the highest refresh rate. |
| 724 | return mPrimaryRefreshRates.back()->second; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 725 | } |
| 726 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 727 | DisplayModePtr RefreshRateConfigs::getActiveMode() const { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 728 | std::lock_guard lock(mLock); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 729 | return mActiveModeIt->second; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 730 | } |
| 731 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 732 | void RefreshRateConfigs::setActiveModeId(DisplayModeId modeId) { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 733 | std::lock_guard lock(mLock); |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 734 | |
| 735 | // Invalidate the cached invocation to getBestRefreshRate. This forces |
| 736 | // the refresh rate to be recomputed on the next call to getBestRefreshRate. |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 737 | mGetBestRefreshRateCache.reset(); |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 738 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 739 | mActiveModeIt = mDisplayModes.find(modeId); |
| 740 | LOG_ALWAYS_FATAL_IF(mActiveModeIt == mDisplayModes.end()); |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 741 | } |
| 742 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 743 | RefreshRateConfigs::RefreshRateConfigs(DisplayModes modes, DisplayModeId activeModeId, |
rnlee | 3bd61066 | 2021-06-23 16:27:57 -0700 | [diff] [blame] | 744 | Config config) |
| 745 | : mKnownFrameRates(constructKnownFrameRates(modes)), mConfig(config) { |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 746 | initializeIdleTimer(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 747 | updateDisplayModes(std::move(modes), activeModeId); |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 748 | } |
| 749 | |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 750 | void RefreshRateConfigs::initializeIdleTimer() { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 751 | if (mConfig.idleTimerTimeout > 0ms) { |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 752 | mIdleTimer.emplace( |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 753 | "IdleTimer", mConfig.idleTimerTimeout, |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 754 | [this] { |
| 755 | std::scoped_lock lock(mIdleTimerCallbacksMutex); |
| 756 | if (const auto callbacks = getIdleTimerCallbacks()) { |
| 757 | callbacks->onReset(); |
| 758 | } |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 759 | }, |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 760 | [this] { |
| 761 | std::scoped_lock lock(mIdleTimerCallbacksMutex); |
| 762 | if (const auto callbacks = getIdleTimerCallbacks()) { |
| 763 | callbacks->onExpired(); |
| 764 | } |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 765 | }); |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 769 | void RefreshRateConfigs::updateDisplayModes(DisplayModes modes, DisplayModeId activeModeId) { |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 770 | std::lock_guard lock(mLock); |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 771 | |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 772 | // Invalidate the cached invocation to getBestRefreshRate. This forces |
| 773 | // the refresh rate to be recomputed on the next call to getBestRefreshRate. |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 774 | mGetBestRefreshRateCache.reset(); |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 775 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 776 | mDisplayModes = std::move(modes); |
| 777 | mActiveModeIt = mDisplayModes.find(activeModeId); |
| 778 | LOG_ALWAYS_FATAL_IF(mActiveModeIt == mDisplayModes.end()); |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 779 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 780 | const auto sortedModes = |
| 781 | sortByRefreshRate(mDisplayModes, [](const DisplayMode&) { return true; }); |
| 782 | mMinRefreshRateModeIt = sortedModes.front(); |
| 783 | mMaxRefreshRateModeIt = sortedModes.back(); |
| 784 | |
Marin Shalamanov | 75f3725 | 2021-02-10 21:43:57 +0100 | [diff] [blame] | 785 | // Reset the policy because the old one may no longer be valid. |
| 786 | mDisplayManagerPolicy = {}; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 787 | mDisplayManagerPolicy.defaultMode = activeModeId; |
Ady Abraham | 64c2fc0 | 2020-12-29 12:07:50 -0800 | [diff] [blame] | 788 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 789 | mSupportsFrameRateOverrideByContent = |
| 790 | mConfig.enableFrameRateOverride && canModesSupportFrameRateOverride(sortedModes); |
Ady Abraham | 4899ff8 | 2021-01-06 13:53:29 -0800 | [diff] [blame] | 791 | |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 792 | constructAvailableRefreshRates(); |
Ady Abraham | b4b1e0a | 2019-11-20 18:25:35 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 795 | bool RefreshRateConfigs::isPolicyValidLocked(const Policy& policy) const { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 796 | // defaultMode must be a valid mode, and within the given refresh rate range. |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 797 | if (const auto mode = mDisplayModes.get(policy.defaultMode)) { |
| 798 | if (!policy.primaryRange.includes(mode->get()->getFps())) { |
| 799 | ALOGE("Default mode is not in the primary range."); |
| 800 | return false; |
| 801 | } |
| 802 | } else { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 803 | ALOGE("Default mode is not found."); |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 804 | return false; |
| 805 | } |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 806 | |
| 807 | using namespace fps_approx_ops; |
| 808 | return policy.appRequestRange.min <= policy.primaryRange.min && |
| 809 | policy.appRequestRange.max >= policy.primaryRange.max; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | status_t RefreshRateConfigs::setDisplayManagerPolicy(const Policy& policy) { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 813 | std::lock_guard lock(mLock); |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 814 | if (!isPolicyValidLocked(policy)) { |
Marin Shalamanov | b6674e7 | 2020-11-06 13:05:57 +0100 | [diff] [blame] | 815 | ALOGE("Invalid refresh rate policy: %s", policy.toString().c_str()); |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 816 | return BAD_VALUE; |
| 817 | } |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 818 | mGetBestRefreshRateCache.reset(); |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 819 | Policy previousPolicy = *getCurrentPolicyLocked(); |
| 820 | mDisplayManagerPolicy = policy; |
| 821 | if (*getCurrentPolicyLocked() == previousPolicy) { |
| 822 | return CURRENT_POLICY_UNCHANGED; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 823 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 824 | constructAvailableRefreshRates(); |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 825 | return NO_ERROR; |
| 826 | } |
| 827 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 828 | status_t RefreshRateConfigs::setOverridePolicy(const std::optional<Policy>& policy) { |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 829 | std::lock_guard lock(mLock); |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 830 | if (policy && !isPolicyValidLocked(*policy)) { |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 831 | return BAD_VALUE; |
| 832 | } |
Dominik Laskowski | a8626ec | 2021-12-15 18:13:30 -0800 | [diff] [blame] | 833 | mGetBestRefreshRateCache.reset(); |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 834 | Policy previousPolicy = *getCurrentPolicyLocked(); |
| 835 | mOverridePolicy = policy; |
| 836 | if (*getCurrentPolicyLocked() == previousPolicy) { |
| 837 | return CURRENT_POLICY_UNCHANGED; |
| 838 | } |
| 839 | constructAvailableRefreshRates(); |
| 840 | return NO_ERROR; |
| 841 | } |
| 842 | |
| 843 | const RefreshRateConfigs::Policy* RefreshRateConfigs::getCurrentPolicyLocked() const { |
| 844 | return mOverridePolicy ? &mOverridePolicy.value() : &mDisplayManagerPolicy; |
| 845 | } |
| 846 | |
| 847 | RefreshRateConfigs::Policy RefreshRateConfigs::getCurrentPolicy() const { |
| 848 | std::lock_guard lock(mLock); |
| 849 | return *getCurrentPolicyLocked(); |
| 850 | } |
| 851 | |
| 852 | RefreshRateConfigs::Policy RefreshRateConfigs::getDisplayManagerPolicy() const { |
| 853 | std::lock_guard lock(mLock); |
| 854 | return mDisplayManagerPolicy; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 855 | } |
| 856 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 857 | bool RefreshRateConfigs::isModeAllowed(DisplayModeId modeId) const { |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 858 | std::lock_guard lock(mLock); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 859 | return std::any_of(mAppRequestRefreshRates.begin(), mAppRequestRefreshRates.end(), |
| 860 | [modeId](DisplayModeIterator modeIt) { |
| 861 | return modeIt->second->getId() == modeId; |
| 862 | }); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | void RefreshRateConfigs::constructAvailableRefreshRates() { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 866 | // Filter modes based on current policy and sort on refresh rate. |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 867 | const Policy* policy = getCurrentPolicyLocked(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 868 | ALOGV("%s: %s ", __func__, policy->toString().c_str()); |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 869 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 870 | const auto& defaultMode = mDisplayModes.get(policy->defaultMode)->get(); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 871 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 872 | const auto filterRefreshRates = [&](FpsRange range, const char* rangeName) REQUIRES(mLock) { |
| 873 | const auto filter = [&](const DisplayMode& mode) { |
| 874 | return mode.getResolution() == defaultMode->getResolution() && |
| 875 | mode.getDpi() == defaultMode->getDpi() && |
| 876 | (policy->allowGroupSwitching || mode.getGroup() == defaultMode->getGroup()) && |
| 877 | range.includes(mode.getFps()); |
| 878 | }; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 879 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 880 | const auto modes = sortByRefreshRate(mDisplayModes, filter); |
| 881 | LOG_ALWAYS_FATAL_IF(modes.empty(), "No matching modes for %s range %s", rangeName, |
| 882 | to_string(range).c_str()); |
Dominik Laskowski | 953b7fd | 2022-01-08 19:34:59 -0800 | [diff] [blame] | 883 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 884 | const auto stringifyModes = [&] { |
| 885 | std::string str; |
| 886 | for (const auto modeIt : modes) { |
| 887 | str += to_string(modeIt->second->getFps()); |
| 888 | str.push_back(' '); |
| 889 | } |
| 890 | return str; |
| 891 | }; |
| 892 | ALOGV("%s refresh rates: %s", rangeName, stringifyModes().c_str()); |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 893 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 894 | return modes; |
| 895 | }; |
| 896 | |
| 897 | mPrimaryRefreshRates = filterRefreshRates(policy->primaryRange, "primary"); |
| 898 | mAppRequestRefreshRates = filterRefreshRates(policy->appRequestRange, "app request"); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 899 | } |
| 900 | |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 901 | Fps RefreshRateConfigs::findClosestKnownFrameRate(Fps frameRate) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 902 | using namespace fps_approx_ops; |
| 903 | |
| 904 | if (frameRate <= mKnownFrameRates.front()) { |
| 905 | return mKnownFrameRates.front(); |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 908 | if (frameRate >= mKnownFrameRates.back()) { |
| 909 | return mKnownFrameRates.back(); |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 912 | auto lowerBound = std::lower_bound(mKnownFrameRates.begin(), mKnownFrameRates.end(), frameRate, |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 913 | isStrictlyLess); |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 914 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 915 | const auto distance1 = std::abs(frameRate.getValue() - lowerBound->getValue()); |
| 916 | const auto distance2 = std::abs(frameRate.getValue() - std::prev(lowerBound)->getValue()); |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 917 | return distance1 < distance2 ? *lowerBound : *std::prev(lowerBound); |
| 918 | } |
| 919 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 920 | RefreshRateConfigs::KernelIdleTimerAction RefreshRateConfigs::getIdleTimerAction() const { |
| 921 | std::lock_guard lock(mLock); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 922 | |
| 923 | const Fps deviceMinFps = mMinRefreshRateModeIt->second->getFps(); |
| 924 | const DisplayModePtr& minByPolicy = getMinRefreshRateByPolicyLocked(); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 925 | |
| 926 | // Kernel idle timer will set the refresh rate to the device min. If DisplayManager says that |
| 927 | // the min allowed refresh rate is higher than the device min, we do not want to enable the |
| 928 | // timer. |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 929 | if (isStrictlyLess(deviceMinFps, minByPolicy->getFps())) { |
| 930 | return KernelIdleTimerAction::TurnOff; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 931 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 932 | |
| 933 | const DisplayModePtr& maxByPolicy = getMaxRefreshRateByPolicyLocked(); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 934 | if (minByPolicy == maxByPolicy) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 935 | // Turn on the timer when the min of the primary range is below the device min. |
| 936 | if (const Policy* currentPolicy = getCurrentPolicyLocked(); |
| 937 | isApproxLess(currentPolicy->primaryRange.min, deviceMinFps)) { |
| 938 | return KernelIdleTimerAction::TurnOn; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 939 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 940 | return KernelIdleTimerAction::TurnOff; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 941 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 942 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 943 | // Turn on the timer in all other cases. |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 944 | return KernelIdleTimerAction::TurnOn; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 947 | int RefreshRateConfigs::getFrameRateDivisor(Fps displayRefreshRate, Fps layerFrameRate) { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 948 | // This calculation needs to be in sync with the java code |
| 949 | // in DisplayManagerService.getDisplayInfoForFrameRateOverride |
Marin Shalamanov | 15a0fc6 | 2021-08-16 18:20:21 +0200 | [diff] [blame] | 950 | |
| 951 | // The threshold must be smaller than 0.001 in order to differentiate |
| 952 | // between the fractional pairs (e.g. 59.94 and 60). |
| 953 | constexpr float kThreshold = 0.0009f; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 954 | const auto numPeriods = displayRefreshRate.getValue() / layerFrameRate.getValue(); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 955 | const auto numPeriodsRounded = std::round(numPeriods); |
| 956 | if (std::abs(numPeriods - numPeriodsRounded) > kThreshold) { |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 957 | return 0; |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 960 | return static_cast<int>(numPeriodsRounded); |
| 961 | } |
| 962 | |
Marin Shalamanov | 15a0fc6 | 2021-08-16 18:20:21 +0200 | [diff] [blame] | 963 | bool RefreshRateConfigs::isFractionalPairOrMultiple(Fps smaller, Fps bigger) { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 964 | if (isStrictlyLess(bigger, smaller)) { |
Marin Shalamanov | 15a0fc6 | 2021-08-16 18:20:21 +0200 | [diff] [blame] | 965 | return isFractionalPairOrMultiple(bigger, smaller); |
| 966 | } |
| 967 | |
| 968 | const auto multiplier = std::round(bigger.getValue() / smaller.getValue()); |
| 969 | constexpr float kCoef = 1000.f / 1001.f; |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 970 | return isApproxEqual(bigger, Fps::fromValue(smaller.getValue() * multiplier / kCoef)) || |
| 971 | isApproxEqual(bigger, Fps::fromValue(smaller.getValue() * multiplier * kCoef)); |
Marin Shalamanov | 15a0fc6 | 2021-08-16 18:20:21 +0200 | [diff] [blame] | 972 | } |
| 973 | |
Marin Shalamanov | ba421a8 | 2020-11-10 21:49:26 +0100 | [diff] [blame] | 974 | void RefreshRateConfigs::dump(std::string& result) const { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 975 | using namespace std::string_literals; |
| 976 | |
Marin Shalamanov | ba421a8 | 2020-11-10 21:49:26 +0100 | [diff] [blame] | 977 | std::lock_guard lock(mLock); |
Marin Shalamanov | ba421a8 | 2020-11-10 21:49:26 +0100 | [diff] [blame] | 978 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 979 | const auto activeModeId = mActiveModeIt->first; |
| 980 | result += " activeModeId="s; |
| 981 | result += std::to_string(activeModeId.value()); |
Marin Shalamanov | ba421a8 | 2020-11-10 21:49:26 +0100 | [diff] [blame] | 982 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 983 | result += "\n displayModes=\n"s; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 984 | for (const auto& [id, mode] : mDisplayModes) { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 985 | result += " "s; |
| 986 | result += to_string(*mode); |
| 987 | result += '\n'; |
Marin Shalamanov | ba421a8 | 2020-11-10 21:49:26 +0100 | [diff] [blame] | 988 | } |
| 989 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 990 | base::StringAppendF(&result, " displayManagerPolicy=%s\n", |
| 991 | mDisplayManagerPolicy.toString().c_str()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 992 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 993 | if (const Policy& currentPolicy = *getCurrentPolicyLocked(); |
| 994 | mOverridePolicy && currentPolicy != mDisplayManagerPolicy) { |
| 995 | base::StringAppendF(&result, " overridePolicy=%s\n", currentPolicy.toString().c_str()); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 996 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 997 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 998 | base::StringAppendF(&result, " supportsFrameRateOverrideByContent=%s\n", |
| 999 | mSupportsFrameRateOverrideByContent ? "true" : "false"); |
| 1000 | |
| 1001 | result += " idleTimer="s; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1002 | if (mIdleTimer) { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 1003 | result += mIdleTimer->dump(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1004 | } else { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 1005 | result += "off"s; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1006 | } |
| 1007 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 1008 | if (const auto controller = mConfig.kernelIdleTimerController) { |
| 1009 | base::StringAppendF(&result, " (kernel via %s)", ftl::enum_string(*controller).c_str()); |
| 1010 | } else { |
| 1011 | result += " (platform)"s; |
| 1012 | } |
| 1013 | |
| 1014 | result += '\n'; |
Marin Shalamanov | ba421a8 | 2020-11-10 21:49:26 +0100 | [diff] [blame] | 1015 | } |
| 1016 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 1017 | std::chrono::milliseconds RefreshRateConfigs::getIdleTimerTimeout() { |
| 1018 | return mConfig.idleTimerTimeout; |
| 1019 | } |
| 1020 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1021 | } // namespace android::scheduler |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 1022 | |
| 1023 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 1024 | #pragma clang diagnostic pop // ignored "-Wextra" |