diff options
author | Prabir Pradhan <prabirmsp@google.com> | 2023-03-09 04:51:55 +0000 |
---|---|---|
committer | Prabir Pradhan <prabirmsp@google.com> | 2023-03-09 22:37:37 +0000 |
commit | db326da336df7f4750881b15de74d30c8faed590 (patch) | |
tree | 137253f4b8cefa34f236fdc582acd1ec45174a9b | |
parent | 51b7ac6e128050f7966c130e4d5b3cb6f73905d0 (diff) | |
download | native-db326da336df7f4750881b15de74d30c8faed590.tar.gz |
InputDispatcher: Use floats to represent location coordinates
This is an adapted backport of a downstream CL.
There should be no behavior changes in this CL.
Bug: 257118693
Test: atest inputflinger_tests
Change-Id: Ib877610197a641e9c179e0809ed962ae206ea6e5
Merged-In: Ib877610197a641e9c179e0809ed962ae206ea6e5
-rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 37 | ||||
-rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.h | 4 |
2 files changed, 19 insertions, 22 deletions
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index f634ce7bd2..8e47acac8c 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -459,7 +459,7 @@ bool isUserActivityEvent(const EventEntry& eventEntry) { } // Returns true if the given window can accept pointer events at the given display location. -bool windowAcceptsTouchAt(const WindowInfo& windowInfo, int32_t displayId, int32_t x, int32_t y, +bool windowAcceptsTouchAt(const WindowInfo& windowInfo, int32_t displayId, float x, float y, bool isStylus) { const auto inputConfig = windowInfo.inputConfig; if (windowInfo.displayId != displayId || @@ -928,10 +928,8 @@ bool InputDispatcher::shouldPruneInboundQueueLocked(const MotionEntry& motionEnt // the touch into the other window. if (isPointerDownEvent && mAwaitedFocusedApplication != nullptr) { int32_t displayId = motionEntry.displayId; - int32_t x = static_cast<int32_t>( - motionEntry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X)); - int32_t y = static_cast<int32_t>( - motionEntry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y)); + const float x = motionEntry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X); + const float y = motionEntry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y); const bool isStylus = isPointerFromStylus(motionEntry, 0 /*pointerIndex*/); sp<WindowInfoHandle> touchedWindowHandle = @@ -1058,8 +1056,8 @@ void InputDispatcher::addRecentEventLocked(std::shared_ptr<EventEntry> entry) { } } -sp<WindowInfoHandle> InputDispatcher::findTouchedWindowAtLocked(int32_t displayId, int32_t x, - int32_t y, TouchState* touchState, +sp<WindowInfoHandle> InputDispatcher::findTouchedWindowAtLocked(int32_t displayId, float x, float y, + TouchState* touchState, bool isStylus, bool addOutsideTargets, bool ignoreDragWindow) { @@ -1088,7 +1086,7 @@ sp<WindowInfoHandle> InputDispatcher::findTouchedWindowAtLocked(int32_t displayI } std::vector<sp<WindowInfoHandle>> InputDispatcher::findTouchedSpyWindowsAtLocked( - int32_t displayId, int32_t x, int32_t y, bool isStylus) const { + int32_t displayId, float x, float y, bool isStylus) const { // Traverse windows from front to back and gather the touched spy windows. std::vector<sp<WindowInfoHandle>> spyWindows; const auto& windowHandles = getWindowHandlesLocked(displayId); @@ -2057,16 +2055,16 @@ InputEventInjectionResult InputDispatcher::findTouchedWindowTargetsLocked( if (newGesture || (isSplit && maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN)) { /* Case 1: New splittable pointer going down, or need target for hover or scroll. */ - int32_t x; - int32_t y; + float x; + float y; const int32_t pointerIndex = getMotionEventActionPointerIndex(action); // Always dispatch mouse events to cursor position. if (isFromMouse) { - x = int32_t(entry.xCursorPosition); - y = int32_t(entry.yCursorPosition); + x = entry.xCursorPosition; + y = entry.yCursorPosition; } else { - x = int32_t(entry.pointerCoords[pointerIndex].getAxisValue(AMOTION_EVENT_AXIS_X)); - y = int32_t(entry.pointerCoords[pointerIndex].getAxisValue(AMOTION_EVENT_AXIS_Y)); + x = entry.pointerCoords[pointerIndex].getAxisValue(AMOTION_EVENT_AXIS_X); + y = entry.pointerCoords[pointerIndex].getAxisValue(AMOTION_EVENT_AXIS_Y); } const bool isDown = maskedAction == AMOTION_EVENT_ACTION_DOWN; const bool isStylus = isPointerFromStylus(entry, pointerIndex); @@ -2075,8 +2073,7 @@ InputEventInjectionResult InputDispatcher::findTouchedWindowTargetsLocked( // Handle the case where we did not find a window. if (newTouchedWindowHandle == nullptr) { - ALOGD("No new touched window at (%" PRId32 ", %" PRId32 ") in display %" PRId32, x, y, - displayId); + ALOGD("No new touched window at (%.1f, %.1f) in display %" PRId32, x, y, displayId); // Try to assign the pointer to the first foreground window we find, if there is one. newTouchedWindowHandle = tempTouchState.getFirstForegroundWindowHandle(); } @@ -2221,8 +2218,8 @@ InputEventInjectionResult InputDispatcher::findTouchedWindowTargetsLocked( // Check whether touches should slip outside of the current foreground window. if (maskedAction == AMOTION_EVENT_ACTION_MOVE && entry.pointerCount == 1 && tempTouchState.isSlippery()) { - const int32_t x = int32_t(entry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X)); - const int32_t y = int32_t(entry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y)); + const float x = entry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X); + const float y = entry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y); const bool isStylus = isPointerFromStylus(entry, 0 /*pointerIndex*/); sp<WindowInfoHandle> oldTouchedWindowHandle = @@ -2534,8 +2531,8 @@ void InputDispatcher::addDragEventLocked(const MotionEntry& entry) { } const int32_t maskedAction = entry.action & AMOTION_EVENT_ACTION_MASK; - const int32_t x = entry.pointerCoords[pointerIndex].getX(); - const int32_t y = entry.pointerCoords[pointerIndex].getY(); + const float x = entry.pointerCoords[pointerIndex].getX(); + const float y = entry.pointerCoords[pointerIndex].getY(); switch (maskedAction) { case AMOTION_EVENT_ACTION_MOVE: { diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index ed89ed0b0f..ce246bcb9a 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -240,11 +240,11 @@ private: std::shared_ptr<EventEntry> mNextUnblockedEvent GUARDED_BY(mLock); sp<android::gui::WindowInfoHandle> findTouchedWindowAtLocked( - int32_t displayId, int32_t x, int32_t y, TouchState* touchState, bool isStylus = false, + int32_t displayId, float x, float y, TouchState* touchState, bool isStylus = false, bool addOutsideTargets = false, bool ignoreDragWindow = false) REQUIRES(mLock); std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAtLocked( - int32_t displayId, int32_t x, int32_t y, bool isStylus) const REQUIRES(mLock); + int32_t displayId, float x, float y, bool isStylus) const REQUIRES(mLock); sp<android::gui::WindowInfoHandle> findTouchedForegroundWindowLocked(int32_t displayId) const REQUIRES(mLock); |