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

Commit 0abd019f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic...

Merge changes from topic "revert-16336498-revert-16306432-revert-16295572-ORWQJPYRMQ-IQBEBXXQNX-CARGQZNFNA"

* changes:
  Revert "Reland "Input injection: Assume transformed values are i...""
  Revert "Reland "Remove x/y offset from MotionEntry""
parents f244445c 663fc83b
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -382,6 +382,7 @@ struct PointerCoords {
    // window scale. The global scale will be applied to TOUCH/TOOL_MAJOR/MINOR
    // axes, however the window scaling will not.
    void scale(float globalScale, float windowXScale, float windowYScale);
    void applyOffset(float xOffset, float yOffset);

    void transform(const ui::Transform& transform);

@@ -571,7 +572,7 @@ public:

    inline float getYOffset() const { return mTransform.ty(); }

    inline const ui::Transform& getTransform() const { return mTransform; }
    inline ui::Transform getTransform() const { return mTransform; }

    int getSurfaceRotation() const;

@@ -589,7 +590,7 @@ public:

    void setCursorPosition(float x, float y);

    inline const ui::Transform& getRawTransform() const { return mRawTransform; }
    ui::Transform getRawTransform() const { return mRawTransform; }

    static inline bool isValidCursorPosition(float x, float y) { return !isnan(x) && !isnan(y); }

+5 −0
Original line number Diff line number Diff line
@@ -344,6 +344,11 @@ void PointerCoords::scale(float globalScaleFactor, float windowXScale, float win
    scaleAxisValue(*this, AMOTION_EVENT_AXIS_RELATIVE_Y, windowYScale);
}

void PointerCoords::applyOffset(float xOffset, float yOffset) {
    setAxisValue(AMOTION_EVENT_AXIS_X, getX() + xOffset);
    setAxisValue(AMOTION_EVENT_AXIS_Y, getY() + yOffset);
}

#ifdef __linux__
status_t PointerCoords::readFromParcel(Parcel* parcel) {
    bits = parcel->readInt64();
+4 −1
Original line number Diff line number Diff line
@@ -214,7 +214,7 @@ MotionEntry::MotionEntry(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32
                         int32_t edgeFlags, float xPrecision, float yPrecision,
                         float xCursorPosition, float yCursorPosition, nsecs_t downTime,
                         uint32_t pointerCount, const PointerProperties* pointerProperties,
                         const PointerCoords* pointerCoords)
                         const PointerCoords* pointerCoords, float xOffset, float yOffset)
      : EventEntry(id, Type::MOTION, eventTime, policyFlags),
        deviceId(deviceId),
        source(source),
@@ -235,6 +235,9 @@ MotionEntry::MotionEntry(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32
    for (uint32_t i = 0; i < pointerCount; i++) {
        this->pointerProperties[i].copyFrom(pointerProperties[i]);
        this->pointerCoords[i].copyFrom(pointerCoords[i]);
        if (xOffset || yOffset) {
            this->pointerCoords[i].applyOffset(xOffset, yOffset);
        }
    }
}

+2 −1
Original line number Diff line number Diff line
@@ -184,7 +184,8 @@ struct MotionEntry : EventEntry {
                int32_t metaState, int32_t buttonState, MotionClassification classification,
                int32_t edgeFlags, float xPrecision, float yPrecision, float xCursorPosition,
                float yCursorPosition, nsecs_t downTime, uint32_t pointerCount,
                const PointerProperties* pointerProperties, const PointerCoords* pointerCoords);
                const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
                float xOffset, float yOffset);
    std::string getDescription() const override;

    ~MotionEntry() override;
+38 −23
Original line number Diff line number Diff line
@@ -378,7 +378,7 @@ std::unique_ptr<DispatchEntry> createDispatchEntry(const InputTarget& inputTarge
                                          motionEntry.yPrecision, motionEntry.xCursorPosition,
                                          motionEntry.yCursorPosition, motionEntry.downTime,
                                          motionEntry.pointerCount, motionEntry.pointerProperties,
                                          pointerCoords.data());
                                          pointerCoords.data(), 0 /* xOffset */, 0 /* yOffset */);

    if (motionEntry.injectionState) {
        combinedMotionEntry->injectionState = motionEntry.injectionState;
@@ -506,6 +506,12 @@ bool isConnectionResponsive(const Connection& connection) {
    return true;
}

vec2 transformWithoutTranslation(const ui::Transform& transform, float x, float y) {
    const vec2 transformedXy = transform.transform(x, y);
    const vec2 transformedOrigin = transform.transform(0, 0);
    return transformedXy - transformedOrigin;
}

// Returns true if the event type passed as argument represents a user activity.
bool isUserActivityEvent(const EventEntry& eventEntry) {
    switch (eventEntry.type) {
@@ -3757,7 +3763,7 @@ std::unique_ptr<MotionEntry> InputDispatcher::splitMotionEvent(
                                          originalMotionEntry.xCursorPosition,
                                          originalMotionEntry.yCursorPosition,
                                          originalMotionEntry.downTime, splitPointerCount,
                                          splitPointerProperties, splitPointerCoords);
                                          splitPointerProperties, splitPointerCoords, 0, 0);

    if (originalMotionEntry.injectionState) {
        splitMotionEntry->injectionState = originalMotionEntry.injectionState;
@@ -3983,7 +3989,7 @@ void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) {
                                              args->xPrecision, args->yPrecision,
                                              args->xCursorPosition, args->yCursorPosition,
                                              args->downTime, args->pointerCount,
                                              args->pointerProperties, args->pointerCoords);
                                              args->pointerProperties, args->pointerCoords, 0, 0);

        if (args->id != android::os::IInputConstants::INVALID_INPUT_EVENT_ID &&
            IdGenerator::getSource(args->id) == IdGenerator::Source::INPUT_READER &&
@@ -4213,8 +4219,10 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(
                                                  motionEvent.getRawXCursorPosition(),
                                                  motionEvent.getRawYCursorPosition(),
                                                  motionEvent.getDownTime(), uint32_t(pointerCount),
                                                  pointerProperties, samplePointerCoords);
            transformMotionEntryForInjectionLocked(*injectedEntry, motionEvent.getTransform());
                                                  pointerProperties, samplePointerCoords,
                                                  motionEvent.getXOffset(),
                                                  motionEvent.getYOffset());
            transformMotionEntryForInjectionLocked(*injectedEntry);
            injectedEntries.push(std::move(injectedEntry));
            for (size_t i = motionEvent.getHistorySize(); i > 0; i--) {
                sampleEventTimes += 1;
@@ -4233,9 +4241,9 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(
                                                      motionEvent.getRawYCursorPosition(),
                                                      motionEvent.getDownTime(),
                                                      uint32_t(pointerCount), pointerProperties,
                                                      samplePointerCoords);
                transformMotionEntryForInjectionLocked(*nextInjectedEntry,
                                                       motionEvent.getTransform());
                                                      samplePointerCoords, motionEvent.getXOffset(),
                                                      motionEvent.getYOffset());
                transformMotionEntryForInjectionLocked(*nextInjectedEntry);
                injectedEntries.push(std::move(nextInjectedEntry));
            }
            break;
@@ -4399,28 +4407,35 @@ void InputDispatcher::setInjectionResult(EventEntry& entry,
    }
}

void InputDispatcher::transformMotionEntryForInjectionLocked(
        MotionEntry& entry, const ui::Transform& injectedTransform) const {
void InputDispatcher::transformMotionEntryForInjectionLocked(MotionEntry& entry) const {
    const bool isRelativeMouseEvent = isFromSource(entry.source, AINPUT_SOURCE_MOUSE_RELATIVE);
    if (!isRelativeMouseEvent && !isFromSource(entry.source, AINPUT_SOURCE_CLASS_POINTER)) {
        return;
    }

    // Input injection works in the logical display coordinate space, but the input pipeline works
    // display space, so we need to transform the injected events accordingly.
    const auto it = mDisplayInfos.find(entry.displayId);
    if (it == mDisplayInfos.end()) return;
    const auto& transformToDisplay = it->second.transform.inverse() * injectedTransform;
    const auto& transformToDisplay = it->second.transform.inverse();

    for (uint32_t i = 0; i < entry.pointerCount; i++) {
        PointerCoords& pc = entry.pointerCoords[i];
        // Make a copy of the injected coords. We cannot change them in place because some of them
        // are interdependent (for example, X coordinate might depend on the Y coordinate).
        PointerCoords injectedCoords = entry.pointerCoords[i];

        BitSet64 bits(injectedCoords.bits);
        while (!bits.isEmpty()) {
            const auto axis = static_cast<int32_t>(bits.clearFirstMarkedBit());
            const float value =
                    MotionEvent::calculateTransformedAxisValue(axis, entry.source,
                                                               transformToDisplay, injectedCoords);
            pc.setAxisValue(axis, value);
        }
        const auto xy = isRelativeMouseEvent
                ? transformWithoutTranslation(transformToDisplay, pc.getX(), pc.getY())
                : transformToDisplay.transform(pc.getXYValue());
        pc.setAxisValue(AMOTION_EVENT_AXIS_X, xy.x);
        pc.setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y);

        // Axes with relative values never represent points on a screen, so they should never have
        // translation applied. If a device does not report relative values, these values are always
        // 0, and will remain unaffected by the following operation.
        const auto rel =
                transformWithoutTranslation(transformToDisplay,
                                            pc.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X),
                                            pc.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y));
        pc.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, rel.x);
        pc.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, rel.y);
    }
}

Loading