Loading include/input/Input.h +5 −1 Original line number Diff line number Diff line Loading @@ -746,10 +746,14 @@ public: void scale(float globalScaleFactor); // Apply 3x3 perspective matrix transformation. // Set 3x3 perspective matrix transformation. // Matrix is in row-major form and compatible with SkMatrix. void transform(const std::array<float, 9>& matrix); // Apply 3x3 perspective matrix transformation only to content (do not modify mTransform). // Matrix is in row-major form and compatible with SkMatrix. void applyTransform(const std::array<float, 9>& matrix); #ifdef __linux__ status_t readFromParcel(Parcel* parcel); status_t writeToParcel(Parcel* parcel) const; Loading libs/input/Input.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -569,6 +569,24 @@ void MotionEvent::transform(const std::array<float, 9>& matrix) { } } void MotionEvent::applyTransform(const std::array<float, 9>& matrix) { // Determine how the origin is transformed by the matrix so that we // can transform orientation vectors. vec2 origin = transformPoint(matrix, 0, 0); // Apply the transformation to all samples. size_t numSamples = mSamplePointerCoords.size(); for (size_t i = 0; i < numSamples; i++) { PointerCoords& c = mSamplePointerCoords.editItemAt(i); float orientation = c.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION); c.setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, transformAngle(matrix, orientation, origin.x, origin.y)); vec2 xy = transformPoint(matrix, c.getX(), c.getY()); c.setAxisValue(AMOTION_EVENT_AXIS_X, xy.x); c.setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y); } } #ifdef __linux__ static status_t readFromParcel(ui::Transform& transform, const Parcel& parcel) { float dsdx, dtdx, tx, dtdy, dsdy, ty; Loading libs/input/tests/InputEvent_test.cpp +47 −21 Original line number Diff line number Diff line Loading @@ -636,8 +636,7 @@ TEST_F(MotionEventTest, Transform) { ASSERT_NEAR(originalRawY, event.getRawY(0), 0.001); } TEST_F(MotionEventTest, RawCompatTransform) { auto createTouchDownEvent = [](int x, int y, ui::Transform transform) { MotionEvent createTouchDownEvent(int x, int y, ui::Transform transform) { std::vector<PointerProperties> pointerProperties; pointerProperties.push_back(PointerProperties{/* id */ 0, AMOTION_EVENT_TOOL_TYPE_FINGER}); std::vector<PointerCoords> pointerCoords; Loading @@ -650,14 +649,41 @@ TEST_F(MotionEventTest, RawCompatTransform) { /* displayId */ 0, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, /* actionButton */ 0, /* flags */ 0, /* edgeFlags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE, transform, /* xPrecision */ 0, /* yPrecision */ 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, /* xPrecision */ 0, /* yPrecision */ 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, /* displayWidth */ 400, /* displayHeight */ 800, eventTime, eventTime, pointerCoords.size(), pointerProperties.data(), pointerCoords.data()); return event; }; } TEST_F(MotionEventTest, ApplyTransform) { // Create a rotate-90 transform with an offset (like a window which isn't fullscreen). ui::Transform identity; ui::Transform xform(ui::Transform::ROT_90, 800, 400); xform.set(xform.tx() + 20, xform.ty() + 40); MotionEvent event = createTouchDownEvent(60, 100, xform); ASSERT_EQ(700, event.getRawX(0)); ASSERT_EQ(60, event.getRawY(0)); ASSERT_NE(event.getRawX(0), event.getX(0)); ASSERT_NE(event.getRawY(0), event.getY(0)); MotionEvent changedEvent = createTouchDownEvent(60, 100, identity); const std::array<float, 9> rowMajor{xform[0][0], xform[1][0], xform[2][0], xform[0][1], xform[1][1], xform[2][1], xform[0][2], xform[1][2], xform[2][2]}; changedEvent.applyTransform(rowMajor); // transformContent effectively rotates the raw coordinates, so those should now include // both rotation AND offset ASSERT_EQ(720, changedEvent.getRawX(0)); ASSERT_EQ(100, changedEvent.getRawY(0)); // The transformed output should be the same then ASSERT_NEAR(event.getX(0), changedEvent.getX(0), 0.001); ASSERT_NEAR(event.getY(0), changedEvent.getY(0), 0.001); } TEST_F(MotionEventTest, RawCompatTransform) { { // Make sure raw is raw regardless of transform translation. ui::Transform xform; Loading Loading
include/input/Input.h +5 −1 Original line number Diff line number Diff line Loading @@ -746,10 +746,14 @@ public: void scale(float globalScaleFactor); // Apply 3x3 perspective matrix transformation. // Set 3x3 perspective matrix transformation. // Matrix is in row-major form and compatible with SkMatrix. void transform(const std::array<float, 9>& matrix); // Apply 3x3 perspective matrix transformation only to content (do not modify mTransform). // Matrix is in row-major form and compatible with SkMatrix. void applyTransform(const std::array<float, 9>& matrix); #ifdef __linux__ status_t readFromParcel(Parcel* parcel); status_t writeToParcel(Parcel* parcel) const; Loading
libs/input/Input.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -569,6 +569,24 @@ void MotionEvent::transform(const std::array<float, 9>& matrix) { } } void MotionEvent::applyTransform(const std::array<float, 9>& matrix) { // Determine how the origin is transformed by the matrix so that we // can transform orientation vectors. vec2 origin = transformPoint(matrix, 0, 0); // Apply the transformation to all samples. size_t numSamples = mSamplePointerCoords.size(); for (size_t i = 0; i < numSamples; i++) { PointerCoords& c = mSamplePointerCoords.editItemAt(i); float orientation = c.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION); c.setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, transformAngle(matrix, orientation, origin.x, origin.y)); vec2 xy = transformPoint(matrix, c.getX(), c.getY()); c.setAxisValue(AMOTION_EVENT_AXIS_X, xy.x); c.setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y); } } #ifdef __linux__ static status_t readFromParcel(ui::Transform& transform, const Parcel& parcel) { float dsdx, dtdx, tx, dtdy, dsdy, ty; Loading
libs/input/tests/InputEvent_test.cpp +47 −21 Original line number Diff line number Diff line Loading @@ -636,8 +636,7 @@ TEST_F(MotionEventTest, Transform) { ASSERT_NEAR(originalRawY, event.getRawY(0), 0.001); } TEST_F(MotionEventTest, RawCompatTransform) { auto createTouchDownEvent = [](int x, int y, ui::Transform transform) { MotionEvent createTouchDownEvent(int x, int y, ui::Transform transform) { std::vector<PointerProperties> pointerProperties; pointerProperties.push_back(PointerProperties{/* id */ 0, AMOTION_EVENT_TOOL_TYPE_FINGER}); std::vector<PointerCoords> pointerCoords; Loading @@ -650,14 +649,41 @@ TEST_F(MotionEventTest, RawCompatTransform) { /* displayId */ 0, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, /* actionButton */ 0, /* flags */ 0, /* edgeFlags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE, transform, /* xPrecision */ 0, /* yPrecision */ 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, /* xPrecision */ 0, /* yPrecision */ 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, /* displayWidth */ 400, /* displayHeight */ 800, eventTime, eventTime, pointerCoords.size(), pointerProperties.data(), pointerCoords.data()); return event; }; } TEST_F(MotionEventTest, ApplyTransform) { // Create a rotate-90 transform with an offset (like a window which isn't fullscreen). ui::Transform identity; ui::Transform xform(ui::Transform::ROT_90, 800, 400); xform.set(xform.tx() + 20, xform.ty() + 40); MotionEvent event = createTouchDownEvent(60, 100, xform); ASSERT_EQ(700, event.getRawX(0)); ASSERT_EQ(60, event.getRawY(0)); ASSERT_NE(event.getRawX(0), event.getX(0)); ASSERT_NE(event.getRawY(0), event.getY(0)); MotionEvent changedEvent = createTouchDownEvent(60, 100, identity); const std::array<float, 9> rowMajor{xform[0][0], xform[1][0], xform[2][0], xform[0][1], xform[1][1], xform[2][1], xform[0][2], xform[1][2], xform[2][2]}; changedEvent.applyTransform(rowMajor); // transformContent effectively rotates the raw coordinates, so those should now include // both rotation AND offset ASSERT_EQ(720, changedEvent.getRawX(0)); ASSERT_EQ(100, changedEvent.getRawY(0)); // The transformed output should be the same then ASSERT_NEAR(event.getX(0), changedEvent.getX(0), 0.001); ASSERT_NEAR(event.getY(0), changedEvent.getY(0), 0.001); } TEST_F(MotionEventTest, RawCompatTransform) { { // Make sure raw is raw regardless of transform translation. ui::Transform xform; Loading