From 00cf5d01b7e51a3ea73f9032ef375c54d2068e43 Mon Sep 17 00:00:00 2001 From: Paul Ramirez Date: Thu, 5 Sep 2024 17:10:12 +0000 Subject: Add current device consumption to InputConsumerNoResampling Added current device consumption to InputConsumerNoResampling in consumeBatchedInputEvents' body Bug: 329776327 Flag: EXEMPT refactor Test: TEST=libinput_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST --gtest_filter="InputConsumerTest*" Change-Id: Ibfcb28f019543a88b3ffada137199b1c3933d542 --- include/input/InputConsumerNoResampling.h | 48 ++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-) (limited to 'include/input') diff --git a/include/input/InputConsumerNoResampling.h b/include/input/InputConsumerNoResampling.h index 358a19158e..10c2aa01f9 100644 --- a/include/input/InputConsumerNoResampling.h +++ b/include/input/InputConsumerNoResampling.h @@ -16,6 +16,11 @@ #pragma once +#include +#include +#include + +#include #include #include #include @@ -36,7 +41,7 @@ public: /** * When you receive this callback, you must (eventually) call "consumeBatchedInputEvents". * If you don't want batching, then call "consumeBatchedInputEvents" immediately with - * std::nullopt frameTime to receive the pending motion event(s). + * std::nullopt requestedFrameTime to receive the pending motion event(s). * @param pendingBatchSource the source of the pending batch. */ virtual void onBatchedInputEventPending(int32_t pendingBatchSource) = 0; @@ -96,15 +101,17 @@ public: void finishInputEvent(uint32_t seq, bool handled); void reportTimeline(int32_t inputEventId, nsecs_t gpuCompletedTime, nsecs_t presentTime); /** - * If you want to consume all events immediately (disable batching), the you still must call - * this. For frameTime, use a std::nullopt. - * @param frameTime the time up to which consume the events. When there's double (or triple) - * buffering, you may want to not consume all events currently available, because you could be - * still working on an older frame, but there could already have been events that arrived that - * are more recent. + * If you want to consume all events immediately (disable batching), then you still must call + * this. For requestedFrameTime, use a std::nullopt. It is not guaranteed that the consumption + * will occur at requestedFrameTime. The resampling strategy may modify it. + * @param requestedFrameTime the time up to which consume the events. When there's double (or + * triple) buffering, you may want to not consume all events currently available, because you + * could be still working on an older frame, but there could already have been events that + * arrived that are more recent. * @return whether any events were actually consumed */ - bool consumeBatchedInputEvents(std::optional frameTime); + bool consumeBatchedInputEvents(std::optional requestedFrameTime); + /** * Returns true when there is *likely* a pending batch or a pending event in the channel. * @@ -200,20 +207,33 @@ private: /** * Batched InputMessages, per deviceId. * For each device, we are storing a queue of batched messages. These will all be collapsed into - * a single MotionEvent (up to a specific frameTime) when the consumer calls + * a single MotionEvent (up to a specific requestedFrameTime) when the consumer calls * `consumeBatchedInputEvents`. */ std::map> mBatches; /** * Creates a MotionEvent by consuming samples from the provided queue. If one message has - * eventTime > frameTime, all subsequent messages in the queue will be skipped. It is assumed - * that messages are queued in chronological order. In other words, only events that occurred - * prior to the requested frameTime will be consumed. - * @param frameTime the time up to which to consume events + * eventTime > adjustedFrameTime, all subsequent messages in the queue will be skipped. It is + * assumed that messages are queued in chronological order. In other words, only events that + * occurred prior to the adjustedFrameTime will be consumed. + * @param requestedFrameTime the time up to which to consume events. * @param messages the queue of messages to consume from */ std::pair, std::optional> createBatchedMotionEvent( - const nsecs_t frameTime, std::queue& messages); + const nsecs_t requestedFrameTime, std::queue& messages); + + /** + * Consumes the batched input events, optionally allowing the caller to specify a device id + * and/or requestedFrameTime threshold. It is not guaranteed that consumption will occur at + * requestedFrameTime. + * @param deviceId The device id from which to consume events. If std::nullopt, consumes events + * from any device id. + * @param requestedFrameTime The time up to which consume the events. If std::nullopt, consumes + * input events with any timestamp. + * @return Whether or not any events were consumed. + */ + bool consumeBatchedInputEvents(std::optional deviceId, + std::optional requestedFrameTime); /** * A map from a single sequence number to several sequence numbers. This is needed because of * batching. When batching is enabled, a single MotionEvent will contain several samples. Each -- cgit v1.2.3-59-g8ed1b