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

Commit 4e955a2d authored by Philip Quinn's avatar Philip Quinn
Browse files

Mark all pointers in a resampled event as resampled.

Even if the coordinates for a pointer are not resampled, they will be
added to an event with a timestamp that doesn't match what the device
is reporting. Algorithms that care about the consistency of pointer
coordinates will want to handle these events in the same manner as
resampled coordinates -- otherwise it may appear as though the
pointer has suddenly stopped moving.

Bug: 301277887
Test: atest --host libinput_tests
Change-Id: Idc833e9844856172ff749a90ee584292536524dc
parent 102d39db
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1276,13 +1276,13 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event,
        PointerCoords& resampledCoords = touchState.lastResample.pointers[i];
        const PointerCoords& currentCoords = current->getPointerById(id);
        resampledCoords = currentCoords;
        resampledCoords.isResampled = true;
        if (other->idBits.hasBit(id) && shouldResampleTool(event->getToolType(i))) {
            const PointerCoords& otherCoords = other->getPointerById(id);
            resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_X,
                                         lerp(currentCoords.getX(), otherCoords.getX(), alpha));
            resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y,
                                         lerp(currentCoords.getY(), otherCoords.getY(), alpha));
            resampledCoords.isResampled = true;
            ALOGD_IF(debugResampling(),
                     "[%d] - out (%0.3f, %0.3f), cur (%0.3f, %0.3f), "
                     "other (%0.3f, %0.3f), alpha %0.3f",
+44 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ struct Pointer {
    int32_t id;
    float x;
    float y;
    ToolType toolType = ToolType::FINGER;
    bool isResampled = false;
};

@@ -99,7 +100,7 @@ void TouchResamplingTest::publishSimpleMotionEvent(int32_t action, nsecs_t event
        properties.push_back({});
        properties.back().clear();
        properties.back().id = pointer.id;
        properties.back().toolType = ToolType::FINGER;
        properties.back().toolType = pointer.toolType;

        coords.push_back({});
        coords.back().clear();
@@ -291,6 +292,48 @@ TEST_F(TouchResamplingTest, EventIsResampledWithDifferentId) {
    consumeInputEventEntries(expectedEntries, frameTime);
}

/**
 * Stylus pointer coordinates are not resampled, but an event is still generated for the batch with
 * a resampled timestamp and should be marked as such.
 */
TEST_F(TouchResamplingTest, StylusCoordinatesNotResampledFor) {
    std::chrono::nanoseconds frameTime;
    std::vector<InputEventEntry> entries, expectedEntries;

    // Initial ACTION_DOWN should be separate, because the first consume event will only return
    // InputEvent with a single action.
    entries = {
            //      id  x   y
            {0ms, {{0, 10, 20, .toolType = ToolType::STYLUS}}, AMOTION_EVENT_ACTION_DOWN},
    };
    publishInputEventEntries(entries);
    frameTime = 5ms;
    expectedEntries = {
            //      id  x   y
            {0ms, {{0, 10, 20, .toolType = ToolType::STYLUS}}, AMOTION_EVENT_ACTION_DOWN},
    };
    consumeInputEventEntries(expectedEntries, frameTime);

    // Two ACTION_MOVE events 10 ms apart that move in X direction and stay still in Y
    entries = {
            //      id  x   y
            {10ms, {{0, 20, 30, .toolType = ToolType::STYLUS}}, AMOTION_EVENT_ACTION_MOVE},
            {20ms, {{0, 30, 30, .toolType = ToolType::STYLUS}}, AMOTION_EVENT_ACTION_MOVE},
    };
    publishInputEventEntries(entries);
    frameTime = 35ms;
    expectedEntries = {
            //      id  x   y
            {10ms, {{0, 20, 30, .toolType = ToolType::STYLUS}}, AMOTION_EVENT_ACTION_MOVE},
            {20ms, {{0, 30, 30, .toolType = ToolType::STYLUS}}, AMOTION_EVENT_ACTION_MOVE},
            // A resampled event is generated, but the stylus coordinates are not resampled.
            {25ms,
             {{0, 30, 30, .toolType = ToolType::STYLUS, .isResampled = true}},
             AMOTION_EVENT_ACTION_MOVE},
    };
    consumeInputEventEntries(expectedEntries, frameTime);
}

/**
 * Event should not be resampled when sample time is equal to event time.
 */