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

Commit e3909ece authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 7328689 from 8ad4bf4f to sc-release

Change-Id: I21f75a6ceb43f6b750727a43a6a6f52f971d4412
parents 5a808f3e 8ad4bf4f
Loading
Loading
Loading
Loading
+33 −3
Original line number Diff line number Diff line
@@ -318,6 +318,12 @@ private:
 */
constexpr float AMOTION_EVENT_INVALID_CURSOR_POSITION = std::numeric_limits<float>::quiet_NaN();

/**
 * Invalid value for display size. Used when display size isn't available for an event or doesn't
 * matter. This is just a constant 0 so that it has no effect if unused.
 */
constexpr int32_t AMOTION_EVENT_INVALID_DISPLAY_SIZE = 0;

/*
 * Pointer coordinate data.
 */
@@ -360,6 +366,8 @@ struct PointerCoords {
        return getAxisValue(AMOTION_EVENT_AXIS_Y);
    }

    vec2 getXYValue() const { return vec2(getX(), getY()); }

#ifdef __linux__
    status_t readFromParcel(Parcel* parcel);
    status_t writeToParcel(Parcel* parcel) const;
@@ -548,6 +556,8 @@ public:

    void setCursorPosition(float x, float y);

    int2 getDisplaySize() const { return {mDisplayWidth, mDisplayHeight}; }

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

    inline nsecs_t getDownTime() const { return mDownTime; }
@@ -570,8 +580,17 @@ public:

    inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; }

    /**
     * The actual raw pointer coords: whatever comes from the input device without any external
     * transforms applied.
     */
    const PointerCoords* getRawPointerCoords(size_t pointerIndex) const;

    /**
     * This is the raw axis value. However, for X/Y axes, this currently applies a "compat-raw"
     * transform because many apps (incorrectly) assumed that raw == oriented-screen-space.
     * "compat raw" is raw coordinates with screen rotation applied.
     */
    float getRawAxisValue(int32_t axis, size_t pointerIndex) const;

    inline float getRawX(size_t pointerIndex) const {
@@ -634,9 +653,18 @@ public:
        return mSampleEventTimes[historicalIndex];
    }

    /**
     * The actual raw pointer coords: whatever comes from the input device without any external
     * transforms applied.
     */
    const PointerCoords* getHistoricalRawPointerCoords(
            size_t pointerIndex, size_t historicalIndex) const;

    /**
     * This is the raw axis value. However, for X/Y axes, this currently applies a "compat-raw"
     * transform because many apps (incorrectly) assumed that raw == oriented-screen-space.
     * "compat raw" is raw coordinates with screen rotation applied.
     */
    float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
            size_t historicalIndex) const;

@@ -704,9 +732,9 @@ public:
                    int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState,
                    MotionClassification classification, const ui::Transform& transform,
                    float xPrecision, float yPrecision, float rawXCursorPosition,
                    float rawYCursorPosition, nsecs_t downTime, nsecs_t eventTime,
                    size_t pointerCount, const PointerProperties* pointerProperties,
                    const PointerCoords* pointerCoords);
                    float rawYCursorPosition, int32_t displayWidth, int32_t displayHeight,
                    nsecs_t downTime, nsecs_t eventTime, size_t pointerCount,
                    const PointerProperties* pointerProperties, const PointerCoords* pointerCoords);

    void copyFrom(const MotionEvent* other, bool keepHistory);

@@ -759,6 +787,8 @@ protected:
    float mYPrecision;
    float mRawXCursorPosition;
    float mRawYCursorPosition;
    int32_t mDisplayWidth;
    int32_t mDisplayHeight;
    nsecs_t mDownTime;
    Vector<PointerProperties> mPointerProperties;
    std::vector<nsecs_t> mSampleEventTimes;
+5 −2
Original line number Diff line number Diff line
@@ -136,6 +136,8 @@ struct InputMessage {
            float yPrecision;
            float xCursorPosition;
            float yCursorPosition;
            int32_t displayWidth;
            int32_t displayHeight;
            uint32_t pointerCount;
            uint32_t empty3;
            /**
@@ -353,8 +355,9 @@ public:
                                int32_t metaState, int32_t buttonState,
                                MotionClassification classification, const ui::Transform& transform,
                                float xPrecision, float yPrecision, float xCursorPosition,
                                float yCursorPosition, nsecs_t downTime, nsecs_t eventTime,
                                uint32_t pointerCount, const PointerProperties* pointerProperties,
                                float yCursorPosition, int32_t displayWidth, int32_t displayHeight,
                                nsecs_t downTime, nsecs_t eventTime, uint32_t pointerCount,
                                const PointerProperties* pointerProperties,
                                const PointerCoords* pointerCoords);

    /* Publishes a focus event to the input channel.
+4 −0
Original line number Diff line number Diff line
@@ -168,6 +168,10 @@ struct InputWindowInfo : public Parcelable {
    // Transform applied to individual windows.
    ui::Transform transform;

    // Display size in its natural rotation. Used to rotate raw coordinates for compatibility.
    int32_t displayWidth = AMOTION_EVENT_INVALID_DISPLAY_SIZE;
    int32_t displayHeight = AMOTION_EVENT_INVALID_DISPLAY_SIZE;

    /*
     * This is filled in by the WM relative to the frame and then translated
     * to absolute coordinates by SurfaceFlinger once the frame is computed.
+41 −16
Original line number Diff line number Diff line
@@ -340,7 +340,8 @@ void MotionEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int3
                             int32_t flags, int32_t edgeFlags, int32_t metaState,
                             int32_t buttonState, MotionClassification classification,
                             const ui::Transform& transform, float xPrecision, float yPrecision,
                             float rawXCursorPosition, float rawYCursorPosition, nsecs_t downTime,
                             float rawXCursorPosition, float rawYCursorPosition,
                             int32_t displayWidth, int32_t displayHeight, nsecs_t downTime,
                             nsecs_t eventTime, size_t pointerCount,
                             const PointerProperties* pointerProperties,
                             const PointerCoords* pointerCoords) {
@@ -357,6 +358,8 @@ void MotionEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int3
    mYPrecision = yPrecision;
    mRawXCursorPosition = rawXCursorPosition;
    mRawYCursorPosition = rawYCursorPosition;
    mDisplayWidth = displayWidth;
    mDisplayHeight = displayHeight;
    mDownTime = downTime;
    mPointerProperties.clear();
    mPointerProperties.appendArray(pointerProperties, pointerCount);
@@ -380,6 +383,8 @@ void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) {
    mYPrecision = other->mYPrecision;
    mRawXCursorPosition = other->mRawXCursorPosition;
    mRawYCursorPosition = other->mRawYCursorPosition;
    mDisplayWidth = other->mDisplayWidth;
    mDisplayHeight = other->mDisplayHeight;
    mDownTime = other->mDownTime;
    mPointerProperties = other->mPointerProperties;

@@ -426,7 +431,7 @@ const PointerCoords* MotionEvent::getRawPointerCoords(size_t pointerIndex) const
}

float MotionEvent::getRawAxisValue(int32_t axis, size_t pointerIndex) const {
    return getRawPointerCoords(pointerIndex)->getAxisValue(axis);
    return getHistoricalRawAxisValue(axis, pointerIndex, getHistorySize());
}

float MotionEvent::getAxisValue(int32_t axis, size_t pointerIndex) const {
@@ -440,28 +445,44 @@ const PointerCoords* MotionEvent::getHistoricalRawPointerCoords(

float MotionEvent::getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
        size_t historicalIndex) const {
    if (axis != AMOTION_EVENT_AXIS_X && axis != AMOTION_EVENT_AXIS_Y) {
        return getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getAxisValue(axis);
    }
    // 0x7 encapsulates all 3 rotations (see ui::Transform::RotationFlags)
    static const int ALL_ROTATIONS_MASK = 0x7;
    uint32_t orientation = (mTransform.getOrientation() & ALL_ROTATIONS_MASK);
    if (orientation == ui::Transform::ROT_0) {
        return getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getAxisValue(axis);
    }

    // For compatibility, convert raw coordinates into "oriented screen space". Once app developers
    // are educated about getRaw, we can consider removing this.
    vec2 xy = getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getXYValue();
    const float unrotatedX = xy.x;
    if (orientation == ui::Transform::ROT_90) {
        xy.x = mDisplayHeight - xy.y;
        xy.y = unrotatedX;
    } else if (orientation == ui::Transform::ROT_180) {
        xy.x = mDisplayWidth - xy.x;
        xy.y = mDisplayHeight - xy.y;
    } else if (orientation == ui::Transform::ROT_270) {
        xy.x = xy.y;
        xy.y = mDisplayWidth - unrotatedX;
    }
    static_assert(AMOTION_EVENT_AXIS_X == 0 && AMOTION_EVENT_AXIS_Y == 1);
    return xy[axis];
}

float MotionEvent::getHistoricalAxisValue(int32_t axis, size_t pointerIndex,
        size_t historicalIndex) const {
    if (axis != AMOTION_EVENT_AXIS_X && axis != AMOTION_EVENT_AXIS_Y) {
        return getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getAxisValue(axis);
    }

    float rawX = getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getX();
    float rawY = getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getY();
    vec2 vals = mTransform.transform(rawX, rawY);

    switch (axis) {
    case AMOTION_EVENT_AXIS_X:
        return vals.x;
    case AMOTION_EVENT_AXIS_Y:
        return vals.y;
    }

    // This should never happen
    return 0;
    vec2 vals = mTransform.transform(
            getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getXYValue());
    static_assert(AMOTION_EVENT_AXIS_X == 0 && AMOTION_EVENT_AXIS_Y == 1);
    return vals[axis];
}

ssize_t MotionEvent::findPointerIndex(int32_t pointerId) const {
@@ -606,6 +627,8 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) {
    mYPrecision = parcel->readFloat();
    mRawXCursorPosition = parcel->readFloat();
    mRawYCursorPosition = parcel->readFloat();
    mDisplayWidth = parcel->readInt32();
    mDisplayHeight = parcel->readInt32();
    mDownTime = parcel->readInt64();

    mPointerProperties.clear();
@@ -665,6 +688,8 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const {
    parcel->writeFloat(mYPrecision);
    parcel->writeFloat(mRawXCursorPosition);
    parcel->writeFloat(mRawYCursorPosition);
    parcel->writeInt32(mDisplayWidth);
    parcel->writeInt32(mDisplayHeight);
    parcel->writeInt64(mDownTime);

    for (size_t i = 0; i < pointerCount; i++) {
+10 −3
Original line number Diff line number Diff line
@@ -228,6 +228,10 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const {
            msg->body.motion.xCursorPosition = body.motion.xCursorPosition;
            // float yCursorPosition
            msg->body.motion.yCursorPosition = body.motion.yCursorPosition;
            // int32_t displayW
            msg->body.motion.displayWidth = body.motion.displayWidth;
            // int32_t displayH
            msg->body.motion.displayHeight = body.motion.displayHeight;
            // uint32_t pointerCount
            msg->body.motion.pointerCount = body.motion.pointerCount;
            //struct Pointer pointers[MAX_POINTERS]
@@ -517,9 +521,9 @@ status_t InputPublisher::publishMotionEvent(
        std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags,
        int32_t edgeFlags, int32_t metaState, int32_t buttonState,
        MotionClassification classification, const ui::Transform& transform, float xPrecision,
        float yPrecision, float xCursorPosition, float yCursorPosition, nsecs_t downTime,
        nsecs_t eventTime, uint32_t pointerCount, const PointerProperties* pointerProperties,
        const PointerCoords* pointerCoords) {
        float yPrecision, float xCursorPosition, float yCursorPosition, int32_t displayWidth,
        int32_t displayHeight, nsecs_t downTime, nsecs_t eventTime, uint32_t pointerCount,
        const PointerProperties* pointerProperties, const PointerCoords* pointerCoords) {
    if (ATRACE_ENABLED()) {
        std::string message = StringPrintf(
                "publishMotionEvent(inputChannel=%s, action=%" PRId32 ")",
@@ -577,6 +581,8 @@ status_t InputPublisher::publishMotionEvent(
    msg.body.motion.yPrecision = yPrecision;
    msg.body.motion.xCursorPosition = xCursorPosition;
    msg.body.motion.yCursorPosition = yCursorPosition;
    msg.body.motion.displayWidth = displayWidth;
    msg.body.motion.displayHeight = displayHeight;
    msg.body.motion.downTime = downTime;
    msg.body.motion.eventTime = eventTime;
    msg.body.motion.pointerCount = pointerCount;
@@ -1343,6 +1349,7 @@ void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage
                      msg->body.motion.buttonState, msg->body.motion.classification, transform,
                      msg->body.motion.xPrecision, msg->body.motion.yPrecision,
                      msg->body.motion.xCursorPosition, msg->body.motion.yCursorPosition,
                      msg->body.motion.displayWidth, msg->body.motion.displayHeight,
                      msg->body.motion.downTime, msg->body.motion.eventTime, pointerCount,
                      pointerProperties, pointerCoords);
}
Loading