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