summaryrefslogtreecommitdiff
path: root/libs/input/Input.cpp
diff options
context:
space:
mode:
author Prabir Pradhan <prabirmsp@google.com> 2021-09-24 06:35:16 -0700
committer Prabir Pradhan <prabirmsp@google.com> 2021-10-04 04:00:44 -0700
commitb5cb957254201f19a434898c249d59752e2a88b7 (patch)
tree1448609838a4c522f11ee3454eb227d2f83dee9e /libs/input/Input.cpp
parentc2872295a47436c5507c38ddac0393b76d5471d1 (diff)
VerifiedMotionEvent: Sign transformed raw values
The values for axes X/Y that are stored in MotionEvent are transformed to values used for its getRaw API based on the source. This is because non-pointer sources should not have translation applied to them. We need to ensure that we use the same raw coordinates when we sign a VerifiedMotionEvent in InputDispatcher that we would get with the MotionEvent#getRaw API. To do this, we re-use the same logic used to transform the raw coordinates in MotionEvent in InputDispatcher. Bug: 179274888 Test: atest inputflinger_tests Test: atest VerifyInputEventTest Change-Id: I552f94064f15573ddda8f7c0b588cd3b984b6a94
Diffstat (limited to 'libs/input/Input.cpp')
-rw-r--r--libs/input/Input.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp
index a1542c8793..1bc244c653 100644
--- a/libs/input/Input.cpp
+++ b/libs/input/Input.cpp
@@ -65,8 +65,8 @@ float transformAngle(const ui::Transform& transform, float angleRadians) {
return result;
}
-vec2 transformWithoutTranslation(const ui::Transform& transform, float x, float y) {
- const vec2 transformedXy = transform.transform(x, y);
+vec2 transformWithoutTranslation(const ui::Transform& transform, const vec2& xy) {
+ const vec2 transformedXy = transform.transform(xy);
const vec2 transformedOrigin = transform.transform(0, 0);
return transformedXy - transformedOrigin;
}
@@ -501,21 +501,16 @@ float MotionEvent::getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
const PointerCoords* coords = getHistoricalRawPointerCoords(pointerIndex, historicalIndex);
if (axis == AMOTION_EVENT_AXIS_X || axis == AMOTION_EVENT_AXIS_Y) {
- // For compatibility, convert raw coordinates into logical display space.
- const vec2 xy = shouldDisregardTranslation(mSource)
- ? transformWithoutTranslation(mRawTransform, coords->getX(), coords->getY())
- : mRawTransform.transform(coords->getX(), coords->getY());
+ const vec2 xy = calculateTransformedXY(mSource, mRawTransform, coords->getXYValue());
static_assert(AMOTION_EVENT_AXIS_X == 0 && AMOTION_EVENT_AXIS_Y == 1);
return xy[axis];
}
if (axis == AMOTION_EVENT_AXIS_RELATIVE_X || axis == AMOTION_EVENT_AXIS_RELATIVE_Y) {
- // For compatibility, since we report raw coordinates in logical display space, we
- // need to convert the relative axes into the same orientation for consistency.
const vec2 relativeXy =
transformWithoutTranslation(mRawTransform,
- coords->getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X),
- coords->getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y));
+ {coords->getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X),
+ coords->getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y)});
return axis == AMOTION_EVENT_AXIS_RELATIVE_X ? relativeXy.x : relativeXy.y;
}
@@ -527,9 +522,7 @@ float MotionEvent::getHistoricalAxisValue(int32_t axis, size_t pointerIndex,
const PointerCoords* coords = getHistoricalRawPointerCoords(pointerIndex, historicalIndex);
if (axis == AMOTION_EVENT_AXIS_X || axis == AMOTION_EVENT_AXIS_Y) {
- const vec2 xy = shouldDisregardTranslation(mSource)
- ? transformWithoutTranslation(mTransform, coords->getX(), coords->getY())
- : mTransform.transform(coords->getXYValue());
+ const vec2 xy = calculateTransformedXY(mSource, mTransform, coords->getXYValue());
static_assert(AMOTION_EVENT_AXIS_X == 0 && AMOTION_EVENT_AXIS_Y == 1);
return xy[axis];
}
@@ -537,8 +530,8 @@ float MotionEvent::getHistoricalAxisValue(int32_t axis, size_t pointerIndex,
if (axis == AMOTION_EVENT_AXIS_RELATIVE_X || axis == AMOTION_EVENT_AXIS_RELATIVE_Y) {
const vec2 relativeXy =
transformWithoutTranslation(mTransform,
- coords->getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X),
- coords->getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y));
+ {coords->getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X),
+ coords->getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y)});
return axis == AMOTION_EVENT_AXIS_RELATIVE_X ? relativeXy.x : relativeXy.y;
}
@@ -815,6 +808,12 @@ std::string MotionEvent::actionToString(int32_t action) {
return android::base::StringPrintf("%" PRId32, action);
}
+vec2 MotionEvent::calculateTransformedXY(uint32_t source, const ui::Transform& transform,
+ const vec2& xy) {
+ return shouldDisregardTranslation(source) ? transformWithoutTranslation(transform, xy)
+ : transform.transform(xy);
+}
+
// --- FocusEvent ---
void FocusEvent::initialize(int32_t id, bool hasFocus, bool inTouchMode) {