Loading libs/input/InputTransport.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -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", Loading libs/input/tests/TouchResampling_test.cpp +44 −1 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ struct Pointer { int32_t id; float x; float y; ToolType toolType = ToolType::FINGER; bool isResampled = false; }; Loading Loading @@ -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(); Loading Loading @@ -291,6 +292,48 @@ TEST_F(TouchResamplingTest, EventIsResampledWithDifferentId) { consumeInputEventEntries(expectedEntries, frameTime); } /** * 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. */ Loading Loading
libs/input/InputTransport.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -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", Loading
libs/input/tests/TouchResampling_test.cpp +44 −1 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ struct Pointer { int32_t id; float x; float y; ToolType toolType = ToolType::FINGER; bool isResampled = false; }; Loading Loading @@ -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(); Loading Loading @@ -291,6 +292,48 @@ TEST_F(TouchResamplingTest, EventIsResampledWithDifferentId) { consumeInputEventEntries(expectedEntries, frameTime); } /** * 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. */ Loading