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