1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _UI_INPUTREADER_TOUCH_INPUT_MAPPER_H 18 #define _UI_INPUTREADER_TOUCH_INPUT_MAPPER_H 19 20 #include "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 29 namespace android { 30 31 /* Raw axis information from the driver. */ 32 struct RawPointerAxes { 33 RawAbsoluteAxisInfo x; 34 RawAbsoluteAxisInfo y; 35 RawAbsoluteAxisInfo pressure; 36 RawAbsoluteAxisInfo touchMajor; 37 RawAbsoluteAxisInfo touchMinor; 38 RawAbsoluteAxisInfo toolMajor; 39 RawAbsoluteAxisInfo toolMinor; 40 RawAbsoluteAxisInfo orientation; 41 RawAbsoluteAxisInfo distance; 42 RawAbsoluteAxisInfo tiltX; 43 RawAbsoluteAxisInfo tiltY; 44 RawAbsoluteAxisInfo trackingId; 45 RawAbsoluteAxisInfo slot; 46 47 RawPointerAxes(); getRawWidthRawPointerAxes48 inline int32_t getRawWidth() const { return x.maxValue - x.minValue + 1; } getRawHeightRawPointerAxes49 inline int32_t getRawHeight() const { return y.maxValue - y.minValue + 1; } 50 void clear(); 51 }; 52 53 /* Raw data for a collection of pointers including a pointer id mapping table. */ 54 struct RawPointerData { 55 struct Pointer { 56 uint32_t id; 57 int32_t x; 58 int32_t y; 59 int32_t pressure; 60 int32_t touchMajor; 61 int32_t touchMinor; 62 int32_t toolMajor; 63 int32_t toolMinor; 64 int32_t orientation; 65 int32_t distance; 66 int32_t tiltX; 67 int32_t tiltY; 68 int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant 69 bool isHovering; 70 }; 71 72 uint32_t pointerCount; 73 Pointer pointers[MAX_POINTERS]; 74 BitSet32 hoveringIdBits, touchingIdBits; 75 uint32_t idToIndex[MAX_POINTER_ID + 1]; 76 77 RawPointerData(); 78 void clear(); 79 void copyFrom(const RawPointerData& other); 80 void getCentroidOfTouchingPointers(float* outX, float* outY) const; 81 markIdBitRawPointerData82 inline void markIdBit(uint32_t id, bool isHovering) { 83 if (isHovering) { 84 hoveringIdBits.markBit(id); 85 } else { 86 touchingIdBits.markBit(id); 87 } 88 } 89 clearIdBitsRawPointerData90 inline void clearIdBits() { 91 hoveringIdBits.clear(); 92 touchingIdBits.clear(); 93 } 94 pointerForIdRawPointerData95 inline const Pointer& pointerForId(uint32_t id) const { return pointers[idToIndex[id]]; } 96 isHoveringRawPointerData97 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. */ 101 struct 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 pointerCoordsForIdCookedPointerData112 inline const PointerCoords& pointerCoordsForId(uint32_t id) const { 113 return pointerCoords[idToIndex[id]]; 114 } 115 editPointerCoordsWithIdCookedPointerData116 inline PointerCoords& editPointerCoordsWithId(uint32_t id) { 117 return pointerCoords[idToIndex[id]]; 118 } 119 editPointerPropertiesWithIdCookedPointerData120 inline PointerProperties& editPointerPropertiesWithId(uint32_t id) { 121 return pointerProperties[idToIndex[id]]; 122 } 123 isHoveringCookedPointerData124 inline bool isHovering(uint32_t pointerIndex) const { 125 return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id); 126 } 127 isTouchingCookedPointerData128 inline bool isTouching(uint32_t pointerIndex) const { 129 return touchingIdBits.hasBit(pointerProperties[pointerIndex].id); 130 } 131 }; 132 133 class TouchInputMapper : public InputMapper { 134 public: 135 explicit TouchInputMapper(InputDeviceContext& deviceContext); 136 virtual ~TouchInputMapper(); 137 138 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; 145 146 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) override; 147 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override; 148 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, 149 const int32_t* keyCodes, uint8_t* outFlags) override; 150 151 virtual void cancelTouch(nsecs_t when) override; 152 virtual void timeoutExpired(nsecs_t when) override; 153 virtual void updateExternalStylusState(const StylusState& state) override; 154 virtual std::optional<int32_t> getAssociatedDisplayId() override; 155 156 protected: 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 isHitVirtualKey172 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 applySizeScaleAndBiasCalibration279 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 copyFromRawState309 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 clearRawState317 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 copyFromCookedState337 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 clearCookedState345 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 402 private: 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 // They could be used for calculating diagonal, scaling factors, and virtual keys. 411 int32_t mRawSurfaceWidth; 412 int32_t mRawSurfaceHeight; 413 414 // The surface origin specifies how the surface coordinates should be translated 415 // to align with the logical display coordinate space. 416 int32_t mSurfaceLeft; 417 int32_t mSurfaceTop; 418 int32_t mSurfaceRight; 419 int32_t mSurfaceBottom; 420 421 // Similar to the surface coordinates, but in the raw display coordinate space rather than in 422 // the logical coordinate space. 423 int32_t mPhysicalWidth; 424 int32_t mPhysicalHeight; 425 int32_t mPhysicalLeft; 426 int32_t mPhysicalTop; 427 428 // The orientation may be different from the viewport orientation as it specifies 429 // the rotation of the surface coordinates required to produce the viewport's 430 // requested orientation, so it will depend on whether the device is orientation aware. 431 int32_t mSurfaceOrientation; 432 433 // Translation and scaling factors, orientation-independent. 434 float mXTranslate; 435 float mXScale; 436 float mXPrecision; 437 438 float mYTranslate; 439 float mYScale; 440 float mYPrecision; 441 442 float mGeometricScale; 443 444 float mPressureScale; 445 446 float mSizeScale; 447 448 float mOrientationScale; 449 450 float mDistanceScale; 451 452 bool mHaveTilt; 453 float mTiltXCenter; 454 float mTiltXScale; 455 float mTiltYCenter; 456 float mTiltYScale; 457 458 bool mExternalStylusConnected; 459 460 // Oriented motion ranges for input device info. 461 struct OrientedRanges { 462 InputDeviceInfo::MotionRange x; 463 InputDeviceInfo::MotionRange y; 464 InputDeviceInfo::MotionRange pressure; 465 466 bool haveSize; 467 InputDeviceInfo::MotionRange size; 468 469 bool haveTouchSize; 470 InputDeviceInfo::MotionRange touchMajor; 471 InputDeviceInfo::MotionRange touchMinor; 472 473 bool haveToolSize; 474 InputDeviceInfo::MotionRange toolMajor; 475 InputDeviceInfo::MotionRange toolMinor; 476 477 bool haveOrientation; 478 InputDeviceInfo::MotionRange orientation; 479 480 bool haveDistance; 481 InputDeviceInfo::MotionRange distance; 482 483 bool haveTilt; 484 InputDeviceInfo::MotionRange tilt; 485 OrientedRangesOrientedRanges486 OrientedRanges() { clear(); } 487 clearOrientedRanges488 void clear() { 489 haveSize = false; 490 haveTouchSize = false; 491 haveToolSize = false; 492 haveOrientation = false; 493 haveDistance = false; 494 haveTilt = false; 495 } 496 } mOrientedRanges; 497 498 // Oriented dimensions and precision. 499 float mOrientedXPrecision; 500 float mOrientedYPrecision; 501 502 struct CurrentVirtualKeyState { 503 bool down; 504 bool ignored; 505 nsecs_t downTime; 506 int32_t keyCode; 507 int32_t scanCode; 508 } mCurrentVirtualKey; 509 510 // Scale factor for gesture or mouse based pointer movements. 511 float mPointerXMovementScale; 512 float mPointerYMovementScale; 513 514 // Scale factor for gesture based zooming and other freeform motions. 515 float mPointerXZoomScale; 516 float mPointerYZoomScale; 517 518 // The maximum swipe width. 519 float mPointerGestureMaxSwipeWidth; 520 521 struct PointerDistanceHeapElement { 522 uint32_t currentPointerIndex : 8; 523 uint32_t lastPointerIndex : 8; 524 uint64_t distance : 48; // squared distance 525 }; 526 527 enum PointerUsage { 528 POINTER_USAGE_NONE, 529 POINTER_USAGE_GESTURES, 530 POINTER_USAGE_STYLUS, 531 POINTER_USAGE_MOUSE, 532 }; 533 PointerUsage mPointerUsage; 534 535 struct PointerGesture { 536 enum Mode { 537 // No fingers, button is not pressed. 538 // Nothing happening. 539 NEUTRAL, 540 541 // No fingers, button is not pressed. 542 // Tap detected. 543 // Emits DOWN and UP events at the pointer location. 544 TAP, 545 546 // Exactly one finger dragging following a tap. 547 // Pointer follows the active finger. 548 // Emits DOWN, MOVE and UP events at the pointer location. 549 // 550 // Detect double-taps when the finger goes up while in TAP_DRAG mode. 551 TAP_DRAG, 552 553 // Button is pressed. 554 // Pointer follows the active finger if there is one. Other fingers are ignored. 555 // Emits DOWN, MOVE and UP events at the pointer location. 556 BUTTON_CLICK_OR_DRAG, 557 558 // Exactly one finger, button is not pressed. 559 // Pointer follows the active finger. 560 // Emits HOVER_MOVE events at the pointer location. 561 // 562 // Detect taps when the finger goes up while in HOVER mode. 563 HOVER, 564 565 // Exactly two fingers but neither have moved enough to clearly indicate 566 // whether a swipe or freeform gesture was intended. We consider the 567 // pointer to be pressed so this enables clicking or long-pressing on buttons. 568 // Pointer does not move. 569 // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate. 570 PRESS, 571 572 // Exactly two fingers moving in the same direction, button is not pressed. 573 // Pointer does not move. 574 // Emits DOWN, MOVE and UP events with a single pointer coordinate that 575 // follows the midpoint between both fingers. 576 SWIPE, 577 578 // Two or more fingers moving in arbitrary directions, button is not pressed. 579 // Pointer does not move. 580 // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow 581 // each finger individually relative to the initial centroid of the finger. 582 FREEFORM, 583 584 // Waiting for quiet time to end before starting the next gesture. 585 QUIET, 586 }; 587 588 // Time the first finger went down. 589 nsecs_t firstTouchTime; 590 591 // The active pointer id from the raw touch data. 592 int32_t activeTouchId; // -1 if none 593 594 // The active pointer id from the gesture last delivered to the application. 595 int32_t activeGestureId; // -1 if none 596 597 // Pointer coords and ids for the current and previous pointer gesture. 598 Mode currentGestureMode; 599 BitSet32 currentGestureIdBits; 600 uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1]; 601 PointerProperties currentGestureProperties[MAX_POINTERS]; 602 PointerCoords currentGestureCoords[MAX_POINTERS]; 603 604 Mode lastGestureMode; 605 BitSet32 lastGestureIdBits; 606 uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1]; 607 PointerProperties lastGestureProperties[MAX_POINTERS]; 608 PointerCoords lastGestureCoords[MAX_POINTERS]; 609 610 // Time the pointer gesture last went down. 611 nsecs_t downTime; 612 613 // Time when the pointer went down for a TAP. 614 nsecs_t tapDownTime; 615 616 // Time when the pointer went up for a TAP. 617 nsecs_t tapUpTime; 618 619 // Location of initial tap. 620 float tapX, tapY; 621 622 // Time we started waiting for quiescence. 623 nsecs_t quietTime; 624 625 // Reference points for multitouch gestures. 626 float referenceTouchX; // reference touch X/Y coordinates in surface units 627 float referenceTouchY; 628 float referenceGestureX; // reference gesture X/Y coordinates in pixels 629 float referenceGestureY; 630 631 // Distance that each pointer has traveled which has not yet been 632 // subsumed into the reference gesture position. 633 BitSet32 referenceIdBits; 634 struct Delta { 635 float dx, dy; 636 }; 637 Delta referenceDeltas[MAX_POINTER_ID + 1]; 638 639 // Describes how touch ids are mapped to gesture ids for freeform gestures. 640 uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1]; 641 642 // A velocity tracker for determining whether to switch active pointers during drags. 643 VelocityTracker velocityTracker; 644 resetPointerGesture645 void reset() { 646 firstTouchTime = LLONG_MIN; 647 activeTouchId = -1; 648 activeGestureId = -1; 649 currentGestureMode = NEUTRAL; 650 currentGestureIdBits.clear(); 651 lastGestureMode = NEUTRAL; 652 lastGestureIdBits.clear(); 653 downTime = 0; 654 velocityTracker.clear(); 655 resetTap(); 656 resetQuietTime(); 657 } 658 resetTapPointerGesture659 void resetTap() { 660 tapDownTime = LLONG_MIN; 661 tapUpTime = LLONG_MIN; 662 } 663 resetQuietTimePointerGesture664 void resetQuietTime() { quietTime = LLONG_MIN; } 665 } mPointerGesture; 666 667 struct PointerSimple { 668 PointerCoords currentCoords; 669 PointerProperties currentProperties; 670 PointerCoords lastCoords; 671 PointerProperties lastProperties; 672 673 // True if the pointer is down. 674 bool down; 675 676 // True if the pointer is hovering. 677 bool hovering; 678 679 // Time the pointer last went down. 680 nsecs_t downTime; 681 resetPointerSimple682 void reset() { 683 currentCoords.clear(); 684 currentProperties.clear(); 685 lastCoords.clear(); 686 lastProperties.clear(); 687 down = false; 688 hovering = false; 689 downTime = 0; 690 } 691 } mPointerSimple; 692 693 // The pointer and scroll velocity controls. 694 VelocityControl mPointerVelocityControl; 695 VelocityControl mWheelXVelocityControl; 696 VelocityControl mWheelYVelocityControl; 697 698 std::optional<DisplayViewport> findViewport(); 699 700 void resetExternalStylus(); 701 void clearStylusDataPendingFlags(); 702 703 void sync(nsecs_t when); 704 705 bool consumeRawTouches(nsecs_t when, uint32_t policyFlags); 706 void processRawTouches(bool timeout); 707 void cookAndDispatch(nsecs_t when); 708 void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags, int32_t keyEventAction, 709 int32_t keyEventFlags); 710 711 void dispatchTouches(nsecs_t when, uint32_t policyFlags); 712 void dispatchHoverExit(nsecs_t when, uint32_t policyFlags); 713 void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags); 714 void dispatchButtonRelease(nsecs_t when, uint32_t policyFlags); 715 void dispatchButtonPress(nsecs_t when, uint32_t policyFlags); 716 const BitSet32& findActiveIdBits(const CookedPointerData& cookedPointerData); 717 void cookPointerData(); 718 void abortTouches(nsecs_t when, uint32_t policyFlags); 719 720 void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage); 721 void abortPointerUsage(nsecs_t when, uint32_t policyFlags); 722 723 void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout); 724 void abortPointerGestures(nsecs_t when, uint32_t policyFlags); 725 bool preparePointerGestures(nsecs_t when, bool* outCancelPreviousGesture, 726 bool* outFinishPreviousGesture, bool isTimeout); 727 728 void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags); 729 void abortPointerStylus(nsecs_t when, uint32_t policyFlags); 730 731 void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags); 732 void abortPointerMouse(nsecs_t when, uint32_t policyFlags); 733 734 void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, bool down, bool hovering); 735 void abortPointerSimple(nsecs_t when, uint32_t policyFlags); 736 737 bool assignExternalStylusId(const RawState& state, bool timeout); 738 void applyExternalStylusButtonState(nsecs_t when); 739 void applyExternalStylusTouchState(nsecs_t when); 740 741 // Dispatches a motion event. 742 // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the 743 // method will take care of setting the index and transmuting the action to DOWN or UP 744 // it is the first / last pointer to go down / up. 745 void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source, int32_t action, 746 int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState, 747 int32_t edgeFlags, const PointerProperties* properties, 748 const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits, 749 int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime); 750 751 // Updates pointer coords and properties for pointers with specified ids that have moved. 752 // Returns true if any of them changed. 753 bool updateMovedPointers(const PointerProperties* inProperties, const PointerCoords* inCoords, 754 const uint32_t* inIdToIndex, PointerProperties* outProperties, 755 PointerCoords* outCoords, const uint32_t* outIdToIndex, 756 BitSet32 idBits) const; 757 758 bool isPointInsideSurface(int32_t x, int32_t y); 759 const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y); 760 761 static void assignPointerIds(const RawState* last, RawState* current); 762 763 const char* modeToString(DeviceMode deviceMode); 764 void rotateAndScale(float& x, float& y); 765 }; 766 767 } // namespace android 768 769 #endif // _UI_INPUTREADER_TOUCH_INPUT_MAPPER_H