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

Commit 69e4d0f5 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Extend the for loop to use all samples

Currently, the last sample is treated in a special manner (consistent
with the docs for MotionEvent).
However, the public api of MotionEvent also work fine if the element at
index [historySize] is accessed.

Therefore, calling event.getX() is the same as calling
event.getHistoricalX(historySize).

To simplify the code, remove the redundant code and instead extend the
loop by 1.

Bug: 167946721
Test: atest libinput_tests
Change-Id: Icc1fff1b0f16d63d7d0eb33e5977a3b3b440f562
parent d2ea0d59
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -578,10 +578,18 @@ public:

    float getAxisValue(int32_t axis, size_t pointerIndex) const;

    /**
     * Get the X coordinate of the latest sample in this MotionEvent for pointer 'pointerIndex'.
     * Identical to calling getHistoricalX(pointerIndex, getHistorySize()).
     */
    inline float getX(size_t pointerIndex) const {
        return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
    }

    /**
     * Get the Y coordinate of the latest sample in this MotionEvent for pointer 'pointerIndex'.
     * Identical to calling getHistoricalX(pointerIndex, getHistorySize()).
     */
    inline float getY(size_t pointerIndex) const {
        return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
    }
+2 −11
Original line number Diff line number Diff line
@@ -289,13 +289,12 @@ void VelocityTracker::addMovement(const MotionEvent* event) {
        pointerIndex[i] = idBits.getIndexOfBit(event->getPointerId(i));
    }

    nsecs_t eventTime;
    std::vector<Position> positions;
    positions.resize(pointerCount);

    size_t historySize = event->getHistorySize();
    for (size_t h = 0; h < historySize; h++) {
        eventTime = event->getHistoricalEventTime(h);
    for (size_t h = 0; h <= historySize; h++) {
        nsecs_t eventTime = event->getHistoricalEventTime(h);
        for (size_t i = 0; i < pointerCount; i++) {
            uint32_t index = pointerIndex[i];
            positions[index].x = event->getHistoricalX(i, h);
@@ -303,14 +302,6 @@ void VelocityTracker::addMovement(const MotionEvent* event) {
        }
        addMovement(eventTime, idBits, positions);
    }

    eventTime = event->getEventTime();
    for (size_t i = 0; i < pointerCount; i++) {
        uint32_t index = pointerIndex[i];
        positions[index].x = event->getX(i);
        positions[index].y = event->getY(i);
    }
    addMovement(eventTime, idBits, positions);
}

bool VelocityTracker::getVelocity(uint32_t id, float* outVx, float* outVy) const {