From 62ce65d6edbc2c34c63b0e2f2fef9cb08e28c783 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Fri, 25 Oct 2013 14:50:36 -0700 Subject: Speculatively schedule input consumption With the new tuned vsync offset, vsyncs are likely to occur shortly after the input is received, meaning we will empty the input queue, and thus won't schedule input consumption until more input is received. If an application then speculatively posts draw commands to the main looper faster than 60 hz, it will eventually end up blocking in eglSwapBuffers. Since we're blocking in eglSwapBuffers, we won't even schedule consumption until after the current frame (8-16ms), and it's entirely likely we won't actually get around to consuming input until after the next frame (another 16 ms of latency). This means we can often go 16-32ms without processing any input events, causing very noticeable amounts of jank. Rather than waiting for the next input event to schedule input consumption, speculatively schedule it every frame as long as we've consumed some motion batch during this frame. Bug: 11398045 Change-Id: I25e46308e00e9f9de00a1d8906f6b0e0f2e845b4 --- core/java/android/view/InputEventReceiver.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'core/java/android/view/InputEventReceiver.java') diff --git a/core/java/android/view/InputEventReceiver.java b/core/java/android/view/InputEventReceiver.java index f5ee7ed..25972e7 100644 --- a/core/java/android/view/InputEventReceiver.java +++ b/core/java/android/view/InputEventReceiver.java @@ -48,7 +48,7 @@ public abstract class InputEventReceiver { InputChannel inputChannel, MessageQueue messageQueue); private static native void nativeDispose(int receiverPtr); private static native void nativeFinishInputEvent(int receiverPtr, int seq, boolean handled); - private static native void nativeConsumeBatchedInputEvents(int receiverPtr, + private static native boolean nativeConsumeBatchedInputEvents(int receiverPtr, long frameTimeNanos); /** @@ -165,14 +165,17 @@ public abstract class InputEventReceiver { * * @param frameTimeNanos The time in the {@link System#nanoTime()} time base * when the current display frame started rendering, or -1 if unknown. + * + * @return Whether a batch was consumed */ - public final void consumeBatchedInputEvents(long frameTimeNanos) { + public final boolean consumeBatchedInputEvents(long frameTimeNanos) { if (mReceiverPtr == 0) { Log.w(TAG, "Attempted to consume batched input events but the input event " + "receiver has already been disposed."); } else { - nativeConsumeBatchedInputEvents(mReceiverPtr, frameTimeNanos); + return nativeConsumeBatchedInputEvents(mReceiverPtr, frameTimeNanos); } + return false; } // Called from native code. -- cgit v1.1