diff options
8 files changed, 81 insertions, 103 deletions
diff --git a/services/inputflinger/PointerChoreographer.cpp b/services/inputflinger/PointerChoreographer.cpp index 8eb6bdd02f..811692f1bf 100644 --- a/services/inputflinger/PointerChoreographer.cpp +++ b/services/inputflinger/PointerChoreographer.cpp @@ -64,9 +64,8 @@ bool isMouseOrTouchpad(uint32_t sources) { !isFromSource(sources, AINPUT_SOURCE_STYLUS)); } -inline void notifyPointerDisplayChange( - std::optional<std::tuple<ui::LogicalDisplayId, FloatPoint>> change, - PointerChoreographerPolicyInterface& policy) { +inline void notifyPointerDisplayChange(std::optional<std::tuple<ui::LogicalDisplayId, vec2>> change, + PointerChoreographerPolicyInterface& policy) { if (!change) { return; } @@ -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); @@ -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 @@ -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); @@ -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. @@ -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; @@ -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); diff --git a/services/inputflinger/PointerChoreographer.h b/services/inputflinger/PointerChoreographer.h index 4ca7323bfc..939529f774 100644 --- a/services/inputflinger/PointerChoreographer.h +++ b/services/inputflinger/PointerChoreographer.h @@ -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; /** @@ -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, @@ -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 @@ -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()); diff --git a/services/inputflinger/include/PointerChoreographerPolicyInterface.h b/services/inputflinger/include/PointerChoreographerPolicyInterface.h index e1f8fdaaa0..36614b2c95 100644 --- a/services/inputflinger/include/PointerChoreographerPolicyInterface.h +++ b/services/inputflinger/include/PointerChoreographerPolicyInterface.h @@ -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; diff --git a/services/inputflinger/include/PointerControllerInterface.h b/services/inputflinger/include/PointerControllerInterface.h index abca209cec..bd464901b6 100644 --- a/services/inputflinger/include/PointerControllerInterface.h +++ b/services/inputflinger/include/PointerControllerInterface.h @@ -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. * @@ -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. diff --git a/services/inputflinger/tests/FakePointerController.cpp b/services/inputflinger/tests/FakePointerController.cpp index f53e63ba25..f033e57ddd 100644 --- a/services/inputflinger/tests/FakePointerController.cpp +++ b/services/inputflinger/tests/FakePointerController.cpp @@ -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}; } @@ -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) { @@ -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; diff --git a/services/inputflinger/tests/FakePointerController.h b/services/inputflinger/tests/FakePointerController.h index 0ee3123d35..c526bb8c59 100644 --- a/services/inputflinger/tests/FakePointerController.h +++ b/services/inputflinger/tests/FakePointerController.h @@ -40,7 +40,7 @@ public: const std::map<ui::LogicalDisplayId, std::vector<int32_t>>& getSpots(); void setPosition(float x, float y) override; - FloatPoint getPosition() const override; + vec2 getPosition() const override; ui::LogicalDisplayId getDisplayId() const override; void setDisplayViewport(const DisplayViewport& viewport) override; void updatePointerIcon(PointerIconStyle iconId) override; @@ -66,7 +66,7 @@ public: private: std::string dump() override { return ""; } - FloatPoint move(float deltaX, float deltaY) override; + vec2 move(float deltaX, float deltaY) override; void unfade(Transition) override; void setPresentation(Presentation) override {} void setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits, diff --git a/services/inputflinger/tests/InterfaceMocks.h b/services/inputflinger/tests/InterfaceMocks.h index 6f7c2e5271..ac616d0296 100644 --- a/services/inputflinger/tests/InterfaceMocks.h +++ b/services/inputflinger/tests/InterfaceMocks.h @@ -188,7 +188,7 @@ public: MOCK_METHOD(std::shared_ptr<PointerControllerInterface>, createPointerController, (PointerControllerInterface::ControllerType), (override)); MOCK_METHOD(void, notifyPointerDisplayIdChanged, - (ui::LogicalDisplayId displayId, const FloatPoint& position), (override)); + (ui::LogicalDisplayId displayId, const vec2& position), (override)); MOCK_METHOD(bool, isInputMethodConnectionActive, (), (override)); MOCK_METHOD(void, notifyMouseCursorFadedOnTyping, (), (override)); }; diff --git a/services/inputflinger/tests/PointerChoreographer_test.cpp b/services/inputflinger/tests/PointerChoreographer_test.cpp index 453c156665..27da3d33f9 100644 --- a/services/inputflinger/tests/PointerChoreographer_test.cpp +++ b/services/inputflinger/tests/PointerChoreographer_test.cpp @@ -135,7 +135,7 @@ protected: }); ON_CALL(mMockPolicy, notifyPointerDisplayIdChanged) - .WillByDefault([this](ui::LogicalDisplayId displayId, const FloatPoint& position) { + .WillByDefault([this](ui::LogicalDisplayId displayId, const vec2& position) { mPointerDisplayIdNotified = displayId; }); } @@ -2604,9 +2604,8 @@ TEST_P(PointerVisibilityAndTouchpadTapStateOnKeyPressTestFixture, TestMetaKeyCom using PointerChoreographerDisplayTopologyTestFixtureParam = std::tuple<std::string_view /*name*/, int32_t /*source device*/, ControllerType /*PointerController*/, ToolType /*pointer tool type*/, - FloatPoint /*source position*/, FloatPoint /*hover move X/Y*/, - ui::LogicalDisplayId /*destination display*/, - FloatPoint /*destination position*/>; + vec2 /*source position*/, vec2 /*hover move X/Y*/, + ui::LogicalDisplayId /*destination display*/, vec2 /*destination position*/>; class PointerChoreographerDisplayTopologyTestFixture : public PointerChoreographerTest, @@ -2708,67 +2707,63 @@ INSTANTIATE_TEST_SUITE_P( // Note: Upon viewport transition cursor will be positioned at the boundary of the // destination, as we drop any unconsumed delta. std::make_tuple("UnchangedDisplay", AINPUT_SOURCE_MOUSE, ControllerType::MOUSE, - ToolType::MOUSE, FloatPoint(50, 50) /* initial x/y */, - FloatPoint(25, 25) /* delta x/y */, + ToolType::MOUSE, vec2(50, 50) /* initial x/y */, + vec2(25, 25) /* delta x/y */, PointerChoreographerDisplayTopologyTestFixture::DISPLAY_CENTER_ID, - FloatPoint(75, 75) /* destination x/y */), - std::make_tuple( - "TransitionToRightDisplay", AINPUT_SOURCE_MOUSE, ControllerType::MOUSE, - ToolType::MOUSE, FloatPoint(50, 50) /* initial x/y */, - FloatPoint(100, 25) /* delta x/y */, - PointerChoreographerDisplayTopologyTestFixture::DISPLAY_RIGHT_ID, - FloatPoint(0, 50 + 25 - 10) /* Left edge: (0, source + delta - offset) */), + vec2(75, 75) /* destination x/y */), + std::make_tuple("TransitionToRightDisplay", AINPUT_SOURCE_MOUSE, + ControllerType::MOUSE, ToolType::MOUSE, + vec2(50, 50) /* initial x/y */, vec2(100, 25) /* delta x/y */, + PointerChoreographerDisplayTopologyTestFixture::DISPLAY_RIGHT_ID, + vec2(0, + 50 + 25 - 10) /* Left edge: (0, source + delta - offset) */), std::make_tuple( "TransitionToLeftDisplay", AINPUT_SOURCE_MOUSE, ControllerType::MOUSE, - ToolType::MOUSE, FloatPoint(50, 50) /* initial x/y */, - FloatPoint(-100, 25) /* delta x/y */, + ToolType::MOUSE, vec2(50, 50) /* initial x/y */, + vec2(-100, 25) /* delta x/y */, PointerChoreographerDisplayTopologyTestFixture::DISPLAY_LEFT_ID, - FloatPoint(90, - 50 + 25 - 10) /* Right edge: (width, source + delta - offset*/), - std::make_tuple( - "TransitionToTopDisplay", AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ControllerType::MOUSE, ToolType::FINGER, - FloatPoint(50, 50) /* initial x/y */, FloatPoint(25, -100) /* delta x/y */, - PointerChoreographerDisplayTopologyTestFixture::DISPLAY_TOP_ID, - FloatPoint(50 + 25 - 10, - 90) /* Bottom edge: (source + delta - offset, height) */), - std::make_tuple( - "TransitionToBottomDisplay", AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ControllerType::MOUSE, ToolType::FINGER, - FloatPoint(50, 50) /* initial x/y */, FloatPoint(25, 100) /* delta x/y */, - PointerChoreographerDisplayTopologyTestFixture::DISPLAY_BOTTOM_ID, - FloatPoint(50 + 25 - 10, 0) /* Top edge: (source + delta - offset, 0) */), + vec2(90, 50 + 25 - 10) /* Right edge: (width, source + delta - offset*/), + std::make_tuple("TransitionToTopDisplay", + AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, ControllerType::MOUSE, + ToolType::FINGER, vec2(50, 50) /* initial x/y */, + vec2(25, -100) /* delta x/y */, + PointerChoreographerDisplayTopologyTestFixture::DISPLAY_TOP_ID, + vec2(50 + 25 - 10, + 90) /* Bottom edge: (source + delta - offset, height) */), + std::make_tuple("TransitionToBottomDisplay", + AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, ControllerType::MOUSE, + ToolType::FINGER, vec2(50, 50) /* initial x/y */, + vec2(25, 100) /* delta x/y */, + PointerChoreographerDisplayTopologyTestFixture::DISPLAY_BOTTOM_ID, + vec2(50 + 25 - 10, 0) /* Top edge: (source + delta - offset, 0) */), std::make_tuple("NoTransitionAtTopOffset", AINPUT_SOURCE_MOUSE, ControllerType::MOUSE, ToolType::MOUSE, - FloatPoint(5, 50) /* initial x/y */, - FloatPoint(0, -100) /* Move Up */, + vec2(5, 50) /* initial x/y */, vec2(0, -100) /* Move Up */, PointerChoreographerDisplayTopologyTestFixture::DISPLAY_CENTER_ID, - FloatPoint(5, 0) /* Top edge */), + vec2(5, 0) /* Top edge */), std::make_tuple("NoTransitionAtRightOffset", AINPUT_SOURCE_MOUSE, ControllerType::MOUSE, ToolType::MOUSE, - FloatPoint(95, 5) /* initial x/y */, - FloatPoint(100, 0) /* Move Right */, + vec2(95, 5) /* initial x/y */, vec2(100, 0) /* Move Right */, PointerChoreographerDisplayTopologyTestFixture::DISPLAY_CENTER_ID, - FloatPoint(99, 5) /* Top edge */), + vec2(99, 5) /* Top edge */), std::make_tuple("NoTransitionAtBottomOffset", AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, ControllerType::MOUSE, - ToolType::FINGER, FloatPoint(5, 95) /* initial x/y */, - FloatPoint(0, 100) /* Move Down */, + ToolType::FINGER, vec2(5, 95) /* initial x/y */, + vec2(0, 100) /* Move Down */, PointerChoreographerDisplayTopologyTestFixture::DISPLAY_CENTER_ID, - FloatPoint(5, 99) /* Bottom edge */), + vec2(5, 99) /* Bottom edge */), std::make_tuple("NoTransitionAtLeftOffset", AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, ControllerType::MOUSE, - ToolType::FINGER, FloatPoint(5, 5) /* initial x/y */, - FloatPoint(-100, 0) /* Move Left */, + ToolType::FINGER, vec2(5, 5) /* initial x/y */, + vec2(-100, 0) /* Move Left */, PointerChoreographerDisplayTopologyTestFixture::DISPLAY_CENTER_ID, - FloatPoint(0, 5) /* Left edge */), + vec2(0, 5) /* Left edge */), std::make_tuple( "TransitionAtTopRightCorner", AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ControllerType::MOUSE, ToolType::FINGER, - FloatPoint(95, 5) /* initial x/y */, - FloatPoint(10, -10) /* Move dignally to top right corner */, + ControllerType::MOUSE, ToolType::FINGER, vec2(95, 5) /* initial x/y */, + vec2(10, -10) /* Move dignally to top right corner */, PointerChoreographerDisplayTopologyTestFixture::DISPLAY_TOP_RIGHT_CORNER_ID, - FloatPoint(0, 90) /* bottom left corner */)), + vec2(0, 90) /* bottom left corner */)), [](const testing::TestParamInfo<PointerChoreographerDisplayTopologyTestFixtureParam>& p) { return std::string{std::get<0>(p.param)}; }); |