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

Commit 75425078 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I1538c0c6,I4001c5b1,I5ca68bed into main

* changes:
  TouchInputMapper: remove gestureMode parameter
  TouchInputMapper: move PointerDistanceHeapElement definition
  TouchInputMapper: remove unnecessary dispatchMotion parameters
parents a773520f 9d5c72bb
Loading
Loading
Loading
Loading
+43 −77
Original line number Diff line number Diff line
@@ -354,25 +354,7 @@ void TouchInputMapper::resolveExternalStylusPresence() {
TouchInputMapper::Parameters TouchInputMapper::computeParameters(
        const InputDeviceContext& deviceContext) {
    Parameters parameters;
    // Use the pointer presentation mode for devices that do not support distinct
    // multitouch.  The spot-based presentation relies on being able to accurately
    // locate two or more fingers on the touch pad.
    parameters.gestureMode = deviceContext.hasInputProperty(INPUT_PROP_SEMI_MT)
            ? Parameters::GestureMode::SINGLE_TOUCH
            : Parameters::GestureMode::MULTI_TOUCH;

    const PropertyMap& config = deviceContext.getConfiguration();
    std::optional<std::string> gestureModeString = config.getString("touch.gestureMode");
    if (gestureModeString.has_value()) {
        if (*gestureModeString == "single-touch") {
            parameters.gestureMode = Parameters::GestureMode::SINGLE_TOUCH;
        } else if (*gestureModeString == "multi-touch") {
            parameters.gestureMode = Parameters::GestureMode::MULTI_TOUCH;
        } else if (*gestureModeString != "default") {
            ALOGW("Invalid value for touch.gestureMode: '%s'", gestureModeString->c_str());
        }
    }

    parameters.deviceType = computeDeviceType(deviceContext);

    parameters.orientationAware =
@@ -467,8 +449,6 @@ TouchInputMapper::Parameters::DeviceType TouchInputMapper::computeDeviceType(
void TouchInputMapper::dumpParameters(std::string& dump) {
    dump += INDENT3 "Parameters:\n";

    dump += INDENT4 "GestureMode: " + ftl::enum_string(mParameters.gestureMode) + "\n";

    dump += INDENT4 "DeviceType: " + ftl::enum_string(mParameters.deviceType) + "\n";

    dump += StringPrintf(INDENT4 "AssociatedDisplay: hasAssociatedDisplay=%s, isExternal=%s, "
@@ -1834,15 +1814,14 @@ std::list<NotifyArgs> TouchInputMapper::abortTouches(
    if (!currentIdBits.isEmpty()) {
        int32_t metaState = getContext()->getGlobalMetaState();
        int32_t buttonState = mCurrentCookedState.buttonState;
        out.push_back(dispatchMotion(when, readTime, policyFlags, mSource,
        out.push_back(dispatchMotion(when, readTime, policyFlags,
                                     currentGestureDisplayId.value_or(resolveDisplayId()),
                                     AMOTION_EVENT_ACTION_CANCEL, 0, AMOTION_EVENT_FLAG_CANCELED,
                                     metaState, buttonState,
                                     mCurrentCookedState.cookedPointerData.pointerProperties,
                                     mCurrentCookedState.cookedPointerData.pointerCoords,
                                     mCurrentCookedState.cookedPointerData.idToIndex, currentIdBits,
                                     -1, mOrientedXPrecision, mOrientedYPrecision, mDownTime,
                                     MotionClassification::NONE));
                                     -1));
        mCurrentMotionAborted = true;
    }
    return out;
@@ -1890,14 +1869,12 @@ std::list<NotifyArgs> TouchInputMapper::dispatchTouches(nsecs_t when, nsecs_t re
        if (!currentIdBits.isEmpty()) {
            // No pointer id changes so this is a move event.
            // The listener takes care of batching moves so we don't have to deal with that here.
            out.push_back(dispatchMotion(when, readTime, policyFlags, mSource, resolveDisplayId(),
            out.push_back(dispatchMotion(when, readTime, policyFlags, resolveDisplayId(),
                                         AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, buttonState,
                                         mCurrentCookedState.cookedPointerData.pointerProperties,
                                         mCurrentCookedState.cookedPointerData.pointerCoords,
                                         mCurrentCookedState.cookedPointerData.idToIndex,
                                         currentIdBits, -1, mOrientedXPrecision,
                                         mOrientedYPrecision, mDownTime,
                                         MotionClassification::NONE));
                                         currentIdBits, -1));
        }
    } else {
        // There may be pointers going up and pointers going down and pointers moving
@@ -1927,16 +1904,14 @@ std::list<NotifyArgs> TouchInputMapper::dispatchTouches(nsecs_t when, nsecs_t re
            if (isCanceled) {
                ALOGI("Canceling pointer %d for the palm event was detected.", upId);
            }
            out.push_back(dispatchMotion(when, readTime, policyFlags, mSource, resolveDisplayId(),
            out.push_back(dispatchMotion(when, readTime, policyFlags, resolveDisplayId(),
                                         AMOTION_EVENT_ACTION_POINTER_UP, 0,
                                         isCanceled ? AMOTION_EVENT_FLAG_CANCELED : 0, metaState,
                                         buttonState,
                                         mLastCookedState.cookedPointerData.pointerProperties,
                                         mLastCookedState.cookedPointerData.pointerCoords,
                                         mLastCookedState.cookedPointerData.idToIndex,
                                         dispatchedIdBits, upId, mOrientedXPrecision,
                                         mOrientedYPrecision, mDownTime,
                                         MotionClassification::NONE));
                                         dispatchedIdBits, upId));
            dispatchedIdBits.clearBit(upId);
            mCurrentCookedState.cookedPointerData.canceledIdBits.clearBit(upId);
        }
@@ -1946,14 +1921,12 @@ std::list<NotifyArgs> TouchInputMapper::dispatchTouches(nsecs_t when, nsecs_t re
        // events, they do not generally handle them except when presented in a move event.
        if (moveNeeded && !moveIdBits.isEmpty()) {
            ALOG_ASSERT(moveIdBits.value == dispatchedIdBits.value);
            out.push_back(dispatchMotion(when, readTime, policyFlags, mSource, resolveDisplayId(),
            out.push_back(dispatchMotion(when, readTime, policyFlags, resolveDisplayId(),
                                         AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, buttonState,
                                         mCurrentCookedState.cookedPointerData.pointerProperties,
                                         mCurrentCookedState.cookedPointerData.pointerCoords,
                                         mCurrentCookedState.cookedPointerData.idToIndex,
                                         dispatchedIdBits, -1, mOrientedXPrecision,
                                         mOrientedYPrecision, mDownTime,
                                         MotionClassification::NONE));
                                         dispatchedIdBits, -1));
        }

        // Dispatch pointer down events using the new pointer locations.
@@ -1967,13 +1940,12 @@ std::list<NotifyArgs> TouchInputMapper::dispatchTouches(nsecs_t when, nsecs_t re
            }

            out.push_back(
                    dispatchMotion(when, readTime, policyFlags, mSource, resolveDisplayId(),
                    dispatchMotion(when, readTime, policyFlags, resolveDisplayId(),
                                   AMOTION_EVENT_ACTION_POINTER_DOWN, 0, 0, metaState, buttonState,
                                   mCurrentCookedState.cookedPointerData.pointerProperties,
                                   mCurrentCookedState.cookedPointerData.pointerCoords,
                                   mCurrentCookedState.cookedPointerData.idToIndex,
                                   dispatchedIdBits, downId, mOrientedXPrecision,
                                   mOrientedYPrecision, mDownTime, MotionClassification::NONE));
                                   dispatchedIdBits, downId));
        }
    }
    return out;
@@ -1986,15 +1958,13 @@ std::list<NotifyArgs> TouchInputMapper::dispatchHoverExit(nsecs_t when, nsecs_t
        (mCurrentCookedState.cookedPointerData.hoveringIdBits.isEmpty() ||
         !mCurrentCookedState.cookedPointerData.touchingIdBits.isEmpty())) {
        int32_t metaState = getContext()->getGlobalMetaState();
        out.push_back(dispatchMotion(when, readTime, policyFlags, mSource, resolveDisplayId(),
        out.push_back(dispatchMotion(when, readTime, policyFlags, resolveDisplayId(),
                                     AMOTION_EVENT_ACTION_HOVER_EXIT, 0, 0, metaState,
                                     mLastCookedState.buttonState,
                                     mLastCookedState.cookedPointerData.pointerProperties,
                                     mLastCookedState.cookedPointerData.pointerCoords,
                                     mLastCookedState.cookedPointerData.idToIndex,
                                     mLastCookedState.cookedPointerData.hoveringIdBits, -1,
                                     mOrientedXPrecision, mOrientedYPrecision, mDownTime,
                                     MotionClassification::NONE));
                                     mLastCookedState.cookedPointerData.hoveringIdBits, -1));
        mSentHoverEnter = false;
    }
    return out;
@@ -2007,27 +1977,23 @@ std::list<NotifyArgs> TouchInputMapper::dispatchHoverEnterAndMove(nsecs_t when,
        !mCurrentCookedState.cookedPointerData.hoveringIdBits.isEmpty()) {
        int32_t metaState = getContext()->getGlobalMetaState();
        if (!mSentHoverEnter) {
            out.push_back(dispatchMotion(when, readTime, policyFlags, mSource, resolveDisplayId(),
            out.push_back(dispatchMotion(when, readTime, policyFlags, resolveDisplayId(),
                                         AMOTION_EVENT_ACTION_HOVER_ENTER, 0, 0, metaState,
                                         mCurrentRawState.buttonState,
                                         mCurrentCookedState.cookedPointerData.pointerProperties,
                                         mCurrentCookedState.cookedPointerData.pointerCoords,
                                         mCurrentCookedState.cookedPointerData.idToIndex,
                                         mCurrentCookedState.cookedPointerData.hoveringIdBits, -1,
                                         mOrientedXPrecision, mOrientedYPrecision, mDownTime,
                                         MotionClassification::NONE));
                                         mCurrentCookedState.cookedPointerData.hoveringIdBits, -1));
            mSentHoverEnter = true;
        }

        out.push_back(dispatchMotion(when, readTime, policyFlags, mSource, resolveDisplayId(),
        out.push_back(dispatchMotion(when, readTime, policyFlags, resolveDisplayId(),
                                     AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, metaState,
                                     mCurrentRawState.buttonState,
                                     mCurrentCookedState.cookedPointerData.pointerProperties,
                                     mCurrentCookedState.cookedPointerData.pointerCoords,
                                     mCurrentCookedState.cookedPointerData.idToIndex,
                                     mCurrentCookedState.cookedPointerData.hoveringIdBits, -1,
                                     mOrientedXPrecision, mOrientedYPrecision, mDownTime,
                                     MotionClassification::NONE));
                                     mCurrentCookedState.cookedPointerData.hoveringIdBits, -1));
    }
    return out;
}
@@ -2042,14 +2008,12 @@ std::list<NotifyArgs> TouchInputMapper::dispatchButtonRelease(nsecs_t when, nsec
    while (!releasedButtons.isEmpty()) {
        int32_t actionButton = BitSet32::valueForBit(releasedButtons.clearFirstMarkedBit());
        buttonState &= ~actionButton;
        out.push_back(dispatchMotion(when, readTime, policyFlags, mSource, resolveDisplayId(),
        out.push_back(dispatchMotion(when, readTime, policyFlags, resolveDisplayId(),
                                     AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, 0,
                                     metaState, buttonState,
                                     mLastCookedState.cookedPointerData.pointerProperties,
                                     mLastCookedState.cookedPointerData.pointerCoords,
                                     mLastCookedState.cookedPointerData.idToIndex, idBits, -1,
                                     mOrientedXPrecision, mOrientedYPrecision, mDownTime,
                                     MotionClassification::NONE));
                                     mLastCookedState.cookedPointerData.idToIndex, idBits, -1));
    }
    return out;
}
@@ -2064,14 +2028,12 @@ std::list<NotifyArgs> TouchInputMapper::dispatchButtonPress(nsecs_t when, nsecs_
    while (!pressedButtons.isEmpty()) {
        int32_t actionButton = BitSet32::valueForBit(pressedButtons.clearFirstMarkedBit());
        buttonState |= actionButton;
        out.push_back(dispatchMotion(when, readTime, policyFlags, mSource, resolveDisplayId(),
        out.push_back(dispatchMotion(when, readTime, policyFlags, resolveDisplayId(),
                                     AMOTION_EVENT_ACTION_BUTTON_PRESS, actionButton, 0, metaState,
                                     buttonState,
                                     mCurrentCookedState.cookedPointerData.pointerProperties,
                                     mCurrentCookedState.cookedPointerData.pointerCoords,
                                     mCurrentCookedState.cookedPointerData.idToIndex, idBits, -1,
                                     mOrientedXPrecision, mOrientedYPrecision, mDownTime,
                                     MotionClassification::NONE));
                                     mCurrentCookedState.cookedPointerData.idToIndex, idBits, -1));
    }
    return out;
}
@@ -2308,12 +2270,10 @@ void TouchInputMapper::cookPointerData() {
}

NotifyMotionArgs TouchInputMapper::dispatchMotion(
        nsecs_t when, nsecs_t readTime, uint32_t policyFlags, uint32_t source,
        ui::LogicalDisplayId displayId, int32_t action, int32_t actionButton, int32_t flags,
        int32_t metaState, int32_t buttonState, const PropertiesArray& properties,
        const CoordsArray& coords, const IdToIndexArray& idToIndex, BitSet32 idBits,
        int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime,
        MotionClassification classification) const {
        nsecs_t when, nsecs_t readTime, uint32_t policyFlags, ui::LogicalDisplayId displayId,
        int32_t action, int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState,
        const PropertiesArray& properties, const CoordsArray& coords,
        const IdToIndexArray& idToIndex, BitSet32 idBits, int32_t changedId) const {
    std::vector<PointerCoords> pointerCoords;
    std::vector<PointerProperties> pointerProperties;
    uint32_t pointerCount = 0;
@@ -2349,6 +2309,7 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion(
            ALOG_ASSERT(false);
        }
    }
    uint32_t source = mSource;
    if (mCurrentStreamModifiedByExternalStylus) {
        source |= AINPUT_SOURCE_BLUETOOTH_STYLUS;
    }
@@ -2375,9 +2336,9 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion(
                  [this](TouchVideoFrame& frame) { frame.rotate(this->mInputDeviceOrientation); });
    return NotifyMotionArgs(getContext()->getNextId(), when, readTime, deviceId, source, displayId,
                            policyFlags, action, actionButton, flags, metaState, buttonState,
                            classification, pointerCount, pointerProperties.data(),
                            pointerCoords.data(), xPrecision, yPrecision, xCursorPosition,
                            yCursorPosition, downTime, std::move(frames));
                            MotionClassification::NONE, pointerCount, pointerProperties.data(),
                            pointerCoords.data(), mOrientedXPrecision, mOrientedYPrecision,
                            xCursorPosition, yCursorPosition, mDownTime, std::move(frames));
}

std::list<NotifyArgs> TouchInputMapper::cancelTouch(nsecs_t when, nsecs_t readTime) {
@@ -2444,6 +2405,11 @@ void TouchInputMapper::assignPointerIds(const RawState& last, RawState& current)
    // match (by distance) for each current pointer.
    // The pointers must have the same tool type but it is possible for them to
    // transition from hovering to touching or vice-versa while retaining the same id.
    struct PointerDistanceHeapElement {
        uint32_t currentPointerIndex : 8 {};
        uint32_t lastPointerIndex : 8 {};
        uint64_t distanceSq : 48 {};
    };
    PointerDistanceHeapElement heap[MAX_POINTERS * MAX_POINTERS];

    uint32_t heapSize = 0;
@@ -2459,12 +2425,12 @@ void TouchInputMapper::assignPointerIds(const RawState& last, RawState& current)
                int64_t deltaX = currentPointer.x - lastPointer.x;
                int64_t deltaY = currentPointer.y - lastPointer.y;

                uint64_t distance = uint64_t(deltaX * deltaX + deltaY * deltaY);
                uint64_t distanceSq = uint64_t(deltaX * deltaX + deltaY * deltaY);

                // Insert new element into the heap (sift up).
                heap[heapSize].currentPointerIndex = currentPointerIndex;
                heap[heapSize].lastPointerIndex = lastPointerIndex;
                heap[heapSize].distance = distance;
                heap[heapSize].distanceSq = distanceSq;
                heapSize += 1;
            }
        }
@@ -2480,11 +2446,11 @@ void TouchInputMapper::assignPointerIds(const RawState& last, RawState& current)
            }

            if (childIndex + 1 < heapSize &&
                heap[childIndex + 1].distance < heap[childIndex].distance) {
                heap[childIndex + 1].distanceSq < heap[childIndex].distanceSq) {
                childIndex += 1;
            }

            if (heap[parentIndex].distance <= heap[childIndex].distance) {
            if (heap[parentIndex].distanceSq <= heap[childIndex].distanceSq) {
                break;
            }

@@ -2497,7 +2463,7 @@ void TouchInputMapper::assignPointerIds(const RawState& last, RawState& current)
        ALOGD("assignPointerIds - initial distance min-heap: size=%d", heapSize);
        for (size_t i = 0; i < heapSize; i++) {
            ALOGD("  heap[%zu]: cur=%" PRIu32 ", last=%" PRIu32 ", distance=%" PRIu64, i,
                  heap[i].currentPointerIndex, heap[i].lastPointerIndex, heap[i].distance);
                  heap[i].currentPointerIndex, heap[i].lastPointerIndex, heap[i].distanceSq);
        }
    }

@@ -2526,11 +2492,11 @@ void TouchInputMapper::assignPointerIds(const RawState& last, RawState& current)
                    }

                    if (childIndex + 1 < heapSize &&
                        heap[childIndex + 1].distance < heap[childIndex].distance) {
                        heap[childIndex + 1].distanceSq < heap[childIndex].distanceSq) {
                        childIndex += 1;
                    }

                    if (heap[parentIndex].distance <= heap[childIndex].distance) {
                    if (heap[parentIndex].distanceSq <= heap[childIndex].distanceSq) {
                        break;
                    }

@@ -2543,7 +2509,7 @@ void TouchInputMapper::assignPointerIds(const RawState& last, RawState& current)
                    for (size_t j = 0; j < heapSize; j++) {
                        ALOGD("  heap[%zu]: cur=%" PRIu32 ", last=%" PRIu32 ", distance=%" PRIu64,
                              j, heap[j].currentPointerIndex, heap[j].lastPointerIndex,
                              heap[j].distance);
                              heap[j].distanceSq);
                    }
                }
            }
@@ -2569,8 +2535,8 @@ void TouchInputMapper::assignPointerIds(const RawState& last, RawState& current)

            ALOGD_IF(DEBUG_POINTER_ASSIGNMENT,
                     "assignPointerIds - matched: cur=%" PRIu32 ", last=%" PRIu32 ", id=%" PRIu32
                     ", distance=%" PRIu64,
                     lastPointerIndex, currentPointerIndex, id, heap[0].distance);
                     ", distanceSq=%" PRIu64,
                     lastPointerIndex, currentPointerIndex, id, heap[0].distanceSq);
            break;
        }
    }
+4 −20
Original line number Diff line number Diff line
@@ -239,14 +239,6 @@ protected:

        std::string uniqueDisplayId;

        enum class GestureMode {
            SINGLE_TOUCH,
            MULTI_TOUCH,

            ftl_last = MULTI_TOUCH
        };
        GestureMode gestureMode;

        bool wake;

        // The Universal Stylus Initiative (USI) protocol version supported by this device.
@@ -502,12 +494,6 @@ private:
        int32_t scanCode;
    } mCurrentVirtualKey;

    struct PointerDistanceHeapElement {
        uint32_t currentPointerIndex : 8 {};
        uint32_t lastPointerIndex : 8 {};
        uint64_t distance : 48 {}; // squared distance
    };

    std::optional<DisplayViewport> findViewport();

    void resetExternalStylus();
@@ -554,12 +540,10 @@ private:
    // method will take care of setting the index and transmuting the action to DOWN or UP
    // it is the first / last pointer to go down / up.
    [[nodiscard]] NotifyMotionArgs dispatchMotion(
            nsecs_t when, nsecs_t readTime, uint32_t policyFlags, uint32_t source,
            ui::LogicalDisplayId displayId, int32_t action, int32_t actionButton, int32_t flags,
            int32_t metaState, int32_t buttonState, const PropertiesArray& properties,
            const CoordsArray& coords, const IdToIndexArray& idToIndex, BitSet32 idBits,
            int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime,
            MotionClassification classification) const;
            nsecs_t when, nsecs_t readTime, uint32_t policyFlags, ui::LogicalDisplayId displayId,
            int32_t action, int32_t actionButton, int32_t flags, int32_t metaState,
            int32_t buttonState, const PropertiesArray& properties, const CoordsArray& coords,
            const IdToIndexArray& idToIndex, BitSet32 idBits, int32_t changedId) const;

    // Returns if this touch device is a touch screen with an associated display.
    bool isTouchScreen();