diff options
author | 2024-08-12 23:00:50 +0000 | |
---|---|---|
committer | 2024-08-14 01:17:18 +0000 | |
commit | 68ca3d1761a26bfe2fcf8ebfddcb960bb811f184 (patch) | |
tree | 46f07058c568e2f5f06b9aabd5457e99dee855e9 | |
parent | 3d04ea3e24e755af047f4f1dc4186e5260306aba (diff) |
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
-rw-r--r-- | libs/input/Resampler.cpp | 4 | ||||
-rw-r--r-- | libs/input/tests/Resampler_test.cpp | 32 |
2 files changed, 34 insertions, 2 deletions
diff --git a/libs/input/Resampler.cpp b/libs/input/Resampler.cpp index af8354c70c..836a97af53 100644 --- a/libs/input/Resampler.cpp +++ b/libs/input/Resampler.cpp @@ -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)); diff --git a/libs/input/tests/Resampler_test.cpp b/libs/input/tests/Resampler_test.cpp index e160ca06d0..135f8b41a2 100644 --- a/libs/input/tests/Resampler_test.cpp +++ b/libs/input/tests/Resampler_test.cpp @@ -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}}}}, |