Skip to content

Commit a923bd4

Browse files
author
Arpit Singh
committed
[3/n InputDispatcher refactor] Move findTouchedWindowAt to DispatcherWindowInfo
Move findTouchedWindowAt to DispatcherWindowInfo as it operates only on the WindowInfo. Bug: 367661487 Bug: 245989146 Test: atest inputflinger_tests Flag: EXEMPT refactor Change-Id: Ib5cadc5da3ed3a78554c376bfc2343680bc0e6ba
1 parent 72b65b8 commit a923bd4

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ bool InputDispatcher::shouldPruneInboundQueueLocked(const MotionEntry& motionEnt
13331333
const bool isStylus = isPointerFromStylus(motionEntry, /*pointerIndex=*/0);
13341334

13351335
sp<WindowInfoHandle> touchedWindowHandle =
1336-
findTouchedWindowAtLocked(displayId, x, y, isStylus);
1336+
mWindowInfos.findTouchedWindowAt(displayId, x, y, isStylus);
13371337
if (touchedWindowHandle != nullptr &&
13381338
touchedWindowHandle->getApplicationToken() !=
13391339
mAwaitedFocusedApplication->getApplicationToken()) {
@@ -1452,20 +1452,19 @@ void InputDispatcher::addRecentEventLocked(std::shared_ptr<const EventEntry> ent
14521452
}
14531453
}
14541454

1455-
sp<WindowInfoHandle> InputDispatcher::findTouchedWindowAtLocked(ui::LogicalDisplayId displayId,
1456-
float x, float y, bool isStylus,
1457-
bool ignoreDragWindow) const {
1455+
sp<WindowInfoHandle> InputDispatcher::DispatcherWindowInfo::findTouchedWindowAt(
1456+
ui::LogicalDisplayId displayId, float x, float y, bool isStylus,
1457+
const sp<android::gui::WindowInfoHandle> ignoreWindow) const {
14581458
// Traverse windows from front to back to find touched window.
1459-
const auto& windowHandles = mWindowInfos.getWindowHandlesForDisplay(displayId);
1459+
const auto& windowHandles = getWindowHandlesForDisplay(displayId);
14601460
for (const sp<WindowInfoHandle>& windowHandle : windowHandles) {
1461-
if (ignoreDragWindow && haveSameToken(windowHandle, mDragState->dragWindow)) {
1461+
if (ignoreWindow && haveSameToken(windowHandle, ignoreWindow)) {
14621462
continue;
14631463
}
14641464

14651465
const WindowInfo& info = *windowHandle->getInfo();
14661466
if (!info.isSpy() &&
1467-
windowAcceptsTouchAt(info, displayId, x, y, isStylus,
1468-
mWindowInfos.getDisplayTransform(displayId))) {
1467+
windowAcceptsTouchAt(info, displayId, x, y, isStylus, getDisplayTransform(displayId))) {
14691468
return windowHandle;
14701469
}
14711470
}
@@ -2474,7 +2473,7 @@ InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const Motio
24742473
// be a pointer that would generate ACTION_DOWN, *and* touch should not already be down.
24752474
const bool isStylus = isPointerFromStylus(entry, pointerIndex);
24762475
sp<WindowInfoHandle> newTouchedWindowHandle =
2477-
findTouchedWindowAtLocked(displayId, x, y, isStylus);
2476+
mWindowInfos.findTouchedWindowAt(displayId, x, y, isStylus);
24782477

24792478
if (isDown) {
24802479
targets += findOutsideTargetsLocked(displayId, newTouchedWindowHandle, pointer.id);
@@ -2657,7 +2656,7 @@ InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const Motio
26572656
tempTouchState.getFirstForegroundWindowHandle(entry.deviceId);
26582657
LOG_ALWAYS_FATAL_IF(oldTouchedWindowHandle == nullptr);
26592658
sp<WindowInfoHandle> newTouchedWindowHandle =
2660-
findTouchedWindowAtLocked(displayId, x, y, isStylus);
2659+
mWindowInfos.findTouchedWindowAt(displayId, x, y, isStylus);
26612660

26622661
// Verify targeted injection.
26632662
if (const auto err = verifyTargetedInjection(newTouchedWindowHandle, entry); err) {
@@ -2881,7 +2880,8 @@ void InputDispatcher::finishDragAndDrop(ui::LogicalDisplayId displayId, float x,
28812880
constexpr bool isStylus = false;
28822881

28832882
sp<WindowInfoHandle> dropWindow =
2884-
findTouchedWindowAtLocked(displayId, x, y, isStylus, /*ignoreDragWindow=*/true);
2883+
mWindowInfos.findTouchedWindowAt(displayId, x, y, isStylus, /*ignoreWindow=*/
2884+
mDragState->dragWindow);
28852885
if (dropWindow) {
28862886
vec2 local = dropWindow->getInfo()->transform.transform(x, y);
28872887
sendDropWindowCommandLocked(dropWindow->getToken(), local.x, local.y);
@@ -2936,8 +2936,8 @@ void InputDispatcher::addDragEventLocked(const MotionEntry& entry) {
29362936
constexpr bool isStylus = false;
29372937

29382938
sp<WindowInfoHandle> hoverWindowHandle =
2939-
findTouchedWindowAtLocked(entry.displayId, x, y, isStylus,
2940-
/*ignoreDragWindow=*/true);
2939+
mWindowInfos.findTouchedWindowAt(entry.displayId, x, y, isStylus,
2940+
/*ignoreWindow=*/mDragState->dragWindow);
29412941
// enqueue drag exit if needed.
29422942
if (hoverWindowHandle != mDragState->dragHoverWindowHandle &&
29432943
!haveSameToken(hoverWindowHandle, mDragState->dragHoverWindowHandle)) {

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
252252
// to transfer focus to a new application.
253253
std::shared_ptr<const EventEntry> mNextUnblockedEvent GUARDED_BY(mLock);
254254

255-
sp<android::gui::WindowInfoHandle> findTouchedWindowAtLocked(
256-
ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false,
257-
bool ignoreDragWindow = false) const REQUIRES(mLock);
258255
std::vector<InputTarget> findOutsideTargetsLocked(
259256
ui::LogicalDisplayId displayId, const sp<android::gui::WindowInfoHandle>& touchedWindow,
260257
int32_t pointerId) const REQUIRES(mLock);
@@ -398,6 +395,11 @@ class InputDispatcher : public android::InputDispatcherInterface {
398395

399396
bool isWindowPresent(const sp<android::gui::WindowInfoHandle>& windowHandle) const;
400397

398+
// Returns the touched window at the given location, excluding the ignoreWindow if provided.
399+
sp<android::gui::WindowInfoHandle> findTouchedWindowAt(
400+
ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false,
401+
const sp<android::gui::WindowInfoHandle> ignoreWindow = nullptr) const;
402+
401403
std::string dumpDisplayAndWindowInfo() const;
402404

403405
private:

0 commit comments

Comments
 (0)