Loading libs/input/MouseCursorController.cpp +23 −23 Original line number Diff line number Diff line Loading @@ -49,8 +49,7 @@ MouseCursorController::MouseCursorController(PointerControllerContext& context) mLocked.lastFrameUpdatedTime = 0; mLocked.pointerFadeDirection = 0; mLocked.pointerX = 0; mLocked.pointerY = 0; mLocked.pointerPosition = {0, 0}; mLocked.pointerAlpha = 0.0f; // pointer is initially faded mLocked.pointerSprite = mContext.getSpriteController().createSprite(); mLocked.updatePointerIcon = false; Loading @@ -66,11 +65,11 @@ MouseCursorController::~MouseCursorController() { mLocked.pointerSprite.clear(); } FloatPoint MouseCursorController::move(float deltaX, float deltaY) { vec2 MouseCursorController::move(vec2 delta) { #if DEBUG_MOUSE_CURSOR_UPDATES ALOGD("Move pointer by deltaX=%0.3f, deltaY=%0.3f", deltaX, deltaY); #endif if (deltaX == 0.0f && deltaY == 0.0f) { if (delta.x == 0.0f && delta.y == 0.0f) { return {0, 0}; } Loading @@ -78,19 +77,19 @@ FloatPoint MouseCursorController::move(float deltaX, float deltaY) { // if there's another display on the other side of the transition. At this point we still need // to move the cursor to the boundary. std::scoped_lock lock(mLock); const FloatPoint position{mLocked.pointerX + deltaX, mLocked.pointerY + deltaY}; setPositionLocked(position.x, position.y); const vec2 targetPosition = mLocked.pointerPosition + delta; setPositionLocked(targetPosition); // The amount of the delta that was not consumed as a result of the cursor // hitting the edge of the display. return {position.x - mLocked.pointerX, position.y - mLocked.pointerY}; return targetPosition - mLocked.pointerPosition; } void MouseCursorController::setPosition(float x, float y) { void MouseCursorController::setPosition(vec2 position) { #if DEBUG_MOUSE_CURSOR_UPDATES ALOGD("Set pointer position to x=%0.3f, y=%0.3f", x, y); #endif std::scoped_lock lock(mLock); setPositionLocked(x, y); setPositionLocked(position); } FloatRect MouseCursorController::getBoundsLocked() REQUIRES(mLock) { Loading @@ -105,21 +104,21 @@ FloatRect MouseCursorController::getBoundsLocked() REQUIRES(mLock) { }; } void MouseCursorController::setPositionLocked(float x, float y) REQUIRES(mLock) { void MouseCursorController::setPositionLocked(vec2 position) REQUIRES(mLock) { const auto& v = mLocked.viewport; if (!v.isValid()) return; const FloatRect bounds = getBoundsLocked(); mLocked.pointerX = std::max(bounds.left, std::min(bounds.right, x)); mLocked.pointerY = std::max(bounds.top, std::min(bounds.bottom, y)); mLocked.pointerPosition.x = std::max(bounds.left, std::min(bounds.right, position.x)); mLocked.pointerPosition.y = std::max(bounds.top, std::min(bounds.bottom, position.y)); updatePointerLocked(); } FloatPoint MouseCursorController::getPosition() const { vec2 MouseCursorController::getPosition() const { std::scoped_lock lock(mLock); return {mLocked.pointerX, mLocked.pointerY}; return mLocked.pointerPosition; } ui::LogicalDisplayId MouseCursorController::getDisplayId() const { Loading Loading @@ -221,20 +220,21 @@ void MouseCursorController::setDisplayViewport(const DisplayViewport& viewport, if (viewport.isValid()) { // Use integer coordinates as the starting point for the cursor location. // We usually expect display sizes to be even numbers, so the flooring is precautionary. mLocked.pointerX = std::floor((viewport.logicalLeft + viewport.logicalRight) / 2); mLocked.pointerY = std::floor((viewport.logicalTop + viewport.logicalBottom) / 2); mLocked.pointerPosition.x = std::floor((viewport.logicalLeft + viewport.logicalRight) / 2); mLocked.pointerPosition.y = std::floor((viewport.logicalTop + viewport.logicalBottom) / 2); // Reload icon resources for density may be changed. loadResourcesLocked(getAdditionalMouseResources); } else { mLocked.pointerX = 0; mLocked.pointerY = 0; mLocked.pointerPosition = {0, 0}; } } else if (oldViewport.orientation != viewport.orientation) { // Apply offsets to convert from the pixel top-left corner position to the pixel center. // This creates an invariant frame of reference that we can easily rotate when // taking into account that the pointer may be located at fractional pixel offsets. float x = mLocked.pointerX + 0.5f; float y = mLocked.pointerY + 0.5f; float x = mLocked.pointerPosition.x + 0.5f; float y = mLocked.pointerPosition.y + 0.5f; float temp; // Undo the previous rotation. Loading Loading @@ -279,8 +279,8 @@ void MouseCursorController::setDisplayViewport(const DisplayViewport& viewport, // Apply offsets to convert from the pixel center to the pixel top-left corner position // and save the results. mLocked.pointerX = x - 0.5f; mLocked.pointerY = y - 0.5f; mLocked.pointerPosition.x = x - 0.5f; mLocked.pointerPosition.y = y - 0.5f; } updatePointerLocked(); Loading Loading @@ -366,7 +366,7 @@ void MouseCursorController::updatePointerLocked() REQUIRES(mLock) { spriteController.openTransaction(); mLocked.pointerSprite->setLayer(Sprite::BASE_LAYER_POINTER); mLocked.pointerSprite->setPosition(mLocked.pointerX, mLocked.pointerY); mLocked.pointerSprite->setPosition(mLocked.pointerPosition.x, mLocked.pointerPosition.y); mLocked.pointerSprite->setDisplayId(mLocked.viewport.displayId); mLocked.pointerSprite->setSkipScreenshot(mLocked.skipScreenshot); Loading libs/input/MouseCursorController.h +5 −6 Original line number Diff line number Diff line Loading @@ -41,9 +41,9 @@ public: ~MouseCursorController(); // Move the pointer and return unconsumed delta FloatPoint move(float deltaX, float deltaY); void setPosition(float x, float y); FloatPoint getPosition() const; vec2 move(vec2 delta); void setPosition(vec2 position); vec2 getPosition() const; ui::LogicalDisplayId getDisplayId() const; void fade(PointerControllerInterface::Transition transition); void unfade(PointerControllerInterface::Transition transition); Loading Loading @@ -81,8 +81,7 @@ private: nsecs_t lastFrameUpdatedTime; int32_t pointerFadeDirection; float pointerX; float pointerY; vec2 pointerPosition; float pointerAlpha; sp<Sprite> pointerSprite; SpriteIcon pointerIcon; Loading @@ -101,7 +100,7 @@ private: } mLocked GUARDED_BY(mLock); void setPositionLocked(float x, float y); void setPositionLocked(vec2 position); void updatePointerLocked(); Loading libs/input/PointerController.cpp +5 −9 Original line number Diff line number Diff line Loading @@ -138,7 +138,7 @@ std::mutex& PointerController::getLock() const { return mDisplayInfoListener->mLock; } FloatPoint PointerController::move(float deltaX, float deltaY) { vec2 PointerController::move(float deltaX, float deltaY) { const ui::LogicalDisplayId displayId = mCursorController.getDisplayId(); ui::Transform transform; { Loading @@ -147,10 +147,7 @@ FloatPoint PointerController::move(float deltaX, float deltaY) { } const vec2 transformed = transformWithoutTranslation(transform, {deltaX, deltaY}); const FloatPoint unconsumedDelta = mCursorController.move(transformed.x, transformed.y); return FloatPoint(transformWithoutTranslation(transform.inverse(), {unconsumedDelta.x, unconsumedDelta.y})); return transformWithoutTranslation(transform.inverse(), mCursorController.move(transformed)); } void PointerController::setPosition(float x, float y) { Loading @@ -161,16 +158,15 @@ void PointerController::setPosition(float x, float y) { const auto& transform = getTransformForDisplayLocked(displayId); transformed = transform.transform(x, y); } mCursorController.setPosition(transformed.x, transformed.y); mCursorController.setPosition(transformed); } FloatPoint PointerController::getPosition() const { vec2 PointerController::getPosition() const { const ui::LogicalDisplayId displayId = mCursorController.getDisplayId(); const auto p = mCursorController.getPosition(); { std::scoped_lock lock(getLock()); const auto& transform = getTransformForDisplayLocked(displayId); return FloatPoint{transform.inverse().transform(p.x, p.y)}; return getTransformForDisplayLocked(displayId).inverse().transform(p.x, p.y); } } Loading libs/input/PointerController.h +4 −4 Original line number Diff line number Diff line Loading @@ -51,9 +51,9 @@ public: ~PointerController() override; FloatPoint move(float deltaX, float deltaY) override; vec2 move(float deltaX, float deltaY) override; void setPosition(float x, float y) override; FloatPoint getPosition() const override; vec2 getPosition() const override; ui::LogicalDisplayId getDisplayId() const override; void fade(Transition transition) override; void unfade(Transition transition) override; Loading Loading @@ -166,13 +166,13 @@ public: ~TouchPointerController() override; FloatPoint move(float, float) override { vec2 move(float, float) override { LOG_ALWAYS_FATAL("Should not be called"); } void setPosition(float, float) override { LOG_ALWAYS_FATAL("Should not be called"); } FloatPoint getPosition() const override { vec2 getPosition() const override { LOG_ALWAYS_FATAL("Should not be called"); } ui::LogicalDisplayId getDisplayId() const override { Loading services/core/jni/com_android_server_input_InputManagerService.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -362,7 +362,7 @@ public: void setMotionClassifierEnabled(bool enabled); std::optional<std::string> getBluetoothAddress(int32_t deviceId); void setStylusButtonMotionEventsEnabled(bool enabled); FloatPoint getMouseCursorPosition(ui::LogicalDisplayId displayId); vec2 getMouseCursorPosition(ui::LogicalDisplayId displayId); void setStylusPointerIconEnabled(bool enabled); void setInputMethodConnectionIsActive(bool isActive); void setKeyRemapping(const std::map<int32_t, int32_t>& keyRemapping); Loading Loading @@ -441,7 +441,7 @@ public: std::shared_ptr<PointerControllerInterface> createPointerController( PointerControllerInterface::ControllerType type) override; void notifyPointerDisplayIdChanged(ui::LogicalDisplayId displayId, const FloatPoint& position) override; const vec2& position) override; void notifyMouseCursorFadedOnTyping() override; /* --- InputFilterPolicyInterface implementation --- */ Loading Loading @@ -871,7 +871,7 @@ std::shared_ptr<PointerControllerInterface> NativeInputManager::createPointerCon } void NativeInputManager::notifyPointerDisplayIdChanged(ui::LogicalDisplayId pointerDisplayId, const FloatPoint& position) { const vec2& position) { // Notify the Reader so that devices can be reconfigured. { // acquire lock std::scoped_lock _l(mLock); Loading Loading @@ -2023,7 +2023,7 @@ void NativeInputManager::setStylusButtonMotionEventsEnabled(bool enabled) { InputReaderConfiguration::Change::STYLUS_BUTTON_REPORTING); } FloatPoint NativeInputManager::getMouseCursorPosition(ui::LogicalDisplayId displayId) { vec2 NativeInputManager::getMouseCursorPosition(ui::LogicalDisplayId displayId) { return mInputManager->getChoreographer().getMouseCursorPosition(displayId); } Loading Loading
libs/input/MouseCursorController.cpp +23 −23 Original line number Diff line number Diff line Loading @@ -49,8 +49,7 @@ MouseCursorController::MouseCursorController(PointerControllerContext& context) mLocked.lastFrameUpdatedTime = 0; mLocked.pointerFadeDirection = 0; mLocked.pointerX = 0; mLocked.pointerY = 0; mLocked.pointerPosition = {0, 0}; mLocked.pointerAlpha = 0.0f; // pointer is initially faded mLocked.pointerSprite = mContext.getSpriteController().createSprite(); mLocked.updatePointerIcon = false; Loading @@ -66,11 +65,11 @@ MouseCursorController::~MouseCursorController() { mLocked.pointerSprite.clear(); } FloatPoint MouseCursorController::move(float deltaX, float deltaY) { vec2 MouseCursorController::move(vec2 delta) { #if DEBUG_MOUSE_CURSOR_UPDATES ALOGD("Move pointer by deltaX=%0.3f, deltaY=%0.3f", deltaX, deltaY); #endif if (deltaX == 0.0f && deltaY == 0.0f) { if (delta.x == 0.0f && delta.y == 0.0f) { return {0, 0}; } Loading @@ -78,19 +77,19 @@ FloatPoint MouseCursorController::move(float deltaX, float deltaY) { // if there's another display on the other side of the transition. At this point we still need // to move the cursor to the boundary. std::scoped_lock lock(mLock); const FloatPoint position{mLocked.pointerX + deltaX, mLocked.pointerY + deltaY}; setPositionLocked(position.x, position.y); const vec2 targetPosition = mLocked.pointerPosition + delta; setPositionLocked(targetPosition); // The amount of the delta that was not consumed as a result of the cursor // hitting the edge of the display. return {position.x - mLocked.pointerX, position.y - mLocked.pointerY}; return targetPosition - mLocked.pointerPosition; } void MouseCursorController::setPosition(float x, float y) { void MouseCursorController::setPosition(vec2 position) { #if DEBUG_MOUSE_CURSOR_UPDATES ALOGD("Set pointer position to x=%0.3f, y=%0.3f", x, y); #endif std::scoped_lock lock(mLock); setPositionLocked(x, y); setPositionLocked(position); } FloatRect MouseCursorController::getBoundsLocked() REQUIRES(mLock) { Loading @@ -105,21 +104,21 @@ FloatRect MouseCursorController::getBoundsLocked() REQUIRES(mLock) { }; } void MouseCursorController::setPositionLocked(float x, float y) REQUIRES(mLock) { void MouseCursorController::setPositionLocked(vec2 position) REQUIRES(mLock) { const auto& v = mLocked.viewport; if (!v.isValid()) return; const FloatRect bounds = getBoundsLocked(); mLocked.pointerX = std::max(bounds.left, std::min(bounds.right, x)); mLocked.pointerY = std::max(bounds.top, std::min(bounds.bottom, y)); mLocked.pointerPosition.x = std::max(bounds.left, std::min(bounds.right, position.x)); mLocked.pointerPosition.y = std::max(bounds.top, std::min(bounds.bottom, position.y)); updatePointerLocked(); } FloatPoint MouseCursorController::getPosition() const { vec2 MouseCursorController::getPosition() const { std::scoped_lock lock(mLock); return {mLocked.pointerX, mLocked.pointerY}; return mLocked.pointerPosition; } ui::LogicalDisplayId MouseCursorController::getDisplayId() const { Loading Loading @@ -221,20 +220,21 @@ void MouseCursorController::setDisplayViewport(const DisplayViewport& viewport, if (viewport.isValid()) { // Use integer coordinates as the starting point for the cursor location. // We usually expect display sizes to be even numbers, so the flooring is precautionary. mLocked.pointerX = std::floor((viewport.logicalLeft + viewport.logicalRight) / 2); mLocked.pointerY = std::floor((viewport.logicalTop + viewport.logicalBottom) / 2); mLocked.pointerPosition.x = std::floor((viewport.logicalLeft + viewport.logicalRight) / 2); mLocked.pointerPosition.y = std::floor((viewport.logicalTop + viewport.logicalBottom) / 2); // Reload icon resources for density may be changed. loadResourcesLocked(getAdditionalMouseResources); } else { mLocked.pointerX = 0; mLocked.pointerY = 0; mLocked.pointerPosition = {0, 0}; } } else if (oldViewport.orientation != viewport.orientation) { // Apply offsets to convert from the pixel top-left corner position to the pixel center. // This creates an invariant frame of reference that we can easily rotate when // taking into account that the pointer may be located at fractional pixel offsets. float x = mLocked.pointerX + 0.5f; float y = mLocked.pointerY + 0.5f; float x = mLocked.pointerPosition.x + 0.5f; float y = mLocked.pointerPosition.y + 0.5f; float temp; // Undo the previous rotation. Loading Loading @@ -279,8 +279,8 @@ void MouseCursorController::setDisplayViewport(const DisplayViewport& viewport, // Apply offsets to convert from the pixel center to the pixel top-left corner position // and save the results. mLocked.pointerX = x - 0.5f; mLocked.pointerY = y - 0.5f; mLocked.pointerPosition.x = x - 0.5f; mLocked.pointerPosition.y = y - 0.5f; } updatePointerLocked(); Loading Loading @@ -366,7 +366,7 @@ void MouseCursorController::updatePointerLocked() REQUIRES(mLock) { spriteController.openTransaction(); mLocked.pointerSprite->setLayer(Sprite::BASE_LAYER_POINTER); mLocked.pointerSprite->setPosition(mLocked.pointerX, mLocked.pointerY); mLocked.pointerSprite->setPosition(mLocked.pointerPosition.x, mLocked.pointerPosition.y); mLocked.pointerSprite->setDisplayId(mLocked.viewport.displayId); mLocked.pointerSprite->setSkipScreenshot(mLocked.skipScreenshot); Loading
libs/input/MouseCursorController.h +5 −6 Original line number Diff line number Diff line Loading @@ -41,9 +41,9 @@ public: ~MouseCursorController(); // Move the pointer and return unconsumed delta FloatPoint move(float deltaX, float deltaY); void setPosition(float x, float y); FloatPoint getPosition() const; vec2 move(vec2 delta); void setPosition(vec2 position); vec2 getPosition() const; ui::LogicalDisplayId getDisplayId() const; void fade(PointerControllerInterface::Transition transition); void unfade(PointerControllerInterface::Transition transition); Loading Loading @@ -81,8 +81,7 @@ private: nsecs_t lastFrameUpdatedTime; int32_t pointerFadeDirection; float pointerX; float pointerY; vec2 pointerPosition; float pointerAlpha; sp<Sprite> pointerSprite; SpriteIcon pointerIcon; Loading @@ -101,7 +100,7 @@ private: } mLocked GUARDED_BY(mLock); void setPositionLocked(float x, float y); void setPositionLocked(vec2 position); void updatePointerLocked(); Loading
libs/input/PointerController.cpp +5 −9 Original line number Diff line number Diff line Loading @@ -138,7 +138,7 @@ std::mutex& PointerController::getLock() const { return mDisplayInfoListener->mLock; } FloatPoint PointerController::move(float deltaX, float deltaY) { vec2 PointerController::move(float deltaX, float deltaY) { const ui::LogicalDisplayId displayId = mCursorController.getDisplayId(); ui::Transform transform; { Loading @@ -147,10 +147,7 @@ FloatPoint PointerController::move(float deltaX, float deltaY) { } const vec2 transformed = transformWithoutTranslation(transform, {deltaX, deltaY}); const FloatPoint unconsumedDelta = mCursorController.move(transformed.x, transformed.y); return FloatPoint(transformWithoutTranslation(transform.inverse(), {unconsumedDelta.x, unconsumedDelta.y})); return transformWithoutTranslation(transform.inverse(), mCursorController.move(transformed)); } void PointerController::setPosition(float x, float y) { Loading @@ -161,16 +158,15 @@ void PointerController::setPosition(float x, float y) { const auto& transform = getTransformForDisplayLocked(displayId); transformed = transform.transform(x, y); } mCursorController.setPosition(transformed.x, transformed.y); mCursorController.setPosition(transformed); } FloatPoint PointerController::getPosition() const { vec2 PointerController::getPosition() const { const ui::LogicalDisplayId displayId = mCursorController.getDisplayId(); const auto p = mCursorController.getPosition(); { std::scoped_lock lock(getLock()); const auto& transform = getTransformForDisplayLocked(displayId); return FloatPoint{transform.inverse().transform(p.x, p.y)}; return getTransformForDisplayLocked(displayId).inverse().transform(p.x, p.y); } } Loading
libs/input/PointerController.h +4 −4 Original line number Diff line number Diff line Loading @@ -51,9 +51,9 @@ public: ~PointerController() override; FloatPoint move(float deltaX, float deltaY) override; vec2 move(float deltaX, float deltaY) override; void setPosition(float x, float y) override; FloatPoint getPosition() const override; vec2 getPosition() const override; ui::LogicalDisplayId getDisplayId() const override; void fade(Transition transition) override; void unfade(Transition transition) override; Loading Loading @@ -166,13 +166,13 @@ public: ~TouchPointerController() override; FloatPoint move(float, float) override { vec2 move(float, float) override { LOG_ALWAYS_FATAL("Should not be called"); } void setPosition(float, float) override { LOG_ALWAYS_FATAL("Should not be called"); } FloatPoint getPosition() const override { vec2 getPosition() const override { LOG_ALWAYS_FATAL("Should not be called"); } ui::LogicalDisplayId getDisplayId() const override { Loading
services/core/jni/com_android_server_input_InputManagerService.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -362,7 +362,7 @@ public: void setMotionClassifierEnabled(bool enabled); std::optional<std::string> getBluetoothAddress(int32_t deviceId); void setStylusButtonMotionEventsEnabled(bool enabled); FloatPoint getMouseCursorPosition(ui::LogicalDisplayId displayId); vec2 getMouseCursorPosition(ui::LogicalDisplayId displayId); void setStylusPointerIconEnabled(bool enabled); void setInputMethodConnectionIsActive(bool isActive); void setKeyRemapping(const std::map<int32_t, int32_t>& keyRemapping); Loading Loading @@ -441,7 +441,7 @@ public: std::shared_ptr<PointerControllerInterface> createPointerController( PointerControllerInterface::ControllerType type) override; void notifyPointerDisplayIdChanged(ui::LogicalDisplayId displayId, const FloatPoint& position) override; const vec2& position) override; void notifyMouseCursorFadedOnTyping() override; /* --- InputFilterPolicyInterface implementation --- */ Loading Loading @@ -871,7 +871,7 @@ std::shared_ptr<PointerControllerInterface> NativeInputManager::createPointerCon } void NativeInputManager::notifyPointerDisplayIdChanged(ui::LogicalDisplayId pointerDisplayId, const FloatPoint& position) { const vec2& position) { // Notify the Reader so that devices can be reconfigured. { // acquire lock std::scoped_lock _l(mLock); Loading Loading @@ -2023,7 +2023,7 @@ void NativeInputManager::setStylusButtonMotionEventsEnabled(bool enabled) { InputReaderConfiguration::Change::STYLUS_BUTTON_REPORTING); } FloatPoint NativeInputManager::getMouseCursorPosition(ui::LogicalDisplayId displayId) { vec2 NativeInputManager::getMouseCursorPosition(ui::LogicalDisplayId displayId) { return mInputManager->getChoreographer().getMouseCursorPosition(displayId); } Loading