diff options
author | 2020-12-29 20:28:15 +0800 | |
---|---|---|
committer | 2021-01-13 23:56:23 +0800 | |
commit | 10052f69bd4e07355e40f601f15294b4abc832b3 (patch) | |
tree | 8ddfb19c5433a2d492bd4389c3674c4b34c7455a | |
parent | 08f1520519828d7cec967916b42c91ee10100f04 (diff) |
Fix coordinate error after rotation and scaling in TouchInputMapper
The 'rotateAndScale' will transform raw coordinate into surface
coordinate, but the raw (x, y) values range would be defined in
RawPointerAxes, so we have to transform the raw event using the
RawPointerAxes and the scaling ratio into surface coordinate, then
calculate the offset by the surface frame.
Test: atest inputflinger_test
Bug: 176138152
Change-Id: I2d428fcbdc4bb879525754aafef05ebebbf131c5
Merged-In: I2d428fcbdc4bb879525754aafef05ebebbf131c5
-rw-r--r-- | services/inputflinger/reader/mapper/TouchInputMapper.cpp | 11 | ||||
-rw-r--r-- | services/inputflinger/tests/InputReader_test.cpp | 32 |
2 files changed, 37 insertions, 6 deletions
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index cfc2919e7b..80910360af 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -3669,6 +3669,9 @@ void TouchInputMapper::rotateAndScale(float& x, float& y) { const float xScaled = float(x - mRawPointerAxes.x.minValue) * mXScale; const float yScaled = float(y - mRawPointerAxes.y.minValue) * mYScale; + const float xScaledMax = float(mRawPointerAxes.x.maxValue - x) * mXScale; + const float yScaledMax = float(mRawPointerAxes.y.maxValue - y) * mYScale; + // Rotate to surface coordinate. // 0 - no swap and reverse. // 90 - swap x/y and reverse y. @@ -3680,16 +3683,16 @@ void TouchInputMapper::rotateAndScale(float& x, float& y) { y = yScaled + mYTranslate; break; case DISPLAY_ORIENTATION_90: - y = mSurfaceRight - xScaled; + y = xScaledMax - (mRawSurfaceWidth - mSurfaceRight); x = yScaled + mYTranslate; break; case DISPLAY_ORIENTATION_180: - x = mSurfaceRight - xScaled; - y = mSurfaceBottom - yScaled; + x = xScaledMax - (mRawSurfaceWidth - mSurfaceRight); + y = yScaledMax - (mRawSurfaceHeight - mSurfaceBottom); break; case DISPLAY_ORIENTATION_270: y = xScaled + mXTranslate; - x = mSurfaceBottom - yScaled; + x = yScaledMax - (mRawSurfaceHeight - mSurfaceBottom); break; default: assert(false); diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 58f83b518d..e9bb169d64 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -7449,8 +7449,8 @@ protected: configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO); } - void processPositionAndVerify(MultiTouchInputMapper& mapper, int32_t xInside, int32_t yInside, - int32_t xOutside, int32_t yOutside, int32_t xExpected, + void processPositionAndVerify(MultiTouchInputMapper& mapper, int32_t xOutside, int32_t yOutside, + int32_t xInside, int32_t yInside, int32_t xExpected, int32_t yExpected) { // touch on outside area should not work. processPosition(mapper, toRawX(xOutside), toRawY(yOutside)); @@ -7532,6 +7532,34 @@ TEST_F(MultiTouchInputMapperTest_SurfaceRange, Viewports_SurfaceRange_270) { processPositionAndVerify(mapper, x - 1, y, x + 1, y, xExpected, yExpected); } +TEST_F(MultiTouchInputMapperTest_SurfaceRange, Viewports_SurfaceRange_Corner) { + addConfigurationProperty("touch.deviceType", "touchScreen"); + prepareDisplay(DISPLAY_ORIENTATION_0); + prepareAxes(POSITION); + MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>(); + + const int32_t x = 0; + const int32_t y = 0; + + const int32_t xExpected = x; + const int32_t yExpected = y; + processPositionAndVerify(mapper, x - 1, y, x, y, xExpected, yExpected); + + clearViewports(); + prepareDisplay(DISPLAY_ORIENTATION_90); + // expect x/y = swap x/y then reverse y. + const int32_t xExpected90 = y; + const int32_t yExpected90 = DISPLAY_WIDTH - 1; + processPositionAndVerify(mapper, x - 1, y, x, y, xExpected90, yExpected90); + + clearViewports(); + prepareDisplay(DISPLAY_ORIENTATION_270); + // expect x/y = swap x/y then reverse x. + const int32_t xExpected270 = DISPLAY_HEIGHT - 1; + const int32_t yExpected270 = x; + processPositionAndVerify(mapper, x - 1, y, x, y, xExpected270, yExpected270); +} + TEST_F(MultiTouchInputMapperTest, Process_TouchpadCapture) { // we need a pointer controller for mouse mode of touchpad (start pointer at 0,0) std::shared_ptr<FakePointerController> fakePointerController = |