Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 330314c6 authored by Jeff Brown's avatar Jeff Brown
Browse files

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
parent aeee2f5d
Loading
Loading
Loading
Loading
+6 −16
Original line number Diff line number Diff line
@@ -947,6 +947,7 @@ public final class ViewRootImpl implements ViewParent,
            mTraversalBarrier = mHandler.getLooper().postSyncBarrier();
            mChoreographer.postCallback(
                    Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null);
            scheduleConsumeBatchedInput();
        }
    }

@@ -964,9 +965,6 @@ public final class ViewRootImpl implements ViewParent,
            mTraversalScheduled = false;
            mHandler.getLooper().removeSyncBarrier(mTraversalBarrier);

            doConsumeBatchedInput(false);
            doProcessInputEvents();

            if (mProfile) {
                Debug.startMethodTracing("ViewAncestor");
            }
@@ -4206,21 +4204,14 @@ public final class ViewRootImpl implements ViewParent,
        }
    }

    void doConsumeBatchedInput(boolean callback) {
    void doConsumeBatchedInput() {
        if (mConsumeBatchedInputScheduled) {
            mConsumeBatchedInputScheduled = false;
            if (!callback) {
                mChoreographer.removeCallbacks(Choreographer.CALLBACK_INPUT,
                        mConsumedBatchedInputRunnable, null);
            }
        }

        // Always consume batched input events even if not scheduled, because there
        // might be new input there waiting for us that we have no noticed yet because
        // the Looper has not had a chance to run again.
            if (mInputEventReceiver != null) {
                mInputEventReceiver.consumeBatchedInputEvents();
            }
            doProcessInputEvents();
        }
    }

    final class TraversalRunnable implements Runnable {
@@ -4257,8 +4248,7 @@ public final class ViewRootImpl implements ViewParent,
    final class ConsumeBatchedInputRunnable implements Runnable {
        @Override
        public void run() {
            doConsumeBatchedInput(true);
            doProcessInputEvents();
            doConsumeBatchedInput();
        }
    }
    final ConsumeBatchedInputRunnable mConsumedBatchedInputRunnable =