summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorSiarhei Vishniakou <svv@google.com>2021-03-22 17:58:12 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2021-03-22 17:58:12 +0000
commite1c0d2a844de54f7645df22bcff0dbd556248604 (patch)
tree059d4602e26552d82f6d687aa9435f522a78959f /core/java/android
parentfefc85a46b72a3c36c8650e62bb97a1f9919d7e5 (diff)
parent5054a9d00990ce35eb5ea6e5c9748d001a87c55c (diff)
Merge "Notify InputEventAssigner about every frame" into sc-dev
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/view/InputEventAssigner.java43
-rw-r--r--core/java/android/view/ViewRootImpl.java6
2 files changed, 18 insertions, 31 deletions
diff --git a/core/java/android/view/InputEventAssigner.java b/core/java/android/view/InputEventAssigner.java
index c159a127f4eb..7fac6c5e4af6 100644
--- a/core/java/android/view/InputEventAssigner.java
+++ b/core/java/android/view/InputEventAssigner.java
@@ -45,13 +45,13 @@ import static android.view.InputDevice.SOURCE_TOUCHSCREEN;
public class InputEventAssigner {
private static final String TAG = "InputEventAssigner";
private boolean mHasUnprocessedDown = false;
- private int mEventId = INVALID_INPUT_EVENT_ID;
+ private int mDownEventId = INVALID_INPUT_EVENT_ID;
/**
- * Notify InputEventAssigner that the Choreographer callback has been processed. This will reset
- * the 'down' state to assign the latest input event to the current frame.
+ * Notify InputEventAssigner that a frame has been processed. We no longer need to keep track of
+ * the DOWN event because a frame has already been produced for it.
*/
- public void onChoreographerCallback() {
+ public void notifyFrameProcessed() {
// Mark completion of this frame. Use newest input event from now on.
mHasUnprocessedDown = false;
}
@@ -62,31 +62,22 @@ public class InputEventAssigner {
* @return the id of the input event to use for the current frame
*/
public int processEvent(InputEvent event) {
- if (event instanceof KeyEvent) {
- // We will not do any special handling for key events
- return event.getId();
- }
-
if (event instanceof MotionEvent) {
MotionEvent motionEvent = (MotionEvent) event;
- final int action = motionEvent.getActionMasked();
-
- if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
- mHasUnprocessedDown = false;
+ if (motionEvent.isFromSource(SOURCE_TOUCHSCREEN)) {
+ final int action = motionEvent.getActionMasked();
+ if (action == MotionEvent.ACTION_DOWN) {
+ mHasUnprocessedDown = true;
+ mDownEventId = event.getId();
+ }
+ if (mHasUnprocessedDown && action == MotionEvent.ACTION_MOVE) {
+ return mDownEventId;
+ }
+ if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
+ mHasUnprocessedDown = false;
+ }
}
- if (motionEvent.isFromSource(SOURCE_TOUCHSCREEN) && action == MotionEvent.ACTION_DOWN) {
- mHasUnprocessedDown = true;
- mEventId = event.getId();
- // This will remain 'true' even if we receive a MOVE event, as long as choreographer
- // hasn't invoked the 'CALLBACK_INPUT' callback.
- }
- // Don't update the event id if we haven't processed DOWN yet.
- if (!mHasUnprocessedDown) {
- mEventId = event.getId();
- }
- return mEventId;
}
-
- throw new IllegalArgumentException("Received unexpected " + event);
+ return event.getId();
}
}
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index e4fb61107c4a..09a42cae52f1 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -474,6 +474,7 @@ public final class ViewRootImpl implements ViewParent,
FrameInfo frameInfo = mChoreographer.mFrameInfo;
mViewFrameInfo.populateFrameInfo(frameInfo);
mViewFrameInfo.reset();
+ mInputEventAssigner.notifyFrameProcessed();
return frameInfo;
}
@@ -8502,11 +8503,6 @@ public final class ViewRootImpl implements ViewParent,
consumedBatches = false;
}
doProcessInputEvents();
- if (consumedBatches) {
- // Must be done after we processed the input events, to mark the completion of the frame
- // from the input point of view
- mInputEventAssigner.onChoreographerCallback();
- }
return consumedBatches;
}