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

Commit a923bd4b authored by Arpit Singh's avatar Arpit Singh
Browse files

[3/n InputDispatcher refactor] Move findTouchedWindowAt to DispatcherWindowInfo

Move findTouchedWindowAt to DispatcherWindowInfo as it operates only on
the WindowInfo.

Bug: 367661487
Bug: 245989146
Test: atest inputflinger_tests
Flag: EXEMPT refactor
Change-Id: Ib5cadc5da3ed3a78554c376bfc2343680bc0e6ba
parent 72b65b83
Loading
Loading
Loading
Loading
+13 −13
Original line number Original line Diff line number Diff line
@@ -1333,7 +1333,7 @@ bool InputDispatcher::shouldPruneInboundQueueLocked(const MotionEntry& motionEnt
        const bool isStylus = isPointerFromStylus(motionEntry, /*pointerIndex=*/0);
        const bool isStylus = isPointerFromStylus(motionEntry, /*pointerIndex=*/0);


        sp<WindowInfoHandle> touchedWindowHandle =
        sp<WindowInfoHandle> touchedWindowHandle =
                findTouchedWindowAtLocked(displayId, x, y, isStylus);
                mWindowInfos.findTouchedWindowAt(displayId, x, y, isStylus);
        if (touchedWindowHandle != nullptr &&
        if (touchedWindowHandle != nullptr &&
            touchedWindowHandle->getApplicationToken() !=
            touchedWindowHandle->getApplicationToken() !=
                    mAwaitedFocusedApplication->getApplicationToken()) {
                    mAwaitedFocusedApplication->getApplicationToken()) {
@@ -1452,20 +1452,19 @@ void InputDispatcher::addRecentEventLocked(std::shared_ptr<const EventEntry> ent
    }
    }
}
}


sp<WindowInfoHandle> InputDispatcher::findTouchedWindowAtLocked(ui::LogicalDisplayId displayId,
sp<WindowInfoHandle> InputDispatcher::DispatcherWindowInfo::findTouchedWindowAt(
                                                                float x, float y, bool isStylus,
        ui::LogicalDisplayId displayId, float x, float y, bool isStylus,
                                                                bool ignoreDragWindow) const {
        const sp<android::gui::WindowInfoHandle> ignoreWindow) const {
    // Traverse windows from front to back to find touched window.
    // Traverse windows from front to back to find touched window.
    const auto& windowHandles = mWindowInfos.getWindowHandlesForDisplay(displayId);
    const auto& windowHandles = getWindowHandlesForDisplay(displayId);
    for (const sp<WindowInfoHandle>& windowHandle : windowHandles) {
    for (const sp<WindowInfoHandle>& windowHandle : windowHandles) {
        if (ignoreDragWindow && haveSameToken(windowHandle, mDragState->dragWindow)) {
        if (ignoreWindow && haveSameToken(windowHandle, ignoreWindow)) {
            continue;
            continue;
        }
        }


        const WindowInfo& info = *windowHandle->getInfo();
        const WindowInfo& info = *windowHandle->getInfo();
        if (!info.isSpy() &&
        if (!info.isSpy() &&
            windowAcceptsTouchAt(info, displayId, x, y, isStylus,
            windowAcceptsTouchAt(info, displayId, x, y, isStylus, getDisplayTransform(displayId))) {
                                 mWindowInfos.getDisplayTransform(displayId))) {
            return windowHandle;
            return windowHandle;
        }
        }
    }
    }
@@ -2474,7 +2473,7 @@ InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const Motio
        // be a pointer that would generate ACTION_DOWN, *and* touch should not already be down.
        // be a pointer that would generate ACTION_DOWN, *and* touch should not already be down.
        const bool isStylus = isPointerFromStylus(entry, pointerIndex);
        const bool isStylus = isPointerFromStylus(entry, pointerIndex);
        sp<WindowInfoHandle> newTouchedWindowHandle =
        sp<WindowInfoHandle> newTouchedWindowHandle =
                findTouchedWindowAtLocked(displayId, x, y, isStylus);
                mWindowInfos.findTouchedWindowAt(displayId, x, y, isStylus);


        if (isDown) {
        if (isDown) {
            targets += findOutsideTargetsLocked(displayId, newTouchedWindowHandle, pointer.id);
            targets += findOutsideTargetsLocked(displayId, newTouchedWindowHandle, pointer.id);
@@ -2657,7 +2656,7 @@ InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const Motio
                    tempTouchState.getFirstForegroundWindowHandle(entry.deviceId);
                    tempTouchState.getFirstForegroundWindowHandle(entry.deviceId);
            LOG_ALWAYS_FATAL_IF(oldTouchedWindowHandle == nullptr);
            LOG_ALWAYS_FATAL_IF(oldTouchedWindowHandle == nullptr);
            sp<WindowInfoHandle> newTouchedWindowHandle =
            sp<WindowInfoHandle> newTouchedWindowHandle =
                    findTouchedWindowAtLocked(displayId, x, y, isStylus);
                    mWindowInfos.findTouchedWindowAt(displayId, x, y, isStylus);


            // Verify targeted injection.
            // Verify targeted injection.
            if (const auto err = verifyTargetedInjection(newTouchedWindowHandle, entry); err) {
            if (const auto err = verifyTargetedInjection(newTouchedWindowHandle, entry); err) {
@@ -2881,7 +2880,8 @@ void InputDispatcher::finishDragAndDrop(ui::LogicalDisplayId displayId, float x,
    constexpr bool isStylus = false;
    constexpr bool isStylus = false;


    sp<WindowInfoHandle> dropWindow =
    sp<WindowInfoHandle> dropWindow =
            findTouchedWindowAtLocked(displayId, x, y, isStylus, /*ignoreDragWindow=*/true);
            mWindowInfos.findTouchedWindowAt(displayId, x, y, isStylus, /*ignoreWindow=*/
                                             mDragState->dragWindow);
    if (dropWindow) {
    if (dropWindow) {
        vec2 local = dropWindow->getInfo()->transform.transform(x, y);
        vec2 local = dropWindow->getInfo()->transform.transform(x, y);
        sendDropWindowCommandLocked(dropWindow->getToken(), local.x, local.y);
        sendDropWindowCommandLocked(dropWindow->getToken(), local.x, local.y);
@@ -2936,8 +2936,8 @@ void InputDispatcher::addDragEventLocked(const MotionEntry& entry) {
            constexpr bool isStylus = false;
            constexpr bool isStylus = false;


            sp<WindowInfoHandle> hoverWindowHandle =
            sp<WindowInfoHandle> hoverWindowHandle =
                    findTouchedWindowAtLocked(entry.displayId, x, y, isStylus,
                    mWindowInfos.findTouchedWindowAt(entry.displayId, x, y, isStylus,
                                              /*ignoreDragWindow=*/true);
                                                     /*ignoreWindow=*/mDragState->dragWindow);
            // enqueue drag exit if needed.
            // enqueue drag exit if needed.
            if (hoverWindowHandle != mDragState->dragHoverWindowHandle &&
            if (hoverWindowHandle != mDragState->dragHoverWindowHandle &&
                !haveSameToken(hoverWindowHandle, mDragState->dragHoverWindowHandle)) {
                !haveSameToken(hoverWindowHandle, mDragState->dragHoverWindowHandle)) {
+5 −3
Original line number Original line Diff line number Diff line
@@ -252,9 +252,6 @@ private:
    // to transfer focus to a new application.
    // to transfer focus to a new application.
    std::shared_ptr<const EventEntry> mNextUnblockedEvent GUARDED_BY(mLock);
    std::shared_ptr<const EventEntry> mNextUnblockedEvent GUARDED_BY(mLock);


    sp<android::gui::WindowInfoHandle> findTouchedWindowAtLocked(
            ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false,
            bool ignoreDragWindow = false) const REQUIRES(mLock);
    std::vector<InputTarget> findOutsideTargetsLocked(
    std::vector<InputTarget> findOutsideTargetsLocked(
            ui::LogicalDisplayId displayId, const sp<android::gui::WindowInfoHandle>& touchedWindow,
            ui::LogicalDisplayId displayId, const sp<android::gui::WindowInfoHandle>& touchedWindow,
            int32_t pointerId) const REQUIRES(mLock);
            int32_t pointerId) const REQUIRES(mLock);
@@ -398,6 +395,11 @@ private:


        bool isWindowPresent(const sp<android::gui::WindowInfoHandle>& windowHandle) const;
        bool isWindowPresent(const sp<android::gui::WindowInfoHandle>& windowHandle) const;


        // Returns the touched window at the given location, excluding the ignoreWindow if provided.
        sp<android::gui::WindowInfoHandle> findTouchedWindowAt(
                ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false,
                const sp<android::gui::WindowInfoHandle> ignoreWindow = nullptr) const;

        std::string dumpDisplayAndWindowInfo() const;
        std::string dumpDisplayAndWindowInfo() const;


    private:
    private: