diff options
-rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 51 | ||||
-rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.h | 15 |
2 files changed, 22 insertions, 44 deletions
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 203b614c50..35558a7a07 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -4276,13 +4276,13 @@ void InputDispatcher::synthesizePointerDownEventsForConnectionLocked( connection->getInputChannelName().c_str(), downEvents.size()); } - const auto [_, touchedWindowState, displayId] = - findTouchStateWindowAndDisplay(connection->getToken(), - mTouchStates.mTouchStatesByDisplay); - if (touchedWindowState == nullptr) { + auto touchedWindowHandleAndDisplay = + mTouchStates.findTouchedWindowHandleAndDisplay(connection->getToken()); + if (!touchedWindowHandleAndDisplay.has_value()) { LOG(FATAL) << __func__ << ": Touch state is out of sync: No touched window for token"; } - const auto& windowHandle = touchedWindowState->windowHandle; + + const auto [windowHandle, displayId] = touchedWindowHandleAndDisplay.value(); const bool wasEmpty = connection->outboundQueue.empty(); for (std::unique_ptr<EventEntry>& downEventEntry : downEvents) { @@ -5796,34 +5796,6 @@ void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) { mWindowInfos.setMaximumObscuringOpacityForTouch(opacity); } -std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId> -InputDispatcher::findTouchStateWindowAndDisplay( - const sp<IBinder>& token, - const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) { - for (auto& [displayId, state] : touchStatesByDisplay) { - for (const TouchedWindow& w : state.windows) { - if (w.windowHandle->getToken() == token) { - return std::make_tuple(&state, &w, displayId); - } - } - } - return std::make_tuple(nullptr, nullptr, ui::LogicalDisplayId::DEFAULT); -} - -std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId> -InputDispatcher::findTouchStateWindowAndDisplay( - const sp<IBinder>& token, - std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) { - auto [constTouchState, constTouchedWindow, displayId] = InputDispatcher:: - findTouchStateWindowAndDisplay(token, - const_cast<const std::unordered_map<ui::LogicalDisplayId, - TouchState>&>( - touchStatesByDisplay)); - - return std::make_tuple(const_cast<TouchState*>(constTouchState), - const_cast<TouchedWindow*>(constTouchedWindow), displayId); -} - bool InputDispatcher::transferTouchGesture(const sp<IBinder>& fromToken, const sp<IBinder>& toToken, bool isDragDrop) { if (fromToken == toToken) { @@ -7490,6 +7462,19 @@ bool InputDispatcher::DispatcherTouchState::isPointerInWindow(const sp<android:: return false; } +std::optional<std::tuple<const sp<gui::WindowInfoHandle>&, ui::LogicalDisplayId>> +InputDispatcher::DispatcherTouchState::findTouchedWindowHandleAndDisplay( + const sp<android::IBinder>& token) const { + for (const auto& [displayId, state] : mTouchStatesByDisplay) { + for (const TouchedWindow& w : state.windows) { + if (w.windowHandle->getToken() == token) { + return std::make_tuple(std::ref(w.windowHandle), displayId); + } + } + } + return std::nullopt; +} + std::string InputDispatcher::DispatcherTouchState::dump() const { std::string dump; if (!mTouchStatesByDisplay.empty()) { diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index f21413124b..9b11c14819 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -392,6 +392,10 @@ private: bool isPointerInWindow(const sp<android::IBinder>& token, ui::LogicalDisplayId displayId, DeviceId deviceId, int32_t pointerId) const; + // Find touched windowHandle and display by token. + std::optional<std::tuple<const sp<gui::WindowInfoHandle>&, ui::LogicalDisplayId>> + findTouchedWindowHandleAndDisplay(const sp<IBinder>& token) const; + std::string dump() const; // Updates the touchState for display from WindowInfo, @@ -855,17 +859,6 @@ private: const std::shared_ptr<Connection>& connection, DispatchEntry* dispatchEntry, bool handled) REQUIRES(mLock); - // Find touched state and touched window by token. - static std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId> - findTouchStateWindowAndDisplay( - const sp<IBinder>& token, - std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay); - - static std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId> - findTouchStateWindowAndDisplay( - const sp<IBinder>& token, - const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay); - // Statistics gathering. nsecs_t mLastStatisticPushTime = 0; std::unique_ptr<InputEventTimelineProcessor> mInputEventTimelineProcessor GUARDED_BY(mLock); |