From 6fbe1b248b868e8403b01d19c18ee9a01e6ec7f2 Mon Sep 17 00:00:00 2001 From: MOVZX Date: Mon, 1 Dec 2025 22:14:43 +0700 Subject: [PATCH] schedule vsync immediately when requested from the Looper thread This patch allows Choreographer to schedule vsync immediately when it is requested from the Looper thread. Previously this is not allowed when vsync is already scheduled from a binder thread and hence there is a delay up to 16ms (one vsync interval) in processing frame callbacks. Change-Id: Idd70f1a6c359e92ecebd778a104b71dfa6660c79 Signed-off-by: Dohyun Lee Signed-off-by: mydongistiny Signed-off-by: MOVZX --- core/java/android/view/Choreographer.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/java/android/view/Choreographer.java b/core/java/android/view/Choreographer.java index 3a2ec91b3b207..bc85b7f21926b 100644 --- a/core/java/android/view/Choreographer.java +++ b/core/java/android/view/Choreographer.java @@ -867,6 +867,19 @@ public final class Choreographer { msg.setAsynchronous(true); mHandler.sendMessageAtTime(msg, nextFrameTime); } + } else { + if (USE_VSYNC) { + if (mHandler.hasMessages(MSG_DO_SCHEDULE_VSYNC)) { + // If running on the Looper thread, then schedule the vsync immediately. + if (isRunningOnLooperThreadLocked()) { + if (DEBUG_FRAMES) { + Log.d(TAG, "Scheduling next frame on vsync."); + } + scheduleVsyncLocked(); + mHandler.removeMessages(MSG_DO_SCHEDULE_VSYNC); + } + } + } } }