Loading include/input/InputTransport.h +13 −1 Original line number Original line Diff line number Diff line Loading @@ -381,6 +381,18 @@ private: } } } } void initializeFrom(const History& other) { eventTime = other.eventTime; idBits = other.idBits; // temporary copy for (size_t i = 0; i < other.idBits.count(); i++) { uint32_t id = idBits.clearFirstMarkedBit(); int32_t index = other.idToIndex[id]; idToIndex[id] = index; pointers[index].copyFrom(other.pointers[index]); } idBits = other.idBits; // final copy } const PointerCoords& getPointerById(uint32_t id) const { const PointerCoords& getPointerById(uint32_t id) const { return pointers[idToIndex[id]]; return pointers[idToIndex[id]]; } } Loading Loading @@ -455,7 +467,6 @@ private: int32_t* displayId); int32_t* displayId); void updateTouchState(InputMessage& msg); void updateTouchState(InputMessage& msg); bool rewriteMessage(const TouchState& state, InputMessage& msg); void resampleTouchState(nsecs_t frameTime, MotionEvent* event, void resampleTouchState(nsecs_t frameTime, MotionEvent* event, const InputMessage *next); const InputMessage *next); Loading @@ -464,6 +475,7 @@ private: status_t sendUnchainedFinishedSignal(uint32_t seq, bool handled); status_t sendUnchainedFinishedSignal(uint32_t seq, bool handled); static void rewriteMessage(TouchState& state, InputMessage& msg); static void initializeKeyEvent(KeyEvent* event, const InputMessage* msg); static void initializeKeyEvent(KeyEvent* event, const InputMessage* msg); static void initializeMotionEvent(MotionEvent* event, const InputMessage* msg); static void initializeMotionEvent(MotionEvent* event, const InputMessage* msg); static void addSample(MotionEvent* event, const InputMessage* msg); static void addSample(MotionEvent* event, const InputMessage* msg); Loading libs/input/InputTransport.cpp +36 −23 Original line number Original line Diff line number Diff line Loading @@ -614,10 +614,7 @@ void InputConsumer::updateTouchState(InputMessage& msg) { if (index >= 0) { if (index >= 0) { TouchState& touchState = mTouchStates.editItemAt(index); TouchState& touchState = mTouchStates.editItemAt(index); touchState.addHistory(msg); touchState.addHistory(msg); bool messageRewritten = rewriteMessage(touchState, msg); rewriteMessage(touchState, msg); if (!messageRewritten) { touchState.lastResample.idBits.clear(); } } } break; break; } } Loading Loading @@ -645,7 +642,7 @@ void InputConsumer::updateTouchState(InputMessage& msg) { case AMOTION_EVENT_ACTION_SCROLL: { case AMOTION_EVENT_ACTION_SCROLL: { ssize_t index = findTouchState(deviceId, source); ssize_t index = findTouchState(deviceId, source); if (index >= 0) { if (index >= 0) { const TouchState& touchState = mTouchStates.itemAt(index); TouchState& touchState = mTouchStates.editItemAt(index); rewriteMessage(touchState, msg); rewriteMessage(touchState, msg); } } break; break; Loading @@ -655,7 +652,7 @@ void InputConsumer::updateTouchState(InputMessage& msg) { case AMOTION_EVENT_ACTION_CANCEL: { case AMOTION_EVENT_ACTION_CANCEL: { ssize_t index = findTouchState(deviceId, source); ssize_t index = findTouchState(deviceId, source); if (index >= 0) { if (index >= 0) { const TouchState& touchState = mTouchStates.itemAt(index); TouchState& touchState = mTouchStates.editItemAt(index); rewriteMessage(touchState, msg); rewriteMessage(touchState, msg); mTouchStates.removeAt(index); mTouchStates.removeAt(index); } } Loading @@ -664,28 +661,38 @@ void InputConsumer::updateTouchState(InputMessage& msg) { } } } } bool InputConsumer::rewriteMessage(const TouchState& state, InputMessage& msg) { /** bool messageRewritten = false; * Replace the coordinates in msg with the coordinates in lastResample, if necessary. * * If lastResample is no longer valid for a specific pointer (i.e. the lastResample time * is in the past relative to msg and the past two events do not contain identical coordinates), * then invalidate the lastResample data for that pointer. * If the two past events have identical coordinates, then lastResample data for that pointer will * remain valid, and will be used to replace these coordinates. Thus, if a certain coordinate x0 is * resampled to the new value x1, then x1 will always be used to replace x0 until some new value * not equal to x0 is received. */ void InputConsumer::rewriteMessage(TouchState& state, InputMessage& msg) { nsecs_t eventTime = msg.body.motion.eventTime; nsecs_t eventTime = msg.body.motion.eventTime; for (uint32_t i = 0; i < msg.body.motion.pointerCount; i++) { for (uint32_t i = 0; i < msg.body.motion.pointerCount; i++) { uint32_t id = msg.body.motion.pointers[i].properties.id; uint32_t id = msg.body.motion.pointers[i].properties.id; if (state.lastResample.idBits.hasBit(id)) { if (state.lastResample.idBits.hasBit(id)) { PointerCoords& msgCoords = msg.body.motion.pointers[i].coords; const PointerCoords& resampleCoords = state.lastResample.getPointerById(id); if (eventTime < state.lastResample.eventTime || if (eventTime < state.lastResample.eventTime || state.recentCoordinatesAreIdentical(id)) { state.recentCoordinatesAreIdentical(id)) { msgCoords.setAxisValue(AMOTION_EVENT_AXIS_X, resampleCoords.getX()); PointerCoords& msgCoords = msg.body.motion.pointers[i].coords; msgCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, resampleCoords.getY()); const PointerCoords& resampleCoords = state.lastResample.getPointerById(id); #if DEBUG_RESAMPLING #if DEBUG_RESAMPLING ALOGD("[%d] - rewrite (%0.3f, %0.3f), old (%0.3f, %0.3f)", id, ALOGD("[%d] - rewrite (%0.3f, %0.3f), old (%0.3f, %0.3f)", id, resampleCoords.getX(), resampleCoords.getY(), resampleCoords.getX(), resampleCoords.getY(), msgCoords.getX(), msgCoords.getY()); msgCoords.getX(), msgCoords.getY()); #endif #endif messageRewritten = true; msgCoords.setAxisValue(AMOTION_EVENT_AXIS_X, resampleCoords.getX()); msgCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, resampleCoords.getY()); } else { state.lastResample.idBits.clearBit(id); } } } } } } return messageRewritten; } } void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, Loading Loading @@ -713,7 +720,6 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, } } // Ensure that the current sample has all of the pointers that need to be reported. // Ensure that the current sample has all of the pointers that need to be reported. // Also ensure that the past two "real" touch events do not contain duplicate coordinates const History* current = touchState.getHistory(0); const History* current = touchState.getHistory(0); size_t pointerCount = event->getPointerCount(); size_t pointerCount = event->getPointerCount(); for (size_t i = 0; i < pointerCount; i++) { for (size_t i = 0; i < pointerCount; i++) { Loading @@ -721,12 +727,6 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, if (!current->idBits.hasBit(id)) { if (!current->idBits.hasBit(id)) { #if DEBUG_RESAMPLING #if DEBUG_RESAMPLING ALOGD("Not resampled, missing id %d", id); ALOGD("Not resampled, missing id %d", id); #endif return; } if (touchState.recentCoordinatesAreIdentical(id)) { #if DEBUG_RESAMPLING ALOGD("Not resampled, past two historical events have duplicate coordinates"); #endif #endif return; return; } } Loading Loading @@ -783,18 +783,32 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, } } // Resample touch coordinates. // Resample touch coordinates. History oldLastResample; oldLastResample.initializeFrom(touchState.lastResample); touchState.lastResample.eventTime = sampleTime; touchState.lastResample.eventTime = sampleTime; touchState.lastResample.idBits.clear(); touchState.lastResample.idBits.clear(); for (size_t i = 0; i < pointerCount; i++) { for (size_t i = 0; i < pointerCount; i++) { uint32_t id = event->getPointerId(i); uint32_t id = event->getPointerId(i); touchState.lastResample.idToIndex[id] = i; touchState.lastResample.idToIndex[id] = i; touchState.lastResample.idBits.markBit(id); touchState.lastResample.idBits.markBit(id); if (oldLastResample.hasPointerId(id) && touchState.recentCoordinatesAreIdentical(id)) { // We maintain the previously resampled value for this pointer (stored in // oldLastResample) when the coordinates for this pointer haven't changed since then. // This way we don't introduce artificial jitter when pointers haven't actually moved. // We know here that the coordinates for the pointer haven't changed because we // would've cleared the resampled bit in rewriteMessage if they had. We can't modify // lastResample in place becasue the mapping from pointer ID to index may have changed. touchState.lastResample.pointers[i].copyFrom(oldLastResample.getPointerById(id)); continue; } PointerCoords& resampledCoords = touchState.lastResample.pointers[i]; PointerCoords& resampledCoords = touchState.lastResample.pointers[i]; const PointerCoords& currentCoords = current->getPointerById(id); const PointerCoords& currentCoords = current->getPointerById(id); resampledCoords.copyFrom(currentCoords); if (other->idBits.hasBit(id) if (other->idBits.hasBit(id) && shouldResampleTool(event->getToolType(i))) { && shouldResampleTool(event->getToolType(i))) { const PointerCoords& otherCoords = other->getPointerById(id); const PointerCoords& otherCoords = other->getPointerById(id); resampledCoords.copyFrom(currentCoords); resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_X, resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_X, lerp(currentCoords.getX(), otherCoords.getX(), alpha)); lerp(currentCoords.getX(), otherCoords.getX(), alpha)); resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, Loading @@ -808,7 +822,6 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, alpha); alpha); #endif #endif } else { } else { resampledCoords.copyFrom(currentCoords); #if DEBUG_RESAMPLING #if DEBUG_RESAMPLING ALOGD("[%d] - out (%0.3f, %0.3f), cur (%0.3f, %0.3f)", ALOGD("[%d] - out (%0.3f, %0.3f), cur (%0.3f, %0.3f)", id, resampledCoords.getX(), resampledCoords.getY(), id, resampledCoords.getX(), resampledCoords.getY(), Loading libs/input/tests/Android.bp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -9,8 +9,8 @@ cc_test { ], ], cflags: [ cflags: [ "-Wall", "-Wall", "-Wextra", "-Werror", "-Werror", "-Wno-error=sign-compare", // to fix later "-Wno-unused-variable", "-Wno-unused-variable", ], ], shared_libs: [ shared_libs: [ Loading libs/input/tests/InputEvent_test.cpp +4 −4 Original line number Original line Diff line number Diff line Loading @@ -184,7 +184,7 @@ TEST_F(KeyEventTest, Properties) { ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event.getType()); ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event.getType()); ASSERT_EQ(2, event.getDeviceId()); ASSERT_EQ(2, event.getDeviceId()); ASSERT_EQ(AINPUT_SOURCE_GAMEPAD, event.getSource()); ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_GAMEPAD), event.getSource()); ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, event.getAction()); ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, event.getAction()); ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, event.getFlags()); ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, event.getFlags()); ASSERT_EQ(AKEYCODE_BUTTON_X, event.getKeyCode()); ASSERT_EQ(AKEYCODE_BUTTON_X, event.getKeyCode()); Loading @@ -196,7 +196,7 @@ TEST_F(KeyEventTest, Properties) { // Set source. // Set source. event.setSource(AINPUT_SOURCE_JOYSTICK); event.setSource(AINPUT_SOURCE_JOYSTICK); ASSERT_EQ(AINPUT_SOURCE_JOYSTICK, event.getSource()); ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_JOYSTICK), event.getSource()); } } Loading Loading @@ -300,7 +300,7 @@ void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) { // Check properties. // Check properties. ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType()); ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType()); ASSERT_EQ(2, event->getDeviceId()); ASSERT_EQ(2, event->getDeviceId()); ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, event->getSource()); ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_TOUCHSCREEN), event->getSource()); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, event->getAction()); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, event->getAction()); ASSERT_EQ(AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED, event->getFlags()); ASSERT_EQ(AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED, event->getFlags()); ASSERT_EQ(AMOTION_EVENT_EDGE_FLAG_TOP, event->getEdgeFlags()); ASSERT_EQ(AMOTION_EVENT_EDGE_FLAG_TOP, event->getEdgeFlags()); Loading Loading @@ -432,7 +432,7 @@ TEST_F(MotionEventTest, Properties) { // Set source. // Set source. event.setSource(AINPUT_SOURCE_JOYSTICK); event.setSource(AINPUT_SOURCE_JOYSTICK); ASSERT_EQ(AINPUT_SOURCE_JOYSTICK, event.getSource()); ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_JOYSTICK), event.getSource()); // Set action. // Set action. event.setAction(AMOTION_EVENT_ACTION_CANCEL); event.setAction(AMOTION_EVENT_ACTION_CANCEL); Loading libs/input/tests/InputPublisherAndConsumer_test.cpp +4 −3 Original line number Original line Diff line number Diff line Loading @@ -89,8 +89,9 @@ void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() { uint32_t consumeSeq; uint32_t consumeSeq; InputEvent* event; InputEvent* event; int32_t displayId; status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event, status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event, 0); &displayId); ASSERT_EQ(OK, status) ASSERT_EQ(OK, status) << "consumer consume should return OK"; << "consumer consume should return OK"; Loading Loading @@ -133,7 +134,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { const uint32_t seq = 15; const uint32_t seq = 15; const int32_t deviceId = 1; const int32_t deviceId = 1; const int32_t source = AINPUT_SOURCE_TOUCHSCREEN; const int32_t source = AINPUT_SOURCE_TOUCHSCREEN; const int32_t displayId = 0; int32_t displayId = 0; const int32_t action = AMOTION_EVENT_ACTION_MOVE; const int32_t action = AMOTION_EVENT_ACTION_MOVE; const int32_t actionButton = 0; const int32_t actionButton = 0; const int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED; const int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED; Loading Loading @@ -176,7 +177,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { uint32_t consumeSeq; uint32_t consumeSeq; InputEvent* event; InputEvent* event; status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event, status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event, 0); &displayId); ASSERT_EQ(OK, status) ASSERT_EQ(OK, status) << "consumer consume should return OK"; << "consumer consume should return OK"; Loading Loading
include/input/InputTransport.h +13 −1 Original line number Original line Diff line number Diff line Loading @@ -381,6 +381,18 @@ private: } } } } void initializeFrom(const History& other) { eventTime = other.eventTime; idBits = other.idBits; // temporary copy for (size_t i = 0; i < other.idBits.count(); i++) { uint32_t id = idBits.clearFirstMarkedBit(); int32_t index = other.idToIndex[id]; idToIndex[id] = index; pointers[index].copyFrom(other.pointers[index]); } idBits = other.idBits; // final copy } const PointerCoords& getPointerById(uint32_t id) const { const PointerCoords& getPointerById(uint32_t id) const { return pointers[idToIndex[id]]; return pointers[idToIndex[id]]; } } Loading Loading @@ -455,7 +467,6 @@ private: int32_t* displayId); int32_t* displayId); void updateTouchState(InputMessage& msg); void updateTouchState(InputMessage& msg); bool rewriteMessage(const TouchState& state, InputMessage& msg); void resampleTouchState(nsecs_t frameTime, MotionEvent* event, void resampleTouchState(nsecs_t frameTime, MotionEvent* event, const InputMessage *next); const InputMessage *next); Loading @@ -464,6 +475,7 @@ private: status_t sendUnchainedFinishedSignal(uint32_t seq, bool handled); status_t sendUnchainedFinishedSignal(uint32_t seq, bool handled); static void rewriteMessage(TouchState& state, InputMessage& msg); static void initializeKeyEvent(KeyEvent* event, const InputMessage* msg); static void initializeKeyEvent(KeyEvent* event, const InputMessage* msg); static void initializeMotionEvent(MotionEvent* event, const InputMessage* msg); static void initializeMotionEvent(MotionEvent* event, const InputMessage* msg); static void addSample(MotionEvent* event, const InputMessage* msg); static void addSample(MotionEvent* event, const InputMessage* msg); Loading
libs/input/InputTransport.cpp +36 −23 Original line number Original line Diff line number Diff line Loading @@ -614,10 +614,7 @@ void InputConsumer::updateTouchState(InputMessage& msg) { if (index >= 0) { if (index >= 0) { TouchState& touchState = mTouchStates.editItemAt(index); TouchState& touchState = mTouchStates.editItemAt(index); touchState.addHistory(msg); touchState.addHistory(msg); bool messageRewritten = rewriteMessage(touchState, msg); rewriteMessage(touchState, msg); if (!messageRewritten) { touchState.lastResample.idBits.clear(); } } } break; break; } } Loading Loading @@ -645,7 +642,7 @@ void InputConsumer::updateTouchState(InputMessage& msg) { case AMOTION_EVENT_ACTION_SCROLL: { case AMOTION_EVENT_ACTION_SCROLL: { ssize_t index = findTouchState(deviceId, source); ssize_t index = findTouchState(deviceId, source); if (index >= 0) { if (index >= 0) { const TouchState& touchState = mTouchStates.itemAt(index); TouchState& touchState = mTouchStates.editItemAt(index); rewriteMessage(touchState, msg); rewriteMessage(touchState, msg); } } break; break; Loading @@ -655,7 +652,7 @@ void InputConsumer::updateTouchState(InputMessage& msg) { case AMOTION_EVENT_ACTION_CANCEL: { case AMOTION_EVENT_ACTION_CANCEL: { ssize_t index = findTouchState(deviceId, source); ssize_t index = findTouchState(deviceId, source); if (index >= 0) { if (index >= 0) { const TouchState& touchState = mTouchStates.itemAt(index); TouchState& touchState = mTouchStates.editItemAt(index); rewriteMessage(touchState, msg); rewriteMessage(touchState, msg); mTouchStates.removeAt(index); mTouchStates.removeAt(index); } } Loading @@ -664,28 +661,38 @@ void InputConsumer::updateTouchState(InputMessage& msg) { } } } } bool InputConsumer::rewriteMessage(const TouchState& state, InputMessage& msg) { /** bool messageRewritten = false; * Replace the coordinates in msg with the coordinates in lastResample, if necessary. * * If lastResample is no longer valid for a specific pointer (i.e. the lastResample time * is in the past relative to msg and the past two events do not contain identical coordinates), * then invalidate the lastResample data for that pointer. * If the two past events have identical coordinates, then lastResample data for that pointer will * remain valid, and will be used to replace these coordinates. Thus, if a certain coordinate x0 is * resampled to the new value x1, then x1 will always be used to replace x0 until some new value * not equal to x0 is received. */ void InputConsumer::rewriteMessage(TouchState& state, InputMessage& msg) { nsecs_t eventTime = msg.body.motion.eventTime; nsecs_t eventTime = msg.body.motion.eventTime; for (uint32_t i = 0; i < msg.body.motion.pointerCount; i++) { for (uint32_t i = 0; i < msg.body.motion.pointerCount; i++) { uint32_t id = msg.body.motion.pointers[i].properties.id; uint32_t id = msg.body.motion.pointers[i].properties.id; if (state.lastResample.idBits.hasBit(id)) { if (state.lastResample.idBits.hasBit(id)) { PointerCoords& msgCoords = msg.body.motion.pointers[i].coords; const PointerCoords& resampleCoords = state.lastResample.getPointerById(id); if (eventTime < state.lastResample.eventTime || if (eventTime < state.lastResample.eventTime || state.recentCoordinatesAreIdentical(id)) { state.recentCoordinatesAreIdentical(id)) { msgCoords.setAxisValue(AMOTION_EVENT_AXIS_X, resampleCoords.getX()); PointerCoords& msgCoords = msg.body.motion.pointers[i].coords; msgCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, resampleCoords.getY()); const PointerCoords& resampleCoords = state.lastResample.getPointerById(id); #if DEBUG_RESAMPLING #if DEBUG_RESAMPLING ALOGD("[%d] - rewrite (%0.3f, %0.3f), old (%0.3f, %0.3f)", id, ALOGD("[%d] - rewrite (%0.3f, %0.3f), old (%0.3f, %0.3f)", id, resampleCoords.getX(), resampleCoords.getY(), resampleCoords.getX(), resampleCoords.getY(), msgCoords.getX(), msgCoords.getY()); msgCoords.getX(), msgCoords.getY()); #endif #endif messageRewritten = true; msgCoords.setAxisValue(AMOTION_EVENT_AXIS_X, resampleCoords.getX()); msgCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, resampleCoords.getY()); } else { state.lastResample.idBits.clearBit(id); } } } } } } return messageRewritten; } } void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, Loading Loading @@ -713,7 +720,6 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, } } // Ensure that the current sample has all of the pointers that need to be reported. // Ensure that the current sample has all of the pointers that need to be reported. // Also ensure that the past two "real" touch events do not contain duplicate coordinates const History* current = touchState.getHistory(0); const History* current = touchState.getHistory(0); size_t pointerCount = event->getPointerCount(); size_t pointerCount = event->getPointerCount(); for (size_t i = 0; i < pointerCount; i++) { for (size_t i = 0; i < pointerCount; i++) { Loading @@ -721,12 +727,6 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, if (!current->idBits.hasBit(id)) { if (!current->idBits.hasBit(id)) { #if DEBUG_RESAMPLING #if DEBUG_RESAMPLING ALOGD("Not resampled, missing id %d", id); ALOGD("Not resampled, missing id %d", id); #endif return; } if (touchState.recentCoordinatesAreIdentical(id)) { #if DEBUG_RESAMPLING ALOGD("Not resampled, past two historical events have duplicate coordinates"); #endif #endif return; return; } } Loading Loading @@ -783,18 +783,32 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, } } // Resample touch coordinates. // Resample touch coordinates. History oldLastResample; oldLastResample.initializeFrom(touchState.lastResample); touchState.lastResample.eventTime = sampleTime; touchState.lastResample.eventTime = sampleTime; touchState.lastResample.idBits.clear(); touchState.lastResample.idBits.clear(); for (size_t i = 0; i < pointerCount; i++) { for (size_t i = 0; i < pointerCount; i++) { uint32_t id = event->getPointerId(i); uint32_t id = event->getPointerId(i); touchState.lastResample.idToIndex[id] = i; touchState.lastResample.idToIndex[id] = i; touchState.lastResample.idBits.markBit(id); touchState.lastResample.idBits.markBit(id); if (oldLastResample.hasPointerId(id) && touchState.recentCoordinatesAreIdentical(id)) { // We maintain the previously resampled value for this pointer (stored in // oldLastResample) when the coordinates for this pointer haven't changed since then. // This way we don't introduce artificial jitter when pointers haven't actually moved. // We know here that the coordinates for the pointer haven't changed because we // would've cleared the resampled bit in rewriteMessage if they had. We can't modify // lastResample in place becasue the mapping from pointer ID to index may have changed. touchState.lastResample.pointers[i].copyFrom(oldLastResample.getPointerById(id)); continue; } PointerCoords& resampledCoords = touchState.lastResample.pointers[i]; PointerCoords& resampledCoords = touchState.lastResample.pointers[i]; const PointerCoords& currentCoords = current->getPointerById(id); const PointerCoords& currentCoords = current->getPointerById(id); resampledCoords.copyFrom(currentCoords); if (other->idBits.hasBit(id) if (other->idBits.hasBit(id) && shouldResampleTool(event->getToolType(i))) { && shouldResampleTool(event->getToolType(i))) { const PointerCoords& otherCoords = other->getPointerById(id); const PointerCoords& otherCoords = other->getPointerById(id); resampledCoords.copyFrom(currentCoords); resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_X, resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_X, lerp(currentCoords.getX(), otherCoords.getX(), alpha)); lerp(currentCoords.getX(), otherCoords.getX(), alpha)); resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, Loading @@ -808,7 +822,6 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, alpha); alpha); #endif #endif } else { } else { resampledCoords.copyFrom(currentCoords); #if DEBUG_RESAMPLING #if DEBUG_RESAMPLING ALOGD("[%d] - out (%0.3f, %0.3f), cur (%0.3f, %0.3f)", ALOGD("[%d] - out (%0.3f, %0.3f), cur (%0.3f, %0.3f)", id, resampledCoords.getX(), resampledCoords.getY(), id, resampledCoords.getX(), resampledCoords.getY(), Loading
libs/input/tests/Android.bp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -9,8 +9,8 @@ cc_test { ], ], cflags: [ cflags: [ "-Wall", "-Wall", "-Wextra", "-Werror", "-Werror", "-Wno-error=sign-compare", // to fix later "-Wno-unused-variable", "-Wno-unused-variable", ], ], shared_libs: [ shared_libs: [ Loading
libs/input/tests/InputEvent_test.cpp +4 −4 Original line number Original line Diff line number Diff line Loading @@ -184,7 +184,7 @@ TEST_F(KeyEventTest, Properties) { ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event.getType()); ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event.getType()); ASSERT_EQ(2, event.getDeviceId()); ASSERT_EQ(2, event.getDeviceId()); ASSERT_EQ(AINPUT_SOURCE_GAMEPAD, event.getSource()); ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_GAMEPAD), event.getSource()); ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, event.getAction()); ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, event.getAction()); ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, event.getFlags()); ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, event.getFlags()); ASSERT_EQ(AKEYCODE_BUTTON_X, event.getKeyCode()); ASSERT_EQ(AKEYCODE_BUTTON_X, event.getKeyCode()); Loading @@ -196,7 +196,7 @@ TEST_F(KeyEventTest, Properties) { // Set source. // Set source. event.setSource(AINPUT_SOURCE_JOYSTICK); event.setSource(AINPUT_SOURCE_JOYSTICK); ASSERT_EQ(AINPUT_SOURCE_JOYSTICK, event.getSource()); ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_JOYSTICK), event.getSource()); } } Loading Loading @@ -300,7 +300,7 @@ void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) { // Check properties. // Check properties. ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType()); ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType()); ASSERT_EQ(2, event->getDeviceId()); ASSERT_EQ(2, event->getDeviceId()); ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, event->getSource()); ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_TOUCHSCREEN), event->getSource()); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, event->getAction()); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, event->getAction()); ASSERT_EQ(AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED, event->getFlags()); ASSERT_EQ(AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED, event->getFlags()); ASSERT_EQ(AMOTION_EVENT_EDGE_FLAG_TOP, event->getEdgeFlags()); ASSERT_EQ(AMOTION_EVENT_EDGE_FLAG_TOP, event->getEdgeFlags()); Loading Loading @@ -432,7 +432,7 @@ TEST_F(MotionEventTest, Properties) { // Set source. // Set source. event.setSource(AINPUT_SOURCE_JOYSTICK); event.setSource(AINPUT_SOURCE_JOYSTICK); ASSERT_EQ(AINPUT_SOURCE_JOYSTICK, event.getSource()); ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_JOYSTICK), event.getSource()); // Set action. // Set action. event.setAction(AMOTION_EVENT_ACTION_CANCEL); event.setAction(AMOTION_EVENT_ACTION_CANCEL); Loading
libs/input/tests/InputPublisherAndConsumer_test.cpp +4 −3 Original line number Original line Diff line number Diff line Loading @@ -89,8 +89,9 @@ void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() { uint32_t consumeSeq; uint32_t consumeSeq; InputEvent* event; InputEvent* event; int32_t displayId; status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event, status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event, 0); &displayId); ASSERT_EQ(OK, status) ASSERT_EQ(OK, status) << "consumer consume should return OK"; << "consumer consume should return OK"; Loading Loading @@ -133,7 +134,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { const uint32_t seq = 15; const uint32_t seq = 15; const int32_t deviceId = 1; const int32_t deviceId = 1; const int32_t source = AINPUT_SOURCE_TOUCHSCREEN; const int32_t source = AINPUT_SOURCE_TOUCHSCREEN; const int32_t displayId = 0; int32_t displayId = 0; const int32_t action = AMOTION_EVENT_ACTION_MOVE; const int32_t action = AMOTION_EVENT_ACTION_MOVE; const int32_t actionButton = 0; const int32_t actionButton = 0; const int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED; const int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED; Loading Loading @@ -176,7 +177,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { uint32_t consumeSeq; uint32_t consumeSeq; InputEvent* event; InputEvent* event; status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event, status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event, 0); &displayId); ASSERT_EQ(OK, status) ASSERT_EQ(OK, status) << "consumer consume should return OK"; << "consumer consume should return OK"; Loading