From 144aedbae81c0cb4c4e9985f2ebd43c0bf1cf74e Mon Sep 17 00:00:00 2001 From: Arpit Singh Date: Thu, 16 Jan 2025 15:07:10 +0000 Subject: [19/n Dispatcher refactor] Remove findTouchStateWindowAndDisplay In this we remove findTouchStateWindowAndDisplay method that allows direct access to the TouchState and Introduce a new method findTouchedWindowHandleAndDisplay which return only the windowHandle and displayId. Bug: 367661487 Bug: 245989146 Test: atest inputflinger_tests Flag: EXEMPT refactor Change-Id: I0d41ba7750ed8539ce07783b22c452f23d9d4cda --- .../inputflinger/dispatcher/InputDispatcher.cpp | 51 ++++++++-------------- services/inputflinger/dispatcher/InputDispatcher.h | 15 ++----- 2 files changed, 22 insertions(+), 44 deletions(-) (limited to 'services/inputflinger') 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& downEventEntry : downEvents) { @@ -5796,34 +5796,6 @@ void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) { mWindowInfos.setMaximumObscuringOpacityForTouch(opacity); } -std::tuple -InputDispatcher::findTouchStateWindowAndDisplay( - const sp& token, - const std::unordered_map& 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 -InputDispatcher::findTouchStateWindowAndDisplay( - const sp& token, - std::unordered_map& touchStatesByDisplay) { - auto [constTouchState, constTouchedWindow, displayId] = InputDispatcher:: - findTouchStateWindowAndDisplay(token, - const_cast&>( - touchStatesByDisplay)); - - return std::make_tuple(const_cast(constTouchState), - const_cast(constTouchedWindow), displayId); -} - bool InputDispatcher::transferTouchGesture(const sp& fromToken, const sp& toToken, bool isDragDrop) { if (fromToken == toToken) { @@ -7490,6 +7462,19 @@ bool InputDispatcher::DispatcherTouchState::isPointerInWindow(const sp&, ui::LogicalDisplayId>> +InputDispatcher::DispatcherTouchState::findTouchedWindowHandleAndDisplay( + const sp& 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& token, ui::LogicalDisplayId displayId, DeviceId deviceId, int32_t pointerId) const; + // Find touched windowHandle and display by token. + std::optional&, ui::LogicalDisplayId>> + findTouchedWindowHandleAndDisplay(const sp& token) const; + std::string dump() const; // Updates the touchState for display from WindowInfo, @@ -855,17 +859,6 @@ private: const std::shared_ptr& connection, DispatchEntry* dispatchEntry, bool handled) REQUIRES(mLock); - // Find touched state and touched window by token. - static std::tuple - findTouchStateWindowAndDisplay( - const sp& token, - std::unordered_map& touchStatesByDisplay); - - static std::tuple - findTouchStateWindowAndDisplay( - const sp& token, - const std::unordered_map& touchStatesByDisplay); - // Statistics gathering. nsecs_t mLastStatisticPushTime = 0; std::unique_ptr mInputEventTimelineProcessor GUARDED_BY(mLock); -- cgit v1.2.3-59-g8ed1b