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

Commit 68ca3d17 authored by Paul Ramirez's avatar Paul Ramirez
Browse files

Change calculateResampledCoords to preserve PointerCoords data

Changed the logic of calculateResampledCoords to not dispose information
of PointerCoords.

Bug: 297226446
Flag: EXEMPT bugfix
Test: TEST=libinput_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST --gtest_filter="ResamplerTest*"
Change-Id: I81285a65ebb571d11ba35bd18072b5ce18763d2d
parent 3d04ea3e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -62,8 +62,8 @@ inline float lerp(float a, float b, float alpha) {

const PointerCoords calculateResampledCoords(const PointerCoords& a, const PointerCoords& b,
                                             const float alpha) {
    // Ensure the struct PointerCoords is initialized.
    PointerCoords resampledCoords{};
    // We use the value of alpha to initialize resampledCoords with the latest sample information.
    PointerCoords resampledCoords = (alpha < 1.0f) ? a : b;
    resampledCoords.isResampled = true;
    resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_X, lerp(a.getX(), b.getX(), alpha));
    resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, lerp(a.getY(), b.getY(), alpha));
+32 −0
Original line number Diff line number Diff line
@@ -229,6 +229,38 @@ void ResamplerTest::assertMotionEventIsNotResampled(const MotionEvent& original,
    EXPECT_EQ(originalSampleSize, notResampledSampleSize);
}

TEST_F(ResamplerTest, NonResampledAxesArePreserved) {
    constexpr float TOUCH_MAJOR_VALUE = 1.0f;

    MotionEvent motionEvent =
            InputStream{{{5ms, {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}}}},
                        AMOTION_EVENT_ACTION_MOVE};

    constexpr std::chrono::nanoseconds eventTime{10ms};
    PointerCoords pointerCoords{};
    pointerCoords.isResampled = false;
    pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, 2.0f);
    pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, 2.0f);
    pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, TOUCH_MAJOR_VALUE);

    motionEvent.addSample(eventTime.count(), &pointerCoords, motionEvent.getId());

    const InputMessage futureSample =
            InputSample{15ms, {{.id = 0, .x = 3.0f, .y = 4.0f, .isResampled = false}}};

    const MotionEvent originalMotionEvent = motionEvent;

    mResampler->resampleMotionEvent(11ms, motionEvent, &futureSample);

    EXPECT_EQ(motionEvent.getTouchMajor(0), TOUCH_MAJOR_VALUE);

    assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, motionEvent,
                                              Pointer{.id = 0,
                                                      .x = 2.2f,
                                                      .y = 2.4f,
                                                      .isResampled = true});
}

TEST_F(ResamplerTest, SinglePointerNotEnoughDataToResample) {
    MotionEvent motionEvent =
            InputStream{{{5ms, {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}}}},