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