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