@@ -4072,13 +4072,17 @@ void InputDispatcher::synthesizeCancelationEventsForAllConnectionsLocked(
40724072 // Generate cancellations for touched windows first. This is to avoid generating cancellations
40734073 // through a non-touched window if there are more than one window for an input channel.
40744074 if (cancelPointers) {
4075- for (const auto & [displayId, touchState] : mTouchStates .mTouchStatesByDisplay ) {
4076- if (options.displayId .has_value () && options.displayId != displayId) {
4077- continue ;
4078- }
4079- for (const auto & touchedWindow : touchState.windows ) {
4080- synthesizeCancelationEventsForWindowLocked (touchedWindow.windowHandle , options);
4081- }
4075+ if (options.displayId .has_value ()) {
4076+ mTouchStates .forAllTouchedWindowsOnDisplay (
4077+ options.displayId .value (), [&](const sp<gui::WindowInfoHandle>& windowHandle) {
4078+ base::ScopedLockAssertion assumeLocked (mLock );
4079+ synthesizeCancelationEventsForWindowLocked (windowHandle, options);
4080+ });
4081+ } else {
4082+ mTouchStates .forAllTouchedWindows ([&](const sp<gui::WindowInfoHandle>& windowHandle) {
4083+ base::ScopedLockAssertion assumeLocked (mLock );
4084+ synthesizeCancelationEventsForWindowLocked (windowHandle, options);
4085+ });
40824086 }
40834087 }
40844088 // Follow up by generating cancellations for all windows, because we don't explicitly track
@@ -7475,6 +7479,27 @@ InputDispatcher::DispatcherTouchState::findTouchedWindowHandleAndDisplay(
74757479 return std::nullopt ;
74767480}
74777481
7482+ void InputDispatcher::DispatcherTouchState::forAllTouchedWindows (
7483+ std::function<void (const sp<gui::WindowInfoHandle>&)> f) const {
7484+ for (const auto & [_, state] : mTouchStatesByDisplay ) {
7485+ for (const TouchedWindow& window : state.windows ) {
7486+ f (window.windowHandle );
7487+ }
7488+ }
7489+ }
7490+
7491+ void InputDispatcher::DispatcherTouchState::forAllTouchedWindowsOnDisplay (
7492+ ui::LogicalDisplayId displayId,
7493+ std::function<void (const sp<gui::WindowInfoHandle>&)> f) const {
7494+ const auto touchStateIt = mTouchStatesByDisplay .find (displayId);
7495+ if (touchStateIt == mTouchStatesByDisplay .end ()) {
7496+ return ;
7497+ }
7498+ for (const TouchedWindow& window : touchStateIt->second .windows ) {
7499+ f (window.windowHandle );
7500+ }
7501+ }
7502+
74787503std::string InputDispatcher::DispatcherTouchState::dump () const {
74797504 std::string dump;
74807505 if (!mTouchStatesByDisplay .empty ()) {
0 commit comments