summaryrefslogtreecommitdiff
path: root/libs/input/Resampler.cpp
diff options
context:
space:
mode:
author Paul Ramirez <peramirez@google.com> 2024-10-01 01:17:39 +0000
committer Paul Ramirez <peramirez@google.com> 2024-10-09 00:58:10 +0000
commit4679e55027a36e63cfdc642de313cb2c46c58c54 (patch)
tree91aca7153c9f7d2c1ef305717efa259488eae757 /libs/input/Resampler.cpp
parent4d3b03adfa3543158c982546f3d6daec7eed06e8 (diff)
Add logic to overwrite pointer coordinates if event time is too old
Included OldEventReceivedAfterResampleOccurs from TouchResampling_test.cpp, and added the missing logic in LegacyResampler to pass the test. The CL wrongly assumes pointer information guarantees between motion events, that is, pointer IDs can appear in different order between samples. This issue is fixed in the second to last CL in the relation chain by using an associative array as a data structure to store and access pointer properties and coordinates. Bug: 297226446 Flag: EXEMPT refactor Test: TEST=libinput_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST --gtest_filter="InputConsumerResamplingTest*" Change-Id: I41cb79eaba965cfdfe7db68c388cb5d0ffa406f3
Diffstat (limited to 'libs/input/Resampler.cpp')
-rw-r--r--libs/input/Resampler.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/libs/input/Resampler.cpp b/libs/input/Resampler.cpp
index 8fe904f9a4..e2cc6fb174 100644
--- a/libs/input/Resampler.cpp
+++ b/libs/input/Resampler.cpp
@@ -271,6 +271,7 @@ void LegacyResampler::overwriteMotionEventSamples(MotionEvent& motionEvent) cons
const size_t numSamples = motionEvent.getHistorySize() + 1;
for (size_t sampleIndex = 0; sampleIndex < numSamples; ++sampleIndex) {
overwriteStillPointers(motionEvent, sampleIndex);
+ overwriteOldPointers(motionEvent, sampleIndex);
}
}
@@ -289,6 +290,24 @@ void LegacyResampler::overwriteStillPointers(MotionEvent& motionEvent, size_t sa
}
}
+void LegacyResampler::overwriteOldPointers(MotionEvent& motionEvent, size_t sampleIndex) const {
+ if (!mPreviousPrediction.has_value()) {
+ return;
+ }
+ if (nanoseconds{motionEvent.getHistoricalEventTime(sampleIndex)} <
+ mPreviousPrediction->eventTime) {
+ LOG_IF(INFO, debugResampling())
+ << "Motion event sample older than predicted sample. Overwriting event time from "
+ << motionEvent.getHistoricalEventTime(sampleIndex) << "ns to "
+ << mPreviousPrediction->eventTime.count() << "ns.";
+ for (size_t pointerIndex = 0; pointerIndex < motionEvent.getPointerCount();
+ ++pointerIndex) {
+ setMotionEventPointerCoords(motionEvent, sampleIndex, pointerIndex,
+ mPreviousPrediction->pointers[pointerIndex].coords);
+ }
+ }
+}
+
void LegacyResampler::resampleMotionEvent(nanoseconds frameTime, MotionEvent& motionEvent,
const InputMessage* futureSample) {
const nanoseconds resampleTime = frameTime - RESAMPLE_LATENCY;