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