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

Commit 6e6c2589 authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge "TouchInputMapper: Use ui::Transform to calulate MotionRanges" into udc-dev

parents 44c11c9f 46211fbf
Loading
Loading
Loading
Loading
+33 −34
Original line number Original line Diff line number Diff line
@@ -805,40 +805,39 @@ void TouchInputMapper::initializeOrientedRanges() {
        };
        };
    }
    }


    // Compute oriented precision, scales and ranges.
    // Oriented X/Y range (in the rotated display's orientation)
    // Note that the maximum value reported is an inclusive maximum value so it is one
    const FloatRect rawFrame = Rect{mRawPointerAxes.x.minValue, mRawPointerAxes.y.minValue,
    // unit less than the total width or height of the display.
                                    mRawPointerAxes.x.maxValue, mRawPointerAxes.y.maxValue}
    // TODO(b/20508709): Calculate the oriented ranges using the input device's raw frame.
                                       .toFloatRect();
    switch (mInputDeviceOrientation) {
    const auto orientedRangeRect = mRawToRotatedDisplay.transform(rawFrame);
        case ui::ROTATION_90:
    mOrientedRanges.x.min = orientedRangeRect.left;
        case ui::ROTATION_270:
    mOrientedRanges.y.min = orientedRangeRect.top;
            mOrientedRanges.x.min = 0;
    mOrientedRanges.x.max = orientedRangeRect.right;
            mOrientedRanges.x.max = mDisplayBounds.height - 1;
    mOrientedRanges.y.max = orientedRangeRect.bottom;
            mOrientedRanges.x.flat = 0;

            mOrientedRanges.x.fuzz = 0;
    // Oriented flat (in the rotated display's orientation)
            mOrientedRanges.x.resolution = mRawPointerAxes.y.resolution * mRawToDisplay.getScaleY();
    const auto orientedFlat =

            transformWithoutTranslation(mRawToRotatedDisplay,
            mOrientedRanges.y.min = 0;
                                        {static_cast<float>(mRawPointerAxes.x.flat),
            mOrientedRanges.y.max = mDisplayBounds.width - 1;
                                         static_cast<float>(mRawPointerAxes.y.flat)});
            mOrientedRanges.y.flat = 0;
    mOrientedRanges.x.flat = std::abs(orientedFlat.x);
            mOrientedRanges.y.fuzz = 0;
    mOrientedRanges.y.flat = std::abs(orientedFlat.y);
            mOrientedRanges.y.resolution = mRawPointerAxes.x.resolution * mRawToDisplay.getScaleX();

            break;
    // Oriented fuzz (in the rotated display's orientation)

    const auto orientedFuzz =
        default:
            transformWithoutTranslation(mRawToRotatedDisplay,
            mOrientedRanges.x.min = 0;
                                        {static_cast<float>(mRawPointerAxes.x.fuzz),
            mOrientedRanges.x.max = mDisplayBounds.width - 1;
                                         static_cast<float>(mRawPointerAxes.y.fuzz)});
            mOrientedRanges.x.flat = 0;
    mOrientedRanges.x.fuzz = std::abs(orientedFuzz.x);
            mOrientedRanges.x.fuzz = 0;
    mOrientedRanges.y.fuzz = std::abs(orientedFuzz.y);
            mOrientedRanges.x.resolution = mRawPointerAxes.x.resolution * mRawToDisplay.getScaleX();


    // Oriented resolution (in the rotated display's orientation)
            mOrientedRanges.y.min = 0;
    const auto orientedRes =
            mOrientedRanges.y.max = mDisplayBounds.height - 1;
            transformWithoutTranslation(mRawToRotatedDisplay,
            mOrientedRanges.y.flat = 0;
                                        {static_cast<float>(mRawPointerAxes.x.resolution),
            mOrientedRanges.y.fuzz = 0;
                                         static_cast<float>(mRawPointerAxes.y.resolution)});
            mOrientedRanges.y.resolution = mRawPointerAxes.y.resolution * mRawToDisplay.getScaleY();
    mOrientedRanges.x.resolution = std::abs(orientedRes.x);
            break;
    mOrientedRanges.y.resolution = std::abs(orientedRes.y);
    }
}
}


void TouchInputMapper::computeInputTransforms() {
void TouchInputMapper::computeInputTransforms() {
+48 −2
Original line number Original line Diff line number Diff line
@@ -6927,9 +6927,11 @@ public:
        // four times the resolution of the display in the Y axis.
        // four times the resolution of the display in the Y axis.
        prepareButtons();
        prepareButtons();
        mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_X, PRECISION_RAW_X_MIN, PRECISION_RAW_X_MAX,
        mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_X, PRECISION_RAW_X_MIN, PRECISION_RAW_X_MAX,
                                       0, 0);
                                       PRECISION_RAW_X_FLAT, PRECISION_RAW_X_FUZZ,
                                       PRECISION_RAW_X_RES);
        mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_Y, PRECISION_RAW_Y_MIN, PRECISION_RAW_Y_MAX,
        mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_Y, PRECISION_RAW_Y_MIN, PRECISION_RAW_Y_MAX,
                                       0, 0);
                                       PRECISION_RAW_Y_FLAT, PRECISION_RAW_Y_FUZZ,
                                       PRECISION_RAW_Y_RES);
    }
    }
    static const int32_t PRECISION_RAW_X_MIN = TouchInputMapperTest::RAW_X_MIN;
    static const int32_t PRECISION_RAW_X_MIN = TouchInputMapperTest::RAW_X_MIN;
@@ -6937,6 +6939,15 @@ public:
    static const int32_t PRECISION_RAW_Y_MIN = TouchInputMapperTest::RAW_Y_MIN;
    static const int32_t PRECISION_RAW_Y_MIN = TouchInputMapperTest::RAW_Y_MIN;
    static const int32_t PRECISION_RAW_Y_MAX = PRECISION_RAW_Y_MIN + DISPLAY_HEIGHT * 4 - 1;
    static const int32_t PRECISION_RAW_Y_MAX = PRECISION_RAW_Y_MIN + DISPLAY_HEIGHT * 4 - 1;
    static const int32_t PRECISION_RAW_X_RES = 50;  // units per millimeter
    static const int32_t PRECISION_RAW_Y_RES = 100; // units per millimeter
    static const int32_t PRECISION_RAW_X_FLAT = 16;
    static const int32_t PRECISION_RAW_Y_FLAT = 32;
    static const int32_t PRECISION_RAW_X_FUZZ = 4;
    static const int32_t PRECISION_RAW_Y_FUZZ = 8;
    static const std::array<Point, 4> kRawCorners;
    static const std::array<Point, 4> kRawCorners;
};
};
@@ -7094,6 +7105,41 @@ TEST_P(TouchscreenPrecisionTestsFixture, RotationPrecisionOrientationAwareInOri2
    }
    }
}
}
TEST_P(TouchscreenPrecisionTestsFixture, MotionRangesAreOrientedInRotatedDisplay) {
    const ui::Rotation displayRotation = GetParam();
    addConfigurationProperty("touch.deviceType", "touchScreen");
    prepareDisplay(displayRotation);
    __attribute__((unused)) SingleTouchInputMapper& mapper =
            addMapperAndConfigure<SingleTouchInputMapper>();
    const InputDeviceInfo deviceInfo = mDevice->getDeviceInfo();
    // MotionRanges use display pixels as their units
    const auto* xRange = deviceInfo.getMotionRange(AMOTION_EVENT_AXIS_X, AINPUT_SOURCE_TOUCHSCREEN);
    const auto* yRange = deviceInfo.getMotionRange(AMOTION_EVENT_AXIS_Y, AINPUT_SOURCE_TOUCHSCREEN);
    // The MotionRanges should be oriented in the rotated display's coordinate space
    const bool displayRotated =
            displayRotation == ui::ROTATION_90 || displayRotation == ui::ROTATION_270;
    constexpr float MAX_X = 479.5;
    constexpr float MAX_Y = 799.75;
    EXPECT_EQ(xRange->min, 0.f);
    EXPECT_EQ(yRange->min, 0.f);
    EXPECT_EQ(xRange->max, displayRotated ? MAX_Y : MAX_X);
    EXPECT_EQ(yRange->max, displayRotated ? MAX_X : MAX_Y);
    EXPECT_EQ(xRange->flat, 8.f);
    EXPECT_EQ(yRange->flat, 8.f);
    EXPECT_EQ(xRange->fuzz, 2.f);
    EXPECT_EQ(yRange->fuzz, 2.f);
    EXPECT_EQ(xRange->resolution, 25.f); // pixels per millimeter
    EXPECT_EQ(yRange->resolution, 25.f); // pixels per millimeter
}
// Run the precision tests for all rotations.
// Run the precision tests for all rotations.
INSTANTIATE_TEST_SUITE_P(TouchscreenPrecisionTests, TouchscreenPrecisionTestsFixture,
INSTANTIATE_TEST_SUITE_P(TouchscreenPrecisionTests, TouchscreenPrecisionTestsFixture,
                         ::testing::Values(ui::ROTATION_0, ui::ROTATION_90, ui::ROTATION_180,
                         ::testing::Values(ui::ROTATION_0, ui::ROTATION_90, ui::ROTATION_180,