Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 17 | #pragma once |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 18 | |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 19 | #include <android-base/thread_annotations.h> |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 20 | #include <android/gui/BnDisplayEventConnection.h> |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 21 | #include <gui/DisplayEventReceiver.h> |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 22 | #include <private/gui/BitTube.h> |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 23 | #include <sys/types.h> |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 24 | #include <utils/Errors.h> |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 25 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 26 | #include <scheduler/FrameRateMode.h> |
Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 27 | #include <condition_variable> |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 28 | #include <cstdint> |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 29 | #include <deque> |
Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 30 | #include <mutex> |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 31 | #include <optional> |
Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 32 | #include <thread> |
Chia-I Wu | 98cd38f | 2018-09-14 11:53:25 -0700 | [diff] [blame] | 33 | #include <vector> |
Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 34 | |
Marin Shalamanov | 23c4420 | 2020-12-22 19:09:20 +0100 | [diff] [blame] | 35 | #include "DisplayHardware/DisplayMode.h" |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 36 | #include "TracedOrdinal.h" |
| 37 | #include "VSyncDispatch.h" |
| 38 | #include "VsyncSchedule.h" |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 39 | |
| 40 | // --------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 41 | namespace android { |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 42 | // --------------------------------------------------------------------------- |
| 43 | |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 44 | class EventThread; |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 45 | class EventThreadTest; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 46 | class SurfaceFlinger; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 47 | |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 48 | namespace frametimeline { |
| 49 | class TokenManager; |
| 50 | } // namespace frametimeline |
| 51 | |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 52 | using gui::ParcelableVsyncEventData; |
Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 53 | using gui::VsyncEventData; |
| 54 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 55 | // --------------------------------------------------------------------------- |
| 56 | |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 57 | using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride; |
Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 58 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 59 | enum class VSyncRequest { |
Tim Murray | b5daa91 | 2020-09-09 21:29:13 +0000 | [diff] [blame] | 60 | None = -2, |
| 61 | // Single wakes up for the next two frames to avoid scheduler overhead |
| 62 | Single = -1, |
| 63 | // SingleSuppressCallback only wakes up for the next frame |
| 64 | SingleSuppressCallback = 0, |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 65 | Periodic = 1, |
| 66 | // Subsequent values are periods. |
| 67 | }; |
| 68 | |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 69 | class EventThreadConnection : public gui::BnDisplayEventConnection { |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 70 | public: |
Ady Abraham | f285161 | 2023-09-25 17:19:00 -0700 | [diff] [blame] | 71 | EventThreadConnection(EventThread*, uid_t callingUid, |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 72 | EventRegistrationFlags eventRegistration = {}); |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 73 | virtual ~EventThreadConnection(); |
| 74 | |
| 75 | virtual status_t postEvent(const DisplayEventReceiver::Event& event); |
| 76 | |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 77 | binder::Status stealReceiveChannel(gui::BitTube* outChannel) override; |
| 78 | binder::Status setVsyncRate(int rate) override; |
| 79 | binder::Status requestNextVsync() override; // asynchronous |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 80 | binder::Status getLatestVsyncEventData(ParcelableVsyncEventData* outVsyncEventData) override; |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 81 | binder::Status getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) override; |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 82 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 83 | VSyncRequest vsyncRequest = VSyncRequest::None; |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 84 | const uid_t mOwnerUid; |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 85 | const EventRegistrationFlags mEventRegistration; |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 86 | |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 87 | /** The frame rate set to the attached choreographer. */ |
| 88 | Fps frameRate; |
| 89 | |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 90 | private: |
| 91 | virtual void onFirstRef(); |
| 92 | EventThread* const mEventThread; |
Ady Abraham | 899e8cd | 2022-06-06 15:16:06 -0700 | [diff] [blame] | 93 | std::mutex mLock; |
| 94 | gui::BitTube mChannel GUARDED_BY(mLock); |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 95 | |
| 96 | std::vector<DisplayEventReceiver::Event> mPendingEvents; |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 99 | class EventThread { |
| 100 | public: |
| 101 | virtual ~EventThread(); |
| 102 | |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 103 | virtual sp<EventThreadConnection> createEventConnection( |
Ady Abraham | f285161 | 2023-09-25 17:19:00 -0700 | [diff] [blame] | 104 | EventRegistrationFlags eventRegistration = {}) const = 0; |
Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 105 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 106 | // Feed clients with fake VSYNC, e.g. while the display is off. |
| 107 | virtual void enableSyntheticVsync(bool) = 0; |
Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 108 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 109 | virtual void onHotplugReceived(PhysicalDisplayId displayId, bool connected) = 0; |
Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 110 | |
Brian Johnson | 5dcd75d | 2023-08-15 09:36:37 -0700 | [diff] [blame] | 111 | virtual void onHotplugConnectionError(int32_t connectionError) = 0; |
| 112 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 113 | // called when SF changes the active mode and apps needs to be notified about the change |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 114 | virtual void onModeChanged(const scheduler::FrameRateMode&) = 0; |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 115 | |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 116 | // called when SF updates the Frame Rate Override list |
| 117 | virtual void onFrameRateOverridesChanged(PhysicalDisplayId displayId, |
| 118 | std::vector<FrameRateOverride> overrides) = 0; |
| 119 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 120 | virtual void dump(std::string& result) const = 0; |
Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 121 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 122 | virtual void setDuration(std::chrono::nanoseconds workDuration, |
| 123 | std::chrono::nanoseconds readyDuration) = 0; |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 124 | |
| 125 | virtual status_t registerDisplayEventConnection( |
| 126 | const sp<EventThreadConnection>& connection) = 0; |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 127 | virtual void setVsyncRate(uint32_t rate, const sp<EventThreadConnection>& connection) = 0; |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 128 | // Requests the next vsync. If resetIdleTimer is set to true, it resets the idle timer. |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 129 | virtual void requestNextVsync(const sp<EventThreadConnection>& connection) = 0; |
Ady Abraham | 40ec584 | 2024-04-04 13:22:38 -0700 | [diff] [blame] | 130 | virtual VsyncEventData getLatestVsyncEventData(const sp<EventThreadConnection>& connection, |
| 131 | nsecs_t now) const = 0; |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 132 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 133 | virtual void onNewVsyncSchedule(std::shared_ptr<scheduler::VsyncSchedule>) = 0; |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 134 | |
| 135 | virtual void onHdcpLevelsChanged(PhysicalDisplayId displayId, int32_t connectedLevel, |
| 136 | int32_t maxLevel) = 0; |
Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 137 | }; |
| 138 | |
Ady Abraham | f285161 | 2023-09-25 17:19:00 -0700 | [diff] [blame] | 139 | struct IEventThreadCallback { |
| 140 | virtual ~IEventThreadCallback() = default; |
| 141 | |
| 142 | virtual bool throttleVsync(TimePoint, uid_t) = 0; |
| 143 | virtual Period getVsyncPeriod(uid_t) = 0; |
| 144 | virtual void resync() = 0; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 145 | virtual void onExpectedPresentTimePosted(TimePoint) = 0; |
Ady Abraham | f285161 | 2023-09-25 17:19:00 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 148 | namespace impl { |
| 149 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 150 | class EventThread : public android::EventThread { |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 151 | public: |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 152 | EventThread(const char* name, std::shared_ptr<scheduler::VsyncSchedule>, |
Ady Abraham | f285161 | 2023-09-25 17:19:00 -0700 | [diff] [blame] | 153 | frametimeline::TokenManager*, IEventThreadCallback& callback, |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 154 | std::chrono::nanoseconds workDuration, std::chrono::nanoseconds readyDuration); |
Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 155 | ~EventThread(); |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 156 | |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 157 | sp<EventThreadConnection> createEventConnection( |
Ady Abraham | f285161 | 2023-09-25 17:19:00 -0700 | [diff] [blame] | 158 | EventRegistrationFlags eventRegistration = {}) const override; |
Mathias Agopian | 8aedd47 | 2012-01-24 16:39:14 -0800 | [diff] [blame] | 159 | |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 160 | status_t registerDisplayEventConnection(const sp<EventThreadConnection>& connection) override; |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 161 | void setVsyncRate(uint32_t rate, const sp<EventThreadConnection>& connection) override; |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 162 | void requestNextVsync(const sp<EventThreadConnection>& connection) override; |
Ady Abraham | 40ec584 | 2024-04-04 13:22:38 -0700 | [diff] [blame] | 163 | VsyncEventData getLatestVsyncEventData(const sp<EventThreadConnection>& connection, |
| 164 | nsecs_t now) const override; |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 165 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 166 | void enableSyntheticVsync(bool) override; |
Mathias Agopian | 8aedd47 | 2012-01-24 16:39:14 -0800 | [diff] [blame] | 167 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 168 | void onHotplugReceived(PhysicalDisplayId displayId, bool connected) override; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 169 | |
Brian Johnson | 5dcd75d | 2023-08-15 09:36:37 -0700 | [diff] [blame] | 170 | void onHotplugConnectionError(int32_t connectionError) override; |
| 171 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 172 | void onModeChanged(const scheduler::FrameRateMode&) override; |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 173 | |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 174 | void onFrameRateOverridesChanged(PhysicalDisplayId displayId, |
| 175 | std::vector<FrameRateOverride> overrides) override; |
| 176 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 177 | void dump(std::string& result) const override; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 178 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 179 | void setDuration(std::chrono::nanoseconds workDuration, |
| 180 | std::chrono::nanoseconds readyDuration) override; |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 181 | |
Leon Scroggins III | b225360 | 2023-04-19 17:04:04 -0400 | [diff] [blame] | 182 | void onNewVsyncSchedule(std::shared_ptr<scheduler::VsyncSchedule>) override EXCLUDES(mMutex); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 183 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 184 | void onHdcpLevelsChanged(PhysicalDisplayId displayId, int32_t connectedLevel, |
| 185 | int32_t maxLevel) override; |
| 186 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 187 | private: |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 188 | friend EventThreadTest; |
| 189 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 190 | using DisplayEventConsumers = std::vector<sp<EventThreadConnection>>; |
| 191 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 192 | void threadMain(std::unique_lock<std::mutex>& lock) REQUIRES(mMutex); |
Chia-I Wu | 98cd38f | 2018-09-14 11:53:25 -0700 | [diff] [blame] | 193 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 194 | bool shouldConsumeEvent(const DisplayEventReceiver::Event& event, |
| 195 | const sp<EventThreadConnection>& connection) const REQUIRES(mMutex); |
| 196 | void dispatchEvent(const DisplayEventReceiver::Event& event, |
| 197 | const DisplayEventConsumers& consumers) REQUIRES(mMutex); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 198 | |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 199 | void removeDisplayEventConnectionLocked(const wp<EventThreadConnection>& connection) |
| 200 | REQUIRES(mMutex); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 201 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 202 | void onVsync(nsecs_t vsyncTime, nsecs_t wakeupTime, nsecs_t readyTime); |
Mathias Agopian | 2374866 | 2011-12-05 14:33:34 -0800 | [diff] [blame] | 203 | |
Rachel Lee | 8d0c610 | 2021-11-03 22:00:25 +0000 | [diff] [blame] | 204 | int64_t generateToken(nsecs_t timestamp, nsecs_t deadlineTimestamp, |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 205 | nsecs_t expectedPresentationTime) const; |
| 206 | void generateFrameTimeline(VsyncEventData& outVsyncEventData, nsecs_t frameInterval, |
| 207 | nsecs_t timestamp, nsecs_t preferredExpectedPresentationTime, |
| 208 | nsecs_t preferredDeadlineTimestamp) const; |
Rachel Lee | 3f02866 | 2021-11-04 19:32:24 +0000 | [diff] [blame] | 209 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 210 | scheduler::VSyncDispatch::Callback createDispatchCallback(); |
| 211 | |
Leon Scroggins III | b225360 | 2023-04-19 17:04:04 -0400 | [diff] [blame] | 212 | // Returns the old registration so it can be destructed outside the lock to |
| 213 | // avoid deadlock. |
| 214 | scheduler::VSyncCallbackRegistration onNewVsyncScheduleInternal( |
| 215 | std::shared_ptr<scheduler::VsyncSchedule>) EXCLUDES(mMutex); |
| 216 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 217 | const char* const mThreadName; |
| 218 | TracedOrdinal<int> mVsyncTracer; |
| 219 | TracedOrdinal<std::chrono::nanoseconds> mWorkDuration GUARDED_BY(mMutex); |
| 220 | std::chrono::nanoseconds mReadyDuration GUARDED_BY(mMutex); |
Leon Scroggins III | ed66a35 | 2023-03-23 17:55:43 -0400 | [diff] [blame] | 221 | std::shared_ptr<scheduler::VsyncSchedule> mVsyncSchedule GUARDED_BY(mMutex); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 222 | TimePoint mLastVsyncCallbackTime GUARDED_BY(mMutex) = TimePoint::now(); |
ramindani | 92ab987 | 2024-07-26 15:09:37 -0700 | [diff] [blame] | 223 | TimePoint mLastCommittedVsyncTime GUARDED_BY(mMutex) = TimePoint::now(); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 224 | scheduler::VSyncCallbackRegistration mVsyncRegistration GUARDED_BY(mMutex); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 225 | frametimeline::TokenManager* const mTokenManager; |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 226 | |
Ady Abraham | f285161 | 2023-09-25 17:19:00 -0700 | [diff] [blame] | 227 | IEventThreadCallback& mCallback; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 228 | |
Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 229 | std::thread mThread; |
| 230 | mutable std::mutex mMutex; |
| 231 | mutable std::condition_variable mCondition; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 232 | |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 233 | std::vector<wp<EventThreadConnection>> mDisplayEventConnections GUARDED_BY(mMutex); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 234 | std::deque<DisplayEventReceiver::Event> mPendingEvents GUARDED_BY(mMutex); |
Dominik Laskowski | 23b867a | 2019-01-22 12:44:53 -0800 | [diff] [blame] | 235 | |
| 236 | // VSYNC state of connected display. |
| 237 | struct VSyncState { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 238 | explicit VSyncState(PhysicalDisplayId displayId) : displayId(displayId) {} |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 239 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 240 | const PhysicalDisplayId displayId; |
Dominik Laskowski | 23b867a | 2019-01-22 12:44:53 -0800 | [diff] [blame] | 241 | |
| 242 | // Number of VSYNC events since display was connected. |
| 243 | uint32_t count = 0; |
| 244 | |
| 245 | // True if VSYNC should be faked, e.g. when display is off. |
| 246 | bool synthetic = false; |
| 247 | }; |
| 248 | |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 249 | // TODO(b/74619554): Create per-display threads waiting on respective VSYNC signals, |
| 250 | // and support headless mode by injecting a fake display with synthetic VSYNC. |
| 251 | std::optional<VSyncState> mVSyncState GUARDED_BY(mMutex); |
Dominik Laskowski | 23b867a | 2019-01-22 12:44:53 -0800 | [diff] [blame] | 252 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 253 | // State machine for event loop. |
| 254 | enum class State { |
| 255 | Idle, |
| 256 | Quit, |
| 257 | SyntheticVSync, |
| 258 | VSync, |
| 259 | }; |
Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 260 | |
Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 261 | State mState GUARDED_BY(mMutex) = State::Idle; |
| 262 | |
| 263 | static const char* toCString(State); |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | // --------------------------------------------------------------------------- |
| 267 | |
Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 268 | } // namespace impl |
| 269 | } // namespace android |