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