blob: ef9268015cc80c917684628bad424e290afe9cac [file] [log] [blame]
Kevin DuBois305bef12019-10-09 13:23:27 -07001/*
2 * Copyright 2019 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
17#define ATRACE_TAG ATRACE_TAG_GRAPHICS
Ady Abraham5e7371c2020-03-24 14:47:24 -070018#include <android-base/stringprintf.h>
Kevin DuBois305bef12019-10-09 13:23:27 -070019#include <utils/Trace.h>
20#include <vector>
21
22#include "TimeKeeper.h"
Kevin DuBoise4f27a82019-11-12 11:41:41 -080023#include "VSyncDispatchTimerQueue.h"
Kevin DuBois305bef12019-10-09 13:23:27 -070024#include "VSyncTracker.h"
25
26namespace android::scheduler {
Ady Abraham5e7371c2020-03-24 14:47:24 -070027using base::StringAppendF;
Kevin DuBois305bef12019-10-09 13:23:27 -070028
Kevin DuBoise4f27a82019-11-12 11:41:41 -080029VSyncDispatch::~VSyncDispatch() = default;
Kevin DuBois305bef12019-10-09 13:23:27 -070030VSyncTracker::~VSyncTracker() = default;
31TimeKeeper::~TimeKeeper() = default;
32
Kevin DuBoise4f27a82019-11-12 11:41:41 -080033VSyncDispatchTimerQueueEntry::VSyncDispatchTimerQueueEntry(std::string const& name,
Kevin DuBois2968afc2020-01-14 09:48:50 -080034 VSyncDispatch::Callback const& cb,
Kevin DuBoisc94ca832019-11-26 12:56:24 -080035 nsecs_t minVsyncDistance)
36 : mName(name),
37 mCallback(cb),
38 mWorkDuration(0),
39 mEarliestVsync(0),
40 mMinVsyncDistance(minVsyncDistance) {}
Kevin DuBois305bef12019-10-09 13:23:27 -070041
Kevin DuBoise4f27a82019-11-12 11:41:41 -080042std::optional<nsecs_t> VSyncDispatchTimerQueueEntry::lastExecutedVsyncTarget() const {
Kevin DuBois305bef12019-10-09 13:23:27 -070043 return mLastDispatchTime;
44}
45
Kevin DuBoise4f27a82019-11-12 11:41:41 -080046std::string_view VSyncDispatchTimerQueueEntry::name() const {
Kevin DuBois305bef12019-10-09 13:23:27 -070047 return mName;
48}
49
Kevin DuBoise4f27a82019-11-12 11:41:41 -080050std::optional<nsecs_t> VSyncDispatchTimerQueueEntry::wakeupTime() const {
Kevin DuBois305bef12019-10-09 13:23:27 -070051 if (!mArmedInfo) {
52 return {};
53 }
54 return {mArmedInfo->mActualWakeupTime};
55}
56
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -080057std::optional<nsecs_t> VSyncDispatchTimerQueueEntry::targetVsync() const {
58 if (!mArmedInfo) {
59 return {};
60 }
61 return {mArmedInfo->mActualVsyncTime};
62}
63
Kevin DuBois2311b1a2019-11-18 16:19:08 -080064ScheduleResult VSyncDispatchTimerQueueEntry::schedule(nsecs_t workDuration, nsecs_t earliestVsync,
65 VSyncTracker& tracker, nsecs_t now) {
Kevin DuBoisc94ca832019-11-26 12:56:24 -080066 auto nextVsyncTime =
Kevin DuBois2311b1a2019-11-18 16:19:08 -080067 tracker.nextAnticipatedVSyncTimeFrom(std::max(earliestVsync, now + workDuration));
Kevin DuBoisc94ca832019-11-26 12:56:24 -080068
69 bool const wouldSkipAVsyncTarget =
70 mArmedInfo && (nextVsyncTime > (mArmedInfo->mActualVsyncTime + mMinVsyncDistance));
71 if (wouldSkipAVsyncTarget) {
72 return ScheduleResult::Scheduled;
73 }
74
75 bool const alreadyDispatchedForVsync = mLastDispatchTime &&
76 ((*mLastDispatchTime + mMinVsyncDistance) >= nextVsyncTime &&
77 (*mLastDispatchTime - mMinVsyncDistance) <= nextVsyncTime);
78 if (alreadyDispatchedForVsync) {
79 nextVsyncTime =
80 tracker.nextAnticipatedVSyncTimeFrom(*mLastDispatchTime + mMinVsyncDistance);
Kevin DuBois2311b1a2019-11-18 16:19:08 -080081 }
82
83 auto const nextWakeupTime = nextVsyncTime - workDuration;
Kevin DuBois305bef12019-10-09 13:23:27 -070084 mWorkDuration = workDuration;
85 mEarliestVsync = earliestVsync;
Kevin DuBois2311b1a2019-11-18 16:19:08 -080086 mArmedInfo = {nextWakeupTime, nextVsyncTime};
Kevin DuBoisc94ca832019-11-26 12:56:24 -080087 return ScheduleResult::Scheduled;
Kevin DuBois305bef12019-10-09 13:23:27 -070088}
89
Kevin DuBois5c18c1c2020-05-27 15:50:50 -070090void VSyncDispatchTimerQueueEntry::addPendingWorkloadUpdate(nsecs_t workDuration,
91 nsecs_t earliestVsync) {
92 mWorkloadUpdateInfo = {.earliestVsync = earliestVsync, .duration = workDuration};
93}
94
95bool VSyncDispatchTimerQueueEntry::hasPendingWorkloadUpdate() const {
96 return mWorkloadUpdateInfo.has_value();
97}
98
Kevin DuBoise4f27a82019-11-12 11:41:41 -080099void VSyncDispatchTimerQueueEntry::update(VSyncTracker& tracker, nsecs_t now) {
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700100 if (!mArmedInfo && !mWorkloadUpdateInfo) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700101 return;
102 }
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700103
104 if (mWorkloadUpdateInfo) {
105 mEarliestVsync = mWorkloadUpdateInfo->earliestVsync;
106 mWorkDuration = mWorkloadUpdateInfo->duration;
107 mWorkloadUpdateInfo.reset();
108 }
109
Kevin DuBois305bef12019-10-09 13:23:27 -0700110 auto const nextVsyncTime =
111 tracker.nextAnticipatedVSyncTimeFrom(std::max(mEarliestVsync, now + mWorkDuration));
112 mArmedInfo = {nextVsyncTime - mWorkDuration, nextVsyncTime};
113}
114
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800115void VSyncDispatchTimerQueueEntry::disarm() {
Kevin DuBois305bef12019-10-09 13:23:27 -0700116 mArmedInfo.reset();
117}
118
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800119nsecs_t VSyncDispatchTimerQueueEntry::executing() {
Kevin DuBois305bef12019-10-09 13:23:27 -0700120 mLastDispatchTime = mArmedInfo->mActualVsyncTime;
121 disarm();
122 return *mLastDispatchTime;
123}
124
Kevin DuBois2968afc2020-01-14 09:48:50 -0800125void VSyncDispatchTimerQueueEntry::callback(nsecs_t vsyncTimestamp, nsecs_t wakeupTimestamp) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700126 {
127 std::lock_guard<std::mutex> lk(mRunningMutex);
128 mRunning = true;
129 }
130
Kevin DuBois2968afc2020-01-14 09:48:50 -0800131 mCallback(vsyncTimestamp, wakeupTimestamp);
Kevin DuBois305bef12019-10-09 13:23:27 -0700132
133 std::lock_guard<std::mutex> lk(mRunningMutex);
134 mRunning = false;
135 mCv.notify_all();
136}
137
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800138void VSyncDispatchTimerQueueEntry::ensureNotRunning() {
Kevin DuBois305bef12019-10-09 13:23:27 -0700139 std::unique_lock<std::mutex> lk(mRunningMutex);
140 mCv.wait(lk, [this]() REQUIRES(mRunningMutex) { return !mRunning; });
141}
142
Ady Abraham5e7371c2020-03-24 14:47:24 -0700143void VSyncDispatchTimerQueueEntry::dump(std::string& result) const {
144 std::lock_guard<std::mutex> lk(mRunningMutex);
145 std::string armedInfo;
146 if (mArmedInfo) {
147 StringAppendF(&armedInfo, "[wake up in %.2fms for vsync %.2fms from now]",
148 (mArmedInfo->mActualWakeupTime - systemTime()) / 1e6f,
149 (mArmedInfo->mActualVsyncTime - systemTime()) / 1e6f);
150 }
151
152 StringAppendF(&result, "\t\t%s: %s %s\n", mName.c_str(),
153 mRunning ? "(in callback function)" : "", armedInfo.c_str());
154 StringAppendF(&result, "\t\t\tmWorkDuration: %.2fms mEarliestVsync: %.2fms relative to now\n",
155 mWorkDuration / 1e6f, (mEarliestVsync - systemTime()) / 1e6f);
156
157 if (mLastDispatchTime) {
158 StringAppendF(&result, "\t\t\tmLastDispatchTime: %.2fms ago\n",
159 (systemTime() - *mLastDispatchTime) / 1e6f);
160 } else {
161 StringAppendF(&result, "\t\t\tmLastDispatchTime unknown\n");
162 }
163}
164
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800165VSyncDispatchTimerQueue::VSyncDispatchTimerQueue(std::unique_ptr<TimeKeeper> tk,
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800166 VSyncTracker& tracker, nsecs_t timerSlack,
167 nsecs_t minVsyncDistance)
168 : mTimeKeeper(std::move(tk)),
169 mTracker(tracker),
170 mTimerSlack(timerSlack),
171 mMinVsyncDistance(minVsyncDistance) {}
Kevin DuBois305bef12019-10-09 13:23:27 -0700172
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800173VSyncDispatchTimerQueue::~VSyncDispatchTimerQueue() {
Kevin DuBois305bef12019-10-09 13:23:27 -0700174 std::lock_guard<decltype(mMutex)> lk(mMutex);
175 cancelTimer();
176}
177
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800178void VSyncDispatchTimerQueue::cancelTimer() {
Kevin DuBois305bef12019-10-09 13:23:27 -0700179 mIntendedWakeupTime = kInvalidTime;
180 mTimeKeeper->alarmCancel();
181}
182
Ady Abraham5ff4bb82020-08-15 15:47:56 -0700183void VSyncDispatchTimerQueue::setTimer(nsecs_t targetTime, nsecs_t /*now*/) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700184 mIntendedWakeupTime = targetTime;
Ady Abraham5ff4bb82020-08-15 15:47:56 -0700185 mTimeKeeper->alarmAt(std::bind(&VSyncDispatchTimerQueue::timerCallback, this),
186 mIntendedWakeupTime);
Ady Abraham75398722020-04-07 14:08:45 -0700187 mLastTimerSchedule = mTimeKeeper->now();
Kevin DuBois305bef12019-10-09 13:23:27 -0700188}
189
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800190void VSyncDispatchTimerQueue::rearmTimer(nsecs_t now) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700191 rearmTimerSkippingUpdateFor(now, mCallbacks.end());
192}
193
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -0800194void VSyncDispatchTimerQueue::TraceBuffer::note(std::string_view name, nsecs_t alarmIn,
195 nsecs_t vsFor) {
196 if (ATRACE_ENABLED()) {
197 snprintf(str_buffer.data(), str_buffer.size(), "%.4s%s%" PRId64 "%s%" PRId64,
198 name.substr(0, kMaxNamePrint).data(), kTraceNamePrefix, alarmIn,
199 kTraceNameSeparator, vsFor);
200 }
201 ATRACE_NAME(str_buffer.data());
202}
203
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800204void VSyncDispatchTimerQueue::rearmTimerSkippingUpdateFor(
205 nsecs_t now, CallbackMap::iterator const& skipUpdateIt) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700206 std::optional<nsecs_t> min;
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -0800207 std::optional<nsecs_t> targetVsync;
208 std::optional<std::string_view> nextWakeupName;
Kevin DuBois305bef12019-10-09 13:23:27 -0700209 for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++) {
210 auto& callback = it->second;
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700211 if (!callback->wakeupTime() && !callback->hasPendingWorkloadUpdate()) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700212 continue;
213 }
214
215 if (it != skipUpdateIt) {
216 callback->update(mTracker, now);
217 }
218 auto const wakeupTime = *callback->wakeupTime();
219 if (!min || (min && *min > wakeupTime)) {
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -0800220 nextWakeupName = callback->name();
Kevin DuBois305bef12019-10-09 13:23:27 -0700221 min = wakeupTime;
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -0800222 targetVsync = callback->targetVsync();
Kevin DuBois305bef12019-10-09 13:23:27 -0700223 }
224 }
225
226 if (min && (min < mIntendedWakeupTime)) {
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -0800227 if (targetVsync && nextWakeupName) {
228 mTraceBuffer.note(*nextWakeupName, *min - now, *targetVsync - now);
229 }
Kevin DuBois305bef12019-10-09 13:23:27 -0700230 setTimer(*min, now);
231 } else {
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -0800232 ATRACE_NAME("cancel timer");
Kevin DuBois305bef12019-10-09 13:23:27 -0700233 cancelTimer();
234 }
235}
236
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800237void VSyncDispatchTimerQueue::timerCallback() {
Kevin DuBois305bef12019-10-09 13:23:27 -0700238 struct Invocation {
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800239 std::shared_ptr<VSyncDispatchTimerQueueEntry> callback;
Kevin DuBois2968afc2020-01-14 09:48:50 -0800240 nsecs_t vsyncTimestamp;
241 nsecs_t wakeupTimestamp;
Kevin DuBois305bef12019-10-09 13:23:27 -0700242 };
243 std::vector<Invocation> invocations;
244 {
245 std::lock_guard<decltype(mMutex)> lk(mMutex);
Kevin DuBoisacfe5542020-07-16 10:21:36 -0700246 auto const now = mTimeKeeper->now();
247 mLastTimerCallback = now;
Kevin DuBois305bef12019-10-09 13:23:27 -0700248 for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++) {
249 auto& callback = it->second;
250 auto const wakeupTime = callback->wakeupTime();
251 if (!wakeupTime) {
252 continue;
253 }
254
Kevin DuBoisacfe5542020-07-16 10:21:36 -0700255 auto const lagAllowance = std::max(now - mIntendedWakeupTime, static_cast<nsecs_t>(0));
256 if (*wakeupTime < mIntendedWakeupTime + mTimerSlack + lagAllowance) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700257 callback->executing();
258 invocations.emplace_back(
Kevin DuBois2968afc2020-01-14 09:48:50 -0800259 Invocation{callback, *callback->lastExecutedVsyncTarget(), *wakeupTime});
Kevin DuBois305bef12019-10-09 13:23:27 -0700260 }
261 }
262
263 mIntendedWakeupTime = kInvalidTime;
264 rearmTimer(mTimeKeeper->now());
265 }
266
267 for (auto const& invocation : invocations) {
Kevin DuBois2968afc2020-01-14 09:48:50 -0800268 invocation.callback->callback(invocation.vsyncTimestamp, invocation.wakeupTimestamp);
Kevin DuBois305bef12019-10-09 13:23:27 -0700269 }
270}
271
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800272VSyncDispatchTimerQueue::CallbackToken VSyncDispatchTimerQueue::registerCallback(
Kevin DuBois2968afc2020-01-14 09:48:50 -0800273 Callback const& callbackFn, std::string callbackName) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700274 std::lock_guard<decltype(mMutex)> lk(mMutex);
275 return CallbackToken{
276 mCallbacks
277 .emplace(++mCallbackToken,
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800278 std::make_shared<VSyncDispatchTimerQueueEntry>(callbackName,
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800279 callbackFn,
280 mMinVsyncDistance))
Kevin DuBois305bef12019-10-09 13:23:27 -0700281 .first->first};
282}
283
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800284void VSyncDispatchTimerQueue::unregisterCallback(CallbackToken token) {
285 std::shared_ptr<VSyncDispatchTimerQueueEntry> entry = nullptr;
Kevin DuBois305bef12019-10-09 13:23:27 -0700286 {
287 std::lock_guard<decltype(mMutex)> lk(mMutex);
288 auto it = mCallbacks.find(token);
289 if (it != mCallbacks.end()) {
290 entry = it->second;
291 mCallbacks.erase(it);
292 }
293 }
294
295 if (entry) {
296 entry->ensureNotRunning();
297 }
298}
299
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800300ScheduleResult VSyncDispatchTimerQueue::schedule(CallbackToken token, nsecs_t workDuration,
301 nsecs_t earliestVsync) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700302 auto result = ScheduleResult::Error;
303 {
304 std::lock_guard<decltype(mMutex)> lk(mMutex);
305
306 auto it = mCallbacks.find(token);
307 if (it == mCallbacks.end()) {
308 return result;
309 }
310 auto& callback = it->second;
Kevin DuBois305bef12019-10-09 13:23:27 -0700311 auto const now = mTimeKeeper->now();
Kevin DuBois5c18c1c2020-05-27 15:50:50 -0700312
313 /* If the timer thread will run soon, we'll apply this work update via the callback
314 * timer recalculation to avoid cancelling a callback that is about to fire. */
315 auto const rearmImminent = now > mIntendedWakeupTime;
316 if (CC_UNLIKELY(rearmImminent)) {
317 callback->addPendingWorkloadUpdate(workDuration, earliestVsync);
318 return ScheduleResult::Scheduled;
319 }
320
Kevin DuBois2311b1a2019-11-18 16:19:08 -0800321 result = callback->schedule(workDuration, earliestVsync, mTracker, now);
322 if (result == ScheduleResult::CannotSchedule) {
323 return result;
Kevin DuBois305bef12019-10-09 13:23:27 -0700324 }
325
Kevin DuBois2311b1a2019-11-18 16:19:08 -0800326 if (callback->wakeupTime() < mIntendedWakeupTime - mTimerSlack) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700327 rearmTimerSkippingUpdateFor(now, it);
328 }
329 }
330
331 return result;
332}
333
Kevin DuBoise4f27a82019-11-12 11:41:41 -0800334CancelResult VSyncDispatchTimerQueue::cancel(CallbackToken token) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700335 std::lock_guard<decltype(mMutex)> lk(mMutex);
336
337 auto it = mCallbacks.find(token);
338 if (it == mCallbacks.end()) {
339 return CancelResult::Error;
340 }
341 auto& callback = it->second;
342
Kevin DuBoisb340b732020-06-16 09:07:35 -0700343 auto const wakeupTime = callback->wakeupTime();
344 if (wakeupTime) {
Kevin DuBois305bef12019-10-09 13:23:27 -0700345 callback->disarm();
Kevin DuBoisb340b732020-06-16 09:07:35 -0700346
347 if (*wakeupTime == mIntendedWakeupTime) {
348 mIntendedWakeupTime = kInvalidTime;
349 rearmTimer(mTimeKeeper->now());
350 }
Kevin DuBois305bef12019-10-09 13:23:27 -0700351 return CancelResult::Cancelled;
352 }
353 return CancelResult::TooLate;
354}
355
Ady Abraham5e7371c2020-03-24 14:47:24 -0700356void VSyncDispatchTimerQueue::dump(std::string& result) const {
357 std::lock_guard<decltype(mMutex)> lk(mMutex);
Ady Abraham75398722020-04-07 14:08:45 -0700358 StringAppendF(&result, "\tTimer:\n");
359 mTimeKeeper->dump(result);
Ady Abraham5e7371c2020-03-24 14:47:24 -0700360 StringAppendF(&result, "\tmTimerSlack: %.2fms mMinVsyncDistance: %.2fms\n", mTimerSlack / 1e6f,
361 mMinVsyncDistance / 1e6f);
362 StringAppendF(&result, "\tmIntendedWakeupTime: %.2fms from now\n",
Ady Abraham75398722020-04-07 14:08:45 -0700363 (mIntendedWakeupTime - mTimeKeeper->now()) / 1e6f);
364 StringAppendF(&result, "\tmLastTimerCallback: %.2fms ago mLastTimerSchedule: %.2fms ago\n",
365 (mTimeKeeper->now() - mLastTimerCallback) / 1e6f,
366 (mTimeKeeper->now() - mLastTimerSchedule) / 1e6f);
Ady Abraham5e7371c2020-03-24 14:47:24 -0700367 StringAppendF(&result, "\tCallbacks:\n");
368 for (const auto& [token, entry] : mCallbacks) {
369 entry->dump(result);
370 }
371}
372
Kevin DuBois305bef12019-10-09 13:23:27 -0700373VSyncCallbackRegistration::VSyncCallbackRegistration(VSyncDispatch& dispatch,
Kevin DuBois2968afc2020-01-14 09:48:50 -0800374 VSyncDispatch::Callback const& callbackFn,
Kevin DuBois305bef12019-10-09 13:23:27 -0700375 std::string const& callbackName)
376 : mDispatch(dispatch),
377 mToken(dispatch.registerCallback(callbackFn, callbackName)),
378 mValidToken(true) {}
379
380VSyncCallbackRegistration::VSyncCallbackRegistration(VSyncCallbackRegistration&& other)
381 : mDispatch(other.mDispatch),
382 mToken(std::move(other.mToken)),
383 mValidToken(std::move(other.mValidToken)) {
384 other.mValidToken = false;
385}
386
387VSyncCallbackRegistration& VSyncCallbackRegistration::operator=(VSyncCallbackRegistration&& other) {
388 mDispatch = std::move(other.mDispatch);
389 mToken = std::move(other.mToken);
390 mValidToken = std::move(other.mValidToken);
391 other.mValidToken = false;
392 return *this;
393}
394
395VSyncCallbackRegistration::~VSyncCallbackRegistration() {
396 if (mValidToken) mDispatch.get().unregisterCallback(mToken);
397}
398
399ScheduleResult VSyncCallbackRegistration::schedule(nsecs_t workDuration, nsecs_t earliestVsync) {
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800400 if (!mValidToken) {
401 return ScheduleResult::Error;
402 }
Kevin DuBois305bef12019-10-09 13:23:27 -0700403 return mDispatch.get().schedule(mToken, workDuration, earliestVsync);
404}
405
406CancelResult VSyncCallbackRegistration::cancel() {
Kevin DuBoisc94ca832019-11-26 12:56:24 -0800407 if (!mValidToken) {
408 return CancelResult::Error;
409 }
Kevin DuBois305bef12019-10-09 13:23:27 -0700410 return mDispatch.get().cancel(mToken);
411}
412
413} // namespace android::scheduler