diff options
author | 2024-07-10 00:12:41 +0000 | |
---|---|---|
committer | 2024-08-05 18:56:00 +0000 | |
commit | be9c544d82db96bd6cb76f6a97e647c52d186faa (patch) | |
tree | 0d74294c9f7cb2dbbebbacb331462006597d1643 /libs/input/InputConsumerNoResampling.cpp | |
parent | 892e766d2aa2c961e506d27f045a75492320d64e (diff) |
Add resampling to InputConsumerNoResampling
Moved resampling into its own class and provided test coverage for it.
Bug: 297226446
Flag: EXEMPT refactor
Test: TEST=libinput_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST --gtest_filter="*ResamplingTest*"
Change-Id: Ic6227b05120395c96643ab05e1cda373dba59e19
Diffstat (limited to 'libs/input/InputConsumerNoResampling.cpp')
-rw-r--r-- | libs/input/InputConsumerNoResampling.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/libs/input/InputConsumerNoResampling.cpp b/libs/input/InputConsumerNoResampling.cpp index c145d5c286..99ffa683dd 100644 --- a/libs/input/InputConsumerNoResampling.cpp +++ b/libs/input/InputConsumerNoResampling.cpp @@ -17,6 +17,8 @@ #define LOG_TAG "InputTransport" #define ATRACE_TAG ATRACE_TAG_INPUT +#include <chrono> + #include <inttypes.h> #include <android-base/logging.h> @@ -168,6 +170,10 @@ InputMessage createTimelineMessage(int32_t inputEventId, nsecs_t gpuCompletedTim return msg; } +bool isPointerEvent(const MotionEvent& motionEvent) { + return (motionEvent.getSource() & AINPUT_SOURCE_CLASS_POINTER) == AINPUT_SOURCE_CLASS_POINTER; +} + } // namespace using android::base::Result; @@ -177,8 +183,13 @@ using android::base::StringPrintf; InputConsumerNoResampling::InputConsumerNoResampling(const std::shared_ptr<InputChannel>& channel, sp<Looper> looper, - InputConsumerCallbacks& callbacks) - : mChannel(channel), mLooper(looper), mCallbacks(callbacks), mFdEvents(0) { + InputConsumerCallbacks& callbacks, + std::unique_ptr<Resampler> resampler) + : mChannel(channel), + mLooper(looper), + mCallbacks(callbacks), + mResampler(std::move(resampler)), + mFdEvents(0) { LOG_ALWAYS_FATAL_IF(mLooper == nullptr); mCallback = sp<LooperEventCallback>::make( std::bind(&InputConsumerNoResampling::handleReceiveCallback, this, @@ -463,6 +474,15 @@ InputConsumerNoResampling::createBatchedMotionEvent(const nsecs_t frameTime, } messages.pop(); } + // Check if resampling should be performed. + if (motionEvent != nullptr && isPointerEvent(*motionEvent) && mResampler != nullptr) { + InputMessage* futureSample = nullptr; + if (!messages.empty()) { + futureSample = &messages.front(); + } + mResampler->resampleMotionEvent(static_cast<std::chrono::nanoseconds>(frameTime), + *motionEvent, futureSample); + } return std::make_pair(std::move(motionEvent), firstSeqForBatch); } |