Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f6de3856 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix coordinate error after rotation and scaling in TouchInputMapper"...

Merge "Fix coordinate error after rotation and scaling in TouchInputMapper" am: 7de7b8c5 am: 0593880b

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1540666

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Id5fa7cd454b98ba8b3518c151f8504cb6c76218b
parents 1484c5c7 0593880b
Loading
Loading
Loading
Loading
+7 −4
Original line number Original line Diff line number Diff line
@@ -3673,6 +3673,9 @@ void TouchInputMapper::rotateAndScale(float& x, float& y) {
    const float xScaled = float(x - mRawPointerAxes.x.minValue) * mXScale;
    const float xScaled = float(x - mRawPointerAxes.x.minValue) * mXScale;
    const float yScaled = float(y - mRawPointerAxes.y.minValue) * mYScale;
    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.
    // Rotate to surface coordinate.
    // 0 - no swap and reverse.
    // 0 - no swap and reverse.
    // 90 - swap x/y and reverse y.
    // 90 - swap x/y and reverse y.
@@ -3684,16 +3687,16 @@ void TouchInputMapper::rotateAndScale(float& x, float& y) {
            y = yScaled + mYTranslate;
            y = yScaled + mYTranslate;
            break;
            break;
        case DISPLAY_ORIENTATION_90:
        case DISPLAY_ORIENTATION_90:
            y = mSurfaceRight - xScaled;
            y = xScaledMax - (mRawSurfaceWidth - mSurfaceRight);
            x = yScaled + mYTranslate;
            x = yScaled + mYTranslate;
            break;
            break;
        case DISPLAY_ORIENTATION_180:
        case DISPLAY_ORIENTATION_180:
            x = mSurfaceRight - xScaled;
            x = xScaledMax - (mRawSurfaceWidth - mSurfaceRight);
            y = mSurfaceBottom - yScaled;
            y = yScaledMax - (mRawSurfaceHeight - mSurfaceBottom);
            break;
            break;
        case DISPLAY_ORIENTATION_270:
        case DISPLAY_ORIENTATION_270:
            y = xScaled + mXTranslate;
            y = xScaled + mXTranslate;
            x = mSurfaceBottom - yScaled;
            x = yScaledMax - (mRawSurfaceHeight - mSurfaceBottom);
            break;
            break;
        default:
        default:
            assert(false);
            assert(false);
+30 −2
Original line number Original line Diff line number Diff line
@@ -7449,8 +7449,8 @@ protected:
        configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
        configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
    }
    }


    void processPositionAndVerify(MultiTouchInputMapper& mapper, int32_t xInside, int32_t yInside,
    void processPositionAndVerify(MultiTouchInputMapper& mapper, int32_t xOutside, int32_t yOutside,
                                  int32_t xOutside, int32_t yOutside, int32_t xExpected,
                                  int32_t xInside, int32_t yInside, int32_t xExpected,
                                  int32_t yExpected) {
                                  int32_t yExpected) {
        // touch on outside area should not work.
        // touch on outside area should not work.
        processPosition(mapper, toRawX(xOutside), toRawY(yOutside));
        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);
    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) {
TEST_F(MultiTouchInputMapperTest, Process_TouchpadCapture) {
    // we need a pointer controller for mouse mode of touchpad (start pointer at 0,0)
    // we need a pointer controller for mouse mode of touchpad (start pointer at 0,0)
    std::shared_ptr<FakePointerController> fakePointerController =
    std::shared_ptr<FakePointerController> fakePointerController =