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