MotionEvent: Get offsets in raw coordinate space
MotionEvents store the underlying axis values in the coordinate space of
the physical display, or "untransformed" space. The MotionEvent's
mRawTransform takes those coordinates into the coordinate space of the
logical display, or "raw" coordinates. The MotionEvent's mTransform
takes those coordinates into the window/View's local coordinates.
Previously, getting the motion event offset would return the offset with
respect to the origin of the "untransformed" space. This is of little
value to callers, since they are expecting the offset in "raw"
coordinates, which is the offset with respect to the logical display's
origin.
To calculate the raw offset, we calculate where the raw point (0, 0)
would map to in untransformed coordinates by applying the inverse raw
transform, and then apply the window transform.
Bug: 249340921
Test: atest libinput_tests
Test: atest inputflinger_tests
Change-Id: Iadbdde4dd45b5527b73be863b198b4c9a9e713cc
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp
index 9e0ce1d..63f5ca4 100644
--- a/libs/input/Input.cpp
+++ b/libs/input/Input.cpp
@@ -690,6 +690,18 @@
mTransform.set(currXOffset + xOffset, currYOffset + yOffset);
}
+float MotionEvent::getRawXOffset() const {
+ // This is equivalent to the x-coordinate of the point that the origin of the raw coordinate
+ // space maps to.
+ return (mTransform * mRawTransform.inverse()).tx();
+}
+
+float MotionEvent::getRawYOffset() const {
+ // This is equivalent to the y-coordinate of the point that the origin of the raw coordinate
+ // space maps to.
+ return (mTransform * mRawTransform.inverse()).ty();
+}
+
void MotionEvent::scale(float globalScaleFactor) {
mTransform.set(mTransform.tx() * globalScaleFactor, mTransform.ty() * globalScaleFactor);
mRawTransform.set(mRawTransform.tx() * globalScaleFactor,