Fix batching logic in InputConsumerNoResampling.cpp
Fixed batching logic in InputConsumerNoResampling.cpp because it was
violating resampling frameTime preconditions.
Bug: 297226446
Flag: EXEMPT bugfix
Test: TEST=libinput_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST --gtest_filter="InputConsumerTest*"
Change-Id: I1b658d5b9ac7a56a8a3917a49c2b97b60641c0d5
diff --git a/libs/input/InputConsumerNoResampling.cpp b/libs/input/InputConsumerNoResampling.cpp
index eb41918..de55828 100644
--- a/libs/input/InputConsumerNoResampling.cpp
+++ b/libs/input/InputConsumerNoResampling.cpp
@@ -37,6 +37,8 @@
namespace {
+using std::chrono::nanoseconds;
+
/**
* Log debug messages relating to the consumer end of the transport channel.
* Enable this via "adb shell setprop log.tag.InputTransportConsumer DEBUG" (requires restart)
@@ -485,7 +487,12 @@
std::queue<InputMessage>& messages) {
std::unique_ptr<MotionEvent> motionEvent;
std::optional<uint32_t> firstSeqForBatch;
- while (!messages.empty() && !(messages.front().body.motion.eventTime > frameTime)) {
+ const nanoseconds resampleLatency =
+ (mResampler != nullptr) ? mResampler->getResampleLatency() : nanoseconds{0};
+ const nanoseconds adjustedFrameTime = nanoseconds{frameTime} - resampleLatency;
+
+ while (!messages.empty() &&
+ (messages.front().body.motion.eventTime <= adjustedFrameTime.count())) {
if (motionEvent == nullptr) {
motionEvent = createMotionEvent(messages.front());
firstSeqForBatch = messages.front().header.seq;
@@ -504,8 +511,7 @@
if (!messages.empty()) {
futureSample = &messages.front();
}
- mResampler->resampleMotionEvent(static_cast<std::chrono::nanoseconds>(frameTime),
- *motionEvent, futureSample);
+ mResampler->resampleMotionEvent(nanoseconds{frameTime}, *motionEvent, futureSample);
}
return std::make_pair(std::move(motionEvent), firstSeqForBatch);
}