Loading services/inputflinger/PointerChoreographer.cpp +22 −25 Original line number Diff line number Diff line Loading @@ -64,8 +64,7 @@ bool isMouseOrTouchpad(uint32_t sources) { !isFromSource(sources, AINPUT_SOURCE_STYLUS)); } inline void notifyPointerDisplayChange( std::optional<std::tuple<ui::LogicalDisplayId, FloatPoint>> change, inline void notifyPointerDisplayChange(std::optional<std::tuple<ui::LogicalDisplayId, vec2>> change, PointerChoreographerPolicyInterface& policy) { if (!change) { return; Loading Loading @@ -245,9 +244,9 @@ NotifyMotionArgs PointerChoreographer::processMouseEventLocked(const NotifyMotio if (MotionEvent::isValidCursorPosition(args.xCursorPosition, args.yCursorPosition)) { // This is an absolute mouse device that knows about the location of the cursor on the // display, so set the cursor position to the specified location. const auto [x, y] = pc.getPosition(); const float deltaX = args.xCursorPosition - x; const float deltaY = args.yCursorPosition - y; const auto position = pc.getPosition(); const float deltaX = args.xCursorPosition - position.x; const float deltaY = args.yCursorPosition - position.y; newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX); newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY); pc.setPosition(args.xCursorPosition, args.yCursorPosition); Loading @@ -273,15 +272,15 @@ NotifyMotionArgs PointerChoreographer::processTouchpadEventLocked(const NotifyMo processPointerDeviceMotionEventLocked(/*byref*/ newArgs, /*byref*/ pc); } else { // This is a trackpad gesture with fake finger(s) that should not move the mouse pointer. const auto [x, y] = pc.getPosition(); const auto position = pc.getPosition(); for (uint32_t i = 0; i < newArgs.getPointerCount(); i++) { newArgs.pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, args.pointerCoords[i].getX() + x); args.pointerCoords[i].getX() + position.x); newArgs.pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, args.pointerCoords[i].getY() + y); args.pointerCoords[i].getY() + position.y); } newArgs.xCursorPosition = x; newArgs.yCursorPosition = y; newArgs.xCursorPosition = position.x; newArgs.yCursorPosition = position.y; } // Note displayId may have changed if the cursor moved to a different display Loading @@ -296,7 +295,7 @@ void PointerChoreographer::processPointerDeviceMotionEventLocked(NotifyMotionArg const float deltaX = newArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X); const float deltaY = newArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y); FloatPoint unconsumedDelta = pc.move(deltaX, deltaY); vec2 unconsumedDelta = pc.move(deltaX, deltaY); if (com::android::input::flags::connected_displays_cursor() && (std::abs(unconsumedDelta.x) > 0 || std::abs(unconsumedDelta.y) > 0)) { handleUnconsumedDeltaLocked(pc, unconsumedDelta); Loading @@ -304,25 +303,23 @@ void PointerChoreographer::processPointerDeviceMotionEventLocked(NotifyMotionArg newArgs.displayId = pc.getDisplayId(); } const auto [x, y] = pc.getPosition(); newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x); newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y); newArgs.xCursorPosition = x; newArgs.yCursorPosition = y; const auto position = pc.getPosition(); newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, position.x); newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, position.y); newArgs.xCursorPosition = position.x; newArgs.yCursorPosition = position.y; } void PointerChoreographer::handleUnconsumedDeltaLocked(PointerControllerInterface& pc, const FloatPoint& unconsumedDelta) { const vec2& unconsumedDelta) { // Display topology is in rotated coordinate space and Pointer controller returns and expects // values in the un-rotated coordinate space. So we need to transform delta and cursor position // back to the rotated coordinate space to lookup adjacent display in the display topology. const auto& sourceDisplayTransform = pc.getDisplayTransform(); const vec2 rotatedUnconsumedDelta = transformWithoutTranslation(sourceDisplayTransform, {unconsumedDelta.x, unconsumedDelta.y}); const FloatPoint cursorPosition = pc.getPosition(); const vec2 rotatedCursorPosition = sourceDisplayTransform.transform(cursorPosition.x, cursorPosition.y); transformWithoutTranslation(sourceDisplayTransform, unconsumedDelta); const vec2 cursorPosition = pc.getPosition(); const vec2 rotatedCursorPosition = sourceDisplayTransform.transform(cursorPosition); // To find out the boundary that cursor is crossing we are checking delta in x and y direction // respectively. This prioritizes x direction over y. Loading Loading @@ -769,7 +766,7 @@ PointerChoreographer::PointerDisplayChange PointerChoreographer::updatePointerCo PointerChoreographer::PointerDisplayChange PointerChoreographer::calculatePointerDisplayChangeToNotify() { ui::LogicalDisplayId displayIdToNotify = ui::LogicalDisplayId::INVALID; FloatPoint cursorPosition = {0, 0}; vec2 cursorPosition = {0, 0}; if (const auto it = mMousePointersByDisplay.find(mDefaultMouseDisplayId); it != mMousePointersByDisplay.end()) { const auto& pointerController = it->second; Loading Loading @@ -840,7 +837,7 @@ std::optional<DisplayViewport> PointerChoreographer::getViewportForPointerDevice return std::nullopt; } FloatPoint PointerChoreographer::getMouseCursorPosition(ui::LogicalDisplayId displayId) { vec2 PointerChoreographer::getMouseCursorPosition(ui::LogicalDisplayId displayId) { std::scoped_lock _l(getLock()); const ui::LogicalDisplayId resolvedDisplayId = getTargetMouseDisplayLocked(displayId); if (auto it = mMousePointersByDisplay.find(resolvedDisplayId); Loading services/inputflinger/PointerChoreographer.h +6 −6 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ public: virtual void setDisplayViewports(const std::vector<DisplayViewport>& viewports) = 0; virtual std::optional<DisplayViewport> getViewportForPointerDevice( ui::LogicalDisplayId associatedDisplayId = ui::LogicalDisplayId::INVALID) = 0; virtual FloatPoint getMouseCursorPosition(ui::LogicalDisplayId displayId) = 0; virtual vec2 getMouseCursorPosition(ui::LogicalDisplayId displayId) = 0; virtual void setShowTouchesEnabled(bool enabled) = 0; virtual void setStylusPointerIconEnabled(bool enabled) = 0; /** Loading Loading @@ -96,7 +96,7 @@ public: void setDisplayViewports(const std::vector<DisplayViewport>& viewports) override; std::optional<DisplayViewport> getViewportForPointerDevice( ui::LogicalDisplayId associatedDisplayId) override; FloatPoint getMouseCursorPosition(ui::LogicalDisplayId displayId) override; vec2 getMouseCursorPosition(ui::LogicalDisplayId displayId) override; void setShowTouchesEnabled(bool enabled) override; void setStylusPointerIconEnabled(bool enabled) override; bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, Loading Loading @@ -134,8 +134,8 @@ public: void dump(std::string& dump) override; private: using PointerDisplayChange = std::optional< std::tuple<ui::LogicalDisplayId /*displayId*/, FloatPoint /*cursorPosition*/>>; using PointerDisplayChange = std::optional<std::tuple<ui::LogicalDisplayId /*displayId*/, vec2 /*cursorPosition*/>>; // PointerChoreographer's DisplayInfoListener can outlive the PointerChoreographer because when // the listener is registered and called from display thread, a strong pointer to the listener Loading Loading @@ -171,8 +171,8 @@ private: const std::unordered_set<ui::LogicalDisplayId>& privacySensitiveDisplays) REQUIRES(getLock()); void handleUnconsumedDeltaLocked(PointerControllerInterface& pc, const FloatPoint& unconsumedDelta) REQUIRES(getLock()); void handleUnconsumedDeltaLocked(PointerControllerInterface& pc, const vec2& unconsumedDelta) REQUIRES(getLock()); void populateFakeDisplayTopologyLocked(const std::vector<gui::DisplayInfo>& displayInfos) REQUIRES(getLock()); Loading services/inputflinger/include/PointerChoreographerPolicyInterface.h +1 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public: * @param position The new position of the mouse cursor on the logical display */ virtual void notifyPointerDisplayIdChanged(ui::LogicalDisplayId displayId, const FloatPoint& position) = 0; const vec2& position) = 0; /* Returns true if any InputConnection is currently active. */ virtual bool isInputMethodConnectionActive() = 0; Loading services/inputflinger/include/PointerControllerInterface.h +2 −16 Original line number Diff line number Diff line Loading @@ -24,20 +24,6 @@ namespace android { struct SpriteIcon; struct FloatPoint { float x; float y; inline FloatPoint(float x, float y) : x(x), y(y) {} inline explicit FloatPoint(vec2 p) : x(p.x), y(p.y) {} template <typename T, typename U> operator std::tuple<T, U>() { return {x, y}; } }; /** * Interface for tracking a mouse / touch pad pointer and touch pad spots. * Loading Loading @@ -77,13 +63,13 @@ public: * * Return value may be used to move pointer to corresponding adjacent display, if it exists in * the display-topology */ [[nodiscard]] virtual FloatPoint move(float deltaX, float deltaY) = 0; [[nodiscard]] virtual vec2 move(float deltaX, float deltaY) = 0; /* Sets the absolute location of the pointer. */ virtual void setPosition(float x, float y) = 0; /* Gets the absolute location of the pointer. */ virtual FloatPoint getPosition() const = 0; virtual vec2 getPosition() const = 0; enum class Transition { // Fade/unfade immediately. Loading services/inputflinger/tests/FakePointerController.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ void FakePointerController::setPosition(float x, float y) { mY = y; } FloatPoint FakePointerController::getPosition() const { vec2 FakePointerController::getPosition() const { if (!mEnabled) { return {0, 0}; } Loading Loading @@ -96,9 +96,9 @@ void FakePointerController::assertViewportNotSet() { } void FakePointerController::assertPosition(float x, float y) { const auto [actualX, actualY] = getPosition(); ASSERT_NEAR(x, actualX, 1); ASSERT_NEAR(y, actualY, 1); const auto actual = getPosition(); ASSERT_NEAR(x, actual.x, 1); ASSERT_NEAR(y, actual.y, 1); } void FakePointerController::assertSpotCount(ui::LogicalDisplayId displayId, int32_t count) { Loading Loading @@ -148,13 +148,13 @@ bool FakePointerController::isPointerShown() { return mIsPointerShown; } FloatPoint FakePointerController::move(float deltaX, float deltaY) { vec2 FakePointerController::move(float deltaX, float deltaY) { if (!mEnabled) return {0, 0}; mX += deltaX; mY += deltaY; const FloatPoint position(mX, mY); const vec2 position(mX, mY); if (mX < mMinX) mX = mMinX; if (mX > mMaxX) mX = mMaxX; Loading Loading
services/inputflinger/PointerChoreographer.cpp +22 −25 Original line number Diff line number Diff line Loading @@ -64,8 +64,7 @@ bool isMouseOrTouchpad(uint32_t sources) { !isFromSource(sources, AINPUT_SOURCE_STYLUS)); } inline void notifyPointerDisplayChange( std::optional<std::tuple<ui::LogicalDisplayId, FloatPoint>> change, inline void notifyPointerDisplayChange(std::optional<std::tuple<ui::LogicalDisplayId, vec2>> change, PointerChoreographerPolicyInterface& policy) { if (!change) { return; Loading Loading @@ -245,9 +244,9 @@ NotifyMotionArgs PointerChoreographer::processMouseEventLocked(const NotifyMotio if (MotionEvent::isValidCursorPosition(args.xCursorPosition, args.yCursorPosition)) { // This is an absolute mouse device that knows about the location of the cursor on the // display, so set the cursor position to the specified location. const auto [x, y] = pc.getPosition(); const float deltaX = args.xCursorPosition - x; const float deltaY = args.yCursorPosition - y; const auto position = pc.getPosition(); const float deltaX = args.xCursorPosition - position.x; const float deltaY = args.yCursorPosition - position.y; newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX); newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY); pc.setPosition(args.xCursorPosition, args.yCursorPosition); Loading @@ -273,15 +272,15 @@ NotifyMotionArgs PointerChoreographer::processTouchpadEventLocked(const NotifyMo processPointerDeviceMotionEventLocked(/*byref*/ newArgs, /*byref*/ pc); } else { // This is a trackpad gesture with fake finger(s) that should not move the mouse pointer. const auto [x, y] = pc.getPosition(); const auto position = pc.getPosition(); for (uint32_t i = 0; i < newArgs.getPointerCount(); i++) { newArgs.pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, args.pointerCoords[i].getX() + x); args.pointerCoords[i].getX() + position.x); newArgs.pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, args.pointerCoords[i].getY() + y); args.pointerCoords[i].getY() + position.y); } newArgs.xCursorPosition = x; newArgs.yCursorPosition = y; newArgs.xCursorPosition = position.x; newArgs.yCursorPosition = position.y; } // Note displayId may have changed if the cursor moved to a different display Loading @@ -296,7 +295,7 @@ void PointerChoreographer::processPointerDeviceMotionEventLocked(NotifyMotionArg const float deltaX = newArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X); const float deltaY = newArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y); FloatPoint unconsumedDelta = pc.move(deltaX, deltaY); vec2 unconsumedDelta = pc.move(deltaX, deltaY); if (com::android::input::flags::connected_displays_cursor() && (std::abs(unconsumedDelta.x) > 0 || std::abs(unconsumedDelta.y) > 0)) { handleUnconsumedDeltaLocked(pc, unconsumedDelta); Loading @@ -304,25 +303,23 @@ void PointerChoreographer::processPointerDeviceMotionEventLocked(NotifyMotionArg newArgs.displayId = pc.getDisplayId(); } const auto [x, y] = pc.getPosition(); newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x); newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y); newArgs.xCursorPosition = x; newArgs.yCursorPosition = y; const auto position = pc.getPosition(); newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, position.x); newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, position.y); newArgs.xCursorPosition = position.x; newArgs.yCursorPosition = position.y; } void PointerChoreographer::handleUnconsumedDeltaLocked(PointerControllerInterface& pc, const FloatPoint& unconsumedDelta) { const vec2& unconsumedDelta) { // Display topology is in rotated coordinate space and Pointer controller returns and expects // values in the un-rotated coordinate space. So we need to transform delta and cursor position // back to the rotated coordinate space to lookup adjacent display in the display topology. const auto& sourceDisplayTransform = pc.getDisplayTransform(); const vec2 rotatedUnconsumedDelta = transformWithoutTranslation(sourceDisplayTransform, {unconsumedDelta.x, unconsumedDelta.y}); const FloatPoint cursorPosition = pc.getPosition(); const vec2 rotatedCursorPosition = sourceDisplayTransform.transform(cursorPosition.x, cursorPosition.y); transformWithoutTranslation(sourceDisplayTransform, unconsumedDelta); const vec2 cursorPosition = pc.getPosition(); const vec2 rotatedCursorPosition = sourceDisplayTransform.transform(cursorPosition); // To find out the boundary that cursor is crossing we are checking delta in x and y direction // respectively. This prioritizes x direction over y. Loading Loading @@ -769,7 +766,7 @@ PointerChoreographer::PointerDisplayChange PointerChoreographer::updatePointerCo PointerChoreographer::PointerDisplayChange PointerChoreographer::calculatePointerDisplayChangeToNotify() { ui::LogicalDisplayId displayIdToNotify = ui::LogicalDisplayId::INVALID; FloatPoint cursorPosition = {0, 0}; vec2 cursorPosition = {0, 0}; if (const auto it = mMousePointersByDisplay.find(mDefaultMouseDisplayId); it != mMousePointersByDisplay.end()) { const auto& pointerController = it->second; Loading Loading @@ -840,7 +837,7 @@ std::optional<DisplayViewport> PointerChoreographer::getViewportForPointerDevice return std::nullopt; } FloatPoint PointerChoreographer::getMouseCursorPosition(ui::LogicalDisplayId displayId) { vec2 PointerChoreographer::getMouseCursorPosition(ui::LogicalDisplayId displayId) { std::scoped_lock _l(getLock()); const ui::LogicalDisplayId resolvedDisplayId = getTargetMouseDisplayLocked(displayId); if (auto it = mMousePointersByDisplay.find(resolvedDisplayId); Loading
services/inputflinger/PointerChoreographer.h +6 −6 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ public: virtual void setDisplayViewports(const std::vector<DisplayViewport>& viewports) = 0; virtual std::optional<DisplayViewport> getViewportForPointerDevice( ui::LogicalDisplayId associatedDisplayId = ui::LogicalDisplayId::INVALID) = 0; virtual FloatPoint getMouseCursorPosition(ui::LogicalDisplayId displayId) = 0; virtual vec2 getMouseCursorPosition(ui::LogicalDisplayId displayId) = 0; virtual void setShowTouchesEnabled(bool enabled) = 0; virtual void setStylusPointerIconEnabled(bool enabled) = 0; /** Loading Loading @@ -96,7 +96,7 @@ public: void setDisplayViewports(const std::vector<DisplayViewport>& viewports) override; std::optional<DisplayViewport> getViewportForPointerDevice( ui::LogicalDisplayId associatedDisplayId) override; FloatPoint getMouseCursorPosition(ui::LogicalDisplayId displayId) override; vec2 getMouseCursorPosition(ui::LogicalDisplayId displayId) override; void setShowTouchesEnabled(bool enabled) override; void setStylusPointerIconEnabled(bool enabled) override; bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, Loading Loading @@ -134,8 +134,8 @@ public: void dump(std::string& dump) override; private: using PointerDisplayChange = std::optional< std::tuple<ui::LogicalDisplayId /*displayId*/, FloatPoint /*cursorPosition*/>>; using PointerDisplayChange = std::optional<std::tuple<ui::LogicalDisplayId /*displayId*/, vec2 /*cursorPosition*/>>; // PointerChoreographer's DisplayInfoListener can outlive the PointerChoreographer because when // the listener is registered and called from display thread, a strong pointer to the listener Loading Loading @@ -171,8 +171,8 @@ private: const std::unordered_set<ui::LogicalDisplayId>& privacySensitiveDisplays) REQUIRES(getLock()); void handleUnconsumedDeltaLocked(PointerControllerInterface& pc, const FloatPoint& unconsumedDelta) REQUIRES(getLock()); void handleUnconsumedDeltaLocked(PointerControllerInterface& pc, const vec2& unconsumedDelta) REQUIRES(getLock()); void populateFakeDisplayTopologyLocked(const std::vector<gui::DisplayInfo>& displayInfos) REQUIRES(getLock()); Loading
services/inputflinger/include/PointerChoreographerPolicyInterface.h +1 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public: * @param position The new position of the mouse cursor on the logical display */ virtual void notifyPointerDisplayIdChanged(ui::LogicalDisplayId displayId, const FloatPoint& position) = 0; const vec2& position) = 0; /* Returns true if any InputConnection is currently active. */ virtual bool isInputMethodConnectionActive() = 0; Loading
services/inputflinger/include/PointerControllerInterface.h +2 −16 Original line number Diff line number Diff line Loading @@ -24,20 +24,6 @@ namespace android { struct SpriteIcon; struct FloatPoint { float x; float y; inline FloatPoint(float x, float y) : x(x), y(y) {} inline explicit FloatPoint(vec2 p) : x(p.x), y(p.y) {} template <typename T, typename U> operator std::tuple<T, U>() { return {x, y}; } }; /** * Interface for tracking a mouse / touch pad pointer and touch pad spots. * Loading Loading @@ -77,13 +63,13 @@ public: * * Return value may be used to move pointer to corresponding adjacent display, if it exists in * the display-topology */ [[nodiscard]] virtual FloatPoint move(float deltaX, float deltaY) = 0; [[nodiscard]] virtual vec2 move(float deltaX, float deltaY) = 0; /* Sets the absolute location of the pointer. */ virtual void setPosition(float x, float y) = 0; /* Gets the absolute location of the pointer. */ virtual FloatPoint getPosition() const = 0; virtual vec2 getPosition() const = 0; enum class Transition { // Fade/unfade immediately. Loading
services/inputflinger/tests/FakePointerController.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ void FakePointerController::setPosition(float x, float y) { mY = y; } FloatPoint FakePointerController::getPosition() const { vec2 FakePointerController::getPosition() const { if (!mEnabled) { return {0, 0}; } Loading Loading @@ -96,9 +96,9 @@ void FakePointerController::assertViewportNotSet() { } void FakePointerController::assertPosition(float x, float y) { const auto [actualX, actualY] = getPosition(); ASSERT_NEAR(x, actualX, 1); ASSERT_NEAR(y, actualY, 1); const auto actual = getPosition(); ASSERT_NEAR(x, actual.x, 1); ASSERT_NEAR(y, actual.y, 1); } void FakePointerController::assertSpotCount(ui::LogicalDisplayId displayId, int32_t count) { Loading Loading @@ -148,13 +148,13 @@ bool FakePointerController::isPointerShown() { return mIsPointerShown; } FloatPoint FakePointerController::move(float deltaX, float deltaY) { vec2 FakePointerController::move(float deltaX, float deltaY) { if (!mEnabled) return {0, 0}; mX += deltaX; mY += deltaY; const FloatPoint position(mX, mY); const vec2 position(mX, mY); if (mX < mMinX) mX = mMinX; if (mX > mMaxX) mX = mMaxX; Loading