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 | |
| 19 | #include <algorithm> |
| 20 | #include <numeric> |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 21 | #include <optional> |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 22 | #include <type_traits> |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 23 | |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 24 | #include <android-base/stringprintf.h> |
| 25 | #include <gui/DisplayEventReceiver.h> |
| 26 | |
| 27 | #include <scheduler/Fps.h> |
| 28 | #include <scheduler/Seamlessness.h> |
| 29 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 30 | #include "DisplayHardware/DisplayMode.h" |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 31 | #include "DisplayHardware/HWComposer.h" |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 32 | #include "Scheduler/OneShotTimer.h" |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 33 | #include "Scheduler/SchedulerUtils.h" |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 34 | #include "Scheduler/StrongTyping.h" |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 35 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 36 | namespace android::scheduler { |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 37 | |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 38 | using namespace std::chrono_literals; |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 39 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 40 | enum class DisplayModeEvent : unsigned { None = 0b0, Changed = 0b1 }; |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 41 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 42 | inline DisplayModeEvent operator|(DisplayModeEvent lhs, DisplayModeEvent rhs) { |
| 43 | using T = std::underlying_type_t<DisplayModeEvent>; |
| 44 | return static_cast<DisplayModeEvent>(static_cast<T>(lhs) | static_cast<T>(rhs)); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 45 | } |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 46 | |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 47 | using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride; |
| 48 | |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 49 | /** |
Ady Abraham | 1902d07 | 2019-03-01 17:18:59 -0800 | [diff] [blame] | 50 | * 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] | 51 | * about available refresh rates on the device, and the mapping between the numbers and human |
| 52 | * readable names. |
| 53 | */ |
| 54 | class RefreshRateConfigs { |
| 55 | public: |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 56 | // Margin used when matching refresh rates to the content desired ones. |
| 57 | static constexpr nsecs_t MARGIN_FOR_PERIOD_CALCULATION = |
rnlee | 3bd61066 | 2021-06-23 16:27:57 -0700 | [diff] [blame] | 58 | std::chrono::nanoseconds(800us).count(); |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 59 | |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 60 | class RefreshRate { |
| 61 | private: |
| 62 | // Effectively making the constructor private while allowing |
| 63 | // std::make_unique to create the object |
| 64 | struct ConstructorTag { |
| 65 | explicit ConstructorTag(int) {} |
| 66 | }; |
Ana Krulec | 72f0d6e | 2020-01-06 15:24:47 -0800 | [diff] [blame] | 67 | |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 68 | public: |
Ady Abraham | 6b7ad65 | 2021-06-23 17:34:57 -0700 | [diff] [blame] | 69 | RefreshRate(DisplayModePtr mode, ConstructorTag) : mode(mode) {} |
Ady Abraham | 2e1dd89 | 2020-03-05 13:48:36 -0800 | [diff] [blame] | 70 | |
Ady Abraham | 6b7ad65 | 2021-06-23 17:34:57 -0700 | [diff] [blame] | 71 | DisplayModeId getModeId() const { return mode->getId(); } |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 72 | nsecs_t getVsyncPeriod() const { return mode->getVsyncPeriod(); } |
| 73 | int32_t getModeGroup() const { return mode->getGroup(); } |
Ady Abraham | 6b7ad65 | 2021-06-23 17:34:57 -0700 | [diff] [blame] | 74 | std::string getName() const { return to_string(getFps()); } |
| 75 | Fps getFps() const { return mode->getFps(); } |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 76 | DisplayModePtr getMode() const { return mode; } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 77 | |
Ana Krulec | 72f0d6e | 2020-01-06 15:24:47 -0800 | [diff] [blame] | 78 | // Checks whether the fps of this RefreshRate struct is within a given min and max refresh |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 79 | // rate passed in. Margin of error is applied to the boundaries for approximation. |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 80 | bool inPolicy(Fps minRefreshRate, Fps maxRefreshRate) const; |
Ana Krulec | 72f0d6e | 2020-01-06 15:24:47 -0800 | [diff] [blame] | 81 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 82 | bool operator==(const RefreshRate& other) const { return mode == other.mode; } |
| 83 | bool operator!=(const RefreshRate& other) const { return !operator==(other); } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 84 | |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 85 | bool operator<(const RefreshRate& other) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 86 | return isStrictlyLess(getFps(), other.getFps()); |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 87 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 88 | |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 89 | std::string toString() const; |
Marin Shalamanov | 65ce551 | 2021-01-22 20:57:13 +0100 | [diff] [blame] | 90 | friend std::ostream& operator<<(std::ostream& os, const RefreshRate& refreshRate) { |
| 91 | return os << refreshRate.toString(); |
| 92 | } |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 93 | |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 94 | private: |
| 95 | friend RefreshRateConfigs; |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 96 | friend class RefreshRateConfigsTest; |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 97 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 98 | DisplayModePtr mode; |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 99 | }; |
| 100 | |
Ady Abraham | 2e1dd89 | 2020-03-05 13:48:36 -0800 | [diff] [blame] | 101 | using AllRefreshRatesMapType = |
Marin Shalamanov | 23c4420 | 2020-12-22 19:09:20 +0100 | [diff] [blame] | 102 | std::unordered_map<DisplayModeId, std::unique_ptr<const RefreshRate>>; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 103 | |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 104 | struct FpsRange { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 105 | Fps min = Fps::fromValue(0.f); |
| 106 | Fps max = Fps::fromValue(std::numeric_limits<float>::max()); |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 107 | |
| 108 | bool operator==(const FpsRange& other) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 109 | return isApproxEqual(min, other.min) && isApproxEqual(max, other.max); |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | bool operator!=(const FpsRange& other) const { return !(*this == other); } |
| 113 | |
| 114 | std::string toString() const { |
| 115 | return base::StringPrintf("[%s %s]", to_string(min).c_str(), to_string(max).c_str()); |
| 116 | } |
| 117 | }; |
| 118 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 119 | struct Policy { |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 120 | private: |
| 121 | static constexpr int kAllowGroupSwitchingDefault = false; |
| 122 | |
| 123 | public: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 124 | // The default mode, used to ensure we only initiate display mode switches within the |
| 125 | // same mode group as defaultMode's group. |
| 126 | DisplayModeId defaultMode; |
| 127 | // Whether or not we switch mode groups to get the best frame rate. |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 128 | bool allowGroupSwitching = kAllowGroupSwitchingDefault; |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 129 | // The primary refresh rate range represents display manager's general guidance on the |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 130 | // display modes we'll consider when switching refresh rates. Unless we get an explicit |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 131 | // signal from an app, we should stay within this range. |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 132 | FpsRange primaryRange; |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 133 | // The app request refresh rate range allows us to consider more display modes when |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 134 | // switching refresh rates. Although we should generally stay within the primary range, |
| 135 | // specific considerations, such as layer frame rate settings specified via the |
| 136 | // setFrameRate() api, may cause us to go outside the primary range. We never go outside the |
| 137 | // app request range. The app request range will be greater than or equal to the primary |
| 138 | // refresh rate range, never smaller. |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 139 | FpsRange appRequestRange; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 140 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 141 | Policy() = default; |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 142 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 143 | Policy(DisplayModeId defaultMode, const FpsRange& range) |
| 144 | : Policy(defaultMode, kAllowGroupSwitchingDefault, range, range) {} |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 145 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 146 | Policy(DisplayModeId defaultMode, bool allowGroupSwitching, const FpsRange& range) |
| 147 | : Policy(defaultMode, allowGroupSwitching, range, range) {} |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 148 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 149 | Policy(DisplayModeId defaultMode, const FpsRange& primaryRange, |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 150 | const FpsRange& appRequestRange) |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 151 | : Policy(defaultMode, kAllowGroupSwitchingDefault, primaryRange, appRequestRange) {} |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 152 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 153 | Policy(DisplayModeId defaultMode, bool allowGroupSwitching, const FpsRange& primaryRange, |
Marin Shalamanov | 23c4420 | 2020-12-22 19:09:20 +0100 | [diff] [blame] | 154 | const FpsRange& appRequestRange) |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 155 | : defaultMode(defaultMode), |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 156 | allowGroupSwitching(allowGroupSwitching), |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 157 | primaryRange(primaryRange), |
| 158 | appRequestRange(appRequestRange) {} |
| 159 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 160 | bool operator==(const Policy& other) const { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 161 | return defaultMode == other.defaultMode && primaryRange == other.primaryRange && |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 162 | appRequestRange == other.appRequestRange && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 163 | allowGroupSwitching == other.allowGroupSwitching; |
| 164 | } |
| 165 | |
| 166 | bool operator!=(const Policy& other) const { return !(*this == other); } |
Marin Shalamanov | b6674e7 | 2020-11-06 13:05:57 +0100 | [diff] [blame] | 167 | std::string toString() const; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | // Return code set*Policy() to indicate the current policy is unchanged. |
| 171 | static constexpr int CURRENT_POLICY_UNCHANGED = 1; |
| 172 | |
| 173 | // We maintain the display manager policy and the override policy separately. The override |
| 174 | // policy is used by CTS tests to get a consistent device state for testing. While the override |
| 175 | // policy is set, it takes precedence over the display manager policy. Once the override policy |
| 176 | // is cleared, we revert to using the display manager policy. |
| 177 | |
| 178 | // Sets the display manager policy to choose refresh rates. The return value will be: |
| 179 | // - A negative value if the policy is invalid or another error occurred. |
| 180 | // - NO_ERROR if the policy was successfully updated, and the current policy is different from |
| 181 | // what it was before the call. |
| 182 | // - CURRENT_POLICY_UNCHANGED if the policy was successfully updated, but the current policy |
| 183 | // is the same as it was before the call. |
| 184 | status_t setDisplayManagerPolicy(const Policy& policy) EXCLUDES(mLock); |
| 185 | // Sets the override policy. See setDisplayManagerPolicy() for the meaning of the return value. |
| 186 | status_t setOverridePolicy(const std::optional<Policy>& policy) EXCLUDES(mLock); |
| 187 | // Gets the current policy, which will be the override policy if active, and the display manager |
| 188 | // policy otherwise. |
| 189 | Policy getCurrentPolicy() const EXCLUDES(mLock); |
| 190 | // Gets the display manager policy, regardless of whether an override policy is active. |
| 191 | Policy getDisplayManagerPolicy() const EXCLUDES(mLock); |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 192 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 193 | // Returns true if mode is allowed by the current policy. |
| 194 | bool isModeAllowed(DisplayModeId) const EXCLUDES(mLock); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 195 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 196 | // Describes the different options the layer voted for refresh rate |
| 197 | enum class LayerVoteType { |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 198 | NoVote, // Doesn't care about the refresh rate |
| 199 | Min, // Minimal refresh rate available |
| 200 | Max, // Maximal refresh rate available |
| 201 | Heuristic, // Specific refresh rate that was calculated by platform using a heuristic |
| 202 | ExplicitDefault, // Specific refresh rate that was provided by the app with Default |
| 203 | // compatibility |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 204 | ExplicitExactOrMultiple, // Specific refresh rate that was provided by the app with |
| 205 | // ExactOrMultiple compatibility |
| 206 | ExplicitExact, // Specific refresh rate that was provided by the app with |
| 207 | // Exact compatibility |
| 208 | |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 209 | ftl_last = ExplicitExact |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | // Captures the layer requirements for a refresh rate. This will be used to determine the |
| 213 | // display refresh rate. |
| 214 | struct LayerRequirement { |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 215 | // Layer's name. Used for debugging purposes. |
| 216 | std::string name; |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 217 | // Layer's owner uid |
| 218 | uid_t ownerUid = static_cast<uid_t>(-1); |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 219 | // Layer vote type. |
| 220 | LayerVoteType vote = LayerVoteType::NoVote; |
| 221 | // Layer's desired refresh rate, if applicable. |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 222 | Fps desiredRefreshRate; |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 223 | // If a seamless mode switch is required. |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 224 | Seamlessness seamlessness = Seamlessness::Default; |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 225 | // Layer's weight in the range of [0, 1]. The higher the weight the more impact this layer |
| 226 | // would have on choosing the refresh rate. |
| 227 | float weight = 0.0f; |
| 228 | // Whether layer is in focus or not based on WindowManager's state |
| 229 | bool focused = false; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 230 | |
| 231 | bool operator==(const LayerRequirement& other) const { |
| 232 | return name == other.name && vote == other.vote && |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 233 | isApproxEqual(desiredRefreshRate, other.desiredRefreshRate) && |
Marin Shalamanov | be97cfa | 2020-12-01 16:02:07 +0100 | [diff] [blame] | 234 | seamlessness == other.seamlessness && weight == other.weight && |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 235 | focused == other.focused; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | bool operator!=(const LayerRequirement& other) const { return !(*this == other); } |
| 239 | }; |
| 240 | |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 241 | // Global state describing signals that affect refresh rate choice. |
| 242 | struct GlobalSignals { |
| 243 | // Whether the user touched the screen recently. Used to apply touch boost. |
| 244 | bool touch = false; |
| 245 | // True if the system hasn't seen any buffers posted to layers recently. |
| 246 | bool idle = false; |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 247 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 248 | bool operator==(GlobalSignals other) const { |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 249 | return touch == other.touch && idle == other.idle; |
| 250 | } |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 251 | }; |
| 252 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 253 | // Returns the refresh rate that best fits the given layers. outSignalsConsidered returns |
| 254 | // whether the refresh rate was chosen based on touch boost and/or idle timer. |
| 255 | RefreshRate getBestRefreshRate(const std::vector<LayerRequirement>&, GlobalSignals, |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 256 | GlobalSignals* outSignalsConsidered = nullptr) const |
Ady Abraham | 6fb599b | 2020-03-05 13:48:22 -0800 | [diff] [blame] | 257 | EXCLUDES(mLock); |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 258 | |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 259 | FpsRange getSupportedRefreshRateRange() const EXCLUDES(mLock) { |
| 260 | std::lock_guard lock(mLock); |
| 261 | return {mMinSupportedRefreshRate->getFps(), mMaxSupportedRefreshRate->getFps()}; |
| 262 | } |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 263 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 264 | std::optional<Fps> onKernelTimerChanged(std::optional<DisplayModeId> desiredActiveModeId, |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 265 | bool timerExpired) const EXCLUDES(mLock); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 266 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 267 | // Returns the highest refresh rate according to the current policy. May change at runtime. Only |
| 268 | // uses the primary range, not the app request range. |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 269 | RefreshRate getMaxRefreshRateByPolicy() const EXCLUDES(mLock); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 270 | |
| 271 | // Returns the current refresh rate |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 272 | RefreshRate getCurrentRefreshRate() const EXCLUDES(mLock); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 273 | |
Ana Krulec | 5d47791 | 2020-02-07 12:02:38 -0800 | [diff] [blame] | 274 | // Returns the current refresh rate, if allowed. Otherwise the default that is allowed by |
| 275 | // the policy. |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 276 | RefreshRate getCurrentRefreshRateByPolicy() const; |
Ana Krulec | 5d47791 | 2020-02-07 12:02:38 -0800 | [diff] [blame] | 277 | |
Marin Shalamanov | 23c4420 | 2020-12-22 19:09:20 +0100 | [diff] [blame] | 278 | // Returns the refresh rate that corresponds to a DisplayModeId. This may change at |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 279 | // runtime. |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 280 | // TODO(b/159590486) An invalid mode id may be given here if the dipslay modes have changed. |
| 281 | RefreshRate getRefreshRateFromModeId(DisplayModeId modeId) const EXCLUDES(mLock) { |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 282 | std::lock_guard lock(mLock); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 283 | return *mRefreshRates.at(modeId); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 284 | }; |
| 285 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 286 | // Stores the current modeId the device operates at |
| 287 | void setCurrentModeId(DisplayModeId) EXCLUDES(mLock); |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 288 | |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 289 | // Returns a known frame rate that is the closest to frameRate |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 290 | Fps findClosestKnownFrameRate(Fps frameRate) const; |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 291 | |
rnlee | 3bd61066 | 2021-06-23 16:27:57 -0700 | [diff] [blame] | 292 | // Configuration flags. |
| 293 | struct Config { |
| 294 | bool enableFrameRateOverride = false; |
| 295 | |
| 296 | // Specifies the upper refresh rate threshold (inclusive) for layer vote types of multiple |
| 297 | // or heuristic, such that refresh rates higher than this value will not be voted for. 0 if |
| 298 | // no threshold is set. |
| 299 | int frameRateMultipleThreshold = 0; |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 300 | |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 301 | // The Idle Timer timeout. 0 timeout means no idle timer. |
| 302 | int32_t idleTimerTimeoutMs = 0; |
| 303 | |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 304 | // Whether to use idle timer callbacks that support the kernel timer. |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 305 | bool supportKernelIdleTimer = false; |
rnlee | 3bd61066 | 2021-06-23 16:27:57 -0700 | [diff] [blame] | 306 | }; |
| 307 | |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 308 | RefreshRateConfigs(const DisplayModes&, DisplayModeId, |
rnlee | 3bd61066 | 2021-06-23 16:27:57 -0700 | [diff] [blame] | 309 | Config config = {.enableFrameRateOverride = false, |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 310 | .frameRateMultipleThreshold = 0, |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 311 | .idleTimerTimeoutMs = 0, |
| 312 | .supportKernelIdleTimer = false}); |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 313 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 314 | // Returns whether switching modes (refresh rate or resolution) is possible. |
| 315 | // TODO(b/158780872): Consider HAL support, and skip frame rate detection if the modes only |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 316 | // differ in resolution. |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 317 | bool canSwitch() const EXCLUDES(mLock) { |
| 318 | std::lock_guard lock(mLock); |
| 319 | return mRefreshRates.size() > 1; |
| 320 | } |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 321 | |
TreeHugger Robot | 758ab61 | 2021-06-22 19:17:29 +0000 | [diff] [blame] | 322 | // Class to enumerate options around toggling the kernel timer on and off. |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 323 | enum class KernelIdleTimerAction { |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 324 | TurnOff, // Turn off the idle timer. |
| 325 | TurnOn // Turn on the idle timer. |
| 326 | }; |
| 327 | // Checks whether kernel idle timer should be active depending the policy decisions around |
| 328 | // refresh rates. |
| 329 | KernelIdleTimerAction getIdleTimerAction() const; |
| 330 | |
Ady Abraham | 64c2fc0 | 2020-12-29 12:07:50 -0800 | [diff] [blame] | 331 | bool supportsFrameRateOverride() const { return mSupportsFrameRateOverride; } |
| 332 | |
Ady Abraham | 5cc2e26 | 2021-03-25 13:09:17 -0700 | [diff] [blame] | 333 | // Return the display refresh rate divider to match the layer |
| 334 | // frame rate, or 0 if the display refresh rate is not a multiple of the |
| 335 | // layer refresh rate. |
| 336 | static int getFrameRateDivider(Fps displayFrameRate, Fps layerFrameRate); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 337 | |
Marin Shalamanov | 15a0fc6 | 2021-08-16 18:20:21 +0200 | [diff] [blame] | 338 | // Returns if the provided frame rates have a ratio t*1000/1001 or t*1001/1000 |
| 339 | // for an integer t. |
| 340 | static bool isFractionalPairOrMultiple(Fps, Fps); |
| 341 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 342 | using UidToFrameRateOverride = std::map<uid_t, Fps>; |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 343 | |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 344 | // Returns the frame rate override for each uid. |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 345 | UidToFrameRateOverride getFrameRateOverrides(const std::vector<LayerRequirement>&, |
| 346 | Fps displayFrameRate, GlobalSignals) const |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 347 | EXCLUDES(mLock); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 348 | |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 349 | bool supportsKernelIdleTimer() const { return mConfig.supportKernelIdleTimer; } |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 350 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 351 | struct IdleTimerCallbacks { |
| 352 | struct Callbacks { |
| 353 | std::function<void()> onReset; |
| 354 | std::function<void()> onExpired; |
| 355 | }; |
| 356 | |
| 357 | Callbacks platform; |
| 358 | Callbacks kernel; |
| 359 | }; |
| 360 | |
| 361 | void setIdleTimerCallbacks(IdleTimerCallbacks callbacks) EXCLUDES(mIdleTimerCallbacksMutex) { |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 362 | std::scoped_lock lock(mIdleTimerCallbacksMutex); |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 363 | mIdleTimerCallbacks = std::move(callbacks); |
| 364 | } |
| 365 | |
| 366 | void clearIdleTimerCallbacks() EXCLUDES(mIdleTimerCallbacksMutex) { |
| 367 | std::scoped_lock lock(mIdleTimerCallbacksMutex); |
| 368 | mIdleTimerCallbacks.reset(); |
Ady Abraham | 1166340 | 2021-11-10 19:46:09 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | void startIdleTimer() { |
| 372 | if (mIdleTimer) { |
| 373 | mIdleTimer->start(); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | void stopIdleTimer() { |
| 378 | if (mIdleTimer) { |
| 379 | mIdleTimer->stop(); |
| 380 | } |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void resetIdleTimer(bool kernelOnly) { |
| 384 | if (!mIdleTimer) { |
| 385 | return; |
| 386 | } |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 387 | if (kernelOnly && !mConfig.supportKernelIdleTimer) { |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 388 | return; |
| 389 | } |
| 390 | mIdleTimer->reset(); |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 391 | } |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 392 | |
Marin Shalamanov | ba421a8 | 2020-11-10 21:49:26 +0100 | [diff] [blame] | 393 | void dump(std::string& result) const EXCLUDES(mLock); |
| 394 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 395 | RefreshRateConfigs(const RefreshRateConfigs&) = delete; |
| 396 | void operator=(const RefreshRateConfigs&) = delete; |
| 397 | |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 398 | private: |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 399 | friend class RefreshRateConfigsTest; |
| 400 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 401 | void constructAvailableRefreshRates() REQUIRES(mLock); |
| 402 | |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 403 | void getSortedRefreshRateListLocked( |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 404 | const std::function<bool(const RefreshRate&)>& shouldAddRefreshRate, |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 405 | std::vector<const RefreshRate*>* outRefreshRates) REQUIRES(mLock); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 406 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 407 | std::optional<RefreshRate> getCachedBestRefreshRate(const std::vector<LayerRequirement>&, |
| 408 | GlobalSignals, |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 409 | GlobalSignals* outSignalsConsidered) const |
| 410 | REQUIRES(mLock); |
| 411 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 412 | RefreshRate getBestRefreshRateLocked(const std::vector<LayerRequirement>&, GlobalSignals, |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 413 | GlobalSignals* outSignalsConsidered) const REQUIRES(mLock); |
| 414 | |
Ady Abraham | 3470210 | 2020-02-10 14:12:05 -0800 | [diff] [blame] | 415 | // Returns the refresh rate with the highest score in the collection specified from begin |
| 416 | // to end. If there are more than one with the same highest refresh rate, the first one is |
| 417 | // returned. |
| 418 | template <typename Iter> |
| 419 | const RefreshRate* getBestRefreshRate(Iter begin, Iter end) const; |
| 420 | |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 421 | // Returns number of display frames and remainder when dividing the layer refresh period by |
| 422 | // display refresh period. |
| 423 | std::pair<nsecs_t, nsecs_t> getDisplayFrames(nsecs_t layerPeriod, nsecs_t displayPeriod) const; |
| 424 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 425 | // Returns the lowest refresh rate according to the current policy. May change at runtime. Only |
| 426 | // uses the primary range, not the app request range. |
| 427 | const RefreshRate& getMinRefreshRateByPolicyLocked() const REQUIRES(mLock); |
| 428 | |
| 429 | // Returns the highest refresh rate according to the current policy. May change at runtime. Only |
| 430 | // uses the primary range, not the app request range. |
Marin Shalamanov | 8cd8a99 | 2021-09-14 23:22:49 +0200 | [diff] [blame] | 431 | const RefreshRate& getMaxRefreshRateByPolicyLocked() const REQUIRES(mLock) { |
| 432 | return getMaxRefreshRateByPolicyLocked(mCurrentRefreshRate->getModeGroup()); |
| 433 | } |
| 434 | |
| 435 | const RefreshRate& getMaxRefreshRateByPolicyLocked(int anchorGroup) const REQUIRES(mLock); |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 436 | |
Ana Krulec | 3d367c8 | 2020-02-25 15:02:01 -0800 | [diff] [blame] | 437 | // Returns the current refresh rate, if allowed. Otherwise the default that is allowed by |
| 438 | // the policy. |
| 439 | const RefreshRate& getCurrentRefreshRateByPolicyLocked() const REQUIRES(mLock); |
| 440 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 441 | const Policy* getCurrentPolicyLocked() const REQUIRES(mLock); |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 442 | bool isPolicyValidLocked(const Policy& policy) const REQUIRES(mLock); |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 443 | |
rnlee | 3bd61066 | 2021-06-23 16:27:57 -0700 | [diff] [blame] | 444 | // Returns whether the layer is allowed to vote for the given refresh rate. |
| 445 | bool isVoteAllowed(const LayerRequirement&, const RefreshRate&) const; |
| 446 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 447 | // calculates a score for a layer. Used to determine the display refresh rate |
| 448 | // and the frame rate override for certains applications. |
| 449 | float calculateLayerScoreLocked(const LayerRequirement&, const RefreshRate&, |
| 450 | bool isSeamlessSwitch) const REQUIRES(mLock); |
| 451 | |
Ady Abraham | 05243be | 2021-09-16 15:58:52 -0700 | [diff] [blame] | 452 | float calculateNonExactMatchingLayerScoreLocked(const LayerRequirement&, |
| 453 | const RefreshRate&) const REQUIRES(mLock); |
| 454 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 455 | void updateDisplayModes(const DisplayModes& mode, DisplayModeId currentModeId) EXCLUDES(mLock); |
| 456 | |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 457 | void initializeIdleTimer(); |
| 458 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 459 | std::optional<IdleTimerCallbacks::Callbacks> getIdleTimerCallbacks() const |
| 460 | REQUIRES(mIdleTimerCallbacksMutex) { |
| 461 | if (!mIdleTimerCallbacks) return {}; |
| 462 | return mConfig.supportKernelIdleTimer ? mIdleTimerCallbacks->kernel |
| 463 | : mIdleTimerCallbacks->platform; |
| 464 | } |
| 465 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 466 | // The list of refresh rates, indexed by display modes ID. This may change after this |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 467 | // object is initialized. |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 468 | AllRefreshRatesMapType mRefreshRates GUARDED_BY(mLock); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 469 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 470 | // The list of refresh rates in the primary range of the current policy, ordered by vsyncPeriod |
| 471 | // (the first element is the lowest refresh rate). |
| 472 | std::vector<const RefreshRate*> mPrimaryRefreshRates GUARDED_BY(mLock); |
| 473 | |
| 474 | // The list of refresh rates in the app request range of the current policy, ordered by |
| 475 | // vsyncPeriod (the first element is the lowest refresh rate). |
| 476 | std::vector<const RefreshRate*> mAppRequestRefreshRates GUARDED_BY(mLock); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 477 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 478 | // The current display mode. This will change at runtime. This is set by SurfaceFlinger on |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 479 | // the main thread, and read by the Scheduler (and other objects) on other threads. |
| 480 | const RefreshRate* mCurrentRefreshRate GUARDED_BY(mLock); |
| 481 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 482 | // The policy values will change at runtime. They're set by SurfaceFlinger on the main thread, |
| 483 | // and read by the Scheduler (and other objects) on other threads. |
| 484 | Policy mDisplayManagerPolicy GUARDED_BY(mLock); |
| 485 | std::optional<Policy> mOverridePolicy GUARDED_BY(mLock); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 486 | |
| 487 | // The min and max refresh rates supported by the device. |
Marin Shalamanov | eadf2e7 | 2020-12-10 15:35:28 +0100 | [diff] [blame] | 488 | // This may change at runtime. |
| 489 | const RefreshRate* mMinSupportedRefreshRate GUARDED_BY(mLock); |
| 490 | const RefreshRate* mMaxSupportedRefreshRate GUARDED_BY(mLock); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 491 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 492 | mutable std::mutex mLock; |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 493 | |
| 494 | // A sorted list of known frame rates that a Heuristic layer will choose |
| 495 | // from based on the closest value. |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 496 | const std::vector<Fps> mKnownFrameRates; |
Ady Abraham | 64c2fc0 | 2020-12-29 12:07:50 -0800 | [diff] [blame] | 497 | |
rnlee | 3bd61066 | 2021-06-23 16:27:57 -0700 | [diff] [blame] | 498 | const Config mConfig; |
Ady Abraham | 64c2fc0 | 2020-12-29 12:07:50 -0800 | [diff] [blame] | 499 | bool mSupportsFrameRateOverride; |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 500 | |
| 501 | struct GetBestRefreshRateInvocation { |
| 502 | std::vector<LayerRequirement> layerRequirements; |
| 503 | GlobalSignals globalSignals; |
| 504 | GlobalSignals outSignalsConsidered; |
| 505 | RefreshRate resultingBestRefreshRate; |
| 506 | }; |
| 507 | mutable std::optional<GetBestRefreshRateInvocation> lastBestRefreshRateInvocation |
| 508 | GUARDED_BY(mLock); |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 509 | |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 510 | // Declare mIdleTimer last to ensure its thread joins before the mutex/callbacks are destroyed. |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 511 | std::mutex mIdleTimerCallbacksMutex; |
| 512 | std::optional<IdleTimerCallbacks> mIdleTimerCallbacks GUARDED_BY(mIdleTimerCallbacksMutex); |
Dominik Laskowski | 83bd771 | 2022-01-07 14:30:53 -0800 | [diff] [blame] | 513 | // Used to detect (lack of) frame activity. |
| 514 | std::optional<scheduler::OneShotTimer> mIdleTimer; |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 515 | }; |
| 516 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 517 | } // namespace android::scheduler |