diff options
author | 2023-09-26 12:09:40 -0700 | |
---|---|---|
committer | 2023-09-27 07:02:51 +0000 | |
commit | 4e955a2d5a1b61ce501354e2b341fc58dcdba1dd (patch) | |
tree | e70c39e280b07e02af15aaedb834d5e65526e964 | |
parent | 102d39dbad6c568fc4daa17493b53380dcb8f0a0 (diff) |
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
-rw-r--r-- | libs/input/InputTransport.cpp | 2 | ||||
-rw-r--r-- | libs/input/tests/TouchResampling_test.cpp | 45 |
2 files changed, 45 insertions, 2 deletions
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index 16000139f7..5450ad075c 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -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", diff --git a/libs/input/tests/TouchResampling_test.cpp b/libs/input/tests/TouchResampling_test.cpp index 655de803ae..106d78a469 100644 --- a/libs/input/tests/TouchResampling_test.cpp +++ b/libs/input/tests/TouchResampling_test.cpp @@ -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(); @@ -292,6 +293,48 @@ TEST_F(TouchResamplingTest, EventIsResampledWithDifferentId) { } /** + * 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. */ TEST_F(TouchResamplingTest, SampleTimeEqualsEventTime) { |