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