• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _UI_INPUTREADER_TOUCH_INPUT_MAPPER_H
18 #define _UI_INPUTREADER_TOUCH_INPUT_MAPPER_H
19 
20 #include <stdint.h>
21 
22 #include "CursorButtonAccumulator.h"
23 #include "CursorScrollAccumulator.h"
24 #include "EventHub.h"
25 #include "InputMapper.h"
26 #include "InputReaderBase.h"
27 #include "TouchButtonAccumulator.h"
28 
29 namespace android {
30 
31 /* Raw axis information from the driver. */
32 struct RawPointerAxes {
33     RawAbsoluteAxisInfo x;
34     RawAbsoluteAxisInfo y;
35     RawAbsoluteAxisInfo pressure;
36     RawAbsoluteAxisInfo touchMajor;
37     RawAbsoluteAxisInfo touchMinor;
38     RawAbsoluteAxisInfo toolMajor;
39     RawAbsoluteAxisInfo toolMinor;
40     RawAbsoluteAxisInfo orientation;
41     RawAbsoluteAxisInfo distance;
42     RawAbsoluteAxisInfo tiltX;
43     RawAbsoluteAxisInfo tiltY;
44     RawAbsoluteAxisInfo trackingId;
45     RawAbsoluteAxisInfo slot;
46 
47     RawPointerAxes();
getRawWidthRawPointerAxes48     inline int32_t getRawWidth() const { return x.maxValue - x.minValue + 1; }
getRawHeightRawPointerAxes49     inline int32_t getRawHeight() const { return y.maxValue - y.minValue + 1; }
50     void clear();
51 };
52 
53 /* Raw data for a collection of pointers including a pointer id mapping table. */
54 struct RawPointerData {
55     struct Pointer {
56         uint32_t id;
57         int32_t x;
58         int32_t y;
59         int32_t pressure;
60         int32_t touchMajor;
61         int32_t touchMinor;
62         int32_t toolMajor;
63         int32_t toolMinor;
64         int32_t orientation;
65         int32_t distance;
66         int32_t tiltX;
67         int32_t tiltY;
68         int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant
69         bool isHovering;
70     };
71 
72     uint32_t pointerCount;
73     Pointer pointers[MAX_POINTERS];
74     BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits;
75     uint32_t idToIndex[MAX_POINTER_ID + 1];
76 
77     RawPointerData();
78     void clear();
79     void copyFrom(const RawPointerData& other);
80     void getCentroidOfTouchingPointers(float* outX, float* outY) const;
81 
markIdBitRawPointerData82     inline void markIdBit(uint32_t id, bool isHovering) {
83         if (isHovering) {
84             hoveringIdBits.markBit(id);
85         } else {
86             touchingIdBits.markBit(id);
87         }
88     }
89 
clearIdBitsRawPointerData90     inline void clearIdBits() {
91         hoveringIdBits.clear();
92         touchingIdBits.clear();
93         canceledIdBits.clear();
94     }
95 
pointerForIdRawPointerData96     inline const Pointer& pointerForId(uint32_t id) const { return pointers[idToIndex[id]]; }
97 
isHoveringRawPointerData98     inline bool isHovering(uint32_t pointerIndex) { return pointers[pointerIndex].isHovering; }
99 };
100 
101 /* Cooked data for a collection of pointers including a pointer id mapping table. */
102 struct CookedPointerData {
103     uint32_t pointerCount;
104     PointerProperties pointerProperties[MAX_POINTERS];
105     PointerCoords pointerCoords[MAX_POINTERS];
106     BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits, validIdBits;
107     uint32_t idToIndex[MAX_POINTER_ID + 1];
108 
109     CookedPointerData();
110     void clear();
111     void copyFrom(const CookedPointerData& other);
112 
pointerCoordsForIdCookedPointerData113     inline const PointerCoords& pointerCoordsForId(uint32_t id) const {
114         return pointerCoords[idToIndex[id]];
115     }
116 
editPointerCoordsWithIdCookedPointerData117     inline PointerCoords& editPointerCoordsWithId(uint32_t id) {
118         return pointerCoords[idToIndex[id]];
119     }
120 
editPointerPropertiesWithIdCookedPointerData121     inline PointerProperties& editPointerPropertiesWithId(uint32_t id) {
122         return pointerProperties[idToIndex[id]];
123     }
124 
isHoveringCookedPointerData125     inline bool isHovering(uint32_t pointerIndex) const {
126         return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id);
127     }
128 
isTouchingCookedPointerData129     inline bool isTouching(uint32_t pointerIndex) const {
130         return touchingIdBits.hasBit(pointerProperties[pointerIndex].id);
131     }
132 
hasPointerCoordsForIdCookedPointerData133     inline bool hasPointerCoordsForId(uint32_t id) const { return validIdBits.hasBit(id); }
134 };
135 
136 class TouchInputMapper : public InputMapper {
137 public:
138     explicit TouchInputMapper(InputDeviceContext& deviceContext);
139     ~TouchInputMapper() override;
140 
141     uint32_t getSources() const override;
142     void populateDeviceInfo(InputDeviceInfo* deviceInfo) override;
143     void dump(std::string& dump) override;
144     void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes) override;
145     void reset(nsecs_t when) override;
146     void process(const RawEvent* rawEvent) override;
147 
148     int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) override;
149     int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override;
150     bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, const int32_t* keyCodes,
151                                uint8_t* outFlags) override;
152 
153     void cancelTouch(nsecs_t when, nsecs_t readTime) override;
154     void timeoutExpired(nsecs_t when) override;
155     void updateExternalStylusState(const StylusState& state) override;
156     std::optional<int32_t> getAssociatedDisplayId() override;
157 
158 protected:
159     CursorButtonAccumulator mCursorButtonAccumulator;
160     CursorScrollAccumulator mCursorScrollAccumulator;
161     TouchButtonAccumulator mTouchButtonAccumulator;
162 
163     struct VirtualKey {
164         int32_t keyCode;
165         int32_t scanCode;
166         uint32_t flags;
167 
168         // computed hit box, specified in touch screen coords based on known display size
169         int32_t hitLeft;
170         int32_t hitTop;
171         int32_t hitRight;
172         int32_t hitBottom;
173 
isHitVirtualKey174         inline bool isHit(int32_t x, int32_t y) const {
175             return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom;
176         }
177     };
178 
179     // Input sources and device mode.
180     uint32_t mSource;
181 
182     enum class DeviceMode {
183         DISABLED,   // input is disabled
184         DIRECT,     // direct mapping (touchscreen)
185         UNSCALED,   // unscaled mapping (touchpad)
186         NAVIGATION, // unscaled mapping with assist gesture (touch navigation)
187         POINTER,    // pointer mapping (pointer)
188 
189         ftl_last = POINTER
190     };
191     DeviceMode mDeviceMode;
192 
193     // The reader's configuration.
194     InputReaderConfiguration mConfig;
195 
196     // Immutable configuration parameters.
197     struct Parameters {
198         enum class DeviceType {
199             TOUCH_SCREEN,
200             TOUCH_PAD,
201             TOUCH_NAVIGATION,
202             POINTER,
203 
204             ftl_last = POINTER
205         };
206 
207         DeviceType deviceType;
208         bool hasAssociatedDisplay;
209         bool associatedDisplayIsExternal;
210         bool orientationAware;
211 
212         enum class Orientation : int32_t {
213             ORIENTATION_0 = DISPLAY_ORIENTATION_0,
214             ORIENTATION_90 = DISPLAY_ORIENTATION_90,
215             ORIENTATION_180 = DISPLAY_ORIENTATION_180,
216             ORIENTATION_270 = DISPLAY_ORIENTATION_270,
217 
218             ftl_last = ORIENTATION_270
219         };
220         Orientation orientation;
221 
222         bool hasButtonUnderPad;
223         std::string uniqueDisplayId;
224 
225         enum class GestureMode {
226             SINGLE_TOUCH,
227             MULTI_TOUCH,
228 
229             ftl_last = MULTI_TOUCH
230         };
231         GestureMode gestureMode;
232 
233         bool wake;
234     } mParameters;
235 
236     // Immutable calibration parameters in parsed form.
237     struct Calibration {
238         // Size
239         enum class SizeCalibration {
240             DEFAULT,
241             NONE,
242             GEOMETRIC,
243             DIAMETER,
244             BOX,
245             AREA,
246             ftl_last = AREA
247         };
248 
249         SizeCalibration sizeCalibration;
250 
251         bool haveSizeScale;
252         float sizeScale;
253         bool haveSizeBias;
254         float sizeBias;
255         bool haveSizeIsSummed;
256         bool sizeIsSummed;
257 
258         // Pressure
259         enum class PressureCalibration {
260             DEFAULT,
261             NONE,
262             PHYSICAL,
263             AMPLITUDE,
264         };
265 
266         PressureCalibration pressureCalibration;
267         bool havePressureScale;
268         float pressureScale;
269 
270         // Orientation
271         enum class OrientationCalibration {
272             DEFAULT,
273             NONE,
274             INTERPOLATED,
275             VECTOR,
276         };
277 
278         OrientationCalibration orientationCalibration;
279 
280         // Distance
281         enum class DistanceCalibration {
282             DEFAULT,
283             NONE,
284             SCALED,
285         };
286 
287         DistanceCalibration distanceCalibration;
288         bool haveDistanceScale;
289         float distanceScale;
290 
291         enum class CoverageCalibration {
292             DEFAULT,
293             NONE,
294             BOX,
295         };
296 
297         CoverageCalibration coverageCalibration;
298 
applySizeScaleAndBiasCalibration299         inline void applySizeScaleAndBias(float* outSize) const {
300             if (haveSizeScale) {
301                 *outSize *= sizeScale;
302             }
303             if (haveSizeBias) {
304                 *outSize += sizeBias;
305             }
306             if (*outSize < 0) {
307                 *outSize = 0;
308             }
309         }
310     } mCalibration;
311 
312     // Affine location transformation/calibration
313     struct TouchAffineTransformation mAffineTransform;
314 
315     RawPointerAxes mRawPointerAxes;
316 
317     struct RawState {
318         nsecs_t when;
319         nsecs_t readTime;
320 
321         // Raw pointer sample data.
322         RawPointerData rawPointerData;
323 
324         int32_t buttonState;
325 
326         // Scroll state.
327         int32_t rawVScroll;
328         int32_t rawHScroll;
329 
RawStateRawState330         explicit inline RawState() { clear(); }
331 
copyFromRawState332         void copyFrom(const RawState& other) {
333             when = other.when;
334             readTime = other.readTime;
335             rawPointerData.copyFrom(other.rawPointerData);
336             buttonState = other.buttonState;
337             rawVScroll = other.rawVScroll;
338             rawHScroll = other.rawHScroll;
339         }
340 
clearRawState341         void clear() {
342             when = 0;
343             readTime = 0;
344             rawPointerData.clear();
345             buttonState = 0;
346             rawVScroll = 0;
347             rawHScroll = 0;
348         }
349     };
350 
351     struct CookedState {
352         // Cooked pointer sample data.
353         CookedPointerData cookedPointerData;
354 
355         // Id bits used to differentiate fingers, stylus and mouse tools.
356         BitSet32 fingerIdBits;
357         BitSet32 stylusIdBits;
358         BitSet32 mouseIdBits;
359 
360         int32_t buttonState;
361 
copyFromCookedState362         void copyFrom(const CookedState& other) {
363             cookedPointerData.copyFrom(other.cookedPointerData);
364             fingerIdBits = other.fingerIdBits;
365             stylusIdBits = other.stylusIdBits;
366             mouseIdBits = other.mouseIdBits;
367             buttonState = other.buttonState;
368         }
369 
clearCookedState370         void clear() {
371             cookedPointerData.clear();
372             fingerIdBits.clear();
373             stylusIdBits.clear();
374             mouseIdBits.clear();
375             buttonState = 0;
376         }
377     };
378 
379     std::vector<RawState> mRawStatesPending;
380     RawState mCurrentRawState;
381     CookedState mCurrentCookedState;
382     RawState mLastRawState;
383     CookedState mLastCookedState;
384 
385     // State provided by an external stylus
386     StylusState mExternalStylusState;
387     int64_t mExternalStylusId;
388     nsecs_t mExternalStylusFusionTimeout;
389     bool mExternalStylusDataPending;
390 
391     // True if we sent a HOVER_ENTER event.
392     bool mSentHoverEnter;
393 
394     // Have we assigned pointer IDs for this stream
395     bool mHavePointerIds;
396 
397     // Is the current stream of direct touch events aborted
398     bool mCurrentMotionAborted;
399 
400     // The time the primary pointer last went down.
401     nsecs_t mDownTime;
402 
403     // The pointer controller, or null if the device is not a pointer.
404     std::shared_ptr<PointerControllerInterface> mPointerController;
405 
406     std::vector<VirtualKey> mVirtualKeys;
407 
408     virtual void configureParameters();
409     virtual void dumpParameters(std::string& dump);
410     virtual void configureRawPointerAxes();
411     virtual void dumpRawPointerAxes(std::string& dump);
412     virtual void configureInputDevice(nsecs_t when, bool* outResetNeeded);
413     virtual void dumpDisplay(std::string& dump);
414     virtual void configureVirtualKeys();
415     virtual void dumpVirtualKeys(std::string& dump);
416     virtual void parseCalibration();
417     virtual void resolveCalibration();
418     virtual void dumpCalibration(std::string& dump);
419     virtual void updateAffineTransformation();
420     virtual void dumpAffineTransformation(std::string& dump);
421     virtual void resolveExternalStylusPresence();
422     virtual bool hasStylus() const = 0;
423     virtual bool hasExternalStylus() const;
424 
425     virtual void syncTouch(nsecs_t when, RawState* outState) = 0;
426 
427 private:
428     // The current viewport.
429     // The components of the viewport are specified in the display's rotated orientation.
430     DisplayViewport mViewport;
431 
432     // The width and height are obtained from the viewport and are specified
433     // in the natural orientation.
434     int32_t mDisplayWidth;
435     int32_t mDisplayHeight;
436 
437     // The physical frame is the rectangle in the display's coordinate space that maps to the
438     // the logical display frame.
439     int32_t mPhysicalWidth;
440     int32_t mPhysicalHeight;
441     int32_t mPhysicalLeft;
442     int32_t mPhysicalTop;
443 
444     // The orientation of the input device relative to that of the display panel. It specifies
445     // the rotation of the input device coordinates required to produce the display panel
446     // orientation, so it will depend on whether the device is orientation aware.
447     int32_t mInputDeviceOrientation;
448 
449     // Translation and scaling factors, orientation-independent.
450     float mXScale;
451     float mXPrecision;
452 
453     float mYScale;
454     float mYPrecision;
455 
456     float mGeometricScale;
457 
458     float mPressureScale;
459 
460     float mSizeScale;
461 
462     float mOrientationScale;
463 
464     float mDistanceScale;
465 
466     bool mHaveTilt;
467     float mTiltXCenter;
468     float mTiltXScale;
469     float mTiltYCenter;
470     float mTiltYScale;
471 
472     bool mExternalStylusConnected;
473 
474     // Oriented motion ranges for input device info.
475     struct OrientedRanges {
476         InputDeviceInfo::MotionRange x;
477         InputDeviceInfo::MotionRange y;
478         InputDeviceInfo::MotionRange pressure;
479 
480         bool haveSize;
481         InputDeviceInfo::MotionRange size;
482 
483         bool haveTouchSize;
484         InputDeviceInfo::MotionRange touchMajor;
485         InputDeviceInfo::MotionRange touchMinor;
486 
487         bool haveToolSize;
488         InputDeviceInfo::MotionRange toolMajor;
489         InputDeviceInfo::MotionRange toolMinor;
490 
491         bool haveOrientation;
492         InputDeviceInfo::MotionRange orientation;
493 
494         bool haveDistance;
495         InputDeviceInfo::MotionRange distance;
496 
497         bool haveTilt;
498         InputDeviceInfo::MotionRange tilt;
499 
OrientedRangesOrientedRanges500         OrientedRanges() { clear(); }
501 
clearOrientedRanges502         void clear() {
503             haveSize = false;
504             haveTouchSize = false;
505             haveToolSize = false;
506             haveOrientation = false;
507             haveDistance = false;
508             haveTilt = false;
509         }
510     } mOrientedRanges;
511 
512     // Oriented dimensions and precision.
513     float mOrientedXPrecision;
514     float mOrientedYPrecision;
515 
516     struct CurrentVirtualKeyState {
517         bool down;
518         bool ignored;
519         nsecs_t downTime;
520         int32_t keyCode;
521         int32_t scanCode;
522     } mCurrentVirtualKey;
523 
524     // Scale factor for gesture or mouse based pointer movements.
525     float mPointerXMovementScale;
526     float mPointerYMovementScale;
527 
528     // Scale factor for gesture based zooming and other freeform motions.
529     float mPointerXZoomScale;
530     float mPointerYZoomScale;
531 
532     // The maximum swipe width.
533     float mPointerGestureMaxSwipeWidth;
534 
535     struct PointerDistanceHeapElement {
536         uint32_t currentPointerIndex : 8;
537         uint32_t lastPointerIndex : 8;
538         uint64_t distance : 48; // squared distance
539     };
540 
541     enum class PointerUsage {
542         NONE,
543         GESTURES,
544         STYLUS,
545         MOUSE,
546     };
547     PointerUsage mPointerUsage;
548 
549     struct PointerGesture {
550         enum class Mode {
551             // No fingers, button is not pressed.
552             // Nothing happening.
553             NEUTRAL,
554 
555             // No fingers, button is not pressed.
556             // Tap detected.
557             // Emits DOWN and UP events at the pointer location.
558             TAP,
559 
560             // Exactly one finger dragging following a tap.
561             // Pointer follows the active finger.
562             // Emits DOWN, MOVE and UP events at the pointer location.
563             //
564             // Detect double-taps when the finger goes up while in TAP_DRAG mode.
565             TAP_DRAG,
566 
567             // Button is pressed.
568             // Pointer follows the active finger if there is one.  Other fingers are ignored.
569             // Emits DOWN, MOVE and UP events at the pointer location.
570             BUTTON_CLICK_OR_DRAG,
571 
572             // Exactly one finger, button is not pressed.
573             // Pointer follows the active finger.
574             // Emits HOVER_MOVE events at the pointer location.
575             //
576             // Detect taps when the finger goes up while in HOVER mode.
577             HOVER,
578 
579             // Exactly two fingers but neither have moved enough to clearly indicate
580             // whether a swipe or freeform gesture was intended.  We consider the
581             // pointer to be pressed so this enables clicking or long-pressing on buttons.
582             // Pointer does not move.
583             // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate.
584             PRESS,
585 
586             // Exactly two fingers moving in the same direction, button is not pressed.
587             // Pointer does not move.
588             // Emits DOWN, MOVE and UP events with a single pointer coordinate that
589             // follows the midpoint between both fingers.
590             SWIPE,
591 
592             // Two or more fingers moving in arbitrary directions, button is not pressed.
593             // Pointer does not move.
594             // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow
595             // each finger individually relative to the initial centroid of the finger.
596             FREEFORM,
597 
598             // Waiting for quiet time to end before starting the next gesture.
599             QUIET,
600         };
601 
602         // When a gesture is sent to an unfocused window, return true if it can bring that window
603         // into focus, false otherwise.
canGestureAffectWindowFocusPointerGesture604         static bool canGestureAffectWindowFocus(Mode mode) {
605             switch (mode) {
606                 case Mode::TAP:
607                 case Mode::TAP_DRAG:
608                 case Mode::BUTTON_CLICK_OR_DRAG:
609                     // Taps can affect window focus.
610                     return true;
611                 case Mode::FREEFORM:
612                 case Mode::HOVER:
613                 case Mode::NEUTRAL:
614                 case Mode::PRESS:
615                 case Mode::QUIET:
616                 case Mode::SWIPE:
617                     // Most gestures can be performed on an unfocused window, so they should not
618                     // not affect window focus.
619                     return false;
620             }
621         }
622 
623         // Time the first finger went down.
624         nsecs_t firstTouchTime;
625 
626         // The active pointer id from the raw touch data.
627         int32_t activeTouchId; // -1 if none
628 
629         // The active pointer id from the gesture last delivered to the application.
630         int32_t activeGestureId; // -1 if none
631 
632         // Pointer coords and ids for the current and previous pointer gesture.
633         Mode currentGestureMode;
634         BitSet32 currentGestureIdBits;
635         uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1];
636         PointerProperties currentGestureProperties[MAX_POINTERS];
637         PointerCoords currentGestureCoords[MAX_POINTERS];
638 
639         Mode lastGestureMode;
640         BitSet32 lastGestureIdBits;
641         uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1];
642         PointerProperties lastGestureProperties[MAX_POINTERS];
643         PointerCoords lastGestureCoords[MAX_POINTERS];
644 
645         // Time the pointer gesture last went down.
646         nsecs_t downTime;
647 
648         // Time when the pointer went down for a TAP.
649         nsecs_t tapDownTime;
650 
651         // Time when the pointer went up for a TAP.
652         nsecs_t tapUpTime;
653 
654         // Location of initial tap.
655         float tapX, tapY;
656 
657         // Time we started waiting for quiescence.
658         nsecs_t quietTime;
659 
660         // Reference points for multitouch gestures.
661         float referenceTouchX; // reference touch X/Y coordinates in surface units
662         float referenceTouchY;
663         float referenceGestureX; // reference gesture X/Y coordinates in pixels
664         float referenceGestureY;
665 
666         // Distance that each pointer has traveled which has not yet been
667         // subsumed into the reference gesture position.
668         BitSet32 referenceIdBits;
669         struct Delta {
670             float dx, dy;
671         };
672         Delta referenceDeltas[MAX_POINTER_ID + 1];
673 
674         // Describes how touch ids are mapped to gesture ids for freeform gestures.
675         uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
676 
677         // A velocity tracker for determining whether to switch active pointers during drags.
678         VelocityTracker velocityTracker;
679 
resetPointerGesture680         void reset() {
681             firstTouchTime = LLONG_MIN;
682             activeTouchId = -1;
683             activeGestureId = -1;
684             currentGestureMode = Mode::NEUTRAL;
685             currentGestureIdBits.clear();
686             lastGestureMode = Mode::NEUTRAL;
687             lastGestureIdBits.clear();
688             downTime = 0;
689             velocityTracker.clear();
690             resetTap();
691             resetQuietTime();
692         }
693 
resetTapPointerGesture694         void resetTap() {
695             tapDownTime = LLONG_MIN;
696             tapUpTime = LLONG_MIN;
697         }
698 
resetQuietTimePointerGesture699         void resetQuietTime() { quietTime = LLONG_MIN; }
700     } mPointerGesture;
701 
702     struct PointerSimple {
703         PointerCoords currentCoords;
704         PointerProperties currentProperties;
705         PointerCoords lastCoords;
706         PointerProperties lastProperties;
707 
708         // True if the pointer is down.
709         bool down;
710 
711         // True if the pointer is hovering.
712         bool hovering;
713 
714         // Time the pointer last went down.
715         nsecs_t downTime;
716 
717         // Values reported for the last pointer event.
718         uint32_t source;
719         int32_t displayId;
720         float lastCursorX;
721         float lastCursorY;
722 
resetPointerSimple723         void reset() {
724             currentCoords.clear();
725             currentProperties.clear();
726             lastCoords.clear();
727             lastProperties.clear();
728             down = false;
729             hovering = false;
730             downTime = 0;
731             source = 0;
732             displayId = ADISPLAY_ID_NONE;
733             lastCursorX = 0.f;
734             lastCursorY = 0.f;
735         }
736     } mPointerSimple;
737 
738     // The pointer and scroll velocity controls.
739     VelocityControl mPointerVelocityControl;
740     VelocityControl mWheelXVelocityControl;
741     VelocityControl mWheelYVelocityControl;
742 
743     std::optional<DisplayViewport> findViewport();
744 
745     void resetExternalStylus();
746     void clearStylusDataPendingFlags();
747 
748     int32_t clampResolution(const char* axisName, int32_t resolution) const;
749     void initializeOrientedRanges();
750     void initializeSizeRanges();
751 
752     void sync(nsecs_t when, nsecs_t readTime);
753 
754     bool consumeRawTouches(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
755     void processRawTouches(bool timeout);
756     void cookAndDispatch(nsecs_t when, nsecs_t readTime);
757     void dispatchVirtualKey(nsecs_t when, nsecs_t readTime, uint32_t policyFlags,
758                             int32_t keyEventAction, int32_t keyEventFlags);
759 
760     void dispatchTouches(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
761     void dispatchHoverExit(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
762     void dispatchHoverEnterAndMove(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
763     void dispatchButtonRelease(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
764     void dispatchButtonPress(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
765     const BitSet32& findActiveIdBits(const CookedPointerData& cookedPointerData);
766     void cookPointerData();
767     void abortTouches(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
768 
769     void dispatchPointerUsage(nsecs_t when, nsecs_t readTime, uint32_t policyFlags,
770                               PointerUsage pointerUsage);
771     void abortPointerUsage(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
772 
773     void dispatchPointerGestures(nsecs_t when, nsecs_t readTime, uint32_t policyFlags,
774                                  bool isTimeout);
775     void abortPointerGestures(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
776     bool preparePointerGestures(nsecs_t when, bool* outCancelPreviousGesture,
777                                 bool* outFinishPreviousGesture, bool isTimeout);
778 
779     void dispatchPointerStylus(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
780     void abortPointerStylus(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
781 
782     void dispatchPointerMouse(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
783     void abortPointerMouse(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
784 
785     void dispatchPointerSimple(nsecs_t when, nsecs_t readTime, uint32_t policyFlags, bool down,
786                                bool hovering);
787     void abortPointerSimple(nsecs_t when, nsecs_t readTime, uint32_t policyFlags);
788 
789     bool assignExternalStylusId(const RawState& state, bool timeout);
790     void applyExternalStylusButtonState(nsecs_t when);
791     void applyExternalStylusTouchState(nsecs_t when);
792 
793     // Dispatches a motion event.
794     // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
795     // method will take care of setting the index and transmuting the action to DOWN or UP
796     // it is the first / last pointer to go down / up.
797     void dispatchMotion(nsecs_t when, nsecs_t readTime, uint32_t policyFlags, uint32_t source,
798                         int32_t action, int32_t actionButton, int32_t flags, int32_t metaState,
799                         int32_t buttonState, int32_t edgeFlags, const PointerProperties* properties,
800                         const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits,
801                         int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime);
802 
803     // Updates pointer coords and properties for pointers with specified ids that have moved.
804     // Returns true if any of them changed.
805     bool updateMovedPointers(const PointerProperties* inProperties, const PointerCoords* inCoords,
806                              const uint32_t* inIdToIndex, PointerProperties* outProperties,
807                              PointerCoords* outCoords, const uint32_t* outIdToIndex,
808                              BitSet32 idBits) const;
809 
810     // Returns if this touch device is a touch screen with an associated display.
811     bool isTouchScreen();
812     // Updates touch spots if they are enabled. Should only be used when this device is a
813     // touchscreen.
814     void updateTouchSpots();
815 
816     bool isPointInsidePhysicalFrame(int32_t x, int32_t y) const;
817     const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y);
818 
819     static void assignPointerIds(const RawState& last, RawState& current);
820 
821     const char* modeToString(DeviceMode deviceMode);
822     void rotateAndScale(float& x, float& y) const;
823 };
824 
825 } // namespace android
826 
827 #endif // _UI_INPUTREADER_TOUCH_INPUT_MAPPER_H
828