blob: df6581d1c87cdf4524a199444befdf74f129b1d3 [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];
arthurhungcc7f9802020-04-30 17:55:40 +080074 BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070075 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();
arthurhungcc7f9802020-04-30 17:55:40 +080093 canceledIdBits.clear();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070094 }
95
96 inline const Pointer& pointerForId(uint32_t id) const { return pointers[idToIndex[id]]; }
97
98 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. */
102struct CookedPointerData {
103 uint32_t pointerCount;
104 PointerProperties pointerProperties[MAX_POINTERS];
105 PointerCoords pointerCoords[MAX_POINTERS];
Nathaniel R. Lewisadb58ea2019-08-21 04:46:29 +0000106 BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits, validIdBits;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700107 uint32_t idToIndex[MAX_POINTER_ID + 1];
108
109 CookedPointerData();
110 void clear();
111 void copyFrom(const CookedPointerData& other);
112
113 inline const PointerCoords& pointerCoordsForId(uint32_t id) const {
114 return pointerCoords[idToIndex[id]];
115 }
116
117 inline PointerCoords& editPointerCoordsWithId(uint32_t id) {
118 return pointerCoords[idToIndex[id]];
119 }
120
121 inline PointerProperties& editPointerPropertiesWithId(uint32_t id) {
122 return pointerProperties[idToIndex[id]];
123 }
124
125 inline bool isHovering(uint32_t pointerIndex) const {
126 return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id);
127 }
128
129 inline bool isTouching(uint32_t pointerIndex) const {
130 return touchingIdBits.hasBit(pointerProperties[pointerIndex].id);
131 }
Nathaniel R. Lewisadb58ea2019-08-21 04:46:29 +0000132
133 inline bool hasPointerCoordsForId(uint32_t id) const { return validIdBits.hasBit(id); }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700134};
135
136class TouchInputMapper : public InputMapper {
137public:
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800138 explicit TouchInputMapper(InputDeviceContext& deviceContext);
Michael Wright227c5542020-07-02 18:30:52 +0100139 ~TouchInputMapper() override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700140
Michael Wright227c5542020-07-02 18:30:52 +0100141 uint32_t getSources() 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;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700147
Michael Wright227c5542020-07-02 18:30:52 +0100148 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;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700152
Michael Wright227c5542020-07-02 18:30:52 +0100153 void cancelTouch(nsecs_t when) override;
154 void timeoutExpired(nsecs_t when) override;
155 void updateExternalStylusState(const StylusState& state) override;
156 std::optional<int32_t> getAssociatedDisplayId() override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700157
158protected:
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
174 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
Michael Wright227c5542020-07-02 18:30:52 +0100182 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)
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700188 };
189 DeviceMode mDeviceMode;
190
191 // The reader's configuration.
192 InputReaderConfiguration mConfig;
193
194 // Immutable configuration parameters.
195 struct Parameters {
Michael Wright227c5542020-07-02 18:30:52 +0100196 enum class DeviceType {
197 TOUCH_SCREEN,
198 TOUCH_PAD,
199 TOUCH_NAVIGATION,
200 POINTER,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700201 };
202
203 DeviceType deviceType;
204 bool hasAssociatedDisplay;
205 bool associatedDisplayIsExternal;
206 bool orientationAware;
207 bool hasButtonUnderPad;
208 std::string uniqueDisplayId;
209
Michael Wright227c5542020-07-02 18:30:52 +0100210 enum class GestureMode {
211 SINGLE_TOUCH,
212 MULTI_TOUCH,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700213 };
214 GestureMode gestureMode;
215
216 bool wake;
217 } mParameters;
218
219 // Immutable calibration parameters in parsed form.
220 struct Calibration {
221 // Size
Michael Wright227c5542020-07-02 18:30:52 +0100222 enum class SizeCalibration {
223 DEFAULT,
224 NONE,
225 GEOMETRIC,
226 DIAMETER,
227 BOX,
228 AREA,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700229 };
230
231 SizeCalibration sizeCalibration;
232
233 bool haveSizeScale;
234 float sizeScale;
235 bool haveSizeBias;
236 float sizeBias;
237 bool haveSizeIsSummed;
238 bool sizeIsSummed;
239
240 // Pressure
Michael Wright227c5542020-07-02 18:30:52 +0100241 enum class PressureCalibration {
242 DEFAULT,
243 NONE,
244 PHYSICAL,
245 AMPLITUDE,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700246 };
247
248 PressureCalibration pressureCalibration;
249 bool havePressureScale;
250 float pressureScale;
251
252 // Orientation
Michael Wright227c5542020-07-02 18:30:52 +0100253 enum class OrientationCalibration {
254 DEFAULT,
255 NONE,
256 INTERPOLATED,
257 VECTOR,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700258 };
259
260 OrientationCalibration orientationCalibration;
261
262 // Distance
Michael Wright227c5542020-07-02 18:30:52 +0100263 enum class DistanceCalibration {
264 DEFAULT,
265 NONE,
266 SCALED,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700267 };
268
269 DistanceCalibration distanceCalibration;
270 bool haveDistanceScale;
271 float distanceScale;
272
Michael Wright227c5542020-07-02 18:30:52 +0100273 enum class CoverageCalibration {
274 DEFAULT,
275 NONE,
276 BOX,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700277 };
278
279 CoverageCalibration coverageCalibration;
280
281 inline void applySizeScaleAndBias(float* outSize) const {
282 if (haveSizeScale) {
283 *outSize *= sizeScale;
284 }
285 if (haveSizeBias) {
286 *outSize += sizeBias;
287 }
288 if (*outSize < 0) {
289 *outSize = 0;
290 }
291 }
292 } mCalibration;
293
294 // Affine location transformation/calibration
295 struct TouchAffineTransformation mAffineTransform;
296
297 RawPointerAxes mRawPointerAxes;
298
299 struct RawState {
300 nsecs_t when;
301
302 // Raw pointer sample data.
303 RawPointerData rawPointerData;
304
305 int32_t buttonState;
306
307 // Scroll state.
308 int32_t rawVScroll;
309 int32_t rawHScroll;
310
311 void copyFrom(const RawState& other) {
312 when = other.when;
313 rawPointerData.copyFrom(other.rawPointerData);
314 buttonState = other.buttonState;
315 rawVScroll = other.rawVScroll;
316 rawHScroll = other.rawHScroll;
317 }
318
319 void clear() {
320 when = 0;
321 rawPointerData.clear();
322 buttonState = 0;
323 rawVScroll = 0;
324 rawHScroll = 0;
325 }
326 };
327
328 struct CookedState {
329 // Cooked pointer sample data.
330 CookedPointerData cookedPointerData;
331
332 // Id bits used to differentiate fingers, stylus and mouse tools.
333 BitSet32 fingerIdBits;
334 BitSet32 stylusIdBits;
335 BitSet32 mouseIdBits;
336
337 int32_t buttonState;
338
339 void copyFrom(const CookedState& other) {
340 cookedPointerData.copyFrom(other.cookedPointerData);
341 fingerIdBits = other.fingerIdBits;
342 stylusIdBits = other.stylusIdBits;
343 mouseIdBits = other.mouseIdBits;
344 buttonState = other.buttonState;
345 }
346
347 void clear() {
348 cookedPointerData.clear();
349 fingerIdBits.clear();
350 stylusIdBits.clear();
351 mouseIdBits.clear();
352 buttonState = 0;
353 }
354 };
355
356 std::vector<RawState> mRawStatesPending;
357 RawState mCurrentRawState;
358 CookedState mCurrentCookedState;
359 RawState mLastRawState;
360 CookedState mLastCookedState;
361
362 // State provided by an external stylus
363 StylusState mExternalStylusState;
364 int64_t mExternalStylusId;
365 nsecs_t mExternalStylusFusionTimeout;
366 bool mExternalStylusDataPending;
367
368 // True if we sent a HOVER_ENTER event.
369 bool mSentHoverEnter;
370
371 // Have we assigned pointer IDs for this stream
372 bool mHavePointerIds;
373
374 // Is the current stream of direct touch events aborted
375 bool mCurrentMotionAborted;
376
377 // The time the primary pointer last went down.
378 nsecs_t mDownTime;
379
380 // The pointer controller, or null if the device is not a pointer.
Michael Wright17db18e2020-06-26 20:51:44 +0100381 std::shared_ptr<PointerControllerInterface> mPointerController;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700382
383 std::vector<VirtualKey> mVirtualKeys;
384
385 virtual void configureParameters();
386 virtual void dumpParameters(std::string& dump);
387 virtual void configureRawPointerAxes();
388 virtual void dumpRawPointerAxes(std::string& dump);
389 virtual void configureSurface(nsecs_t when, bool* outResetNeeded);
390 virtual void dumpSurface(std::string& dump);
391 virtual void configureVirtualKeys();
392 virtual void dumpVirtualKeys(std::string& dump);
393 virtual void parseCalibration();
394 virtual void resolveCalibration();
395 virtual void dumpCalibration(std::string& dump);
396 virtual void updateAffineTransformation();
397 virtual void dumpAffineTransformation(std::string& dump);
398 virtual void resolveExternalStylusPresence();
399 virtual bool hasStylus() const = 0;
400 virtual bool hasExternalStylus() const;
401
402 virtual void syncTouch(nsecs_t when, RawState* outState) = 0;
403
404private:
405 // The current viewport.
406 // The components of the viewport are specified in the display's rotated orientation.
407 DisplayViewport mViewport;
408
409 // The surface orientation, width and height set by configureSurface().
410 // The width and height are derived from the viewport but are specified
411 // in the natural orientation.
Arthur Hung4197f6b2020-03-16 15:39:59 +0800412 // They could be used for calculating diagonal, scaling factors, and virtual keys.
413 int32_t mRawSurfaceWidth;
414 int32_t mRawSurfaceHeight;
415
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700416 // The surface origin specifies how the surface coordinates should be translated
417 // to align with the logical display coordinate space.
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700418 int32_t mSurfaceLeft;
419 int32_t mSurfaceTop;
Arthur Hung4197f6b2020-03-16 15:39:59 +0800420 int32_t mSurfaceRight;
421 int32_t mSurfaceBottom;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700422
423 // Similar to the surface coordinates, but in the raw display coordinate space rather than in
424 // the logical coordinate space.
425 int32_t mPhysicalWidth;
426 int32_t mPhysicalHeight;
427 int32_t mPhysicalLeft;
428 int32_t mPhysicalTop;
429
430 // The orientation may be different from the viewport orientation as it specifies
431 // the rotation of the surface coordinates required to produce the viewport's
432 // requested orientation, so it will depend on whether the device is orientation aware.
433 int32_t mSurfaceOrientation;
434
435 // Translation and scaling factors, orientation-independent.
436 float mXTranslate;
437 float mXScale;
438 float mXPrecision;
439
440 float mYTranslate;
441 float mYScale;
442 float mYPrecision;
443
444 float mGeometricScale;
445
446 float mPressureScale;
447
448 float mSizeScale;
449
450 float mOrientationScale;
451
452 float mDistanceScale;
453
454 bool mHaveTilt;
455 float mTiltXCenter;
456 float mTiltXScale;
457 float mTiltYCenter;
458 float mTiltYScale;
459
460 bool mExternalStylusConnected;
461
462 // Oriented motion ranges for input device info.
463 struct OrientedRanges {
464 InputDeviceInfo::MotionRange x;
465 InputDeviceInfo::MotionRange y;
466 InputDeviceInfo::MotionRange pressure;
467
468 bool haveSize;
469 InputDeviceInfo::MotionRange size;
470
471 bool haveTouchSize;
472 InputDeviceInfo::MotionRange touchMajor;
473 InputDeviceInfo::MotionRange touchMinor;
474
475 bool haveToolSize;
476 InputDeviceInfo::MotionRange toolMajor;
477 InputDeviceInfo::MotionRange toolMinor;
478
479 bool haveOrientation;
480 InputDeviceInfo::MotionRange orientation;
481
482 bool haveDistance;
483 InputDeviceInfo::MotionRange distance;
484
485 bool haveTilt;
486 InputDeviceInfo::MotionRange tilt;
487
488 OrientedRanges() { clear(); }
489
490 void clear() {
491 haveSize = false;
492 haveTouchSize = false;
493 haveToolSize = false;
494 haveOrientation = false;
495 haveDistance = false;
496 haveTilt = false;
497 }
498 } mOrientedRanges;
499
500 // Oriented dimensions and precision.
501 float mOrientedXPrecision;
502 float mOrientedYPrecision;
503
504 struct CurrentVirtualKeyState {
505 bool down;
506 bool ignored;
507 nsecs_t downTime;
508 int32_t keyCode;
509 int32_t scanCode;
510 } mCurrentVirtualKey;
511
512 // Scale factor for gesture or mouse based pointer movements.
513 float mPointerXMovementScale;
514 float mPointerYMovementScale;
515
516 // Scale factor for gesture based zooming and other freeform motions.
517 float mPointerXZoomScale;
518 float mPointerYZoomScale;
519
520 // The maximum swipe width.
521 float mPointerGestureMaxSwipeWidth;
522
523 struct PointerDistanceHeapElement {
524 uint32_t currentPointerIndex : 8;
525 uint32_t lastPointerIndex : 8;
526 uint64_t distance : 48; // squared distance
527 };
528
Michael Wright227c5542020-07-02 18:30:52 +0100529 enum class PointerUsage {
530 NONE,
531 GESTURES,
532 STYLUS,
533 MOUSE,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700534 };
535 PointerUsage mPointerUsage;
536
537 struct PointerGesture {
Michael Wright227c5542020-07-02 18:30:52 +0100538 enum class Mode {
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700539 // No fingers, button is not pressed.
540 // Nothing happening.
541 NEUTRAL,
542
543 // No fingers, button is not pressed.
544 // Tap detected.
545 // Emits DOWN and UP events at the pointer location.
546 TAP,
547
548 // Exactly one finger dragging following a tap.
549 // Pointer follows the active finger.
550 // Emits DOWN, MOVE and UP events at the pointer location.
551 //
552 // Detect double-taps when the finger goes up while in TAP_DRAG mode.
553 TAP_DRAG,
554
555 // Button is pressed.
556 // Pointer follows the active finger if there is one. Other fingers are ignored.
557 // Emits DOWN, MOVE and UP events at the pointer location.
558 BUTTON_CLICK_OR_DRAG,
559
560 // Exactly one finger, button is not pressed.
561 // Pointer follows the active finger.
562 // Emits HOVER_MOVE events at the pointer location.
563 //
564 // Detect taps when the finger goes up while in HOVER mode.
565 HOVER,
566
567 // Exactly two fingers but neither have moved enough to clearly indicate
568 // whether a swipe or freeform gesture was intended. We consider the
569 // pointer to be pressed so this enables clicking or long-pressing on buttons.
570 // Pointer does not move.
571 // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate.
572 PRESS,
573
574 // Exactly two fingers moving in the same direction, button is not pressed.
575 // Pointer does not move.
576 // Emits DOWN, MOVE and UP events with a single pointer coordinate that
577 // follows the midpoint between both fingers.
578 SWIPE,
579
580 // Two or more fingers moving in arbitrary directions, button is not pressed.
581 // Pointer does not move.
582 // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow
583 // each finger individually relative to the initial centroid of the finger.
584 FREEFORM,
585
586 // Waiting for quiet time to end before starting the next gesture.
587 QUIET,
588 };
589
590 // Time the first finger went down.
591 nsecs_t firstTouchTime;
592
593 // The active pointer id from the raw touch data.
594 int32_t activeTouchId; // -1 if none
595
596 // The active pointer id from the gesture last delivered to the application.
597 int32_t activeGestureId; // -1 if none
598
599 // Pointer coords and ids for the current and previous pointer gesture.
600 Mode currentGestureMode;
601 BitSet32 currentGestureIdBits;
602 uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1];
603 PointerProperties currentGestureProperties[MAX_POINTERS];
604 PointerCoords currentGestureCoords[MAX_POINTERS];
605
606 Mode lastGestureMode;
607 BitSet32 lastGestureIdBits;
608 uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1];
609 PointerProperties lastGestureProperties[MAX_POINTERS];
610 PointerCoords lastGestureCoords[MAX_POINTERS];
611
612 // Time the pointer gesture last went down.
613 nsecs_t downTime;
614
615 // Time when the pointer went down for a TAP.
616 nsecs_t tapDownTime;
617
618 // Time when the pointer went up for a TAP.
619 nsecs_t tapUpTime;
620
621 // Location of initial tap.
622 float tapX, tapY;
623
624 // Time we started waiting for quiescence.
625 nsecs_t quietTime;
626
627 // Reference points for multitouch gestures.
628 float referenceTouchX; // reference touch X/Y coordinates in surface units
629 float referenceTouchY;
630 float referenceGestureX; // reference gesture X/Y coordinates in pixels
631 float referenceGestureY;
632
633 // Distance that each pointer has traveled which has not yet been
634 // subsumed into the reference gesture position.
635 BitSet32 referenceIdBits;
636 struct Delta {
637 float dx, dy;
638 };
639 Delta referenceDeltas[MAX_POINTER_ID + 1];
640
641 // Describes how touch ids are mapped to gesture ids for freeform gestures.
642 uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
643
644 // A velocity tracker for determining whether to switch active pointers during drags.
645 VelocityTracker velocityTracker;
646
647 void reset() {
648 firstTouchTime = LLONG_MIN;
649 activeTouchId = -1;
650 activeGestureId = -1;
Michael Wright227c5542020-07-02 18:30:52 +0100651 currentGestureMode = Mode::NEUTRAL;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700652 currentGestureIdBits.clear();
Michael Wright227c5542020-07-02 18:30:52 +0100653 lastGestureMode = Mode::NEUTRAL;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700654 lastGestureIdBits.clear();
655 downTime = 0;
656 velocityTracker.clear();
657 resetTap();
658 resetQuietTime();
659 }
660
661 void resetTap() {
662 tapDownTime = LLONG_MIN;
663 tapUpTime = LLONG_MIN;
664 }
665
666 void resetQuietTime() { quietTime = LLONG_MIN; }
667 } mPointerGesture;
668
669 struct PointerSimple {
670 PointerCoords currentCoords;
671 PointerProperties currentProperties;
672 PointerCoords lastCoords;
673 PointerProperties lastProperties;
674
675 // True if the pointer is down.
676 bool down;
677
678 // True if the pointer is hovering.
679 bool hovering;
680
681 // Time the pointer last went down.
682 nsecs_t downTime;
683
684 void reset() {
685 currentCoords.clear();
686 currentProperties.clear();
687 lastCoords.clear();
688 lastProperties.clear();
689 down = false;
690 hovering = false;
691 downTime = 0;
692 }
693 } mPointerSimple;
694
695 // The pointer and scroll velocity controls.
696 VelocityControl mPointerVelocityControl;
697 VelocityControl mWheelXVelocityControl;
698 VelocityControl mWheelYVelocityControl;
699
700 std::optional<DisplayViewport> findViewport();
701
702 void resetExternalStylus();
703 void clearStylusDataPendingFlags();
704
705 void sync(nsecs_t when);
706
707 bool consumeRawTouches(nsecs_t when, uint32_t policyFlags);
708 void processRawTouches(bool timeout);
709 void cookAndDispatch(nsecs_t when);
710 void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags, int32_t keyEventAction,
711 int32_t keyEventFlags);
712
713 void dispatchTouches(nsecs_t when, uint32_t policyFlags);
714 void dispatchHoverExit(nsecs_t when, uint32_t policyFlags);
715 void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags);
716 void dispatchButtonRelease(nsecs_t when, uint32_t policyFlags);
717 void dispatchButtonPress(nsecs_t when, uint32_t policyFlags);
718 const BitSet32& findActiveIdBits(const CookedPointerData& cookedPointerData);
719 void cookPointerData();
720 void abortTouches(nsecs_t when, uint32_t policyFlags);
721
722 void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage);
723 void abortPointerUsage(nsecs_t when, uint32_t policyFlags);
724
725 void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
726 void abortPointerGestures(nsecs_t when, uint32_t policyFlags);
727 bool preparePointerGestures(nsecs_t when, bool* outCancelPreviousGesture,
728 bool* outFinishPreviousGesture, bool isTimeout);
729
730 void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags);
731 void abortPointerStylus(nsecs_t when, uint32_t policyFlags);
732
733 void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags);
734 void abortPointerMouse(nsecs_t when, uint32_t policyFlags);
735
736 void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, bool down, bool hovering);
737 void abortPointerSimple(nsecs_t when, uint32_t policyFlags);
738
739 bool assignExternalStylusId(const RawState& state, bool timeout);
740 void applyExternalStylusButtonState(nsecs_t when);
741 void applyExternalStylusTouchState(nsecs_t when);
742
743 // Dispatches a motion event.
744 // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
745 // method will take care of setting the index and transmuting the action to DOWN or UP
746 // it is the first / last pointer to go down / up.
747 void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source, int32_t action,
748 int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState,
749 int32_t edgeFlags, const PointerProperties* properties,
750 const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits,
751 int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime);
752
753 // Updates pointer coords and properties for pointers with specified ids that have moved.
754 // Returns true if any of them changed.
755 bool updateMovedPointers(const PointerProperties* inProperties, const PointerCoords* inCoords,
756 const uint32_t* inIdToIndex, PointerProperties* outProperties,
757 PointerCoords* outCoords, const uint32_t* outIdToIndex,
758 BitSet32 idBits) const;
759
760 bool isPointInsideSurface(int32_t x, int32_t y);
761 const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y);
762
763 static void assignPointerIds(const RawState* last, RawState* current);
764
765 const char* modeToString(DeviceMode deviceMode);
Arthur Hung05de5772019-09-26 18:31:26 +0800766 void rotateAndScale(float& x, float& y);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700767};
768
769} // namespace android
770
771#endif // _UI_INPUTREADER_TOUCH_INPUT_MAPPER_H