@@ -4276,13 +4276,13 @@ void InputDispatcher::synthesizePointerDownEventsForConnectionLocked(
42764276 connection->getInputChannelName ().c_str (), downEvents.size ());
42774277 }
42784278
4279- const auto [_, touchedWindowState, displayId] =
4280- findTouchStateWindowAndDisplay (connection->getToken (),
4281- mTouchStates .mTouchStatesByDisplay );
4282- if (touchedWindowState == nullptr ) {
4279+ auto touchedWindowHandleAndDisplay =
4280+ mTouchStates .findTouchedWindowHandleAndDisplay (connection->getToken ());
4281+ if (!touchedWindowHandleAndDisplay.has_value ()) {
42834282 LOG (FATAL) << __func__ << " : Touch state is out of sync: No touched window for token" ;
42844283 }
4285- const auto & windowHandle = touchedWindowState->windowHandle ;
4284+
4285+ const auto [windowHandle, displayId] = touchedWindowHandleAndDisplay.value ();
42864286
42874287 const bool wasEmpty = connection->outboundQueue .empty ();
42884288 for (std::unique_ptr<EventEntry>& downEventEntry : downEvents) {
@@ -5796,34 +5796,6 @@ void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) {
57965796 mWindowInfos .setMaximumObscuringOpacityForTouch (opacity);
57975797}
57985798
5799- std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
5800- InputDispatcher::findTouchStateWindowAndDisplay (
5801- const sp<IBinder>& token,
5802- const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) {
5803- for (auto & [displayId, state] : touchStatesByDisplay) {
5804- for (const TouchedWindow& w : state.windows ) {
5805- if (w.windowHandle ->getToken () == token) {
5806- return std::make_tuple (&state, &w, displayId);
5807- }
5808- }
5809- }
5810- return std::make_tuple (nullptr , nullptr , ui::LogicalDisplayId::DEFAULT);
5811- }
5812-
5813- std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId>
5814- InputDispatcher::findTouchStateWindowAndDisplay (
5815- const sp<IBinder>& token,
5816- std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) {
5817- auto [constTouchState, constTouchedWindow, displayId] = InputDispatcher::
5818- findTouchStateWindowAndDisplay (token,
5819- const_cast <const std::unordered_map<ui::LogicalDisplayId,
5820- TouchState>&>(
5821- touchStatesByDisplay));
5822-
5823- return std::make_tuple (const_cast <TouchState*>(constTouchState),
5824- const_cast <TouchedWindow*>(constTouchedWindow), displayId);
5825- }
5826-
58275799bool InputDispatcher::transferTouchGesture (const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
58285800 bool isDragDrop) {
58295801 if (fromToken == toToken) {
@@ -7490,6 +7462,19 @@ bool InputDispatcher::DispatcherTouchState::isPointerInWindow(const sp<android::
74907462 return false ;
74917463}
74927464
7465+ std::optional<std::tuple<const sp<gui::WindowInfoHandle>&, ui::LogicalDisplayId>>
7466+ InputDispatcher::DispatcherTouchState::findTouchedWindowHandleAndDisplay (
7467+ const sp<android::IBinder>& token) const {
7468+ for (const auto & [displayId, state] : mTouchStatesByDisplay ) {
7469+ for (const TouchedWindow& w : state.windows ) {
7470+ if (w.windowHandle ->getToken () == token) {
7471+ return std::make_tuple (std::ref (w.windowHandle ), displayId);
7472+ }
7473+ }
7474+ }
7475+ return std::nullopt ;
7476+ }
7477+
74937478std::string InputDispatcher::DispatcherTouchState::dump () const {
74947479 std::string dump;
74957480 if (!mTouchStatesByDisplay .empty ()) {
0 commit comments