Skip to content

Commit 144aedb

Browse files
author
Arpit Singh
committed
[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
1 parent c95ea81 commit 144aedb

2 files changed

Lines changed: 22 additions & 44 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
58275799
bool 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+
74937478
std::string InputDispatcher::DispatcherTouchState::dump() const {
74947479
std::string dump;
74957480
if (!mTouchStatesByDisplay.empty()) {

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ class InputDispatcher : public android::InputDispatcherInterface {
392392
bool isPointerInWindow(const sp<android::IBinder>& token, ui::LogicalDisplayId displayId,
393393
DeviceId deviceId, int32_t pointerId) const;
394394

395+
// Find touched windowHandle and display by token.
396+
std::optional<std::tuple<const sp<gui::WindowInfoHandle>&, ui::LogicalDisplayId>>
397+
findTouchedWindowHandleAndDisplay(const sp<IBinder>& token) const;
398+
395399
std::string dump() const;
396400

397401
// Updates the touchState for display from WindowInfo,
@@ -855,17 +859,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
855859
const std::shared_ptr<Connection>& connection, DispatchEntry* dispatchEntry,
856860
bool handled) REQUIRES(mLock);
857861

858-
// Find touched state and touched window by token.
859-
static std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId>
860-
findTouchStateWindowAndDisplay(
861-
const sp<IBinder>& token,
862-
std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay);
863-
864-
static std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
865-
findTouchStateWindowAndDisplay(
866-
const sp<IBinder>& token,
867-
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay);
868-
869862
// Statistics gathering.
870863
nsecs_t mLastStatisticPushTime = 0;
871864
std::unique_ptr<InputEventTimelineProcessor> mInputEventTimelineProcessor GUARDED_BY(mLock);

0 commit comments

Comments
 (0)