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

Commit 6b430413 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Change PointerController to display space

PointerController used to work in the logical display space, so
TouchInputMapper and CursorInputMapper would need to transform the
coordinates before interacting with it.

This CL makes PointerController work in the display space. It will
transform incoming and outgoing coordinates to stay in the display
space using the DisplayInfo provided by SurfaceFlinger. Using info
provided by SF also means that there will be better synchonization
between the pointers and display changes like rotation.

Bug: 188939842
Bug: 144544464
Test: manual: ensure mouse and touch spots work in different display
orientations and sizes set using "adb shell wm size"

Change-Id: I764c070adef7e9f26c0062f1b3466c7115a305ac
parent 3bb6799f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -201,6 +201,11 @@ namespace android {
class Parcel;
#endif

/*
 * Apply the given transform to the point without applying any translation/offset.
 */
vec2 transformWithoutTranslation(const ui::Transform& transform, const vec2& xy);

const char* inputEventTypeToString(int32_t type);

std::string inputEventSourceToString(int32_t source);
+6 −6
Original line number Diff line number Diff line
@@ -60,12 +60,6 @@ float transformAngle(const ui::Transform& transform, float angleRadians) {
    return atan2f(transformedPoint.x, -transformedPoint.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;
}

bool shouldDisregardTransformation(uint32_t source) {
    // Do not apply any transformations to axes from joysticks or touchpads.
    return isFromSource(source, AINPUT_SOURCE_CLASS_JOYSTICK) ||
@@ -120,6 +114,12 @@ int32_t IdGenerator::nextId() const {

// --- InputEvent ---

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;
}

const char* inputEventTypeToString(int32_t type) {
    switch (type) {
        case AINPUT_EVENT_TYPE_KEY: {
+2 −1
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@ namespace android {
 * fingers
 *
 * The pointer controller is responsible for providing synchronization and for tracking
 * display orientation changes if needed.
 * display orientation changes if needed. It works in the display panel's coordinate space, which
 * is the same coordinate space used by InputReader.
 */
class PointerControllerInterface {
protected:
+1 −16
Original line number Diff line number Diff line
@@ -188,8 +188,6 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*

    if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
        mOrientation = DISPLAY_ORIENTATION_0;
        mDisplayWidth = 0;
        mDisplayHeight = 0;
        const bool isOrientedDevice =
                (mParameters.orientationAware && mParameters.hasAssociatedDisplay);

@@ -203,8 +201,6 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*
                    config->getDisplayViewportByType(ViewportType::INTERNAL);
            if (internalViewport) {
                mOrientation = getInverseRotation(internalViewport->orientation);
                mDisplayWidth = internalViewport->deviceWidth;
                mDisplayHeight = internalViewport->deviceHeight;
            }
        }

@@ -335,14 +331,7 @@ void CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) {
            mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER);

            if (moved) {
                float dx = deltaX;
                float dy = deltaY;
                // Rotate the delta from InputReader's un-rotated coordinate space to
                // PointerController's rotated coordinate space that is oriented with the
                // viewport.
                rotateDelta(getInverseRotation(mOrientation), &dx, &dy);

                mPointerController->move(dx, dy);
                mPointerController->move(deltaX, deltaY);
            }

            if (buttonsChanged) {
@@ -353,10 +342,6 @@ void CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) {
        }

        mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
        // Rotate the cursor position that is in PointerController's rotated coordinate space
        // to InputReader's un-rotated coordinate space.
        rotatePoint(mOrientation, xCursorPosition /*byRef*/, yCursorPosition /*byRef*/,
                    mDisplayWidth, mDisplayHeight);

        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, xCursorPosition);
        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition);
+0 −2
Original line number Diff line number Diff line
@@ -105,8 +105,6 @@ private:
    VelocityControl mWheelYVelocityControl;

    int32_t mOrientation;
    int32_t mDisplayWidth;
    int32_t mDisplayHeight;

    std::shared_ptr<PointerControllerInterface> mPointerController;

Loading