Skip to content

Commit 330314c

Browse files
author
Jeff Brown
committed
Simplify the consume before traversal heuristic.
Calling doConsumeBatchedInput() from doTraversals() can result in redundant attempts to consume batched input. Instead of making this call directly, just schedule consume batched input at the same time as traversals are scheduled. This should have the same overall effect. Bug: 6375101 Change-Id: Ie5799e6a68fedbd1978cca6d03852d9a7f1b1f64
1 parent aeee2f5 commit 330314c

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

core/java/android/view/ViewRootImpl.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ void scheduleTraversals() {
947947
mTraversalBarrier = mHandler.getLooper().postSyncBarrier();
948948
mChoreographer.postCallback(
949949
Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null);
950+
scheduleConsumeBatchedInput();
950951
}
951952
}
952953

@@ -964,9 +965,6 @@ void doTraversal() {
964965
mTraversalScheduled = false;
965966
mHandler.getLooper().removeSyncBarrier(mTraversalBarrier);
966967

967-
doConsumeBatchedInput(false);
968-
doProcessInputEvents();
969-
970968
if (mProfile) {
971969
Debug.startMethodTracing("ViewAncestor");
972970
}
@@ -4206,20 +4204,13 @@ void unscheduleConsumeBatchedInput() {
42064204
}
42074205
}
42084206

4209-
void doConsumeBatchedInput(boolean callback) {
4207+
void doConsumeBatchedInput() {
42104208
if (mConsumeBatchedInputScheduled) {
42114209
mConsumeBatchedInputScheduled = false;
4212-
if (!callback) {
4213-
mChoreographer.removeCallbacks(Choreographer.CALLBACK_INPUT,
4214-
mConsumedBatchedInputRunnable, null);
4210+
if (mInputEventReceiver != null) {
4211+
mInputEventReceiver.consumeBatchedInputEvents();
42154212
}
4216-
}
4217-
4218-
// Always consume batched input events even if not scheduled, because there
4219-
// might be new input there waiting for us that we have no noticed yet because
4220-
// the Looper has not had a chance to run again.
4221-
if (mInputEventReceiver != null) {
4222-
mInputEventReceiver.consumeBatchedInputEvents();
4213+
doProcessInputEvents();
42234214
}
42244215
}
42254216

@@ -4257,8 +4248,7 @@ public void dispose() {
42574248
final class ConsumeBatchedInputRunnable implements Runnable {
42584249
@Override
42594250
public void run() {
4260-
doConsumeBatchedInput(true);
4261-
doProcessInputEvents();
4251+
doConsumeBatchedInput();
42624252
}
42634253
}
42644254
final ConsumeBatchedInputRunnable mConsumedBatchedInputRunnable =

0 commit comments

Comments
 (0)