blob: 6e0c0d3897fd82472c519db9d610856db04b673d [file] [log] [blame]
Ana Krulecb43429d2019-01-09 14:28:51 -08001/*
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 Laskowski98041832019-08-01 18:35:59 -070019#include <android-base/stringprintf.h>
Ady Abraham62f216c2020-10-13 19:07:23 -070020#include <gui/DisplayEventReceiver.h>
Dominik Laskowski98041832019-08-01 18:35:59 -070021
Ana Krulecb43429d2019-01-09 14:28:51 -080022#include <algorithm>
23#include <numeric>
Steven Thomasd4071902020-03-24 16:02:53 -070024#include <optional>
Dominik Laskowski98041832019-08-01 18:35:59 -070025#include <type_traits>
Ana Krulecb43429d2019-01-09 14:28:51 -080026
Ana Krulec4593b692019-01-11 22:07:25 -080027#include "DisplayHardware/HWComposer.h"
Ady Abraham2139f732019-11-13 18:56:40 -080028#include "HwcStrongTypes.h"
Ana Krulec4593b692019-01-11 22:07:25 -080029#include "Scheduler/SchedulerUtils.h"
Marin Shalamanov53fc11d2020-11-20 14:00:13 +010030#include "Scheduler/Seamlessness.h"
Ady Abraham2139f732019-11-13 18:56:40 -080031#include "Scheduler/StrongTyping.h"
Ana Krulec4593b692019-01-11 22:07:25 -080032
Dominik Laskowski98041832019-08-01 18:35:59 -070033namespace android::scheduler {
Ady Abrahamabc27602020-04-08 17:20:29 -070034
Ady Abraham4ccdcb42020-02-11 17:34:34 -080035using namespace std::chrono_literals;
Dominik Laskowski98041832019-08-01 18:35:59 -070036
37enum class RefreshRateConfigEvent : unsigned { None = 0b0, Changed = 0b1 };
38
39inline RefreshRateConfigEvent operator|(RefreshRateConfigEvent lhs, RefreshRateConfigEvent rhs) {
40 using T = std::underlying_type_t<RefreshRateConfigEvent>;
41 return static_cast<RefreshRateConfigEvent>(static_cast<T>(lhs) | static_cast<T>(rhs));
42}
Ana Krulecb43429d2019-01-09 14:28:51 -080043
Ady Abraham62f216c2020-10-13 19:07:23 -070044using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride;
45
Ana Krulecb43429d2019-01-09 14:28:51 -080046/**
Ady Abraham1902d072019-03-01 17:18:59 -080047 * This class is used to encapsulate configuration for refresh rates. It holds information
Ana Krulecb43429d2019-01-09 14:28:51 -080048 * about available refresh rates on the device, and the mapping between the numbers and human
49 * readable names.
50 */
51class RefreshRateConfigs {
52public:
Ady Abraham4ccdcb42020-02-11 17:34:34 -080053 // Margin used when matching refresh rates to the content desired ones.
54 static constexpr nsecs_t MARGIN_FOR_PERIOD_CALCULATION =
55 std::chrono::nanoseconds(800us).count();
56
Ady Abrahamabc27602020-04-08 17:20:29 -070057 class RefreshRate {
58 private:
59 // Effectively making the constructor private while allowing
60 // std::make_unique to create the object
61 struct ConstructorTag {
62 explicit ConstructorTag(int) {}
63 };
Ana Krulec72f0d6e2020-01-06 15:24:47 -080064
Ady Abrahamabc27602020-04-08 17:20:29 -070065 public:
66 RefreshRate(HwcConfigIndexType configId,
67 std::shared_ptr<const HWC2::Display::Config> config, std::string name,
68 float fps, ConstructorTag)
69 : configId(configId), hwcConfig(config), name(std::move(name)), fps(fps) {}
Ady Abraham2e1dd892020-03-05 13:48:36 -080070
71 RefreshRate(const RefreshRate&) = delete;
Ady Abrahamabc27602020-04-08 17:20:29 -070072
73 HwcConfigIndexType getConfigId() const { return configId; }
74 nsecs_t getVsyncPeriod() const { return hwcConfig->getVsyncPeriod(); }
75 int32_t getConfigGroup() const { return hwcConfig->getConfigGroup(); }
76 const std::string& getName() const { return name; }
77 float getFps() const { return fps; }
Ady Abraham2139f732019-11-13 18:56:40 -080078
Ana Krulec72f0d6e2020-01-06 15:24:47 -080079 // Checks whether the fps of this RefreshRate struct is within a given min and max refresh
80 // rate passed in. FPS_EPSILON is applied to the boundaries for approximation.
81 bool inPolicy(float minRefreshRate, float maxRefreshRate) const {
82 return (fps >= (minRefreshRate - FPS_EPSILON) && fps <= (maxRefreshRate + FPS_EPSILON));
83 }
84
Ady Abraham2139f732019-11-13 18:56:40 -080085 bool operator!=(const RefreshRate& other) const {
Ady Abrahamabc27602020-04-08 17:20:29 -070086 return configId != other.configId || hwcConfig != other.hwcConfig;
Ady Abraham2139f732019-11-13 18:56:40 -080087 }
88
Ana Krulecb9afd792020-06-11 13:16:15 -070089 bool operator<(const RefreshRate& other) const { return getFps() < other.getFps(); }
90
Ady Abraham2139f732019-11-13 18:56:40 -080091 bool operator==(const RefreshRate& other) const { return !(*this != other); }
Ady Abrahamabc27602020-04-08 17:20:29 -070092
Marin Shalamanov46084422020-10-13 12:33:42 +020093 std::string toString() const;
94
Ady Abrahamabc27602020-04-08 17:20:29 -070095 private:
96 friend RefreshRateConfigs;
Ady Abrahamb1b9d412020-06-01 19:53:52 -070097 friend class RefreshRateConfigsTest;
Ady Abrahamabc27602020-04-08 17:20:29 -070098
99 // The tolerance within which we consider FPS approximately equals.
100 static constexpr float FPS_EPSILON = 0.001f;
101
102 // This config ID corresponds to the position of the config in the vector that is stored
103 // on the device.
104 const HwcConfigIndexType configId;
105 // The config itself
106 std::shared_ptr<const HWC2::Display::Config> hwcConfig;
107 // Human readable name of the refresh rate.
108 const std::string name;
109 // Refresh rate in frames per second
110 const float fps = 0;
Ana Krulecb43429d2019-01-09 14:28:51 -0800111 };
112
Ady Abraham2e1dd892020-03-05 13:48:36 -0800113 using AllRefreshRatesMapType =
114 std::unordered_map<HwcConfigIndexType, std::unique_ptr<const RefreshRate>>;
Ady Abraham2139f732019-11-13 18:56:40 -0800115
Steven Thomasd4071902020-03-24 16:02:53 -0700116 struct Policy {
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200117 private:
118 static constexpr int kAllowGroupSwitchingDefault = false;
119
120 public:
Steven Thomasf734df42020-04-13 21:09:28 -0700121 struct Range {
122 float min = 0;
123 float max = std::numeric_limits<float>::max();
124
125 bool operator==(const Range& other) const {
126 return min == other.min && max == other.max;
127 }
128
129 bool operator!=(const Range& other) const { return !(*this == other); }
130 };
131
Steven Thomasd4071902020-03-24 16:02:53 -0700132 // The default config, used to ensure we only initiate display config switches within the
133 // same config group as defaultConfigId's group.
134 HwcConfigIndexType defaultConfig;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200135 // Whether or not we switch config groups to get the best frame rate.
136 bool allowGroupSwitching = kAllowGroupSwitchingDefault;
Steven Thomasf734df42020-04-13 21:09:28 -0700137 // The primary refresh rate range represents display manager's general guidance on the
138 // display configs we'll consider when switching refresh rates. Unless we get an explicit
139 // signal from an app, we should stay within this range.
140 Range primaryRange;
141 // The app request refresh rate range allows us to consider more display configs when
142 // switching refresh rates. Although we should generally stay within the primary range,
143 // specific considerations, such as layer frame rate settings specified via the
144 // setFrameRate() api, may cause us to go outside the primary range. We never go outside the
145 // app request range. The app request range will be greater than or equal to the primary
146 // refresh rate range, never smaller.
147 Range appRequestRange;
Steven Thomasd4071902020-03-24 16:02:53 -0700148
Steven Thomasf734df42020-04-13 21:09:28 -0700149 Policy() = default;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200150
Steven Thomasf734df42020-04-13 21:09:28 -0700151 Policy(HwcConfigIndexType defaultConfig, const Range& range)
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200152 : Policy(defaultConfig, kAllowGroupSwitchingDefault, range, range) {}
153
154 Policy(HwcConfigIndexType defaultConfig, bool allowGroupSwitching, const Range& range)
155 : Policy(defaultConfig, allowGroupSwitching, range, range) {}
156
Steven Thomasf734df42020-04-13 21:09:28 -0700157 Policy(HwcConfigIndexType defaultConfig, const Range& primaryRange,
158 const Range& appRequestRange)
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200159 : Policy(defaultConfig, kAllowGroupSwitchingDefault, primaryRange, appRequestRange) {}
160
161 Policy(HwcConfigIndexType defaultConfig, bool allowGroupSwitching,
162 const Range& primaryRange, const Range& appRequestRange)
Steven Thomasf734df42020-04-13 21:09:28 -0700163 : defaultConfig(defaultConfig),
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200164 allowGroupSwitching(allowGroupSwitching),
Steven Thomasf734df42020-04-13 21:09:28 -0700165 primaryRange(primaryRange),
166 appRequestRange(appRequestRange) {}
167
Steven Thomasd4071902020-03-24 16:02:53 -0700168 bool operator==(const Policy& other) const {
Steven Thomasf734df42020-04-13 21:09:28 -0700169 return defaultConfig == other.defaultConfig && primaryRange == other.primaryRange &&
170 appRequestRange == other.appRequestRange &&
Steven Thomasd4071902020-03-24 16:02:53 -0700171 allowGroupSwitching == other.allowGroupSwitching;
172 }
173
174 bool operator!=(const Policy& other) const { return !(*this == other); }
Marin Shalamanovb6674e72020-11-06 13:05:57 +0100175 std::string toString() const;
Steven Thomasd4071902020-03-24 16:02:53 -0700176 };
177
178 // Return code set*Policy() to indicate the current policy is unchanged.
179 static constexpr int CURRENT_POLICY_UNCHANGED = 1;
180
181 // We maintain the display manager policy and the override policy separately. The override
182 // policy is used by CTS tests to get a consistent device state for testing. While the override
183 // policy is set, it takes precedence over the display manager policy. Once the override policy
184 // is cleared, we revert to using the display manager policy.
185
186 // Sets the display manager policy to choose refresh rates. The return value will be:
187 // - A negative value if the policy is invalid or another error occurred.
188 // - NO_ERROR if the policy was successfully updated, and the current policy is different from
189 // what it was before the call.
190 // - CURRENT_POLICY_UNCHANGED if the policy was successfully updated, but the current policy
191 // is the same as it was before the call.
192 status_t setDisplayManagerPolicy(const Policy& policy) EXCLUDES(mLock);
193 // Sets the override policy. See setDisplayManagerPolicy() for the meaning of the return value.
194 status_t setOverridePolicy(const std::optional<Policy>& policy) EXCLUDES(mLock);
195 // Gets the current policy, which will be the override policy if active, and the display manager
196 // policy otherwise.
197 Policy getCurrentPolicy() const EXCLUDES(mLock);
198 // Gets the display manager policy, regardless of whether an override policy is active.
199 Policy getDisplayManagerPolicy() const EXCLUDES(mLock);
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100200
201 // Returns true if config is allowed by the current policy.
202 bool isConfigAllowed(HwcConfigIndexType config) const EXCLUDES(mLock);
Ady Abraham2139f732019-11-13 18:56:40 -0800203
Ady Abraham8a82ba62020-01-17 12:43:17 -0800204 // Describes the different options the layer voted for refresh rate
205 enum class LayerVoteType {
Ady Abraham71c437d2020-01-31 15:56:57 -0800206 NoVote, // Doesn't care about the refresh rate
207 Min, // Minimal refresh rate available
208 Max, // Maximal refresh rate available
209 Heuristic, // Specific refresh rate that was calculated by platform using a heuristic
210 ExplicitDefault, // Specific refresh rate that was provided by the app with Default
211 // compatibility
212 ExplicitExactOrMultiple // Specific refresh rate that was provided by the app with
213 // ExactOrMultiple compatibility
Ady Abraham8a82ba62020-01-17 12:43:17 -0800214 };
215
216 // Captures the layer requirements for a refresh rate. This will be used to determine the
217 // display refresh rate.
218 struct LayerRequirement {
Ady Abrahamaae5ed52020-06-26 09:32:43 -0700219 // Layer's name. Used for debugging purposes.
220 std::string name;
221 // Layer vote type.
222 LayerVoteType vote = LayerVoteType::NoVote;
223 // Layer's desired refresh rate, if applicable.
224 float desiredRefreshRate = 0.0f;
Marin Shalamanov46084422020-10-13 12:33:42 +0200225 // If a seamless mode switch is required.
Marin Shalamanov53fc11d2020-11-20 14:00:13 +0100226 Seamlessness seamlessness = Seamlessness::Default;
Ady Abrahamaae5ed52020-06-26 09:32:43 -0700227 // Layer's weight in the range of [0, 1]. The higher the weight the more impact this layer
228 // would have on choosing the refresh rate.
229 float weight = 0.0f;
230 // Whether layer is in focus or not based on WindowManager's state
231 bool focused = false;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800232
233 bool operator==(const LayerRequirement& other) const {
234 return name == other.name && vote == other.vote &&
Marin Shalamanovbe97cfa2020-12-01 16:02:07 +0100235 desiredRefreshRate == other.desiredRefreshRate &&
236 seamlessness == other.seamlessness && weight == other.weight &&
Ady Abrahamaae5ed52020-06-26 09:32:43 -0700237 focused == other.focused;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800238 }
239
240 bool operator!=(const LayerRequirement& other) const { return !(*this == other); }
241 };
242
Ady Abrahamdfd62162020-06-10 16:11:56 -0700243 // Global state describing signals that affect refresh rate choice.
244 struct GlobalSignals {
245 // Whether the user touched the screen recently. Used to apply touch boost.
246 bool touch = false;
247 // True if the system hasn't seen any buffers posted to layers recently.
248 bool idle = false;
249 };
250
Steven Thomasbb374322020-04-28 22:47:16 -0700251 // Returns the refresh rate that fits best to the given layers.
252 // layers - The layer requirements to consider.
Ady Abrahamdfd62162020-06-10 16:11:56 -0700253 // globalSignals - global state of touch and idle
254 // outSignalsConsidered - An output param that tells the caller whether the refresh rate was
255 // chosen based on touch boost and/or idle timer.
Steven Thomasbb374322020-04-28 22:47:16 -0700256 const RefreshRate& getBestRefreshRate(const std::vector<LayerRequirement>& layers,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700257 const GlobalSignals& globalSignals,
258 GlobalSignals* outSignalsConsidered = nullptr) const
Ady Abraham6fb599b2020-03-05 13:48:22 -0800259 EXCLUDES(mLock);
Ana Krulecb43429d2019-01-09 14:28:51 -0800260
Ady Abraham2139f732019-11-13 18:56:40 -0800261 // Returns all the refresh rates supported by the device. This won't change at runtime.
262 const AllRefreshRatesMapType& getAllRefreshRates() const EXCLUDES(mLock);
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700263
Ady Abraham2139f732019-11-13 18:56:40 -0800264 // Returns the lowest refresh rate supported by the device. This won't change at runtime.
265 const RefreshRate& getMinRefreshRate() const { return *mMinSupportedRefreshRate; }
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700266
Steven Thomasf734df42020-04-13 21:09:28 -0700267 // Returns the lowest refresh rate according to the current policy. May change at runtime. Only
268 // uses the primary range, not the app request range.
Ady Abraham2139f732019-11-13 18:56:40 -0800269 const RefreshRate& getMinRefreshRateByPolicy() const EXCLUDES(mLock);
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700270
Ady Abraham2139f732019-11-13 18:56:40 -0800271 // Returns the highest refresh rate supported by the device. This won't change at runtime.
272 const RefreshRate& getMaxRefreshRate() const { return *mMaxSupportedRefreshRate; }
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700273
Steven Thomasf734df42020-04-13 21:09:28 -0700274 // Returns the highest refresh rate according to the current policy. May change at runtime. Only
275 // uses the primary range, not the app request range.
Ady Abraham2139f732019-11-13 18:56:40 -0800276 const RefreshRate& getMaxRefreshRateByPolicy() const EXCLUDES(mLock);
277
278 // Returns the current refresh rate
279 const RefreshRate& getCurrentRefreshRate() const EXCLUDES(mLock);
280
Ana Krulec5d477912020-02-07 12:02:38 -0800281 // Returns the current refresh rate, if allowed. Otherwise the default that is allowed by
282 // the policy.
283 const RefreshRate& getCurrentRefreshRateByPolicy() const;
284
Ady Abraham2139f732019-11-13 18:56:40 -0800285 // Returns the refresh rate that corresponds to a HwcConfigIndexType. This won't change at
286 // runtime.
287 const RefreshRate& getRefreshRateFromConfigId(HwcConfigIndexType configId) const {
Ady Abraham2e1dd892020-03-05 13:48:36 -0800288 return *mRefreshRates.at(configId);
Ady Abraham2139f732019-11-13 18:56:40 -0800289 };
290
291 // Stores the current configId the device operates at
292 void setCurrentConfigId(HwcConfigIndexType configId) EXCLUDES(mLock);
Dominik Laskowski22488f62019-03-28 09:53:04 -0700293
Ady Abrahama6b676e2020-05-27 14:29:09 -0700294 // Returns a string that represents the layer vote type
295 static std::string layerVoteTypeString(LayerVoteType vote);
296
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700297 // Returns a known frame rate that is the closest to frameRate
298 float findClosestKnownFrameRate(float frameRate) const;
299
Ana Krulec3f6a2062020-01-23 15:48:01 -0800300 RefreshRateConfigs(const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
Ady Abraham2139f732019-11-13 18:56:40 -0800301 HwcConfigIndexType currentConfigId);
Ana Krulec4593b692019-01-11 22:07:25 -0800302
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700303 // Returns whether switching configs (refresh rate or resolution) is possible.
304 // TODO(b/158780872): Consider HAL support, and skip frame rate detection if the configs only
305 // differ in resolution.
306 bool canSwitch() const { return mRefreshRates.size() > 1; }
307
Ana Krulecb9afd792020-06-11 13:16:15 -0700308 // Class to enumerate options around toggling the kernel timer on and off. We have an option
309 // for no change to avoid extra calls to kernel.
310 enum class KernelIdleTimerAction {
311 NoChange, // Do not change the idle timer.
312 TurnOff, // Turn off the idle timer.
313 TurnOn // Turn on the idle timer.
314 };
315 // Checks whether kernel idle timer should be active depending the policy decisions around
316 // refresh rates.
317 KernelIdleTimerAction getIdleTimerAction() const;
318
Ady Abraham0bb6a472020-10-12 10:22:13 -0700319 // Stores the preferred refresh rate that an app should run at.
Ady Abraham62f216c2020-10-13 19:07:23 -0700320 // FrameRateOverride.refreshRateHz == 0 means no preference.
321 void setPreferredRefreshRateForUid(FrameRateOverride) EXCLUDES(mLock);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700322
323 // Returns a divider for the current refresh rate
324 int getRefreshRateDividerForUid(uid_t) const EXCLUDES(mLock);
325
Marin Shalamanovba421a82020-11-10 21:49:26 +0100326 void dump(std::string& result) const EXCLUDES(mLock);
327
Ady Abraham62f216c2020-10-13 19:07:23 -0700328 // Returns the current frame rate overrides
329 std::vector<FrameRateOverride> getFrameRateOverrides() EXCLUDES(mLock);
330
Dominik Laskowski22488f62019-03-28 09:53:04 -0700331private:
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700332 friend class RefreshRateConfigsTest;
333
Ady Abraham2139f732019-11-13 18:56:40 -0800334 void constructAvailableRefreshRates() REQUIRES(mLock);
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700335 static std::vector<float> constructKnownFrameRates(
336 const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs);
Ady Abraham2139f732019-11-13 18:56:40 -0800337
338 void getSortedRefreshRateList(
339 const std::function<bool(const RefreshRate&)>& shouldAddRefreshRate,
340 std::vector<const RefreshRate*>* outRefreshRates);
341
Ady Abraham34702102020-02-10 14:12:05 -0800342 // Returns the refresh rate with the highest score in the collection specified from begin
343 // to end. If there are more than one with the same highest refresh rate, the first one is
344 // returned.
345 template <typename Iter>
346 const RefreshRate* getBestRefreshRate(Iter begin, Iter end) const;
347
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800348 // Returns number of display frames and remainder when dividing the layer refresh period by
349 // display refresh period.
350 std::pair<nsecs_t, nsecs_t> getDisplayFrames(nsecs_t layerPeriod, nsecs_t displayPeriod) const;
351
Steven Thomasf734df42020-04-13 21:09:28 -0700352 // Returns the lowest refresh rate according to the current policy. May change at runtime. Only
353 // uses the primary range, not the app request range.
354 const RefreshRate& getMinRefreshRateByPolicyLocked() const REQUIRES(mLock);
355
356 // Returns the highest refresh rate according to the current policy. May change at runtime. Only
357 // uses the primary range, not the app request range.
358 const RefreshRate& getMaxRefreshRateByPolicyLocked() const REQUIRES(mLock);
359
Ana Krulec3d367c82020-02-25 15:02:01 -0800360 // Returns the current refresh rate, if allowed. Otherwise the default that is allowed by
361 // the policy.
362 const RefreshRate& getCurrentRefreshRateByPolicyLocked() const REQUIRES(mLock);
363
Steven Thomasd4071902020-03-24 16:02:53 -0700364 const Policy* getCurrentPolicyLocked() const REQUIRES(mLock);
365 bool isPolicyValid(const Policy& policy);
366
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700367 // The list of refresh rates, indexed by display config ID. This must not change after this
368 // object is initialized.
Ady Abraham2139f732019-11-13 18:56:40 -0800369 AllRefreshRatesMapType mRefreshRates;
370
Steven Thomasf734df42020-04-13 21:09:28 -0700371 // The list of refresh rates in the primary range of the current policy, ordered by vsyncPeriod
372 // (the first element is the lowest refresh rate).
373 std::vector<const RefreshRate*> mPrimaryRefreshRates GUARDED_BY(mLock);
374
375 // The list of refresh rates in the app request range of the current policy, ordered by
376 // vsyncPeriod (the first element is the lowest refresh rate).
377 std::vector<const RefreshRate*> mAppRequestRefreshRates GUARDED_BY(mLock);
Ady Abraham2139f732019-11-13 18:56:40 -0800378
379 // The current config. This will change at runtime. This is set by SurfaceFlinger on
380 // the main thread, and read by the Scheduler (and other objects) on other threads.
381 const RefreshRate* mCurrentRefreshRate GUARDED_BY(mLock);
382
Steven Thomasd4071902020-03-24 16:02:53 -0700383 // The policy values will change at runtime. They're set by SurfaceFlinger on the main thread,
384 // and read by the Scheduler (and other objects) on other threads.
385 Policy mDisplayManagerPolicy GUARDED_BY(mLock);
386 std::optional<Policy> mOverridePolicy GUARDED_BY(mLock);
Ady Abraham2139f732019-11-13 18:56:40 -0800387
Ady Abraham62f216c2020-10-13 19:07:23 -0700388 // A mapping between a UID and a preferred refresh rate that this app would
389 // run at.
Ady Abraham0bb6a472020-10-12 10:22:13 -0700390 std::unordered_map<uid_t, float> mPreferredRefreshRateForUid GUARDED_BY(mLock);
391
Ady Abraham2139f732019-11-13 18:56:40 -0800392 // The min and max refresh rates supported by the device.
393 // This will not change at runtime.
394 const RefreshRate* mMinSupportedRefreshRate;
395 const RefreshRate* mMaxSupportedRefreshRate;
396
Ady Abraham2139f732019-11-13 18:56:40 -0800397 mutable std::mutex mLock;
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700398
399 // A sorted list of known frame rates that a Heuristic layer will choose
400 // from based on the closest value.
401 const std::vector<float> mKnownFrameRates;
Ana Krulecb43429d2019-01-09 14:28:51 -0800402};
403
Dominik Laskowski98041832019-08-01 18:35:59 -0700404} // namespace android::scheduler