Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 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 LOG_NDEBUG 0 |
Ady Abraham | e08a092 | 2023-02-16 18:07:41 +0000 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 19 | |
Rachel Lee | 273c18c | 2022-12-13 14:35:07 -0800 | [diff] [blame] | 20 | #include <gui/Choreographer.h> |
Ady Abraham | e08a092 | 2023-02-16 18:07:41 +0000 | [diff] [blame] | 21 | #include <gui/TraceUtils.h> |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 22 | #include <jni.h> |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 23 | |
| 24 | #undef LOG_TAG |
| 25 | #define LOG_TAG "AChoreographer" |
| 26 | |
| 27 | namespace { |
| 28 | struct { |
| 29 | // Global JVM that is provided by zygote |
| 30 | JavaVM* jvm = nullptr; |
| 31 | struct { |
| 32 | jclass clazz; |
| 33 | jmethodID getInstance; |
| 34 | jmethodID registerNativeChoreographerForRefreshRateCallbacks; |
| 35 | jmethodID unregisterNativeChoreographerForRefreshRateCallbacks; |
| 36 | } displayManagerGlobal; |
| 37 | } gJni; |
| 38 | |
| 39 | // Gets the JNIEnv* for this thread, and performs one-off initialization if we |
| 40 | // have never retrieved a JNIEnv* pointer before. |
| 41 | JNIEnv* getJniEnv() { |
| 42 | if (gJni.jvm == nullptr) { |
| 43 | ALOGW("AChoreographer: No JVM provided!"); |
| 44 | return nullptr; |
| 45 | } |
| 46 | |
| 47 | JNIEnv* env = nullptr; |
| 48 | if (gJni.jvm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) { |
| 49 | ALOGD("Attaching thread to JVM for AChoreographer"); |
| 50 | JavaVMAttachArgs args = {JNI_VERSION_1_4, "AChoreographer_env", NULL}; |
| 51 | jint attachResult = gJni.jvm->AttachCurrentThreadAsDaemon(&env, (void*)&args); |
| 52 | if (attachResult != JNI_OK) { |
| 53 | ALOGE("Unable to attach thread. Error: %d", attachResult); |
| 54 | return nullptr; |
| 55 | } |
| 56 | } |
| 57 | if (env == nullptr) { |
| 58 | ALOGW("AChoreographer: No JNI env available!"); |
| 59 | } |
| 60 | return env; |
| 61 | } |
| 62 | |
| 63 | inline const char* toString(bool value) { |
| 64 | return value ? "true" : "false"; |
| 65 | } |
| 66 | } // namespace |
| 67 | |
| 68 | namespace android { |
| 69 | |
| 70 | Choreographer::Context Choreographer::gChoreographers; |
| 71 | |
| 72 | static thread_local Choreographer* gChoreographer; |
| 73 | |
| 74 | void Choreographer::initJVM(JNIEnv* env) { |
| 75 | env->GetJavaVM(&gJni.jvm); |
| 76 | // Now we need to find the java classes. |
| 77 | jclass dmgClass = env->FindClass("android/hardware/display/DisplayManagerGlobal"); |
| 78 | gJni.displayManagerGlobal.clazz = static_cast<jclass>(env->NewGlobalRef(dmgClass)); |
| 79 | gJni.displayManagerGlobal.getInstance = |
| 80 | env->GetStaticMethodID(dmgClass, "getInstance", |
| 81 | "()Landroid/hardware/display/DisplayManagerGlobal;"); |
| 82 | gJni.displayManagerGlobal.registerNativeChoreographerForRefreshRateCallbacks = |
| 83 | env->GetMethodID(dmgClass, "registerNativeChoreographerForRefreshRateCallbacks", "()V"); |
| 84 | gJni.displayManagerGlobal.unregisterNativeChoreographerForRefreshRateCallbacks = |
| 85 | env->GetMethodID(dmgClass, "unregisterNativeChoreographerForRefreshRateCallbacks", |
| 86 | "()V"); |
| 87 | } |
| 88 | |
| 89 | Choreographer* Choreographer::getForThread() { |
| 90 | if (gChoreographer == nullptr) { |
| 91 | sp<Looper> looper = Looper::getForThread(); |
| 92 | if (!looper.get()) { |
| 93 | ALOGW("No looper prepared for thread"); |
| 94 | return nullptr; |
| 95 | } |
| 96 | gChoreographer = new Choreographer(looper); |
| 97 | status_t result = gChoreographer->initialize(); |
| 98 | if (result != OK) { |
| 99 | ALOGW("Failed to initialize"); |
| 100 | return nullptr; |
| 101 | } |
| 102 | } |
| 103 | return gChoreographer; |
| 104 | } |
| 105 | |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 106 | Choreographer::Choreographer(const sp<Looper>& looper, const sp<IBinder>& layerHandle) |
| 107 | : DisplayEventDispatcher(looper, gui::ISurfaceComposer::VsyncSource::eVsyncSourceApp, {}, |
| 108 | layerHandle), |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 109 | mLooper(looper), |
| 110 | mThreadId(std::this_thread::get_id()) { |
| 111 | std::lock_guard<std::mutex> _l(gChoreographers.lock); |
| 112 | gChoreographers.ptrs.push_back(this); |
| 113 | } |
| 114 | |
| 115 | Choreographer::~Choreographer() { |
| 116 | std::lock_guard<std::mutex> _l(gChoreographers.lock); |
| 117 | gChoreographers.ptrs.erase(std::remove_if(gChoreographers.ptrs.begin(), |
| 118 | gChoreographers.ptrs.end(), |
Elliott Hughes | 0800465 | 2024-01-30 11:18:51 -0800 | [diff] [blame] | 119 | [=, this](Choreographer* c) { return c == this; }), |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 120 | gChoreographers.ptrs.end()); |
| 121 | // Only poke DisplayManagerGlobal to unregister if we previously registered |
| 122 | // callbacks. |
| 123 | if (gChoreographers.ptrs.empty() && gChoreographers.registeredToDisplayManager) { |
| 124 | gChoreographers.registeredToDisplayManager = false; |
| 125 | JNIEnv* env = getJniEnv(); |
| 126 | if (env == nullptr) { |
| 127 | ALOGW("JNI environment is unavailable, skipping choreographer cleanup"); |
| 128 | return; |
| 129 | } |
| 130 | jobject dmg = env->CallStaticObjectMethod(gJni.displayManagerGlobal.clazz, |
| 131 | gJni.displayManagerGlobal.getInstance); |
| 132 | if (dmg == nullptr) { |
| 133 | ALOGW("DMS is not initialized yet, skipping choreographer cleanup"); |
| 134 | } else { |
| 135 | env->CallVoidMethod(dmg, |
| 136 | gJni.displayManagerGlobal |
| 137 | .unregisterNativeChoreographerForRefreshRateCallbacks); |
| 138 | env->DeleteLocalRef(dmg); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | void Choreographer::postFrameCallbackDelayed(AChoreographer_frameCallback cb, |
| 144 | AChoreographer_frameCallback64 cb64, |
| 145 | AChoreographer_vsyncCallback vsyncCallback, void* data, |
Chavi Weingarten | 475c413 | 2024-02-29 15:56:15 +0000 | [diff] [blame] | 146 | nsecs_t delay, CallbackType callbackType) { |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 147 | nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); |
Chavi Weingarten | 475c413 | 2024-02-29 15:56:15 +0000 | [diff] [blame] | 148 | FrameCallback callback{cb, cb64, vsyncCallback, data, now + delay, callbackType}; |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 149 | { |
| 150 | std::lock_guard<std::mutex> _l{mLock}; |
| 151 | mFrameCallbacks.push(callback); |
| 152 | } |
| 153 | if (callback.dueTime <= now) { |
| 154 | if (std::this_thread::get_id() != mThreadId) { |
| 155 | if (mLooper != nullptr) { |
| 156 | Message m{MSG_SCHEDULE_VSYNC}; |
| 157 | mLooper->sendMessage(this, m); |
| 158 | } else { |
| 159 | scheduleVsync(); |
| 160 | } |
| 161 | } else { |
| 162 | scheduleVsync(); |
| 163 | } |
| 164 | } else { |
| 165 | if (mLooper != nullptr) { |
| 166 | Message m{MSG_SCHEDULE_CALLBACKS}; |
| 167 | mLooper->sendMessageDelayed(delay, this, m); |
| 168 | } else { |
| 169 | scheduleCallbacks(); |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void Choreographer::registerRefreshRateCallback(AChoreographer_refreshRateCallback cb, void* data) { |
| 175 | std::lock_guard<std::mutex> _l{mLock}; |
| 176 | for (const auto& callback : mRefreshRateCallbacks) { |
| 177 | // Don't re-add callbacks. |
| 178 | if (cb == callback.callback && data == callback.data) { |
| 179 | return; |
| 180 | } |
| 181 | } |
| 182 | mRefreshRateCallbacks.emplace_back( |
| 183 | RefreshRateCallback{.callback = cb, .data = data, .firstCallbackFired = false}); |
| 184 | bool needsRegistration = false; |
| 185 | { |
| 186 | std::lock_guard<std::mutex> _l2(gChoreographers.lock); |
| 187 | needsRegistration = !gChoreographers.registeredToDisplayManager; |
| 188 | } |
| 189 | if (needsRegistration) { |
| 190 | JNIEnv* env = getJniEnv(); |
| 191 | if (env == nullptr) { |
| 192 | ALOGW("JNI environment is unavailable, skipping registration"); |
| 193 | return; |
| 194 | } |
| 195 | jobject dmg = env->CallStaticObjectMethod(gJni.displayManagerGlobal.clazz, |
| 196 | gJni.displayManagerGlobal.getInstance); |
| 197 | if (dmg == nullptr) { |
| 198 | ALOGW("DMS is not initialized yet: skipping registration"); |
| 199 | return; |
| 200 | } else { |
| 201 | env->CallVoidMethod(dmg, |
| 202 | gJni.displayManagerGlobal |
| 203 | .registerNativeChoreographerForRefreshRateCallbacks, |
| 204 | reinterpret_cast<int64_t>(this)); |
| 205 | env->DeleteLocalRef(dmg); |
| 206 | { |
| 207 | std::lock_guard<std::mutex> _l2(gChoreographers.lock); |
| 208 | gChoreographers.registeredToDisplayManager = true; |
| 209 | } |
| 210 | } |
| 211 | } else { |
| 212 | scheduleLatestConfigRequest(); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | void Choreographer::unregisterRefreshRateCallback(AChoreographer_refreshRateCallback cb, |
| 217 | void* data) { |
| 218 | std::lock_guard<std::mutex> _l{mLock}; |
| 219 | mRefreshRateCallbacks.erase(std::remove_if(mRefreshRateCallbacks.begin(), |
| 220 | mRefreshRateCallbacks.end(), |
| 221 | [&](const RefreshRateCallback& callback) { |
| 222 | return cb == callback.callback && |
| 223 | data == callback.data; |
| 224 | }), |
| 225 | mRefreshRateCallbacks.end()); |
| 226 | } |
| 227 | |
| 228 | void Choreographer::scheduleLatestConfigRequest() { |
| 229 | if (mLooper != nullptr) { |
| 230 | Message m{MSG_HANDLE_REFRESH_RATE_UPDATES}; |
| 231 | mLooper->sendMessage(this, m); |
| 232 | } else { |
| 233 | // If the looper thread is detached from Choreographer, then refresh rate |
| 234 | // changes will be handled in AChoreographer_handlePendingEvents, so we |
| 235 | // need to wake up the looper thread by writing to the write-end of the |
| 236 | // socket the looper is listening on. |
| 237 | // Fortunately, these events are small so sending packets across the |
| 238 | // socket should be atomic across processes. |
| 239 | DisplayEventReceiver::Event event; |
| 240 | event.header = |
| 241 | DisplayEventReceiver::Event::Header{DisplayEventReceiver::DISPLAY_EVENT_NULL, |
| 242 | PhysicalDisplayId::fromPort(0), systemTime()}; |
| 243 | injectEvent(event); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | void Choreographer::scheduleCallbacks() { |
| 248 | const nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); |
| 249 | nsecs_t dueTime; |
| 250 | { |
| 251 | std::lock_guard<std::mutex> _l{mLock}; |
| 252 | // If there are no pending callbacks then don't schedule a vsync |
| 253 | if (mFrameCallbacks.empty()) { |
| 254 | return; |
| 255 | } |
| 256 | dueTime = mFrameCallbacks.top().dueTime; |
| 257 | } |
| 258 | |
| 259 | if (dueTime <= now) { |
| 260 | ALOGV("choreographer %p ~ scheduling vsync", this); |
| 261 | scheduleVsync(); |
| 262 | return; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | void Choreographer::handleRefreshRateUpdates() { |
| 267 | std::vector<RefreshRateCallback> callbacks{}; |
| 268 | const nsecs_t pendingPeriod = gChoreographers.mLastKnownVsync.load(); |
| 269 | const nsecs_t lastPeriod = mLatestVsyncPeriod; |
| 270 | if (pendingPeriod > 0) { |
| 271 | mLatestVsyncPeriod = pendingPeriod; |
| 272 | } |
| 273 | { |
| 274 | std::lock_guard<std::mutex> _l{mLock}; |
| 275 | for (auto& cb : mRefreshRateCallbacks) { |
| 276 | callbacks.push_back(cb); |
| 277 | cb.firstCallbackFired = true; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | for (auto& cb : callbacks) { |
| 282 | if (!cb.firstCallbackFired || (pendingPeriod > 0 && pendingPeriod != lastPeriod)) { |
| 283 | cb.callback(pendingPeriod, cb.data); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
Chavi Weingarten | 475c413 | 2024-02-29 15:56:15 +0000 | [diff] [blame] | 288 | void Choreographer::dispatchCallbacks(const std::vector<FrameCallback>& callbacks, |
| 289 | VsyncEventData vsyncEventData, nsecs_t timestamp) { |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 290 | for (const auto& cb : callbacks) { |
| 291 | if (cb.vsyncCallback != nullptr) { |
Ady Abraham | e08a092 | 2023-02-16 18:07:41 +0000 | [diff] [blame] | 292 | ATRACE_FORMAT("AChoreographer_vsyncCallback %" PRId64, |
| 293 | vsyncEventData.preferredVsyncId()); |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 294 | const ChoreographerFrameCallbackDataImpl frameCallbackData = |
| 295 | createFrameCallbackData(timestamp); |
| 296 | registerStartTime(); |
| 297 | mInCallback = true; |
| 298 | cb.vsyncCallback(reinterpret_cast<const AChoreographerFrameCallbackData*>( |
| 299 | &frameCallbackData), |
| 300 | cb.data); |
| 301 | mInCallback = false; |
| 302 | } else if (cb.callback64 != nullptr) { |
Ady Abraham | e08a092 | 2023-02-16 18:07:41 +0000 | [diff] [blame] | 303 | ATRACE_FORMAT("AChoreographer_frameCallback64"); |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 304 | cb.callback64(timestamp, cb.data); |
| 305 | } else if (cb.callback != nullptr) { |
Ady Abraham | e08a092 | 2023-02-16 18:07:41 +0000 | [diff] [blame] | 306 | ATRACE_FORMAT("AChoreographer_frameCallback"); |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 307 | cb.callback(timestamp, cb.data); |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
Chavi Weingarten | 475c413 | 2024-02-29 15:56:15 +0000 | [diff] [blame] | 312 | void Choreographer::dispatchVsync(nsecs_t timestamp, PhysicalDisplayId, uint32_t, |
| 313 | VsyncEventData vsyncEventData) { |
| 314 | std::vector<FrameCallback> animationCallbacks{}; |
| 315 | std::vector<FrameCallback> inputCallbacks{}; |
| 316 | { |
| 317 | std::lock_guard<std::mutex> _l{mLock}; |
| 318 | nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); |
| 319 | while (!mFrameCallbacks.empty() && mFrameCallbacks.top().dueTime < now) { |
| 320 | if (mFrameCallbacks.top().callbackType == CALLBACK_INPUT) { |
| 321 | inputCallbacks.push_back(mFrameCallbacks.top()); |
| 322 | } else { |
| 323 | animationCallbacks.push_back(mFrameCallbacks.top()); |
| 324 | } |
| 325 | mFrameCallbacks.pop(); |
| 326 | } |
| 327 | } |
| 328 | mLastVsyncEventData = vsyncEventData; |
| 329 | // Callbacks with type CALLBACK_INPUT should always run first |
| 330 | { |
| 331 | ATRACE_FORMAT("CALLBACK_INPUT"); |
| 332 | dispatchCallbacks(inputCallbacks, vsyncEventData, timestamp); |
| 333 | } |
| 334 | { |
| 335 | ATRACE_FORMAT("CALLBACK_ANIMATION"); |
| 336 | dispatchCallbacks(animationCallbacks, vsyncEventData, timestamp); |
| 337 | } |
| 338 | } |
| 339 | |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 340 | void Choreographer::dispatchHotplug(nsecs_t, PhysicalDisplayId displayId, bool connected) { |
| 341 | ALOGV("choreographer %p ~ received hotplug event (displayId=%s, connected=%s), ignoring.", this, |
| 342 | to_string(displayId).c_str(), toString(connected)); |
| 343 | } |
| 344 | |
Brian Johnson | 5dcd75d | 2023-08-15 09:36:37 -0700 | [diff] [blame] | 345 | void Choreographer::dispatchHotplugConnectionError(nsecs_t, int32_t connectionError) { |
| 346 | ALOGV("choreographer %p ~ received hotplug connection error event (connectionError=%d), " |
| 347 | "ignoring.", |
| 348 | this, connectionError); |
| 349 | } |
| 350 | |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 351 | void Choreographer::dispatchModeChanged(nsecs_t, PhysicalDisplayId, int32_t, nsecs_t) { |
| 352 | LOG_ALWAYS_FATAL("dispatchModeChanged was called but was never registered"); |
| 353 | } |
| 354 | |
| 355 | void Choreographer::dispatchFrameRateOverrides(nsecs_t, PhysicalDisplayId, |
| 356 | std::vector<FrameRateOverride>) { |
| 357 | LOG_ALWAYS_FATAL("dispatchFrameRateOverrides was called but was never registered"); |
| 358 | } |
| 359 | |
| 360 | void Choreographer::dispatchNullEvent(nsecs_t, PhysicalDisplayId) { |
| 361 | ALOGV("choreographer %p ~ received null event.", this); |
| 362 | handleRefreshRateUpdates(); |
| 363 | } |
| 364 | |
Huihong Luo | b1c1af4 | 2023-12-29 10:46:30 -0800 | [diff] [blame] | 365 | void Choreographer::dispatchHdcpLevelsChanged(PhysicalDisplayId displayId, int32_t connectedLevel, |
| 366 | int32_t maxLevel) { |
| 367 | ALOGV("choreographer %p ~ received hdcp levels change event (displayId=%s, connectedLevel=%d, " |
| 368 | "maxLevel=%d), ignoring.", |
| 369 | this, to_string(displayId).c_str(), connectedLevel, maxLevel); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Manasi Navare | 5ef1fa1 | 2024-11-07 23:49:46 +0000 | [diff] [blame] | 372 | void Choreographer::dispatchModeRejected(PhysicalDisplayId, int32_t) { |
| 373 | LOG_ALWAYS_FATAL("dispatchModeRejected was called but was never registered"); |
| 374 | } |
| 375 | |
Rachel Lee | ace701c | 2022-10-05 10:23:47 -0700 | [diff] [blame] | 376 | void Choreographer::handleMessage(const Message& message) { |
| 377 | switch (message.what) { |
| 378 | case MSG_SCHEDULE_CALLBACKS: |
| 379 | scheduleCallbacks(); |
| 380 | break; |
| 381 | case MSG_SCHEDULE_VSYNC: |
| 382 | scheduleVsync(); |
| 383 | break; |
| 384 | case MSG_HANDLE_REFRESH_RATE_UPDATES: |
| 385 | handleRefreshRateUpdates(); |
| 386 | break; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | int64_t Choreographer::getFrameInterval() const { |
| 391 | return mLastVsyncEventData.frameInterval; |
| 392 | } |
| 393 | |
| 394 | bool Choreographer::inCallback() const { |
| 395 | return mInCallback; |
| 396 | } |
| 397 | |
| 398 | ChoreographerFrameCallbackDataImpl Choreographer::createFrameCallbackData(nsecs_t timestamp) const { |
| 399 | return {.frameTimeNanos = timestamp, |
| 400 | .vsyncEventData = mLastVsyncEventData, |
| 401 | .choreographer = this}; |
| 402 | } |
| 403 | |
| 404 | void Choreographer::registerStartTime() const { |
| 405 | std::scoped_lock _l(gChoreographers.lock); |
| 406 | for (VsyncEventData::FrameTimeline frameTimeline : mLastVsyncEventData.frameTimelines) { |
| 407 | while (gChoreographers.startTimes.size() >= kMaxStartTimes) { |
| 408 | gChoreographers.startTimes.erase(gChoreographers.startTimes.begin()); |
| 409 | } |
| 410 | gChoreographers.startTimes[frameTimeline.vsyncId] = systemTime(SYSTEM_TIME_MONOTONIC); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | void Choreographer::signalRefreshRateCallbacks(nsecs_t vsyncPeriod) { |
| 415 | std::lock_guard<std::mutex> _l(gChoreographers.lock); |
| 416 | gChoreographers.mLastKnownVsync.store(vsyncPeriod); |
| 417 | for (auto c : gChoreographers.ptrs) { |
| 418 | c->scheduleLatestConfigRequest(); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | int64_t Choreographer::getStartTimeNanosForVsyncId(AVsyncId vsyncId) { |
| 423 | std::scoped_lock _l(gChoreographers.lock); |
| 424 | const auto iter = gChoreographers.startTimes.find(vsyncId); |
| 425 | if (iter == gChoreographers.startTimes.end()) { |
| 426 | ALOGW("Start time was not found for vsync id: %" PRId64, vsyncId); |
| 427 | return 0; |
| 428 | } |
| 429 | return iter->second; |
| 430 | } |
| 431 | |
Chavi Weingarten | 9928099 | 2024-03-04 22:49:22 +0000 | [diff] [blame] | 432 | const sp<Looper> Choreographer::getLooper() { |
| 433 | return mLooper; |
| 434 | } |
| 435 | |
Brian Johnson | 5dcd75d | 2023-08-15 09:36:37 -0700 | [diff] [blame] | 436 | } // namespace android |