Use raw coordinates in VelocityTracker
Currently, VelocityTracker uses the "default" motionevent coordinates in
order to estimate the liftoff velocity of a pointer. When a view
receives a MotionEvent, the coordinates are getting adjusted relative to
the top left corner of the view. In a situation where a view itself is
moving while the user is interacting with the screen, and the view is
trying to estimate the fling velocity for a finger, this would cause
velocitytracker to use dynamic view coordinates. When these dynamically
adjusted coordinates are used in VelocityTracker, the resulting estimate
no longer accurately represents the liftoff velocity of a finger, since
the received data does not have a common origin.
Instead of using the offset-adjusted coordinates of a MotionEvent, use
the raw coordinates that are relative to the display itself and
independent of the view hierarchy.
Bug: 72263561
Test: m -j inputflinger_tests_InputReader_test
inputflinger_tests_InputDispatcher_test libinput_tests_InputChannel_test
libinput_tests_InputEvent_test
libinput_tests_InputPublisherAndConsumer_test
libinput_tests_VelocityTracker_test && adb push
out/target/product/$TARGET_PRODUCT/data/nativetest64/*
/data/nativetest64/
then run the tests on the device.
When "impulse" strategy is enabled, the velocitytracker test fails
because the flings need to be re-recorded.
Also manual fling in Google Maps (one and two finger), youtube, settings.
Change-Id: Id4d152dae00c2e6a342a71f5c89cbb5426c169ff
diff --git a/libs/input/VelocityTracker.cpp b/libs/input/VelocityTracker.cpp
index e54f147..e0d2113 100644
--- a/libs/input/VelocityTracker.cpp
+++ b/libs/input/VelocityTracker.cpp
@@ -325,8 +325,8 @@
eventTime = event->getHistoricalEventTime(h);
for (size_t i = 0; i < pointerCount; i++) {
uint32_t index = pointerIndex[i];
- positions[index].x = event->getHistoricalX(i, h);
- positions[index].y = event->getHistoricalY(i, h);
+ positions[index].x = event->getHistoricalRawX(i, h);
+ positions[index].y = event->getHistoricalRawY(i, h);
}
addMovement(eventTime, idBits, positions);
}
@@ -334,8 +334,8 @@
eventTime = event->getEventTime();
for (size_t i = 0; i < pointerCount; i++) {
uint32_t index = pointerIndex[i];
- positions[index].x = event->getX(i);
- positions[index].y = event->getY(i);
+ positions[index].x = event->getRawX(i);
+ positions[index].y = event->getRawY(i);
}
addMovement(eventTime, idBits, positions);
}