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
diff --git a/libs/input/Resampler.cpp b/libs/input/Resampler.cpp
index af8354c..836a97a 100644
--- a/libs/input/Resampler.cpp
+++ b/libs/input/Resampler.cpp
@@ -62,8 +62,8 @@
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 e160ca0..135f8b4 100644
--- a/libs/input/tests/Resampler_test.cpp
+++ b/libs/input/tests/Resampler_test.cpp
@@ -229,6 +229,38 @@
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}}}},