| 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 |  | 
| 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( | 
| Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 104 |             ResyncCallback, EventRegistrationFlags eventRegistration = {}) const = 0; | 
| Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 105 |  | 
 | 106 |     // called before the screen is turned off from main thread | 
 | 107 |     virtual void onScreenReleased() = 0; | 
 | 108 |  | 
 | 109 |     // called after the screen is turned on from main thread | 
 | 110 |     virtual void onScreenAcquired() = 0; | 
 | 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; | 
| Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 136 | }; | 
 | 137 |  | 
 | 138 | namespace impl { | 
 | 139 |  | 
| Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 140 | class EventThread : public android::EventThread { | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 141 | public: | 
| Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 142 |     using ThrottleVsyncCallback = std::function<bool(nsecs_t, uid_t)>; | 
| Jorim Jaggi | c0086af | 2021-02-12 18:18:11 +0100 | [diff] [blame] | 143 |     using GetVsyncPeriodFunction = std::function<nsecs_t(uid_t)>; | 
| Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 144 |  | 
| Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 145 |     EventThread(const char* name, scheduler::VsyncSchedule&, frametimeline::TokenManager*, | 
 | 146 |                 ThrottleVsyncCallback, GetVsyncPeriodFunction, | 
 | 147 |                 std::chrono::nanoseconds workDuration, std::chrono::nanoseconds readyDuration); | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 148 |     ~EventThread(); | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 149 |  | 
| Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 150 |     sp<EventThreadConnection> createEventConnection( | 
| Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 151 |             ResyncCallback, EventRegistrationFlags eventRegistration = {}) const override; | 
| Mathias Agopian | 8aedd47 | 2012-01-24 16:39:14 -0800 | [diff] [blame] | 152 |  | 
| Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 153 |     status_t registerDisplayEventConnection(const sp<EventThreadConnection>& connection) override; | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 154 |     void setVsyncRate(uint32_t rate, const sp<EventThreadConnection>& connection) override; | 
| Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 155 |     void requestNextVsync(const sp<EventThreadConnection>& connection) override; | 
| Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame] | 156 |     VsyncEventData getLatestVsyncEventData( | 
 | 157 |             const sp<EventThreadConnection>& connection) const override; | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 158 |  | 
| Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 159 |     // called before the screen is turned off from main thread | 
| Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 160 |     void onScreenReleased() override; | 
| Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 161 |  | 
 | 162 |     // called after the screen is turned on from main thread | 
| Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 163 |     void onScreenAcquired() override; | 
| Mathias Agopian | 8aedd47 | 2012-01-24 16:39:14 -0800 | [diff] [blame] | 164 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 165 |     void onHotplugReceived(PhysicalDisplayId displayId, bool connected) override; | 
| Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 166 |  | 
| Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 167 |     void onModeChanged(const scheduler::FrameRateMode&) override; | 
| Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 168 |  | 
| Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 169 |     void onFrameRateOverridesChanged(PhysicalDisplayId displayId, | 
 | 170 |                                      std::vector<FrameRateOverride> overrides) override; | 
 | 171 |  | 
| Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 172 |     void dump(std::string& result) const override; | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 173 |  | 
| Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 174 |     void setDuration(std::chrono::nanoseconds workDuration, | 
 | 175 |                      std::chrono::nanoseconds readyDuration) override; | 
| Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 176 |  | 
| Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 177 |     size_t getEventThreadConnectionCount() 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 |  | 
| Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 202 |     const char* const mThreadName; | 
 | 203 |     TracedOrdinal<int> mVsyncTracer; | 
 | 204 |     TracedOrdinal<std::chrono::nanoseconds> mWorkDuration GUARDED_BY(mMutex); | 
 | 205 |     std::chrono::nanoseconds mReadyDuration GUARDED_BY(mMutex); | 
 | 206 |     scheduler::VsyncSchedule& mVsyncSchedule; | 
 | 207 |     TimePoint mLastVsyncCallbackTime GUARDED_BY(mMutex) = TimePoint::now(); | 
 | 208 |     scheduler::VSyncCallbackRegistration mVsyncRegistration GUARDED_BY(mMutex); | 
| Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 209 |     frametimeline::TokenManager* const mTokenManager; | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 210 |  | 
| Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 211 |     const ThrottleVsyncCallback mThrottleVsyncCallback; | 
| Jorim Jaggi | c0086af | 2021-02-12 18:18:11 +0100 | [diff] [blame] | 212 |     const GetVsyncPeriodFunction mGetVsyncPeriodFunction; | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 213 |  | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 214 |     std::thread mThread; | 
 | 215 |     mutable std::mutex mMutex; | 
 | 216 |     mutable std::condition_variable mCondition; | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 217 |  | 
| Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 218 |     std::vector<wp<EventThreadConnection>> mDisplayEventConnections GUARDED_BY(mMutex); | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 219 |     std::deque<DisplayEventReceiver::Event> mPendingEvents GUARDED_BY(mMutex); | 
| Dominik Laskowski | 23b867a | 2019-01-22 12:44:53 -0800 | [diff] [blame] | 220 |  | 
 | 221 |     // VSYNC state of connected display. | 
 | 222 |     struct VSyncState { | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 223 |         explicit VSyncState(PhysicalDisplayId displayId) : displayId(displayId) {} | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 224 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 225 |         const PhysicalDisplayId displayId; | 
| Dominik Laskowski | 23b867a | 2019-01-22 12:44:53 -0800 | [diff] [blame] | 226 |  | 
 | 227 |         // Number of VSYNC events since display was connected. | 
 | 228 |         uint32_t count = 0; | 
 | 229 |  | 
 | 230 |         // True if VSYNC should be faked, e.g. when display is off. | 
 | 231 |         bool synthetic = false; | 
 | 232 |     }; | 
 | 233 |  | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 234 |     // TODO(b/74619554): Create per-display threads waiting on respective VSYNC signals, | 
 | 235 |     // and support headless mode by injecting a fake display with synthetic VSYNC. | 
 | 236 |     std::optional<VSyncState> mVSyncState GUARDED_BY(mMutex); | 
| Dominik Laskowski | 23b867a | 2019-01-22 12:44:53 -0800 | [diff] [blame] | 237 |  | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 238 |     // State machine for event loop. | 
 | 239 |     enum class State { | 
 | 240 |         Idle, | 
 | 241 |         Quit, | 
 | 242 |         SyntheticVSync, | 
 | 243 |         VSync, | 
 | 244 |     }; | 
| Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 245 |  | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 246 |     State mState GUARDED_BY(mMutex) = State::Idle; | 
 | 247 |  | 
 | 248 |     static const char* toCString(State); | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 249 | }; | 
 | 250 |  | 
 | 251 | // --------------------------------------------------------------------------- | 
 | 252 |  | 
| Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 253 | } // namespace impl | 
 | 254 | } // namespace android |