3333#include < utils/RefBase.h>
3434#include < utils/String8.h>
3535#include < utils/Vector.h>
36+ #include < utils/BitSet.h>
3637
3738namespace android {
3839
@@ -271,6 +272,9 @@ class InputConsumer {
271272 * If consumeBatches is true, then events are still batched but they are consumed
272273 * immediately as soon as the input channel is exhausted.
273274 *
275+ * The frameTime parameter specifies the time when the current display frame started
276+ * rendering in the CLOCK_MONOTONIC time base, or -1 if unknown.
277+ *
274278 * The returned sequence number is never 0 unless the operation failed.
275279 *
276280 * Returns OK on success.
@@ -280,7 +284,7 @@ class InputConsumer {
280284 * Other errors probably indicate that the channel is broken.
281285 */
282286 status_t consume (InputEventFactoryInterface* factory, bool consumeBatches,
283- uint32_t * outSeq, InputEvent** outEvent);
287+ nsecs_t frameTime, uint32_t * outSeq, InputEvent** outEvent);
284288
285289 /* Sends a finished signal to the publisher to inform it that the message
286290 * with the specified sequence number has finished being process and whether
@@ -298,7 +302,7 @@ class InputConsumer {
298302 * has a deferred event to be processed. Deferred events are somewhat special in
299303 * that they have already been removed from the input channel. If the input channel
300304 * becomes empty, the client may need to do extra work to ensure that it processes
301- * the deferred event despite the fact that the inptu channel's file descriptor
305+ * the deferred event despite the fact that the input channel's file descriptor
302306 * is not readable.
303307 *
304308 * One option is simply to call consume() in a loop until it returns WOULD_BLOCK.
@@ -329,11 +333,55 @@ class InputConsumer {
329333
330334 // Batched motion events per device and source.
331335 struct Batch {
332- uint32_t seq; // sequence number of last input message batched in the event
333- MotionEvent event;
336+ Vector<InputMessage> samples;
334337 };
335338 Vector<Batch> mBatches ;
336339
340+ // Touch state per device and source, only for sources of class pointer.
341+ struct History {
342+ nsecs_t eventTime;
343+ BitSet32 idBits;
344+ PointerCoords pointers[MAX_POINTERS];
345+
346+ void initializeFrom (const InputMessage* msg) {
347+ eventTime = msg->body .motion .eventTime ;
348+ idBits.clear ();
349+ for (size_t i = 0 ; i < msg->body .motion .pointerCount ; i++) {
350+ uint32_t id = msg->body .motion .pointers [i].properties .id ;
351+ idBits.markBit (id);
352+ size_t index = idBits.getIndexOfBit (id);
353+ pointers[index].copyFrom (msg->body .motion .pointers [i].coords );
354+ }
355+ }
356+ };
357+ struct TouchState {
358+ int32_t deviceId;
359+ int32_t source;
360+ size_t historyCurrent;
361+ size_t historySize;
362+ History history[2 ];
363+
364+ void initialize (int32_t deviceId, int32_t source) {
365+ this ->deviceId = deviceId;
366+ this ->source = source;
367+ historyCurrent = 0 ;
368+ historySize = 0 ;
369+ }
370+
371+ void addHistory (const InputMessage* msg) {
372+ historyCurrent ^= 1 ;
373+ if (historySize < 2 ) {
374+ historySize += 1 ;
375+ }
376+ history[historyCurrent].initializeFrom (msg);
377+ }
378+
379+ const History* getHistory (size_t index) const {
380+ return &history[(historyCurrent + index) & 1 ];
381+ }
382+ };
383+ Vector<TouchState> mTouchStates ;
384+
337385 // Chain of batched sequence numbers. When multiple input messages are combined into
338386 // a batch, we append a record here that associates the last sequence number in the
339387 // batch with the previous one. When the finished signal is sent, we traverse the
@@ -344,13 +392,26 @@ class InputConsumer {
344392 };
345393 Vector<SeqChain> mSeqChains ;
346394
395+ status_t consumeBatch (InputEventFactoryInterface* factory,
396+ nsecs_t frameTime, uint32_t * outSeq, InputEvent** outEvent);
397+ status_t consumeSamples (InputEventFactoryInterface* factory,
398+ Batch& batch, size_t count, uint32_t * outSeq, InputEvent** outEvent);
399+
400+ void updateTouchState (InputMessage* msg);
401+ void resampleTouchState (nsecs_t frameTime, MotionEvent* event,
402+ const InputMessage *next);
403+
347404 ssize_t findBatch (int32_t deviceId, int32_t source) const ;
405+ ssize_t findTouchState (int32_t deviceId, int32_t source) const ;
406+
348407 status_t sendUnchainedFinishedSignal (uint32_t seq, bool handled);
349408
350409 static void initializeKeyEvent (KeyEvent* event, const InputMessage* msg);
351410 static void initializeMotionEvent (MotionEvent* event, const InputMessage* msg);
352- static bool canAppendSamples (const MotionEvent* event, const InputMessage* msg);
353- static void appendSamples (MotionEvent* event, const InputMessage* msg);
411+ static void addSample (MotionEvent* event, const InputMessage* msg);
412+ static bool canAddSample (const Batch& batch, const InputMessage* msg);
413+ static ssize_t findSampleNoLaterThan (const Batch& batch, nsecs_t time);
414+ static bool shouldResampleTool (int32_t toolType);
354415};
355416
356417} // namespace android
0 commit comments