From 5b3c824b5d2300fa7a3373a62be1551083471f4b 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 d971a95859543..41a72786f9f0e 100644 --- a/core/java/android/view/Choreographer.java +++ b/core/java/android/view/Choreographer.java @@ -872,6 +872,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); + } + } + } } }