@@ -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
@@ -4276,13 +4280,13 @@ void InputDispatcher::synthesizePointerDownEventsForConnectionLocked(
42764280 connection->getInputChannelName ().c_str (), downEvents.size ());
42774281 }
42784282
4279- const auto [_, touchedWindowState, displayId] =
4280- findTouchStateWindowAndDisplay (connection->getToken (),
4281- mTouchStates .mTouchStatesByDisplay );
4282- if (touchedWindowState == nullptr ) {
4283+ auto touchedWindowHandleAndDisplay =
4284+ mTouchStates .findTouchedWindowHandleAndDisplay (connection->getToken ());
4285+ if (!touchedWindowHandleAndDisplay.has_value ()) {
42834286 LOG (FATAL) << __func__ << " : Touch state is out of sync: No touched window for token" ;
42844287 }
4285- const auto & windowHandle = touchedWindowState->windowHandle ;
4288+
4289+ const auto [windowHandle, displayId] = touchedWindowHandleAndDisplay.value ();
42864290
42874291 const bool wasEmpty = connection->outboundQueue .empty ();
42884292 for (std::unique_ptr<EventEntry>& downEventEntry : downEvents) {
@@ -5798,34 +5802,6 @@ void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) {
57985802 mWindowInfos .setMaximumObscuringOpacityForTouch (opacity);
57995803}
58005804
5801- std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
5802- InputDispatcher::findTouchStateWindowAndDisplay (
5803- const sp<IBinder>& token,
5804- const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) {
5805- for (auto & [displayId, state] : touchStatesByDisplay) {
5806- for (const TouchedWindow& w : state.windows ) {
5807- if (w.windowHandle ->getToken () == token) {
5808- return std::make_tuple (&state, &w, displayId);
5809- }
5810- }
5811- }
5812- return std::make_tuple (nullptr , nullptr , ui::LogicalDisplayId::DEFAULT);
5813- }
5814-
5815- std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId>
5816- InputDispatcher::findTouchStateWindowAndDisplay (
5817- const sp<IBinder>& token,
5818- std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) {
5819- auto [constTouchState, constTouchedWindow, displayId] = InputDispatcher::
5820- findTouchStateWindowAndDisplay (token,
5821- const_cast <const std::unordered_map<ui::LogicalDisplayId,
5822- TouchState>&>(
5823- touchStatesByDisplay));
5824-
5825- return std::make_tuple (const_cast <TouchState*>(constTouchState),
5826- const_cast <TouchedWindow*>(constTouchedWindow), displayId);
5827- }
5828-
58295805bool InputDispatcher::transferTouchGesture (const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
58305806 bool isDragDrop) {
58315807 if (fromToken == toToken) {
@@ -7492,6 +7468,40 @@ bool InputDispatcher::DispatcherTouchState::isPointerInWindow(const sp<android::
74927468 return false ;
74937469}
74947470
7471+ std::optional<std::tuple<const sp<gui::WindowInfoHandle>&, ui::LogicalDisplayId>>
7472+ InputDispatcher::DispatcherTouchState::findTouchedWindowHandleAndDisplay (
7473+ const sp<android::IBinder>& token) const {
7474+ for (const auto & [displayId, state] : mTouchStatesByDisplay ) {
7475+ for (const TouchedWindow& w : state.windows ) {
7476+ if (w.windowHandle ->getToken () == token) {
7477+ return std::make_tuple (std::ref (w.windowHandle ), displayId);
7478+ }
7479+ }
7480+ }
7481+ return std::nullopt ;
7482+ }
7483+
7484+ void InputDispatcher::DispatcherTouchState::forAllTouchedWindows (
7485+ std::function<void (const sp<gui::WindowInfoHandle>&)> f) const {
7486+ for (const auto & [_, state] : mTouchStatesByDisplay ) {
7487+ for (const TouchedWindow& window : state.windows ) {
7488+ f (window.windowHandle );
7489+ }
7490+ }
7491+ }
7492+
7493+ void InputDispatcher::DispatcherTouchState::forAllTouchedWindowsOnDisplay (
7494+ ui::LogicalDisplayId displayId,
7495+ std::function<void (const sp<gui::WindowInfoHandle>&)> f) const {
7496+ const auto touchStateIt = mTouchStatesByDisplay .find (displayId);
7497+ if (touchStateIt == mTouchStatesByDisplay .end ()) {
7498+ return ;
7499+ }
7500+ for (const TouchedWindow& window : touchStateIt->second .windows ) {
7501+ f (window.windowHandle );
7502+ }
7503+ }
7504+
74957505std::string InputDispatcher::DispatcherTouchState::dump () const {
74967506 std::string dump;
74977507 if (!mTouchStatesByDisplay .empty ()) {
0 commit comments