|
1 | | - |
2 | 1 | /* |
3 | 2 | * Copyright (C) 2024 The Android Open Source Project |
4 | 3 | * |
@@ -193,7 +192,7 @@ void InputConsumerResamplingTest::assertReceivedMotionEvent( |
193 | 192 | * last two real events, which would put this time at: 20 ms + (20 ms - 10 ms) / 2 = 25 ms. |
194 | 193 | */ |
195 | 194 | TEST_F(InputConsumerResamplingTest, EventIsResampled) { |
196 | | - // Initial ACTION_DOWN should be separate, because the first consume event will only return |
| 195 | + // Send the initial ACTION_DOWN separately, so that the first consumed event will only return an |
197 | 196 | // InputEvent with a single action. |
198 | 197 | mClientTestChannel->enqueueMessage(nextPointerMessage( |
199 | 198 | {0ms, {Pointer{.id = 0, .x = 10.0f, .y = 20.0f}}, AMOTION_EVENT_ACTION_DOWN})); |
@@ -234,7 +233,7 @@ TEST_F(InputConsumerResamplingTest, EventIsResampled) { |
234 | 233 | * have these hardcoded. |
235 | 234 | */ |
236 | 235 | TEST_F(InputConsumerResamplingTest, EventIsResampledWithDifferentId) { |
237 | | - // Initial ACTION_DOWN should be separate, because the first consume event will only return |
| 236 | + // Send the initial ACTION_DOWN separately, so that the first consumed event will only return an |
238 | 237 | // InputEvent with a single action. |
239 | 238 | mClientTestChannel->enqueueMessage(nextPointerMessage( |
240 | 239 | {0ms, {Pointer{.id = 1, .x = 10.0f, .y = 20.0f}}, AMOTION_EVENT_ACTION_DOWN})); |
@@ -274,7 +273,7 @@ TEST_F(InputConsumerResamplingTest, EventIsResampledWithDifferentId) { |
274 | 273 | * Stylus pointer coordinates are resampled. |
275 | 274 | */ |
276 | 275 | TEST_F(InputConsumerResamplingTest, StylusEventIsResampled) { |
277 | | - // Initial ACTION_DOWN should be separate, because the first consume event will only return |
| 276 | + // Send the initial ACTION_DOWN separately, so that the first consumed event will only return an |
278 | 277 | // InputEvent with a single action. |
279 | 278 | mClientTestChannel->enqueueMessage(nextPointerMessage( |
280 | 279 | {0ms, |
@@ -332,9 +331,8 @@ TEST_F(InputConsumerResamplingTest, StylusEventIsResampled) { |
332 | 331 | * Mouse pointer coordinates are resampled. |
333 | 332 | */ |
334 | 333 | TEST_F(InputConsumerResamplingTest, MouseEventIsResampled) { |
335 | | - // Initial ACTION_DOWN should be separate, because the first consume event will only return |
| 334 | + // Send the initial ACTION_DOWN separately, so that the first consumed event will only return an |
336 | 335 | // InputEvent with a single action. |
337 | | - |
338 | 336 | mClientTestChannel->enqueueMessage(nextPointerMessage( |
339 | 337 | {0ms, |
340 | 338 | {Pointer{.id = 0, .x = 10.0f, .y = 20.0f, .toolType = ToolType::MOUSE}}, |
@@ -391,7 +389,7 @@ TEST_F(InputConsumerResamplingTest, MouseEventIsResampled) { |
391 | 389 | * Motion events with palm tool type are not resampled. |
392 | 390 | */ |
393 | 391 | TEST_F(InputConsumerResamplingTest, PalmEventIsNotResampled) { |
394 | | - // Initial ACTION_DOWN should be separate, because the first consume event will only return |
| 392 | + // Send the initial ACTION_DOWN separately, so that the first consumed event will only return an |
395 | 393 | // InputEvent with a single action. |
396 | 394 | mClientTestChannel->enqueueMessage(nextPointerMessage( |
397 | 395 | {0ms, |
@@ -431,4 +429,43 @@ TEST_F(InputConsumerResamplingTest, PalmEventIsNotResampled) { |
431 | 429 | mClientTestChannel->assertFinishMessage(/*seq=*/3, /*handled=*/true); |
432 | 430 | } |
433 | 431 |
|
| 432 | +/** |
| 433 | + * Event should not be resampled when sample time is equal to event time. |
| 434 | + */ |
| 435 | +TEST_F(InputConsumerResamplingTest, SampleTimeEqualsEventTime) { |
| 436 | + // Send the initial ACTION_DOWN separately, so that the first consumed event will only return an |
| 437 | + // InputEvent with a single action. |
| 438 | + mClientTestChannel->enqueueMessage(nextPointerMessage( |
| 439 | + {0ms, {Pointer{.id = 0, .x = 10.0f, .y = 20.0f}}, AMOTION_EVENT_ACTION_DOWN})); |
| 440 | + |
| 441 | + mClientTestChannel->assertNoSentMessages(); |
| 442 | + |
| 443 | + invokeLooperCallback(); |
| 444 | + assertReceivedMotionEvent({InputEventEntry{0ms, |
| 445 | + {Pointer{.id = 0, .x = 10.0f, .y = 20.0f}}, |
| 446 | + AMOTION_EVENT_ACTION_DOWN}}); |
| 447 | + |
| 448 | + // Two ACTION_MOVE events 10 ms apart that move in X direction and stay still in Y |
| 449 | + mClientTestChannel->enqueueMessage(nextPointerMessage( |
| 450 | + {10ms, {Pointer{.id = 0, .x = 20.0f, .y = 30.0f}}, AMOTION_EVENT_ACTION_MOVE})); |
| 451 | + mClientTestChannel->enqueueMessage(nextPointerMessage( |
| 452 | + {20ms, {Pointer{.id = 0, .x = 30.0f, .y = 30.0f}}, AMOTION_EVENT_ACTION_MOVE})); |
| 453 | + |
| 454 | + invokeLooperCallback(); |
| 455 | + mConsumer->consumeBatchedInputEvents(nanoseconds{20ms + 5ms /*RESAMPLE_LATENCY*/}.count()); |
| 456 | + |
| 457 | + // MotionEvent should not resampled because the resample time falls exactly on the existing |
| 458 | + // event time. |
| 459 | + assertReceivedMotionEvent({InputEventEntry{10ms, |
| 460 | + {Pointer{.id = 0, .x = 20.0f, .y = 30.0f}}, |
| 461 | + AMOTION_EVENT_ACTION_MOVE}, |
| 462 | + InputEventEntry{20ms, |
| 463 | + {Pointer{.id = 0, .x = 30.0f, .y = 30.0f}}, |
| 464 | + AMOTION_EVENT_ACTION_MOVE}}); |
| 465 | + |
| 466 | + mClientTestChannel->assertFinishMessage(/*seq=*/1, /*handled=*/true); |
| 467 | + mClientTestChannel->assertFinishMessage(/*seq=*/2, /*handled=*/true); |
| 468 | + mClientTestChannel->assertFinishMessage(/*seq=*/3, /*handled=*/true); |
| 469 | +} |
| 470 | + |
434 | 471 | } // namespace android |
0 commit comments