InputReader.h revision cb5ffcf0e41d2597401208221c61589547a00f3d
1/* 2 * Copyright (C) 2010 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_INPUT_READER_H 18#define _UI_INPUT_READER_H 19 20#include "EventHub.h" 21#include "InputDispatcher.h" 22#include "PointerController.h" 23 24#include <ui/Input.h> 25#include <ui/DisplayInfo.h> 26#include <utils/KeyedVector.h> 27#include <utils/threads.h> 28#include <utils/Timers.h> 29#include <utils/RefBase.h> 30#include <utils/String8.h> 31#include <utils/BitSet.h> 32 33#include <stddef.h> 34#include <unistd.h> 35 36namespace android { 37 38class InputDevice; 39class InputMapper; 40 41 42/* 43 * Input reader configuration. 44 * 45 * Specifies various options that modify the behavior of the input reader. 46 */ 47struct InputReaderConfiguration { 48 // Determines whether to turn on some hacks we have to improve the touch interaction with a 49 // certain device whose screen currently is not all that good. 50 bool filterTouchEvents; 51 52 // Determines whether to turn on some hacks to improve touch interaction with another device 53 // where touch coordinate data can get corrupted. 54 bool filterJumpyTouchEvents; 55 56 // Gets the amount of time to disable virtual keys after the screen is touched 57 // in order to filter out accidental virtual key presses due to swiping gestures 58 // or taps near the edge of the display. May be 0 to disable the feature. 59 nsecs_t virtualKeyQuietTime; 60 61 // The excluded device names for the platform. 62 // Devices with these names will be ignored. 63 Vector<String8> excludedDeviceNames; 64 65 // Velocity control parameters for mouse pointer movements. 66 VelocityControlParameters pointerVelocityControlParameters; 67 68 // Velocity control parameters for mouse wheel movements. 69 VelocityControlParameters wheelVelocityControlParameters; 70 71 // Quiet time between certain pointer gesture transitions. 72 // Time to allow for all fingers or buttons to settle into a stable state before 73 // starting a new gesture. 74 nsecs_t pointerGestureQuietInterval; 75 76 // The minimum speed that a pointer must travel for us to consider switching the active 77 // touch pointer to it during a drag. This threshold is set to avoid switching due 78 // to noise from a finger resting on the touch pad (perhaps just pressing it down). 79 float pointerGestureDragMinSwitchSpeed; // in pixels per second 80 81 // Tap gesture delay time. 82 // The time between down and up must be less than this to be considered a tap. 83 nsecs_t pointerGestureTapInterval; 84 85 // Tap drag gesture delay time. 86 // The time between the previous tap's up and the next down must be less than 87 // this to be considered a drag. Otherwise, the previous tap is finished and a 88 // new tap begins. 89 // 90 // Note that the previous tap will be held down for this entire duration so this 91 // interval must be shorter than the long press timeout. 92 nsecs_t pointerGestureTapDragInterval; 93 94 // The distance in pixels that the pointer is allowed to move from initial down 95 // to up and still be called a tap. 96 float pointerGestureTapSlop; // in pixels 97 98 // Time after the first touch points go down to settle on an initial centroid. 99 // This is intended to be enough time to handle cases where the user puts down two 100 // fingers at almost but not quite exactly the same time. 101 nsecs_t pointerGestureMultitouchSettleInterval; 102 103 // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when 104 // at least two pointers have moved at least this far from their starting place. 105 float pointerGestureMultitouchMinDistance; // in pixels 106 107 // The transition from PRESS to SWIPE gesture mode can only occur when the 108 // cosine of the angle between the two vectors is greater than or equal to than this value 109 // which indicates that the vectors are oriented in the same direction. 110 // When the vectors are oriented in the exactly same direction, the cosine is 1.0. 111 // (In exactly opposite directions, the cosine is -1.0.) 112 float pointerGestureSwipeTransitionAngleCosine; 113 114 // The transition from PRESS to SWIPE gesture mode can only occur when the 115 // fingers are no more than this far apart relative to the diagonal size of 116 // the touch pad. For example, a ratio of 0.5 means that the fingers must be 117 // no more than half the diagonal size of the touch pad apart. 118 float pointerGestureSwipeMaxWidthRatio; 119 120 // The gesture movement speed factor relative to the size of the display. 121 // Movement speed applies when the fingers are moving in the same direction. 122 // Without acceleration, a full swipe of the touch pad diagonal in movement mode 123 // will cover this portion of the display diagonal. 124 float pointerGestureMovementSpeedRatio; 125 126 // The gesture zoom speed factor relative to the size of the display. 127 // Zoom speed applies when the fingers are mostly moving relative to each other 128 // to execute a scale gesture or similar. 129 // Without acceleration, a full swipe of the touch pad diagonal in zoom mode 130 // will cover this portion of the display diagonal. 131 float pointerGestureZoomSpeedRatio; 132 133 InputReaderConfiguration() : 134 filterTouchEvents(false), 135 filterJumpyTouchEvents(false), 136 virtualKeyQuietTime(0), 137 pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f), 138 wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f), 139 pointerGestureQuietInterval(100 * 1000000LL), // 100 ms 140 pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second 141 pointerGestureTapInterval(150 * 1000000LL), // 150 ms 142 pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms 143 pointerGestureTapSlop(10.0f), // 10 pixels 144 pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms 145 pointerGestureMultitouchMinDistance(15), // 15 pixels 146 pointerGestureSwipeTransitionAngleCosine(0.5f), // cosine of 45degrees 147 pointerGestureSwipeMaxWidthRatio(0.25f), 148 pointerGestureMovementSpeedRatio(0.8f), 149 pointerGestureZoomSpeedRatio(0.3f) { } 150}; 151 152 153/* 154 * Input reader policy interface. 155 * 156 * The input reader policy is used by the input reader to interact with the Window Manager 157 * and other system components. 158 * 159 * The actual implementation is partially supported by callbacks into the DVM 160 * via JNI. This interface is also mocked in the unit tests. 161 */ 162class InputReaderPolicyInterface : public virtual RefBase { 163protected: 164 InputReaderPolicyInterface() { } 165 virtual ~InputReaderPolicyInterface() { } 166 167public: 168 /* Display orientations. */ 169 enum { 170 ROTATION_0 = 0, 171 ROTATION_90 = 1, 172 ROTATION_180 = 2, 173 ROTATION_270 = 3 174 }; 175 176 /* Gets information about the display with the specified id. 177 * Returns true if the display info is available, false otherwise. 178 */ 179 virtual bool getDisplayInfo(int32_t displayId, 180 int32_t* width, int32_t* height, int32_t* orientation) = 0; 181 182 /* Gets the input reader configuration. */ 183 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0; 184 185 /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */ 186 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0; 187}; 188 189 190/* Processes raw input events and sends cooked event data to an input dispatcher. */ 191class InputReaderInterface : public virtual RefBase { 192protected: 193 InputReaderInterface() { } 194 virtual ~InputReaderInterface() { } 195 196public: 197 /* Dumps the state of the input reader. 198 * 199 * This method may be called on any thread (usually by the input manager). */ 200 virtual void dump(String8& dump) = 0; 201 202 /* Runs a single iteration of the processing loop. 203 * Nominally reads and processes one incoming message from the EventHub. 204 * 205 * This method should be called on the input reader thread. 206 */ 207 virtual void loopOnce() = 0; 208 209 /* Gets the current input device configuration. 210 * 211 * This method may be called on any thread (usually by the input manager). 212 */ 213 virtual void getInputConfiguration(InputConfiguration* outConfiguration) = 0; 214 215 /* Gets information about the specified input device. 216 * Returns OK if the device information was obtained or NAME_NOT_FOUND if there 217 * was no such device. 218 * 219 * This method may be called on any thread (usually by the input manager). 220 */ 221 virtual status_t getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo) = 0; 222 223 /* Gets the list of all registered device ids. */ 224 virtual void getInputDeviceIds(Vector<int32_t>& outDeviceIds) = 0; 225 226 /* Query current input state. */ 227 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, 228 int32_t scanCode) = 0; 229 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, 230 int32_t keyCode) = 0; 231 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, 232 int32_t sw) = 0; 233 234 /* Determine whether physical keys exist for the given framework-domain key codes. */ 235 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, 236 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0; 237 238 /* Reopens and reconfigures all input devices. */ 239 virtual void refreshConfiguration() = 0; 240}; 241 242 243/* Internal interface used by individual input devices to access global input device state 244 * and parameters maintained by the input reader. 245 */ 246class InputReaderContext { 247public: 248 InputReaderContext() { } 249 virtual ~InputReaderContext() { } 250 251 virtual void updateGlobalMetaState() = 0; 252 virtual int32_t getGlobalMetaState() = 0; 253 254 virtual void disableVirtualKeysUntil(nsecs_t time) = 0; 255 virtual bool shouldDropVirtualKey(nsecs_t now, 256 InputDevice* device, int32_t keyCode, int32_t scanCode) = 0; 257 258 virtual void fadePointer() = 0; 259 260 virtual void requestTimeoutAtTime(nsecs_t when) = 0; 261 262 virtual InputReaderPolicyInterface* getPolicy() = 0; 263 virtual const InputReaderConfiguration* getConfig() = 0; 264 virtual InputDispatcherInterface* getDispatcher() = 0; 265 virtual EventHubInterface* getEventHub() = 0; 266}; 267 268 269/* The input reader reads raw event data from the event hub and processes it into input events 270 * that it sends to the input dispatcher. Some functions of the input reader, such as early 271 * event filtering in low power states, are controlled by a separate policy object. 272 * 273 * IMPORTANT INVARIANT: 274 * Because the policy and dispatcher can potentially block or cause re-entrance into 275 * the input reader, the input reader never calls into other components while holding 276 * an exclusive internal lock whenever re-entrance can happen. 277 */ 278class InputReader : public InputReaderInterface, protected InputReaderContext { 279public: 280 InputReader(const sp<EventHubInterface>& eventHub, 281 const sp<InputReaderPolicyInterface>& policy, 282 const sp<InputDispatcherInterface>& dispatcher); 283 virtual ~InputReader(); 284 285 virtual void dump(String8& dump); 286 287 virtual void loopOnce(); 288 289 virtual void getInputConfiguration(InputConfiguration* outConfiguration); 290 291 virtual status_t getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo); 292 virtual void getInputDeviceIds(Vector<int32_t>& outDeviceIds); 293 294 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, 295 int32_t scanCode); 296 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, 297 int32_t keyCode); 298 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, 299 int32_t sw); 300 301 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, 302 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags); 303 304 virtual void refreshConfiguration(); 305 306protected: 307 // These methods are protected virtual so they can be overridden and instrumented 308 // by test cases. 309 virtual InputDevice* createDevice(int32_t deviceId, const String8& name, uint32_t classes); 310 311private: 312 sp<EventHubInterface> mEventHub; 313 sp<InputReaderPolicyInterface> mPolicy; 314 sp<InputDispatcherInterface> mDispatcher; 315 316 InputReaderConfiguration mConfig; 317 318 virtual InputReaderPolicyInterface* getPolicy() { return mPolicy.get(); } 319 virtual const InputReaderConfiguration* getConfig() { return &mConfig; } 320 virtual InputDispatcherInterface* getDispatcher() { return mDispatcher.get(); } 321 virtual EventHubInterface* getEventHub() { return mEventHub.get(); } 322 323 // The event queue. 324 static const int EVENT_BUFFER_SIZE = 256; 325 RawEvent mEventBuffer[EVENT_BUFFER_SIZE]; 326 327 // This reader/writer lock guards the list of input devices. 328 // The writer lock must be held whenever the list of input devices is modified 329 // and then promptly released. 330 // The reader lock must be held whenever the list of input devices is traversed or an 331 // input device in the list is accessed. 332 // This lock only protects the registry and prevents inadvertent deletion of device objects 333 // that are in use. Individual devices are responsible for guarding their own internal state 334 // as needed for concurrent operation. 335 RWLock mDeviceRegistryLock; 336 KeyedVector<int32_t, InputDevice*> mDevices; 337 338 // low-level input event decoding and device management 339 void processEvents(const RawEvent* rawEvents, size_t count); 340 341 void addDevice(int32_t deviceId); 342 void removeDevice(int32_t deviceId); 343 void processEventsForDevice(int32_t deviceId, const RawEvent* rawEvents, size_t count); 344 void timeoutExpired(nsecs_t when); 345 346 void handleConfigurationChanged(nsecs_t when); 347 348 // state management for all devices 349 Mutex mStateLock; 350 351 int32_t mGlobalMetaState; // guarded by mStateLock 352 virtual void updateGlobalMetaState(); 353 virtual int32_t getGlobalMetaState(); 354 355 virtual void fadePointer(); 356 357 InputConfiguration mInputConfiguration; // guarded by mStateLock 358 void updateInputConfiguration(); 359 360 nsecs_t mDisableVirtualKeysTimeout; // only accessed by reader thread 361 virtual void disableVirtualKeysUntil(nsecs_t time); 362 virtual bool shouldDropVirtualKey(nsecs_t now, 363 InputDevice* device, int32_t keyCode, int32_t scanCode); 364 365 nsecs_t mNextTimeout; // only accessed by reader thread, not guarded 366 virtual void requestTimeoutAtTime(nsecs_t when); 367 368 volatile int32_t mRefreshConfiguration; // atomic 369 void configure(bool firstTime); 370 371 // state queries 372 typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code); 373 int32_t getState(int32_t deviceId, uint32_t sourceMask, int32_t code, 374 GetStateFunc getStateFunc); 375 bool markSupportedKeyCodes(int32_t deviceId, uint32_t sourceMask, size_t numCodes, 376 const int32_t* keyCodes, uint8_t* outFlags); 377}; 378 379 380/* Reads raw events from the event hub and processes them, endlessly. */ 381class InputReaderThread : public Thread { 382public: 383 InputReaderThread(const sp<InputReaderInterface>& reader); 384 virtual ~InputReaderThread(); 385 386private: 387 sp<InputReaderInterface> mReader; 388 389 virtual bool threadLoop(); 390}; 391 392 393/* Represents the state of a single input device. */ 394class InputDevice { 395public: 396 InputDevice(InputReaderContext* context, int32_t id, const String8& name); 397 ~InputDevice(); 398 399 inline InputReaderContext* getContext() { return mContext; } 400 inline int32_t getId() { return mId; } 401 inline const String8& getName() { return mName; } 402 inline uint32_t getSources() { return mSources; } 403 404 inline bool isExternal() { return mIsExternal; } 405 inline void setExternal(bool external) { mIsExternal = external; } 406 407 inline bool isIgnored() { return mMappers.isEmpty(); } 408 409 void dump(String8& dump); 410 void addMapper(InputMapper* mapper); 411 void configure(); 412 void reset(); 413 void process(const RawEvent* rawEvents, size_t count); 414 void timeoutExpired(nsecs_t when); 415 416 void getDeviceInfo(InputDeviceInfo* outDeviceInfo); 417 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); 418 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); 419 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); 420 bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, 421 const int32_t* keyCodes, uint8_t* outFlags); 422 423 int32_t getMetaState(); 424 425 void fadePointer(); 426 427 inline const PropertyMap& getConfiguration() { 428 return mConfiguration; 429 } 430 431private: 432 InputReaderContext* mContext; 433 int32_t mId; 434 435 Vector<InputMapper*> mMappers; 436 437 String8 mName; 438 uint32_t mSources; 439 bool mIsExternal; 440 441 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code); 442 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc); 443 444 PropertyMap mConfiguration; 445}; 446 447 448/* An input mapper transforms raw input events into cooked event data. 449 * A single input device can have multiple associated input mappers in order to interpret 450 * different classes of events. 451 */ 452class InputMapper { 453public: 454 InputMapper(InputDevice* device); 455 virtual ~InputMapper(); 456 457 inline InputDevice* getDevice() { return mDevice; } 458 inline int32_t getDeviceId() { return mDevice->getId(); } 459 inline const String8 getDeviceName() { return mDevice->getName(); } 460 inline InputReaderContext* getContext() { return mContext; } 461 inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); } 462 inline const InputReaderConfiguration* getConfig() { return mContext->getConfig(); } 463 inline InputDispatcherInterface* getDispatcher() { return mContext->getDispatcher(); } 464 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); } 465 466 virtual uint32_t getSources() = 0; 467 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); 468 virtual void dump(String8& dump); 469 virtual void configure(); 470 virtual void reset(); 471 virtual void process(const RawEvent* rawEvent) = 0; 472 virtual void timeoutExpired(nsecs_t when); 473 474 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); 475 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); 476 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); 477 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, 478 const int32_t* keyCodes, uint8_t* outFlags); 479 480 virtual int32_t getMetaState(); 481 482 virtual void fadePointer(); 483 484protected: 485 InputDevice* mDevice; 486 InputReaderContext* mContext; 487 488 static void dumpRawAbsoluteAxisInfo(String8& dump, 489 const RawAbsoluteAxisInfo& axis, const char* name); 490}; 491 492 493class SwitchInputMapper : public InputMapper { 494public: 495 SwitchInputMapper(InputDevice* device); 496 virtual ~SwitchInputMapper(); 497 498 virtual uint32_t getSources(); 499 virtual void process(const RawEvent* rawEvent); 500 501 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); 502 503private: 504 void processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue); 505}; 506 507 508class KeyboardInputMapper : public InputMapper { 509public: 510 KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType); 511 virtual ~KeyboardInputMapper(); 512 513 virtual uint32_t getSources(); 514 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); 515 virtual void dump(String8& dump); 516 virtual void configure(); 517 virtual void reset(); 518 virtual void process(const RawEvent* rawEvent); 519 520 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); 521 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); 522 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, 523 const int32_t* keyCodes, uint8_t* outFlags); 524 525 virtual int32_t getMetaState(); 526 527private: 528 Mutex mLock; 529 530 struct KeyDown { 531 int32_t keyCode; 532 int32_t scanCode; 533 }; 534 535 uint32_t mSource; 536 int32_t mKeyboardType; 537 538 // Immutable configuration parameters. 539 struct Parameters { 540 int32_t associatedDisplayId; 541 bool orientationAware; 542 } mParameters; 543 544 struct LockedState { 545 Vector<KeyDown> keyDowns; // keys that are down 546 int32_t metaState; 547 nsecs_t downTime; // time of most recent key down 548 549 struct LedState { 550 bool avail; // led is available 551 bool on; // we think the led is currently on 552 }; 553 LedState capsLockLedState; 554 LedState numLockLedState; 555 LedState scrollLockLedState; 556 } mLocked; 557 558 void initializeLocked(); 559 560 void configureParameters(); 561 void dumpParameters(String8& dump); 562 563 bool isKeyboardOrGamepadKey(int32_t scanCode); 564 565 void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode, 566 uint32_t policyFlags); 567 568 ssize_t findKeyDownLocked(int32_t scanCode); 569 570 void resetLedStateLocked(); 571 void initializeLedStateLocked(LockedState::LedState& ledState, int32_t led); 572 void updateLedStateLocked(bool reset); 573 void updateLedStateForModifierLocked(LockedState::LedState& ledState, int32_t led, 574 int32_t modifier, bool reset); 575}; 576 577 578class CursorInputMapper : public InputMapper { 579public: 580 CursorInputMapper(InputDevice* device); 581 virtual ~CursorInputMapper(); 582 583 virtual uint32_t getSources(); 584 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); 585 virtual void dump(String8& dump); 586 virtual void configure(); 587 virtual void reset(); 588 virtual void process(const RawEvent* rawEvent); 589 590 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); 591 592 virtual void fadePointer(); 593 594private: 595 // Amount that trackball needs to move in order to generate a key event. 596 static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6; 597 598 Mutex mLock; 599 600 // Immutable configuration parameters. 601 struct Parameters { 602 enum Mode { 603 MODE_POINTER, 604 MODE_NAVIGATION, 605 }; 606 607 Mode mode; 608 int32_t associatedDisplayId; 609 bool orientationAware; 610 } mParameters; 611 612 struct Accumulator { 613 enum { 614 FIELD_BUTTONS = 1, 615 FIELD_REL_X = 2, 616 FIELD_REL_Y = 4, 617 FIELD_REL_WHEEL = 8, 618 FIELD_REL_HWHEEL = 16, 619 }; 620 621 uint32_t fields; 622 623 uint32_t buttonDown; 624 uint32_t buttonUp; 625 626 int32_t relX; 627 int32_t relY; 628 int32_t relWheel; 629 int32_t relHWheel; 630 631 inline void clear() { 632 fields = 0; 633 } 634 } mAccumulator; 635 636 int32_t mSource; 637 float mXScale; 638 float mYScale; 639 float mXPrecision; 640 float mYPrecision; 641 642 bool mHaveVWheel; 643 bool mHaveHWheel; 644 float mVWheelScale; 645 float mHWheelScale; 646 647 // Velocity controls for mouse pointer and wheel movements. 648 // The controls for X and Y wheel movements are separate to keep them decoupled. 649 VelocityControl mPointerVelocityControl; 650 VelocityControl mWheelXVelocityControl; 651 VelocityControl mWheelYVelocityControl; 652 653 sp<PointerControllerInterface> mPointerController; 654 655 struct LockedState { 656 uint32_t buttonState; 657 nsecs_t downTime; 658 } mLocked; 659 660 void initializeLocked(); 661 662 void configureParameters(); 663 void dumpParameters(String8& dump); 664 665 void sync(nsecs_t when); 666}; 667 668 669class TouchInputMapper : public InputMapper { 670public: 671 TouchInputMapper(InputDevice* device); 672 virtual ~TouchInputMapper(); 673 674 virtual uint32_t getSources(); 675 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); 676 virtual void dump(String8& dump); 677 virtual void configure(); 678 virtual void reset(); 679 680 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); 681 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); 682 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, 683 const int32_t* keyCodes, uint8_t* outFlags); 684 685 virtual void fadePointer(); 686 virtual void timeoutExpired(nsecs_t when); 687 688protected: 689 Mutex mLock; 690 691 struct VirtualKey { 692 int32_t keyCode; 693 int32_t scanCode; 694 uint32_t flags; 695 696 // computed hit box, specified in touch screen coords based on known display size 697 int32_t hitLeft; 698 int32_t hitTop; 699 int32_t hitRight; 700 int32_t hitBottom; 701 702 inline bool isHit(int32_t x, int32_t y) const { 703 return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom; 704 } 705 }; 706 707 // Raw data for a single pointer. 708 struct PointerData { 709 uint32_t id; 710 int32_t x; 711 int32_t y; 712 int32_t pressure; 713 int32_t touchMajor; 714 int32_t touchMinor; 715 int32_t toolMajor; 716 int32_t toolMinor; 717 int32_t orientation; 718 719 inline bool operator== (const PointerData& other) const { 720 return id == other.id 721 && x == other.x 722 && y == other.y 723 && pressure == other.pressure 724 && touchMajor == other.touchMajor 725 && touchMinor == other.touchMinor 726 && toolMajor == other.toolMajor 727 && toolMinor == other.toolMinor 728 && orientation == other.orientation; 729 } 730 inline bool operator!= (const PointerData& other) const { 731 return !(*this == other); 732 } 733 }; 734 735 // Raw data for a collection of pointers including a pointer id mapping table. 736 struct TouchData { 737 uint32_t pointerCount; 738 PointerData pointers[MAX_POINTERS]; 739 BitSet32 idBits; 740 uint32_t idToIndex[MAX_POINTER_ID + 1]; 741 uint32_t buttonState; 742 743 void copyFrom(const TouchData& other) { 744 pointerCount = other.pointerCount; 745 idBits = other.idBits; 746 buttonState = other.buttonState; 747 748 for (uint32_t i = 0; i < pointerCount; i++) { 749 pointers[i] = other.pointers[i]; 750 751 int id = pointers[i].id; 752 idToIndex[id] = other.idToIndex[id]; 753 } 754 } 755 756 inline void clear() { 757 pointerCount = 0; 758 idBits.clear(); 759 buttonState = 0; 760 } 761 762 void getCentroid(float* outX, float* outY) { 763 float x = 0, y = 0; 764 if (pointerCount != 0) { 765 for (uint32_t i = 0; i < pointerCount; i++) { 766 x += pointers[i].x; 767 y += pointers[i].y; 768 } 769 x /= pointerCount; 770 y /= pointerCount; 771 } 772 *outX = x; 773 *outY = y; 774 } 775 }; 776 777 // Input sources supported by the device. 778 uint32_t mTouchSource; // sources when reporting touch data 779 uint32_t mPointerSource; // sources when reporting pointer gestures 780 781 // The reader's configuration. 782 const InputReaderConfiguration* mConfig; 783 784 // Immutable configuration parameters. 785 struct Parameters { 786 enum DeviceType { 787 DEVICE_TYPE_TOUCH_SCREEN, 788 DEVICE_TYPE_TOUCH_PAD, 789 DEVICE_TYPE_POINTER, 790 }; 791 792 DeviceType deviceType; 793 int32_t associatedDisplayId; 794 bool orientationAware; 795 796 bool useBadTouchFilter; 797 bool useJumpyTouchFilter; 798 bool useAveragingTouchFilter; 799 800 enum GestureMode { 801 GESTURE_MODE_POINTER, 802 GESTURE_MODE_SPOTS, 803 }; 804 GestureMode gestureMode; 805 } mParameters; 806 807 // Immutable calibration parameters in parsed form. 808 struct Calibration { 809 // Touch Size 810 enum TouchSizeCalibration { 811 TOUCH_SIZE_CALIBRATION_DEFAULT, 812 TOUCH_SIZE_CALIBRATION_NONE, 813 TOUCH_SIZE_CALIBRATION_GEOMETRIC, 814 TOUCH_SIZE_CALIBRATION_PRESSURE, 815 }; 816 817 TouchSizeCalibration touchSizeCalibration; 818 819 // Tool Size 820 enum ToolSizeCalibration { 821 TOOL_SIZE_CALIBRATION_DEFAULT, 822 TOOL_SIZE_CALIBRATION_NONE, 823 TOOL_SIZE_CALIBRATION_GEOMETRIC, 824 TOOL_SIZE_CALIBRATION_LINEAR, 825 TOOL_SIZE_CALIBRATION_AREA, 826 }; 827 828 ToolSizeCalibration toolSizeCalibration; 829 bool haveToolSizeLinearScale; 830 float toolSizeLinearScale; 831 bool haveToolSizeLinearBias; 832 float toolSizeLinearBias; 833 bool haveToolSizeAreaScale; 834 float toolSizeAreaScale; 835 bool haveToolSizeAreaBias; 836 float toolSizeAreaBias; 837 bool haveToolSizeIsSummed; 838 bool toolSizeIsSummed; 839 840 // Pressure 841 enum PressureCalibration { 842 PRESSURE_CALIBRATION_DEFAULT, 843 PRESSURE_CALIBRATION_NONE, 844 PRESSURE_CALIBRATION_PHYSICAL, 845 PRESSURE_CALIBRATION_AMPLITUDE, 846 }; 847 enum PressureSource { 848 PRESSURE_SOURCE_DEFAULT, 849 PRESSURE_SOURCE_PRESSURE, 850 PRESSURE_SOURCE_TOUCH, 851 }; 852 853 PressureCalibration pressureCalibration; 854 PressureSource pressureSource; 855 bool havePressureScale; 856 float pressureScale; 857 858 // Size 859 enum SizeCalibration { 860 SIZE_CALIBRATION_DEFAULT, 861 SIZE_CALIBRATION_NONE, 862 SIZE_CALIBRATION_NORMALIZED, 863 }; 864 865 SizeCalibration sizeCalibration; 866 867 // Orientation 868 enum OrientationCalibration { 869 ORIENTATION_CALIBRATION_DEFAULT, 870 ORIENTATION_CALIBRATION_NONE, 871 ORIENTATION_CALIBRATION_INTERPOLATED, 872 ORIENTATION_CALIBRATION_VECTOR, 873 }; 874 875 OrientationCalibration orientationCalibration; 876 } mCalibration; 877 878 // Raw axis information from the driver. 879 struct RawAxes { 880 RawAbsoluteAxisInfo x; 881 RawAbsoluteAxisInfo y; 882 RawAbsoluteAxisInfo pressure; 883 RawAbsoluteAxisInfo touchMajor; 884 RawAbsoluteAxisInfo touchMinor; 885 RawAbsoluteAxisInfo toolMajor; 886 RawAbsoluteAxisInfo toolMinor; 887 RawAbsoluteAxisInfo orientation; 888 } mRawAxes; 889 890 // Current and previous touch sample data. 891 TouchData mCurrentTouch; 892 PointerCoords mCurrentTouchCoords[MAX_POINTERS]; 893 894 TouchData mLastTouch; 895 PointerCoords mLastTouchCoords[MAX_POINTERS]; 896 897 // The time the primary pointer last went down. 898 nsecs_t mDownTime; 899 900 // The pointer controller, or null if the device is not a pointer. 901 sp<PointerControllerInterface> mPointerController; 902 903 struct LockedState { 904 Vector<VirtualKey> virtualKeys; 905 906 // The surface orientation and width and height set by configureSurfaceLocked(). 907 int32_t surfaceOrientation; 908 int32_t surfaceWidth, surfaceHeight; 909 910 // The associated display orientation and width and height set by configureSurfaceLocked(). 911 int32_t associatedDisplayOrientation; 912 int32_t associatedDisplayWidth, associatedDisplayHeight; 913 914 // Translation and scaling factors, orientation-independent. 915 float xScale; 916 float xPrecision; 917 918 float yScale; 919 float yPrecision; 920 921 float geometricScale; 922 923 float toolSizeLinearScale; 924 float toolSizeLinearBias; 925 float toolSizeAreaScale; 926 float toolSizeAreaBias; 927 928 float pressureScale; 929 930 float sizeScale; 931 932 float orientationScale; 933 934 // Oriented motion ranges for input device info. 935 struct OrientedRanges { 936 InputDeviceInfo::MotionRange x; 937 InputDeviceInfo::MotionRange y; 938 939 bool havePressure; 940 InputDeviceInfo::MotionRange pressure; 941 942 bool haveSize; 943 InputDeviceInfo::MotionRange size; 944 945 bool haveTouchSize; 946 InputDeviceInfo::MotionRange touchMajor; 947 InputDeviceInfo::MotionRange touchMinor; 948 949 bool haveToolSize; 950 InputDeviceInfo::MotionRange toolMajor; 951 InputDeviceInfo::MotionRange toolMinor; 952 953 bool haveOrientation; 954 InputDeviceInfo::MotionRange orientation; 955 } orientedRanges; 956 957 // Oriented dimensions and precision. 958 float orientedSurfaceWidth, orientedSurfaceHeight; 959 float orientedXPrecision, orientedYPrecision; 960 961 struct CurrentVirtualKeyState { 962 bool down; 963 nsecs_t downTime; 964 int32_t keyCode; 965 int32_t scanCode; 966 } currentVirtualKey; 967 968 // Scale factor for gesture based pointer movements. 969 float pointerGestureXMovementScale; 970 float pointerGestureYMovementScale; 971 972 // Scale factor for gesture based zooming and other freeform motions. 973 float pointerGestureXZoomScale; 974 float pointerGestureYZoomScale; 975 976 // The maximum swipe width. 977 float pointerGestureMaxSwipeWidth; 978 } mLocked; 979 980 virtual void configureParameters(); 981 virtual void dumpParameters(String8& dump); 982 virtual void configureRawAxes(); 983 virtual void dumpRawAxes(String8& dump); 984 virtual bool configureSurfaceLocked(); 985 virtual void dumpSurfaceLocked(String8& dump); 986 virtual void configureVirtualKeysLocked(); 987 virtual void dumpVirtualKeysLocked(String8& dump); 988 virtual void parseCalibration(); 989 virtual void resolveCalibration(); 990 virtual void dumpCalibration(String8& dump); 991 992 enum TouchResult { 993 // Dispatch the touch normally. 994 DISPATCH_TOUCH, 995 // Do not dispatch the touch, but keep tracking the current stroke. 996 SKIP_TOUCH, 997 // Do not dispatch the touch, and drop all information associated with the current stoke 998 // so the next movement will appear as a new down. 999 DROP_STROKE 1000 }; 1001 1002 void syncTouch(nsecs_t when, bool havePointerIds); 1003 1004private: 1005 /* Maximum number of historical samples to average. */ 1006 static const uint32_t AVERAGING_HISTORY_SIZE = 5; 1007 1008 /* Slop distance for jumpy pointer detection. 1009 * The vertical range of the screen divided by this is our epsilon value. */ 1010 static const uint32_t JUMPY_EPSILON_DIVISOR = 212; 1011 1012 /* Number of jumpy points to drop for touchscreens that need it. */ 1013 static const uint32_t JUMPY_TRANSITION_DROPS = 3; 1014 static const uint32_t JUMPY_DROP_LIMIT = 3; 1015 1016 /* Maximum squared distance for averaging. 1017 * If moving farther than this, turn of averaging to avoid lag in response. */ 1018 static const uint64_t AVERAGING_DISTANCE_LIMIT = 75 * 75; 1019 1020 struct AveragingTouchFilterState { 1021 // Individual history tracks are stored by pointer id 1022 uint32_t historyStart[MAX_POINTERS]; 1023 uint32_t historyEnd[MAX_POINTERS]; 1024 struct { 1025 struct { 1026 int32_t x; 1027 int32_t y; 1028 int32_t pressure; 1029 } pointers[MAX_POINTERS]; 1030 } historyData[AVERAGING_HISTORY_SIZE]; 1031 } mAveragingTouchFilter; 1032 1033 struct JumpyTouchFilterState { 1034 uint32_t jumpyPointsDropped; 1035 } mJumpyTouchFilter; 1036 1037 struct PointerDistanceHeapElement { 1038 uint32_t currentPointerIndex : 8; 1039 uint32_t lastPointerIndex : 8; 1040 uint64_t distance : 48; // squared distance 1041 }; 1042 1043 struct PointerGesture { 1044 enum Mode { 1045 // No fingers, button is not pressed. 1046 // Nothing happening. 1047 NEUTRAL, 1048 1049 // No fingers, button is not pressed. 1050 // Tap detected. 1051 // Emits DOWN and UP events at the pointer location. 1052 TAP, 1053 1054 // Exactly one finger dragging following a tap. 1055 // Pointer follows the active finger. 1056 // Emits DOWN, MOVE and UP events at the pointer location. 1057 // 1058 // Detect double-taps when the finger goes up while in TAP_DRAG mode. 1059 TAP_DRAG, 1060 1061 // Button is pressed. 1062 // Pointer follows the active finger if there is one. Other fingers are ignored. 1063 // Emits DOWN, MOVE and UP events at the pointer location. 1064 BUTTON_CLICK_OR_DRAG, 1065 1066 // Exactly one finger, button is not pressed. 1067 // Pointer follows the active finger. 1068 // Emits HOVER_MOVE events at the pointer location. 1069 // 1070 // Detect taps when the finger goes up while in HOVER mode. 1071 HOVER, 1072 1073 // Exactly two fingers but neither have moved enough to clearly indicate 1074 // whether a swipe or freeform gesture was intended. We consider the 1075 // pointer to be pressed so this enables clicking or long-pressing on buttons. 1076 // Pointer does not move. 1077 // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate. 1078 PRESS, 1079 1080 // Exactly two fingers moving in the same direction, button is not pressed. 1081 // Pointer does not move. 1082 // Emits DOWN, MOVE and UP events with a single pointer coordinate that 1083 // follows the midpoint between both fingers. 1084 SWIPE, 1085 1086 // Two or more fingers moving in arbitrary directions, button is not pressed. 1087 // Pointer does not move. 1088 // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow 1089 // each finger individually relative to the initial centroid of the finger. 1090 FREEFORM, 1091 1092 // Waiting for quiet time to end before starting the next gesture. 1093 QUIET, 1094 }; 1095 1096 // Time the first finger went down. 1097 nsecs_t firstTouchTime; 1098 1099 // The active pointer id from the raw touch data. 1100 int32_t activeTouchId; // -1 if none 1101 1102 // The active pointer id from the gesture last delivered to the application. 1103 int32_t activeGestureId; // -1 if none 1104 1105 // Pointer coords and ids for the current and previous pointer gesture. 1106 Mode currentGestureMode; 1107 BitSet32 currentGestureIdBits; 1108 uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1]; 1109 PointerCoords currentGestureCoords[MAX_POINTERS]; 1110 1111 Mode lastGestureMode; 1112 BitSet32 lastGestureIdBits; 1113 uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1]; 1114 PointerCoords lastGestureCoords[MAX_POINTERS]; 1115 1116 // Time the pointer gesture last went down. 1117 nsecs_t downTime; 1118 1119 // Time when the pointer went down for a TAP. 1120 nsecs_t tapDownTime; 1121 1122 // Time when the pointer went up for a TAP. 1123 nsecs_t tapUpTime; 1124 1125 // Location of initial tap. 1126 float tapX, tapY; 1127 1128 // Time we started waiting for quiescence. 1129 nsecs_t quietTime; 1130 1131 // Reference points for multitouch gestures. 1132 float referenceTouchX; // reference touch X/Y coordinates in surface units 1133 float referenceTouchY; 1134 float referenceGestureX; // reference gesture X/Y coordinates in pixels 1135 float referenceGestureY; 1136 1137 // Distance that each pointer has traveled which has not yet been 1138 // subsumed into the reference gesture position. 1139 BitSet32 referenceIdBits; 1140 struct Delta { 1141 float dx, dy; 1142 }; 1143 Delta referenceDeltas[MAX_POINTER_ID + 1]; 1144 1145 // Describes how touch ids are mapped to gesture ids for freeform gestures. 1146 uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1]; 1147 1148 // A velocity tracker for determining whether to switch active pointers during drags. 1149 VelocityTracker velocityTracker; 1150 1151 // Velocity control for pointer movements. 1152 VelocityControl pointerVelocityControl; 1153 1154 void reset() { 1155 firstTouchTime = LLONG_MIN; 1156 activeTouchId = -1; 1157 activeGestureId = -1; 1158 currentGestureMode = NEUTRAL; 1159 currentGestureIdBits.clear(); 1160 lastGestureMode = NEUTRAL; 1161 lastGestureIdBits.clear(); 1162 downTime = 0; 1163 velocityTracker.clear(); 1164 resetTap(); 1165 resetQuietTime(); 1166 pointerVelocityControl.reset(); 1167 } 1168 1169 void resetTap() { 1170 tapDownTime = LLONG_MIN; 1171 tapUpTime = LLONG_MIN; 1172 } 1173 1174 void resetQuietTime() { 1175 quietTime = LLONG_MIN; 1176 } 1177 } mPointerGesture; 1178 1179 void initializeLocked(); 1180 1181 TouchResult consumeOffScreenTouches(nsecs_t when, uint32_t policyFlags); 1182 void dispatchTouches(nsecs_t when, uint32_t policyFlags); 1183 void prepareTouches(int32_t* outEdgeFlags, float* outXPrecision, float* outYPrecision); 1184 void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout); 1185 bool preparePointerGestures(nsecs_t when, 1186 bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, bool isTimeout); 1187 1188 // Dispatches a motion event. 1189 // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the 1190 // method will take care of setting the index and transmuting the action to DOWN or UP 1191 // it is the first / last pointer to go down / up. 1192 void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source, 1193 int32_t action, int32_t flags, uint32_t metaState, int32_t edgeFlags, 1194 const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits, 1195 int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime); 1196 1197 // Updates pointer coords for pointers with specified ids that have moved. 1198 // Returns true if any of them changed. 1199 bool updateMovedPointerCoords(const PointerCoords* inCoords, const uint32_t* inIdToIndex, 1200 PointerCoords* outCoords, const uint32_t* outIdToIndex, BitSet32 idBits) const; 1201 1202 void suppressSwipeOntoVirtualKeys(nsecs_t when); 1203 1204 bool isPointInsideSurfaceLocked(int32_t x, int32_t y); 1205 const VirtualKey* findVirtualKeyHitLocked(int32_t x, int32_t y); 1206 1207 bool applyBadTouchFilter(); 1208 bool applyJumpyTouchFilter(); 1209 void applyAveragingTouchFilter(); 1210 void calculatePointerIds(); 1211}; 1212 1213 1214class SingleTouchInputMapper : public TouchInputMapper { 1215public: 1216 SingleTouchInputMapper(InputDevice* device); 1217 virtual ~SingleTouchInputMapper(); 1218 1219 virtual void reset(); 1220 virtual void process(const RawEvent* rawEvent); 1221 1222protected: 1223 virtual void configureRawAxes(); 1224 1225private: 1226 struct Accumulator { 1227 enum { 1228 FIELD_BTN_TOUCH = 1, 1229 FIELD_ABS_X = 2, 1230 FIELD_ABS_Y = 4, 1231 FIELD_ABS_PRESSURE = 8, 1232 FIELD_ABS_TOOL_WIDTH = 16, 1233 FIELD_BUTTONS = 32, 1234 }; 1235 1236 uint32_t fields; 1237 1238 bool btnTouch; 1239 int32_t absX; 1240 int32_t absY; 1241 int32_t absPressure; 1242 int32_t absToolWidth; 1243 1244 uint32_t buttonDown; 1245 uint32_t buttonUp; 1246 1247 inline void clear() { 1248 fields = 0; 1249 buttonDown = 0; 1250 buttonUp = 0; 1251 } 1252 } mAccumulator; 1253 1254 bool mDown; 1255 int32_t mX; 1256 int32_t mY; 1257 int32_t mPressure; 1258 int32_t mToolWidth; 1259 uint32_t mButtonState; 1260 1261 void initialize(); 1262 1263 void sync(nsecs_t when); 1264}; 1265 1266 1267class MultiTouchInputMapper : public TouchInputMapper { 1268public: 1269 MultiTouchInputMapper(InputDevice* device); 1270 virtual ~MultiTouchInputMapper(); 1271 1272 virtual void reset(); 1273 virtual void process(const RawEvent* rawEvent); 1274 1275protected: 1276 virtual void configureRawAxes(); 1277 1278private: 1279 struct Accumulator { 1280 enum { 1281 FIELD_ABS_MT_POSITION_X = 1, 1282 FIELD_ABS_MT_POSITION_Y = 2, 1283 FIELD_ABS_MT_TOUCH_MAJOR = 4, 1284 FIELD_ABS_MT_TOUCH_MINOR = 8, 1285 FIELD_ABS_MT_WIDTH_MAJOR = 16, 1286 FIELD_ABS_MT_WIDTH_MINOR = 32, 1287 FIELD_ABS_MT_ORIENTATION = 64, 1288 FIELD_ABS_MT_TRACKING_ID = 128, 1289 FIELD_ABS_MT_PRESSURE = 256, 1290 }; 1291 1292 uint32_t pointerCount; 1293 struct Pointer { 1294 uint32_t fields; 1295 1296 int32_t absMTPositionX; 1297 int32_t absMTPositionY; 1298 int32_t absMTTouchMajor; 1299 int32_t absMTTouchMinor; 1300 int32_t absMTWidthMajor; 1301 int32_t absMTWidthMinor; 1302 int32_t absMTOrientation; 1303 int32_t absMTTrackingId; 1304 int32_t absMTPressure; 1305 1306 inline void clear() { 1307 fields = 0; 1308 } 1309 } pointers[MAX_POINTERS + 1]; // + 1 to remove the need for extra range checks 1310 1311 // Bitfield of buttons that went down or up. 1312 uint32_t buttonDown; 1313 uint32_t buttonUp; 1314 1315 inline void clear() { 1316 pointerCount = 0; 1317 pointers[0].clear(); 1318 buttonDown = 0; 1319 buttonUp = 0; 1320 } 1321 } mAccumulator; 1322 1323 uint32_t mButtonState; 1324 1325 void initialize(); 1326 1327 void sync(nsecs_t when); 1328}; 1329 1330 1331class JoystickInputMapper : public InputMapper { 1332public: 1333 JoystickInputMapper(InputDevice* device); 1334 virtual ~JoystickInputMapper(); 1335 1336 virtual uint32_t getSources(); 1337 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); 1338 virtual void dump(String8& dump); 1339 virtual void configure(); 1340 virtual void reset(); 1341 virtual void process(const RawEvent* rawEvent); 1342 1343private: 1344 struct Axis { 1345 RawAbsoluteAxisInfo rawAxisInfo; 1346 AxisInfo axisInfo; 1347 1348 bool explicitlyMapped; // true if the axis was explicitly assigned an axis id 1349 1350 float scale; // scale factor from raw to normalized values 1351 float offset; // offset to add after scaling for normalization 1352 float highScale; // scale factor from raw to normalized values of high split 1353 float highOffset; // offset to add after scaling for normalization of high split 1354 1355 float min; // normalized inclusive minimum 1356 float max; // normalized inclusive maximum 1357 float flat; // normalized flat region size 1358 float fuzz; // normalized error tolerance 1359 1360 float filter; // filter out small variations of this size 1361 float currentValue; // current value 1362 float newValue; // most recent value 1363 float highCurrentValue; // current value of high split 1364 float highNewValue; // most recent value of high split 1365 1366 void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo, 1367 bool explicitlyMapped, float scale, float offset, 1368 float highScale, float highOffset, 1369 float min, float max, float flat, float fuzz) { 1370 this->rawAxisInfo = rawAxisInfo; 1371 this->axisInfo = axisInfo; 1372 this->explicitlyMapped = explicitlyMapped; 1373 this->scale = scale; 1374 this->offset = offset; 1375 this->highScale = highScale; 1376 this->highOffset = highOffset; 1377 this->min = min; 1378 this->max = max; 1379 this->flat = flat; 1380 this->fuzz = fuzz; 1381 this->filter = 0; 1382 resetValue(); 1383 } 1384 1385 void resetValue() { 1386 this->currentValue = 0; 1387 this->newValue = 0; 1388 this->highCurrentValue = 0; 1389 this->highNewValue = 0; 1390 } 1391 }; 1392 1393 // Axes indexed by raw ABS_* axis index. 1394 KeyedVector<int32_t, Axis> mAxes; 1395 1396 void sync(nsecs_t when, bool force); 1397 1398 bool haveAxis(int32_t axisId); 1399 void pruneAxes(bool ignoreExplicitlyMappedAxes); 1400 bool filterAxes(bool force); 1401 1402 static bool hasValueChangedSignificantly(float filter, 1403 float newValue, float currentValue, float min, float max); 1404 static bool hasMovedNearerToValueWithinFilteredRange(float filter, 1405 float newValue, float currentValue, float thresholdValue); 1406 1407 static bool isCenteredAxis(int32_t axis); 1408}; 1409 1410} // namespace android 1411 1412#endif // _UI_INPUT_READER_H 1413