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