Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 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 "PointerControllerInterface.h" |
| 22 | #include "InputListener.h" |
| 23 | |
| 24 | #include <input/Input.h> |
| 25 | #include <input/VelocityControl.h> |
| 26 | #include <input/VelocityTracker.h> |
| 27 | #include <ui/DisplayInfo.h> |
| 28 | #include <utils/KeyedVector.h> |
| 29 | #include <utils/threads.h> |
| 30 | #include <utils/Timers.h> |
| 31 | #include <utils/RefBase.h> |
| 32 | #include <utils/String8.h> |
| 33 | #include <utils/BitSet.h> |
| 34 | |
| 35 | #include <stddef.h> |
| 36 | #include <unistd.h> |
| 37 | |
| 38 | // Maximum supported size of a vibration pattern. |
| 39 | // Must be at least 2. |
| 40 | #define MAX_VIBRATE_PATTERN_SIZE 100 |
| 41 | |
| 42 | // Maximum allowable delay value in a vibration pattern before |
| 43 | // which the delay will be truncated. |
| 44 | #define MAX_VIBRATE_PATTERN_DELAY_NSECS (1000000 * 1000000000LL) |
| 45 | |
| 46 | namespace android { |
| 47 | |
| 48 | class InputDevice; |
| 49 | class InputMapper; |
| 50 | |
| 51 | /* |
| 52 | * Describes how coordinates are mapped on a physical display. |
| 53 | * See com.android.server.display.DisplayViewport. |
| 54 | */ |
| 55 | struct DisplayViewport { |
| 56 | int32_t displayId; // -1 if invalid |
| 57 | int32_t orientation; |
| 58 | int32_t logicalLeft; |
| 59 | int32_t logicalTop; |
| 60 | int32_t logicalRight; |
| 61 | int32_t logicalBottom; |
| 62 | int32_t physicalLeft; |
| 63 | int32_t physicalTop; |
| 64 | int32_t physicalRight; |
| 65 | int32_t physicalBottom; |
| 66 | int32_t deviceWidth; |
| 67 | int32_t deviceHeight; |
| 68 | |
| 69 | DisplayViewport() : |
| 70 | displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0), |
| 71 | logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0), |
| 72 | physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0), |
| 73 | deviceWidth(0), deviceHeight(0) { |
| 74 | } |
| 75 | |
| 76 | bool operator==(const DisplayViewport& other) const { |
| 77 | return displayId == other.displayId |
| 78 | && orientation == other.orientation |
| 79 | && logicalLeft == other.logicalLeft |
| 80 | && logicalTop == other.logicalTop |
| 81 | && logicalRight == other.logicalRight |
| 82 | && logicalBottom == other.logicalBottom |
| 83 | && physicalLeft == other.physicalLeft |
| 84 | && physicalTop == other.physicalTop |
| 85 | && physicalRight == other.physicalRight |
| 86 | && physicalBottom == other.physicalBottom |
| 87 | && deviceWidth == other.deviceWidth |
| 88 | && deviceHeight == other.deviceHeight; |
| 89 | } |
| 90 | |
| 91 | bool operator!=(const DisplayViewport& other) const { |
| 92 | return !(*this == other); |
| 93 | } |
| 94 | |
| 95 | inline bool isValid() const { |
| 96 | return displayId >= 0; |
| 97 | } |
| 98 | |
| 99 | void setNonDisplayViewport(int32_t width, int32_t height) { |
| 100 | displayId = ADISPLAY_ID_NONE; |
| 101 | orientation = DISPLAY_ORIENTATION_0; |
| 102 | logicalLeft = 0; |
| 103 | logicalTop = 0; |
| 104 | logicalRight = width; |
| 105 | logicalBottom = height; |
| 106 | physicalLeft = 0; |
| 107 | physicalTop = 0; |
| 108 | physicalRight = width; |
| 109 | physicalBottom = height; |
| 110 | deviceWidth = width; |
| 111 | deviceHeight = height; |
| 112 | } |
| 113 | }; |
| 114 | |
| 115 | /* |
| 116 | * Input reader configuration. |
| 117 | * |
| 118 | * Specifies various options that modify the behavior of the input reader. |
| 119 | */ |
| 120 | struct InputReaderConfiguration { |
| 121 | // Describes changes that have occurred. |
| 122 | enum { |
| 123 | // The pointer speed changed. |
| 124 | CHANGE_POINTER_SPEED = 1 << 0, |
| 125 | |
| 126 | // The pointer gesture control changed. |
| 127 | CHANGE_POINTER_GESTURE_ENABLEMENT = 1 << 1, |
| 128 | |
| 129 | // The display size or orientation changed. |
| 130 | CHANGE_DISPLAY_INFO = 1 << 2, |
| 131 | |
| 132 | // The visible touches option changed. |
| 133 | CHANGE_SHOW_TOUCHES = 1 << 3, |
| 134 | |
| 135 | // The keyboard layouts must be reloaded. |
| 136 | CHANGE_KEYBOARD_LAYOUTS = 1 << 4, |
| 137 | |
| 138 | // The device name alias supplied by the may have changed for some devices. |
| 139 | CHANGE_DEVICE_ALIAS = 1 << 5, |
| 140 | |
Jason Gerecke | 12d6baa | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 141 | // The location calibration matrix changed. |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 142 | CHANGE_TOUCH_AFFINE_TRANSFORMATION = 1 << 6, |
| 143 | |
| 144 | // The presence of an external stylus has changed. |
| 145 | CHANGE_EXTERNAL_STYLUS_PRESENCE = 1 << 7, |
Jason Gerecke | 12d6baa | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 146 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 147 | // All devices must be reopened. |
| 148 | CHANGE_MUST_REOPEN = 1 << 31, |
| 149 | }; |
| 150 | |
| 151 | // Gets the amount of time to disable virtual keys after the screen is touched |
| 152 | // in order to filter out accidental virtual key presses due to swiping gestures |
| 153 | // or taps near the edge of the display. May be 0 to disable the feature. |
| 154 | nsecs_t virtualKeyQuietTime; |
| 155 | |
| 156 | // The excluded device names for the platform. |
| 157 | // Devices with these names will be ignored. |
| 158 | Vector<String8> excludedDeviceNames; |
| 159 | |
| 160 | // Velocity control parameters for mouse pointer movements. |
| 161 | VelocityControlParameters pointerVelocityControlParameters; |
| 162 | |
| 163 | // Velocity control parameters for mouse wheel movements. |
| 164 | VelocityControlParameters wheelVelocityControlParameters; |
| 165 | |
| 166 | // True if pointer gestures are enabled. |
| 167 | bool pointerGesturesEnabled; |
| 168 | |
| 169 | // Quiet time between certain pointer gesture transitions. |
| 170 | // Time to allow for all fingers or buttons to settle into a stable state before |
| 171 | // starting a new gesture. |
| 172 | nsecs_t pointerGestureQuietInterval; |
| 173 | |
| 174 | // The minimum speed that a pointer must travel for us to consider switching the active |
| 175 | // touch pointer to it during a drag. This threshold is set to avoid switching due |
| 176 | // to noise from a finger resting on the touch pad (perhaps just pressing it down). |
| 177 | float pointerGestureDragMinSwitchSpeed; // in pixels per second |
| 178 | |
| 179 | // Tap gesture delay time. |
| 180 | // The time between down and up must be less than this to be considered a tap. |
| 181 | nsecs_t pointerGestureTapInterval; |
| 182 | |
| 183 | // Tap drag gesture delay time. |
| 184 | // The time between the previous tap's up and the next down must be less than |
| 185 | // this to be considered a drag. Otherwise, the previous tap is finished and a |
| 186 | // new tap begins. |
| 187 | // |
| 188 | // Note that the previous tap will be held down for this entire duration so this |
| 189 | // interval must be shorter than the long press timeout. |
| 190 | nsecs_t pointerGestureTapDragInterval; |
| 191 | |
| 192 | // The distance in pixels that the pointer is allowed to move from initial down |
| 193 | // to up and still be called a tap. |
| 194 | float pointerGestureTapSlop; // in pixels |
| 195 | |
| 196 | // Time after the first touch points go down to settle on an initial centroid. |
| 197 | // This is intended to be enough time to handle cases where the user puts down two |
| 198 | // fingers at almost but not quite exactly the same time. |
| 199 | nsecs_t pointerGestureMultitouchSettleInterval; |
| 200 | |
| 201 | // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when |
| 202 | // at least two pointers have moved at least this far from their starting place. |
| 203 | float pointerGestureMultitouchMinDistance; // in pixels |
| 204 | |
| 205 | // The transition from PRESS to SWIPE gesture mode can only occur when the |
| 206 | // cosine of the angle between the two vectors is greater than or equal to than this value |
| 207 | // which indicates that the vectors are oriented in the same direction. |
| 208 | // When the vectors are oriented in the exactly same direction, the cosine is 1.0. |
| 209 | // (In exactly opposite directions, the cosine is -1.0.) |
| 210 | float pointerGestureSwipeTransitionAngleCosine; |
| 211 | |
| 212 | // The transition from PRESS to SWIPE gesture mode can only occur when the |
| 213 | // fingers are no more than this far apart relative to the diagonal size of |
| 214 | // the touch pad. For example, a ratio of 0.5 means that the fingers must be |
| 215 | // no more than half the diagonal size of the touch pad apart. |
| 216 | float pointerGestureSwipeMaxWidthRatio; |
| 217 | |
| 218 | // The gesture movement speed factor relative to the size of the display. |
| 219 | // Movement speed applies when the fingers are moving in the same direction. |
| 220 | // Without acceleration, a full swipe of the touch pad diagonal in movement mode |
| 221 | // will cover this portion of the display diagonal. |
| 222 | float pointerGestureMovementSpeedRatio; |
| 223 | |
| 224 | // The gesture zoom speed factor relative to the size of the display. |
| 225 | // Zoom speed applies when the fingers are mostly moving relative to each other |
| 226 | // to execute a scale gesture or similar. |
| 227 | // Without acceleration, a full swipe of the touch pad diagonal in zoom mode |
| 228 | // will cover this portion of the display diagonal. |
| 229 | float pointerGestureZoomSpeedRatio; |
| 230 | |
| 231 | // True to show the location of touches on the touch screen as spots. |
| 232 | bool showTouches; |
| 233 | |
| 234 | InputReaderConfiguration() : |
| 235 | virtualKeyQuietTime(0), |
| 236 | pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f), |
| 237 | wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f), |
| 238 | pointerGesturesEnabled(true), |
| 239 | pointerGestureQuietInterval(100 * 1000000LL), // 100 ms |
| 240 | pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second |
| 241 | pointerGestureTapInterval(150 * 1000000LL), // 150 ms |
| 242 | pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms |
| 243 | pointerGestureTapSlop(10.0f), // 10 pixels |
| 244 | pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms |
| 245 | pointerGestureMultitouchMinDistance(15), // 15 pixels |
| 246 | pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees |
| 247 | pointerGestureSwipeMaxWidthRatio(0.25f), |
| 248 | pointerGestureMovementSpeedRatio(0.8f), |
| 249 | pointerGestureZoomSpeedRatio(0.3f), |
| 250 | showTouches(false) { } |
| 251 | |
| 252 | bool getDisplayInfo(bool external, DisplayViewport* outViewport) const; |
| 253 | void setDisplayInfo(bool external, const DisplayViewport& viewport); |
| 254 | |
| 255 | private: |
| 256 | DisplayViewport mInternalDisplay; |
| 257 | DisplayViewport mExternalDisplay; |
| 258 | }; |
| 259 | |
| 260 | |
Jason Gerecke | af126fb | 2012-05-10 14:22:47 -0700 | [diff] [blame] | 261 | struct TouchAffineTransformation { |
| 262 | float x_scale; |
| 263 | float x_ymix; |
| 264 | float x_offset; |
| 265 | float y_xmix; |
| 266 | float y_scale; |
| 267 | float y_offset; |
| 268 | |
| 269 | TouchAffineTransformation() : |
| 270 | x_scale(1.0f), x_ymix(0.0f), x_offset(0.0f), |
| 271 | y_xmix(0.0f), y_scale(1.0f), y_offset(0.0f) { |
| 272 | } |
| 273 | |
Jason Gerecke | 489fda8 | 2012-09-07 17:19:40 -0700 | [diff] [blame] | 274 | TouchAffineTransformation(float xscale, float xymix, float xoffset, |
| 275 | float yxmix, float yscale, float yoffset) : |
| 276 | x_scale(xscale), x_ymix(xymix), x_offset(xoffset), |
| 277 | y_xmix(yxmix), y_scale(yscale), y_offset(yoffset) { |
| 278 | } |
| 279 | |
Jason Gerecke | af126fb | 2012-05-10 14:22:47 -0700 | [diff] [blame] | 280 | void applyTo(float& x, float& y) const; |
| 281 | }; |
| 282 | |
| 283 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 284 | /* |
| 285 | * Input reader policy interface. |
| 286 | * |
| 287 | * The input reader policy is used by the input reader to interact with the Window Manager |
| 288 | * and other system components. |
| 289 | * |
| 290 | * The actual implementation is partially supported by callbacks into the DVM |
| 291 | * via JNI. This interface is also mocked in the unit tests. |
| 292 | * |
| 293 | * These methods must NOT re-enter the input reader since they may be called while |
| 294 | * holding the input reader lock. |
| 295 | */ |
| 296 | class InputReaderPolicyInterface : public virtual RefBase { |
| 297 | protected: |
| 298 | InputReaderPolicyInterface() { } |
| 299 | virtual ~InputReaderPolicyInterface() { } |
| 300 | |
| 301 | public: |
| 302 | /* Gets the input reader configuration. */ |
| 303 | virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0; |
| 304 | |
| 305 | /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */ |
| 306 | virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0; |
| 307 | |
| 308 | /* Notifies the input reader policy that some input devices have changed |
| 309 | * and provides information about all current input devices. |
| 310 | */ |
| 311 | virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) = 0; |
| 312 | |
| 313 | /* Gets the keyboard layout for a particular input device. */ |
| 314 | virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay( |
| 315 | const InputDeviceIdentifier& identifier) = 0; |
| 316 | |
| 317 | /* Gets a user-supplied alias for a particular input device, or an empty string if none. */ |
| 318 | virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) = 0; |
Jason Gerecke | 12d6baa | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 319 | |
| 320 | /* Gets the affine calibration associated with the specified device. */ |
| 321 | virtual TouchAffineTransformation getTouchAffineTransformation( |
Jason Gerecke | 71b16e8 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 322 | const String8& inputDeviceDescriptor, int32_t surfaceRotation) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | |
| 326 | /* Processes raw input events and sends cooked event data to an input listener. */ |
| 327 | class InputReaderInterface : public virtual RefBase { |
| 328 | protected: |
| 329 | InputReaderInterface() { } |
| 330 | virtual ~InputReaderInterface() { } |
| 331 | |
| 332 | public: |
| 333 | /* Dumps the state of the input reader. |
| 334 | * |
| 335 | * This method may be called on any thread (usually by the input manager). */ |
| 336 | virtual void dump(String8& dump) = 0; |
| 337 | |
| 338 | /* Called by the heatbeat to ensures that the reader has not deadlocked. */ |
| 339 | virtual void monitor() = 0; |
| 340 | |
| 341 | /* Runs a single iteration of the processing loop. |
| 342 | * Nominally reads and processes one incoming message from the EventHub. |
| 343 | * |
| 344 | * This method should be called on the input reader thread. |
| 345 | */ |
| 346 | virtual void loopOnce() = 0; |
| 347 | |
| 348 | /* Gets information about all input devices. |
| 349 | * |
| 350 | * This method may be called on any thread (usually by the input manager). |
| 351 | */ |
| 352 | virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices) = 0; |
| 353 | |
| 354 | /* Query current input state. */ |
| 355 | virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, |
| 356 | int32_t scanCode) = 0; |
| 357 | virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, |
| 358 | int32_t keyCode) = 0; |
| 359 | virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, |
| 360 | int32_t sw) = 0; |
| 361 | |
| 362 | /* Determine whether physical keys exist for the given framework-domain key codes. */ |
| 363 | virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 364 | size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0; |
| 365 | |
| 366 | /* Requests that a reconfiguration of all input devices. |
| 367 | * The changes flag is a bitfield that indicates what has changed and whether |
| 368 | * the input devices must all be reopened. */ |
| 369 | virtual void requestRefreshConfiguration(uint32_t changes) = 0; |
| 370 | |
| 371 | /* Controls the vibrator of a particular input device. */ |
| 372 | virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize, |
| 373 | ssize_t repeat, int32_t token) = 0; |
| 374 | virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0; |
| 375 | }; |
| 376 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 377 | struct StylusState { |
| 378 | /* Time the stylus event was received. */ |
| 379 | nsecs_t when; |
| 380 | /* Pressure as reported by the stylus, normalized to the range [0, 1.0]. */ |
| 381 | float pressure; |
| 382 | /* The state of the stylus buttons as a bitfield (e.g. AMOTION_EVENT_BUTTON_SECONDARY). */ |
| 383 | uint32_t buttons; |
| 384 | /* Which tool type the stylus is currently using (e.g. AMOTION_EVENT_TOOL_TYPE_ERASER). */ |
| 385 | int32_t toolType; |
| 386 | |
| 387 | void copyFrom(const StylusState& other) { |
| 388 | when = other.when; |
| 389 | pressure = other.pressure; |
| 390 | buttons = other.buttons; |
| 391 | toolType = other.toolType; |
| 392 | } |
| 393 | |
| 394 | void clear() { |
| 395 | when = LLONG_MAX; |
| 396 | pressure = 0.f; |
| 397 | buttons = 0; |
| 398 | toolType = AMOTION_EVENT_TOOL_TYPE_UNKNOWN; |
| 399 | } |
| 400 | }; |
| 401 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 402 | |
| 403 | /* Internal interface used by individual input devices to access global input device state |
| 404 | * and parameters maintained by the input reader. |
| 405 | */ |
| 406 | class InputReaderContext { |
| 407 | public: |
| 408 | InputReaderContext() { } |
| 409 | virtual ~InputReaderContext() { } |
| 410 | |
| 411 | virtual void updateGlobalMetaState() = 0; |
| 412 | virtual int32_t getGlobalMetaState() = 0; |
| 413 | |
| 414 | virtual void disableVirtualKeysUntil(nsecs_t time) = 0; |
| 415 | virtual bool shouldDropVirtualKey(nsecs_t now, |
| 416 | InputDevice* device, int32_t keyCode, int32_t scanCode) = 0; |
| 417 | |
| 418 | virtual void fadePointer() = 0; |
| 419 | |
| 420 | virtual void requestTimeoutAtTime(nsecs_t when) = 0; |
| 421 | virtual int32_t bumpGeneration() = 0; |
| 422 | |
Michael Wright | b85401d | 2015-04-17 18:35:15 +0100 | [diff] [blame] | 423 | virtual void getExternalStylusDevices(Vector<InputDeviceInfo>& outDevices) = 0; |
| 424 | virtual void dispatchExternalStylusState(const StylusState& outState) = 0; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 425 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 426 | virtual InputReaderPolicyInterface* getPolicy() = 0; |
| 427 | virtual InputListenerInterface* getListener() = 0; |
| 428 | virtual EventHubInterface* getEventHub() = 0; |
| 429 | }; |
| 430 | |
| 431 | |
| 432 | /* The input reader reads raw event data from the event hub and processes it into input events |
| 433 | * that it sends to the input listener. Some functions of the input reader, such as early |
| 434 | * event filtering in low power states, are controlled by a separate policy object. |
| 435 | * |
| 436 | * The InputReader owns a collection of InputMappers. Most of the work it does happens |
| 437 | * on the input reader thread but the InputReader can receive queries from other system |
| 438 | * components running on arbitrary threads. To keep things manageable, the InputReader |
| 439 | * uses a single Mutex to guard its state. The Mutex may be held while calling into the |
| 440 | * EventHub or the InputReaderPolicy but it is never held while calling into the |
| 441 | * InputListener. |
| 442 | */ |
| 443 | class InputReader : public InputReaderInterface { |
| 444 | public: |
| 445 | InputReader(const sp<EventHubInterface>& eventHub, |
| 446 | const sp<InputReaderPolicyInterface>& policy, |
| 447 | const sp<InputListenerInterface>& listener); |
| 448 | virtual ~InputReader(); |
| 449 | |
| 450 | virtual void dump(String8& dump); |
| 451 | virtual void monitor(); |
| 452 | |
| 453 | virtual void loopOnce(); |
| 454 | |
| 455 | virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices); |
| 456 | |
| 457 | virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, |
| 458 | int32_t scanCode); |
| 459 | virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, |
| 460 | int32_t keyCode); |
| 461 | virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, |
| 462 | int32_t sw); |
| 463 | |
| 464 | virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 465 | size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags); |
| 466 | |
| 467 | virtual void requestRefreshConfiguration(uint32_t changes); |
| 468 | |
| 469 | virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize, |
| 470 | ssize_t repeat, int32_t token); |
| 471 | virtual void cancelVibrate(int32_t deviceId, int32_t token); |
| 472 | |
| 473 | protected: |
| 474 | // These members are protected so they can be instrumented by test cases. |
| 475 | virtual InputDevice* createDeviceLocked(int32_t deviceId, int32_t controllerNumber, |
| 476 | const InputDeviceIdentifier& identifier, uint32_t classes); |
| 477 | |
| 478 | class ContextImpl : public InputReaderContext { |
| 479 | InputReader* mReader; |
| 480 | |
| 481 | public: |
| 482 | ContextImpl(InputReader* reader); |
| 483 | |
| 484 | virtual void updateGlobalMetaState(); |
| 485 | virtual int32_t getGlobalMetaState(); |
| 486 | virtual void disableVirtualKeysUntil(nsecs_t time); |
| 487 | virtual bool shouldDropVirtualKey(nsecs_t now, |
| 488 | InputDevice* device, int32_t keyCode, int32_t scanCode); |
| 489 | virtual void fadePointer(); |
| 490 | virtual void requestTimeoutAtTime(nsecs_t when); |
| 491 | virtual int32_t bumpGeneration(); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 492 | virtual void getExternalStylusDevices(Vector<InputDeviceInfo>& outDevices); |
| 493 | virtual void dispatchExternalStylusState(const StylusState& outState); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 494 | virtual InputReaderPolicyInterface* getPolicy(); |
| 495 | virtual InputListenerInterface* getListener(); |
| 496 | virtual EventHubInterface* getEventHub(); |
| 497 | } mContext; |
| 498 | |
| 499 | friend class ContextImpl; |
| 500 | |
| 501 | private: |
| 502 | Mutex mLock; |
| 503 | |
| 504 | Condition mReaderIsAliveCondition; |
| 505 | |
| 506 | sp<EventHubInterface> mEventHub; |
| 507 | sp<InputReaderPolicyInterface> mPolicy; |
| 508 | sp<QueuedInputListener> mQueuedListener; |
| 509 | |
| 510 | InputReaderConfiguration mConfig; |
| 511 | |
| 512 | // The event queue. |
| 513 | static const int EVENT_BUFFER_SIZE = 256; |
| 514 | RawEvent mEventBuffer[EVENT_BUFFER_SIZE]; |
| 515 | |
| 516 | KeyedVector<int32_t, InputDevice*> mDevices; |
| 517 | |
| 518 | // low-level input event decoding and device management |
| 519 | void processEventsLocked(const RawEvent* rawEvents, size_t count); |
| 520 | |
| 521 | void addDeviceLocked(nsecs_t when, int32_t deviceId); |
| 522 | void removeDeviceLocked(nsecs_t when, int32_t deviceId); |
| 523 | void processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, size_t count); |
| 524 | void timeoutExpiredLocked(nsecs_t when); |
| 525 | |
| 526 | void handleConfigurationChangedLocked(nsecs_t when); |
| 527 | |
| 528 | int32_t mGlobalMetaState; |
| 529 | void updateGlobalMetaStateLocked(); |
| 530 | int32_t getGlobalMetaStateLocked(); |
| 531 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 532 | void notifyExternalStylusPresenceChanged(); |
| 533 | void getExternalStylusDevicesLocked(Vector<InputDeviceInfo>& outDevices); |
| 534 | void dispatchExternalStylusState(const StylusState& state); |
| 535 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 536 | void fadePointerLocked(); |
| 537 | |
| 538 | int32_t mGeneration; |
| 539 | int32_t bumpGenerationLocked(); |
| 540 | |
| 541 | void getInputDevicesLocked(Vector<InputDeviceInfo>& outInputDevices); |
| 542 | |
| 543 | nsecs_t mDisableVirtualKeysTimeout; |
| 544 | void disableVirtualKeysUntilLocked(nsecs_t time); |
| 545 | bool shouldDropVirtualKeyLocked(nsecs_t now, |
| 546 | InputDevice* device, int32_t keyCode, int32_t scanCode); |
| 547 | |
| 548 | nsecs_t mNextTimeout; |
| 549 | void requestTimeoutAtTimeLocked(nsecs_t when); |
| 550 | |
| 551 | uint32_t mConfigurationChangesToRefresh; |
| 552 | void refreshConfigurationLocked(uint32_t changes); |
| 553 | |
| 554 | // state queries |
| 555 | typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code); |
| 556 | int32_t getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code, |
| 557 | GetStateFunc getStateFunc); |
| 558 | bool markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, size_t numCodes, |
| 559 | const int32_t* keyCodes, uint8_t* outFlags); |
| 560 | }; |
| 561 | |
| 562 | |
| 563 | /* Reads raw events from the event hub and processes them, endlessly. */ |
| 564 | class InputReaderThread : public Thread { |
| 565 | public: |
| 566 | InputReaderThread(const sp<InputReaderInterface>& reader); |
| 567 | virtual ~InputReaderThread(); |
| 568 | |
| 569 | private: |
| 570 | sp<InputReaderInterface> mReader; |
| 571 | |
| 572 | virtual bool threadLoop(); |
| 573 | }; |
| 574 | |
| 575 | |
| 576 | /* Represents the state of a single input device. */ |
| 577 | class InputDevice { |
| 578 | public: |
| 579 | InputDevice(InputReaderContext* context, int32_t id, int32_t generation, int32_t |
| 580 | controllerNumber, const InputDeviceIdentifier& identifier, uint32_t classes); |
| 581 | ~InputDevice(); |
| 582 | |
| 583 | inline InputReaderContext* getContext() { return mContext; } |
| 584 | inline int32_t getId() const { return mId; } |
| 585 | inline int32_t getControllerNumber() const { return mControllerNumber; } |
| 586 | inline int32_t getGeneration() const { return mGeneration; } |
| 587 | inline const String8& getName() const { return mIdentifier.name; } |
Jason Gerecke | 12d6baa | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 588 | inline const String8& getDescriptor() { return mIdentifier.descriptor; } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 589 | inline uint32_t getClasses() const { return mClasses; } |
| 590 | inline uint32_t getSources() const { return mSources; } |
| 591 | |
| 592 | inline bool isExternal() { return mIsExternal; } |
| 593 | inline void setExternal(bool external) { mIsExternal = external; } |
| 594 | |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 595 | inline void setMic(bool hasMic) { mHasMic = hasMic; } |
| 596 | inline bool hasMic() const { return mHasMic; } |
| 597 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 598 | inline bool isIgnored() { return mMappers.isEmpty(); } |
| 599 | |
| 600 | void dump(String8& dump); |
| 601 | void addMapper(InputMapper* mapper); |
| 602 | void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 603 | void reset(nsecs_t when); |
| 604 | void process(const RawEvent* rawEvents, size_t count); |
| 605 | void timeoutExpired(nsecs_t when); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 606 | void updateExternalStylusState(const StylusState& state); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 607 | |
| 608 | void getDeviceInfo(InputDeviceInfo* outDeviceInfo); |
| 609 | int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 610 | int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 611 | int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 612 | bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 613 | const int32_t* keyCodes, uint8_t* outFlags); |
| 614 | void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token); |
| 615 | void cancelVibrate(int32_t token); |
Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 616 | void cancelTouch(nsecs_t when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 617 | |
| 618 | int32_t getMetaState(); |
| 619 | |
| 620 | void fadePointer(); |
| 621 | |
| 622 | void bumpGeneration(); |
| 623 | |
| 624 | void notifyReset(nsecs_t when); |
| 625 | |
| 626 | inline const PropertyMap& getConfiguration() { return mConfiguration; } |
| 627 | inline EventHubInterface* getEventHub() { return mContext->getEventHub(); } |
| 628 | |
| 629 | bool hasKey(int32_t code) { |
| 630 | return getEventHub()->hasScanCode(mId, code); |
| 631 | } |
| 632 | |
| 633 | bool hasAbsoluteAxis(int32_t code) { |
| 634 | RawAbsoluteAxisInfo info; |
| 635 | getEventHub()->getAbsoluteAxisInfo(mId, code, &info); |
| 636 | return info.valid; |
| 637 | } |
| 638 | |
| 639 | bool isKeyPressed(int32_t code) { |
| 640 | return getEventHub()->getScanCodeState(mId, code) == AKEY_STATE_DOWN; |
| 641 | } |
| 642 | |
| 643 | int32_t getAbsoluteAxisValue(int32_t code) { |
| 644 | int32_t value; |
| 645 | getEventHub()->getAbsoluteAxisValue(mId, code, &value); |
| 646 | return value; |
| 647 | } |
| 648 | |
| 649 | private: |
| 650 | InputReaderContext* mContext; |
| 651 | int32_t mId; |
| 652 | int32_t mGeneration; |
| 653 | int32_t mControllerNumber; |
| 654 | InputDeviceIdentifier mIdentifier; |
| 655 | String8 mAlias; |
| 656 | uint32_t mClasses; |
| 657 | |
| 658 | Vector<InputMapper*> mMappers; |
| 659 | |
| 660 | uint32_t mSources; |
| 661 | bool mIsExternal; |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 662 | bool mHasMic; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 663 | bool mDropUntilNextSync; |
| 664 | |
| 665 | typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code); |
| 666 | int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc); |
| 667 | |
| 668 | PropertyMap mConfiguration; |
| 669 | }; |
| 670 | |
| 671 | |
| 672 | /* Keeps track of the state of mouse or touch pad buttons. */ |
| 673 | class CursorButtonAccumulator { |
| 674 | public: |
| 675 | CursorButtonAccumulator(); |
| 676 | void reset(InputDevice* device); |
| 677 | |
| 678 | void process(const RawEvent* rawEvent); |
| 679 | |
| 680 | uint32_t getButtonState() const; |
| 681 | |
| 682 | private: |
| 683 | bool mBtnLeft; |
| 684 | bool mBtnRight; |
| 685 | bool mBtnMiddle; |
| 686 | bool mBtnBack; |
| 687 | bool mBtnSide; |
| 688 | bool mBtnForward; |
| 689 | bool mBtnExtra; |
| 690 | bool mBtnTask; |
| 691 | |
| 692 | void clearButtons(); |
| 693 | }; |
| 694 | |
| 695 | |
| 696 | /* Keeps track of cursor movements. */ |
| 697 | |
| 698 | class CursorMotionAccumulator { |
| 699 | public: |
| 700 | CursorMotionAccumulator(); |
| 701 | void reset(InputDevice* device); |
| 702 | |
| 703 | void process(const RawEvent* rawEvent); |
| 704 | void finishSync(); |
| 705 | |
| 706 | inline int32_t getRelativeX() const { return mRelX; } |
| 707 | inline int32_t getRelativeY() const { return mRelY; } |
| 708 | |
| 709 | private: |
| 710 | int32_t mRelX; |
| 711 | int32_t mRelY; |
| 712 | |
| 713 | void clearRelativeAxes(); |
| 714 | }; |
| 715 | |
| 716 | |
| 717 | /* Keeps track of cursor scrolling motions. */ |
| 718 | |
| 719 | class CursorScrollAccumulator { |
| 720 | public: |
| 721 | CursorScrollAccumulator(); |
| 722 | void configure(InputDevice* device); |
| 723 | void reset(InputDevice* device); |
| 724 | |
| 725 | void process(const RawEvent* rawEvent); |
| 726 | void finishSync(); |
| 727 | |
| 728 | inline bool haveRelativeVWheel() const { return mHaveRelWheel; } |
| 729 | inline bool haveRelativeHWheel() const { return mHaveRelHWheel; } |
| 730 | |
| 731 | inline int32_t getRelativeX() const { return mRelX; } |
| 732 | inline int32_t getRelativeY() const { return mRelY; } |
| 733 | inline int32_t getRelativeVWheel() const { return mRelWheel; } |
| 734 | inline int32_t getRelativeHWheel() const { return mRelHWheel; } |
| 735 | |
| 736 | private: |
| 737 | bool mHaveRelWheel; |
| 738 | bool mHaveRelHWheel; |
| 739 | |
| 740 | int32_t mRelX; |
| 741 | int32_t mRelY; |
| 742 | int32_t mRelWheel; |
| 743 | int32_t mRelHWheel; |
| 744 | |
| 745 | void clearRelativeAxes(); |
| 746 | }; |
| 747 | |
| 748 | |
| 749 | /* Keeps track of the state of touch, stylus and tool buttons. */ |
| 750 | class TouchButtonAccumulator { |
| 751 | public: |
| 752 | TouchButtonAccumulator(); |
| 753 | void configure(InputDevice* device); |
| 754 | void reset(InputDevice* device); |
| 755 | |
| 756 | void process(const RawEvent* rawEvent); |
| 757 | |
| 758 | uint32_t getButtonState() const; |
| 759 | int32_t getToolType() const; |
| 760 | bool isToolActive() const; |
| 761 | bool isHovering() const; |
| 762 | bool hasStylus() const; |
| 763 | |
| 764 | private: |
| 765 | bool mHaveBtnTouch; |
| 766 | bool mHaveStylus; |
| 767 | |
| 768 | bool mBtnTouch; |
| 769 | bool mBtnStylus; |
| 770 | bool mBtnStylus2; |
| 771 | bool mBtnToolFinger; |
| 772 | bool mBtnToolPen; |
| 773 | bool mBtnToolRubber; |
| 774 | bool mBtnToolBrush; |
| 775 | bool mBtnToolPencil; |
| 776 | bool mBtnToolAirbrush; |
| 777 | bool mBtnToolMouse; |
| 778 | bool mBtnToolLens; |
| 779 | bool mBtnToolDoubleTap; |
| 780 | bool mBtnToolTripleTap; |
| 781 | bool mBtnToolQuadTap; |
| 782 | |
| 783 | void clearButtons(); |
| 784 | }; |
| 785 | |
| 786 | |
| 787 | /* Raw axis information from the driver. */ |
| 788 | struct RawPointerAxes { |
| 789 | RawAbsoluteAxisInfo x; |
| 790 | RawAbsoluteAxisInfo y; |
| 791 | RawAbsoluteAxisInfo pressure; |
| 792 | RawAbsoluteAxisInfo touchMajor; |
| 793 | RawAbsoluteAxisInfo touchMinor; |
| 794 | RawAbsoluteAxisInfo toolMajor; |
| 795 | RawAbsoluteAxisInfo toolMinor; |
| 796 | RawAbsoluteAxisInfo orientation; |
| 797 | RawAbsoluteAxisInfo distance; |
| 798 | RawAbsoluteAxisInfo tiltX; |
| 799 | RawAbsoluteAxisInfo tiltY; |
| 800 | RawAbsoluteAxisInfo trackingId; |
| 801 | RawAbsoluteAxisInfo slot; |
| 802 | |
| 803 | RawPointerAxes(); |
| 804 | void clear(); |
| 805 | }; |
| 806 | |
| 807 | |
| 808 | /* Raw data for a collection of pointers including a pointer id mapping table. */ |
| 809 | struct RawPointerData { |
| 810 | struct Pointer { |
| 811 | uint32_t id; |
| 812 | int32_t x; |
| 813 | int32_t y; |
| 814 | int32_t pressure; |
| 815 | int32_t touchMajor; |
| 816 | int32_t touchMinor; |
| 817 | int32_t toolMajor; |
| 818 | int32_t toolMinor; |
| 819 | int32_t orientation; |
| 820 | int32_t distance; |
| 821 | int32_t tiltX; |
| 822 | int32_t tiltY; |
| 823 | int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant |
| 824 | bool isHovering; |
| 825 | }; |
| 826 | |
| 827 | uint32_t pointerCount; |
| 828 | Pointer pointers[MAX_POINTERS]; |
| 829 | BitSet32 hoveringIdBits, touchingIdBits; |
| 830 | uint32_t idToIndex[MAX_POINTER_ID + 1]; |
| 831 | |
| 832 | RawPointerData(); |
| 833 | void clear(); |
| 834 | void copyFrom(const RawPointerData& other); |
| 835 | void getCentroidOfTouchingPointers(float* outX, float* outY) const; |
| 836 | |
| 837 | inline void markIdBit(uint32_t id, bool isHovering) { |
| 838 | if (isHovering) { |
| 839 | hoveringIdBits.markBit(id); |
| 840 | } else { |
| 841 | touchingIdBits.markBit(id); |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | inline void clearIdBits() { |
| 846 | hoveringIdBits.clear(); |
| 847 | touchingIdBits.clear(); |
| 848 | } |
| 849 | |
| 850 | inline const Pointer& pointerForId(uint32_t id) const { |
| 851 | return pointers[idToIndex[id]]; |
| 852 | } |
| 853 | |
| 854 | inline bool isHovering(uint32_t pointerIndex) { |
| 855 | return pointers[pointerIndex].isHovering; |
| 856 | } |
| 857 | }; |
| 858 | |
| 859 | |
| 860 | /* Cooked data for a collection of pointers including a pointer id mapping table. */ |
| 861 | struct CookedPointerData { |
| 862 | uint32_t pointerCount; |
| 863 | PointerProperties pointerProperties[MAX_POINTERS]; |
| 864 | PointerCoords pointerCoords[MAX_POINTERS]; |
| 865 | BitSet32 hoveringIdBits, touchingIdBits; |
| 866 | uint32_t idToIndex[MAX_POINTER_ID + 1]; |
| 867 | |
| 868 | CookedPointerData(); |
| 869 | void clear(); |
| 870 | void copyFrom(const CookedPointerData& other); |
| 871 | |
| 872 | inline const PointerCoords& pointerCoordsForId(uint32_t id) const { |
| 873 | return pointerCoords[idToIndex[id]]; |
| 874 | } |
| 875 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 876 | inline PointerCoords& editPointerCoordsWithId(uint32_t id) { |
| 877 | return pointerCoords[idToIndex[id]]; |
| 878 | } |
| 879 | |
| 880 | inline PointerProperties& editPointerPropertiesWithId(uint32_t id) { |
| 881 | return pointerProperties[idToIndex[id]]; |
| 882 | } |
| 883 | |
Michael Wright | 53dca3a | 2015-04-23 17:39:53 +0100 | [diff] [blame] | 884 | inline bool isHovering(uint32_t pointerIndex) const { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 885 | return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id); |
| 886 | } |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 887 | |
Michael Wright | 53dca3a | 2015-04-23 17:39:53 +0100 | [diff] [blame] | 888 | inline bool isTouching(uint32_t pointerIndex) const { |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 889 | return touchingIdBits.hasBit(pointerProperties[pointerIndex].id); |
| 890 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 891 | }; |
| 892 | |
| 893 | |
| 894 | /* Keeps track of the state of single-touch protocol. */ |
| 895 | class SingleTouchMotionAccumulator { |
| 896 | public: |
| 897 | SingleTouchMotionAccumulator(); |
| 898 | |
| 899 | void process(const RawEvent* rawEvent); |
| 900 | void reset(InputDevice* device); |
| 901 | |
| 902 | inline int32_t getAbsoluteX() const { return mAbsX; } |
| 903 | inline int32_t getAbsoluteY() const { return mAbsY; } |
| 904 | inline int32_t getAbsolutePressure() const { return mAbsPressure; } |
| 905 | inline int32_t getAbsoluteToolWidth() const { return mAbsToolWidth; } |
| 906 | inline int32_t getAbsoluteDistance() const { return mAbsDistance; } |
| 907 | inline int32_t getAbsoluteTiltX() const { return mAbsTiltX; } |
| 908 | inline int32_t getAbsoluteTiltY() const { return mAbsTiltY; } |
| 909 | |
| 910 | private: |
| 911 | int32_t mAbsX; |
| 912 | int32_t mAbsY; |
| 913 | int32_t mAbsPressure; |
| 914 | int32_t mAbsToolWidth; |
| 915 | int32_t mAbsDistance; |
| 916 | int32_t mAbsTiltX; |
| 917 | int32_t mAbsTiltY; |
| 918 | |
| 919 | void clearAbsoluteAxes(); |
| 920 | }; |
| 921 | |
| 922 | |
| 923 | /* Keeps track of the state of multi-touch protocol. */ |
| 924 | class MultiTouchMotionAccumulator { |
| 925 | public: |
| 926 | class Slot { |
| 927 | public: |
| 928 | inline bool isInUse() const { return mInUse; } |
| 929 | inline int32_t getX() const { return mAbsMTPositionX; } |
| 930 | inline int32_t getY() const { return mAbsMTPositionY; } |
| 931 | inline int32_t getTouchMajor() const { return mAbsMTTouchMajor; } |
| 932 | inline int32_t getTouchMinor() const { |
| 933 | return mHaveAbsMTTouchMinor ? mAbsMTTouchMinor : mAbsMTTouchMajor; } |
| 934 | inline int32_t getToolMajor() const { return mAbsMTWidthMajor; } |
| 935 | inline int32_t getToolMinor() const { |
| 936 | return mHaveAbsMTWidthMinor ? mAbsMTWidthMinor : mAbsMTWidthMajor; } |
| 937 | inline int32_t getOrientation() const { return mAbsMTOrientation; } |
| 938 | inline int32_t getTrackingId() const { return mAbsMTTrackingId; } |
| 939 | inline int32_t getPressure() const { return mAbsMTPressure; } |
| 940 | inline int32_t getDistance() const { return mAbsMTDistance; } |
| 941 | inline int32_t getToolType() const; |
| 942 | |
| 943 | private: |
| 944 | friend class MultiTouchMotionAccumulator; |
| 945 | |
| 946 | bool mInUse; |
| 947 | bool mHaveAbsMTTouchMinor; |
| 948 | bool mHaveAbsMTWidthMinor; |
| 949 | bool mHaveAbsMTToolType; |
| 950 | |
| 951 | int32_t mAbsMTPositionX; |
| 952 | int32_t mAbsMTPositionY; |
| 953 | int32_t mAbsMTTouchMajor; |
| 954 | int32_t mAbsMTTouchMinor; |
| 955 | int32_t mAbsMTWidthMajor; |
| 956 | int32_t mAbsMTWidthMinor; |
| 957 | int32_t mAbsMTOrientation; |
| 958 | int32_t mAbsMTTrackingId; |
| 959 | int32_t mAbsMTPressure; |
| 960 | int32_t mAbsMTDistance; |
| 961 | int32_t mAbsMTToolType; |
| 962 | |
| 963 | Slot(); |
| 964 | void clear(); |
| 965 | }; |
| 966 | |
| 967 | MultiTouchMotionAccumulator(); |
| 968 | ~MultiTouchMotionAccumulator(); |
| 969 | |
| 970 | void configure(InputDevice* device, size_t slotCount, bool usingSlotsProtocol); |
| 971 | void reset(InputDevice* device); |
| 972 | void process(const RawEvent* rawEvent); |
| 973 | void finishSync(); |
| 974 | bool hasStylus() const; |
| 975 | |
| 976 | inline size_t getSlotCount() const { return mSlotCount; } |
| 977 | inline const Slot* getSlot(size_t index) const { return &mSlots[index]; } |
| 978 | |
| 979 | private: |
| 980 | int32_t mCurrentSlot; |
| 981 | Slot* mSlots; |
| 982 | size_t mSlotCount; |
| 983 | bool mUsingSlotsProtocol; |
| 984 | bool mHaveStylus; |
| 985 | |
| 986 | void clearSlots(int32_t initialSlot); |
| 987 | }; |
| 988 | |
| 989 | |
| 990 | /* An input mapper transforms raw input events into cooked event data. |
| 991 | * A single input device can have multiple associated input mappers in order to interpret |
| 992 | * different classes of events. |
| 993 | * |
| 994 | * InputMapper lifecycle: |
| 995 | * - create |
| 996 | * - configure with 0 changes |
| 997 | * - reset |
| 998 | * - process, process, process (may occasionally reconfigure with non-zero changes or reset) |
| 999 | * - reset |
| 1000 | * - destroy |
| 1001 | */ |
| 1002 | class InputMapper { |
| 1003 | public: |
| 1004 | InputMapper(InputDevice* device); |
| 1005 | virtual ~InputMapper(); |
| 1006 | |
| 1007 | inline InputDevice* getDevice() { return mDevice; } |
| 1008 | inline int32_t getDeviceId() { return mDevice->getId(); } |
| 1009 | inline const String8 getDeviceName() { return mDevice->getName(); } |
| 1010 | inline InputReaderContext* getContext() { return mContext; } |
| 1011 | inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); } |
| 1012 | inline InputListenerInterface* getListener() { return mContext->getListener(); } |
| 1013 | inline EventHubInterface* getEventHub() { return mContext->getEventHub(); } |
| 1014 | |
| 1015 | virtual uint32_t getSources() = 0; |
| 1016 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
| 1017 | virtual void dump(String8& dump); |
| 1018 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 1019 | virtual void reset(nsecs_t when); |
| 1020 | virtual void process(const RawEvent* rawEvent) = 0; |
| 1021 | virtual void timeoutExpired(nsecs_t when); |
| 1022 | |
| 1023 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 1024 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 1025 | virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 1026 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 1027 | const int32_t* keyCodes, uint8_t* outFlags); |
| 1028 | virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, |
| 1029 | int32_t token); |
| 1030 | virtual void cancelVibrate(int32_t token); |
Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 1031 | virtual void cancelTouch(nsecs_t when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1032 | |
| 1033 | virtual int32_t getMetaState(); |
| 1034 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1035 | virtual void updateExternalStylusState(const StylusState& state); |
| 1036 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1037 | virtual void fadePointer(); |
| 1038 | |
| 1039 | protected: |
| 1040 | InputDevice* mDevice; |
| 1041 | InputReaderContext* mContext; |
| 1042 | |
| 1043 | status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo); |
| 1044 | void bumpGeneration(); |
| 1045 | |
| 1046 | static void dumpRawAbsoluteAxisInfo(String8& dump, |
| 1047 | const RawAbsoluteAxisInfo& axis, const char* name); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1048 | static void dumpStylusState(String8& dump, const StylusState& state); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1049 | }; |
| 1050 | |
| 1051 | |
| 1052 | class SwitchInputMapper : public InputMapper { |
| 1053 | public: |
| 1054 | SwitchInputMapper(InputDevice* device); |
| 1055 | virtual ~SwitchInputMapper(); |
| 1056 | |
| 1057 | virtual uint32_t getSources(); |
| 1058 | virtual void process(const RawEvent* rawEvent); |
| 1059 | |
| 1060 | virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
Michael Wright | bcbf97e | 2014-08-29 14:31:32 -0700 | [diff] [blame] | 1061 | virtual void dump(String8& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1062 | |
| 1063 | private: |
Michael Wright | bcbf97e | 2014-08-29 14:31:32 -0700 | [diff] [blame] | 1064 | uint32_t mSwitchValues; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1065 | uint32_t mUpdatedSwitchMask; |
| 1066 | |
| 1067 | void processSwitch(int32_t switchCode, int32_t switchValue); |
| 1068 | void sync(nsecs_t when); |
| 1069 | }; |
| 1070 | |
| 1071 | |
| 1072 | class VibratorInputMapper : public InputMapper { |
| 1073 | public: |
| 1074 | VibratorInputMapper(InputDevice* device); |
| 1075 | virtual ~VibratorInputMapper(); |
| 1076 | |
| 1077 | virtual uint32_t getSources(); |
| 1078 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
| 1079 | virtual void process(const RawEvent* rawEvent); |
| 1080 | |
| 1081 | virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, |
| 1082 | int32_t token); |
| 1083 | virtual void cancelVibrate(int32_t token); |
| 1084 | virtual void timeoutExpired(nsecs_t when); |
| 1085 | virtual void dump(String8& dump); |
| 1086 | |
| 1087 | private: |
| 1088 | bool mVibrating; |
| 1089 | nsecs_t mPattern[MAX_VIBRATE_PATTERN_SIZE]; |
| 1090 | size_t mPatternSize; |
| 1091 | ssize_t mRepeat; |
| 1092 | int32_t mToken; |
| 1093 | ssize_t mIndex; |
| 1094 | nsecs_t mNextStepTime; |
| 1095 | |
| 1096 | void nextStep(); |
| 1097 | void stopVibrating(); |
| 1098 | }; |
| 1099 | |
| 1100 | |
| 1101 | class KeyboardInputMapper : public InputMapper { |
| 1102 | public: |
| 1103 | KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType); |
| 1104 | virtual ~KeyboardInputMapper(); |
| 1105 | |
| 1106 | virtual uint32_t getSources(); |
| 1107 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
| 1108 | virtual void dump(String8& dump); |
| 1109 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 1110 | virtual void reset(nsecs_t when); |
| 1111 | virtual void process(const RawEvent* rawEvent); |
| 1112 | |
| 1113 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 1114 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 1115 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 1116 | const int32_t* keyCodes, uint8_t* outFlags); |
| 1117 | |
| 1118 | virtual int32_t getMetaState(); |
| 1119 | |
| 1120 | private: |
| 1121 | struct KeyDown { |
| 1122 | int32_t keyCode; |
| 1123 | int32_t scanCode; |
| 1124 | }; |
| 1125 | |
| 1126 | uint32_t mSource; |
| 1127 | int32_t mKeyboardType; |
| 1128 | |
| 1129 | int32_t mOrientation; // orientation for dpad keys |
| 1130 | |
| 1131 | Vector<KeyDown> mKeyDowns; // keys that are down |
| 1132 | int32_t mMetaState; |
| 1133 | nsecs_t mDownTime; // time of most recent key down |
| 1134 | |
| 1135 | int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none |
| 1136 | |
| 1137 | struct LedState { |
| 1138 | bool avail; // led is available |
| 1139 | bool on; // we think the led is currently on |
| 1140 | }; |
| 1141 | LedState mCapsLockLedState; |
| 1142 | LedState mNumLockLedState; |
| 1143 | LedState mScrollLockLedState; |
| 1144 | |
| 1145 | // Immutable configuration parameters. |
| 1146 | struct Parameters { |
| 1147 | bool hasAssociatedDisplay; |
| 1148 | bool orientationAware; |
Michael Wright | dcfcf5d | 2014-03-17 12:58:21 -0700 | [diff] [blame] | 1149 | bool handlesKeyRepeat; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1150 | } mParameters; |
| 1151 | |
| 1152 | void configureParameters(); |
| 1153 | void dumpParameters(String8& dump); |
| 1154 | |
| 1155 | bool isKeyboardOrGamepadKey(int32_t scanCode); |
| 1156 | |
Dmitry Torokhov | 0faaa0b | 2015-09-24 13:13:55 -0700 | [diff] [blame] | 1157 | void processKey(nsecs_t when, bool down, int32_t scanCode, int32_t usageCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1158 | |
| 1159 | ssize_t findKeyDown(int32_t scanCode); |
| 1160 | |
| 1161 | void resetLedState(); |
| 1162 | void initializeLedState(LedState& ledState, int32_t led); |
| 1163 | void updateLedState(bool reset); |
| 1164 | void updateLedStateForModifier(LedState& ledState, int32_t led, |
| 1165 | int32_t modifier, bool reset); |
| 1166 | }; |
| 1167 | |
| 1168 | |
| 1169 | class CursorInputMapper : public InputMapper { |
| 1170 | public: |
| 1171 | CursorInputMapper(InputDevice* device); |
| 1172 | virtual ~CursorInputMapper(); |
| 1173 | |
| 1174 | virtual uint32_t getSources(); |
| 1175 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
| 1176 | virtual void dump(String8& dump); |
| 1177 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 1178 | virtual void reset(nsecs_t when); |
| 1179 | virtual void process(const RawEvent* rawEvent); |
| 1180 | |
| 1181 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 1182 | |
| 1183 | virtual void fadePointer(); |
| 1184 | |
| 1185 | private: |
| 1186 | // Amount that trackball needs to move in order to generate a key event. |
| 1187 | static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6; |
| 1188 | |
| 1189 | // Immutable configuration parameters. |
| 1190 | struct Parameters { |
| 1191 | enum Mode { |
| 1192 | MODE_POINTER, |
| 1193 | MODE_NAVIGATION, |
| 1194 | }; |
| 1195 | |
| 1196 | Mode mode; |
| 1197 | bool hasAssociatedDisplay; |
| 1198 | bool orientationAware; |
| 1199 | } mParameters; |
| 1200 | |
| 1201 | CursorButtonAccumulator mCursorButtonAccumulator; |
| 1202 | CursorMotionAccumulator mCursorMotionAccumulator; |
| 1203 | CursorScrollAccumulator mCursorScrollAccumulator; |
| 1204 | |
| 1205 | int32_t mSource; |
| 1206 | float mXScale; |
| 1207 | float mYScale; |
| 1208 | float mXPrecision; |
| 1209 | float mYPrecision; |
| 1210 | |
| 1211 | float mVWheelScale; |
| 1212 | float mHWheelScale; |
| 1213 | |
| 1214 | // Velocity controls for mouse pointer and wheel movements. |
| 1215 | // The controls for X and Y wheel movements are separate to keep them decoupled. |
| 1216 | VelocityControl mPointerVelocityControl; |
| 1217 | VelocityControl mWheelXVelocityControl; |
| 1218 | VelocityControl mWheelYVelocityControl; |
| 1219 | |
| 1220 | int32_t mOrientation; |
| 1221 | |
| 1222 | sp<PointerControllerInterface> mPointerController; |
| 1223 | |
| 1224 | int32_t mButtonState; |
| 1225 | nsecs_t mDownTime; |
| 1226 | |
| 1227 | void configureParameters(); |
| 1228 | void dumpParameters(String8& dump); |
| 1229 | |
| 1230 | void sync(nsecs_t when); |
| 1231 | }; |
| 1232 | |
| 1233 | |
| 1234 | class TouchInputMapper : public InputMapper { |
| 1235 | public: |
| 1236 | TouchInputMapper(InputDevice* device); |
| 1237 | virtual ~TouchInputMapper(); |
| 1238 | |
| 1239 | virtual uint32_t getSources(); |
| 1240 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
| 1241 | virtual void dump(String8& dump); |
| 1242 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 1243 | virtual void reset(nsecs_t when); |
| 1244 | virtual void process(const RawEvent* rawEvent); |
| 1245 | |
| 1246 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 1247 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 1248 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 1249 | const int32_t* keyCodes, uint8_t* outFlags); |
| 1250 | |
| 1251 | virtual void fadePointer(); |
Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 1252 | virtual void cancelTouch(nsecs_t when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1253 | virtual void timeoutExpired(nsecs_t when); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1254 | virtual void updateExternalStylusState(const StylusState& state); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1255 | |
| 1256 | protected: |
| 1257 | CursorButtonAccumulator mCursorButtonAccumulator; |
| 1258 | CursorScrollAccumulator mCursorScrollAccumulator; |
| 1259 | TouchButtonAccumulator mTouchButtonAccumulator; |
| 1260 | |
| 1261 | struct VirtualKey { |
| 1262 | int32_t keyCode; |
| 1263 | int32_t scanCode; |
| 1264 | uint32_t flags; |
| 1265 | |
| 1266 | // computed hit box, specified in touch screen coords based on known display size |
| 1267 | int32_t hitLeft; |
| 1268 | int32_t hitTop; |
| 1269 | int32_t hitRight; |
| 1270 | int32_t hitBottom; |
| 1271 | |
| 1272 | inline bool isHit(int32_t x, int32_t y) const { |
| 1273 | return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom; |
| 1274 | } |
| 1275 | }; |
| 1276 | |
| 1277 | // Input sources and device mode. |
| 1278 | uint32_t mSource; |
| 1279 | |
| 1280 | enum DeviceMode { |
| 1281 | DEVICE_MODE_DISABLED, // input is disabled |
| 1282 | DEVICE_MODE_DIRECT, // direct mapping (touchscreen) |
| 1283 | DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad) |
| 1284 | DEVICE_MODE_NAVIGATION, // unscaled mapping with assist gesture (touch navigation) |
| 1285 | DEVICE_MODE_POINTER, // pointer mapping (pointer) |
| 1286 | }; |
| 1287 | DeviceMode mDeviceMode; |
| 1288 | |
| 1289 | // The reader's configuration. |
| 1290 | InputReaderConfiguration mConfig; |
| 1291 | |
| 1292 | // Immutable configuration parameters. |
| 1293 | struct Parameters { |
| 1294 | enum DeviceType { |
| 1295 | DEVICE_TYPE_TOUCH_SCREEN, |
| 1296 | DEVICE_TYPE_TOUCH_PAD, |
| 1297 | DEVICE_TYPE_TOUCH_NAVIGATION, |
| 1298 | DEVICE_TYPE_POINTER, |
| 1299 | }; |
| 1300 | |
| 1301 | DeviceType deviceType; |
| 1302 | bool hasAssociatedDisplay; |
| 1303 | bool associatedDisplayIsExternal; |
| 1304 | bool orientationAware; |
| 1305 | bool hasButtonUnderPad; |
| 1306 | |
| 1307 | enum GestureMode { |
| 1308 | GESTURE_MODE_POINTER, |
| 1309 | GESTURE_MODE_SPOTS, |
| 1310 | }; |
| 1311 | GestureMode gestureMode; |
Jeff Brown | c5e2442 | 2014-02-26 18:48:51 -0800 | [diff] [blame] | 1312 | |
| 1313 | bool wake; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1314 | } mParameters; |
| 1315 | |
| 1316 | // Immutable calibration parameters in parsed form. |
| 1317 | struct Calibration { |
| 1318 | // Size |
| 1319 | enum SizeCalibration { |
| 1320 | SIZE_CALIBRATION_DEFAULT, |
| 1321 | SIZE_CALIBRATION_NONE, |
| 1322 | SIZE_CALIBRATION_GEOMETRIC, |
| 1323 | SIZE_CALIBRATION_DIAMETER, |
| 1324 | SIZE_CALIBRATION_BOX, |
| 1325 | SIZE_CALIBRATION_AREA, |
| 1326 | }; |
| 1327 | |
| 1328 | SizeCalibration sizeCalibration; |
| 1329 | |
| 1330 | bool haveSizeScale; |
| 1331 | float sizeScale; |
| 1332 | bool haveSizeBias; |
| 1333 | float sizeBias; |
| 1334 | bool haveSizeIsSummed; |
| 1335 | bool sizeIsSummed; |
| 1336 | |
| 1337 | // Pressure |
| 1338 | enum PressureCalibration { |
| 1339 | PRESSURE_CALIBRATION_DEFAULT, |
| 1340 | PRESSURE_CALIBRATION_NONE, |
| 1341 | PRESSURE_CALIBRATION_PHYSICAL, |
| 1342 | PRESSURE_CALIBRATION_AMPLITUDE, |
| 1343 | }; |
| 1344 | |
| 1345 | PressureCalibration pressureCalibration; |
| 1346 | bool havePressureScale; |
| 1347 | float pressureScale; |
| 1348 | |
| 1349 | // Orientation |
| 1350 | enum OrientationCalibration { |
| 1351 | ORIENTATION_CALIBRATION_DEFAULT, |
| 1352 | ORIENTATION_CALIBRATION_NONE, |
| 1353 | ORIENTATION_CALIBRATION_INTERPOLATED, |
| 1354 | ORIENTATION_CALIBRATION_VECTOR, |
| 1355 | }; |
| 1356 | |
| 1357 | OrientationCalibration orientationCalibration; |
| 1358 | |
| 1359 | // Distance |
| 1360 | enum DistanceCalibration { |
| 1361 | DISTANCE_CALIBRATION_DEFAULT, |
| 1362 | DISTANCE_CALIBRATION_NONE, |
| 1363 | DISTANCE_CALIBRATION_SCALED, |
| 1364 | }; |
| 1365 | |
| 1366 | DistanceCalibration distanceCalibration; |
| 1367 | bool haveDistanceScale; |
| 1368 | float distanceScale; |
| 1369 | |
| 1370 | enum CoverageCalibration { |
| 1371 | COVERAGE_CALIBRATION_DEFAULT, |
| 1372 | COVERAGE_CALIBRATION_NONE, |
| 1373 | COVERAGE_CALIBRATION_BOX, |
| 1374 | }; |
| 1375 | |
| 1376 | CoverageCalibration coverageCalibration; |
| 1377 | |
| 1378 | inline void applySizeScaleAndBias(float* outSize) const { |
| 1379 | if (haveSizeScale) { |
| 1380 | *outSize *= sizeScale; |
| 1381 | } |
| 1382 | if (haveSizeBias) { |
| 1383 | *outSize += sizeBias; |
| 1384 | } |
| 1385 | if (*outSize < 0) { |
| 1386 | *outSize = 0; |
| 1387 | } |
| 1388 | } |
| 1389 | } mCalibration; |
| 1390 | |
Jason Gerecke | af126fb | 2012-05-10 14:22:47 -0700 | [diff] [blame] | 1391 | // Affine location transformation/calibration |
| 1392 | struct TouchAffineTransformation mAffineTransform; |
| 1393 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1394 | RawPointerAxes mRawPointerAxes; |
| 1395 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1396 | struct RawState { |
| 1397 | nsecs_t when; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1398 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1399 | // Raw pointer sample data. |
| 1400 | RawPointerData rawPointerData; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1401 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1402 | int32_t buttonState; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1403 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1404 | // Scroll state. |
| 1405 | int32_t rawVScroll; |
| 1406 | int32_t rawHScroll; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1407 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1408 | void copyFrom(const RawState& other) { |
| 1409 | when = other.when; |
| 1410 | rawPointerData.copyFrom(other.rawPointerData); |
| 1411 | buttonState = other.buttonState; |
| 1412 | rawVScroll = other.rawVScroll; |
| 1413 | rawHScroll = other.rawHScroll; |
| 1414 | } |
| 1415 | |
| 1416 | void clear() { |
| 1417 | when = 0; |
| 1418 | rawPointerData.clear(); |
| 1419 | buttonState = 0; |
| 1420 | rawVScroll = 0; |
| 1421 | rawHScroll = 0; |
| 1422 | } |
| 1423 | }; |
| 1424 | |
| 1425 | struct CookedState { |
| 1426 | // Cooked pointer sample data. |
| 1427 | CookedPointerData cookedPointerData; |
| 1428 | |
| 1429 | // Id bits used to differentiate fingers, stylus and mouse tools. |
| 1430 | BitSet32 fingerIdBits; |
| 1431 | BitSet32 stylusIdBits; |
| 1432 | BitSet32 mouseIdBits; |
| 1433 | |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 1434 | int32_t buttonState; |
| 1435 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1436 | void copyFrom(const CookedState& other) { |
| 1437 | cookedPointerData.copyFrom(other.cookedPointerData); |
| 1438 | fingerIdBits = other.fingerIdBits; |
| 1439 | stylusIdBits = other.stylusIdBits; |
| 1440 | mouseIdBits = other.mouseIdBits; |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 1441 | buttonState = other.buttonState; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | void clear() { |
| 1445 | cookedPointerData.clear(); |
| 1446 | fingerIdBits.clear(); |
| 1447 | stylusIdBits.clear(); |
| 1448 | mouseIdBits.clear(); |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 1449 | buttonState = 0; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1450 | } |
| 1451 | }; |
| 1452 | |
| 1453 | Vector<RawState> mRawStatesPending; |
| 1454 | RawState mCurrentRawState; |
| 1455 | CookedState mCurrentCookedState; |
| 1456 | RawState mLastRawState; |
| 1457 | CookedState mLastCookedState; |
| 1458 | |
| 1459 | // State provided by an external stylus |
| 1460 | StylusState mExternalStylusState; |
| 1461 | int64_t mExternalStylusId; |
Michael Wright | 43fd19f | 2015-04-21 19:02:58 +0100 | [diff] [blame] | 1462 | nsecs_t mExternalStylusFusionTimeout; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1463 | bool mExternalStylusDataPending; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1464 | |
| 1465 | // True if we sent a HOVER_ENTER event. |
| 1466 | bool mSentHoverEnter; |
| 1467 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1468 | // Have we assigned pointer IDs for this stream |
| 1469 | bool mHavePointerIds; |
| 1470 | |
Michael Wright | 8e81282 | 2015-06-22 16:18:21 +0100 | [diff] [blame] | 1471 | // Is the current stream of direct touch events aborted |
| 1472 | bool mCurrentMotionAborted; |
| 1473 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1474 | // The time the primary pointer last went down. |
| 1475 | nsecs_t mDownTime; |
| 1476 | |
| 1477 | // The pointer controller, or null if the device is not a pointer. |
| 1478 | sp<PointerControllerInterface> mPointerController; |
| 1479 | |
| 1480 | Vector<VirtualKey> mVirtualKeys; |
| 1481 | |
| 1482 | virtual void configureParameters(); |
| 1483 | virtual void dumpParameters(String8& dump); |
| 1484 | virtual void configureRawPointerAxes(); |
| 1485 | virtual void dumpRawPointerAxes(String8& dump); |
| 1486 | virtual void configureSurface(nsecs_t when, bool* outResetNeeded); |
| 1487 | virtual void dumpSurface(String8& dump); |
| 1488 | virtual void configureVirtualKeys(); |
| 1489 | virtual void dumpVirtualKeys(String8& dump); |
| 1490 | virtual void parseCalibration(); |
| 1491 | virtual void resolveCalibration(); |
| 1492 | virtual void dumpCalibration(String8& dump); |
Jason Gerecke | 12d6baa | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 1493 | virtual void updateAffineTransformation(); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1494 | virtual void dumpAffineTransformation(String8& dump); |
| 1495 | virtual void resolveExternalStylusPresence(); |
| 1496 | virtual bool hasStylus() const = 0; |
| 1497 | virtual bool hasExternalStylus() const; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1498 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1499 | virtual void syncTouch(nsecs_t when, RawState* outState) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1500 | |
| 1501 | private: |
| 1502 | // The current viewport. |
| 1503 | // The components of the viewport are specified in the display's rotated orientation. |
| 1504 | DisplayViewport mViewport; |
| 1505 | |
| 1506 | // The surface orientation, width and height set by configureSurface(). |
| 1507 | // The width and height are derived from the viewport but are specified |
| 1508 | // in the natural orientation. |
| 1509 | // The surface origin specifies how the surface coordinates should be translated |
| 1510 | // to align with the logical display coordinate space. |
| 1511 | // The orientation may be different from the viewport orientation as it specifies |
| 1512 | // the rotation of the surface coordinates required to produce the viewport's |
| 1513 | // requested orientation, so it will depend on whether the device is orientation aware. |
| 1514 | int32_t mSurfaceWidth; |
| 1515 | int32_t mSurfaceHeight; |
| 1516 | int32_t mSurfaceLeft; |
| 1517 | int32_t mSurfaceTop; |
| 1518 | int32_t mSurfaceOrientation; |
| 1519 | |
| 1520 | // Translation and scaling factors, orientation-independent. |
| 1521 | float mXTranslate; |
| 1522 | float mXScale; |
| 1523 | float mXPrecision; |
| 1524 | |
| 1525 | float mYTranslate; |
| 1526 | float mYScale; |
| 1527 | float mYPrecision; |
| 1528 | |
| 1529 | float mGeometricScale; |
| 1530 | |
| 1531 | float mPressureScale; |
| 1532 | |
| 1533 | float mSizeScale; |
| 1534 | |
| 1535 | float mOrientationScale; |
| 1536 | |
| 1537 | float mDistanceScale; |
| 1538 | |
| 1539 | bool mHaveTilt; |
| 1540 | float mTiltXCenter; |
| 1541 | float mTiltXScale; |
| 1542 | float mTiltYCenter; |
| 1543 | float mTiltYScale; |
| 1544 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1545 | bool mExternalStylusConnected; |
| 1546 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1547 | // Oriented motion ranges for input device info. |
| 1548 | struct OrientedRanges { |
| 1549 | InputDeviceInfo::MotionRange x; |
| 1550 | InputDeviceInfo::MotionRange y; |
| 1551 | InputDeviceInfo::MotionRange pressure; |
| 1552 | |
| 1553 | bool haveSize; |
| 1554 | InputDeviceInfo::MotionRange size; |
| 1555 | |
| 1556 | bool haveTouchSize; |
| 1557 | InputDeviceInfo::MotionRange touchMajor; |
| 1558 | InputDeviceInfo::MotionRange touchMinor; |
| 1559 | |
| 1560 | bool haveToolSize; |
| 1561 | InputDeviceInfo::MotionRange toolMajor; |
| 1562 | InputDeviceInfo::MotionRange toolMinor; |
| 1563 | |
| 1564 | bool haveOrientation; |
| 1565 | InputDeviceInfo::MotionRange orientation; |
| 1566 | |
| 1567 | bool haveDistance; |
| 1568 | InputDeviceInfo::MotionRange distance; |
| 1569 | |
| 1570 | bool haveTilt; |
| 1571 | InputDeviceInfo::MotionRange tilt; |
| 1572 | |
| 1573 | OrientedRanges() { |
| 1574 | clear(); |
| 1575 | } |
| 1576 | |
| 1577 | void clear() { |
| 1578 | haveSize = false; |
| 1579 | haveTouchSize = false; |
| 1580 | haveToolSize = false; |
| 1581 | haveOrientation = false; |
| 1582 | haveDistance = false; |
| 1583 | haveTilt = false; |
| 1584 | } |
| 1585 | } mOrientedRanges; |
| 1586 | |
| 1587 | // Oriented dimensions and precision. |
| 1588 | float mOrientedXPrecision; |
| 1589 | float mOrientedYPrecision; |
| 1590 | |
| 1591 | struct CurrentVirtualKeyState { |
| 1592 | bool down; |
| 1593 | bool ignored; |
| 1594 | nsecs_t downTime; |
| 1595 | int32_t keyCode; |
| 1596 | int32_t scanCode; |
| 1597 | } mCurrentVirtualKey; |
| 1598 | |
| 1599 | // Scale factor for gesture or mouse based pointer movements. |
| 1600 | float mPointerXMovementScale; |
| 1601 | float mPointerYMovementScale; |
| 1602 | |
| 1603 | // Scale factor for gesture based zooming and other freeform motions. |
| 1604 | float mPointerXZoomScale; |
| 1605 | float mPointerYZoomScale; |
| 1606 | |
| 1607 | // The maximum swipe width. |
| 1608 | float mPointerGestureMaxSwipeWidth; |
| 1609 | |
| 1610 | struct PointerDistanceHeapElement { |
| 1611 | uint32_t currentPointerIndex : 8; |
| 1612 | uint32_t lastPointerIndex : 8; |
| 1613 | uint64_t distance : 48; // squared distance |
| 1614 | }; |
| 1615 | |
| 1616 | enum PointerUsage { |
| 1617 | POINTER_USAGE_NONE, |
| 1618 | POINTER_USAGE_GESTURES, |
| 1619 | POINTER_USAGE_STYLUS, |
| 1620 | POINTER_USAGE_MOUSE, |
| 1621 | }; |
| 1622 | PointerUsage mPointerUsage; |
| 1623 | |
| 1624 | struct PointerGesture { |
| 1625 | enum Mode { |
| 1626 | // No fingers, button is not pressed. |
| 1627 | // Nothing happening. |
| 1628 | NEUTRAL, |
| 1629 | |
| 1630 | // No fingers, button is not pressed. |
| 1631 | // Tap detected. |
| 1632 | // Emits DOWN and UP events at the pointer location. |
| 1633 | TAP, |
| 1634 | |
| 1635 | // Exactly one finger dragging following a tap. |
| 1636 | // Pointer follows the active finger. |
| 1637 | // Emits DOWN, MOVE and UP events at the pointer location. |
| 1638 | // |
| 1639 | // Detect double-taps when the finger goes up while in TAP_DRAG mode. |
| 1640 | TAP_DRAG, |
| 1641 | |
| 1642 | // Button is pressed. |
| 1643 | // Pointer follows the active finger if there is one. Other fingers are ignored. |
| 1644 | // Emits DOWN, MOVE and UP events at the pointer location. |
| 1645 | BUTTON_CLICK_OR_DRAG, |
| 1646 | |
| 1647 | // Exactly one finger, button is not pressed. |
| 1648 | // Pointer follows the active finger. |
| 1649 | // Emits HOVER_MOVE events at the pointer location. |
| 1650 | // |
| 1651 | // Detect taps when the finger goes up while in HOVER mode. |
| 1652 | HOVER, |
| 1653 | |
| 1654 | // Exactly two fingers but neither have moved enough to clearly indicate |
| 1655 | // whether a swipe or freeform gesture was intended. We consider the |
| 1656 | // pointer to be pressed so this enables clicking or long-pressing on buttons. |
| 1657 | // Pointer does not move. |
| 1658 | // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate. |
| 1659 | PRESS, |
| 1660 | |
| 1661 | // Exactly two fingers moving in the same direction, button is not pressed. |
| 1662 | // Pointer does not move. |
| 1663 | // Emits DOWN, MOVE and UP events with a single pointer coordinate that |
| 1664 | // follows the midpoint between both fingers. |
| 1665 | SWIPE, |
| 1666 | |
| 1667 | // Two or more fingers moving in arbitrary directions, button is not pressed. |
| 1668 | // Pointer does not move. |
| 1669 | // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow |
| 1670 | // each finger individually relative to the initial centroid of the finger. |
| 1671 | FREEFORM, |
| 1672 | |
| 1673 | // Waiting for quiet time to end before starting the next gesture. |
| 1674 | QUIET, |
| 1675 | }; |
| 1676 | |
| 1677 | // Time the first finger went down. |
| 1678 | nsecs_t firstTouchTime; |
| 1679 | |
| 1680 | // The active pointer id from the raw touch data. |
| 1681 | int32_t activeTouchId; // -1 if none |
| 1682 | |
| 1683 | // The active pointer id from the gesture last delivered to the application. |
| 1684 | int32_t activeGestureId; // -1 if none |
| 1685 | |
| 1686 | // Pointer coords and ids for the current and previous pointer gesture. |
| 1687 | Mode currentGestureMode; |
| 1688 | BitSet32 currentGestureIdBits; |
| 1689 | uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1]; |
| 1690 | PointerProperties currentGestureProperties[MAX_POINTERS]; |
| 1691 | PointerCoords currentGestureCoords[MAX_POINTERS]; |
| 1692 | |
| 1693 | Mode lastGestureMode; |
| 1694 | BitSet32 lastGestureIdBits; |
| 1695 | uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1]; |
| 1696 | PointerProperties lastGestureProperties[MAX_POINTERS]; |
| 1697 | PointerCoords lastGestureCoords[MAX_POINTERS]; |
| 1698 | |
| 1699 | // Time the pointer gesture last went down. |
| 1700 | nsecs_t downTime; |
| 1701 | |
| 1702 | // Time when the pointer went down for a TAP. |
| 1703 | nsecs_t tapDownTime; |
| 1704 | |
| 1705 | // Time when the pointer went up for a TAP. |
| 1706 | nsecs_t tapUpTime; |
| 1707 | |
| 1708 | // Location of initial tap. |
| 1709 | float tapX, tapY; |
| 1710 | |
| 1711 | // Time we started waiting for quiescence. |
| 1712 | nsecs_t quietTime; |
| 1713 | |
| 1714 | // Reference points for multitouch gestures. |
| 1715 | float referenceTouchX; // reference touch X/Y coordinates in surface units |
| 1716 | float referenceTouchY; |
| 1717 | float referenceGestureX; // reference gesture X/Y coordinates in pixels |
| 1718 | float referenceGestureY; |
| 1719 | |
| 1720 | // Distance that each pointer has traveled which has not yet been |
| 1721 | // subsumed into the reference gesture position. |
| 1722 | BitSet32 referenceIdBits; |
| 1723 | struct Delta { |
| 1724 | float dx, dy; |
| 1725 | }; |
| 1726 | Delta referenceDeltas[MAX_POINTER_ID + 1]; |
| 1727 | |
| 1728 | // Describes how touch ids are mapped to gesture ids for freeform gestures. |
| 1729 | uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1]; |
| 1730 | |
| 1731 | // A velocity tracker for determining whether to switch active pointers during drags. |
| 1732 | VelocityTracker velocityTracker; |
| 1733 | |
| 1734 | void reset() { |
| 1735 | firstTouchTime = LLONG_MIN; |
| 1736 | activeTouchId = -1; |
| 1737 | activeGestureId = -1; |
| 1738 | currentGestureMode = NEUTRAL; |
| 1739 | currentGestureIdBits.clear(); |
| 1740 | lastGestureMode = NEUTRAL; |
| 1741 | lastGestureIdBits.clear(); |
| 1742 | downTime = 0; |
| 1743 | velocityTracker.clear(); |
| 1744 | resetTap(); |
| 1745 | resetQuietTime(); |
| 1746 | } |
| 1747 | |
| 1748 | void resetTap() { |
| 1749 | tapDownTime = LLONG_MIN; |
| 1750 | tapUpTime = LLONG_MIN; |
| 1751 | } |
| 1752 | |
| 1753 | void resetQuietTime() { |
| 1754 | quietTime = LLONG_MIN; |
| 1755 | } |
| 1756 | } mPointerGesture; |
| 1757 | |
| 1758 | struct PointerSimple { |
| 1759 | PointerCoords currentCoords; |
| 1760 | PointerProperties currentProperties; |
| 1761 | PointerCoords lastCoords; |
| 1762 | PointerProperties lastProperties; |
| 1763 | |
| 1764 | // True if the pointer is down. |
| 1765 | bool down; |
| 1766 | |
| 1767 | // True if the pointer is hovering. |
| 1768 | bool hovering; |
| 1769 | |
| 1770 | // Time the pointer last went down. |
| 1771 | nsecs_t downTime; |
| 1772 | |
| 1773 | void reset() { |
| 1774 | currentCoords.clear(); |
| 1775 | currentProperties.clear(); |
| 1776 | lastCoords.clear(); |
| 1777 | lastProperties.clear(); |
| 1778 | down = false; |
| 1779 | hovering = false; |
| 1780 | downTime = 0; |
| 1781 | } |
| 1782 | } mPointerSimple; |
| 1783 | |
| 1784 | // The pointer and scroll velocity controls. |
| 1785 | VelocityControl mPointerVelocityControl; |
| 1786 | VelocityControl mWheelXVelocityControl; |
| 1787 | VelocityControl mWheelYVelocityControl; |
| 1788 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1789 | void resetExternalStylus(); |
Michael Wright | 43fd19f | 2015-04-21 19:02:58 +0100 | [diff] [blame] | 1790 | void clearStylusDataPendingFlags(); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1791 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1792 | void sync(nsecs_t when); |
| 1793 | |
| 1794 | bool consumeRawTouches(nsecs_t when, uint32_t policyFlags); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1795 | void processRawTouches(bool timeout); |
| 1796 | void cookAndDispatch(nsecs_t when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1797 | void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags, |
| 1798 | int32_t keyEventAction, int32_t keyEventFlags); |
| 1799 | |
| 1800 | void dispatchTouches(nsecs_t when, uint32_t policyFlags); |
| 1801 | void dispatchHoverExit(nsecs_t when, uint32_t policyFlags); |
| 1802 | void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags); |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 1803 | void dispatchButtonRelease(nsecs_t when, uint32_t policyFlags); |
| 1804 | void dispatchButtonPress(nsecs_t when, uint32_t policyFlags); |
| 1805 | const BitSet32& findActiveIdBits(const CookedPointerData& cookedPointerData); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1806 | void cookPointerData(); |
Michael Wright | 8e81282 | 2015-06-22 16:18:21 +0100 | [diff] [blame] | 1807 | void abortTouches(nsecs_t when, uint32_t policyFlags); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1808 | |
| 1809 | void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage); |
| 1810 | void abortPointerUsage(nsecs_t when, uint32_t policyFlags); |
| 1811 | |
| 1812 | void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout); |
| 1813 | void abortPointerGestures(nsecs_t when, uint32_t policyFlags); |
| 1814 | bool preparePointerGestures(nsecs_t when, |
| 1815 | bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, |
| 1816 | bool isTimeout); |
| 1817 | |
| 1818 | void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags); |
| 1819 | void abortPointerStylus(nsecs_t when, uint32_t policyFlags); |
| 1820 | |
| 1821 | void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags); |
| 1822 | void abortPointerMouse(nsecs_t when, uint32_t policyFlags); |
| 1823 | |
| 1824 | void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, |
| 1825 | bool down, bool hovering); |
| 1826 | void abortPointerSimple(nsecs_t when, uint32_t policyFlags); |
| 1827 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1828 | bool assignExternalStylusId(const RawState& state, bool timeout); |
| 1829 | void applyExternalStylusButtonState(nsecs_t when); |
| 1830 | void applyExternalStylusTouchState(nsecs_t when); |
| 1831 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1832 | // Dispatches a motion event. |
| 1833 | // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the |
| 1834 | // method will take care of setting the index and transmuting the action to DOWN or UP |
| 1835 | // it is the first / last pointer to go down / up. |
| 1836 | void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source, |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 1837 | int32_t action, int32_t actionButton, |
| 1838 | int32_t flags, int32_t metaState, int32_t buttonState, int32_t edgeFlags, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1839 | const PointerProperties* properties, const PointerCoords* coords, |
| 1840 | const uint32_t* idToIndex, BitSet32 idBits, |
| 1841 | int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime); |
| 1842 | |
| 1843 | // Updates pointer coords and properties for pointers with specified ids that have moved. |
| 1844 | // Returns true if any of them changed. |
| 1845 | bool updateMovedPointers(const PointerProperties* inProperties, |
| 1846 | const PointerCoords* inCoords, const uint32_t* inIdToIndex, |
| 1847 | PointerProperties* outProperties, PointerCoords* outCoords, |
| 1848 | const uint32_t* outIdToIndex, BitSet32 idBits) const; |
| 1849 | |
| 1850 | bool isPointInsideSurface(int32_t x, int32_t y); |
| 1851 | const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y); |
| 1852 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1853 | static void assignPointerIds(const RawState* last, RawState* current); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1854 | }; |
| 1855 | |
| 1856 | |
| 1857 | class SingleTouchInputMapper : public TouchInputMapper { |
| 1858 | public: |
| 1859 | SingleTouchInputMapper(InputDevice* device); |
| 1860 | virtual ~SingleTouchInputMapper(); |
| 1861 | |
| 1862 | virtual void reset(nsecs_t when); |
| 1863 | virtual void process(const RawEvent* rawEvent); |
| 1864 | |
| 1865 | protected: |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1866 | virtual void syncTouch(nsecs_t when, RawState* outState); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1867 | virtual void configureRawPointerAxes(); |
| 1868 | virtual bool hasStylus() const; |
| 1869 | |
| 1870 | private: |
| 1871 | SingleTouchMotionAccumulator mSingleTouchMotionAccumulator; |
| 1872 | }; |
| 1873 | |
| 1874 | |
| 1875 | class MultiTouchInputMapper : public TouchInputMapper { |
| 1876 | public: |
| 1877 | MultiTouchInputMapper(InputDevice* device); |
| 1878 | virtual ~MultiTouchInputMapper(); |
| 1879 | |
| 1880 | virtual void reset(nsecs_t when); |
| 1881 | virtual void process(const RawEvent* rawEvent); |
| 1882 | |
| 1883 | protected: |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1884 | virtual void syncTouch(nsecs_t when, RawState* outState); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1885 | virtual void configureRawPointerAxes(); |
| 1886 | virtual bool hasStylus() const; |
| 1887 | |
| 1888 | private: |
| 1889 | MultiTouchMotionAccumulator mMultiTouchMotionAccumulator; |
| 1890 | |
| 1891 | // Specifies the pointer id bits that are in use, and their associated tracking id. |
| 1892 | BitSet32 mPointerIdBits; |
| 1893 | int32_t mPointerTrackingIdMap[MAX_POINTER_ID + 1]; |
| 1894 | }; |
| 1895 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1896 | class ExternalStylusInputMapper : public InputMapper { |
| 1897 | public: |
| 1898 | ExternalStylusInputMapper(InputDevice* device); |
| 1899 | virtual ~ExternalStylusInputMapper() = default; |
| 1900 | |
| 1901 | virtual uint32_t getSources(); |
| 1902 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
| 1903 | virtual void dump(String8& dump); |
| 1904 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 1905 | virtual void reset(nsecs_t when); |
| 1906 | virtual void process(const RawEvent* rawEvent); |
| 1907 | virtual void sync(nsecs_t when); |
| 1908 | |
| 1909 | private: |
| 1910 | SingleTouchMotionAccumulator mSingleTouchMotionAccumulator; |
| 1911 | RawAbsoluteAxisInfo mRawPressureAxis; |
| 1912 | TouchButtonAccumulator mTouchButtonAccumulator; |
| 1913 | |
| 1914 | StylusState mStylusState; |
| 1915 | }; |
| 1916 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1917 | |
| 1918 | class JoystickInputMapper : public InputMapper { |
| 1919 | public: |
| 1920 | JoystickInputMapper(InputDevice* device); |
| 1921 | virtual ~JoystickInputMapper(); |
| 1922 | |
| 1923 | virtual uint32_t getSources(); |
| 1924 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
| 1925 | virtual void dump(String8& dump); |
| 1926 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 1927 | virtual void reset(nsecs_t when); |
| 1928 | virtual void process(const RawEvent* rawEvent); |
| 1929 | |
| 1930 | private: |
| 1931 | struct Axis { |
| 1932 | RawAbsoluteAxisInfo rawAxisInfo; |
| 1933 | AxisInfo axisInfo; |
| 1934 | |
| 1935 | bool explicitlyMapped; // true if the axis was explicitly assigned an axis id |
| 1936 | |
| 1937 | float scale; // scale factor from raw to normalized values |
| 1938 | float offset; // offset to add after scaling for normalization |
| 1939 | float highScale; // scale factor from raw to normalized values of high split |
| 1940 | float highOffset; // offset to add after scaling for normalization of high split |
| 1941 | |
| 1942 | float min; // normalized inclusive minimum |
| 1943 | float max; // normalized inclusive maximum |
| 1944 | float flat; // normalized flat region size |
| 1945 | float fuzz; // normalized error tolerance |
| 1946 | float resolution; // normalized resolution in units/mm |
| 1947 | |
| 1948 | float filter; // filter out small variations of this size |
| 1949 | float currentValue; // current value |
| 1950 | float newValue; // most recent value |
| 1951 | float highCurrentValue; // current value of high split |
| 1952 | float highNewValue; // most recent value of high split |
| 1953 | |
| 1954 | void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo, |
| 1955 | bool explicitlyMapped, float scale, float offset, |
| 1956 | float highScale, float highOffset, |
| 1957 | float min, float max, float flat, float fuzz, float resolution) { |
| 1958 | this->rawAxisInfo = rawAxisInfo; |
| 1959 | this->axisInfo = axisInfo; |
| 1960 | this->explicitlyMapped = explicitlyMapped; |
| 1961 | this->scale = scale; |
| 1962 | this->offset = offset; |
| 1963 | this->highScale = highScale; |
| 1964 | this->highOffset = highOffset; |
| 1965 | this->min = min; |
| 1966 | this->max = max; |
| 1967 | this->flat = flat; |
| 1968 | this->fuzz = fuzz; |
| 1969 | this->resolution = resolution; |
| 1970 | this->filter = 0; |
| 1971 | resetValue(); |
| 1972 | } |
| 1973 | |
| 1974 | void resetValue() { |
| 1975 | this->currentValue = 0; |
| 1976 | this->newValue = 0; |
| 1977 | this->highCurrentValue = 0; |
| 1978 | this->highNewValue = 0; |
| 1979 | } |
| 1980 | }; |
| 1981 | |
| 1982 | // Axes indexed by raw ABS_* axis index. |
| 1983 | KeyedVector<int32_t, Axis> mAxes; |
| 1984 | |
| 1985 | void sync(nsecs_t when, bool force); |
| 1986 | |
| 1987 | bool haveAxis(int32_t axisId); |
| 1988 | void pruneAxes(bool ignoreExplicitlyMappedAxes); |
| 1989 | bool filterAxes(bool force); |
| 1990 | |
| 1991 | static bool hasValueChangedSignificantly(float filter, |
| 1992 | float newValue, float currentValue, float min, float max); |
| 1993 | static bool hasMovedNearerToValueWithinFilteredRange(float filter, |
| 1994 | float newValue, float currentValue, float thresholdValue); |
| 1995 | |
| 1996 | static bool isCenteredAxis(int32_t axis); |
| 1997 | static int32_t getCompatAxis(int32_t axis); |
| 1998 | |
| 1999 | static void addMotionRange(int32_t axisId, const Axis& axis, InputDeviceInfo* info); |
| 2000 | static void setPointerCoordsAxisValue(PointerCoords* pointerCoords, int32_t axis, |
| 2001 | float value); |
| 2002 | }; |
| 2003 | |
| 2004 | } // namespace android |
| 2005 | |
| 2006 | #endif // _UI_INPUT_READER_H |