@@ -92,6 +92,12 @@ struct InputMessage {
9292 PointerCoords coords;
9393 } pointers[MAX_POINTERS];
9494
95+ int32_t getActionId () const {
96+ uint32_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
97+ >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
98+ return pointers[index].properties .id ;
99+ }
100+
95101 inline size_t size () const {
96102 return sizeof (Motion) - sizeof (Pointer) * MAX_POINTERS
97103 + sizeof (Pointer) * pointerCount;
@@ -322,6 +328,10 @@ class InputConsumer {
322328 bool hasPendingBatch () const ;
323329
324330private:
331+ // True if touch resampling is enabled.
332+ const bool mResampleTouch ;
333+
334+ // The input channel.
325335 sp<InputChannel> mChannel ;
326336
327337 // The current input message.
@@ -341,6 +351,7 @@ class InputConsumer {
341351 struct History {
342352 nsecs_t eventTime;
343353 BitSet32 idBits;
354+ int32_t idToIndex[MAX_POINTER_ID + 1 ];
344355 PointerCoords pointers[MAX_POINTERS];
345356
346357 void initializeFrom (const InputMessage* msg) {
@@ -349,23 +360,30 @@ class InputConsumer {
349360 for (size_t i = 0 ; i < msg->body .motion .pointerCount ; i++) {
350361 uint32_t id = msg->body .motion .pointers [i].properties .id ;
351362 idBits.markBit (id);
352- size_t index = idBits. getIndexOfBit (id) ;
353- pointers[index ].copyFrom (msg->body .motion .pointers [i].coords );
363+ idToIndex[id] = i ;
364+ pointers[i ].copyFrom (msg->body .motion .pointers [i].coords );
354365 }
355366 }
367+
368+ const PointerCoords& getPointerById (uint32_t id) const {
369+ return pointers[idToIndex[id]];
370+ }
356371 };
357372 struct TouchState {
358373 int32_t deviceId;
359374 int32_t source;
360375 size_t historyCurrent;
361376 size_t historySize;
362377 History history[2 ];
378+ History lastResample;
363379
364380 void initialize (int32_t deviceId, int32_t source) {
365381 this ->deviceId = deviceId;
366382 this ->source = source;
367383 historyCurrent = 0 ;
368384 historySize = 0 ;
385+ lastResample.eventTime = 0 ;
386+ lastResample.idBits .clear ();
369387 }
370388
371389 void addHistory (const InputMessage* msg) {
@@ -398,6 +416,7 @@ class InputConsumer {
398416 Batch& batch, size_t count, uint32_t * outSeq, InputEvent** outEvent);
399417
400418 void updateTouchState (InputMessage* msg);
419+ void rewriteMessage (const TouchState& state, InputMessage* msg);
401420 void resampleTouchState (nsecs_t frameTime, MotionEvent* event,
402421 const InputMessage *next);
403422
@@ -412,6 +431,8 @@ class InputConsumer {
412431 static bool canAddSample (const Batch& batch, const InputMessage* msg);
413432 static ssize_t findSampleNoLaterThan (const Batch& batch, nsecs_t time);
414433 static bool shouldResampleTool (int32_t toolType);
434+
435+ static bool isTouchResamplingEnabled ();
415436};
416437
417438} // namespace android
0 commit comments