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 <stdint.h> 21 22 #include "CursorButtonAccumulator.h" 23 #include "CursorScrollAccumulator.h" 24 #include "EventHub.h" 25 #include "InputMapper.h" 26 #include "InputReaderBase.h" 27 #include "TouchButtonAccumulator.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, canceledIdBits; 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 canceledIdBits.clear(); 94 } 95 pointerForIdRawPointerData96 inline const Pointer& pointerForId(uint32_t id) const { return pointers[idToIndex[id]]; } 97 isHoveringRawPointerData98 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. */ 102 struct CookedPointerData { 103 uint32_t pointerCount; 104 PointerProperties pointerProperties[MAX_POINTERS]; 105 PointerCoords pointerCoords[MAX_POINTERS]; 106 BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits, validIdBits; 107 uint32_t idToIndex[MAX_POINTER_ID + 1]; 108 109 CookedPointerData(); 110 void clear(); 111 void copyFrom(const CookedPointerData& other); 112 pointerCoordsForIdCookedPointerData113 inline const PointerCoords& pointerCoordsForId(uint32_t id) const { 114 return pointerCoords[idToIndex[id]]; 115 } 116 editPointerCoordsWithIdCookedPointerData117 inline PointerCoords& editPointerCoordsWithId(uint32_t id) { 118 return pointerCoords[idToIndex[id]]; 119 } 120 editPointerPropertiesWithIdCookedPointerData121 inline PointerProperties& editPointerPropertiesWithId(uint32_t id) { 122 return pointerProperties[idToIndex[id]]; 123 } 124 isHoveringCookedPointerData125 inline bool isHovering(uint32_t pointerIndex) const { 126 return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id); 127 } 128 isTouchingCookedPointerData129 inline bool isTouching(uint32_t pointerIndex) const { 130 return touchingIdBits.hasBit(pointerProperties[pointerIndex].id); 131 } 132 hasPointerCoordsForIdCookedPointerData133 inline bool hasPointerCoordsForId(uint32_t id) const { return validIdBits.hasBit(id); } 134 }; 135 136 class TouchInputMapper : public InputMapper { 137 public: 138 explicit TouchInputMapper(InputDeviceContext& deviceContext); 139 ~TouchInputMapper() override; 140 141 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; 147 148 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; 152 153 void cancelTouch(nsecs_t when, nsecs_t readTime) override; 154 void timeoutExpired(nsecs_t when) override; 155 void updateExternalStylusState(const StylusState& state) override; 156 std::optional<int32_t> getAssociatedDisplayId() override; 157 158 protected: 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 isHitVirtualKey174 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 182 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) 188 }; 189 DeviceMode mDeviceMode; 190 191 // The reader's configuration. 192 InputReaderConfiguration mConfig; 193 194 // Immutable configuration parameters. 195 struct Parameters { 196 enum class DeviceType { 197 TOUCH_SCREEN, 198 TOUCH_PAD, 199 TOUCH_NAVIGATION, 200 POINTER, 201 }; 202 203 DeviceType deviceType; 204 bool hasAssociatedDisplay; 205 bool associatedDisplayIsExternal; 206 bool orientationAware; 207 bool hasButtonUnderPad; 208 std::string uniqueDisplayId; 209 210 enum class GestureMode { 211 SINGLE_TOUCH, 212 MULTI_TOUCH, 213 }; 214 GestureMode gestureMode; 215 216 bool wake; 217 } mParameters; 218 219 // Immutable calibration parameters in parsed form. 220 struct Calibration { 221 // Size 222 enum class SizeCalibration { 223 DEFAULT, 224 NONE, 225 GEOMETRIC, 226 DIAMETER, 227 BOX, 228 AREA, 229 }; 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 241 enum class PressureCalibration { 242 DEFAULT, 243 NONE, 244 PHYSICAL, 245 AMPLITUDE, 246 }; 247 248 PressureCalibration pressureCalibration; 249 bool havePressureScale; 250 float pressureScale; 251 252 // Orientation 253 enum class OrientationCalibration { 254 DEFAULT, 255 NONE, 256 INTERPOLATED, 257 VECTOR, 258 }; 259 260 OrientationCalibration orientationCalibration; 261 262 // Distance 263 enum class DistanceCalibration { 264 DEFAULT, 265 NONE, 266 SCALED, 267 }; 268 269 DistanceCalibration distanceCalibration; 270 bool haveDistanceScale; 271 float distanceScale; 272 273 enum class CoverageCalibration { 274 DEFAULT, 275 NONE, 276 BOX, 277 }; 278 279 CoverageCalibration coverageCalibration; 280 applySizeScaleAndBiasCalibration281 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 nsecs_t readTime; 302 303 // Raw pointer sample data. 304 RawPointerData rawPointerData; 305 306 int32_t buttonState; 307 308 // Scroll state. 309 int32_t rawVScroll; 310 int32_t rawHScroll; 311 copyFromRawState312 void copyFrom(const RawState& other) { 313 when = other.when; 314 readTime = other.readTime; 315 rawPointerData.copyFrom(other.rawPointerData); 316 buttonState = other.buttonState; 317 rawVScroll = other.rawVScroll; 318 rawHScroll = other.rawHScroll; 319 } 320 clearRawState321 void clear() { 322 when = 0; 323 readTime = 0; 324 rawPointerData.clear(); 325 buttonState = 0; 326 rawVScroll = 0; 327 rawHScroll = 0; 328 } 329 }; 330 331 struct CookedState { 332 // Cooked pointer sample data. 333 CookedPointerData cookedPointerData; 334 335 // Id bits used to differentiate fingers, stylus and mouse tools. 336 BitSet32 fingerIdBits; 337 BitSet32 stylusIdBits; 338 BitSet32 mouseIdBits; 339 340 int32_t buttonState; 341 copyFromCookedState342 void copyFrom(const CookedState& other) { 343 cookedPointerData.copyFrom(other.cookedPointerData); 344 fingerIdBits = other.fingerIdBits; 345 stylusIdBits = other.stylusIdBits; 346 mouseIdBits = other.mouseIdBits; 347 buttonState = other.buttonState; 348 } 349 clearCookedState350 void clear() { 351 cookedPointerData.clear(); 352 fingerIdBits.clear(); 353 stylusIdBits.clear(); 354 mouseIdBits.clear(); 355 buttonState = 0; 356 } 357 }; 358 359 std::vector<RawState> mRawStatesPending; 360 RawState mCurrentRawState; 361 CookedState mCurrentCookedState; 362 RawState mLastRawState; 363 CookedState mLastCookedState; 364 365 // State provided by an external stylus 366 StylusState mExternalStylusState; 367 int64_t mExternalStylusId; 368 nsecs_t mExternalStylusFusionTimeout; 369 bool mExternalStylusDataPending; 370 371 // True if we sent a HOVER_ENTER event. 372 bool mSentHoverEnter; 373 374 // Have we assigned pointer IDs for this stream 375 bool mHavePointerIds; 376 377 // Is the current stream of direct touch events aborted 378 bool mCurrentMotionAborted; 379 380 // The time the primary pointer last went down. 381 nsecs_t mDownTime; 382 383 // The pointer controller, or null if the device is not a pointer. 384 std::shared_ptr<PointerControllerInterface> mPointerController; 385 386 std::vector<VirtualKey> mVirtualKeys; 387 388 virtual void configureParameters(); 389 virtual void dumpParameters(std::string& dump); 390 virtual void configureRawPointerAxes(); 391 virtual void dumpRawPointerAxes(std::string& dump); 392 virtual void configureSurface(nsecs_t when, bool* outResetNeeded); 393 virtual void dumpSurface(std::string& dump); 394 virtual void configureVirtualKeys(); 395 virtual void dumpVirtualKeys(std::string& dump); 396 virtual void parseCalibration(); 397 virtual void resolveCalibration(); 398 virtual void dumpCalibration(std::string& dump); 399 virtual void updateAffineTransformation(); 400 virtual void dumpAffineTransformation(std::string& dump); 401 virtual void resolveExternalStylusPresence(); 402 virtual bool hasStylus() const = 0; 403 virtual bool hasExternalStylus() const; 404 405 virtual void syncTouch(nsecs_t when, RawState* outState) = 0; 406 407 private: 408 // The current viewport. 409 // The components of the viewport are specified in the display's rotated orientation. 410 DisplayViewport mViewport; 411 412 // The surface orientation, width and height set by configureSurface(). 413 // The width and height are derived from the viewport but are specified 414 // in the natural orientation. 415 // They could be used for calculating diagonal, scaling factors, and virtual keys. 416 int32_t mRawSurfaceWidth; 417 int32_t mRawSurfaceHeight; 418 419 // The surface origin specifies how the surface coordinates should be translated 420 // to align with the logical display coordinate space. 421 int32_t mSurfaceLeft; 422 int32_t mSurfaceTop; 423 int32_t mSurfaceRight; 424 int32_t mSurfaceBottom; 425 426 // Similar to the surface coordinates, but in the raw display coordinate space rather than in 427 // the logical coordinate space. 428 int32_t mPhysicalWidth; 429 int32_t mPhysicalHeight; 430 int32_t mPhysicalLeft; 431 int32_t mPhysicalTop; 432 433 // The orientation may be different from the viewport orientation as it specifies 434 // the rotation of the surface coordinates required to produce the viewport's 435 // requested orientation, so it will depend on whether the device is orientation aware. 436 int32_t mSurfaceOrientation; 437 438 // Translation and scaling factors, orientation-independent. 439 float mXTranslate; 440 float mXScale; 441 float mXPrecision; 442 443 float mYTranslate; 444 float mYScale; 445 float mYPrecision; 446 447 float mGeometricScale; 448 449 float mPressureScale; 450 451 float mSizeScale; 452 453 float mOrientationScale; 454 455 float mDistanceScale; 456 457 bool mHaveTilt; 458 float mTiltXCenter; 459 float mTiltXScale; 460 float mTiltYCenter; 461 float mTiltYScale; 462 463 bool mExternalStylusConnected; 464 465 // Oriented motion ranges for input device info. 466 struct OrientedRanges { 467 InputDeviceInfo::MotionRange x; 468 InputDeviceInfo::MotionRange y; 469 InputDeviceInfo::MotionRange pressure; 470 471 bool haveSize; 472 InputDeviceInfo::MotionRange size; 473 474 bool haveTouchSize; 475 InputDeviceInfo::MotionRange touchMajor; 476 InputDeviceInfo::MotionRange touchMinor; 477 478 bool haveToolSize; 479 InputDeviceInfo::MotionRange toolMajor; 480 InputDeviceInfo::MotionRange toolMinor; 481 482 bool haveOrientation; 483 InputDeviceInfo::MotionRange orientation; 484 485 bool haveDistance; 486 InputDeviceInfo::MotionRange distance; 487 488 bool haveTilt; 489 InputDeviceInfo::MotionRange tilt; 490 OrientedRangesOrientedRanges491 OrientedRanges() { clear(); } 492 clearOrientedRanges493 void clear() { 494 haveSize = false; 495 haveTouchSize = false; 496 haveToolSize = false; 497 haveOrientation = false; 498 haveDistance = false; 499 haveTilt = false; 500 } 501 } mOrientedRanges; 502 503 // Oriented dimensions and precision. 504 float mOrientedXPrecision; 505 float mOrientedYPrecision; 506 507 struct CurrentVirtualKeyState { 508 bool down; 509 bool ignored; 510 nsecs_t downTime; 511 int32_t keyCode; 512 int32_t scanCode; 513 } mCurrentVirtualKey; 514 515 // Scale factor for gesture or mouse based pointer movements. 516 float mPointerXMovementScale; 517 float mPointerYMovementScale; 518 519 // Scale factor for gesture based zooming and other freeform motions. 520 float mPointerXZoomScale; 521 float mPointerYZoomScale; 522 523 // The maximum swipe width. 524 float mPointerGestureMaxSwipeWidth; 525 526 struct PointerDistanceHeapElement { 527 uint32_t currentPointerIndex : 8; 528 uint32_t lastPointerIndex : 8; 529 uint64_t distance : 48; // squared distance 530 }; 531 532 enum class PointerUsage { 533 NONE, 534 GESTURES, 535 STYLUS, 536 MOUSE, 537 }; 538 PointerUsage mPointerUsage; 539 540 struct PointerGesture { 541 enum class Mode { 542 // No fingers, button is not pressed. 543 // Nothing happening. 544 NEUTRAL, 545 546 // No fingers, button is not pressed. 547 // Tap detected. 548 // Emits DOWN and UP events at the pointer location. 549 TAP, 550 551 // Exactly one finger dragging following a tap. 552 // Pointer follows the active finger. 553 // Emits DOWN, MOVE and UP events at the pointer location. 554 // 555 // Detect double-taps when the finger goes up while in TAP_DRAG mode. 556 TAP_DRAG, 557 558 // Button is pressed. 559 // Pointer follows the active finger if there is one. Other fingers are ignored. 560 // Emits DOWN, MOVE and UP events at the pointer location. 561 BUTTON_CLICK_OR_DRAG, 562 563 // Exactly one finger, button is not pressed. 564 // Pointer follows the active finger. 565 // Emits HOVER_MOVE events at the pointer location. 566 // 567 // Detect taps when the finger goes up while in HOVER mode. 568 HOVER, 569 570 // Exactly two fingers but neither have moved enough to clearly indicate 571 // whether a swipe or freeform gesture was intended. We consider the 572 // pointer to be pressed so this enables clicking or long-pressing on buttons. 573 // Pointer does not move. 574 // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate. 575 PRESS, 576 577 // Exactly two fingers moving in the same direction, button is not pressed. 578 // Pointer does not move. 579 // Emits DOWN, MOVE and UP events with a single pointer coordinate that 580 // follows the midpoint between both fingers. 581 SWIPE, 582 583 // Two or more fingers moving in arbitrary directions, button is not pressed. 584 // Pointer does not move. 585 // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow 586 // each finger individually relative to the initial centroid of the finger. 587 FREEFORM, 588 589 // Waiting for quiet time to end before starting the next gesture. 590 QUIET, 591 }; 592 593 // When a gesture is sent to an unfocused window, return true if it can bring that window 594 // into focus, false otherwise. canGestureAffectWindowFocusPointerGesture595 static bool canGestureAffectWindowFocus(Mode mode) { 596 switch (mode) { 597 case Mode::TAP: 598 case Mode::TAP_DRAG: 599 case Mode::BUTTON_CLICK_OR_DRAG: 600 // Taps can affect window focus. 601 return true; 602 case Mode::FREEFORM: 603 case Mode::HOVER: 604 case Mode::NEUTRAL: 605 case Mode::PRESS: 606 case Mode::QUIET: 607 case Mode::SWIPE: 608 // Most gestures can be performed on an unfocused window, so they should not 609 // not affect window focus. 610 return false; 611 } 612 } 613 614 // Time the first finger went down. 615 nsecs_t firstTouchTime; 616 617 // The active pointer id from the raw touch data. 618 int32_t activeTouchId; // -1 if none 619 620 // The active pointer id from the gesture last delivered to the application. 621 int32_t activeGestureId; // -1 if none 622 623 // Pointer coords and ids for the current and previous pointer gesture. 624 Mode currentGestureMode; 625 BitSet32 currentGestureIdBits; 626 uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1]; 627 PointerProperties currentGestureProperties[MAX_POINTERS]; 628 PointerCoords currentGestureCoords[MAX_POINTERS]; 629 630 Mode lastGestureMode; 631 BitSet32 lastGestureIdBits; 632 uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1]; 633 PointerProperties lastGestureProperties[MAX_POINTERS]; 634 PointerCoords lastGestureCoords[MAX_POINTERS]; 635 636 // Time the pointer gesture last went down. 637 nsecs_t downTime; 638 639 // Time when the pointer went down for a TAP. 640 nsecs_t tapDownTime; 641 642 // Time when the pointer went up for a TAP. 643 nsecs_t tapUpTime; 644 645 // Location of initial tap. 646 float tapX, tapY; 647 648 // Time we started waiting for quiescence. 649 nsecs_t quietTime; 650 651 // Reference points for multitouch gestures. 652 float referenceTouchX; // reference touch X/Y coordinates in surface units 653 float referenceTouchY; 654 float referenceGestureX; // reference gesture X/Y coordinates in pixels 655 float referenceGestureY; 656 657 // Distance that each pointer has traveled which has not yet been 658 // subsumed into the reference gesture position. 659 BitSet32 referenceIdBits; 660 struct Delta { 661 float dx, dy; 662 }; 663 Delta referenceDeltas[MAX_POINTER_ID + 1]; 664 665 // Describes how touch ids are mapped to gesture ids for freeform gestures. 666 uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1]; 667 668 // A velocity tracker for determining whether to switch active pointers during drags. 669 VelocityTracker velocityTracker; 670 resetPointerGesture671 void reset() { 672 firstTouchTime = LLONG_MIN; 673 activeTouchId = -1; 674 activeGestureId = -1; 675 currentGestureMode = Mode::NEUTRAL; 676 currentGestureIdBits.clear(); 677 lastGestureMode = Mode::NEUTRAL; 678 lastGestureIdBits.clear(); 679 downTime = 0; 680 velocityTracker.clear(); 681 resetTap(); 682 resetQuietTime(); 683 } 684 resetTapPointerGesture685 void resetTap() { 686 tapDownTime = LLONG_MIN; 687 tapUpTime = LLONG_MIN; 688 } 689 resetQuietTimePointerGesture690 void resetQuietTime() { quietTime = LLONG_MIN; } 691 } mPointerGesture; 692 693 struct PointerSimple { 694 PointerCoords currentCoords; 695 PointerProperties currentProperties; 696 PointerCoords lastCoords; 697 PointerProperties lastProperties; 698 699 // True if the pointer is down. 700 bool down; 701 702 // True if the pointer is hovering. 703 bool hovering; 704 705 // Time the pointer last went down. 706 nsecs_t downTime; 707 resetPointerSimple708 void reset() { 709 currentCoords.clear(); 710 currentProperties.clear(); 711 lastCoords.clear(); 712 lastProperties.clear(); 713 down = false; 714 hovering = false; 715 downTime = 0; 716 } 717 } mPointerSimple; 718 719 // The pointer and scroll velocity controls. 720 VelocityControl mPointerVelocityControl; 721 VelocityControl mWheelXVelocityControl; 722 VelocityControl mWheelYVelocityControl; 723 724 std::optional<DisplayViewport> findViewport(); 725 726 void resetExternalStylus(); 727 void clearStylusDataPendingFlags(); 728 729 void sync(nsecs_t when, nsecs_t readTime); 730 731 bool consumeRawTouches(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 732 void processRawTouches(bool timeout); 733 void cookAndDispatch(nsecs_t when, nsecs_t readTime); 734 void dispatchVirtualKey(nsecs_t when, nsecs_t readTime, uint32_t policyFlags, 735 int32_t keyEventAction, int32_t keyEventFlags); 736 737 void dispatchTouches(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 738 void dispatchHoverExit(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 739 void dispatchHoverEnterAndMove(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 740 void dispatchButtonRelease(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 741 void dispatchButtonPress(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 742 const BitSet32& findActiveIdBits(const CookedPointerData& cookedPointerData); 743 void cookPointerData(); 744 void abortTouches(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 745 746 void dispatchPointerUsage(nsecs_t when, nsecs_t readTime, uint32_t policyFlags, 747 PointerUsage pointerUsage); 748 void abortPointerUsage(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 749 750 void dispatchPointerGestures(nsecs_t when, nsecs_t readTime, uint32_t policyFlags, 751 bool isTimeout); 752 void abortPointerGestures(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 753 bool preparePointerGestures(nsecs_t when, bool* outCancelPreviousGesture, 754 bool* outFinishPreviousGesture, bool isTimeout); 755 756 void dispatchPointerStylus(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 757 void abortPointerStylus(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 758 759 void dispatchPointerMouse(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 760 void abortPointerMouse(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 761 762 void dispatchPointerSimple(nsecs_t when, nsecs_t readTime, uint32_t policyFlags, bool down, 763 bool hovering); 764 void abortPointerSimple(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); 765 766 bool assignExternalStylusId(const RawState& state, bool timeout); 767 void applyExternalStylusButtonState(nsecs_t when); 768 void applyExternalStylusTouchState(nsecs_t when); 769 770 // Dispatches a motion event. 771 // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the 772 // method will take care of setting the index and transmuting the action to DOWN or UP 773 // it is the first / last pointer to go down / up. 774 void dispatchMotion(nsecs_t when, nsecs_t readTime, uint32_t policyFlags, uint32_t source, 775 int32_t action, int32_t actionButton, int32_t flags, int32_t metaState, 776 int32_t buttonState, int32_t edgeFlags, const PointerProperties* properties, 777 const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits, 778 int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime); 779 780 // Updates pointer coords and properties for pointers with specified ids that have moved. 781 // Returns true if any of them changed. 782 bool updateMovedPointers(const PointerProperties* inProperties, const PointerCoords* inCoords, 783 const uint32_t* inIdToIndex, PointerProperties* outProperties, 784 PointerCoords* outCoords, const uint32_t* outIdToIndex, 785 BitSet32 idBits) const; 786 787 // Returns if this touch device is a touch screen with an associated display. 788 bool isTouchScreen(); 789 // Updates touch spots if they are enabled. Should only be used when this device is a 790 // touchscreen. 791 void updateTouchSpots(); 792 793 bool isPointInsideSurface(int32_t x, int32_t y); 794 const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y); 795 796 static void assignPointerIds(const RawState& last, RawState& current); 797 798 const char* modeToString(DeviceMode deviceMode); 799 void rotateAndScale(float& x, float& y); 800 801 // Wrapper methods for interfacing with PointerController. These are used to convert points 802 // between the coordinate spaces used by InputReader and PointerController, if they differ. 803 void moveMouseCursor(float dx, float dy) const; 804 std::pair<float, float> getMouseCursorPosition() const; 805 void setMouseCursorPosition(float x, float y) const; 806 void setTouchSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, 807 BitSet32 spotIdBits, int32_t displayId); 808 }; 809 810 } // namespace android 811 812 #endif // _UI_INPUTREADER_TOUCH_INPUT_MAPPER_H