Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 144aedba authored by Arpit Singh's avatar Arpit Singh
Browse files

[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
parent c95ea817
Loading
Loading
Loading
Loading
+18 −33
Original line number Diff line number Diff line
@@ -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()) {
+4 −11
Original line number Diff line number Diff line
@@ -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);