blob: 4b1c0cbeaf88672482d5b88e39e65f6b5630156d [file] [log] [blame]
Prabir Pradhanbaa5c822019-08-30 15:27:05 -07001/*
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 "CursorButtonAccumulator.h"
21#include "CursorScrollAccumulator.h"
22#include "EventHub.h"
23#include "InputMapper.h"
24#include "InputReaderBase.h"
25#include "TouchButtonAccumulator.h"
26
27#include <stdint.h>
28
29namespace android {
30
31/* Raw axis information from the driver. */
32struct 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();
48 inline int32_t getRawWidth() const { return x.maxValue - x.minValue + 1; }
49 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. */
54struct 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;
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
82 inline void markIdBit(uint32_t id, bool isHovering) {
83 if (isHovering) {
84 hoveringIdBits.markBit(id);
85 } else {
86 touchingIdBits.markBit(id);
87 }
88 }
89
90 inline void clearIdBits() {
91 hoveringIdBits.clear();
92 touchingIdBits.clear();
93 }
94
95 inline const Pointer& pointerForId(uint32_t id) const { return pointers[idToIndex[id]]; }
96
97 inline bool isHovering(uint32_t pointerIndex) { return pointers[pointerIndex].isHovering; }
98};
99
100/* Cooked data for a collection of pointers including a pointer id mapping table. */
101struct CookedPointerData {
102 uint32_t pointerCount;
103 PointerProperties pointerProperties[MAX_POINTERS];
104 PointerCoords pointerCoords[MAX_POINTERS];
105 BitSet32 hoveringIdBits, touchingIdBits;
106 uint32_t idToIndex[MAX_POINTER_ID + 1];
107
108 CookedPointerData();
109 void clear();
110 void copyFrom(const CookedPointerData& other);
111
112 inline const PointerCoords& pointerCoordsForId(uint32_t id) const {
113 return pointerCoords[idToIndex[id]];
114 }
115
116 inline PointerCoords& editPointerCoordsWithId(uint32_t id) {
117 return pointerCoords[idToIndex[id]];
118 }
119
120 inline PointerProperties& editPointerPropertiesWithId(uint32_t id) {
121 return pointerProperties[idToIndex[id]];
122 }
123
124 inline bool isHovering(uint32_t pointerIndex) const {
125 return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id);
126 }
127
128 inline bool isTouching(uint32_t pointerIndex) const {
129 return touchingIdBits.hasBit(pointerProperties[pointerIndex].id);
130 }
131};
132
133class TouchInputMapper : public InputMapper {
134public:
135 explicit TouchInputMapper(InputDevice* device);
136 virtual ~TouchInputMapper();
137
Prabir Pradhanf1fbf9e2019-09-04 16:29:40 -0700138 virtual uint32_t getSources() override;
139 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo) override;
140 virtual void dump(std::string& dump) override;
141 virtual void configure(nsecs_t when, const InputReaderConfiguration* config,
142 uint32_t changes) override;
143 virtual void reset(nsecs_t when) override;
144 virtual void process(const RawEvent* rawEvent) override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700145
Prabir Pradhanf1fbf9e2019-09-04 16:29:40 -0700146 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) override;
147 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700148 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
Prabir Pradhanf1fbf9e2019-09-04 16:29:40 -0700149 const int32_t* keyCodes, uint8_t* outFlags) override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700150
Prabir Pradhanf1fbf9e2019-09-04 16:29:40 -0700151 virtual void fadePointer() override;
152 virtual void cancelTouch(nsecs_t when) override;
153 virtual void timeoutExpired(nsecs_t when) override;
154 virtual void updateExternalStylusState(const StylusState& state) override;
155 virtual std::optional<int32_t> getAssociatedDisplayId() override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700156
157protected:
158 CursorButtonAccumulator mCursorButtonAccumulator;
159 CursorScrollAccumulator mCursorScrollAccumulator;
160 TouchButtonAccumulator mTouchButtonAccumulator;
161
162 struct VirtualKey {
163 int32_t keyCode;
164 int32_t scanCode;
165 uint32_t flags;
166
167 // computed hit box, specified in touch screen coords based on known display size
168 int32_t hitLeft;
169 int32_t hitTop;
170 int32_t hitRight;
171 int32_t hitBottom;
172
173 inline bool isHit(int32_t x, int32_t y) const {
174 return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom;
175 }
176 };
177
178 // Input sources and device mode.
179 uint32_t mSource;
180
181 enum DeviceMode {
182 DEVICE_MODE_DISABLED, // input is disabled
183 DEVICE_MODE_DIRECT, // direct mapping (touchscreen)
184 DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad)
185 DEVICE_MODE_NAVIGATION, // unscaled mapping with assist gesture (touch navigation)
186 DEVICE_MODE_POINTER, // pointer mapping (pointer)
187 };
188 DeviceMode mDeviceMode;
189
190 // The reader's configuration.
191 InputReaderConfiguration mConfig;
192
193 // Immutable configuration parameters.
194 struct Parameters {
195 enum DeviceType {
196 DEVICE_TYPE_TOUCH_SCREEN,
197 DEVICE_TYPE_TOUCH_PAD,
198 DEVICE_TYPE_TOUCH_NAVIGATION,
199 DEVICE_TYPE_POINTER,
200 };
201
202 DeviceType deviceType;
203 bool hasAssociatedDisplay;
204 bool associatedDisplayIsExternal;
205 bool orientationAware;
206 bool hasButtonUnderPad;
207 std::string uniqueDisplayId;
208
209 enum GestureMode {
210 GESTURE_MODE_SINGLE_TOUCH,
211 GESTURE_MODE_MULTI_TOUCH,
212 };
213 GestureMode gestureMode;
214
215 bool wake;
216 } mParameters;
217
218 // Immutable calibration parameters in parsed form.
219 struct Calibration {
220 // Size
221 enum SizeCalibration {
222 SIZE_CALIBRATION_DEFAULT,
223 SIZE_CALIBRATION_NONE,
224 SIZE_CALIBRATION_GEOMETRIC,
225 SIZE_CALIBRATION_DIAMETER,
226 SIZE_CALIBRATION_BOX,
227 SIZE_CALIBRATION_AREA,
228 };
229
230 SizeCalibration sizeCalibration;
231
232 bool haveSizeScale;
233 float sizeScale;
234 bool haveSizeBias;
235 float sizeBias;
236 bool haveSizeIsSummed;
237 bool sizeIsSummed;
238
239 // Pressure
240 enum PressureCalibration {
241 PRESSURE_CALIBRATION_DEFAULT,
242 PRESSURE_CALIBRATION_NONE,
243 PRESSURE_CALIBRATION_PHYSICAL,
244 PRESSURE_CALIBRATION_AMPLITUDE,
245 };
246
247 PressureCalibration pressureCalibration;
248 bool havePressureScale;
249 float pressureScale;
250
251 // Orientation
252 enum OrientationCalibration {
253 ORIENTATION_CALIBRATION_DEFAULT,
254 ORIENTATION_CALIBRATION_NONE,
255 ORIENTATION_CALIBRATION_INTERPOLATED,
256 ORIENTATION_CALIBRATION_VECTOR,
257 };
258
259 OrientationCalibration orientationCalibration;
260
261 // Distance
262 enum DistanceCalibration {
263 DISTANCE_CALIBRATION_DEFAULT,
264 DISTANCE_CALIBRATION_NONE,
265 DISTANCE_CALIBRATION_SCALED,
266 };
267
268 DistanceCalibration distanceCalibration;
269 bool haveDistanceScale;
270 float distanceScale;
271
272 enum CoverageCalibration {
273 COVERAGE_CALIBRATION_DEFAULT,
274 COVERAGE_CALIBRATION_NONE,
275 COVERAGE_CALIBRATION_BOX,
276 };
277
278 CoverageCalibration coverageCalibration;
279
280 inline void applySizeScaleAndBias(float* outSize) const {
281 if (haveSizeScale) {
282 *outSize *= sizeScale;
283 }
284 if (haveSizeBias) {
285 *outSize += sizeBias;
286 }
287 if (*outSize < 0) {
288 *outSize = 0;
289 }
290 }
291 } mCalibration;
292
293 // Affine location transformation/calibration
294 struct TouchAffineTransformation mAffineTransform;
295
296 RawPointerAxes mRawPointerAxes;
297
298 struct RawState {
299 nsecs_t when;
300
301 // Raw pointer sample data.
302 RawPointerData rawPointerData;
303
304 int32_t buttonState;
305
306 // Scroll state.
307 int32_t rawVScroll;
308 int32_t rawHScroll;
309
310 void copyFrom(const RawState& other) {
311 when = other.when;
312 rawPointerData.copyFrom(other.rawPointerData);
313 buttonState = other.buttonState;
314 rawVScroll = other.rawVScroll;
315 rawHScroll = other.rawHScroll;
316 }
317
318 void clear() {
319 when = 0;
320 rawPointerData.clear();
321 buttonState = 0;
322 rawVScroll = 0;
323 rawHScroll = 0;
324 }
325 };
326
327 struct CookedState {
328 // Cooked pointer sample data.
329 CookedPointerData cookedPointerData;
330
331 // Id bits used to differentiate fingers, stylus and mouse tools.
332 BitSet32 fingerIdBits;
333 BitSet32 stylusIdBits;
334 BitSet32 mouseIdBits;
335
336 int32_t buttonState;
337
338 void copyFrom(const CookedState& other) {
339 cookedPointerData.copyFrom(other.cookedPointerData);
340 fingerIdBits = other.fingerIdBits;
341 stylusIdBits = other.stylusIdBits;
342 mouseIdBits = other.mouseIdBits;
343 buttonState = other.buttonState;
344 }
345
346 void clear() {
347 cookedPointerData.clear();
348 fingerIdBits.clear();
349 stylusIdBits.clear();
350 mouseIdBits.clear();
351 buttonState = 0;
352 }
353 };
354
355 std::vector<RawState> mRawStatesPending;
356 RawState mCurrentRawState;
357 CookedState mCurrentCookedState;
358 RawState mLastRawState;
359 CookedState mLastCookedState;
360
361 // State provided by an external stylus
362 StylusState mExternalStylusState;
363 int64_t mExternalStylusId;
364 nsecs_t mExternalStylusFusionTimeout;
365 bool mExternalStylusDataPending;
366
367 // True if we sent a HOVER_ENTER event.
368 bool mSentHoverEnter;
369
370 // Have we assigned pointer IDs for this stream
371 bool mHavePointerIds;
372
373 // Is the current stream of direct touch events aborted
374 bool mCurrentMotionAborted;
375
376 // The time the primary pointer last went down.
377 nsecs_t mDownTime;
378
379 // The pointer controller, or null if the device is not a pointer.
380 sp<PointerControllerInterface> mPointerController;
381
382 std::vector<VirtualKey> mVirtualKeys;
383
384 virtual void configureParameters();
385 virtual void dumpParameters(std::string& dump);
386 virtual void configureRawPointerAxes();
387 virtual void dumpRawPointerAxes(std::string& dump);
388 virtual void configureSurface(nsecs_t when, bool* outResetNeeded);
389 virtual void dumpSurface(std::string& dump);
390 virtual void configureVirtualKeys();
391 virtual void dumpVirtualKeys(std::string& dump);
392 virtual void parseCalibration();
393 virtual void resolveCalibration();
394 virtual void dumpCalibration(std::string& dump);
395 virtual void updateAffineTransformation();
396 virtual void dumpAffineTransformation(std::string& dump);
397 virtual void resolveExternalStylusPresence();
398 virtual bool hasStylus() const = 0;
399 virtual bool hasExternalStylus() const;
400
401 virtual void syncTouch(nsecs_t when, RawState* outState) = 0;
402
403private:
404 // The current viewport.
405 // The components of the viewport are specified in the display's rotated orientation.
406 DisplayViewport mViewport;
407
408 // The surface orientation, width and height set by configureSurface().
409 // The width and height are derived from the viewport but are specified
410 // in the natural orientation.
411 // The surface origin specifies how the surface coordinates should be translated
412 // to align with the logical display coordinate space.
413 int32_t mSurfaceWidth;
414 int32_t mSurfaceHeight;
415 int32_t mSurfaceLeft;
416 int32_t mSurfaceTop;
417
418 // Similar to the surface coordinates, but in the raw display coordinate space rather than in
419 // the logical coordinate space.
420 int32_t mPhysicalWidth;
421 int32_t mPhysicalHeight;
422 int32_t mPhysicalLeft;
423 int32_t mPhysicalTop;
424
425 // The orientation may be different from the viewport orientation as it specifies
426 // the rotation of the surface coordinates required to produce the viewport's
427 // requested orientation, so it will depend on whether the device is orientation aware.
428 int32_t mSurfaceOrientation;
429
430 // Translation and scaling factors, orientation-independent.
431 float mXTranslate;
432 float mXScale;
433 float mXPrecision;
434
435 float mYTranslate;
436 float mYScale;
437 float mYPrecision;
438
439 float mGeometricScale;
440
441 float mPressureScale;
442
443 float mSizeScale;
444
445 float mOrientationScale;
446
447 float mDistanceScale;
448
449 bool mHaveTilt;
450 float mTiltXCenter;
451 float mTiltXScale;
452 float mTiltYCenter;
453 float mTiltYScale;
454
455 bool mExternalStylusConnected;
456
457 // Oriented motion ranges for input device info.
458 struct OrientedRanges {
459 InputDeviceInfo::MotionRange x;
460 InputDeviceInfo::MotionRange y;
461 InputDeviceInfo::MotionRange pressure;
462
463 bool haveSize;
464 InputDeviceInfo::MotionRange size;
465
466 bool haveTouchSize;
467 InputDeviceInfo::MotionRange touchMajor;
468 InputDeviceInfo::MotionRange touchMinor;
469
470 bool haveToolSize;
471 InputDeviceInfo::MotionRange toolMajor;
472 InputDeviceInfo::MotionRange toolMinor;
473
474 bool haveOrientation;
475 InputDeviceInfo::MotionRange orientation;
476
477 bool haveDistance;
478 InputDeviceInfo::MotionRange distance;
479
480 bool haveTilt;
481 InputDeviceInfo::MotionRange tilt;
482
483 OrientedRanges() { clear(); }
484
485 void clear() {
486 haveSize = false;
487 haveTouchSize = false;
488 haveToolSize = false;
489 haveOrientation = false;
490 haveDistance = false;
491 haveTilt = false;
492 }
493 } mOrientedRanges;
494
495 // Oriented dimensions and precision.
496 float mOrientedXPrecision;
497 float mOrientedYPrecision;
498
499 struct CurrentVirtualKeyState {
500 bool down;
501 bool ignored;
502 nsecs_t downTime;
503 int32_t keyCode;
504 int32_t scanCode;
505 } mCurrentVirtualKey;
506
507 // Scale factor for gesture or mouse based pointer movements.
508 float mPointerXMovementScale;
509 float mPointerYMovementScale;
510
511 // Scale factor for gesture based zooming and other freeform motions.
512 float mPointerXZoomScale;
513 float mPointerYZoomScale;
514
515 // The maximum swipe width.
516 float mPointerGestureMaxSwipeWidth;
517
518 struct PointerDistanceHeapElement {
519 uint32_t currentPointerIndex : 8;
520 uint32_t lastPointerIndex : 8;
521 uint64_t distance : 48; // squared distance
522 };
523
524 enum PointerUsage {
525 POINTER_USAGE_NONE,
526 POINTER_USAGE_GESTURES,
527 POINTER_USAGE_STYLUS,
528 POINTER_USAGE_MOUSE,
529 };
530 PointerUsage mPointerUsage;
531
532 struct PointerGesture {
533 enum Mode {
534 // No fingers, button is not pressed.
535 // Nothing happening.
536 NEUTRAL,
537
538 // No fingers, button is not pressed.
539 // Tap detected.
540 // Emits DOWN and UP events at the pointer location.
541 TAP,
542
543 // Exactly one finger dragging following a tap.
544 // Pointer follows the active finger.
545 // Emits DOWN, MOVE and UP events at the pointer location.
546 //
547 // Detect double-taps when the finger goes up while in TAP_DRAG mode.
548 TAP_DRAG,
549
550 // Button is pressed.
551 // Pointer follows the active finger if there is one. Other fingers are ignored.
552 // Emits DOWN, MOVE and UP events at the pointer location.
553 BUTTON_CLICK_OR_DRAG,
554
555 // Exactly one finger, button is not pressed.
556 // Pointer follows the active finger.
557 // Emits HOVER_MOVE events at the pointer location.
558 //
559 // Detect taps when the finger goes up while in HOVER mode.
560 HOVER,
561
562 // Exactly two fingers but neither have moved enough to clearly indicate
563 // whether a swipe or freeform gesture was intended. We consider the
564 // pointer to be pressed so this enables clicking or long-pressing on buttons.
565 // Pointer does not move.
566 // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate.
567 PRESS,
568
569 // Exactly two fingers moving in the same direction, button is not pressed.
570 // Pointer does not move.
571 // Emits DOWN, MOVE and UP events with a single pointer coordinate that
572 // follows the midpoint between both fingers.
573 SWIPE,
574
575 // Two or more fingers moving in arbitrary directions, button is not pressed.
576 // Pointer does not move.
577 // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow
578 // each finger individually relative to the initial centroid of the finger.
579 FREEFORM,
580
581 // Waiting for quiet time to end before starting the next gesture.
582 QUIET,
583 };
584
585 // Time the first finger went down.
586 nsecs_t firstTouchTime;
587
588 // The active pointer id from the raw touch data.
589 int32_t activeTouchId; // -1 if none
590
591 // The active pointer id from the gesture last delivered to the application.
592 int32_t activeGestureId; // -1 if none
593
594 // Pointer coords and ids for the current and previous pointer gesture.
595 Mode currentGestureMode;
596 BitSet32 currentGestureIdBits;
597 uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1];
598 PointerProperties currentGestureProperties[MAX_POINTERS];
599 PointerCoords currentGestureCoords[MAX_POINTERS];
600
601 Mode lastGestureMode;
602 BitSet32 lastGestureIdBits;
603 uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1];
604 PointerProperties lastGestureProperties[MAX_POINTERS];
605 PointerCoords lastGestureCoords[MAX_POINTERS];
606
607 // Time the pointer gesture last went down.
608 nsecs_t downTime;
609
610 // Time when the pointer went down for a TAP.
611 nsecs_t tapDownTime;
612
613 // Time when the pointer went up for a TAP.
614 nsecs_t tapUpTime;
615
616 // Location of initial tap.
617 float tapX, tapY;
618
619 // Time we started waiting for quiescence.
620 nsecs_t quietTime;
621
622 // Reference points for multitouch gestures.
623 float referenceTouchX; // reference touch X/Y coordinates in surface units
624 float referenceTouchY;
625 float referenceGestureX; // reference gesture X/Y coordinates in pixels
626 float referenceGestureY;
627
628 // Distance that each pointer has traveled which has not yet been
629 // subsumed into the reference gesture position.
630 BitSet32 referenceIdBits;
631 struct Delta {
632 float dx, dy;
633 };
634 Delta referenceDeltas[MAX_POINTER_ID + 1];
635
636 // Describes how touch ids are mapped to gesture ids for freeform gestures.
637 uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
638
639 // A velocity tracker for determining whether to switch active pointers during drags.
640 VelocityTracker velocityTracker;
641
642 void reset() {
643 firstTouchTime = LLONG_MIN;
644 activeTouchId = -1;
645 activeGestureId = -1;
646 currentGestureMode = NEUTRAL;
647 currentGestureIdBits.clear();
648 lastGestureMode = NEUTRAL;
649 lastGestureIdBits.clear();
650 downTime = 0;
651 velocityTracker.clear();
652 resetTap();
653 resetQuietTime();
654 }
655
656 void resetTap() {
657 tapDownTime = LLONG_MIN;
658 tapUpTime = LLONG_MIN;
659 }
660
661 void resetQuietTime() { quietTime = LLONG_MIN; }
662 } mPointerGesture;
663
664 struct PointerSimple {
665 PointerCoords currentCoords;
666 PointerProperties currentProperties;
667 PointerCoords lastCoords;
668 PointerProperties lastProperties;
669
670 // True if the pointer is down.
671 bool down;
672
673 // True if the pointer is hovering.
674 bool hovering;
675
676 // Time the pointer last went down.
677 nsecs_t downTime;
678
679 void reset() {
680 currentCoords.clear();
681 currentProperties.clear();
682 lastCoords.clear();
683 lastProperties.clear();
684 down = false;
685 hovering = false;
686 downTime = 0;
687 }
688 } mPointerSimple;
689
690 // The pointer and scroll velocity controls.
691 VelocityControl mPointerVelocityControl;
692 VelocityControl mWheelXVelocityControl;
693 VelocityControl mWheelYVelocityControl;
694
695 std::optional<DisplayViewport> findViewport();
696
697 void resetExternalStylus();
698 void clearStylusDataPendingFlags();
699
700 void sync(nsecs_t when);
701
702 bool consumeRawTouches(nsecs_t when, uint32_t policyFlags);
703 void processRawTouches(bool timeout);
704 void cookAndDispatch(nsecs_t when);
705 void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags, int32_t keyEventAction,
706 int32_t keyEventFlags);
707
708 void dispatchTouches(nsecs_t when, uint32_t policyFlags);
709 void dispatchHoverExit(nsecs_t when, uint32_t policyFlags);
710 void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags);
711 void dispatchButtonRelease(nsecs_t when, uint32_t policyFlags);
712 void dispatchButtonPress(nsecs_t when, uint32_t policyFlags);
713 const BitSet32& findActiveIdBits(const CookedPointerData& cookedPointerData);
714 void cookPointerData();
715 void abortTouches(nsecs_t when, uint32_t policyFlags);
716
717 void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage);
718 void abortPointerUsage(nsecs_t when, uint32_t policyFlags);
719
720 void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
721 void abortPointerGestures(nsecs_t when, uint32_t policyFlags);
722 bool preparePointerGestures(nsecs_t when, bool* outCancelPreviousGesture,
723 bool* outFinishPreviousGesture, bool isTimeout);
724
725 void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags);
726 void abortPointerStylus(nsecs_t when, uint32_t policyFlags);
727
728 void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags);
729 void abortPointerMouse(nsecs_t when, uint32_t policyFlags);
730
731 void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, bool down, bool hovering);
732 void abortPointerSimple(nsecs_t when, uint32_t policyFlags);
733
734 bool assignExternalStylusId(const RawState& state, bool timeout);
735 void applyExternalStylusButtonState(nsecs_t when);
736 void applyExternalStylusTouchState(nsecs_t when);
737
738 // Dispatches a motion event.
739 // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
740 // method will take care of setting the index and transmuting the action to DOWN or UP
741 // it is the first / last pointer to go down / up.
742 void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source, int32_t action,
743 int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState,
744 int32_t edgeFlags, const PointerProperties* properties,
745 const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits,
746 int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime);
747
748 // Updates pointer coords and properties for pointers with specified ids that have moved.
749 // Returns true if any of them changed.
750 bool updateMovedPointers(const PointerProperties* inProperties, const PointerCoords* inCoords,
751 const uint32_t* inIdToIndex, PointerProperties* outProperties,
752 PointerCoords* outCoords, const uint32_t* outIdToIndex,
753 BitSet32 idBits) const;
754
755 bool isPointInsideSurface(int32_t x, int32_t y);
756 const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y);
757
758 static void assignPointerIds(const RawState* last, RawState* current);
759
760 const char* modeToString(DeviceMode deviceMode);
Arthur Hung05de5772019-09-26 18:31:26 +0800761 void rotateAndScale(float& x, float& y);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700762};
763
764} // namespace android
765
766#endif // _UI_INPUTREADER_TOUCH_INPUT_MAPPER_H