Loading services/inputflinger/reader/mapper/CursorInputMapper.cpp +34 −11 Original line number Diff line number Diff line Loading @@ -188,13 +188,31 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration* if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) { mOrientation = DISPLAY_ORIENTATION_0; if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) { const bool isOrientedDevice = (mParameters.orientationAware && mParameters.hasAssociatedDisplay); if (isPerWindowInputRotationEnabled()) { // When per-window input rotation is enabled, InputReader works in the un-rotated // coordinate space, so we don't need to do anything if the device is already // orientation-aware. If the device is not orientation-aware, then we need to apply the // inverse rotation of the display so that when the display rotation is applied later // as a part of the per-window transform, we get the expected screen coordinates. if (!isOrientedDevice) { std::optional<DisplayViewport> internalViewport = config->getDisplayViewportByType(ViewportType::INTERNAL); if (internalViewport) { mOrientation = getInverseRotation(internalViewport->orientation); } } } else { if (isOrientedDevice) { std::optional<DisplayViewport> internalViewport = config->getDisplayViewportByType(ViewportType::INTERNAL); if (internalViewport) { mOrientation = internalViewport->orientation; } } } bumpGeneration(); } Loading Loading @@ -294,11 +312,8 @@ void CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) { float deltaY = mCursorMotionAccumulator.getRelativeY() * mYScale; bool moved = deltaX != 0 || deltaY != 0; // Rotate delta according to orientation if needed. if (mParameters.orientationAware && mParameters.hasAssociatedDisplay && (deltaX != 0.0f || deltaY != 0.0f)) { // Rotate delta according to orientation. rotateDelta(mOrientation, &deltaX, &deltaY); } // Move the pointer. PointerProperties pointerProperties; Loading Loading @@ -326,7 +341,15 @@ void CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) { mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER); if (moved) { mPointerController->move(deltaX, deltaY); float dx = deltaX; float dy = deltaY; if (isPerWindowInputRotationEnabled()) { // 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); } if (buttonsChanged) { Loading services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h +21 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #ifndef _UI_INPUTREADER_TOUCH_CURSOR_INPUT_MAPPER_COMMON_H #define _UI_INPUTREADER_TOUCH_CURSOR_INPUT_MAPPER_COMMON_H #include <android-base/properties.h> #include <input/DisplayViewport.h> #include <stdint.h> Loading @@ -28,6 +29,26 @@ namespace android { // --- Static Definitions --- // When per-window input rotation is enabled, display transformations such as rotation and // projection are part of the input window's transform. This means InputReader should work in the // un-rotated coordinate space. static bool isPerWindowInputRotationEnabled() { static const bool PER_WINDOW_INPUT_ROTATION = base::GetBoolProperty("persist.debug.per_window_input_rotation", false); return PER_WINDOW_INPUT_ROTATION; } static int32_t getInverseRotation(int32_t orientation) { switch (orientation) { case DISPLAY_ORIENTATION_90: return DISPLAY_ORIENTATION_270; case DISPLAY_ORIENTATION_270: return DISPLAY_ORIENTATION_90; default: return orientation; } } static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) { float temp; switch (orientation) { Loading services/inputflinger/reader/mapper/TouchInputMapper.cpp +122 −35 Original line number Diff line number Diff line Loading @@ -28,6 +28,30 @@ namespace android { namespace { // Rotates the given point (x, y) by the supplied orientation. The width and height are the // dimensions of the surface prior to this rotation being applied. void rotatePoint(int32_t orientation, float& x, float& y, int32_t width, int32_t height) { rotateDelta(orientation, &x, &y); switch (orientation) { case DISPLAY_ORIENTATION_90: y += width; break; case DISPLAY_ORIENTATION_180: x += width; y += height; break; case DISPLAY_ORIENTATION_270: x += height; break; default: break; } } } // namespace // --- Constants --- // Maximum amount of latency to add to touch events while waiting for data from an Loading Loading @@ -729,8 +753,20 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { mSurfaceRight = mSurfaceLeft + naturalLogicalWidth; mSurfaceBottom = mSurfaceTop + naturalLogicalHeight; mSurfaceOrientation = mParameters.orientationAware ? mViewport.orientation : DISPLAY_ORIENTATION_0; if (isPerWindowInputRotationEnabled()) { // When per-window input rotation is enabled, InputReader works in the un-rotated // coordinate space, so we don't need to do anything if the device is already // orientation-aware. If the device is not orientation-aware, then we need to apply // the inverse rotation of the display so that when the display rotation is applied // later as a part of the per-window transform, we get the expected screen // coordinates. mSurfaceOrientation = mParameters.orientationAware ? DISPLAY_ORIENTATION_0 : getInverseRotation(mViewport.orientation); } else { mSurfaceOrientation = mParameters.orientationAware ? mViewport.orientation : DISPLAY_ORIENTATION_0; } } else { mPhysicalWidth = rawWidth; mPhysicalHeight = rawHeight; Loading Loading @@ -1637,10 +1673,9 @@ void TouchInputMapper::updateTouchSpots() { mPointerController->fade(PointerControllerInterface::Transition::GRADUAL); mPointerController->setButtonState(mCurrentRawState.buttonState); mPointerController->setSpots(mCurrentCookedState.cookedPointerData.pointerCoords, setTouchSpots(mCurrentCookedState.cookedPointerData.pointerCoords, mCurrentCookedState.cookedPointerData.idToIndex, mCurrentCookedState.cookedPointerData.touchingIdBits, mViewport.displayId); mCurrentCookedState.cookedPointerData.touchingIdBits, mViewport.displayId); } bool TouchInputMapper::isTouchScreen() { Loading Loading @@ -2378,10 +2413,9 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, nsecs_t readTime, u } if (mPointerGesture.currentGestureMode == PointerGesture::Mode::FREEFORM) { mPointerController->setSpots(mPointerGesture.currentGestureCoords, setTouchSpots(mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex, mPointerGesture.currentGestureIdBits, mPointerController->getDisplayId()); mPointerGesture.currentGestureIdBits, mPointerController->getDisplayId()); } } else { mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER); Loading Loading @@ -2525,8 +2559,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, nsecs_t readTime, u // the pointer is hovering again even if the user is not currently touching // the touch pad. This ensures that a view will receive a fresh hover enter // event after a tap. float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); PointerProperties pointerProperties; pointerProperties.clear(); Loading Loading @@ -2783,13 +2816,12 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi // Move the pointer using a relative motion. // When using spots, the click will occur at the position of the anchor // spot and all other spots will move there. mPointerController->move(deltaX, deltaY); moveMouseCursor(deltaX, deltaY); } else { mPointerVelocityControl.reset(); } float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); mPointerGesture.currentGestureMode = PointerGesture::Mode::BUTTON_CLICK_OR_DRAG; mPointerGesture.currentGestureIdBits.clear(); Loading @@ -2815,8 +2847,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mPointerGesture.lastGestureMode == PointerGesture::Mode::TAP_DRAG) && lastFingerCount == 1) { if (when <= mPointerGesture.tapDownTime + mConfig.pointerGestureTapInterval) { float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) { #if DEBUG_GESTURES Loading Loading @@ -2884,8 +2915,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mPointerGesture.currentGestureMode = PointerGesture::Mode::HOVER; if (mPointerGesture.lastGestureMode == PointerGesture::Mode::TAP) { if (when <= mPointerGesture.tapUpTime + mConfig.pointerGestureTapDragInterval) { float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) { mPointerGesture.currentGestureMode = PointerGesture::Mode::TAP_DRAG; Loading Loading @@ -2919,7 +2949,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi // Move the pointer using a relative motion. // When using spots, the hover or drag will occur at the position of the anchor spot. mPointerController->move(deltaX, deltaY); moveMouseCursor(deltaX, deltaY); } else { mPointerVelocityControl.reset(); } Loading @@ -2941,8 +2971,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi down = false; } float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); mPointerGesture.currentGestureIdBits.clear(); mPointerGesture.currentGestureIdBits.markBit(mPointerGesture.activeGestureId); Loading Loading @@ -3015,8 +3044,9 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mCurrentRawState.rawPointerData .getCentroidOfTouchingPointers(&mPointerGesture.referenceTouchX, &mPointerGesture.referenceTouchY); mPointerController->getPosition(&mPointerGesture.referenceGestureX, &mPointerGesture.referenceGestureY); auto [x, y] = getMouseCursorPosition(); mPointerGesture.referenceGestureX = x; mPointerGesture.referenceGestureY = y; } // Clear the reference deltas for fingers not yet included in the reference calculation. Loading Loading @@ -3354,14 +3384,13 @@ void TouchInputMapper::dispatchPointerStylus(nsecs_t when, nsecs_t readTime, uin if (!mCurrentCookedState.stylusIdBits.isEmpty()) { uint32_t id = mCurrentCookedState.stylusIdBits.firstMarkedBit(); uint32_t index = mCurrentCookedState.cookedPointerData.idToIndex[id]; float x = mCurrentCookedState.cookedPointerData.pointerCoords[index].getX(); float y = mCurrentCookedState.cookedPointerData.pointerCoords[index].getY(); mPointerController->setPosition(x, y); setMouseCursorPosition(mCurrentCookedState.cookedPointerData.pointerCoords[index].getX(), mCurrentCookedState.cookedPointerData.pointerCoords[index].getY()); hovering = mCurrentCookedState.cookedPointerData.hoveringIdBits.hasBit(id); down = !hovering; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); mPointerSimple.currentCoords.copyFrom( mCurrentCookedState.cookedPointerData.pointerCoords[index]); mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x); Loading Loading @@ -3402,7 +3431,7 @@ void TouchInputMapper::dispatchPointerMouse(nsecs_t when, nsecs_t readTime, uint rotateDelta(mSurfaceOrientation, &deltaX, &deltaY); mPointerVelocityControl.move(when, &deltaX, &deltaY); mPointerController->move(deltaX, deltaY); moveMouseCursor(deltaX, deltaY); } else { mPointerVelocityControl.reset(); } Loading @@ -3410,8 +3439,7 @@ void TouchInputMapper::dispatchPointerMouse(nsecs_t when, nsecs_t readTime, uint down = isPointerDown(mCurrentRawState.buttonState); hovering = !down; float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); mPointerSimple.currentCoords.copyFrom( mCurrentCookedState.cookedPointerData.pointerCoords[currentIndex]); mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x); Loading Loading @@ -3451,9 +3479,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, nsecs_t readTime, uin } int32_t displayId = mPointerController->getDisplayId(); float xCursorPosition; float yCursorPosition; mPointerController->getPosition(&xCursorPosition, &yCursorPosition); auto [xCursorPosition, yCursorPosition] = getMouseCursorPosition(); if (mPointerSimple.down && !down) { mPointerSimple.down = false; Loading Loading @@ -3619,7 +3645,9 @@ void TouchInputMapper::dispatchMotion(nsecs_t when, nsecs_t readTime, uint32_t p float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION; float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION; if (mDeviceMode == DeviceMode::POINTER) { mPointerController->getPosition(&xCursorPosition, &yCursorPosition); auto [x, y] = getMouseCursorPosition(); xCursorPosition = x; yCursorPosition = y; } const int32_t displayId = getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE); const int32_t deviceId = getDeviceId(); Loading Loading @@ -3969,4 +3997,63 @@ std::optional<int32_t> TouchInputMapper::getAssociatedDisplayId() { return std::nullopt; } void TouchInputMapper::moveMouseCursor(float dx, float dy) const { if (isPerWindowInputRotationEnabled()) { // Convert from InputReader's un-rotated coordinate space to PointerController's coordinate // space that is oriented with the viewport. rotateDelta(mViewport.orientation, &dx, &dy); } mPointerController->move(dx, dy); } std::pair<float, float> TouchInputMapper::getMouseCursorPosition() const { float x = 0; float y = 0; mPointerController->getPosition(&x, &y); if (!isPerWindowInputRotationEnabled()) return {x, y}; if (!mViewport.isValid()) return {x, y}; // Convert from PointerController's rotated coordinate space that is oriented with the viewport // to InputReader's un-rotated coordinate space. const int32_t orientation = getInverseRotation(mViewport.orientation); rotatePoint(orientation, x, y, mViewport.deviceWidth, mViewport.deviceHeight); return {x, y}; } void TouchInputMapper::setMouseCursorPosition(float x, float y) const { if (isPerWindowInputRotationEnabled() && mViewport.isValid()) { // Convert from InputReader's un-rotated coordinate space to PointerController's rotated // coordinate space that is oriented with the viewport. rotatePoint(mViewport.orientation, x, y, mRawSurfaceWidth, mRawSurfaceHeight); } mPointerController->setPosition(x, y); } void TouchInputMapper::setTouchSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, BitSet32 spotIdBits, int32_t displayId) { std::array<PointerCoords, MAX_POINTERS> outSpotCoords{}; for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) { const uint32_t index = spotIdToIndex[idBits.clearFirstMarkedBit()]; float x = spotCoords[index].getX(); float y = spotCoords[index].getY(); float pressure = spotCoords[index].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE); if (isPerWindowInputRotationEnabled()) { // Convert from InputReader's un-rotated coordinate space to PointerController's rotated // coordinate space. rotatePoint(mViewport.orientation, x, y, mRawSurfaceWidth, mRawSurfaceHeight); } outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_X, x); outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_Y, y); outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure); } mPointerController->setSpots(outSpotCoords.data(), spotIdToIndex, spotIdBits, displayId); } } // namespace android services/inputflinger/reader/mapper/TouchInputMapper.h +8 −0 Original line number Diff line number Diff line Loading @@ -776,6 +776,14 @@ private: const char* modeToString(DeviceMode deviceMode); void rotateAndScale(float& x, float& y); // Wrapper methods for interfacing with PointerController. These are used to convert points // between the coordinate spaces used by InputReader and PointerController, if they differ. void moveMouseCursor(float dx, float dy) const; std::pair<float, float> getMouseCursorPosition() const; void setMouseCursorPosition(float x, float y) const; void setTouchSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, BitSet32 spotIdBits, int32_t displayId); }; } // namespace android Loading Loading
services/inputflinger/reader/mapper/CursorInputMapper.cpp +34 −11 Original line number Diff line number Diff line Loading @@ -188,13 +188,31 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration* if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) { mOrientation = DISPLAY_ORIENTATION_0; if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) { const bool isOrientedDevice = (mParameters.orientationAware && mParameters.hasAssociatedDisplay); if (isPerWindowInputRotationEnabled()) { // When per-window input rotation is enabled, InputReader works in the un-rotated // coordinate space, so we don't need to do anything if the device is already // orientation-aware. If the device is not orientation-aware, then we need to apply the // inverse rotation of the display so that when the display rotation is applied later // as a part of the per-window transform, we get the expected screen coordinates. if (!isOrientedDevice) { std::optional<DisplayViewport> internalViewport = config->getDisplayViewportByType(ViewportType::INTERNAL); if (internalViewport) { mOrientation = getInverseRotation(internalViewport->orientation); } } } else { if (isOrientedDevice) { std::optional<DisplayViewport> internalViewport = config->getDisplayViewportByType(ViewportType::INTERNAL); if (internalViewport) { mOrientation = internalViewport->orientation; } } } bumpGeneration(); } Loading Loading @@ -294,11 +312,8 @@ void CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) { float deltaY = mCursorMotionAccumulator.getRelativeY() * mYScale; bool moved = deltaX != 0 || deltaY != 0; // Rotate delta according to orientation if needed. if (mParameters.orientationAware && mParameters.hasAssociatedDisplay && (deltaX != 0.0f || deltaY != 0.0f)) { // Rotate delta according to orientation. rotateDelta(mOrientation, &deltaX, &deltaY); } // Move the pointer. PointerProperties pointerProperties; Loading Loading @@ -326,7 +341,15 @@ void CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) { mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER); if (moved) { mPointerController->move(deltaX, deltaY); float dx = deltaX; float dy = deltaY; if (isPerWindowInputRotationEnabled()) { // 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); } if (buttonsChanged) { Loading
services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h +21 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #ifndef _UI_INPUTREADER_TOUCH_CURSOR_INPUT_MAPPER_COMMON_H #define _UI_INPUTREADER_TOUCH_CURSOR_INPUT_MAPPER_COMMON_H #include <android-base/properties.h> #include <input/DisplayViewport.h> #include <stdint.h> Loading @@ -28,6 +29,26 @@ namespace android { // --- Static Definitions --- // When per-window input rotation is enabled, display transformations such as rotation and // projection are part of the input window's transform. This means InputReader should work in the // un-rotated coordinate space. static bool isPerWindowInputRotationEnabled() { static const bool PER_WINDOW_INPUT_ROTATION = base::GetBoolProperty("persist.debug.per_window_input_rotation", false); return PER_WINDOW_INPUT_ROTATION; } static int32_t getInverseRotation(int32_t orientation) { switch (orientation) { case DISPLAY_ORIENTATION_90: return DISPLAY_ORIENTATION_270; case DISPLAY_ORIENTATION_270: return DISPLAY_ORIENTATION_90; default: return orientation; } } static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) { float temp; switch (orientation) { Loading
services/inputflinger/reader/mapper/TouchInputMapper.cpp +122 −35 Original line number Diff line number Diff line Loading @@ -28,6 +28,30 @@ namespace android { namespace { // Rotates the given point (x, y) by the supplied orientation. The width and height are the // dimensions of the surface prior to this rotation being applied. void rotatePoint(int32_t orientation, float& x, float& y, int32_t width, int32_t height) { rotateDelta(orientation, &x, &y); switch (orientation) { case DISPLAY_ORIENTATION_90: y += width; break; case DISPLAY_ORIENTATION_180: x += width; y += height; break; case DISPLAY_ORIENTATION_270: x += height; break; default: break; } } } // namespace // --- Constants --- // Maximum amount of latency to add to touch events while waiting for data from an Loading Loading @@ -729,8 +753,20 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { mSurfaceRight = mSurfaceLeft + naturalLogicalWidth; mSurfaceBottom = mSurfaceTop + naturalLogicalHeight; mSurfaceOrientation = mParameters.orientationAware ? mViewport.orientation : DISPLAY_ORIENTATION_0; if (isPerWindowInputRotationEnabled()) { // When per-window input rotation is enabled, InputReader works in the un-rotated // coordinate space, so we don't need to do anything if the device is already // orientation-aware. If the device is not orientation-aware, then we need to apply // the inverse rotation of the display so that when the display rotation is applied // later as a part of the per-window transform, we get the expected screen // coordinates. mSurfaceOrientation = mParameters.orientationAware ? DISPLAY_ORIENTATION_0 : getInverseRotation(mViewport.orientation); } else { mSurfaceOrientation = mParameters.orientationAware ? mViewport.orientation : DISPLAY_ORIENTATION_0; } } else { mPhysicalWidth = rawWidth; mPhysicalHeight = rawHeight; Loading Loading @@ -1637,10 +1673,9 @@ void TouchInputMapper::updateTouchSpots() { mPointerController->fade(PointerControllerInterface::Transition::GRADUAL); mPointerController->setButtonState(mCurrentRawState.buttonState); mPointerController->setSpots(mCurrentCookedState.cookedPointerData.pointerCoords, setTouchSpots(mCurrentCookedState.cookedPointerData.pointerCoords, mCurrentCookedState.cookedPointerData.idToIndex, mCurrentCookedState.cookedPointerData.touchingIdBits, mViewport.displayId); mCurrentCookedState.cookedPointerData.touchingIdBits, mViewport.displayId); } bool TouchInputMapper::isTouchScreen() { Loading Loading @@ -2378,10 +2413,9 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, nsecs_t readTime, u } if (mPointerGesture.currentGestureMode == PointerGesture::Mode::FREEFORM) { mPointerController->setSpots(mPointerGesture.currentGestureCoords, setTouchSpots(mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex, mPointerGesture.currentGestureIdBits, mPointerController->getDisplayId()); mPointerGesture.currentGestureIdBits, mPointerController->getDisplayId()); } } else { mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER); Loading Loading @@ -2525,8 +2559,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, nsecs_t readTime, u // the pointer is hovering again even if the user is not currently touching // the touch pad. This ensures that a view will receive a fresh hover enter // event after a tap. float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); PointerProperties pointerProperties; pointerProperties.clear(); Loading Loading @@ -2783,13 +2816,12 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi // Move the pointer using a relative motion. // When using spots, the click will occur at the position of the anchor // spot and all other spots will move there. mPointerController->move(deltaX, deltaY); moveMouseCursor(deltaX, deltaY); } else { mPointerVelocityControl.reset(); } float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); mPointerGesture.currentGestureMode = PointerGesture::Mode::BUTTON_CLICK_OR_DRAG; mPointerGesture.currentGestureIdBits.clear(); Loading @@ -2815,8 +2847,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mPointerGesture.lastGestureMode == PointerGesture::Mode::TAP_DRAG) && lastFingerCount == 1) { if (when <= mPointerGesture.tapDownTime + mConfig.pointerGestureTapInterval) { float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) { #if DEBUG_GESTURES Loading Loading @@ -2884,8 +2915,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mPointerGesture.currentGestureMode = PointerGesture::Mode::HOVER; if (mPointerGesture.lastGestureMode == PointerGesture::Mode::TAP) { if (when <= mPointerGesture.tapUpTime + mConfig.pointerGestureTapDragInterval) { float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) { mPointerGesture.currentGestureMode = PointerGesture::Mode::TAP_DRAG; Loading Loading @@ -2919,7 +2949,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi // Move the pointer using a relative motion. // When using spots, the hover or drag will occur at the position of the anchor spot. mPointerController->move(deltaX, deltaY); moveMouseCursor(deltaX, deltaY); } else { mPointerVelocityControl.reset(); } Loading @@ -2941,8 +2971,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi down = false; } float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); mPointerGesture.currentGestureIdBits.clear(); mPointerGesture.currentGestureIdBits.markBit(mPointerGesture.activeGestureId); Loading Loading @@ -3015,8 +3044,9 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mCurrentRawState.rawPointerData .getCentroidOfTouchingPointers(&mPointerGesture.referenceTouchX, &mPointerGesture.referenceTouchY); mPointerController->getPosition(&mPointerGesture.referenceGestureX, &mPointerGesture.referenceGestureY); auto [x, y] = getMouseCursorPosition(); mPointerGesture.referenceGestureX = x; mPointerGesture.referenceGestureY = y; } // Clear the reference deltas for fingers not yet included in the reference calculation. Loading Loading @@ -3354,14 +3384,13 @@ void TouchInputMapper::dispatchPointerStylus(nsecs_t when, nsecs_t readTime, uin if (!mCurrentCookedState.stylusIdBits.isEmpty()) { uint32_t id = mCurrentCookedState.stylusIdBits.firstMarkedBit(); uint32_t index = mCurrentCookedState.cookedPointerData.idToIndex[id]; float x = mCurrentCookedState.cookedPointerData.pointerCoords[index].getX(); float y = mCurrentCookedState.cookedPointerData.pointerCoords[index].getY(); mPointerController->setPosition(x, y); setMouseCursorPosition(mCurrentCookedState.cookedPointerData.pointerCoords[index].getX(), mCurrentCookedState.cookedPointerData.pointerCoords[index].getY()); hovering = mCurrentCookedState.cookedPointerData.hoveringIdBits.hasBit(id); down = !hovering; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); mPointerSimple.currentCoords.copyFrom( mCurrentCookedState.cookedPointerData.pointerCoords[index]); mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x); Loading Loading @@ -3402,7 +3431,7 @@ void TouchInputMapper::dispatchPointerMouse(nsecs_t when, nsecs_t readTime, uint rotateDelta(mSurfaceOrientation, &deltaX, &deltaY); mPointerVelocityControl.move(when, &deltaX, &deltaY); mPointerController->move(deltaX, deltaY); moveMouseCursor(deltaX, deltaY); } else { mPointerVelocityControl.reset(); } Loading @@ -3410,8 +3439,7 @@ void TouchInputMapper::dispatchPointerMouse(nsecs_t when, nsecs_t readTime, uint down = isPointerDown(mCurrentRawState.buttonState); hovering = !down; float x, y; mPointerController->getPosition(&x, &y); auto [x, y] = getMouseCursorPosition(); mPointerSimple.currentCoords.copyFrom( mCurrentCookedState.cookedPointerData.pointerCoords[currentIndex]); mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x); Loading Loading @@ -3451,9 +3479,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, nsecs_t readTime, uin } int32_t displayId = mPointerController->getDisplayId(); float xCursorPosition; float yCursorPosition; mPointerController->getPosition(&xCursorPosition, &yCursorPosition); auto [xCursorPosition, yCursorPosition] = getMouseCursorPosition(); if (mPointerSimple.down && !down) { mPointerSimple.down = false; Loading Loading @@ -3619,7 +3645,9 @@ void TouchInputMapper::dispatchMotion(nsecs_t when, nsecs_t readTime, uint32_t p float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION; float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION; if (mDeviceMode == DeviceMode::POINTER) { mPointerController->getPosition(&xCursorPosition, &yCursorPosition); auto [x, y] = getMouseCursorPosition(); xCursorPosition = x; yCursorPosition = y; } const int32_t displayId = getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE); const int32_t deviceId = getDeviceId(); Loading Loading @@ -3969,4 +3997,63 @@ std::optional<int32_t> TouchInputMapper::getAssociatedDisplayId() { return std::nullopt; } void TouchInputMapper::moveMouseCursor(float dx, float dy) const { if (isPerWindowInputRotationEnabled()) { // Convert from InputReader's un-rotated coordinate space to PointerController's coordinate // space that is oriented with the viewport. rotateDelta(mViewport.orientation, &dx, &dy); } mPointerController->move(dx, dy); } std::pair<float, float> TouchInputMapper::getMouseCursorPosition() const { float x = 0; float y = 0; mPointerController->getPosition(&x, &y); if (!isPerWindowInputRotationEnabled()) return {x, y}; if (!mViewport.isValid()) return {x, y}; // Convert from PointerController's rotated coordinate space that is oriented with the viewport // to InputReader's un-rotated coordinate space. const int32_t orientation = getInverseRotation(mViewport.orientation); rotatePoint(orientation, x, y, mViewport.deviceWidth, mViewport.deviceHeight); return {x, y}; } void TouchInputMapper::setMouseCursorPosition(float x, float y) const { if (isPerWindowInputRotationEnabled() && mViewport.isValid()) { // Convert from InputReader's un-rotated coordinate space to PointerController's rotated // coordinate space that is oriented with the viewport. rotatePoint(mViewport.orientation, x, y, mRawSurfaceWidth, mRawSurfaceHeight); } mPointerController->setPosition(x, y); } void TouchInputMapper::setTouchSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, BitSet32 spotIdBits, int32_t displayId) { std::array<PointerCoords, MAX_POINTERS> outSpotCoords{}; for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) { const uint32_t index = spotIdToIndex[idBits.clearFirstMarkedBit()]; float x = spotCoords[index].getX(); float y = spotCoords[index].getY(); float pressure = spotCoords[index].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE); if (isPerWindowInputRotationEnabled()) { // Convert from InputReader's un-rotated coordinate space to PointerController's rotated // coordinate space. rotatePoint(mViewport.orientation, x, y, mRawSurfaceWidth, mRawSurfaceHeight); } outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_X, x); outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_Y, y); outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure); } mPointerController->setSpots(outSpotCoords.data(), spotIdToIndex, spotIdBits, displayId); } } // namespace android
services/inputflinger/reader/mapper/TouchInputMapper.h +8 −0 Original line number Diff line number Diff line Loading @@ -776,6 +776,14 @@ private: const char* modeToString(DeviceMode deviceMode); void rotateAndScale(float& x, float& y); // Wrapper methods for interfacing with PointerController. These are used to convert points // between the coordinate spaces used by InputReader and PointerController, if they differ. void moveMouseCursor(float dx, float dy) const; std::pair<float, float> getMouseCursorPosition() const; void setMouseCursorPosition(float x, float y) const; void setTouchSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, BitSet32 spotIdBits, int32_t displayId); }; } // namespace android Loading