| 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 |  | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 18 | #pragma clang diagnostic push | 
|  | 19 | #pragma clang diagnostic ignored "-Wconversion" | 
|  | 20 |  | 
| Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 21 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
|  | 22 |  | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 23 | #include <pthread.h> | 
|  | 24 | #include <sched.h> | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 25 | #include <sys/types.h> | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 26 |  | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 27 | #include <chrono> | 
|  | 28 | #include <cstdint> | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 29 | #include <optional> | 
|  | 30 | #include <type_traits> | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 31 |  | 
| Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 32 | #include <android-base/stringprintf.h> | 
|  | 33 |  | 
| Mathias Agopian | a4cb35a | 2012-08-20 20:07:34 -0700 | [diff] [blame] | 34 | #include <cutils/compiler.h> | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 35 | #include <cutils/sched_policy.h> | 
| Mathias Agopian | a4cb35a | 2012-08-20 20:07:34 -0700 | [diff] [blame] | 36 |  | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 37 | #include <gui/DisplayEventReceiver.h> | 
|  | 38 |  | 
|  | 39 | #include <utils/Errors.h> | 
| Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 40 | #include <utils/Trace.h> | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 41 |  | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 42 | #include "EventThread.h" | 
| Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 43 | #include "FrameTimeline.h" | 
| Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 44 | #include "HwcStrongTypes.h" | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 45 |  | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 46 | using namespace std::chrono_literals; | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 47 |  | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 48 | namespace android { | 
|  | 49 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 50 | using base::StringAppendF; | 
|  | 51 | using base::StringPrintf; | 
|  | 52 |  | 
|  | 53 | namespace { | 
|  | 54 |  | 
|  | 55 | auto vsyncPeriod(VSyncRequest request) { | 
|  | 56 | return static_cast<std::underlying_type_t<VSyncRequest>>(request); | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | std::string toString(VSyncRequest request) { | 
|  | 60 | switch (request) { | 
|  | 61 | case VSyncRequest::None: | 
|  | 62 | return "VSyncRequest::None"; | 
|  | 63 | case VSyncRequest::Single: | 
|  | 64 | return "VSyncRequest::Single"; | 
|  | 65 | default: | 
|  | 66 | return StringPrintf("VSyncRequest::Periodic{period=%d}", vsyncPeriod(request)); | 
|  | 67 | } | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | std::string toString(const EventThreadConnection& connection) { | 
|  | 71 | return StringPrintf("Connection{%p, %s}", &connection, | 
|  | 72 | toString(connection.vsyncRequest).c_str()); | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | std::string toString(const DisplayEventReceiver::Event& event) { | 
|  | 76 | switch (event.header.type) { | 
|  | 77 | case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG: | 
| Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 78 | return StringPrintf("Hotplug{displayId=%s, %s}", | 
|  | 79 | to_string(event.header.displayId).c_str(), | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 80 | event.hotplug.connected ? "connected" : "disconnected"); | 
|  | 81 | case DisplayEventReceiver::DISPLAY_EVENT_VSYNC: | 
| Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 82 | return StringPrintf("VSync{displayId=%s, count=%u, expectedVSyncTimestamp=%" PRId64 "}", | 
|  | 83 | to_string(event.header.displayId).c_str(), event.vsync.count, | 
| Ady Abraham | 5facfb1 | 2020-04-22 15:18:31 -0700 | [diff] [blame] | 84 | event.vsync.expectedVSyncTimestamp); | 
| Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 85 | case DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED: | 
| Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 86 | return StringPrintf("ConfigChanged{displayId=%s, configId=%u}", | 
|  | 87 | to_string(event.header.displayId).c_str(), event.config.configId); | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 88 | default: | 
|  | 89 | return "Event{}"; | 
|  | 90 | } | 
|  | 91 | } | 
|  | 92 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 93 | DisplayEventReceiver::Event makeHotplug(PhysicalDisplayId displayId, nsecs_t timestamp, | 
|  | 94 | bool connected) { | 
| Dominik Laskowski | 23b867a | 2019-01-22 12:44:53 -0800 | [diff] [blame] | 95 | DisplayEventReceiver::Event event; | 
|  | 96 | event.header = {DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG, displayId, timestamp}; | 
|  | 97 | event.hotplug.connected = connected; | 
|  | 98 | return event; | 
|  | 99 | } | 
|  | 100 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 101 | DisplayEventReceiver::Event makeVSync(PhysicalDisplayId displayId, nsecs_t timestamp, | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 102 | uint32_t count, nsecs_t expectedVSyncTimestamp, | 
| Ady Abraham | 74e1756 | 2020-08-24 18:18:19 -0700 | [diff] [blame] | 103 | nsecs_t deadlineTimestamp, int64_t vsyncId) { | 
| Dominik Laskowski | 23b867a | 2019-01-22 12:44:53 -0800 | [diff] [blame] | 104 | DisplayEventReceiver::Event event; | 
|  | 105 | event.header = {DisplayEventReceiver::DISPLAY_EVENT_VSYNC, displayId, timestamp}; | 
|  | 106 | event.vsync.count = count; | 
| Ady Abraham | 5facfb1 | 2020-04-22 15:18:31 -0700 | [diff] [blame] | 107 | event.vsync.expectedVSyncTimestamp = expectedVSyncTimestamp; | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 108 | event.vsync.deadlineTimestamp = deadlineTimestamp; | 
| Ady Abraham | 74e1756 | 2020-08-24 18:18:19 -0700 | [diff] [blame] | 109 | event.vsync.vsyncId = vsyncId; | 
| Dominik Laskowski | 23b867a | 2019-01-22 12:44:53 -0800 | [diff] [blame] | 110 | return event; | 
|  | 111 | } | 
|  | 112 |  | 
| Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 113 | DisplayEventReceiver::Event makeConfigChanged(PhysicalDisplayId displayId, | 
| Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 114 | HwcConfigIndexType configId, nsecs_t vsyncPeriod) { | 
| Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 115 | DisplayEventReceiver::Event event; | 
|  | 116 | event.header = {DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED, displayId, systemTime()}; | 
| Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 117 | event.config.configId = configId.value(); | 
| Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 118 | event.config.vsyncPeriod = vsyncPeriod; | 
| Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 119 | return event; | 
|  | 120 | } | 
|  | 121 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 122 | } // namespace | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 123 |  | 
| Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 124 | EventThreadConnection::EventThreadConnection(EventThread* eventThread, | 
| Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 125 | ResyncCallback resyncCallback, | 
|  | 126 | ISurfaceComposer::ConfigChanged configChanged) | 
| Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 127 | : resyncCallback(std::move(resyncCallback)), | 
| Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 128 | mConfigChanged(configChanged), | 
| Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 129 | mEventThread(eventThread), | 
|  | 130 | mChannel(gui::BitTube::DefaultSize) {} | 
| Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 131 |  | 
|  | 132 | EventThreadConnection::~EventThreadConnection() { | 
|  | 133 | // do nothing here -- clean-up will happen automatically | 
|  | 134 | // when the main thread wakes up | 
|  | 135 | } | 
|  | 136 |  | 
|  | 137 | void EventThreadConnection::onFirstRef() { | 
|  | 138 | // NOTE: mEventThread doesn't hold a strong reference on us | 
|  | 139 | mEventThread->registerDisplayEventConnection(this); | 
|  | 140 | } | 
|  | 141 |  | 
|  | 142 | status_t EventThreadConnection::stealReceiveChannel(gui::BitTube* outChannel) { | 
|  | 143 | outChannel->setReceiveFd(mChannel.moveReceiveFd()); | 
| Alec Mouri | 967d5d7 | 2020-08-05 12:50:03 -0700 | [diff] [blame] | 144 | outChannel->setSendFd(base::unique_fd(dup(mChannel.getSendFd()))); | 
| Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 145 | return NO_ERROR; | 
|  | 146 | } | 
|  | 147 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 148 | status_t EventThreadConnection::setVsyncRate(uint32_t rate) { | 
|  | 149 | mEventThread->setVsyncRate(rate, this); | 
| Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 150 | return NO_ERROR; | 
|  | 151 | } | 
|  | 152 |  | 
|  | 153 | void EventThreadConnection::requestNextVsync() { | 
| Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 154 | ATRACE_NAME("requestNextVsync"); | 
| Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 155 | mEventThread->requestNextVsync(this); | 
| Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
|  | 158 | status_t EventThreadConnection::postEvent(const DisplayEventReceiver::Event& event) { | 
|  | 159 | ssize_t size = DisplayEventReceiver::sendEvents(&mChannel, &event, 1); | 
|  | 160 | return size < 0 ? status_t(size) : status_t(NO_ERROR); | 
|  | 161 | } | 
|  | 162 |  | 
|  | 163 | // --------------------------------------------------------------------------- | 
|  | 164 |  | 
| Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 165 | EventThread::~EventThread() = default; | 
|  | 166 |  | 
|  | 167 | namespace impl { | 
|  | 168 |  | 
| Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 169 | EventThread::EventThread(std::unique_ptr<VSyncSource> vsyncSource, | 
| Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 170 | android::frametimeline::TokenManager* tokenManager, | 
| Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 171 | InterceptVSyncsCallback interceptVSyncsCallback) | 
|  | 172 | : mVSyncSource(std::move(vsyncSource)), | 
| Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 173 | mTokenManager(tokenManager), | 
| Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 174 | mInterceptVSyncsCallback(std::move(interceptVSyncsCallback)), | 
| Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 175 | mThreadName(mVSyncSource->getName()) { | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 176 | mVSyncSource->setCallback(this); | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 177 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 178 | mThread = std::thread([this]() NO_THREAD_SAFETY_ANALYSIS { | 
|  | 179 | std::unique_lock<std::mutex> lock(mMutex); | 
|  | 180 | threadMain(lock); | 
|  | 181 | }); | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 182 |  | 
| Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 183 | pthread_setname_np(mThread.native_handle(), mThreadName); | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 184 |  | 
|  | 185 | pid_t tid = pthread_gettid_np(mThread.native_handle()); | 
|  | 186 |  | 
|  | 187 | // Use SCHED_FIFO to minimize jitter | 
|  | 188 | constexpr int EVENT_THREAD_PRIORITY = 2; | 
|  | 189 | struct sched_param param = {0}; | 
|  | 190 | param.sched_priority = EVENT_THREAD_PRIORITY; | 
|  | 191 | if (pthread_setschedparam(mThread.native_handle(), SCHED_FIFO, ¶m) != 0) { | 
|  | 192 | ALOGE("Couldn't set SCHED_FIFO for EventThread"); | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | set_sched_policy(tid, SP_FOREGROUND); | 
|  | 196 | } | 
|  | 197 |  | 
|  | 198 | EventThread::~EventThread() { | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 199 | mVSyncSource->setCallback(nullptr); | 
|  | 200 |  | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 201 | { | 
|  | 202 | std::lock_guard<std::mutex> lock(mMutex); | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 203 | mState = State::Quit; | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 204 | mCondition.notify_all(); | 
|  | 205 | } | 
|  | 206 | mThread.join(); | 
| Ruchi Kandoi | ef472ec | 2014-04-02 12:50:06 -0700 | [diff] [blame] | 207 | } | 
|  | 208 |  | 
| Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 209 | void EventThread::setDuration(std::chrono::nanoseconds workDuration, | 
|  | 210 | std::chrono::nanoseconds readyDuration) { | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 211 | std::lock_guard<std::mutex> lock(mMutex); | 
| Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 212 | mVSyncSource->setDuration(workDuration, readyDuration); | 
| Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 213 | } | 
|  | 214 |  | 
| Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 215 | sp<EventThreadConnection> EventThread::createEventConnection( | 
|  | 216 | ResyncCallback resyncCallback, ISurfaceComposer::ConfigChanged configChanged) const { | 
|  | 217 | return new EventThreadConnection(const_cast<EventThread*>(this), std::move(resyncCallback), | 
|  | 218 | configChanged); | 
| Mathias Agopian | 8aedd47 | 2012-01-24 16:39:14 -0800 | [diff] [blame] | 219 | } | 
|  | 220 |  | 
| Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 221 | status_t EventThread::registerDisplayEventConnection(const sp<EventThreadConnection>& connection) { | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 222 | std::lock_guard<std::mutex> lock(mMutex); | 
| Chia-I Wu | 98cd38f | 2018-09-14 11:53:25 -0700 | [diff] [blame] | 223 |  | 
|  | 224 | // this should never happen | 
|  | 225 | auto it = std::find(mDisplayEventConnections.cbegin(), | 
|  | 226 | mDisplayEventConnections.cend(), connection); | 
|  | 227 | if (it != mDisplayEventConnections.cend()) { | 
|  | 228 | ALOGW("DisplayEventConnection %p already exists", connection.get()); | 
|  | 229 | mCondition.notify_all(); | 
|  | 230 | return ALREADY_EXISTS; | 
|  | 231 | } | 
|  | 232 |  | 
|  | 233 | mDisplayEventConnections.push_back(connection); | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 234 | mCondition.notify_all(); | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 235 | return NO_ERROR; | 
|  | 236 | } | 
|  | 237 |  | 
| Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 238 | void EventThread::removeDisplayEventConnectionLocked(const wp<EventThreadConnection>& connection) { | 
| Chia-I Wu | 98cd38f | 2018-09-14 11:53:25 -0700 | [diff] [blame] | 239 | auto it = std::find(mDisplayEventConnections.cbegin(), | 
|  | 240 | mDisplayEventConnections.cend(), connection); | 
|  | 241 | if (it != mDisplayEventConnections.cend()) { | 
|  | 242 | mDisplayEventConnections.erase(it); | 
|  | 243 | } | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 244 | } | 
|  | 245 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 246 | void EventThread::setVsyncRate(uint32_t rate, const sp<EventThreadConnection>& connection) { | 
|  | 247 | if (static_cast<std::underlying_type_t<VSyncRequest>>(rate) < 0) { | 
|  | 248 | return; | 
|  | 249 | } | 
|  | 250 |  | 
|  | 251 | std::lock_guard<std::mutex> lock(mMutex); | 
|  | 252 |  | 
|  | 253 | const auto request = rate == 0 ? VSyncRequest::None : static_cast<VSyncRequest>(rate); | 
|  | 254 | if (connection->vsyncRequest != request) { | 
|  | 255 | connection->vsyncRequest = request; | 
|  | 256 | mCondition.notify_all(); | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 257 | } | 
|  | 258 | } | 
|  | 259 |  | 
| Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 260 | void EventThread::requestNextVsync(const sp<EventThreadConnection>& connection) { | 
| Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 261 | if (connection->resyncCallback) { | 
|  | 262 | connection->resyncCallback(); | 
| Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 263 | } | 
| Tim Murray | 4a4e4a2 | 2016-04-19 16:29:23 +0000 | [diff] [blame] | 264 |  | 
| Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 265 | std::lock_guard<std::mutex> lock(mMutex); | 
|  | 266 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 267 | if (connection->vsyncRequest == VSyncRequest::None) { | 
|  | 268 | connection->vsyncRequest = VSyncRequest::Single; | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 269 | mCondition.notify_all(); | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 270 | } | 
| Mathias Agopian | 2374866 | 2011-12-05 14:33:34 -0800 | [diff] [blame] | 271 | } | 
|  | 272 |  | 
| Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 273 | void EventThread::onScreenReleased() { | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 274 | std::lock_guard<std::mutex> lock(mMutex); | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 275 | if (!mVSyncState || mVSyncState->synthetic) { | 
|  | 276 | return; | 
| Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 277 | } | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 278 |  | 
|  | 279 | mVSyncState->synthetic = true; | 
|  | 280 | mCondition.notify_all(); | 
| Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 281 | } | 
|  | 282 |  | 
|  | 283 | void EventThread::onScreenAcquired() { | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 284 | std::lock_guard<std::mutex> lock(mMutex); | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 285 | if (!mVSyncState || !mVSyncState->synthetic) { | 
|  | 286 | return; | 
| Mathias Agopian | 7d88647 | 2012-06-14 23:39:35 -0700 | [diff] [blame] | 287 | } | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 288 |  | 
|  | 289 | mVSyncState->synthetic = false; | 
|  | 290 | mCondition.notify_all(); | 
| Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 291 | } | 
|  | 292 |  | 
| Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 293 | void EventThread::onVSyncEvent(nsecs_t timestamp, nsecs_t expectedVSyncTimestamp, | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 294 | nsecs_t deadlineTimestamp) { | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 295 | std::lock_guard<std::mutex> lock(mMutex); | 
| Dominik Laskowski | 23b867a | 2019-01-22 12:44:53 -0800 | [diff] [blame] | 296 |  | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 297 | LOG_FATAL_IF(!mVSyncState); | 
| Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 298 | const int64_t vsyncId = [&] { | 
|  | 299 | if (mTokenManager != nullptr) { | 
|  | 300 | return mTokenManager->generateTokenForPredictions( | 
|  | 301 | {timestamp, deadlineTimestamp, expectedVSyncTimestamp}); | 
|  | 302 | } | 
|  | 303 | return static_cast<int64_t>(0); | 
|  | 304 | }(); | 
|  | 305 |  | 
| Ady Abraham | 5facfb1 | 2020-04-22 15:18:31 -0700 | [diff] [blame] | 306 | mPendingEvents.push_back(makeVSync(mVSyncState->displayId, timestamp, ++mVSyncState->count, | 
| Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 307 | expectedVSyncTimestamp, deadlineTimestamp, vsyncId)); | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 308 | mCondition.notify_all(); | 
| Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 309 | } | 
|  | 310 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 311 | void EventThread::onHotplugReceived(PhysicalDisplayId displayId, bool connected) { | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 312 | std::lock_guard<std::mutex> lock(mMutex); | 
| Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 313 |  | 
| Dominik Laskowski | 23b867a | 2019-01-22 12:44:53 -0800 | [diff] [blame] | 314 | mPendingEvents.push_back(makeHotplug(displayId, systemTime(), connected)); | 
| Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 315 | mCondition.notify_all(); | 
| Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 316 | } | 
|  | 317 |  | 
| Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 318 | void EventThread::onConfigChanged(PhysicalDisplayId displayId, HwcConfigIndexType configId, | 
|  | 319 | nsecs_t vsyncPeriod) { | 
| Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 320 | std::lock_guard<std::mutex> lock(mMutex); | 
|  | 321 |  | 
| Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 322 | mPendingEvents.push_back(makeConfigChanged(displayId, configId, vsyncPeriod)); | 
| Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 323 | mCondition.notify_all(); | 
|  | 324 | } | 
|  | 325 |  | 
| Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 326 | size_t EventThread::getEventThreadConnectionCount() { | 
|  | 327 | std::lock_guard<std::mutex> lock(mMutex); | 
|  | 328 | return mDisplayEventConnections.size(); | 
|  | 329 | } | 
|  | 330 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 331 | void EventThread::threadMain(std::unique_lock<std::mutex>& lock) { | 
|  | 332 | DisplayEventConsumers consumers; | 
|  | 333 |  | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 334 | while (mState != State::Quit) { | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 335 | std::optional<DisplayEventReceiver::Event> event; | 
| Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 336 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 337 | // Determine next event to dispatch. | 
|  | 338 | if (!mPendingEvents.empty()) { | 
|  | 339 | event = mPendingEvents.front(); | 
|  | 340 | mPendingEvents.pop_front(); | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 341 |  | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 342 | switch (event->header.type) { | 
|  | 343 | case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG: | 
|  | 344 | if (event->hotplug.connected && !mVSyncState) { | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 345 | mVSyncState.emplace(event->header.displayId); | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 346 | } else if (!event->hotplug.connected && mVSyncState && | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 347 | mVSyncState->displayId == event->header.displayId) { | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 348 | mVSyncState.reset(); | 
|  | 349 | } | 
|  | 350 | break; | 
|  | 351 |  | 
|  | 352 | case DisplayEventReceiver::DISPLAY_EVENT_VSYNC: | 
|  | 353 | if (mInterceptVSyncsCallback) { | 
|  | 354 | mInterceptVSyncsCallback(event->header.timestamp); | 
|  | 355 | } | 
|  | 356 | break; | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 357 | } | 
| Mathias Agopian | ff28e20 | 2012-09-20 23:24:19 -0700 | [diff] [blame] | 358 | } | 
|  | 359 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 360 | bool vsyncRequested = false; | 
| Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 361 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 362 | // Find connections that should consume this event. | 
| Chia-I Wu | 98cd38f | 2018-09-14 11:53:25 -0700 | [diff] [blame] | 363 | auto it = mDisplayEventConnections.begin(); | 
|  | 364 | while (it != mDisplayEventConnections.end()) { | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 365 | if (const auto connection = it->promote()) { | 
|  | 366 | vsyncRequested |= connection->vsyncRequest != VSyncRequest::None; | 
|  | 367 |  | 
|  | 368 | if (event && shouldConsumeEvent(*event, connection)) { | 
|  | 369 | consumers.push_back(connection); | 
| Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 370 | } | 
| Mathias Agopian | b4d18ed | 2012-09-20 23:14:05 -0700 | [diff] [blame] | 371 |  | 
| Chia-I Wu | 98cd38f | 2018-09-14 11:53:25 -0700 | [diff] [blame] | 372 | ++it; | 
| Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 373 | } else { | 
| Chia-I Wu | 98cd38f | 2018-09-14 11:53:25 -0700 | [diff] [blame] | 374 | it = mDisplayEventConnections.erase(it); | 
| Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 375 | } | 
|  | 376 | } | 
|  | 377 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 378 | if (!consumers.empty()) { | 
|  | 379 | dispatchEvent(*event, consumers); | 
|  | 380 | consumers.clear(); | 
|  | 381 | } | 
|  | 382 |  | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 383 | State nextState; | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 384 | if (mVSyncState && vsyncRequested) { | 
|  | 385 | nextState = mVSyncState->synthetic ? State::SyntheticVSync : State::VSync; | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 386 | } else { | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 387 | ALOGW_IF(!mVSyncState, "Ignoring VSYNC request while display is disconnected"); | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 388 | nextState = State::Idle; | 
|  | 389 | } | 
|  | 390 |  | 
|  | 391 | if (mState != nextState) { | 
|  | 392 | if (mState == State::VSync) { | 
|  | 393 | mVSyncSource->setVSyncEnabled(false); | 
|  | 394 | } else if (nextState == State::VSync) { | 
|  | 395 | mVSyncSource->setVSyncEnabled(true); | 
|  | 396 | } | 
|  | 397 |  | 
|  | 398 | mState = nextState; | 
| Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 399 | } | 
|  | 400 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 401 | if (event) { | 
|  | 402 | continue; | 
|  | 403 | } | 
|  | 404 |  | 
|  | 405 | // Wait for event or client registration/request. | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 406 | if (mState == State::Idle) { | 
|  | 407 | mCondition.wait(lock); | 
|  | 408 | } else { | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 409 | // Generate a fake VSYNC after a long timeout in case the driver stalls. When the | 
|  | 410 | // display is off, keep feeding clients at 60 Hz. | 
| Ady Abraham | 5facfb1 | 2020-04-22 15:18:31 -0700 | [diff] [blame] | 411 | const std::chrono::nanoseconds timeout = | 
|  | 412 | mState == State::SyntheticVSync ? 16ms : 1000ms; | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 413 | if (mCondition.wait_for(lock, timeout) == std::cv_status::timeout) { | 
| Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 414 | if (mState == State::VSync) { | 
|  | 415 | ALOGW("Faking VSYNC due to driver stall for thread %s", mThreadName); | 
|  | 416 | std::string debugInfo = "VsyncSource debug info:\n"; | 
|  | 417 | mVSyncSource->dump(debugInfo); | 
| Ady Abraham | 7539872 | 2020-04-07 14:08:45 -0700 | [diff] [blame] | 418 | // Log the debug info line-by-line to avoid logcat overflow | 
|  | 419 | auto pos = debugInfo.find('\n'); | 
|  | 420 | while (pos != std::string::npos) { | 
|  | 421 | ALOGW("%s", debugInfo.substr(0, pos).c_str()); | 
|  | 422 | debugInfo = debugInfo.substr(pos + 1); | 
|  | 423 | pos = debugInfo.find('\n'); | 
|  | 424 | } | 
| Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 425 | } | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 426 |  | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 427 | LOG_FATAL_IF(!mVSyncState); | 
| Ady Abraham | 5facfb1 | 2020-04-22 15:18:31 -0700 | [diff] [blame] | 428 | const auto now = systemTime(SYSTEM_TIME_MONOTONIC); | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 429 | const auto deadlineTimestamp = now + timeout.count(); | 
|  | 430 | const auto expectedVSyncTime = deadlineTimestamp + timeout.count(); | 
| Ady Abraham | 74e1756 | 2020-08-24 18:18:19 -0700 | [diff] [blame] | 431 | // TODO(b/162890590): use TokenManager to populate vsyncId | 
| Ady Abraham | 5facfb1 | 2020-04-22 15:18:31 -0700 | [diff] [blame] | 432 | mPendingEvents.push_back(makeVSync(mVSyncState->displayId, now, | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 433 | ++mVSyncState->count, expectedVSyncTime, | 
| Ady Abraham | 74e1756 | 2020-08-24 18:18:19 -0700 | [diff] [blame] | 434 | deadlineTimestamp, /*vsyncId=*/0)); | 
| Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 435 | } | 
|  | 436 | } | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 437 | } | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 438 | } | 
| Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 439 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 440 | bool EventThread::shouldConsumeEvent(const DisplayEventReceiver::Event& event, | 
|  | 441 | const sp<EventThreadConnection>& connection) const { | 
|  | 442 | switch (event.header.type) { | 
|  | 443 | case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG: | 
|  | 444 | return true; | 
|  | 445 |  | 
| Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 446 | case DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED: { | 
| Alec Mouri | 967d5d7 | 2020-08-05 12:50:03 -0700 | [diff] [blame] | 447 | return connection->mConfigChanged == ISurfaceComposer::eConfigChangedDispatch; | 
| Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 448 | } | 
| Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 449 |  | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 450 | case DisplayEventReceiver::DISPLAY_EVENT_VSYNC: | 
|  | 451 | switch (connection->vsyncRequest) { | 
|  | 452 | case VSyncRequest::None: | 
|  | 453 | return false; | 
|  | 454 | case VSyncRequest::Single: | 
|  | 455 | connection->vsyncRequest = VSyncRequest::None; | 
|  | 456 | return true; | 
|  | 457 | case VSyncRequest::Periodic: | 
|  | 458 | return true; | 
|  | 459 | default: | 
|  | 460 | return event.vsync.count % vsyncPeriod(connection->vsyncRequest) == 0; | 
|  | 461 | } | 
|  | 462 |  | 
|  | 463 | default: | 
|  | 464 | return false; | 
|  | 465 | } | 
|  | 466 | } | 
|  | 467 |  | 
|  | 468 | void EventThread::dispatchEvent(const DisplayEventReceiver::Event& event, | 
|  | 469 | const DisplayEventConsumers& consumers) { | 
|  | 470 | for (const auto& consumer : consumers) { | 
|  | 471 | switch (consumer->postEvent(event)) { | 
|  | 472 | case NO_ERROR: | 
|  | 473 | break; | 
|  | 474 |  | 
|  | 475 | case -EAGAIN: | 
|  | 476 | // TODO: Try again if pipe is full. | 
|  | 477 | ALOGW("Failed dispatching %s for %s", toString(event).c_str(), | 
|  | 478 | toString(*consumer).c_str()); | 
|  | 479 | break; | 
|  | 480 |  | 
|  | 481 | default: | 
|  | 482 | // Treat EPIPE and other errors as fatal. | 
|  | 483 | removeDisplayEventConnectionLocked(consumer); | 
|  | 484 | } | 
|  | 485 | } | 
| Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 486 | } | 
|  | 487 |  | 
| Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 488 | void EventThread::dump(std::string& result) const { | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 489 | std::lock_guard<std::mutex> lock(mMutex); | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 490 |  | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 491 | StringAppendF(&result, "%s: state=%s VSyncState=", mThreadName, toCString(mState)); | 
|  | 492 | if (mVSyncState) { | 
| Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 493 | StringAppendF(&result, "{displayId=%s, count=%u%s}\n", | 
|  | 494 | to_string(mVSyncState->displayId).c_str(), mVSyncState->count, | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 495 | mVSyncState->synthetic ? ", synthetic" : ""); | 
| Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 496 | } else { | 
|  | 497 | StringAppendF(&result, "none\n"); | 
|  | 498 | } | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 499 |  | 
|  | 500 | StringAppendF(&result, "  pending events (count=%zu):\n", mPendingEvents.size()); | 
|  | 501 | for (const auto& event : mPendingEvents) { | 
|  | 502 | StringAppendF(&result, "    %s\n", toString(event).c_str()); | 
| Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 503 | } | 
| Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 504 |  | 
|  | 505 | StringAppendF(&result, "  connections (count=%zu):\n", mDisplayEventConnections.size()); | 
|  | 506 | for (const auto& ptr : mDisplayEventConnections) { | 
|  | 507 | if (const auto connection = ptr.promote()) { | 
|  | 508 | StringAppendF(&result, "    %s\n", toString(*connection).c_str()); | 
|  | 509 | } | 
|  | 510 | } | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 511 | } | 
|  | 512 |  | 
| Dominik Laskowski | 029cc12 | 2019-01-23 19:52:06 -0800 | [diff] [blame] | 513 | const char* EventThread::toCString(State state) { | 
|  | 514 | switch (state) { | 
|  | 515 | case State::Idle: | 
|  | 516 | return "Idle"; | 
|  | 517 | case State::Quit: | 
|  | 518 | return "Quit"; | 
|  | 519 | case State::SyntheticVSync: | 
|  | 520 | return "SyntheticVSync"; | 
|  | 521 | case State::VSync: | 
|  | 522 | return "VSync"; | 
|  | 523 | } | 
|  | 524 | } | 
|  | 525 |  | 
| Lloyd Pique | 0fcde1b | 2017-12-20 16:50:21 -0800 | [diff] [blame] | 526 | } // namespace impl | 
| Lloyd Pique | 46a46b3 | 2018-01-31 19:01:18 -0800 | [diff] [blame] | 527 | } // namespace android | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 528 |  | 
|  | 529 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 530 | #pragma clang diagnostic pop // ignored "-Wconversion" |