blob: 548c34b5d2f5a124611f8d77b946f117e82e4039 [file] [log] [blame]
Ana Krulec98b5b242018-08-10 15:03:23 -07001/*
2 * Copyright 2018 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 <atomic>
Kevin DuBois413287f2019-02-25 08:46:47 -080020#include <functional>
Dominik Laskowski756b7892021-08-04 12:53:59 -070021#include <future>
Ana Krulec98b5b242018-08-10 15:03:23 -070022#include <memory>
Dominik Laskowski98041832019-08-01 18:35:59 -070023#include <mutex>
24#include <optional>
25#include <unordered_map>
Ana Krulec98b5b242018-08-10 15:03:23 -070026
Ady Abrahamdec1a412020-01-24 10:23:50 -080027// TODO(b/129481165): remove the #pragma below and fix conversion issues
28#pragma clang diagnostic push
29#pragma clang diagnostic ignored "-Wconversion"
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010030#pragma clang diagnostic ignored "-Wextra"
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080031#include <ui/GraphicTypes.h>
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010032#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
Ana Krulec98b5b242018-08-10 15:03:23 -070033
Dominik Laskowski068173d2021-08-11 17:22:59 -070034#include <scheduler/Features.h>
35
Ana Krulec98b5b242018-08-10 15:03:23 -070036#include "EventThread.h"
Ana Krulec3084c052018-11-21 20:27:17 +010037#include "LayerHistory.h"
Dominik Laskowski756b7892021-08-04 12:53:59 -070038#include "MessageQueue.h"
Ana Krulecf2c006d2019-06-21 15:37:07 -070039#include "OneShotTimer.h"
Ana Krulec8d3e4f32019-03-05 10:40:33 -080040#include "RefreshRateConfigs.h"
Ana Krulec434c22d2018-11-28 13:48:36 +010041#include "SchedulerUtils.h"
Dominik Laskowski068173d2021-08-11 17:22:59 -070042#include "VsyncSchedule.h"
Ana Krulec98b5b242018-08-10 15:03:23 -070043
44namespace android {
45
Dominik Laskowski98041832019-08-01 18:35:59 -070046class FenceTime;
Dominik Laskowski6505f792019-09-18 11:10:05 -070047class InjectVSyncSource;
Ana Krulece588e312018-09-18 12:32:24 -070048
Adithya Srinivasan5f683cf2020-09-15 14:21:04 -070049namespace frametimeline {
50class TokenManager;
51} // namespace frametimeline
52
Dominik Laskowski068173d2021-08-11 17:22:59 -070053namespace scheduler {
54
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070055struct ISchedulerCallback {
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -070056 // Indicates frame activity, i.e. whether commit and/or composite is taking place.
57 enum class FrameHint { kNone, kActive };
58
Dominik Laskowski068173d2021-08-11 17:22:59 -070059 using RefreshRate = RefreshRateConfigs::RefreshRate;
60 using DisplayModeEvent = scheduler::DisplayModeEvent;
61
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -070062 virtual void scheduleComposite(FrameHint) = 0;
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070063 virtual void setVsyncEnabled(bool) = 0;
Dominik Laskowski068173d2021-08-11 17:22:59 -070064 virtual void changeRefreshRate(const RefreshRate&, DisplayModeEvent) = 0;
Ady Abrahama09852a2020-02-20 14:23:42 -080065 virtual void kernelTimerChanged(bool expired) = 0;
Ady Abraham62a0be22020-12-08 16:54:10 -080066 virtual void triggerOnFrameRateOverridesChanged() = 0;
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070067
68protected:
69 ~ISchedulerCallback() = default;
Ady Abraham3a77a7b2019-12-02 18:46:59 -080070};
71
Dominik Laskowski756b7892021-08-04 12:53:59 -070072class Scheduler : impl::MessageQueue {
73 using Impl = impl::MessageQueue;
74
Ana Krulec98b5b242018-08-10 15:03:23 -070075public:
Dominik Laskowski068173d2021-08-11 17:22:59 -070076 Scheduler(ICompositor&, ISchedulerCallback&, FeatureFlags);
Dominik Laskowski83bd7712022-01-07 14:30:53 -080077 virtual ~Scheduler();
78
79 void startTimers();
80 void setRefreshRateConfigs(std::shared_ptr<RefreshRateConfigs>)
81 EXCLUDES(mRefreshRateConfigsLock);
82
83 void run();
Ana Krulec98b5b242018-08-10 15:03:23 -070084
Dominik Laskowski068173d2021-08-11 17:22:59 -070085 void createVsyncSchedule(FeatureFlags);
Dominik Laskowski756b7892021-08-04 12:53:59 -070086
87 using Impl::initVsync;
88 using Impl::setInjector;
89
90 using Impl::getScheduledFrameTime;
91 using Impl::setDuration;
92
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -070093 using Impl::scheduleFrame;
Dominik Laskowski756b7892021-08-04 12:53:59 -070094
95 // Schedule an asynchronous or synchronous task on the main thread.
96 template <typename F, typename T = std::invoke_result_t<F>>
97 [[nodiscard]] std::future<T> schedule(F&& f) {
98 auto [task, future] = makeTask(std::move(f));
99 postMessage(std::move(task));
100 return std::move(future);
101 }
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700102
Adithya Srinivasan5f683cf2020-09-15 14:21:04 -0700103 ConnectionHandle createConnection(const char* connectionName, frametimeline::TokenManager*,
Ady Abraham9c53ee72020-07-22 21:16:18 -0700104 std::chrono::nanoseconds workDuration,
105 std::chrono::nanoseconds readyDuration,
Dominik Laskowski98041832019-08-01 18:35:59 -0700106 impl::EventThread::InterceptVSyncsCallback);
Ana Krulec98b5b242018-08-10 15:03:23 -0700107
Ady Abraham62f216c2020-10-13 19:07:23 -0700108 sp<IDisplayEventConnection> createDisplayEventConnection(
109 ConnectionHandle, ISurfaceComposer::EventRegistrationFlags eventRegistration = {});
Ana Krulece588e312018-09-18 12:32:24 -0700110
Dominik Laskowski98041832019-08-01 18:35:59 -0700111 sp<EventThreadConnection> getEventConnection(ConnectionHandle);
Kevin DuBois413287f2019-02-25 08:46:47 -0800112
Dominik Laskowski98041832019-08-01 18:35:59 -0700113 void onHotplugReceived(ConnectionHandle, PhysicalDisplayId, bool connected);
Dominik Laskowski068173d2021-08-11 17:22:59 -0700114 void onPrimaryDisplayModeChanged(ConnectionHandle, DisplayModePtr) EXCLUDES(mPolicyLock);
Ady Abraham690f4612021-07-01 23:24:03 -0700115 void onNonPrimaryDisplayModeChanged(ConnectionHandle, DisplayModePtr);
Dominik Laskowski98041832019-08-01 18:35:59 -0700116 void onScreenAcquired(ConnectionHandle);
117 void onScreenReleased(ConnectionHandle);
Ana Krulece588e312018-09-18 12:32:24 -0700118
Ady Abraham62a0be22020-12-08 16:54:10 -0800119 void onFrameRateOverridesChanged(ConnectionHandle, PhysicalDisplayId)
Ady Abraham3efa3942021-06-24 19:01:25 -0700120 EXCLUDES(mFrameRateOverridesLock) EXCLUDES(mConnectionsLock);
Ady Abraham62f216c2020-10-13 19:07:23 -0700121
Ady Abraham9c53ee72020-07-22 21:16:18 -0700122 // Modifies work duration in the event thread.
123 void setDuration(ConnectionHandle, std::chrono::nanoseconds workDuration,
124 std::chrono::nanoseconds readyDuration);
Ana Krulec98b5b242018-08-10 15:03:23 -0700125
Ady Abrahame90dd522020-12-29 12:08:45 -0800126 DisplayStatInfo getDisplayStatInfo(nsecs_t now);
Ana Krulece588e312018-09-18 12:32:24 -0700127
Dominik Laskowski6505f792019-09-18 11:10:05 -0700128 // Returns injector handle if injection has toggled, or an invalid handle otherwise.
129 ConnectionHandle enableVSyncInjection(bool enable);
Dominik Laskowski6505f792019-09-18 11:10:05 -0700130 // Returns false if injection is disabled.
Ady Abraham9c53ee72020-07-22 21:16:18 -0700131 bool injectVSync(nsecs_t when, nsecs_t expectedVSyncTime, nsecs_t deadlineTimestamp);
Ana Krulece588e312018-09-18 12:32:24 -0700132 void enableHardwareVsync();
133 void disableHardwareVsync(bool makeUnavailable);
Dominik Laskowski98041832019-08-01 18:35:59 -0700134
Alec Mourif8e689c2019-05-20 18:32:22 -0700135 // Resyncs the scheduler to hardware vsync.
136 // If makeAvailable is true, then hardware vsync will be turned on.
137 // Otherwise, if hardware vsync is not already enabled then this method will
138 // no-op.
139 // The period is the vsync period from the current display configuration.
Ana Krulecc2870422019-01-29 19:00:58 -0800140 void resyncToHardwareVsync(bool makeAvailable, nsecs_t period);
Ady Abraham3efa3942021-06-24 19:01:25 -0700141 void resync() EXCLUDES(mRefreshRateConfigsLock);
Dominik Laskowski98041832019-08-01 18:35:59 -0700142
Ady Abraham8cb21882020-08-26 18:22:05 -0700143 // Passes a vsync sample to VsyncController. periodFlushed will be true if
144 // VsyncController detected that the vsync period changed, and false otherwise.
Ady Abraham5dee2f12020-02-05 17:49:47 -0800145 void addResyncSample(nsecs_t timestamp, std::optional<nsecs_t> hwcVsyncPeriod,
146 bool* periodFlushed);
Dominik Laskowski068173d2021-08-11 17:22:59 -0700147 void addPresentFence(std::shared_ptr<FenceTime>);
Ady Abraham8f1ee7f2019-04-05 10:32:50 -0700148
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700149 // Layers are registered on creation, and unregistered when the weak reference expires.
150 void registerLayer(Layer*);
Ady Abraham3efa3942021-06-24 19:01:25 -0700151 void recordLayerHistory(Layer*, nsecs_t presentTime, LayerHistory::LayerUpdateType updateType)
152 EXCLUDES(mRefreshRateConfigsLock);
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100153 void setModeChangePending(bool pending);
Ady Abrahambdda8f02021-04-01 16:06:11 -0700154 void deregisterLayer(Layer*);
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -0700155
Dominik Laskowski49cea512019-11-12 14:13:23 -0800156 // Detects content using layer history, and selects a matching refresh rate.
Ady Abraham3efa3942021-06-24 19:01:25 -0700157 void chooseRefreshRateForContent() EXCLUDES(mRefreshRateConfigsLock);
Ady Abraham97d04232019-03-05 19:48:12 -0800158
Ady Abraham8532d012019-05-08 14:50:56 -0700159 void resetIdleTimer();
160
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700161 // Indicates that touch interaction is taking place.
162 void onTouchHint();
Ady Abraham8532d012019-05-08 14:50:56 -0700163
Ady Abraham6fe2c172019-07-12 12:37:57 -0700164 void setDisplayPowerState(bool normal);
165
Dominik Laskowski068173d2021-08-11 17:22:59 -0700166 VSyncDispatch& getVsyncDispatch() { return mVsyncSchedule->getDispatch(); }
Ady Abraham55fa7272020-09-30 19:19:27 -0700167
Ady Abraham0bb6a472020-10-12 10:22:13 -0700168 // Returns true if a given vsync timestamp is considered valid vsync
169 // for a given uid
Ady Abraham62a0be22020-12-08 16:54:10 -0800170 bool isVsyncValid(nsecs_t expectedVsyncTimestamp, uid_t uid) const
Ady Abraham3efa3942021-06-24 19:01:25 -0700171 EXCLUDES(mFrameRateOverridesLock);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700172
Ady Abraham3645e642021-04-20 18:39:00 -0700173 std::chrono::steady_clock::time_point getPreviousVsyncFrom(nsecs_t expectedPresentTime) const;
174
Dominik Laskowski98041832019-08-01 18:35:59 -0700175 void dump(std::string&) const;
176 void dump(ConnectionHandle, std::string&) const;
Ady Abraham8cb21882020-08-26 18:22:05 -0700177 void dumpVsync(std::string&) const;
Ana Krulec0c8cd522018-08-31 12:27:28 -0700178
Ady Abraham2139f732019-11-13 18:56:40 -0800179 // Get the appropriate refresh for current conditions.
Ady Abraham690f4612021-07-01 23:24:03 -0700180 DisplayModePtr getPreferredDisplayMode();
Daniel Solomon0f0ddc12019-08-19 19:31:09 -0700181
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800182 // Notifies the scheduler about a refresh rate timeline change.
Peiyong Line9d809e2020-04-14 13:10:48 -0700183 void onNewVsyncPeriodChangeTimeline(const hal::VsyncPeriodChangeTimeline& timeline);
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800184
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700185 // Notifies the scheduler post composition.
186 void onPostComposition(nsecs_t presentTime);
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800187
Ady Abraham8a82ba62020-01-17 12:43:17 -0800188 // Notifies the scheduler when the display size has changed. Called from SF's main thread
Ady Abraham7825c682021-05-17 15:12:14 -0700189 void onActiveDisplayAreaChanged(uint32_t displayArea);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800190
Alec Mouri717bcb62020-02-10 17:07:19 -0800191 size_t getEventThreadConnectionCount(ConnectionHandle handle);
192
Ady Abraham9c53ee72020-07-22 21:16:18 -0700193 std::unique_ptr<VSyncSource> makePrimaryDispSyncSource(const char* name,
194 std::chrono::nanoseconds workDuration,
195 std::chrono::nanoseconds readyDuration,
196 bool traceVsync = true);
197
Ady Abraham62a0be22020-12-08 16:54:10 -0800198 // Stores the preferred refresh rate that an app should run at.
199 // FrameRateOverride.refreshRateHz == 0 means no preference.
Ady Abraham3efa3942021-06-24 19:01:25 -0700200 void setPreferredRefreshRateForUid(FrameRateOverride) EXCLUDES(mFrameRateOverridesLock);
Alec Mouri7d436ec2021-01-27 20:40:50 -0800201 // Retrieves the overridden refresh rate for a given uid.
Ady Abraham3efa3942021-06-24 19:01:25 -0700202 std::optional<Fps> getFrameRateOverride(uid_t uid) const
203 EXCLUDES(mRefreshRateConfigsLock, mFrameRateOverridesLock);
204
Ady Abraham3efa3942021-06-24 19:01:25 -0700205 nsecs_t getVsyncPeriodFromRefreshRateConfigs() const EXCLUDES(mRefreshRateConfigsLock) {
206 std::scoped_lock lock(mRefreshRateConfigsLock);
207 return mRefreshRateConfigs->getCurrentRefreshRate().getVsyncPeriod();
208 }
Ady Abraham62a0be22020-12-08 16:54:10 -0800209
Nathaniel Nifong1303d912021-10-06 09:41:24 -0400210 // Returns the framerate of the layer with the given sequence ID
211 float getLayerFramerate(nsecs_t now, int32_t id) const {
212 return mLayerHistory.getLayerFramerate(now, id);
213 }
214
Ana Krulec98b5b242018-08-10 15:03:23 -0700215private:
Ana Krulecafb45842019-02-13 13:33:03 -0800216 friend class TestableScheduler;
217
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700218 using FrameHint = ISchedulerCallback::FrameHint;
219
Dominik Laskowskidd252cd2019-07-26 09:10:16 -0700220 enum class ContentDetectionState { Off, On };
221 enum class TimerState { Reset, Expired };
222 enum class TouchState { Inactive, Active };
Ana Krulecfefd6ae2019-02-13 17:53:08 -0800223
Dominik Laskowski6505f792019-09-18 11:10:05 -0700224 // Create a connection on the given EventThread.
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700225 ConnectionHandle createConnection(std::unique_ptr<EventThread>);
Ady Abraham62f216c2020-10-13 19:07:23 -0700226 sp<EventThreadConnection> createConnectionInternal(
227 EventThread*, ISurfaceComposer::EventRegistrationFlags eventRegistration = {});
Dominik Laskowskiccf37d72019-02-01 16:47:58 -0800228
Dominik Laskowski3a80a382019-07-25 11:16:07 -0700229 // Update feature state machine to given state when corresponding timer resets or expires.
Ady Abraham3efa3942021-06-24 19:01:25 -0700230 void kernelIdleTimerCallback(TimerState) EXCLUDES(mRefreshRateConfigsLock);
Dominik Laskowski3a80a382019-07-25 11:16:07 -0700231 void idleTimerCallback(TimerState);
232 void touchTimerCallback(TimerState);
233 void displayPowerTimerCallback(TimerState);
234
Ady Abraham6fe2c172019-07-12 12:37:57 -0700235 // handles various timer features to change the refresh rate.
236 template <class T>
Ady Abrahamdfd62162020-06-10 16:11:56 -0700237 bool handleTimerStateChanged(T* currentState, T newState);
Dominik Laskowski98041832019-08-01 18:35:59 -0700238
239 void setVsyncPeriod(nsecs_t period);
240
Ana Krulec3803b8d2020-02-03 16:35:46 -0800241 // This function checks whether individual features that are affecting the refresh rate
Marin Shalamanov23c44202020-12-22 19:09:20 +0100242 // selection were initialized, prioritizes them, and calculates the DisplayModeId
Ana Krulec3803b8d2020-02-03 16:35:46 -0800243 // for the suggested refresh rate.
Ady Abraham690f4612021-07-01 23:24:03 -0700244 DisplayModePtr calculateRefreshRateModeId(
Dominik Laskowski068173d2021-08-11 17:22:59 -0700245 RefreshRateConfigs::GlobalSignals* consideredSignals = nullptr) REQUIRES(mPolicyLock);
Ana Krulec7ab56032018-11-02 20:51:06 +0100246
Dominik Laskowski068173d2021-08-11 17:22:59 -0700247 void dispatchCachedReportedMode() REQUIRES(mPolicyLock) EXCLUDES(mRefreshRateConfigsLock);
248 bool updateFrameRateOverrides(RefreshRateConfigs::GlobalSignals, Fps displayRefreshRate)
249 REQUIRES(mPolicyLock) EXCLUDES(mFrameRateOverridesLock);
Ady Abraham62a0be22020-12-08 16:54:10 -0800250
Ady Abraham3efa3942021-06-24 19:01:25 -0700251 impl::EventThread::ThrottleVsyncCallback makeThrottleVsyncCallback() const
252 EXCLUDES(mRefreshRateConfigsLock);
Jorim Jaggic0086af2021-02-12 18:18:11 +0100253 impl::EventThread::GetVsyncPeriodFunction makeGetVsyncPeriodFunction() const;
Ady Abrahamdfd62162020-06-10 16:11:56 -0700254
Dominik Laskowski068173d2021-08-11 17:22:59 -0700255 std::shared_ptr<RefreshRateConfigs> holdRefreshRateConfigs() const
Ady Abraham3efa3942021-06-24 19:01:25 -0700256 EXCLUDES(mRefreshRateConfigsLock) {
257 std::scoped_lock lock(mRefreshRateConfigsLock);
258 return mRefreshRateConfigs;
259 }
260
Dominik Laskowski98041832019-08-01 18:35:59 -0700261 // Stores EventThread associated with a given VSyncSource, and an initial EventThreadConnection.
262 struct Connection {
263 sp<EventThreadConnection> connection;
264 std::unique_ptr<EventThread> thread;
265 };
Ady Abraham09bd3922019-04-08 10:44:56 -0700266
Dominik Laskowski98041832019-08-01 18:35:59 -0700267 ConnectionHandle::Id mNextConnectionHandleId = 0;
Ana Krulec6ddd2612020-09-24 13:06:33 -0700268 mutable std::mutex mConnectionsLock;
269 std::unordered_map<ConnectionHandle, Connection> mConnections GUARDED_BY(mConnectionsLock);
Ana Krulece588e312018-09-18 12:32:24 -0700270
Dominik Laskowski6505f792019-09-18 11:10:05 -0700271 bool mInjectVSyncs = false;
272 InjectVSyncSource* mVSyncInjector = nullptr;
273 ConnectionHandle mInjectorConnectionHandle;
274
Ady Abraham4f960d12021-10-13 16:59:49 -0700275 mutable std::mutex mHWVsyncLock;
Dominik Laskowski98041832019-08-01 18:35:59 -0700276 bool mPrimaryHWVsyncEnabled GUARDED_BY(mHWVsyncLock) = false;
277 bool mHWVsyncAvailable GUARDED_BY(mHWVsyncLock) = false;
278
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700279 std::atomic<nsecs_t> mLastResyncTime = 0;
Ana Krulece588e312018-09-18 12:32:24 -0700280
Dominik Laskowski068173d2021-08-11 17:22:59 -0700281 const FeatureFlags mFeatures;
282 std::optional<VsyncSchedule> mVsyncSchedule;
Ana Krulec7ab56032018-11-02 20:51:06 +0100283
Dominik Laskowski49cea512019-11-12 14:13:23 -0800284 // Used to choose refresh rate if content detection is enabled.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700285 LayerHistory mLayerHistory;
Ana Krulecfb772822018-11-30 10:44:07 +0100286
Ady Abraham8532d012019-05-08 14:50:56 -0700287 // Timer used to monitor touch events.
Dominik Laskowski068173d2021-08-11 17:22:59 -0700288 std::optional<OneShotTimer> mTouchTimer;
Ady Abraham6fe2c172019-07-12 12:37:57 -0700289 // Timer used to monitor display power mode.
Dominik Laskowski068173d2021-08-11 17:22:59 -0700290 std::optional<OneShotTimer> mDisplayPowerTimer;
Ady Abraham6fe2c172019-07-12 12:37:57 -0700291
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800292 ISchedulerCallback& mSchedulerCallback;
Ana Krulecfefd6ae2019-02-13 17:53:08 -0800293
Dominik Laskowski068173d2021-08-11 17:22:59 -0700294 mutable std::mutex mPolicyLock;
Dominik Laskowskidd252cd2019-07-26 09:10:16 -0700295
296 struct {
Dominik Laskowski068173d2021-08-11 17:22:59 -0700297 // Policy for choosing the display mode.
298 LayerHistory::Summary contentRequirements;
Dominik Laskowskidd252cd2019-07-26 09:10:16 -0700299 TimerState idleTimer = TimerState::Reset;
300 TouchState touch = TouchState::Inactive;
301 TimerState displayPowerTimer = TimerState::Expired;
Dominik Laskowskidd252cd2019-07-26 09:10:16 -0700302 bool isDisplayPowerStateNormal = true;
Ady Abrahamdfd62162020-06-10 16:11:56 -0700303
Dominik Laskowski068173d2021-08-11 17:22:59 -0700304 // Chosen display mode.
305 DisplayModePtr mode;
306
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100307 struct ModeChangedParams {
Ady Abrahamdfd62162020-06-10 16:11:56 -0700308 ConnectionHandle handle;
Ady Abraham690f4612021-07-01 23:24:03 -0700309 DisplayModePtr mode;
Ady Abrahamdfd62162020-06-10 16:11:56 -0700310 };
311
Dominik Laskowski068173d2021-08-11 17:22:59 -0700312 // Parameters for latest dispatch of mode change event.
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100313 std::optional<ModeChangedParams> cachedModeChangedParams;
Dominik Laskowski068173d2021-08-11 17:22:59 -0700314 } mPolicy GUARDED_BY(mPolicyLock);
Ady Abraham09bd3922019-04-08 10:44:56 -0700315
Ady Abraham3efa3942021-06-24 19:01:25 -0700316 mutable std::mutex mRefreshRateConfigsLock;
Dominik Laskowski068173d2021-08-11 17:22:59 -0700317 std::shared_ptr<RefreshRateConfigs> mRefreshRateConfigs GUARDED_BY(mRefreshRateConfigsLock);
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800318
319 std::mutex mVsyncTimelineLock;
Peiyong Line9d809e2020-04-14 13:10:48 -0700320 std::optional<hal::VsyncPeriodChangeTimeline> mLastVsyncPeriodChangeTimeline
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800321 GUARDED_BY(mVsyncTimelineLock);
322 static constexpr std::chrono::nanoseconds MAX_VSYNC_APPLIED_TIME = 200ms;
Ady Abraham8735eac2020-08-12 16:35:04 -0700323
Ady Abraham62a0be22020-12-08 16:54:10 -0800324 // The frame rate override lists need their own mutex as they are being read
325 // by SurfaceFlinger, Scheduler and EventThread (as a callback) to prevent deadlocks
Ady Abraham3efa3942021-06-24 19:01:25 -0700326 mutable std::mutex mFrameRateOverridesLock;
Ady Abraham62a0be22020-12-08 16:54:10 -0800327
328 // mappings between a UID and a preferred refresh rate that this app would
329 // run at.
Dominik Laskowski068173d2021-08-11 17:22:59 -0700330 RefreshRateConfigs::UidToFrameRateOverride mFrameRateOverridesByContent
Ady Abraham3efa3942021-06-24 19:01:25 -0700331 GUARDED_BY(mFrameRateOverridesLock);
Dominik Laskowski068173d2021-08-11 17:22:59 -0700332 RefreshRateConfigs::UidToFrameRateOverride mFrameRateOverridesFromBackdoor
Ady Abraham3efa3942021-06-24 19:01:25 -0700333 GUARDED_BY(mFrameRateOverridesLock);
Ady Abraham4f960d12021-10-13 16:59:49 -0700334
335 // Keeps track of whether the screen is acquired for debug
336 std::atomic<bool> mScreenAcquired = false;
Ana Krulec98b5b242018-08-10 15:03:23 -0700337};
338
Dominik Laskowski068173d2021-08-11 17:22:59 -0700339} // namespace scheduler
Ana Krulec7ab56032018-11-02 20:51:06 +0100340} // namespace android