Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 1 | /* |
| 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 |
Dominik Laskowski | 62eff35 | 2021-12-06 09:59:41 -0800 | [diff] [blame] | 18 | |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 19 | #include <vector> |
| 20 | |
Dominik Laskowski | 62eff35 | 2021-12-06 09:59:41 -0800 | [diff] [blame] | 21 | #include <android-base/stringprintf.h> |
| 22 | #include <ftl/concat.h> |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame^] | 23 | #include <utils/Trace.h> |
Leon Scroggins III | 0773813 | 2023-04-24 11:43:53 -0400 | [diff] [blame] | 24 | #include <log/log_main.h> |
Dominik Laskowski | 62eff35 | 2021-12-06 09:59:41 -0800 | [diff] [blame] | 25 | |
Dominik Laskowski | 4e0d20d | 2021-12-06 11:31:02 -0800 | [diff] [blame] | 26 | #include <scheduler/TimeKeeper.h> |
| 27 | |
Alec Mouri | 9b133ca | 2023-11-14 19:00:01 +0000 | [diff] [blame] | 28 | #include <common/FlagManager.h> |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 29 | #include "VSyncDispatchTimerQueue.h" |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 30 | #include "VSyncTracker.h" |
| 31 | |
Leon Scroggins III | 0773813 | 2023-04-24 11:43:53 -0400 | [diff] [blame] | 32 | #undef LOG_TAG |
| 33 | #define LOG_TAG "VSyncDispatch" |
| 34 | |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 35 | namespace android::scheduler { |
Dominik Laskowski | 62eff35 | 2021-12-06 09:59:41 -0800 | [diff] [blame] | 36 | |
Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 37 | using base::StringAppendF; |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 38 | |
Ady Abraham | b5d3afa | 2021-05-07 11:22:23 -0700 | [diff] [blame] | 39 | namespace { |
Dominik Laskowski | 4e0d20d | 2021-12-06 11:31:02 -0800 | [diff] [blame] | 40 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 41 | ScheduleResult getExpectedCallbackTime(nsecs_t nextVsyncTime, |
| 42 | const VSyncDispatch::ScheduleTiming& timing) { |
| 43 | return {TimePoint::fromNs(nextVsyncTime - timing.readyDuration - timing.workDuration), |
| 44 | TimePoint::fromNs(nextVsyncTime)}; |
Ady Abraham | b5d3afa | 2021-05-07 11:22:23 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Ady Abraham | b5d3afa | 2021-05-07 11:22:23 -0700 | [diff] [blame] | 47 | } // namespace |
| 48 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 49 | VSyncDispatch::~VSyncDispatch() = default; |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 50 | VSyncTracker::~VSyncTracker() = default; |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 51 | |
Dominik Laskowski | 4e0d20d | 2021-12-06 11:31:02 -0800 | [diff] [blame] | 52 | VSyncDispatchTimerQueueEntry::VSyncDispatchTimerQueueEntry(std::string name, |
| 53 | VSyncDispatch::Callback callback, |
Kevin DuBois | c94ca83 | 2019-11-26 12:56:24 -0800 | [diff] [blame] | 54 | nsecs_t minVsyncDistance) |
Dominik Laskowski | 4e0d20d | 2021-12-06 11:31:02 -0800 | [diff] [blame] | 55 | : mName(std::move(name)), |
| 56 | mCallback(std::move(callback)), |
Kevin DuBois | c94ca83 | 2019-11-26 12:56:24 -0800 | [diff] [blame] | 57 | mMinVsyncDistance(minVsyncDistance) {} |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 58 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 59 | std::optional<nsecs_t> VSyncDispatchTimerQueueEntry::lastExecutedVsyncTarget() const { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 60 | return mLastDispatchTime; |
| 61 | } |
| 62 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 63 | std::string_view VSyncDispatchTimerQueueEntry::name() const { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 64 | return mName; |
| 65 | } |
| 66 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 67 | std::optional<nsecs_t> VSyncDispatchTimerQueueEntry::wakeupTime() const { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 68 | if (!mArmedInfo) { |
| 69 | return {}; |
| 70 | } |
| 71 | return {mArmedInfo->mActualWakeupTime}; |
| 72 | } |
| 73 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 74 | std::optional<nsecs_t> VSyncDispatchTimerQueueEntry::readyTime() const { |
| 75 | if (!mArmedInfo) { |
| 76 | return {}; |
| 77 | } |
| 78 | return {mArmedInfo->mActualReadyTime}; |
| 79 | } |
| 80 | |
Kevin DuBois | ecb1f0d | 2019-12-12 10:47:41 -0800 | [diff] [blame] | 81 | std::optional<nsecs_t> VSyncDispatchTimerQueueEntry::targetVsync() const { |
| 82 | if (!mArmedInfo) { |
| 83 | return {}; |
| 84 | } |
| 85 | return {mArmedInfo->mActualVsyncTime}; |
| 86 | } |
| 87 | |
ramindani | 558f4a9 | 2024-02-16 15:49:23 -0800 | [diff] [blame] | 88 | ScheduleResult VSyncDispatchTimerQueueEntry::schedule(VSyncDispatch::ScheduleTiming timing, |
| 89 | VSyncTracker& tracker, nsecs_t now) { |
Ady Abraham | 4335afd | 2023-12-18 19:10:47 -0800 | [diff] [blame] | 90 | auto nextVsyncTime = |
| 91 | tracker.nextAnticipatedVSyncTimeFrom(std::max(timing.lastVsync, |
| 92 | now + timing.workDuration + |
| 93 | timing.readyDuration), |
| 94 | timing.lastVsync); |
Ady Abraham | 69b9e62 | 2021-07-19 12:24:31 -0700 | [diff] [blame] | 95 | auto nextWakeupTime = nextVsyncTime - timing.workDuration - timing.readyDuration; |
Kevin DuBois | c94ca83 | 2019-11-26 12:56:24 -0800 | [diff] [blame] | 96 | |
| 97 | bool const wouldSkipAVsyncTarget = |
| 98 | mArmedInfo && (nextVsyncTime > (mArmedInfo->mActualVsyncTime + mMinVsyncDistance)); |
Ady Abraham | 69b9e62 | 2021-07-19 12:24:31 -0700 | [diff] [blame] | 99 | bool const wouldSkipAWakeup = |
| 100 | mArmedInfo && ((nextWakeupTime > (mArmedInfo->mActualWakeupTime + mMinVsyncDistance))); |
Ady Abraham | bf55489 | 2024-02-14 18:18:21 +0000 | [diff] [blame] | 101 | if (FlagManager::getInstance().dont_skip_on_early_ro()) { |
Ady Abraham | 529bd9f | 2023-10-05 14:55:30 -0700 | [diff] [blame] | 102 | if (wouldSkipAVsyncTarget || wouldSkipAWakeup) { |
Ady Abraham | b0d3d98 | 2023-10-30 11:29:51 -0700 | [diff] [blame] | 103 | nextVsyncTime = mArmedInfo->mActualVsyncTime; |
| 104 | } else { |
| 105 | nextVsyncTime = adjustVsyncIfNeeded(tracker, nextVsyncTime); |
Ady Abraham | 529bd9f | 2023-10-05 14:55:30 -0700 | [diff] [blame] | 106 | } |
Ady Abraham | b0d3d98 | 2023-10-30 11:29:51 -0700 | [diff] [blame] | 107 | nextWakeupTime = std::max(now, nextVsyncTime - timing.workDuration - timing.readyDuration); |
Ady Abraham | 529bd9f | 2023-10-05 14:55:30 -0700 | [diff] [blame] | 108 | } else { |
| 109 | if (wouldSkipAVsyncTarget && wouldSkipAWakeup) { |
Ady Abraham | b0d3d98 | 2023-10-30 11:29:51 -0700 | [diff] [blame] | 110 | return getExpectedCallbackTime(nextVsyncTime, timing); |
Ady Abraham | 529bd9f | 2023-10-05 14:55:30 -0700 | [diff] [blame] | 111 | } |
Ady Abraham | b0d3d98 | 2023-10-30 11:29:51 -0700 | [diff] [blame] | 112 | nextVsyncTime = adjustVsyncIfNeeded(tracker, nextVsyncTime); |
| 113 | nextWakeupTime = nextVsyncTime - timing.workDuration - timing.readyDuration; |
Kevin DuBois | c94ca83 | 2019-11-26 12:56:24 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 116 | auto const nextReadyTime = nextVsyncTime - timing.readyDuration; |
| 117 | mScheduleTiming = timing; |
| 118 | mArmedInfo = {nextWakeupTime, nextVsyncTime, nextReadyTime}; |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 119 | return ScheduleResult{TimePoint::fromNs(nextWakeupTime), TimePoint::fromNs(nextVsyncTime)}; |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 120 | } |
| 121 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 122 | ScheduleResult VSyncDispatchTimerQueueEntry::addPendingWorkloadUpdate( |
Ady Abraham | da8af4c | 2024-02-14 00:24:34 +0000 | [diff] [blame] | 123 | VSyncTracker& tracker, nsecs_t now, VSyncDispatch::ScheduleTiming timing) { |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 124 | mWorkloadUpdateInfo = timing; |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame^] | 125 | const auto armedInfo = update(tracker, now, timing, mArmedInfo); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 126 | return {TimePoint::fromNs(armedInfo.mActualWakeupTime), |
| 127 | TimePoint::fromNs(armedInfo.mActualVsyncTime)}; |
Kevin DuBois | 5c18c1c | 2020-05-27 15:50:50 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | bool VSyncDispatchTimerQueueEntry::hasPendingWorkloadUpdate() const { |
| 131 | return mWorkloadUpdateInfo.has_value(); |
| 132 | } |
| 133 | |
Ady Abraham | 3fcfd8b | 2022-07-12 12:31:00 -0700 | [diff] [blame] | 134 | nsecs_t VSyncDispatchTimerQueueEntry::adjustVsyncIfNeeded(VSyncTracker& tracker, |
| 135 | nsecs_t nextVsyncTime) const { |
| 136 | bool const alreadyDispatchedForVsync = mLastDispatchTime && |
| 137 | ((*mLastDispatchTime + mMinVsyncDistance) >= nextVsyncTime && |
| 138 | (*mLastDispatchTime - mMinVsyncDistance) <= nextVsyncTime); |
| 139 | const nsecs_t currentPeriod = tracker.currentPeriod(); |
| 140 | bool const nextVsyncTooClose = mLastDispatchTime && |
| 141 | (nextVsyncTime - *mLastDispatchTime + mMinVsyncDistance) <= currentPeriod; |
| 142 | if (alreadyDispatchedForVsync) { |
Ady Abraham | 4335afd | 2023-12-18 19:10:47 -0800 | [diff] [blame] | 143 | return tracker.nextAnticipatedVSyncTimeFrom(*mLastDispatchTime + mMinVsyncDistance, |
| 144 | *mLastDispatchTime); |
Ady Abraham | 3fcfd8b | 2022-07-12 12:31:00 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | if (nextVsyncTooClose) { |
Ady Abraham | 4335afd | 2023-12-18 19:10:47 -0800 | [diff] [blame] | 148 | return tracker.nextAnticipatedVSyncTimeFrom(*mLastDispatchTime + currentPeriod, |
| 149 | *mLastDispatchTime + currentPeriod); |
Ady Abraham | 3fcfd8b | 2022-07-12 12:31:00 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | return nextVsyncTime; |
| 153 | } |
| 154 | |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame^] | 155 | auto VSyncDispatchTimerQueueEntry::update(VSyncTracker& tracker, nsecs_t now, |
| 156 | VSyncDispatch::ScheduleTiming timing, |
| 157 | std::optional<ArmingInfo> armedInfo) const -> ArmingInfo { |
Ady Abraham | da8af4c | 2024-02-14 00:24:34 +0000 | [diff] [blame] | 158 | const auto earliestReadyBy = now + timing.workDuration + timing.readyDuration; |
| 159 | const auto earliestVsync = std::max(earliestReadyBy, timing.lastVsync); |
| 160 | |
| 161 | const auto nextVsyncTime = |
| 162 | adjustVsyncIfNeeded(tracker, /*nextVsyncTime*/ |
| 163 | tracker.nextAnticipatedVSyncTimeFrom(earliestVsync, |
| 164 | timing.lastVsync)); |
| 165 | const auto nextReadyTime = nextVsyncTime - timing.readyDuration; |
| 166 | const auto nextWakeupTime = nextReadyTime - timing.workDuration; |
| 167 | |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame^] | 168 | bool const wouldSkipAVsyncTarget = |
| 169 | armedInfo && (nextVsyncTime > (armedInfo->mActualVsyncTime + mMinVsyncDistance)); |
| 170 | bool const wouldSkipAWakeup = |
| 171 | armedInfo && (nextWakeupTime > (armedInfo->mActualWakeupTime + mMinVsyncDistance)); |
| 172 | if (FlagManager::getInstance().dont_skip_on_early_ro() && |
| 173 | (wouldSkipAVsyncTarget || wouldSkipAWakeup)) { |
| 174 | return *armedInfo; |
Ady Abraham | da8af4c | 2024-02-14 00:24:34 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | return ArmingInfo{nextWakeupTime, nextVsyncTime, nextReadyTime}; |
| 178 | } |
| 179 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 180 | void VSyncDispatchTimerQueueEntry::update(VSyncTracker& tracker, nsecs_t now) { |
Kevin DuBois | 5c18c1c | 2020-05-27 15:50:50 -0700 | [diff] [blame] | 181 | if (!mArmedInfo && !mWorkloadUpdateInfo) { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 182 | return; |
| 183 | } |
Kevin DuBois | 5c18c1c | 2020-05-27 15:50:50 -0700 | [diff] [blame] | 184 | |
| 185 | if (mWorkloadUpdateInfo) { |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 186 | mScheduleTiming = *mWorkloadUpdateInfo; |
Kevin DuBois | 5c18c1c | 2020-05-27 15:50:50 -0700 | [diff] [blame] | 187 | mWorkloadUpdateInfo.reset(); |
| 188 | } |
| 189 | |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame^] | 190 | mArmedInfo = update(tracker, now, mScheduleTiming, mArmedInfo); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 193 | void VSyncDispatchTimerQueueEntry::disarm() { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 194 | mArmedInfo.reset(); |
| 195 | } |
| 196 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 197 | nsecs_t VSyncDispatchTimerQueueEntry::executing() { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 198 | mLastDispatchTime = mArmedInfo->mActualVsyncTime; |
| 199 | disarm(); |
| 200 | return *mLastDispatchTime; |
| 201 | } |
| 202 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 203 | void VSyncDispatchTimerQueueEntry::callback(nsecs_t vsyncTimestamp, nsecs_t wakeupTimestamp, |
| 204 | nsecs_t deadlineTimestamp) { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 205 | { |
| 206 | std::lock_guard<std::mutex> lk(mRunningMutex); |
| 207 | mRunning = true; |
| 208 | } |
| 209 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 210 | mCallback(vsyncTimestamp, wakeupTimestamp, deadlineTimestamp); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 211 | |
| 212 | std::lock_guard<std::mutex> lk(mRunningMutex); |
| 213 | mRunning = false; |
| 214 | mCv.notify_all(); |
| 215 | } |
| 216 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 217 | void VSyncDispatchTimerQueueEntry::ensureNotRunning() { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 218 | std::unique_lock<std::mutex> lk(mRunningMutex); |
| 219 | mCv.wait(lk, [this]() REQUIRES(mRunningMutex) { return !mRunning; }); |
| 220 | } |
| 221 | |
Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 222 | void VSyncDispatchTimerQueueEntry::dump(std::string& result) const { |
| 223 | std::lock_guard<std::mutex> lk(mRunningMutex); |
| 224 | std::string armedInfo; |
| 225 | if (mArmedInfo) { |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 226 | StringAppendF(&armedInfo, |
| 227 | "[wake up in %.2fms deadline in %.2fms for vsync %.2fms from now]", |
Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 228 | (mArmedInfo->mActualWakeupTime - systemTime()) / 1e6f, |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 229 | (mArmedInfo->mActualReadyTime - systemTime()) / 1e6f, |
Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 230 | (mArmedInfo->mActualVsyncTime - systemTime()) / 1e6f); |
| 231 | } |
| 232 | |
| 233 | StringAppendF(&result, "\t\t%s: %s %s\n", mName.c_str(), |
| 234 | mRunning ? "(in callback function)" : "", armedInfo.c_str()); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 235 | StringAppendF(&result, |
Ady Abraham | 4335afd | 2023-12-18 19:10:47 -0800 | [diff] [blame] | 236 | "\t\t\tworkDuration: %.2fms readyDuration: %.2fms lastVsync: %.2fms relative " |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 237 | "to now\n", |
| 238 | mScheduleTiming.workDuration / 1e6f, mScheduleTiming.readyDuration / 1e6f, |
Ady Abraham | 4335afd | 2023-12-18 19:10:47 -0800 | [diff] [blame] | 239 | (mScheduleTiming.lastVsync - systemTime()) / 1e6f); |
Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 240 | |
| 241 | if (mLastDispatchTime) { |
| 242 | StringAppendF(&result, "\t\t\tmLastDispatchTime: %.2fms ago\n", |
| 243 | (systemTime() - *mLastDispatchTime) / 1e6f); |
| 244 | } else { |
| 245 | StringAppendF(&result, "\t\t\tmLastDispatchTime unknown\n"); |
| 246 | } |
| 247 | } |
| 248 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 249 | VSyncDispatchTimerQueue::VSyncDispatchTimerQueue(std::unique_ptr<TimeKeeper> tk, |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 250 | VsyncSchedule::TrackerPtr tracker, |
| 251 | nsecs_t timerSlack, nsecs_t minVsyncDistance) |
Kevin DuBois | c94ca83 | 2019-11-26 12:56:24 -0800 | [diff] [blame] | 252 | : mTimeKeeper(std::move(tk)), |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 253 | mTracker(std::move(tracker)), |
Kevin DuBois | c94ca83 | 2019-11-26 12:56:24 -0800 | [diff] [blame] | 254 | mTimerSlack(timerSlack), |
| 255 | mMinVsyncDistance(minVsyncDistance) {} |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 256 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 257 | VSyncDispatchTimerQueue::~VSyncDispatchTimerQueue() { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 258 | std::lock_guard lock(mMutex); |
en.liu | 07e0e29 | 2023-07-05 19:01:52 +0800 | [diff] [blame] | 259 | mRunning = false; |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 260 | cancelTimer(); |
Leon Scroggins III | 0773813 | 2023-04-24 11:43:53 -0400 | [diff] [blame] | 261 | for (auto& [_, entry] : mCallbacks) { |
| 262 | ALOGE("Forgot to unregister a callback on VSyncDispatch!"); |
| 263 | entry->ensureNotRunning(); |
| 264 | } |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 267 | void VSyncDispatchTimerQueue::cancelTimer() { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 268 | mIntendedWakeupTime = kInvalidTime; |
| 269 | mTimeKeeper->alarmCancel(); |
| 270 | } |
| 271 | |
Ady Abraham | b491c90 | 2020-08-15 15:47:56 -0700 | [diff] [blame] | 272 | void VSyncDispatchTimerQueue::setTimer(nsecs_t targetTime, nsecs_t /*now*/) { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 273 | mIntendedWakeupTime = targetTime; |
Ady Abraham | b491c90 | 2020-08-15 15:47:56 -0700 | [diff] [blame] | 274 | mTimeKeeper->alarmAt(std::bind(&VSyncDispatchTimerQueue::timerCallback, this), |
| 275 | mIntendedWakeupTime); |
Ady Abraham | 7539872 | 2020-04-07 14:08:45 -0700 | [diff] [blame] | 276 | mLastTimerSchedule = mTimeKeeper->now(); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 279 | void VSyncDispatchTimerQueue::rearmTimer(nsecs_t now) { |
Dominik Laskowski | 0f3e5b9 | 2023-11-17 18:03:41 -0500 | [diff] [blame] | 280 | rearmTimerSkippingUpdateFor(now, mCallbacks.cend()); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 283 | void VSyncDispatchTimerQueue::rearmTimerSkippingUpdateFor( |
Dominik Laskowski | 0f3e5b9 | 2023-11-17 18:03:41 -0500 | [diff] [blame] | 284 | nsecs_t now, CallbackMap::const_iterator skipUpdateIt) { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 285 | std::optional<nsecs_t> min; |
Kevin DuBois | ecb1f0d | 2019-12-12 10:47:41 -0800 | [diff] [blame] | 286 | std::optional<nsecs_t> targetVsync; |
| 287 | std::optional<std::string_view> nextWakeupName; |
Dominik Laskowski | 0f3e5b9 | 2023-11-17 18:03:41 -0500 | [diff] [blame] | 288 | for (auto it = mCallbacks.cbegin(); it != mCallbacks.cend(); ++it) { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 289 | auto& callback = it->second; |
Kevin DuBois | 5c18c1c | 2020-05-27 15:50:50 -0700 | [diff] [blame] | 290 | if (!callback->wakeupTime() && !callback->hasPendingWorkloadUpdate()) { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 291 | continue; |
| 292 | } |
| 293 | |
| 294 | if (it != skipUpdateIt) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 295 | callback->update(*mTracker, now); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 296 | } |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame^] | 297 | auto const wakeupTime = *callback->wakeupTime(); |
Dominik Laskowski | 62eff35 | 2021-12-06 09:59:41 -0800 | [diff] [blame] | 298 | if (!min || *min > wakeupTime) { |
Kevin DuBois | ecb1f0d | 2019-12-12 10:47:41 -0800 | [diff] [blame] | 299 | nextWakeupName = callback->name(); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 300 | min = wakeupTime; |
Kevin DuBois | ecb1f0d | 2019-12-12 10:47:41 -0800 | [diff] [blame] | 301 | targetVsync = callback->targetVsync(); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
Dominik Laskowski | 62eff35 | 2021-12-06 09:59:41 -0800 | [diff] [blame] | 305 | if (min && min < mIntendedWakeupTime) { |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame^] | 306 | if (ATRACE_ENABLED() && nextWakeupName && targetVsync) { |
| 307 | ftl::Concat trace(ftl::truncated<5>(*nextWakeupName), " alarm in ", ns2us(*min - now), |
| 308 | "us; VSYNC in ", ns2us(*targetVsync - now), "us"); |
| 309 | ATRACE_NAME(trace.c_str()); |
| 310 | } |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 311 | setTimer(*min, now); |
| 312 | } else { |
Kevin DuBois | ecb1f0d | 2019-12-12 10:47:41 -0800 | [diff] [blame] | 313 | ATRACE_NAME("cancel timer"); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 314 | cancelTimer(); |
| 315 | } |
| 316 | } |
| 317 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 318 | void VSyncDispatchTimerQueue::timerCallback() { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 319 | struct Invocation { |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 320 | std::shared_ptr<VSyncDispatchTimerQueueEntry> callback; |
Kevin DuBois | 2968afc | 2020-01-14 09:48:50 -0800 | [diff] [blame] | 321 | nsecs_t vsyncTimestamp; |
| 322 | nsecs_t wakeupTimestamp; |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 323 | nsecs_t deadlineTimestamp; |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 324 | }; |
| 325 | std::vector<Invocation> invocations; |
| 326 | { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 327 | std::lock_guard lock(mMutex); |
en.liu | 07e0e29 | 2023-07-05 19:01:52 +0800 | [diff] [blame] | 328 | if (!mRunning) { |
| 329 | ALOGD("TimerQueue is not running. Skipping callback."); |
| 330 | return; |
| 331 | } |
Kevin DuBois | f947783 | 2020-07-16 10:21:36 -0700 | [diff] [blame] | 332 | auto const now = mTimeKeeper->now(); |
| 333 | mLastTimerCallback = now; |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 334 | for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++) { |
| 335 | auto& callback = it->second; |
| 336 | auto const wakeupTime = callback->wakeupTime(); |
| 337 | if (!wakeupTime) { |
| 338 | continue; |
| 339 | } |
| 340 | |
Ady Abraham | b6c7f88 | 2024-01-29 14:43:29 -0800 | [diff] [blame] | 341 | auto const readyTime = callback->readyTime(); |
Ady Abraham | 9633f8e | 2024-03-04 19:38:12 +0000 | [diff] [blame^] | 342 | |
Kevin DuBois | f947783 | 2020-07-16 10:21:36 -0700 | [diff] [blame] | 343 | auto const lagAllowance = std::max(now - mIntendedWakeupTime, static_cast<nsecs_t>(0)); |
| 344 | if (*wakeupTime < mIntendedWakeupTime + mTimerSlack + lagAllowance) { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 345 | callback->executing(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 346 | invocations.emplace_back(Invocation{callback, *callback->lastExecutedVsyncTarget(), |
| 347 | *wakeupTime, *readyTime}); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
| 351 | mIntendedWakeupTime = kInvalidTime; |
| 352 | rearmTimer(mTimeKeeper->now()); |
| 353 | } |
| 354 | |
| 355 | for (auto const& invocation : invocations) { |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 356 | invocation.callback->callback(invocation.vsyncTimestamp, invocation.wakeupTimestamp, |
| 357 | invocation.deadlineTimestamp); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 361 | VSyncDispatchTimerQueue::CallbackToken VSyncDispatchTimerQueue::registerCallback( |
Dominik Laskowski | 4e0d20d | 2021-12-06 11:31:02 -0800 | [diff] [blame] | 362 | Callback callback, std::string callbackName) { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 363 | std::lock_guard lock(mMutex); |
Dominik Laskowski | 0f3e5b9 | 2023-11-17 18:03:41 -0500 | [diff] [blame] | 364 | return mCallbacks |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 365 | .try_emplace(++mCallbackToken, |
Dominik Laskowski | 0f3e5b9 | 2023-11-17 18:03:41 -0500 | [diff] [blame] | 366 | std::make_shared<VSyncDispatchTimerQueueEntry>(std::move(callbackName), |
| 367 | std::move(callback), |
| 368 | mMinVsyncDistance)) |
| 369 | .first->first; |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 372 | void VSyncDispatchTimerQueue::unregisterCallback(CallbackToken token) { |
| 373 | std::shared_ptr<VSyncDispatchTimerQueueEntry> entry = nullptr; |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 374 | { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 375 | std::lock_guard lock(mMutex); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 376 | auto it = mCallbacks.find(token); |
| 377 | if (it != mCallbacks.end()) { |
| 378 | entry = it->second; |
Dominik Laskowski | 0f3e5b9 | 2023-11-17 18:03:41 -0500 | [diff] [blame] | 379 | mCallbacks.erase(it->first); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
| 383 | if (entry) { |
| 384 | entry->ensureNotRunning(); |
| 385 | } |
| 386 | } |
| 387 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 388 | std::optional<ScheduleResult> VSyncDispatchTimerQueue::schedule(CallbackToken token, |
| 389 | ScheduleTiming scheduleTiming) { |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 390 | std::lock_guard lock(mMutex); |
| 391 | return scheduleLocked(token, scheduleTiming); |
| 392 | } |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 393 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 394 | std::optional<ScheduleResult> VSyncDispatchTimerQueue::scheduleLocked( |
| 395 | CallbackToken token, ScheduleTiming scheduleTiming) { |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 396 | auto it = mCallbacks.find(token); |
| 397 | if (it == mCallbacks.end()) { |
| 398 | return {}; |
| 399 | } |
| 400 | auto& callback = it->second; |
| 401 | auto const now = mTimeKeeper->now(); |
Kevin DuBois | 5c18c1c | 2020-05-27 15:50:50 -0700 | [diff] [blame] | 402 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 403 | /* If the timer thread will run soon, we'll apply this work update via the callback |
| 404 | * timer recalculation to avoid cancelling a callback that is about to fire. */ |
| 405 | auto const rearmImminent = now > mIntendedWakeupTime; |
| 406 | if (CC_UNLIKELY(rearmImminent)) { |
Ady Abraham | da8af4c | 2024-02-14 00:24:34 +0000 | [diff] [blame] | 407 | return callback->addPendingWorkloadUpdate(*mTracker, now, scheduleTiming); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 408 | } |
Kevin DuBois | 5c18c1c | 2020-05-27 15:50:50 -0700 | [diff] [blame] | 409 | |
ramindani | 558f4a9 | 2024-02-16 15:49:23 -0800 | [diff] [blame] | 410 | const auto result = callback->schedule(scheduleTiming, *mTracker, now); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 411 | |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 412 | if (callback->wakeupTime() < mIntendedWakeupTime - mTimerSlack) { |
| 413 | rearmTimerSkippingUpdateFor(now, it); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 414 | } |
| 415 | |
ramindani | 558f4a9 | 2024-02-16 15:49:23 -0800 | [diff] [blame] | 416 | return result; |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 417 | } |
| 418 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 419 | std::optional<ScheduleResult> VSyncDispatchTimerQueue::update(CallbackToken token, |
| 420 | ScheduleTiming scheduleTiming) { |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 421 | std::lock_guard lock(mMutex); |
| 422 | const auto it = mCallbacks.find(token); |
| 423 | if (it == mCallbacks.end()) { |
| 424 | return {}; |
| 425 | } |
| 426 | |
| 427 | auto& callback = it->second; |
| 428 | if (!callback->targetVsync().has_value()) { |
| 429 | return {}; |
| 430 | } |
| 431 | |
| 432 | return scheduleLocked(token, scheduleTiming); |
| 433 | } |
| 434 | |
Kevin DuBois | e4f27a8 | 2019-11-12 11:41:41 -0800 | [diff] [blame] | 435 | CancelResult VSyncDispatchTimerQueue::cancel(CallbackToken token) { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 436 | std::lock_guard lock(mMutex); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 437 | |
| 438 | auto it = mCallbacks.find(token); |
| 439 | if (it == mCallbacks.end()) { |
| 440 | return CancelResult::Error; |
| 441 | } |
| 442 | auto& callback = it->second; |
| 443 | |
Kevin DuBois | b340b73 | 2020-06-16 09:07:35 -0700 | [diff] [blame] | 444 | auto const wakeupTime = callback->wakeupTime(); |
| 445 | if (wakeupTime) { |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 446 | callback->disarm(); |
Kevin DuBois | b340b73 | 2020-06-16 09:07:35 -0700 | [diff] [blame] | 447 | |
| 448 | if (*wakeupTime == mIntendedWakeupTime) { |
| 449 | mIntendedWakeupTime = kInvalidTime; |
| 450 | rearmTimer(mTimeKeeper->now()); |
| 451 | } |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 452 | return CancelResult::Cancelled; |
| 453 | } |
| 454 | return CancelResult::TooLate; |
| 455 | } |
| 456 | |
Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 457 | void VSyncDispatchTimerQueue::dump(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 458 | std::lock_guard lock(mMutex); |
Ady Abraham | 7539872 | 2020-04-07 14:08:45 -0700 | [diff] [blame] | 459 | StringAppendF(&result, "\tTimer:\n"); |
| 460 | mTimeKeeper->dump(result); |
Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 461 | StringAppendF(&result, "\tmTimerSlack: %.2fms mMinVsyncDistance: %.2fms\n", mTimerSlack / 1e6f, |
| 462 | mMinVsyncDistance / 1e6f); |
| 463 | StringAppendF(&result, "\tmIntendedWakeupTime: %.2fms from now\n", |
Ady Abraham | 7539872 | 2020-04-07 14:08:45 -0700 | [diff] [blame] | 464 | (mIntendedWakeupTime - mTimeKeeper->now()) / 1e6f); |
| 465 | StringAppendF(&result, "\tmLastTimerCallback: %.2fms ago mLastTimerSchedule: %.2fms ago\n", |
| 466 | (mTimeKeeper->now() - mLastTimerCallback) / 1e6f, |
| 467 | (mTimeKeeper->now() - mLastTimerSchedule) / 1e6f); |
Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 468 | StringAppendF(&result, "\tCallbacks:\n"); |
| 469 | for (const auto& [token, entry] : mCallbacks) { |
| 470 | entry->dump(result); |
| 471 | } |
| 472 | } |
| 473 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 474 | VSyncCallbackRegistration::VSyncCallbackRegistration(std::shared_ptr<VSyncDispatch> dispatch, |
Dominik Laskowski | 4e0d20d | 2021-12-06 11:31:02 -0800 | [diff] [blame] | 475 | VSyncDispatch::Callback callback, |
| 476 | std::string callbackName) |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 477 | : mDispatch(std::move(dispatch)), |
Leon Scroggins III | 6c440ae | 2023-04-21 15:01:03 -0400 | [diff] [blame] | 478 | mToken(mDispatch->registerCallback(std::move(callback), std::move(callbackName))) {} |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 479 | |
| 480 | VSyncCallbackRegistration::VSyncCallbackRegistration(VSyncCallbackRegistration&& other) |
Leon Scroggins III | 6c440ae | 2023-04-21 15:01:03 -0400 | [diff] [blame] | 481 | : mDispatch(std::move(other.mDispatch)), mToken(std::exchange(other.mToken, std::nullopt)) {} |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 482 | |
| 483 | VSyncCallbackRegistration& VSyncCallbackRegistration::operator=(VSyncCallbackRegistration&& other) { |
Leon Scroggins III | 6c440ae | 2023-04-21 15:01:03 -0400 | [diff] [blame] | 484 | if (this == &other) return *this; |
| 485 | if (mToken) { |
| 486 | mDispatch->unregisterCallback(*mToken); |
| 487 | } |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 488 | mDispatch = std::move(other.mDispatch); |
Leon Scroggins III | 6c440ae | 2023-04-21 15:01:03 -0400 | [diff] [blame] | 489 | mToken = std::exchange(other.mToken, std::nullopt); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 490 | return *this; |
| 491 | } |
| 492 | |
| 493 | VSyncCallbackRegistration::~VSyncCallbackRegistration() { |
Leon Scroggins III | 6c440ae | 2023-04-21 15:01:03 -0400 | [diff] [blame] | 494 | if (mToken) mDispatch->unregisterCallback(*mToken); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 495 | } |
| 496 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 497 | std::optional<ScheduleResult> VSyncCallbackRegistration::schedule( |
| 498 | VSyncDispatch::ScheduleTiming scheduleTiming) { |
Leon Scroggins III | 6c440ae | 2023-04-21 15:01:03 -0400 | [diff] [blame] | 499 | if (!mToken) { |
Ady Abraham | b5d3afa | 2021-05-07 11:22:23 -0700 | [diff] [blame] | 500 | return std::nullopt; |
Kevin DuBois | c94ca83 | 2019-11-26 12:56:24 -0800 | [diff] [blame] | 501 | } |
Leon Scroggins III | 6c440ae | 2023-04-21 15:01:03 -0400 | [diff] [blame] | 502 | return mDispatch->schedule(*mToken, scheduleTiming); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 503 | } |
| 504 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 505 | std::optional<ScheduleResult> VSyncCallbackRegistration::update( |
| 506 | VSyncDispatch::ScheduleTiming scheduleTiming) { |
Leon Scroggins III | 6c440ae | 2023-04-21 15:01:03 -0400 | [diff] [blame] | 507 | if (!mToken) { |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 508 | return std::nullopt; |
| 509 | } |
Leon Scroggins III | 6c440ae | 2023-04-21 15:01:03 -0400 | [diff] [blame] | 510 | return mDispatch->update(*mToken, scheduleTiming); |
Ady Abraham | 011f8ba | 2022-11-22 15:09:07 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 513 | CancelResult VSyncCallbackRegistration::cancel() { |
Leon Scroggins III | 6c440ae | 2023-04-21 15:01:03 -0400 | [diff] [blame] | 514 | if (!mToken) { |
Kevin DuBois | c94ca83 | 2019-11-26 12:56:24 -0800 | [diff] [blame] | 515 | return CancelResult::Error; |
| 516 | } |
Leon Scroggins III | 6c440ae | 2023-04-21 15:01:03 -0400 | [diff] [blame] | 517 | return mDispatch->cancel(*mToken); |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | } // namespace android::scheduler |