Loading libs/input/Resampler.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -62,8 +62,8 @@ inline float lerp(float a, float b, float alpha) { const PointerCoords calculateResampledCoords(const PointerCoords& a, const PointerCoords& b, const PointerCoords calculateResampledCoords(const PointerCoords& a, const PointerCoords& b, const float alpha) { const float alpha) { // Ensure the struct PointerCoords is initialized. // We use the value of alpha to initialize resampledCoords with the latest sample information. PointerCoords resampledCoords{}; PointerCoords resampledCoords = (alpha < 1.0f) ? a : b; resampledCoords.isResampled = true; resampledCoords.isResampled = true; resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_X, lerp(a.getX(), b.getX(), alpha)); resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_X, lerp(a.getX(), b.getX(), alpha)); resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, lerp(a.getY(), b.getY(), alpha)); resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, lerp(a.getY(), b.getY(), alpha)); Loading libs/input/tests/Resampler_test.cpp +32 −0 Original line number Original line Diff line number Diff line Loading @@ -229,6 +229,38 @@ void ResamplerTest::assertMotionEventIsNotResampled(const MotionEvent& original, EXPECT_EQ(originalSampleSize, notResampledSampleSize); 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) { TEST_F(ResamplerTest, SinglePointerNotEnoughDataToResample) { MotionEvent motionEvent = MotionEvent motionEvent = InputStream{{{5ms, {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}}}}, InputStream{{{5ms, {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}}}}, Loading Loading
libs/input/Resampler.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -62,8 +62,8 @@ inline float lerp(float a, float b, float alpha) { const PointerCoords calculateResampledCoords(const PointerCoords& a, const PointerCoords& b, const PointerCoords calculateResampledCoords(const PointerCoords& a, const PointerCoords& b, const float alpha) { const float alpha) { // Ensure the struct PointerCoords is initialized. // We use the value of alpha to initialize resampledCoords with the latest sample information. PointerCoords resampledCoords{}; PointerCoords resampledCoords = (alpha < 1.0f) ? a : b; resampledCoords.isResampled = true; resampledCoords.isResampled = true; resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_X, lerp(a.getX(), b.getX(), alpha)); resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_X, lerp(a.getX(), b.getX(), alpha)); resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, lerp(a.getY(), b.getY(), alpha)); resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, lerp(a.getY(), b.getY(), alpha)); Loading
libs/input/tests/Resampler_test.cpp +32 −0 Original line number Original line Diff line number Diff line Loading @@ -229,6 +229,38 @@ void ResamplerTest::assertMotionEventIsNotResampled(const MotionEvent& original, EXPECT_EQ(originalSampleSize, notResampledSampleSize); 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) { TEST_F(ResamplerTest, SinglePointerNotEnoughDataToResample) { MotionEvent motionEvent = MotionEvent motionEvent = InputStream{{{5ms, {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}}}}, InputStream{{{5ms, {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}}}}, Loading