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