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 | |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | #include <sys/types.h> |
| 21 | |
Mathias Agopian | a4cb35a | 2012-08-20 20:07:34 -0700 | [diff] [blame] | 22 | #include <cutils/compiler.h> |
| 23 | |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 24 | #include <gui/BitTube.h> |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 25 | #include <gui/IDisplayEventConnection.h> |
| 26 | #include <gui/DisplayEventReceiver.h> |
| 27 | |
| 28 | #include <utils/Errors.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 29 | #include <utils/String8.h> |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 30 | #include <utils/Trace.h> |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 31 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 32 | #include "EventThread.h" |
| 33 | #include "SurfaceFlinger.h" |
| 34 | |
| 35 | // --------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 36 | namespace android { |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 37 | // --------------------------------------------------------------------------- |
| 38 | |
| 39 | EventThread::EventThread(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 40 | : mFlinger(flinger), |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 41 | mVSyncTimestamp(0), |
Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 42 | mUseSoftwareVSync(false), |
Mathias Agopian | 10125f0 | 2012-08-17 15:06:02 -0700 | [diff] [blame] | 43 | mVSyncCount(0), |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 44 | mDebugVsyncEnabled(false) { |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void EventThread::onFirstRef() { |
| 48 | run("EventThread", PRIORITY_URGENT_DISPLAY + PRIORITY_MORE_FAVORABLE); |
| 49 | } |
| 50 | |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 51 | sp<EventThread::Connection> EventThread::createEventConnection() const { |
| 52 | return new Connection(const_cast<EventThread*>(this)); |
Mathias Agopian | 8aedd47 | 2012-01-24 16:39:14 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 55 | status_t EventThread::registerDisplayEventConnection( |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 56 | const sp<EventThread::Connection>& connection) { |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 57 | Mutex::Autolock _l(mLock); |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 58 | mDisplayEventConnections.add(connection); |
Mathias Agopian | 7d88647 | 2012-06-14 23:39:35 -0700 | [diff] [blame] | 59 | mCondition.broadcast(); |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 60 | return NO_ERROR; |
| 61 | } |
| 62 | |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 63 | void EventThread::removeDisplayEventConnection( |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 64 | const wp<EventThread::Connection>& connection) { |
Mathias Agopian | 2374866 | 2011-12-05 14:33:34 -0800 | [diff] [blame] | 65 | Mutex::Autolock _l(mLock); |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 66 | mDisplayEventConnections.remove(connection); |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void EventThread::setVsyncRate(uint32_t count, |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 70 | const sp<EventThread::Connection>& connection) { |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 71 | if (int32_t(count) >= 0) { // server must protect against bad params |
| 72 | Mutex::Autolock _l(mLock); |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 73 | const int32_t new_count = (count == 0) ? -1 : count; |
| 74 | if (connection->count != new_count) { |
| 75 | connection->count = new_count; |
Mathias Agopian | 7d88647 | 2012-06-14 23:39:35 -0700 | [diff] [blame] | 76 | mCondition.broadcast(); |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | void EventThread::requestNextVsync( |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 82 | const sp<EventThread::Connection>& connection) { |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 83 | Mutex::Autolock _l(mLock); |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 84 | if (connection->count < 0) { |
| 85 | connection->count = 0; |
Mathias Agopian | 7d88647 | 2012-06-14 23:39:35 -0700 | [diff] [blame] | 86 | mCondition.broadcast(); |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 87 | } |
Mathias Agopian | 2374866 | 2011-12-05 14:33:34 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 90 | void EventThread::onScreenReleased() { |
| 91 | Mutex::Autolock _l(mLock); |
Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 92 | if (!mUseSoftwareVSync) { |
Mathias Agopian | 7d88647 | 2012-06-14 23:39:35 -0700 | [diff] [blame] | 93 | // disable reliance on h/w vsync |
| 94 | mUseSoftwareVSync = true; |
| 95 | mCondition.broadcast(); |
Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 96 | } |
Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | void EventThread::onScreenAcquired() { |
| 100 | Mutex::Autolock _l(mLock); |
Mathias Agopian | 7d88647 | 2012-06-14 23:39:35 -0700 | [diff] [blame] | 101 | if (mUseSoftwareVSync) { |
| 102 | // resume use of h/w vsync |
| 103 | mUseSoftwareVSync = false; |
| 104 | mCondition.broadcast(); |
| 105 | } |
Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame^] | 109 | void EventThread::onVSyncReceived(int type, nsecs_t timestamp) { |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 110 | Mutex::Autolock _l(mLock); |
| 111 | mVSyncTimestamp = timestamp; |
Mathias Agopian | 10125f0 | 2012-08-17 15:06:02 -0700 | [diff] [blame] | 112 | mVSyncCount++; |
Mathias Agopian | 7d88647 | 2012-06-14 23:39:35 -0700 | [diff] [blame] | 113 | mCondition.broadcast(); |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame^] | 116 | void EventThread::onHotplugReceived(int type, bool connected) { |
| 117 | Mutex::Autolock _l(mLock); |
| 118 | DisplayEventReceiver::Event event; |
| 119 | event.header.type = DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG; |
| 120 | event.header.timestamp = systemTime(); |
| 121 | event.hotplug.id = type; |
| 122 | event.hotplug.connected = connected; |
| 123 | mPendingEvents.add(event); |
| 124 | mCondition.broadcast(); |
| 125 | } |
| 126 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 127 | bool EventThread::threadLoop() { |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 128 | DisplayEventReceiver::Event vsync; |
Mathias Agopian | a4cb35a | 2012-08-20 20:07:34 -0700 | [diff] [blame] | 129 | Vector< sp<EventThread::Connection> > signalConnections; |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 130 | signalConnections = waitForEvent(&vsync); |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 131 | |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame^] | 132 | // dispatch events to listeners... |
Mathias Agopian | a4cb35a | 2012-08-20 20:07:34 -0700 | [diff] [blame] | 133 | const size_t count = signalConnections.size(); |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 134 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | a4cb35a | 2012-08-20 20:07:34 -0700 | [diff] [blame] | 135 | const sp<Connection>& conn(signalConnections[i]); |
Mathias Agopian | 10125f0 | 2012-08-17 15:06:02 -0700 | [diff] [blame] | 136 | // now see if we still need to report this VSYNC event |
Mathias Agopian | a4cb35a | 2012-08-20 20:07:34 -0700 | [diff] [blame] | 137 | status_t err = conn->postEvent(vsync); |
| 138 | if (err == -EAGAIN || err == -EWOULDBLOCK) { |
| 139 | // The destination doesn't accept events anymore, it's probably |
| 140 | // full. For now, we just drop the events on the floor. |
| 141 | // Note that some events cannot be dropped and would have to be |
| 142 | // re-sent later. Right-now we don't have the ability to do |
| 143 | // this, but it doesn't matter for VSYNC. |
| 144 | } else if (err < 0) { |
| 145 | // handle any other error on the pipe as fatal. the only |
| 146 | // reasonable thing to do is to clean-up this connection. |
| 147 | // The most common error we'll get here is -EPIPE. |
| 148 | removeDisplayEventConnection(signalConnections[i]); |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 149 | } |
| 150 | } |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 151 | return true; |
| 152 | } |
| 153 | |
Andy McFadden | 6bf552e | 2012-08-30 16:34:41 -0700 | [diff] [blame] | 154 | // This will return when (1) a vsync event has been received, and (2) there was |
| 155 | // at least one connection interested in receiving it when we started waiting. |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 156 | Vector< sp<EventThread::Connection> > EventThread::waitForEvent( |
| 157 | DisplayEventReceiver::Event* event) |
| 158 | { |
| 159 | Mutex::Autolock _l(mLock); |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 160 | Vector< sp<EventThread::Connection> > signalConnections; |
| 161 | |
| 162 | do { |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame^] | 163 | bool eventPending = false; |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 164 | bool waitForVSync = false; |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame^] | 165 | size_t vsyncCount = mVSyncCount; |
| 166 | nsecs_t timestamp = mVSyncTimestamp; |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 167 | mVSyncTimestamp = 0; |
| 168 | |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame^] | 169 | if (timestamp) { |
| 170 | // we have a vsync event to dispatch |
| 171 | event->header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC; |
| 172 | event->header.timestamp = timestamp; |
| 173 | event->vsync.count = vsyncCount; |
| 174 | } else { |
| 175 | eventPending = !mPendingEvents.isEmpty(); |
| 176 | if (eventPending) { |
| 177 | // we have some other event to dispatch |
| 178 | *event = mPendingEvents[0]; |
| 179 | mPendingEvents.removeAt(0); |
| 180 | } |
| 181 | } |
| 182 | |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 183 | // find out connections waiting for events |
| 184 | size_t count = mDisplayEventConnections.size(); |
| 185 | for (size_t i=0 ; i<count ; i++) { |
| 186 | sp<Connection> connection(mDisplayEventConnections[i].promote()); |
| 187 | if (connection != NULL) { |
| 188 | if (connection->count >= 0) { |
| 189 | // we need vsync events because at least |
| 190 | // one connection is waiting for it |
| 191 | waitForVSync = true; |
| 192 | if (timestamp) { |
| 193 | // we consume the event only if it's time |
| 194 | // (ie: we received a vsync event) |
| 195 | if (connection->count == 0) { |
| 196 | // fired this time around |
| 197 | connection->count = -1; |
| 198 | signalConnections.add(connection); |
| 199 | } else if (connection->count == 1 || |
| 200 | (vsyncCount % connection->count) == 0) { |
| 201 | // continuous event, and time to report it |
| 202 | signalConnections.add(connection); |
| 203 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame^] | 204 | } else if (eventPending) { |
| 205 | // we don't have a vsync event to process |
| 206 | // (timestamp==0), but we have some pending |
| 207 | // messages. |
| 208 | signalConnections.add(connection); |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | } else { |
| 212 | // we couldn't promote this reference, the connection has |
| 213 | // died, so clean-up! |
| 214 | mDisplayEventConnections.removeAt(i); |
| 215 | --i; --count; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // Here we figure out if we need to enable or disable vsyncs |
| 220 | if (timestamp && !waitForVSync) { |
| 221 | // we received a VSYNC but we have no clients |
| 222 | // don't report it, and disable VSYNC events |
| 223 | disableVSyncLocked(); |
| 224 | } else if (!timestamp && waitForVSync) { |
Andy McFadden | 6bf552e | 2012-08-30 16:34:41 -0700 | [diff] [blame] | 225 | // we have at least one client, so we want vsync enabled |
| 226 | // (TODO: this function is called right after we finish |
| 227 | // notifying clients of a vsync, so this call will be made |
| 228 | // at the vsync rate, e.g. 60fps. If we can accurately |
| 229 | // track the current state we could avoid making this call |
| 230 | // so often.) |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 231 | enableVSyncLocked(); |
| 232 | } |
| 233 | |
Andy McFadden | 6bf552e | 2012-08-30 16:34:41 -0700 | [diff] [blame] | 234 | // note: !timestamp implies signalConnections.isEmpty(), because we |
| 235 | // don't populate signalConnections if there's no vsync pending |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame^] | 236 | if (!timestamp && !eventPending) { |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 237 | // wait for something to happen |
Andy McFadden | 6bf552e | 2012-08-30 16:34:41 -0700 | [diff] [blame] | 238 | if (waitForVSync) { |
| 239 | // This is where we spend most of our time, waiting |
| 240 | // for vsync events and new client registrations. |
| 241 | // |
| 242 | // If the screen is off, we can't use h/w vsync, so we |
| 243 | // use a 16ms timeout instead. It doesn't need to be |
| 244 | // precise, we just need to keep feeding our clients. |
| 245 | // |
| 246 | // We don't want to stall if there's a driver bug, so we |
| 247 | // use a (long) timeout when waiting for h/w vsync, and |
| 248 | // generate fake events when necessary. |
| 249 | bool softwareSync = mUseSoftwareVSync; |
| 250 | nsecs_t timeout = softwareSync ? ms2ns(16) : ms2ns(1000); |
| 251 | if (mCondition.waitRelative(mLock, timeout) == TIMED_OUT) { |
| 252 | if (!softwareSync) { |
| 253 | ALOGW("Timed out waiting for hw vsync; faking it"); |
| 254 | } |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 255 | mVSyncTimestamp = systemTime(SYSTEM_TIME_MONOTONIC); |
| 256 | mVSyncCount++; |
| 257 | } |
| 258 | } else { |
Andy McFadden | 6bf552e | 2012-08-30 16:34:41 -0700 | [diff] [blame] | 259 | // Nobody is interested in vsync, so we just want to sleep. |
| 260 | // h/w vsync should be disabled, so this will wait until we |
| 261 | // get a new connection, or an existing connection becomes |
| 262 | // interested in receiving vsync again. |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 263 | mCondition.wait(mLock); |
| 264 | } |
| 265 | } |
| 266 | } while (signalConnections.isEmpty()); |
| 267 | |
| 268 | // here we're guaranteed to have a timestamp and some connections to signal |
Andy McFadden | 6bf552e | 2012-08-30 16:34:41 -0700 | [diff] [blame] | 269 | // (The connections might have dropped out of mDisplayEventConnections |
| 270 | // while we were asleep, but we'll still have strong references to them.) |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 271 | return signalConnections; |
| 272 | } |
| 273 | |
Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 274 | void EventThread::enableVSyncLocked() { |
| 275 | if (!mUseSoftwareVSync) { |
| 276 | // never enable h/w VSYNC when screen is off |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 277 | mFlinger->eventControl(SurfaceFlinger::EVENT_VSYNC, true); |
| 278 | mPowerHAL.vsyncHint(true); |
Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 279 | } |
Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 280 | mDebugVsyncEnabled = true; |
| 281 | } |
| 282 | |
Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 283 | void EventThread::disableVSyncLocked() { |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 284 | mFlinger->eventControl(SurfaceFlinger::EVENT_VSYNC, false); |
| 285 | mPowerHAL.vsyncHint(false); |
Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 286 | mDebugVsyncEnabled = false; |
| 287 | } |
| 288 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 289 | void EventThread::dump(String8& result, char* buffer, size_t SIZE) const { |
| 290 | Mutex::Autolock _l(mLock); |
Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 291 | result.appendFormat("VSYNC state: %s\n", |
| 292 | mDebugVsyncEnabled?"enabled":"disabled"); |
Mathias Agopian | 22ffb11 | 2012-04-10 21:04:02 -0700 | [diff] [blame] | 293 | result.appendFormat(" soft-vsync: %s\n", |
| 294 | mUseSoftwareVSync?"enabled":"disabled"); |
Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 295 | result.appendFormat(" numListeners=%u,\n events-delivered: %u\n", |
Mathias Agopian | 10125f0 | 2012-08-17 15:06:02 -0700 | [diff] [blame] | 296 | mDisplayEventConnections.size(), mVSyncCount); |
Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 297 | for (size_t i=0 ; i<mDisplayEventConnections.size() ; i++) { |
| 298 | sp<Connection> connection = |
| 299 | mDisplayEventConnections.itemAt(i).promote(); |
| 300 | result.appendFormat(" %p: count=%d\n", |
| 301 | connection.get(), connection!=NULL ? connection->count : 0); |
| 302 | } |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | // --------------------------------------------------------------------------- |
| 306 | |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 307 | EventThread::Connection::Connection( |
| 308 | const sp<EventThread>& eventThread) |
| 309 | : count(-1), mEventThread(eventThread), mChannel(new BitTube()) |
| 310 | { |
| 311 | } |
| 312 | |
| 313 | EventThread::Connection::~Connection() { |
Mathias Agopian | f6bbd44 | 2012-08-21 15:47:28 -0700 | [diff] [blame] | 314 | // do nothing here -- clean-up will happen automatically |
| 315 | // when the main thread wakes up |
Mathias Agopian | cb9732a | 2012-04-03 17:48:03 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | void EventThread::Connection::onFirstRef() { |
| 319 | // NOTE: mEventThread doesn't hold a strong reference on us |
| 320 | mEventThread->registerDisplayEventConnection(this); |
| 321 | } |
| 322 | |
| 323 | sp<BitTube> EventThread::Connection::getDataChannel() const { |
| 324 | return mChannel; |
| 325 | } |
| 326 | |
| 327 | void EventThread::Connection::setVsyncRate(uint32_t count) { |
| 328 | mEventThread->setVsyncRate(count, this); |
| 329 | } |
| 330 | |
| 331 | void EventThread::Connection::requestNextVsync() { |
| 332 | mEventThread->requestNextVsync(this); |
| 333 | } |
| 334 | |
| 335 | status_t EventThread::Connection::postEvent( |
| 336 | const DisplayEventReceiver::Event& event) { |
| 337 | ssize_t size = DisplayEventReceiver::sendEvents(mChannel, &event, 1); |
| 338 | return size < 0 ? status_t(size) : status_t(NO_ERROR); |
| 339 | } |
| 340 | |
| 341 | // --------------------------------------------------------------------------- |
| 342 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 343 | }; // namespace android |