Ana Krulec | b43429d | 2019-01-09 14:28:51 -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 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 19 | #include <android-base/stringprintf.h> |
| 20 | |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 21 | #include <algorithm> |
| 22 | #include <numeric> |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 23 | #include <optional> |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 24 | #include <type_traits> |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 25 | |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 26 | #include "DisplayHardware/HWComposer.h" |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 27 | #include "HwcStrongTypes.h" |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 28 | #include "Scheduler/SchedulerUtils.h" |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 29 | #include "Scheduler/StrongTyping.h" |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 30 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 31 | namespace android::scheduler { |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 32 | |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 33 | using namespace std::chrono_literals; |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 34 | |
| 35 | enum class RefreshRateConfigEvent : unsigned { None = 0b0, Changed = 0b1 }; |
| 36 | |
| 37 | inline RefreshRateConfigEvent operator|(RefreshRateConfigEvent lhs, RefreshRateConfigEvent rhs) { |
| 38 | using T = std::underlying_type_t<RefreshRateConfigEvent>; |
| 39 | return static_cast<RefreshRateConfigEvent>(static_cast<T>(lhs) | static_cast<T>(rhs)); |
| 40 | } |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 41 | |
| 42 | /** |
Ady Abraham | 1902d07 | 2019-03-01 17:18:59 -0800 | [diff] [blame] | 43 | * This class is used to encapsulate configuration for refresh rates. It holds information |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 44 | * about available refresh rates on the device, and the mapping between the numbers and human |
| 45 | * readable names. |
| 46 | */ |
| 47 | class RefreshRateConfigs { |
| 48 | public: |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 49 | // Margin used when matching refresh rates to the content desired ones. |
| 50 | static constexpr nsecs_t MARGIN_FOR_PERIOD_CALCULATION = |
| 51 | std::chrono::nanoseconds(800us).count(); |
| 52 | |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 53 | class RefreshRate { |
| 54 | private: |
| 55 | // Effectively making the constructor private while allowing |
| 56 | // std::make_unique to create the object |
| 57 | struct ConstructorTag { |
| 58 | explicit ConstructorTag(int) {} |
| 59 | }; |
Ana Krulec | 72f0d6e | 2020-01-06 15:24:47 -0800 | [diff] [blame] | 60 | |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 61 | public: |
| 62 | RefreshRate(HwcConfigIndexType configId, |
| 63 | std::shared_ptr<const HWC2::Display::Config> config, std::string name, |
| 64 | float fps, ConstructorTag) |
| 65 | : configId(configId), hwcConfig(config), name(std::move(name)), fps(fps) {} |
Ady Abraham | 2e1dd89 | 2020-03-05 13:48:36 -0800 | [diff] [blame] | 66 | |
| 67 | RefreshRate(const RefreshRate&) = delete; |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 68 | |
| 69 | HwcConfigIndexType getConfigId() const { return configId; } |
| 70 | nsecs_t getVsyncPeriod() const { return hwcConfig->getVsyncPeriod(); } |
| 71 | int32_t getConfigGroup() const { return hwcConfig->getConfigGroup(); } |
| 72 | const std::string& getName() const { return name; } |
| 73 | float getFps() const { return fps; } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 74 | |
Ana Krulec | 72f0d6e | 2020-01-06 15:24:47 -0800 | [diff] [blame] | 75 | // Checks whether the fps of this RefreshRate struct is within a given min and max refresh |
| 76 | // rate passed in. FPS_EPSILON is applied to the boundaries for approximation. |
| 77 | bool inPolicy(float minRefreshRate, float maxRefreshRate) const { |
| 78 | return (fps >= (minRefreshRate - FPS_EPSILON) && fps <= (maxRefreshRate + FPS_EPSILON)); |
| 79 | } |
| 80 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 81 | bool operator!=(const RefreshRate& other) const { |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 82 | return configId != other.configId || hwcConfig != other.hwcConfig; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | bool operator==(const RefreshRate& other) const { return !(*this != other); } |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 86 | |
| 87 | private: |
| 88 | friend RefreshRateConfigs; |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 89 | friend class RefreshRateConfigsTest; |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 90 | |
| 91 | // The tolerance within which we consider FPS approximately equals. |
| 92 | static constexpr float FPS_EPSILON = 0.001f; |
| 93 | |
| 94 | // This config ID corresponds to the position of the config in the vector that is stored |
| 95 | // on the device. |
| 96 | const HwcConfigIndexType configId; |
| 97 | // The config itself |
| 98 | std::shared_ptr<const HWC2::Display::Config> hwcConfig; |
| 99 | // Human readable name of the refresh rate. |
| 100 | const std::string name; |
| 101 | // Refresh rate in frames per second |
| 102 | const float fps = 0; |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 103 | }; |
| 104 | |
Ady Abraham | 2e1dd89 | 2020-03-05 13:48:36 -0800 | [diff] [blame] | 105 | using AllRefreshRatesMapType = |
| 106 | std::unordered_map<HwcConfigIndexType, std::unique_ptr<const RefreshRate>>; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 107 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 108 | struct Policy { |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 109 | struct Range { |
| 110 | float min = 0; |
| 111 | float max = std::numeric_limits<float>::max(); |
| 112 | |
| 113 | bool operator==(const Range& other) const { |
| 114 | return min == other.min && max == other.max; |
| 115 | } |
| 116 | |
| 117 | bool operator!=(const Range& other) const { return !(*this == other); } |
| 118 | }; |
| 119 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 120 | // The default config, used to ensure we only initiate display config switches within the |
| 121 | // same config group as defaultConfigId's group. |
| 122 | HwcConfigIndexType defaultConfig; |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 123 | // The primary refresh rate range represents display manager's general guidance on the |
| 124 | // display configs we'll consider when switching refresh rates. Unless we get an explicit |
| 125 | // signal from an app, we should stay within this range. |
| 126 | Range primaryRange; |
| 127 | // The app request refresh rate range allows us to consider more display configs when |
| 128 | // switching refresh rates. Although we should generally stay within the primary range, |
| 129 | // specific considerations, such as layer frame rate settings specified via the |
| 130 | // setFrameRate() api, may cause us to go outside the primary range. We never go outside the |
| 131 | // app request range. The app request range will be greater than or equal to the primary |
| 132 | // refresh rate range, never smaller. |
| 133 | Range appRequestRange; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 134 | // Whether or not we switch config groups to get the best frame rate. Only used by tests. |
| 135 | bool allowGroupSwitching = false; |
| 136 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 137 | Policy() = default; |
| 138 | Policy(HwcConfigIndexType defaultConfig, const Range& range) |
| 139 | : Policy(defaultConfig, range, range) {} |
| 140 | Policy(HwcConfigIndexType defaultConfig, const Range& primaryRange, |
| 141 | const Range& appRequestRange) |
| 142 | : defaultConfig(defaultConfig), |
| 143 | primaryRange(primaryRange), |
| 144 | appRequestRange(appRequestRange) {} |
| 145 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 146 | bool operator==(const Policy& other) const { |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 147 | return defaultConfig == other.defaultConfig && primaryRange == other.primaryRange && |
| 148 | appRequestRange == other.appRequestRange && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 149 | allowGroupSwitching == other.allowGroupSwitching; |
| 150 | } |
| 151 | |
| 152 | bool operator!=(const Policy& other) const { return !(*this == other); } |
| 153 | }; |
| 154 | |
| 155 | // Return code set*Policy() to indicate the current policy is unchanged. |
| 156 | static constexpr int CURRENT_POLICY_UNCHANGED = 1; |
| 157 | |
| 158 | // We maintain the display manager policy and the override policy separately. The override |
| 159 | // policy is used by CTS tests to get a consistent device state for testing. While the override |
| 160 | // policy is set, it takes precedence over the display manager policy. Once the override policy |
| 161 | // is cleared, we revert to using the display manager policy. |
| 162 | |
| 163 | // Sets the display manager policy to choose refresh rates. The return value will be: |
| 164 | // - A negative value if the policy is invalid or another error occurred. |
| 165 | // - NO_ERROR if the policy was successfully updated, and the current policy is different from |
| 166 | // what it was before the call. |
| 167 | // - CURRENT_POLICY_UNCHANGED if the policy was successfully updated, but the current policy |
| 168 | // is the same as it was before the call. |
| 169 | status_t setDisplayManagerPolicy(const Policy& policy) EXCLUDES(mLock); |
| 170 | // Sets the override policy. See setDisplayManagerPolicy() for the meaning of the return value. |
| 171 | status_t setOverridePolicy(const std::optional<Policy>& policy) EXCLUDES(mLock); |
| 172 | // Gets the current policy, which will be the override policy if active, and the display manager |
| 173 | // policy otherwise. |
| 174 | Policy getCurrentPolicy() const EXCLUDES(mLock); |
| 175 | // Gets the display manager policy, regardless of whether an override policy is active. |
| 176 | Policy getDisplayManagerPolicy() const EXCLUDES(mLock); |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 177 | |
| 178 | // Returns true if config is allowed by the current policy. |
| 179 | bool isConfigAllowed(HwcConfigIndexType config) const EXCLUDES(mLock); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 180 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 181 | // Describes the different options the layer voted for refresh rate |
| 182 | enum class LayerVoteType { |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 183 | NoVote, // Doesn't care about the refresh rate |
| 184 | Min, // Minimal refresh rate available |
| 185 | Max, // Maximal refresh rate available |
| 186 | Heuristic, // Specific refresh rate that was calculated by platform using a heuristic |
| 187 | ExplicitDefault, // Specific refresh rate that was provided by the app with Default |
| 188 | // compatibility |
| 189 | ExplicitExactOrMultiple // Specific refresh rate that was provided by the app with |
| 190 | // ExactOrMultiple compatibility |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | // Captures the layer requirements for a refresh rate. This will be used to determine the |
| 194 | // display refresh rate. |
| 195 | struct LayerRequirement { |
| 196 | std::string name; // Layer's name. Used for debugging purposes. |
| 197 | LayerVoteType vote; // Layer vote type. |
| 198 | float desiredRefreshRate; // Layer's desired refresh rate, if applicable. |
| 199 | float weight; // Layer's weight in the range of [0, 1]. The higher the weight the more |
| 200 | // impact this layer would have on choosing the refresh rate. |
| 201 | |
| 202 | bool operator==(const LayerRequirement& other) const { |
| 203 | return name == other.name && vote == other.vote && |
| 204 | desiredRefreshRate == other.desiredRefreshRate && weight == other.weight; |
| 205 | } |
| 206 | |
| 207 | bool operator!=(const LayerRequirement& other) const { return !(*this == other); } |
| 208 | }; |
| 209 | |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 210 | // Returns the refresh rate that fits best to the given layers. |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 211 | const RefreshRate& getRefreshRateForContent(const std::vector<LayerRequirement>& layers) const |
| 212 | EXCLUDES(mLock); |
| 213 | |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame^] | 214 | // Global state describing signals that affect refresh rate choice. |
| 215 | struct GlobalSignals { |
| 216 | // Whether the user touched the screen recently. Used to apply touch boost. |
| 217 | bool touch = false; |
| 218 | // True if the system hasn't seen any buffers posted to layers recently. |
| 219 | bool idle = false; |
| 220 | }; |
| 221 | |
Steven Thomas | bb37432 | 2020-04-28 22:47:16 -0700 | [diff] [blame] | 222 | // Returns the refresh rate that fits best to the given layers. |
| 223 | // layers - The layer requirements to consider. |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame^] | 224 | // globalSignals - global state of touch and idle |
| 225 | // outSignalsConsidered - An output param that tells the caller whether the refresh rate was |
| 226 | // chosen based on touch boost and/or idle timer. |
Steven Thomas | bb37432 | 2020-04-28 22:47:16 -0700 | [diff] [blame] | 227 | const RefreshRate& getBestRefreshRate(const std::vector<LayerRequirement>& layers, |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame^] | 228 | const GlobalSignals& globalSignals, |
| 229 | GlobalSignals* outSignalsConsidered = nullptr) const |
Ady Abraham | 6fb599b | 2020-03-05 13:48:22 -0800 | [diff] [blame] | 230 | EXCLUDES(mLock); |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 231 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 232 | // Returns all the refresh rates supported by the device. This won't change at runtime. |
| 233 | const AllRefreshRatesMapType& getAllRefreshRates() const EXCLUDES(mLock); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 234 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 235 | // Returns the lowest refresh rate supported by the device. This won't change at runtime. |
| 236 | const RefreshRate& getMinRefreshRate() const { return *mMinSupportedRefreshRate; } |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 237 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 238 | // Returns the lowest refresh rate according to the current policy. May change at runtime. Only |
| 239 | // uses the primary range, not the app request range. |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 240 | const RefreshRate& getMinRefreshRateByPolicy() const EXCLUDES(mLock); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 241 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 242 | // Returns the highest refresh rate supported by the device. This won't change at runtime. |
| 243 | const RefreshRate& getMaxRefreshRate() const { return *mMaxSupportedRefreshRate; } |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 244 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 245 | // Returns the highest refresh rate according to the current policy. May change at runtime. Only |
| 246 | // uses the primary range, not the app request range. |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 247 | const RefreshRate& getMaxRefreshRateByPolicy() const EXCLUDES(mLock); |
| 248 | |
| 249 | // Returns the current refresh rate |
| 250 | const RefreshRate& getCurrentRefreshRate() const EXCLUDES(mLock); |
| 251 | |
Ana Krulec | 5d47791 | 2020-02-07 12:02:38 -0800 | [diff] [blame] | 252 | // Returns the current refresh rate, if allowed. Otherwise the default that is allowed by |
| 253 | // the policy. |
| 254 | const RefreshRate& getCurrentRefreshRateByPolicy() const; |
| 255 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 256 | // Returns the refresh rate that corresponds to a HwcConfigIndexType. This won't change at |
| 257 | // runtime. |
| 258 | const RefreshRate& getRefreshRateFromConfigId(HwcConfigIndexType configId) const { |
Ady Abraham | 2e1dd89 | 2020-03-05 13:48:36 -0800 | [diff] [blame] | 259 | return *mRefreshRates.at(configId); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | // Stores the current configId the device operates at |
| 263 | void setCurrentConfigId(HwcConfigIndexType configId) EXCLUDES(mLock); |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 264 | |
Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 265 | // Returns a string that represents the layer vote type |
| 266 | static std::string layerVoteTypeString(LayerVoteType vote); |
| 267 | |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 268 | // Returns a known frame rate that is the closest to frameRate |
| 269 | float findClosestKnownFrameRate(float frameRate) const; |
| 270 | |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 271 | RefreshRateConfigs(const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs, |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 272 | HwcConfigIndexType currentConfigId); |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 273 | |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 274 | private: |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 275 | friend class RefreshRateConfigsTest; |
| 276 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 277 | void constructAvailableRefreshRates() REQUIRES(mLock); |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 278 | static std::vector<float> constructKnownFrameRates( |
| 279 | const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 280 | |
| 281 | void getSortedRefreshRateList( |
| 282 | const std::function<bool(const RefreshRate&)>& shouldAddRefreshRate, |
| 283 | std::vector<const RefreshRate*>* outRefreshRates); |
| 284 | |
Ady Abraham | 3470210 | 2020-02-10 14:12:05 -0800 | [diff] [blame] | 285 | // Returns the refresh rate with the highest score in the collection specified from begin |
| 286 | // to end. If there are more than one with the same highest refresh rate, the first one is |
| 287 | // returned. |
| 288 | template <typename Iter> |
| 289 | const RefreshRate* getBestRefreshRate(Iter begin, Iter end) const; |
| 290 | |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 291 | // Returns number of display frames and remainder when dividing the layer refresh period by |
| 292 | // display refresh period. |
| 293 | std::pair<nsecs_t, nsecs_t> getDisplayFrames(nsecs_t layerPeriod, nsecs_t displayPeriod) const; |
| 294 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 295 | // Returns the lowest refresh rate according to the current policy. May change at runtime. Only |
| 296 | // uses the primary range, not the app request range. |
| 297 | const RefreshRate& getMinRefreshRateByPolicyLocked() const REQUIRES(mLock); |
| 298 | |
| 299 | // Returns the highest refresh rate according to the current policy. May change at runtime. Only |
| 300 | // uses the primary range, not the app request range. |
| 301 | const RefreshRate& getMaxRefreshRateByPolicyLocked() const REQUIRES(mLock); |
| 302 | |
Ana Krulec | 3d367c8 | 2020-02-25 15:02:01 -0800 | [diff] [blame] | 303 | // Returns the current refresh rate, if allowed. Otherwise the default that is allowed by |
| 304 | // the policy. |
| 305 | const RefreshRate& getCurrentRefreshRateByPolicyLocked() const REQUIRES(mLock); |
| 306 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 307 | const Policy* getCurrentPolicyLocked() const REQUIRES(mLock); |
| 308 | bool isPolicyValid(const Policy& policy); |
| 309 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 310 | // The list of refresh rates, indexed by display config ID. This must not change after this |
| 311 | // object is initialized. |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 312 | AllRefreshRatesMapType mRefreshRates; |
| 313 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 314 | // The list of refresh rates in the primary range of the current policy, ordered by vsyncPeriod |
| 315 | // (the first element is the lowest refresh rate). |
| 316 | std::vector<const RefreshRate*> mPrimaryRefreshRates GUARDED_BY(mLock); |
| 317 | |
| 318 | // The list of refresh rates in the app request range of the current policy, ordered by |
| 319 | // vsyncPeriod (the first element is the lowest refresh rate). |
| 320 | std::vector<const RefreshRate*> mAppRequestRefreshRates GUARDED_BY(mLock); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 321 | |
| 322 | // The current config. This will change at runtime. This is set by SurfaceFlinger on |
| 323 | // the main thread, and read by the Scheduler (and other objects) on other threads. |
| 324 | const RefreshRate* mCurrentRefreshRate GUARDED_BY(mLock); |
| 325 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 326 | // The policy values will change at runtime. They're set by SurfaceFlinger on the main thread, |
| 327 | // and read by the Scheduler (and other objects) on other threads. |
| 328 | Policy mDisplayManagerPolicy GUARDED_BY(mLock); |
| 329 | std::optional<Policy> mOverridePolicy GUARDED_BY(mLock); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 330 | |
| 331 | // The min and max refresh rates supported by the device. |
| 332 | // This will not change at runtime. |
| 333 | const RefreshRate* mMinSupportedRefreshRate; |
| 334 | const RefreshRate* mMaxSupportedRefreshRate; |
| 335 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 336 | mutable std::mutex mLock; |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 337 | |
| 338 | // A sorted list of known frame rates that a Heuristic layer will choose |
| 339 | // from based on the closest value. |
| 340 | const std::vector<float> mKnownFrameRates; |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 341 | }; |
| 342 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 343 | } // namespace android::scheduler |