Skip to content

Commit f684980

Browse files
author
Arpit Singh
committed
[16/n Dispatcher refactor] Move transferWallpaperTouch
In this CL we move transferWallpaperTouch to DispatcherTouchState subclass. Bug: 367661487 Bug: 245989146 Test: atest inputflinger_tests Flag: EXEMPT refactor Change-Id: I41ec66dcc56e4da395ab2b9dd7786e00fda5037d
1 parent bbd72f6 commit f684980

2 files changed

Lines changed: 62 additions & 26 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5907,8 +5907,24 @@ bool InputDispatcher::transferTouchGesture(const sp<IBinder>& fromToken, const s
59075907
synthesizeCancelationEventsForWindowLocked(fromWindowHandle, options, fromConnection);
59085908

59095909
// Check if the wallpaper window should deliver the corresponding event.
5910-
transferWallpaperTouch(oldTargetFlags, newTargetFlags, fromWindowHandle, toWindowHandle,
5911-
*state, deviceId, pointers, traceContext.getTracker());
5910+
const auto [cancellations, pointerDowns] =
5911+
mTouchStates.transferWallpaperTouch(fromWindowHandle, toWindowHandle, displayId,
5912+
deviceId, pointers, oldTargetFlags,
5913+
newTargetFlags, mWindowInfos,
5914+
mConnectionManager);
5915+
for (const auto& cancellationArgs : cancellations) {
5916+
// touch should be cancelled for old wallpaper window
5917+
LOG_ALWAYS_FATAL_IF(cancellationArgs.mode !=
5918+
CancelationOptions::Mode::CANCEL_POINTER_EVENTS);
5919+
synthesizeCancelationEventsForWindowLocked(cancellationArgs.windowHandle, options);
5920+
}
5921+
for (const auto& pointerDownArgs : pointerDowns) {
5922+
// expect pointer down on new the wallpaper window
5923+
synthesizePointerDownEventsForConnectionLocked(pointerDownArgs.downTimeInTarget,
5924+
pointerDownArgs.connection,
5925+
pointerDownArgs.targetFlags,
5926+
traceContext.getTracker());
5927+
}
59125928

59135929
// Because new window may have a wallpaper window, it will merge input state from it
59145930
// parent window, after this the firstNewPointerIdx in input state will be reset, then
@@ -7156,12 +7172,17 @@ void InputDispatcher::DispatcherTouchState::slipWallpaperTouch(
71567172
}
71577173
}
71587174

7159-
void InputDispatcher::transferWallpaperTouch(
7175+
std::pair<std::list<InputDispatcher::DispatcherTouchState::CancellationArgs>,
7176+
std::list<InputDispatcher::DispatcherTouchState::PointerDownArgs>>
7177+
InputDispatcher::DispatcherTouchState::transferWallpaperTouch(
7178+
const sp<gui::WindowInfoHandle> fromWindowHandle,
7179+
const sp<gui::WindowInfoHandle> toWindowHandle, ui::LogicalDisplayId displayId,
7180+
android::DeviceId deviceId, const std::vector<PointerProperties>& pointers,
71607181
ftl::Flags<InputTarget::Flags> oldTargetFlags,
7161-
ftl::Flags<InputTarget::Flags> newTargetFlags, const sp<WindowInfoHandle> fromWindowHandle,
7162-
const sp<WindowInfoHandle> toWindowHandle, TouchState& state, DeviceId deviceId,
7163-
const std::vector<PointerProperties>& pointers,
7164-
const std::unique_ptr<trace::EventTrackerInterface>& traceTracker) {
7182+
ftl::Flags<InputTarget::Flags> newTargetFlags, const DispatcherWindowInfo& windowInfos,
7183+
const ConnectionManager& connections) {
7184+
TouchState& state = getTouchState(displayId);
7185+
71657186
const bool oldHasWallpaper = oldTargetFlags.test(InputTarget::Flags::FOREGROUND) &&
71667187
fromWindowHandle->getInfo()->inputConfig.test(
71677188
gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER);
@@ -7172,16 +7193,17 @@ void InputDispatcher::transferWallpaperTouch(
71727193
const sp<WindowInfoHandle> oldWallpaper =
71737194
oldHasWallpaper ? state.getWallpaperWindow(deviceId) : nullptr;
71747195
const sp<WindowInfoHandle> newWallpaper =
7175-
newHasWallpaper ? mWindowInfos.findWallpaperWindowBelow(toWindowHandle) : nullptr;
7196+
newHasWallpaper ? windowInfos.findWallpaperWindowBelow(toWindowHandle) : nullptr;
71767197
if (oldWallpaper == newWallpaper) {
7177-
return;
7198+
return {};
71787199
}
71797200

7201+
std::list<CancellationArgs> cancellations;
7202+
std::list<PointerDownArgs> pointerDowns;
71807203
if (oldWallpaper != nullptr) {
7181-
CancelationOptions options(CancelationOptions::Mode::CANCEL_POINTER_EVENTS,
7182-
"transferring touch focus to another window", traceTracker);
71837204
state.removeWindowByToken(oldWallpaper->getToken());
7184-
synthesizeCancelationEventsForWindowLocked(oldWallpaper, options);
7205+
cancellations.emplace_back(oldWallpaper, CancelationOptions::Mode::CANCEL_POINTER_EVENTS,
7206+
/*deviceId*/ std::nullopt);
71857207
}
71867208

71877209
if (newWallpaper != nullptr) {
@@ -7193,15 +7215,16 @@ void InputDispatcher::transferWallpaperTouch(
71937215
state.addOrUpdateWindow(newWallpaper, InputTarget::DispatchMode::AS_IS, wallpaperFlags,
71947216
deviceId, pointers, downTimeInTarget);
71957217
std::shared_ptr<Connection> wallpaperConnection =
7196-
mConnectionManager.getConnection(newWallpaper->getToken());
7218+
connections.getConnection(newWallpaper->getToken());
71977219
if (wallpaperConnection != nullptr) {
71987220
std::shared_ptr<Connection> toConnection =
7199-
mConnectionManager.getConnection(toWindowHandle->getToken());
7221+
connections.getConnection(toWindowHandle->getToken());
72007222
toConnection->inputState.mergePointerStateTo(wallpaperConnection->inputState);
7201-
synthesizePointerDownEventsForConnectionLocked(downTimeInTarget, wallpaperConnection,
7202-
wallpaperFlags, traceTracker);
7223+
pointerDowns.emplace_back(downTimeInTarget, wallpaperConnection, wallpaperFlags);
72037224
}
7225+
pointerDowns.emplace_back(downTimeInTarget, wallpaperConnection, wallpaperFlags);
72047226
}
7227+
return {cancellations, pointerDowns};
72057228
}
72067229

72077230
sp<WindowInfoHandle> InputDispatcher::DispatcherWindowInfo::findWallpaperWindowBelow(
@@ -7455,4 +7478,10 @@ void InputDispatcher::DispatcherTouchState::clear() {
74557478
mTouchStatesByDisplay.clear();
74567479
}
74577480

7481+
TouchState& InputDispatcher::DispatcherTouchState::getTouchState(ui::LogicalDisplayId displayId) {
7482+
auto touchStateIt = mTouchStatesByDisplay.find(displayId);
7483+
LOG_ALWAYS_FATAL_IF(touchStateIt == mTouchStatesByDisplay.end());
7484+
return touchStateIt->second;
7485+
}
7486+
74587487
} // namespace android::inputdispatcher

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ class InputDispatcher : public android::InputDispatcherInterface {
358358
std::optional<DeviceId> deviceId;
359359
};
360360

361+
struct PointerDownArgs {
362+
const nsecs_t downTimeInTarget;
363+
const std::shared_ptr<Connection> connection;
364+
const ftl::Flags<InputTarget::Flags> targetFlags;
365+
};
366+
361367
static void addPointerWindowTarget(const sp<android::gui::WindowInfoHandle>& windowHandle,
362368
InputTarget::DispatchMode dispatchMode,
363369
ftl::Flags<InputTarget::Flags> targetFlags,
@@ -387,17 +393,27 @@ class InputDispatcher : public android::InputDispatcherInterface {
387393
std::string dump() const;
388394

389395
// Updates the touchState for display from WindowInfo,
390-
// return vector of CancellationArgs for every cancelled touch
396+
// returns list of CancellationArgs for every cancelled touch
391397
std::list<CancellationArgs> updateFromWindowInfo(ui::LogicalDisplayId displayId,
392398
const DispatcherWindowInfo& windowInfos);
393399

394400
void removeAllPointersForDevice(DeviceId deviceId);
395401

402+
std::pair<std::list<CancellationArgs>, std::list<PointerDownArgs>> transferWallpaperTouch(
403+
const sp<gui::WindowInfoHandle> fromWindowHandle,
404+
const sp<gui::WindowInfoHandle> toWindowHandle, ui::LogicalDisplayId displayId,
405+
DeviceId deviceId, const std::vector<PointerProperties>& pointers,
406+
ftl::Flags<InputTarget::Flags> oldTargetFlags,
407+
ftl::Flags<InputTarget::Flags> newTargetFlags,
408+
const DispatcherWindowInfo& windowInfos, const ConnectionManager& connections);
409+
396410
void clear();
397411

398412
std::unordered_map<ui::LogicalDisplayId, TouchState> mTouchStatesByDisplay;
399413

400414
private:
415+
TouchState& getTouchState(ui::LogicalDisplayId displayId);
416+
401417
static std::list<CancellationArgs> eraseRemovedWindowsFromWindowInfo(
402418
TouchState& state, ui::LogicalDisplayId displayId,
403419
const DispatcherWindowInfo& windowInfos);
@@ -849,15 +865,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
849865

850866
sp<InputReporterInterface> mReporter;
851867

852-
void transferWallpaperTouch(ftl::Flags<InputTarget::Flags> oldTargetFlags,
853-
ftl::Flags<InputTarget::Flags> newTargetFlags,
854-
const sp<android::gui::WindowInfoHandle> fromWindowHandle,
855-
const sp<android::gui::WindowInfoHandle> toWindowHandle,
856-
TouchState& state, DeviceId deviceId,
857-
const std::vector<PointerProperties>& pointers,
858-
const std::unique_ptr<trace::EventTrackerInterface>& traceTracker)
859-
REQUIRES(mLock);
860-
861868
/** Stores the value of the input flag for per device input latency metrics. */
862869
const bool mPerDeviceInputLatencyMetricsFlag =
863870
com::android::input::flags::enable_per_device_input_latency_metrics();

0 commit comments

Comments
 (0)