John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 17 | #include "RenderThread.h" |
| 18 | |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 19 | #include "../renderstate/RenderState.h" |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 20 | #include "CanvasContext.h" |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 21 | #include "EglManager.h" |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 22 | #include "RenderProxy.h" |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 23 | |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 24 | #include <gui/DisplayEventReceiver.h> |
| 25 | #include <sys/resource.h> |
| 26 | #include <utils/Log.h> |
| 27 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 28 | namespace android { |
| 29 | using namespace uirenderer::renderthread; |
| 30 | ANDROID_SINGLETON_STATIC_INSTANCE(RenderThread); |
| 31 | |
| 32 | namespace uirenderer { |
| 33 | namespace renderthread { |
| 34 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 35 | // Number of events to read at a time from the DisplayEventReceiver pipe. |
| 36 | // The value should be large enough that we can quickly drain the pipe |
| 37 | // using just a few large reads. |
| 38 | static const size_t EVENT_BUFFER_SIZE = 100; |
| 39 | |
| 40 | // Slight delay to give the UI time to push us a new frame before we replay |
John Reck | a733f89 | 2014-12-19 11:37:21 -0800 | [diff] [blame] | 41 | static const nsecs_t DISPATCH_FRAME_CALLBACKS_DELAY = milliseconds_to_nanoseconds(4); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 42 | |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 43 | TaskQueue::TaskQueue() : mHead(nullptr), mTail(nullptr) {} |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 44 | |
| 45 | RenderTask* TaskQueue::next() { |
| 46 | RenderTask* ret = mHead; |
| 47 | if (ret) { |
| 48 | mHead = ret->mNext; |
| 49 | if (!mHead) { |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 50 | mTail = nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 51 | } |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 52 | ret->mNext = nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 53 | } |
| 54 | return ret; |
| 55 | } |
| 56 | |
| 57 | RenderTask* TaskQueue::peek() { |
| 58 | return mHead; |
| 59 | } |
| 60 | |
| 61 | void TaskQueue::queue(RenderTask* task) { |
| 62 | // Since the RenderTask itself forms the linked list it is not allowed |
| 63 | // to have the same task queued twice |
| 64 | LOG_ALWAYS_FATAL_IF(task->mNext || mTail == task, "Task is already in the queue!"); |
| 65 | if (mTail) { |
| 66 | // Fast path if we can just append |
| 67 | if (mTail->mRunAt <= task->mRunAt) { |
| 68 | mTail->mNext = task; |
| 69 | mTail = task; |
| 70 | } else { |
| 71 | // Need to find the proper insertion point |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 72 | RenderTask* previous = nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 73 | RenderTask* next = mHead; |
| 74 | while (next && next->mRunAt <= task->mRunAt) { |
| 75 | previous = next; |
| 76 | next = next->mNext; |
| 77 | } |
| 78 | if (!previous) { |
| 79 | task->mNext = mHead; |
| 80 | mHead = task; |
| 81 | } else { |
| 82 | previous->mNext = task; |
| 83 | if (next) { |
| 84 | task->mNext = next; |
| 85 | } else { |
| 86 | mTail = task; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | } else { |
| 91 | mTail = mHead = task; |
| 92 | } |
| 93 | } |
| 94 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 95 | void TaskQueue::queueAtFront(RenderTask* task) { |
| 96 | if (mTail) { |
| 97 | task->mNext = mHead; |
| 98 | mHead = task; |
| 99 | } else { |
| 100 | mTail = mHead = task; |
| 101 | } |
| 102 | } |
| 103 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 104 | void TaskQueue::remove(RenderTask* task) { |
| 105 | // TaskQueue is strict here to enforce that users are keeping track of |
| 106 | // their RenderTasks due to how their memory is managed |
| 107 | LOG_ALWAYS_FATAL_IF(!task->mNext && mTail != task, |
| 108 | "Cannot remove a task that isn't in the queue!"); |
| 109 | |
| 110 | // If task is the head we can just call next() to pop it off |
| 111 | // Otherwise we need to scan through to find the task before it |
| 112 | if (peek() == task) { |
| 113 | next(); |
| 114 | } else { |
| 115 | RenderTask* previous = mHead; |
| 116 | while (previous->mNext != task) { |
| 117 | previous = previous->mNext; |
| 118 | } |
| 119 | previous->mNext = task->mNext; |
| 120 | if (mTail == task) { |
| 121 | mTail = previous; |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 126 | class DispatchFrameCallbacks : public RenderTask { |
| 127 | private: |
| 128 | RenderThread* mRenderThread; |
| 129 | public: |
| 130 | DispatchFrameCallbacks(RenderThread* rt) : mRenderThread(rt) {} |
| 131 | |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 132 | virtual void run() override { |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 133 | mRenderThread->dispatchFrameCallbacks(); |
| 134 | } |
| 135 | }; |
| 136 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 137 | RenderThread::RenderThread() : Thread(true), Singleton<RenderThread>() |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 138 | , mNextWakeup(LLONG_MAX) |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 139 | , mDisplayEventReceiver(nullptr) |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 140 | , mVsyncRequested(false) |
| 141 | , mFrameCallbackTaskPending(false) |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 142 | , mFrameCallbackTask(nullptr) |
| 143 | , mRenderState(nullptr) |
| 144 | , mEglManager(nullptr) { |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 145 | mFrameCallbackTask = new DispatchFrameCallbacks(this); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 146 | mLooper = new Looper(false); |
| 147 | run("RenderThread"); |
| 148 | } |
| 149 | |
| 150 | RenderThread::~RenderThread() { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 151 | LOG_ALWAYS_FATAL("Can't destroy the render thread"); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 152 | } |
| 153 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 154 | void RenderThread::setFrameInterval(nsecs_t frameInterval) { |
| 155 | mTimeLord.setFrameInterval(frameInterval); |
| 156 | mJankTracker->setFrameInterval(frameInterval); |
| 157 | } |
| 158 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 159 | void RenderThread::initializeDisplayEventReceiver() { |
| 160 | LOG_ALWAYS_FATAL_IF(mDisplayEventReceiver, "Initializing a second DisplayEventReceiver?"); |
| 161 | mDisplayEventReceiver = new DisplayEventReceiver(); |
| 162 | status_t status = mDisplayEventReceiver->initCheck(); |
| 163 | LOG_ALWAYS_FATAL_IF(status != NO_ERROR, "Initialization of DisplayEventReceiver " |
| 164 | "failed with status: %d", status); |
| 165 | |
| 166 | // Register the FD |
| 167 | mLooper->addFd(mDisplayEventReceiver->getFd(), 0, |
| 168 | Looper::EVENT_INPUT, RenderThread::displayEventReceiverCallback, this); |
| 169 | } |
| 170 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 171 | void RenderThread::initThreadLocals() { |
| 172 | initializeDisplayEventReceiver(); |
| 173 | mEglManager = new EglManager(*this); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 174 | mRenderState = new RenderState(*this); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 175 | mJankTracker = new JankTracker(mTimeLord.frameIntervalNanos()); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 176 | } |
| 177 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 178 | int RenderThread::displayEventReceiverCallback(int fd, int events, void* data) { |
| 179 | if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) { |
| 180 | ALOGE("Display event receiver pipe was closed or an error occurred. " |
| 181 | "events=0x%x", events); |
| 182 | return 0; // remove the callback |
| 183 | } |
| 184 | |
| 185 | if (!(events & Looper::EVENT_INPUT)) { |
| 186 | ALOGW("Received spurious callback for unhandled poll event. " |
| 187 | "events=0x%x", events); |
| 188 | return 1; // keep the callback |
| 189 | } |
| 190 | |
| 191 | reinterpret_cast<RenderThread*>(data)->drainDisplayEventQueue(); |
| 192 | |
| 193 | return 1; // keep the callback |
| 194 | } |
| 195 | |
| 196 | static nsecs_t latestVsyncEvent(DisplayEventReceiver* receiver) { |
| 197 | DisplayEventReceiver::Event buf[EVENT_BUFFER_SIZE]; |
| 198 | nsecs_t latest = 0; |
| 199 | ssize_t n; |
| 200 | while ((n = receiver->getEvents(buf, EVENT_BUFFER_SIZE)) > 0) { |
| 201 | for (ssize_t i = 0; i < n; i++) { |
| 202 | const DisplayEventReceiver::Event& ev = buf[i]; |
| 203 | switch (ev.header.type) { |
| 204 | case DisplayEventReceiver::DISPLAY_EVENT_VSYNC: |
| 205 | latest = ev.header.timestamp; |
| 206 | break; |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | if (n < 0) { |
| 211 | ALOGW("Failed to get events from display event receiver, status=%d", status_t(n)); |
| 212 | } |
| 213 | return latest; |
| 214 | } |
| 215 | |
John Reck | a733f89 | 2014-12-19 11:37:21 -0800 | [diff] [blame] | 216 | void RenderThread::drainDisplayEventQueue() { |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 217 | ATRACE_CALL(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 218 | nsecs_t vsyncEvent = latestVsyncEvent(mDisplayEventReceiver); |
| 219 | if (vsyncEvent > 0) { |
| 220 | mVsyncRequested = false; |
John Reck | a733f89 | 2014-12-19 11:37:21 -0800 | [diff] [blame] | 221 | if (mTimeLord.vsyncReceived(vsyncEvent) && !mFrameCallbackTaskPending) { |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 222 | ATRACE_NAME("queue mFrameCallbackTask"); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 223 | mFrameCallbackTaskPending = true; |
John Reck | a733f89 | 2014-12-19 11:37:21 -0800 | [diff] [blame] | 224 | nsecs_t runAt = (vsyncEvent + DISPATCH_FRAME_CALLBACKS_DELAY); |
| 225 | queueAt(mFrameCallbackTask, runAt); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | void RenderThread::dispatchFrameCallbacks() { |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 231 | ATRACE_CALL(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 232 | mFrameCallbackTaskPending = false; |
| 233 | |
| 234 | std::set<IFrameCallback*> callbacks; |
| 235 | mFrameCallbacks.swap(callbacks); |
| 236 | |
John Reck | a733f89 | 2014-12-19 11:37:21 -0800 | [diff] [blame] | 237 | if (callbacks.size()) { |
| 238 | // Assume one of them will probably animate again so preemptively |
| 239 | // request the next vsync in case it occurs mid-frame |
| 240 | requestVsync(); |
| 241 | for (std::set<IFrameCallback*>::iterator it = callbacks.begin(); it != callbacks.end(); it++) { |
| 242 | (*it)->doFrame(); |
| 243 | } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 247 | void RenderThread::requestVsync() { |
| 248 | if (!mVsyncRequested) { |
| 249 | mVsyncRequested = true; |
| 250 | status_t status = mDisplayEventReceiver->requestNextVsync(); |
| 251 | LOG_ALWAYS_FATAL_IF(status != NO_ERROR, |
| 252 | "requestNextVsync failed with status: %d", status); |
| 253 | } |
| 254 | } |
| 255 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 256 | bool RenderThread::threadLoop() { |
John Reck | 21be43e | 2014-08-14 10:25:16 -0700 | [diff] [blame] | 257 | setpriority(PRIO_PROCESS, 0, PRIORITY_DISPLAY); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 258 | initThreadLocals(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 259 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 260 | int timeoutMillis = -1; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 261 | for (;;) { |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 262 | int result = mLooper->pollOnce(timeoutMillis); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 263 | LOG_ALWAYS_FATAL_IF(result == Looper::POLL_ERROR, |
| 264 | "RenderThread Looper POLL_ERROR!"); |
| 265 | |
| 266 | nsecs_t nextWakeup; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 267 | // Process our queue, if we have anything |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 268 | while (RenderTask* task = nextTask(&nextWakeup)) { |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 269 | task->run(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 270 | // task may have deleted itself, do not reference it again |
| 271 | } |
| 272 | if (nextWakeup == LLONG_MAX) { |
| 273 | timeoutMillis = -1; |
| 274 | } else { |
John Reck | a6260b8 | 2014-01-29 18:31:51 -0800 | [diff] [blame] | 275 | nsecs_t timeoutNanos = nextWakeup - systemTime(SYSTEM_TIME_MONOTONIC); |
| 276 | timeoutMillis = nanoseconds_to_milliseconds(timeoutNanos); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 277 | if (timeoutMillis < 0) { |
| 278 | timeoutMillis = 0; |
| 279 | } |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 280 | } |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 281 | |
| 282 | if (mPendingRegistrationFrameCallbacks.size() && !mFrameCallbackTaskPending) { |
John Reck | a733f89 | 2014-12-19 11:37:21 -0800 | [diff] [blame] | 283 | drainDisplayEventQueue(); |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 284 | mFrameCallbacks.insert( |
| 285 | mPendingRegistrationFrameCallbacks.begin(), mPendingRegistrationFrameCallbacks.end()); |
| 286 | mPendingRegistrationFrameCallbacks.clear(); |
| 287 | requestVsync(); |
| 288 | } |
John Reck | a22c9b2 | 2015-01-14 10:40:15 -0800 | [diff] [blame] | 289 | |
| 290 | if (!mFrameCallbackTaskPending && !mVsyncRequested && mFrameCallbacks.size()) { |
| 291 | // TODO: Clean this up. This is working around an issue where a combination |
| 292 | // of bad timing and slow drawing can result in dropping a stale vsync |
| 293 | // on the floor (correct!) but fails to schedule to listen for the |
| 294 | // next vsync (oops), so none of the callbacks are run. |
| 295 | requestVsync(); |
| 296 | } |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | return false; |
| 300 | } |
| 301 | |
| 302 | void RenderThread::queue(RenderTask* task) { |
| 303 | AutoMutex _lock(mLock); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 304 | mQueue.queue(task); |
| 305 | if (mNextWakeup && task->mRunAt < mNextWakeup) { |
| 306 | mNextWakeup = 0; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 307 | mLooper->wake(); |
| 308 | } |
| 309 | } |
| 310 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 311 | void RenderThread::queueAtFront(RenderTask* task) { |
| 312 | AutoMutex _lock(mLock); |
| 313 | mQueue.queueAtFront(task); |
| 314 | mLooper->wake(); |
| 315 | } |
| 316 | |
John Reck | a733f89 | 2014-12-19 11:37:21 -0800 | [diff] [blame] | 317 | void RenderThread::queueAt(RenderTask* task, nsecs_t runAtNs) { |
| 318 | task->mRunAt = runAtNs; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 319 | queue(task); |
| 320 | } |
| 321 | |
| 322 | void RenderThread::remove(RenderTask* task) { |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 323 | AutoMutex _lock(mLock); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 324 | mQueue.remove(task); |
| 325 | } |
| 326 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 327 | void RenderThread::postFrameCallback(IFrameCallback* callback) { |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 328 | mPendingRegistrationFrameCallbacks.insert(callback); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 329 | } |
| 330 | |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 331 | bool RenderThread::removeFrameCallback(IFrameCallback* callback) { |
| 332 | size_t erased; |
| 333 | erased = mFrameCallbacks.erase(callback); |
| 334 | erased |= mPendingRegistrationFrameCallbacks.erase(callback); |
| 335 | return erased; |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | void RenderThread::pushBackFrameCallback(IFrameCallback* callback) { |
| 339 | if (mFrameCallbacks.erase(callback)) { |
| 340 | mPendingRegistrationFrameCallbacks.insert(callback); |
| 341 | } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 342 | } |
| 343 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 344 | RenderTask* RenderThread::nextTask(nsecs_t* nextWakeup) { |
| 345 | AutoMutex _lock(mLock); |
| 346 | RenderTask* next = mQueue.peek(); |
| 347 | if (!next) { |
| 348 | mNextWakeup = LLONG_MAX; |
| 349 | } else { |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 350 | mNextWakeup = next->mRunAt; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 351 | // Most tasks won't be delayed, so avoid unnecessary systemTime() calls |
| 352 | if (next->mRunAt <= 0 || next->mRunAt <= systemTime(SYSTEM_TIME_MONOTONIC)) { |
| 353 | next = mQueue.next(); |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 354 | } else { |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 355 | next = nullptr; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 356 | } |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 357 | } |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 358 | if (nextWakeup) { |
| 359 | *nextWakeup = mNextWakeup; |
| 360 | } |
| 361 | return next; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 362 | } |
| 363 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 364 | } /* namespace renderthread */ |
| 365 | } /* namespace uirenderer */ |
| 366 | } /* namespace android */ |