Skip to content

Commit 9bad23a

Browse files
author
Arpit Singh
committed
[5/n InputDispatcher refactor] Move findTouchedSpyWindowsAt to DispatcherWindowInfo
Move findTouchedSpyWindowsAt to DispatcherWindowInfo as it operates only on WindowInfo. This Cl also makes windowHasTouchingPointers and findTouchStateWindowAndDisplay static as they are used by findTouchedSpyWindowsAt. Bug: 367661487 Bug: 245989146 Test: atest inputflinger_tests Flag: EXEMPT refactor Change-Id: Id9fdcb21e4f7df068ac6b5250066648d046159e0
1 parent 0a94f46 commit 9bad23a

2 files changed

Lines changed: 57 additions & 33 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,8 @@ bool InputDispatcher::shouldPruneInboundQueueLocked(const MotionEntry& motionEnt
13461346

13471347
// Alternatively, maybe there's a spy window that could handle this event.
13481348
const std::vector<sp<WindowInfoHandle>> touchedSpies =
1349-
findTouchedSpyWindowsAtLocked(displayId, x, y, isStylus, motionEntry.deviceId);
1349+
mWindowInfos.findTouchedSpyWindowsAt(displayId, x, y, isStylus,
1350+
motionEntry.deviceId, mTouchStatesByDisplay);
13501351
for (const auto& windowHandle : touchedSpies) {
13511352
const std::shared_ptr<Connection> connection =
13521353
getConnectionLocked(windowHandle->getToken());
@@ -1499,15 +1500,16 @@ std::vector<InputTarget> InputDispatcher::findOutsideTargetsLocked(
14991500
return outsideTargets;
15001501
}
15011502

1502-
std::vector<sp<WindowInfoHandle>> InputDispatcher::findTouchedSpyWindowsAtLocked(
1503-
ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId) const {
1503+
std::vector<sp<WindowInfoHandle>> InputDispatcher::DispatcherWindowInfo::findTouchedSpyWindowsAt(
1504+
ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
1505+
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) const {
15041506
// Traverse windows from front to back and gather the touched spy windows.
15051507
std::vector<sp<WindowInfoHandle>> spyWindows;
1506-
const auto& windowHandles = mWindowInfos.getWindowHandlesForDisplay(displayId);
1508+
const auto& windowHandles = getWindowHandlesForDisplay(displayId);
15071509
for (const sp<WindowInfoHandle>& windowHandle : windowHandles) {
15081510
const WindowInfo& info = *windowHandle->getInfo();
15091511
if (!windowAcceptsTouchAt(info, displayId, x, y, isStylus,
1510-
mWindowInfos.getDisplayTransform(displayId))) {
1512+
getDisplayTransform(displayId))) {
15111513
// Generally, we would skip any pointer that's outside of the window. However, if the
15121514
// spy prevents splitting, and already has some of the pointers from this device, then
15131515
// it should get more pointers from the same device, even if they are outside of that
@@ -1518,7 +1520,7 @@ std::vector<sp<WindowInfoHandle>> InputDispatcher::findTouchedSpyWindowsAtLocked
15181520

15191521
// We know that split touch is not supported. Skip this window only if it doesn't have
15201522
// any touching pointers for this device already.
1521-
if (!windowHasTouchingPointersLocked(windowHandle, deviceId)) {
1523+
if (!windowHasTouchingPointers(windowHandle, deviceId, touchStatesByDisplay)) {
15221524
continue;
15231525
}
15241526
// If it already has pointers down for this device, then give it this pointer, too.
@@ -2519,7 +2521,8 @@ InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const Motio
25192521
}
25202522

25212523
std::vector<sp<WindowInfoHandle>> newTouchedWindows =
2522-
findTouchedSpyWindowsAtLocked(displayId, x, y, isStylus, entry.deviceId);
2524+
mWindowInfos.findTouchedSpyWindowsAt(displayId, x, y, isStylus, entry.deviceId,
2525+
mTouchStatesByDisplay);
25232526
if (newTouchedWindowHandle != nullptr) {
25242527
// Process the foreground window first so that it is the first to receive the event.
25252528
newTouchedWindows.insert(newTouchedWindows.begin(), newTouchedWindowHandle);
@@ -4340,7 +4343,7 @@ void InputDispatcher::synthesizePointerDownEventsForConnectionLocked(
43404343
}
43414344

43424345
const auto [_, touchedWindowState, displayId] =
4343-
findTouchStateWindowAndDisplayLocked(connection->getToken());
4346+
findTouchStateWindowAndDisplay(connection->getToken(), mTouchStatesByDisplay);
43444347
if (touchedWindowState == nullptr) {
43454348
LOG(FATAL) << __func__ << ": Touch state is out of sync: No touched window for token";
43464349
}
@@ -5798,10 +5801,12 @@ void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) {
57985801
mMaximumObscuringOpacityForTouch = opacity;
57995802
}
58005803

5801-
std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId>
5802-
InputDispatcher::findTouchStateWindowAndDisplayLocked(const sp<IBinder>& token) {
5803-
for (auto& [displayId, state] : mTouchStatesByDisplay) {
5804-
for (TouchedWindow& w : state.windows) {
5804+
std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
5805+
InputDispatcher::findTouchStateWindowAndDisplay(
5806+
const sp<IBinder>& token,
5807+
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) {
5808+
for (auto& [displayId, state] : touchStatesByDisplay) {
5809+
for (const TouchedWindow& w : state.windows) {
58055810
if (w.windowHandle->getToken() == token) {
58065811
return std::make_tuple(&state, &w, displayId);
58075812
}
@@ -5810,15 +5815,25 @@ InputDispatcher::findTouchStateWindowAndDisplayLocked(const sp<IBinder>& token)
58105815
return std::make_tuple(nullptr, nullptr, ui::LogicalDisplayId::DEFAULT);
58115816
}
58125817

5813-
std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
5814-
InputDispatcher::findTouchStateWindowAndDisplayLocked(const sp<IBinder>& token) const {
5815-
return const_cast<InputDispatcher*>(this)->findTouchStateWindowAndDisplayLocked(token);
5816-
}
5817-
5818-
bool InputDispatcher::windowHasTouchingPointersLocked(const sp<WindowInfoHandle>& windowHandle,
5819-
DeviceId deviceId) const {
5818+
std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId>
5819+
InputDispatcher::findTouchStateWindowAndDisplay(
5820+
const sp<IBinder>& token,
5821+
std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) {
5822+
auto [constTouchState, constTouchedWindow, displayId] = InputDispatcher::
5823+
findTouchStateWindowAndDisplay(token,
5824+
const_cast<const std::unordered_map<ui::LogicalDisplayId,
5825+
TouchState>&>(
5826+
touchStatesByDisplay));
5827+
5828+
return std::make_tuple(const_cast<TouchState*>(constTouchState),
5829+
const_cast<TouchedWindow*>(constTouchedWindow), displayId);
5830+
}
5831+
5832+
bool InputDispatcher::windowHasTouchingPointers(
5833+
const sp<WindowInfoHandle>& windowHandle, DeviceId deviceId,
5834+
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) {
58205835
const auto& [touchState, touchedWindow, _] =
5821-
findTouchStateWindowAndDisplayLocked(windowHandle->getToken());
5836+
findTouchStateWindowAndDisplay(windowHandle->getToken(), touchStatesByDisplay);
58225837
if (touchState == nullptr) {
58235838
// No touching pointers at all
58245839
return false;
@@ -5839,7 +5854,8 @@ bool InputDispatcher::transferTouchGesture(const sp<IBinder>& fromToken, const s
58395854
std::scoped_lock _l(mLock);
58405855

58415856
// Find the target touch state and touched window by fromToken.
5842-
auto [state, touchedWindow, displayId] = findTouchStateWindowAndDisplayLocked(fromToken);
5857+
auto [state, touchedWindow, displayId] =
5858+
findTouchStateWindowAndDisplay(fromToken, mTouchStatesByDisplay);
58435859

58445860
if (state == nullptr || touchedWindow == nullptr) {
58455861
ALOGD("Touch transfer failed because from window is not being touched.");
@@ -6344,7 +6360,8 @@ status_t InputDispatcher::pilferPointersLocked(const sp<IBinder>& token) {
63446360
return BAD_VALUE;
63456361
}
63466362

6347-
auto [statePtr, windowPtr, displayId] = findTouchStateWindowAndDisplayLocked(token);
6363+
auto [statePtr, windowPtr, displayId] =
6364+
findTouchStateWindowAndDisplay(token, mTouchStatesByDisplay);
63486365
if (statePtr == nullptr || windowPtr == nullptr) {
63496366
LOG(WARNING)
63506367
<< "Attempted to pilfer points from a channel without any on-going pointer streams."

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
256256
ui::LogicalDisplayId displayId, const sp<android::gui::WindowInfoHandle>& touchedWindow,
257257
int32_t pointerId) const REQUIRES(mLock);
258258

259-
std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAtLocked(
260-
ui::LogicalDisplayId displayId, float x, float y, bool isStylus,
261-
DeviceId deviceId) const REQUIRES(mLock);
262-
263259
static sp<android::gui::WindowInfoHandle> findTouchedForegroundWindow(
264260
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay,
265261
ui::LogicalDisplayId displayId);
@@ -401,6 +397,11 @@ class InputDispatcher : public android::InputDispatcherInterface {
401397
ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false,
402398
const sp<android::gui::WindowInfoHandle> ignoreWindow = nullptr) const;
403399

400+
std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAt(
401+
ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
402+
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay)
403+
const;
404+
404405
std::string dumpDisplayAndWindowInfo() const;
405406

406407
private:
@@ -727,13 +728,19 @@ class InputDispatcher : public android::InputDispatcherInterface {
727728
bool handled) REQUIRES(mLock);
728729

729730
// Find touched state and touched window by token.
730-
std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId>
731-
findTouchStateWindowAndDisplayLocked(const sp<IBinder>& token) REQUIRES(mLock);
732-
733-
std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
734-
findTouchStateWindowAndDisplayLocked(const sp<IBinder>& token) const REQUIRES(mLock);
735-
bool windowHasTouchingPointersLocked(const sp<android::gui::WindowInfoHandle>& windowHandle,
736-
DeviceId deviceId) const REQUIRES(mLock);
731+
static std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId>
732+
findTouchStateWindowAndDisplay(
733+
const sp<IBinder>& token,
734+
std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay);
735+
736+
static std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
737+
findTouchStateWindowAndDisplay(
738+
const sp<IBinder>& token,
739+
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay);
740+
741+
static bool windowHasTouchingPointers(
742+
const sp<android::gui::WindowInfoHandle>& windowHandle, DeviceId deviceId,
743+
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay);
737744

738745
// Statistics gathering.
739746
nsecs_t mLastStatisticPushTime = 0;

0 commit comments

Comments
 (0)