Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _UI_INPUT_READER_H |
| 18 | #define _UI_INPUT_READER_H |
| 19 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 20 | #include "EventHub.h" |
| 21 | #include "InputDispatcher.h" |
| 22 | #include "PointerController.h" |
| 23 | |
Jeff Brown | 46b9ac0 | 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 | 46b9ac0 | 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 | 46b9ac0 | 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 { |
| 48 | // Determines whether to turn on some hacks we have to improve the touch interaction with a |
| 49 | // certain device whose screen currently is not all that good. |
| 50 | bool filterTouchEvents; |
| 51 | |
| 52 | // Determines whether to turn on some hacks to improve touch interaction with another device |
| 53 | // where touch coordinate data can get corrupted. |
| 54 | bool filterJumpyTouchEvents; |
| 55 | |
| 56 | // Gets the amount of time to disable virtual keys after the screen is touched |
| 57 | // in order to filter out accidental virtual key presses due to swiping gestures |
| 58 | // or taps near the edge of the display. May be 0 to disable the feature. |
| 59 | nsecs_t virtualKeyQuietTime; |
| 60 | |
| 61 | // The excluded device names for the platform. |
| 62 | // Devices with these names will be ignored. |
| 63 | Vector<String8> excludedDeviceNames; |
| 64 | |
Jeff Brown | 19c97d46 | 2011-06-01 12:33:19 -0700 | [diff] [blame] | 65 | // Velocity control parameters for mouse pointer movements. |
| 66 | VelocityControlParameters pointerVelocityControlParameters; |
| 67 | |
| 68 | // Velocity control parameters for mouse wheel movements. |
| 69 | VelocityControlParameters wheelVelocityControlParameters; |
| 70 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 71 | // Quiet time between certain pointer gesture transitions. |
| 72 | // Time to allow for all fingers or buttons to settle into a stable state before |
| 73 | // starting a new gesture. |
| 74 | nsecs_t pointerGestureQuietInterval; |
| 75 | |
| 76 | // The minimum speed that a pointer must travel for us to consider switching the active |
| 77 | // touch pointer to it during a drag. This threshold is set to avoid switching due |
| 78 | // to noise from a finger resting on the touch pad (perhaps just pressing it down). |
| 79 | float pointerGestureDragMinSwitchSpeed; // in pixels per second |
| 80 | |
| 81 | // Tap gesture delay time. |
| 82 | // The time between down and up must be less than this to be considered a tap. |
| 83 | nsecs_t pointerGestureTapInterval; |
| 84 | |
| 85 | // Tap drag gesture delay time. |
| 86 | // The time between the previous tap's up and the next down must be less than |
| 87 | // this to be considered a drag. Otherwise, the previous tap is finished and a |
| 88 | // new tap begins. |
| 89 | // |
| 90 | // Note that the previous tap will be held down for this entire duration so this |
| 91 | // interval must be shorter than the long press timeout. |
| 92 | nsecs_t pointerGestureTapDragInterval; |
| 93 | |
| 94 | // The distance in pixels that the pointer is allowed to move from initial down |
| 95 | // to up and still be called a tap. |
| 96 | float pointerGestureTapSlop; // in pixels |
| 97 | |
| 98 | // Time after the first touch points go down to settle on an initial centroid. |
| 99 | // This is intended to be enough time to handle cases where the user puts down two |
| 100 | // fingers at almost but not quite exactly the same time. |
| 101 | nsecs_t pointerGestureMultitouchSettleInterval; |
| 102 | |
| 103 | // 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] | 104 | // at least two pointers have moved at least this far from their starting place. |
| 105 | float pointerGestureMultitouchMinDistance; // in pixels |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 106 | |
| 107 | // The transition from PRESS to SWIPE gesture mode can only occur when the |
| 108 | // cosine of the angle between the two vectors is greater than or equal to than this value |
| 109 | // which indicates that the vectors are oriented in the same direction. |
| 110 | // When the vectors are oriented in the exactly same direction, the cosine is 1.0. |
| 111 | // (In exactly opposite directions, the cosine is -1.0.) |
| 112 | float pointerGestureSwipeTransitionAngleCosine; |
| 113 | |
| 114 | // The transition from PRESS to SWIPE gesture mode can only occur when the |
| 115 | // fingers are no more than this far apart relative to the diagonal size of |
| 116 | // the touch pad. For example, a ratio of 0.5 means that the fingers must be |
| 117 | // no more than half the diagonal size of the touch pad apart. |
| 118 | float pointerGestureSwipeMaxWidthRatio; |
| 119 | |
| 120 | // The gesture movement speed factor relative to the size of the display. |
| 121 | // Movement speed applies when the fingers are moving in the same direction. |
| 122 | // Without acceleration, a full swipe of the touch pad diagonal in movement mode |
| 123 | // will cover this portion of the display diagonal. |
| 124 | float pointerGestureMovementSpeedRatio; |
| 125 | |
| 126 | // The gesture zoom speed factor relative to the size of the display. |
| 127 | // Zoom speed applies when the fingers are mostly moving relative to each other |
| 128 | // to execute a scale gesture or similar. |
| 129 | // Without acceleration, a full swipe of the touch pad diagonal in zoom mode |
| 130 | // will cover this portion of the display diagonal. |
| 131 | float pointerGestureZoomSpeedRatio; |
| 132 | |
| 133 | InputReaderConfiguration() : |
| 134 | filterTouchEvents(false), |
| 135 | filterJumpyTouchEvents(false), |
| 136 | virtualKeyQuietTime(0), |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 137 | pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f), |
Jeff Brown | 19c97d46 | 2011-06-01 12:33:19 -0700 | [diff] [blame] | 138 | wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f), |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 139 | pointerGestureQuietInterval(100 * 1000000LL), // 100 ms |
| 140 | pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second |
| 141 | pointerGestureTapInterval(150 * 1000000LL), // 150 ms |
| 142 | pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms |
| 143 | pointerGestureTapSlop(10.0f), // 10 pixels |
| 144 | pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 145 | pointerGestureMultitouchMinDistance(15), // 15 pixels |
Jeff Brown | 6674d9b | 2011-06-07 16:50:14 -0700 | [diff] [blame] | 146 | pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 147 | pointerGestureSwipeMaxWidthRatio(0.25f), |
| 148 | pointerGestureMovementSpeedRatio(0.8f), |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 149 | pointerGestureZoomSpeedRatio(0.3f) { } |
| 150 | }; |
| 151 | |
| 152 | |
| 153 | /* |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 154 | * Input reader policy interface. |
| 155 | * |
| 156 | * The input reader policy is used by the input reader to interact with the Window Manager |
| 157 | * and other system components. |
| 158 | * |
| 159 | * The actual implementation is partially supported by callbacks into the DVM |
| 160 | * via JNI. This interface is also mocked in the unit tests. |
| 161 | */ |
| 162 | class InputReaderPolicyInterface : public virtual RefBase { |
| 163 | protected: |
| 164 | InputReaderPolicyInterface() { } |
| 165 | virtual ~InputReaderPolicyInterface() { } |
| 166 | |
| 167 | public: |
| 168 | /* Display orientations. */ |
| 169 | enum { |
| 170 | ROTATION_0 = 0, |
| 171 | ROTATION_90 = 1, |
| 172 | ROTATION_180 = 2, |
| 173 | ROTATION_270 = 3 |
| 174 | }; |
| 175 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 176 | /* Gets information about the display with the specified id. |
| 177 | * Returns true if the display info is available, false otherwise. |
| 178 | */ |
| 179 | virtual bool getDisplayInfo(int32_t displayId, |
| 180 | int32_t* width, int32_t* height, int32_t* orientation) = 0; |
| 181 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 182 | /* Gets the input reader configuration. */ |
| 183 | virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 184 | |
| 185 | /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */ |
| 186 | virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | |
| 190 | /* Processes raw input events and sends cooked event data to an input dispatcher. */ |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 191 | class InputReaderInterface : public virtual RefBase { |
| 192 | protected: |
| 193 | InputReaderInterface() { } |
| 194 | virtual ~InputReaderInterface() { } |
| 195 | |
| 196 | public: |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 197 | /* Dumps the state of the input reader. |
| 198 | * |
| 199 | * This method may be called on any thread (usually by the input manager). */ |
| 200 | virtual void dump(String8& dump) = 0; |
| 201 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 202 | /* Runs a single iteration of the processing loop. |
| 203 | * Nominally reads and processes one incoming message from the EventHub. |
| 204 | * |
| 205 | * This method should be called on the input reader thread. |
| 206 | */ |
| 207 | virtual void loopOnce() = 0; |
| 208 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 209 | /* Gets the current input device configuration. |
| 210 | * |
| 211 | * This method may be called on any thread (usually by the input manager). |
| 212 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 213 | virtual void getInputConfiguration(InputConfiguration* outConfiguration) = 0; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 214 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 215 | /* Gets information about the specified input device. |
| 216 | * Returns OK if the device information was obtained or NAME_NOT_FOUND if there |
| 217 | * was no such device. |
| 218 | * |
| 219 | * 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] | 220 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 221 | virtual status_t getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo) = 0; |
| 222 | |
| 223 | /* Gets the list of all registered device ids. */ |
| 224 | virtual void getInputDeviceIds(Vector<int32_t>& outDeviceIds) = 0; |
| 225 | |
| 226 | /* Query current input state. */ |
| 227 | virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, |
| 228 | int32_t scanCode) = 0; |
| 229 | virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, |
| 230 | int32_t keyCode) = 0; |
| 231 | virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, |
| 232 | int32_t sw) = 0; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 233 | |
| 234 | /* Determine whether physical keys exist for the given framework-domain key codes. */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 235 | virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 236 | size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 237 | |
| 238 | /* Reopens and reconfigures all input devices. */ |
| 239 | virtual void refreshConfiguration() = 0; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 240 | }; |
| 241 | |
| 242 | |
| 243 | /* Internal interface used by individual input devices to access global input device state |
| 244 | * and parameters maintained by the input reader. |
| 245 | */ |
| 246 | class InputReaderContext { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 247 | public: |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 248 | InputReaderContext() { } |
| 249 | virtual ~InputReaderContext() { } |
| 250 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 251 | virtual void updateGlobalMetaState() = 0; |
| 252 | virtual int32_t getGlobalMetaState() = 0; |
| 253 | |
Jeff Brown | fe50892 | 2011-01-18 15:10:10 -0800 | [diff] [blame] | 254 | virtual void disableVirtualKeysUntil(nsecs_t time) = 0; |
| 255 | virtual bool shouldDropVirtualKey(nsecs_t now, |
| 256 | InputDevice* device, int32_t keyCode, int32_t scanCode) = 0; |
| 257 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 258 | virtual void fadePointer() = 0; |
| 259 | |
Jeff Brown | 68d6075 | 2011-03-17 01:34:19 -0700 | [diff] [blame] | 260 | virtual void requestTimeoutAtTime(nsecs_t when) = 0; |
| 261 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 262 | virtual InputReaderPolicyInterface* getPolicy() = 0; |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 263 | virtual const InputReaderConfiguration* getConfig() = 0; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 264 | virtual InputDispatcherInterface* getDispatcher() = 0; |
| 265 | virtual EventHubInterface* getEventHub() = 0; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 266 | }; |
| 267 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 268 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 269 | /* 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] | 270 | * that it sends to the input dispatcher. Some functions of the input reader, such as early |
| 271 | * event filtering in low power states, are controlled by a separate policy object. |
| 272 | * |
| 273 | * IMPORTANT INVARIANT: |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 274 | * Because the policy and dispatcher can potentially block or cause re-entrance into |
| 275 | * 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] | 276 | * an exclusive internal lock whenever re-entrance can happen. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 277 | */ |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 278 | class InputReader : public InputReaderInterface, protected InputReaderContext { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 279 | public: |
| 280 | InputReader(const sp<EventHubInterface>& eventHub, |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 281 | const sp<InputReaderPolicyInterface>& policy, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 282 | const sp<InputDispatcherInterface>& dispatcher); |
| 283 | virtual ~InputReader(); |
| 284 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 285 | virtual void dump(String8& dump); |
| 286 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 287 | virtual void loopOnce(); |
| 288 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 289 | virtual void getInputConfiguration(InputConfiguration* outConfiguration); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 290 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 291 | virtual status_t getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo); |
| 292 | virtual void getInputDeviceIds(Vector<int32_t>& outDeviceIds); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 293 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 294 | virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, |
| 295 | int32_t scanCode); |
| 296 | virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, |
| 297 | int32_t keyCode); |
| 298 | virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, |
| 299 | int32_t sw); |
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 bool hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 302 | size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 303 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 304 | virtual void refreshConfiguration(); |
| 305 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 306 | protected: |
| 307 | // These methods are protected virtual so they can be overridden and instrumented |
| 308 | // by test cases. |
| 309 | virtual InputDevice* createDevice(int32_t deviceId, const String8& name, uint32_t classes); |
| 310 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 311 | private: |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 312 | sp<EventHubInterface> mEventHub; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 313 | sp<InputReaderPolicyInterface> mPolicy; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 314 | sp<InputDispatcherInterface> mDispatcher; |
| 315 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 316 | InputReaderConfiguration mConfig; |
| 317 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 318 | virtual InputReaderPolicyInterface* getPolicy() { return mPolicy.get(); } |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 319 | virtual const InputReaderConfiguration* getConfig() { return &mConfig; } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 320 | virtual InputDispatcherInterface* getDispatcher() { return mDispatcher.get(); } |
| 321 | virtual EventHubInterface* getEventHub() { return mEventHub.get(); } |
| 322 | |
Jeff Brown | dbf8d27 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 323 | // The event queue. |
| 324 | static const int EVENT_BUFFER_SIZE = 256; |
| 325 | RawEvent mEventBuffer[EVENT_BUFFER_SIZE]; |
| 326 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 327 | // This reader/writer lock guards the list of input devices. |
| 328 | // The writer lock must be held whenever the list of input devices is modified |
| 329 | // and then promptly released. |
| 330 | // The reader lock must be held whenever the list of input devices is traversed or an |
| 331 | // input device in the list is accessed. |
| 332 | // This lock only protects the registry and prevents inadvertent deletion of device objects |
| 333 | // that are in use. Individual devices are responsible for guarding their own internal state |
| 334 | // as needed for concurrent operation. |
| 335 | RWLock mDeviceRegistryLock; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 336 | KeyedVector<int32_t, InputDevice*> mDevices; |
| 337 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 338 | // low-level input event decoding and device management |
Jeff Brown | dbf8d27 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 339 | void processEvents(const RawEvent* rawEvents, size_t count); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 340 | |
Jeff Brown | 7342bb9 | 2010-10-01 18:55:43 -0700 | [diff] [blame] | 341 | void addDevice(int32_t deviceId); |
| 342 | void removeDevice(int32_t deviceId); |
Jeff Brown | dbf8d27 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 343 | void processEventsForDevice(int32_t deviceId, const RawEvent* rawEvents, size_t count); |
Jeff Brown | 68d6075 | 2011-03-17 01:34:19 -0700 | [diff] [blame] | 344 | void timeoutExpired(nsecs_t when); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 345 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 346 | void handleConfigurationChanged(nsecs_t when); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 347 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 348 | // state management for all devices |
| 349 | Mutex mStateLock; |
| 350 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 351 | int32_t mGlobalMetaState; // guarded by mStateLock |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 352 | virtual void updateGlobalMetaState(); |
| 353 | virtual int32_t getGlobalMetaState(); |
| 354 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 355 | virtual void fadePointer(); |
| 356 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 357 | InputConfiguration mInputConfiguration; // guarded by mStateLock |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 358 | void updateInputConfiguration(); |
| 359 | |
Jeff Brown | dbf8d27 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 360 | nsecs_t mDisableVirtualKeysTimeout; // only accessed by reader thread |
Jeff Brown | fe50892 | 2011-01-18 15:10:10 -0800 | [diff] [blame] | 361 | virtual void disableVirtualKeysUntil(nsecs_t time); |
| 362 | virtual bool shouldDropVirtualKey(nsecs_t now, |
| 363 | InputDevice* device, int32_t keyCode, int32_t scanCode); |
| 364 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 365 | nsecs_t mNextTimeout; // only accessed by reader thread, not guarded |
Jeff Brown | 68d6075 | 2011-03-17 01:34:19 -0700 | [diff] [blame] | 366 | virtual void requestTimeoutAtTime(nsecs_t when); |
| 367 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 368 | volatile int32_t mRefreshConfiguration; // atomic |
| 369 | void configure(bool firstTime); |
| 370 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 371 | // state queries |
| 372 | typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code); |
| 373 | int32_t getState(int32_t deviceId, uint32_t sourceMask, int32_t code, |
| 374 | GetStateFunc getStateFunc); |
| 375 | bool markSupportedKeyCodes(int32_t deviceId, uint32_t sourceMask, size_t numCodes, |
| 376 | const int32_t* keyCodes, uint8_t* outFlags); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 377 | }; |
| 378 | |
| 379 | |
| 380 | /* Reads raw events from the event hub and processes them, endlessly. */ |
| 381 | class InputReaderThread : public Thread { |
| 382 | public: |
| 383 | InputReaderThread(const sp<InputReaderInterface>& reader); |
| 384 | virtual ~InputReaderThread(); |
| 385 | |
| 386 | private: |
| 387 | sp<InputReaderInterface> mReader; |
| 388 | |
| 389 | virtual bool threadLoop(); |
| 390 | }; |
| 391 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 392 | |
| 393 | /* Represents the state of a single input device. */ |
| 394 | class InputDevice { |
| 395 | public: |
| 396 | InputDevice(InputReaderContext* context, int32_t id, const String8& name); |
| 397 | ~InputDevice(); |
| 398 | |
| 399 | inline InputReaderContext* getContext() { return mContext; } |
| 400 | inline int32_t getId() { return mId; } |
| 401 | inline const String8& getName() { return mName; } |
| 402 | inline uint32_t getSources() { return mSources; } |
| 403 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 404 | inline bool isExternal() { return mIsExternal; } |
| 405 | inline void setExternal(bool external) { mIsExternal = external; } |
| 406 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 407 | inline bool isIgnored() { return mMappers.isEmpty(); } |
| 408 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 409 | void dump(String8& dump); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 410 | void addMapper(InputMapper* mapper); |
| 411 | void configure(); |
| 412 | void reset(); |
Jeff Brown | dbf8d27 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 413 | void process(const RawEvent* rawEvents, size_t count); |
Jeff Brown | 68d6075 | 2011-03-17 01:34:19 -0700 | [diff] [blame] | 414 | void timeoutExpired(nsecs_t when); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 415 | |
| 416 | void getDeviceInfo(InputDeviceInfo* outDeviceInfo); |
| 417 | int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 418 | int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 419 | int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 420 | bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 421 | const int32_t* keyCodes, uint8_t* outFlags); |
| 422 | |
| 423 | int32_t getMetaState(); |
| 424 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 425 | void fadePointer(); |
| 426 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 427 | inline const PropertyMap& getConfiguration() { |
| 428 | return mConfiguration; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 431 | private: |
| 432 | InputReaderContext* mContext; |
| 433 | int32_t mId; |
| 434 | |
| 435 | Vector<InputMapper*> mMappers; |
| 436 | |
| 437 | String8 mName; |
| 438 | uint32_t mSources; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 439 | bool mIsExternal; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 440 | |
| 441 | typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code); |
| 442 | int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 443 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 444 | PropertyMap mConfiguration; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | |
| 448 | /* An input mapper transforms raw input events into cooked event data. |
| 449 | * A single input device can have multiple associated input mappers in order to interpret |
| 450 | * different classes of events. |
| 451 | */ |
| 452 | class InputMapper { |
| 453 | public: |
| 454 | InputMapper(InputDevice* device); |
| 455 | virtual ~InputMapper(); |
| 456 | |
| 457 | inline InputDevice* getDevice() { return mDevice; } |
| 458 | inline int32_t getDeviceId() { return mDevice->getId(); } |
| 459 | inline const String8 getDeviceName() { return mDevice->getName(); } |
| 460 | inline InputReaderContext* getContext() { return mContext; } |
| 461 | inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); } |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 462 | inline const InputReaderConfiguration* getConfig() { return mContext->getConfig(); } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 463 | inline InputDispatcherInterface* getDispatcher() { return mContext->getDispatcher(); } |
| 464 | inline EventHubInterface* getEventHub() { return mContext->getEventHub(); } |
| 465 | |
| 466 | virtual uint32_t getSources() = 0; |
| 467 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 468 | virtual void dump(String8& dump); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 469 | virtual void configure(); |
| 470 | virtual void reset(); |
| 471 | virtual void process(const RawEvent* rawEvent) = 0; |
Jeff Brown | 68d6075 | 2011-03-17 01:34:19 -0700 | [diff] [blame] | 472 | virtual void timeoutExpired(nsecs_t when); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 473 | |
| 474 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 475 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 476 | virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 477 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 478 | const int32_t* keyCodes, uint8_t* outFlags); |
| 479 | |
| 480 | virtual int32_t getMetaState(); |
| 481 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 482 | virtual void fadePointer(); |
| 483 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 484 | protected: |
| 485 | InputDevice* mDevice; |
| 486 | InputReaderContext* mContext; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 487 | |
| 488 | static void dumpRawAbsoluteAxisInfo(String8& dump, |
| 489 | const RawAbsoluteAxisInfo& axis, const char* name); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 490 | }; |
| 491 | |
| 492 | |
| 493 | class SwitchInputMapper : public InputMapper { |
| 494 | public: |
| 495 | SwitchInputMapper(InputDevice* device); |
| 496 | virtual ~SwitchInputMapper(); |
| 497 | |
| 498 | virtual uint32_t getSources(); |
| 499 | virtual void process(const RawEvent* rawEvent); |
| 500 | |
| 501 | virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 502 | |
| 503 | private: |
| 504 | void processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue); |
| 505 | }; |
| 506 | |
| 507 | |
| 508 | class KeyboardInputMapper : public InputMapper { |
| 509 | public: |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 510 | KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 511 | virtual ~KeyboardInputMapper(); |
| 512 | |
| 513 | virtual uint32_t getSources(); |
| 514 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 515 | virtual void dump(String8& dump); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 516 | virtual void configure(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 517 | virtual void reset(); |
| 518 | virtual void process(const RawEvent* rawEvent); |
| 519 | |
| 520 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 521 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 522 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 523 | const int32_t* keyCodes, uint8_t* outFlags); |
| 524 | |
| 525 | virtual int32_t getMetaState(); |
| 526 | |
| 527 | private: |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 528 | Mutex mLock; |
| 529 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 530 | struct KeyDown { |
| 531 | int32_t keyCode; |
| 532 | int32_t scanCode; |
| 533 | }; |
| 534 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 535 | uint32_t mSource; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 536 | int32_t mKeyboardType; |
| 537 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 538 | // Immutable configuration parameters. |
| 539 | struct Parameters { |
| 540 | int32_t associatedDisplayId; |
| 541 | bool orientationAware; |
| 542 | } mParameters; |
| 543 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 544 | struct LockedState { |
| 545 | Vector<KeyDown> keyDowns; // keys that are down |
| 546 | int32_t metaState; |
| 547 | nsecs_t downTime; // time of most recent key down |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 548 | |
| 549 | struct LedState { |
| 550 | bool avail; // led is available |
| 551 | bool on; // we think the led is currently on |
| 552 | }; |
| 553 | LedState capsLockLedState; |
| 554 | LedState numLockLedState; |
| 555 | LedState scrollLockLedState; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 556 | } mLocked; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 557 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 558 | void initializeLocked(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 559 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 560 | void configureParameters(); |
| 561 | void dumpParameters(String8& dump); |
| 562 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 563 | bool isKeyboardOrGamepadKey(int32_t scanCode); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 564 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 565 | void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode, |
| 566 | uint32_t policyFlags); |
| 567 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 568 | ssize_t findKeyDownLocked(int32_t scanCode); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 569 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 570 | void resetLedStateLocked(); |
| 571 | void initializeLedStateLocked(LockedState::LedState& ledState, int32_t led); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 572 | void updateLedStateLocked(bool reset); |
| 573 | void updateLedStateForModifierLocked(LockedState::LedState& ledState, int32_t led, |
| 574 | int32_t modifier, bool reset); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 575 | }; |
| 576 | |
| 577 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 578 | class CursorInputMapper : public InputMapper { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 579 | public: |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 580 | CursorInputMapper(InputDevice* device); |
| 581 | virtual ~CursorInputMapper(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 582 | |
| 583 | virtual uint32_t getSources(); |
| 584 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 585 | virtual void dump(String8& dump); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 586 | virtual void configure(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 587 | virtual void reset(); |
| 588 | virtual void process(const RawEvent* rawEvent); |
| 589 | |
Jeff Brown | c3fc2d0 | 2010-08-10 15:47:53 -0700 | [diff] [blame] | 590 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 591 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 592 | virtual void fadePointer(); |
| 593 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 594 | private: |
| 595 | // Amount that trackball needs to move in order to generate a key event. |
| 596 | static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6; |
| 597 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 598 | Mutex mLock; |
| 599 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 600 | // Immutable configuration parameters. |
| 601 | struct Parameters { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 602 | enum Mode { |
| 603 | MODE_POINTER, |
| 604 | MODE_NAVIGATION, |
| 605 | }; |
| 606 | |
| 607 | Mode mode; |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 608 | int32_t associatedDisplayId; |
| 609 | bool orientationAware; |
| 610 | } mParameters; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 611 | |
| 612 | struct Accumulator { |
| 613 | enum { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 614 | FIELD_BUTTONS = 1, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 615 | FIELD_REL_X = 2, |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 616 | FIELD_REL_Y = 4, |
| 617 | FIELD_REL_WHEEL = 8, |
| 618 | FIELD_REL_HWHEEL = 16, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 619 | }; |
| 620 | |
| 621 | uint32_t fields; |
| 622 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 623 | uint32_t buttonDown; |
| 624 | uint32_t buttonUp; |
| 625 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 626 | int32_t relX; |
| 627 | int32_t relY; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 628 | int32_t relWheel; |
| 629 | int32_t relHWheel; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 630 | |
| 631 | inline void clear() { |
| 632 | fields = 0; |
| 633 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 634 | } mAccumulator; |
| 635 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 636 | int32_t mSource; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 637 | float mXScale; |
| 638 | float mYScale; |
| 639 | float mXPrecision; |
| 640 | float mYPrecision; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 641 | |
| 642 | bool mHaveVWheel; |
| 643 | bool mHaveHWheel; |
| 644 | float mVWheelScale; |
| 645 | float mHWheelScale; |
| 646 | |
Jeff Brown | 19c97d46 | 2011-06-01 12:33:19 -0700 | [diff] [blame] | 647 | // Velocity controls for mouse pointer and wheel movements. |
| 648 | // The controls for X and Y wheel movements are separate to keep them decoupled. |
| 649 | VelocityControl mPointerVelocityControl; |
| 650 | VelocityControl mWheelXVelocityControl; |
| 651 | VelocityControl mWheelYVelocityControl; |
| 652 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 653 | sp<PointerControllerInterface> mPointerController; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 654 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 655 | struct LockedState { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 656 | uint32_t buttonState; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 657 | nsecs_t downTime; |
| 658 | } mLocked; |
| 659 | |
| 660 | void initializeLocked(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 661 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 662 | void configureParameters(); |
| 663 | void dumpParameters(String8& dump); |
| 664 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 665 | void sync(nsecs_t when); |
| 666 | }; |
| 667 | |
| 668 | |
| 669 | class TouchInputMapper : public InputMapper { |
| 670 | public: |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 671 | TouchInputMapper(InputDevice* device); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 672 | virtual ~TouchInputMapper(); |
| 673 | |
| 674 | virtual uint32_t getSources(); |
| 675 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 676 | virtual void dump(String8& dump); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 677 | virtual void configure(); |
| 678 | virtual void reset(); |
| 679 | |
| 680 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 681 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 682 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 683 | const int32_t* keyCodes, uint8_t* outFlags); |
| 684 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 685 | virtual void fadePointer(); |
Jeff Brown | 325bd07 | 2011-04-19 21:20:10 -0700 | [diff] [blame] | 686 | virtual void timeoutExpired(nsecs_t when); |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 687 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 688 | protected: |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 689 | Mutex mLock; |
| 690 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 691 | struct VirtualKey { |
| 692 | int32_t keyCode; |
| 693 | int32_t scanCode; |
| 694 | uint32_t flags; |
| 695 | |
| 696 | // computed hit box, specified in touch screen coords based on known display size |
| 697 | int32_t hitLeft; |
| 698 | int32_t hitTop; |
| 699 | int32_t hitRight; |
| 700 | int32_t hitBottom; |
| 701 | |
| 702 | inline bool isHit(int32_t x, int32_t y) const { |
| 703 | return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom; |
| 704 | } |
| 705 | }; |
| 706 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 707 | // Raw data for a single pointer. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 708 | struct PointerData { |
| 709 | uint32_t id; |
| 710 | int32_t x; |
| 711 | int32_t y; |
| 712 | int32_t pressure; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 713 | int32_t touchMajor; |
| 714 | int32_t touchMinor; |
| 715 | int32_t toolMajor; |
| 716 | int32_t toolMinor; |
| 717 | int32_t orientation; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 718 | |
| 719 | inline bool operator== (const PointerData& other) const { |
| 720 | return id == other.id |
| 721 | && x == other.x |
| 722 | && y == other.y |
| 723 | && pressure == other.pressure |
| 724 | && touchMajor == other.touchMajor |
| 725 | && touchMinor == other.touchMinor |
| 726 | && toolMajor == other.toolMajor |
| 727 | && toolMinor == other.toolMinor |
| 728 | && orientation == other.orientation; |
| 729 | } |
| 730 | inline bool operator!= (const PointerData& other) const { |
| 731 | return !(*this == other); |
| 732 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 733 | }; |
| 734 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 735 | // 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] | 736 | struct TouchData { |
| 737 | uint32_t pointerCount; |
| 738 | PointerData pointers[MAX_POINTERS]; |
| 739 | BitSet32 idBits; |
| 740 | uint32_t idToIndex[MAX_POINTER_ID + 1]; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 741 | uint32_t buttonState; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 742 | |
| 743 | void copyFrom(const TouchData& other) { |
| 744 | pointerCount = other.pointerCount; |
| 745 | idBits = other.idBits; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 746 | buttonState = other.buttonState; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 747 | |
| 748 | for (uint32_t i = 0; i < pointerCount; i++) { |
| 749 | pointers[i] = other.pointers[i]; |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame] | 750 | |
| 751 | int id = pointers[i].id; |
| 752 | idToIndex[id] = other.idToIndex[id]; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
| 756 | inline void clear() { |
| 757 | pointerCount = 0; |
| 758 | idBits.clear(); |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 759 | buttonState = 0; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 760 | } |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 761 | |
| 762 | void getCentroid(float* outX, float* outY) { |
| 763 | float x = 0, y = 0; |
| 764 | if (pointerCount != 0) { |
| 765 | for (uint32_t i = 0; i < pointerCount; i++) { |
| 766 | x += pointers[i].x; |
| 767 | y += pointers[i].y; |
| 768 | } |
| 769 | x /= pointerCount; |
| 770 | y /= pointerCount; |
| 771 | } |
| 772 | *outX = x; |
| 773 | *outY = y; |
| 774 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 775 | }; |
| 776 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 777 | // Input sources supported by the device. |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 778 | uint32_t mTouchSource; // sources when reporting touch data |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 779 | uint32_t mPointerSource; // sources when reporting pointer gestures |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 780 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 781 | // The reader's configuration. |
| 782 | const InputReaderConfiguration* mConfig; |
| 783 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 784 | // Immutable configuration parameters. |
| 785 | struct Parameters { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 786 | enum DeviceType { |
| 787 | DEVICE_TYPE_TOUCH_SCREEN, |
| 788 | DEVICE_TYPE_TOUCH_PAD, |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 789 | DEVICE_TYPE_POINTER, |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 790 | }; |
| 791 | |
| 792 | DeviceType deviceType; |
| 793 | int32_t associatedDisplayId; |
| 794 | bool orientationAware; |
| 795 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 796 | bool useBadTouchFilter; |
| 797 | bool useJumpyTouchFilter; |
| 798 | bool useAveragingTouchFilter; |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 799 | |
| 800 | enum GestureMode { |
| 801 | GESTURE_MODE_POINTER, |
| 802 | GESTURE_MODE_SPOTS, |
| 803 | }; |
| 804 | GestureMode gestureMode; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 805 | } mParameters; |
| 806 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 807 | // Immutable calibration parameters in parsed form. |
| 808 | struct Calibration { |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 809 | // Touch Size |
| 810 | enum TouchSizeCalibration { |
| 811 | TOUCH_SIZE_CALIBRATION_DEFAULT, |
| 812 | TOUCH_SIZE_CALIBRATION_NONE, |
| 813 | TOUCH_SIZE_CALIBRATION_GEOMETRIC, |
| 814 | TOUCH_SIZE_CALIBRATION_PRESSURE, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 815 | }; |
| 816 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 817 | TouchSizeCalibration touchSizeCalibration; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 818 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 819 | // Tool Size |
| 820 | enum ToolSizeCalibration { |
| 821 | TOOL_SIZE_CALIBRATION_DEFAULT, |
| 822 | TOOL_SIZE_CALIBRATION_NONE, |
| 823 | TOOL_SIZE_CALIBRATION_GEOMETRIC, |
| 824 | TOOL_SIZE_CALIBRATION_LINEAR, |
| 825 | TOOL_SIZE_CALIBRATION_AREA, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 826 | }; |
| 827 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 828 | ToolSizeCalibration toolSizeCalibration; |
| 829 | bool haveToolSizeLinearScale; |
| 830 | float toolSizeLinearScale; |
| 831 | bool haveToolSizeLinearBias; |
| 832 | float toolSizeLinearBias; |
| 833 | bool haveToolSizeAreaScale; |
| 834 | float toolSizeAreaScale; |
| 835 | bool haveToolSizeAreaBias; |
| 836 | float toolSizeAreaBias; |
| 837 | bool haveToolSizeIsSummed; |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 838 | bool toolSizeIsSummed; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 839 | |
| 840 | // Pressure |
| 841 | enum PressureCalibration { |
| 842 | PRESSURE_CALIBRATION_DEFAULT, |
| 843 | PRESSURE_CALIBRATION_NONE, |
| 844 | PRESSURE_CALIBRATION_PHYSICAL, |
| 845 | PRESSURE_CALIBRATION_AMPLITUDE, |
| 846 | }; |
| 847 | enum PressureSource { |
| 848 | PRESSURE_SOURCE_DEFAULT, |
| 849 | PRESSURE_SOURCE_PRESSURE, |
| 850 | PRESSURE_SOURCE_TOUCH, |
| 851 | }; |
| 852 | |
| 853 | PressureCalibration pressureCalibration; |
| 854 | PressureSource pressureSource; |
| 855 | bool havePressureScale; |
| 856 | float pressureScale; |
| 857 | |
| 858 | // Size |
| 859 | enum SizeCalibration { |
| 860 | SIZE_CALIBRATION_DEFAULT, |
| 861 | SIZE_CALIBRATION_NONE, |
| 862 | SIZE_CALIBRATION_NORMALIZED, |
| 863 | }; |
| 864 | |
| 865 | SizeCalibration sizeCalibration; |
| 866 | |
| 867 | // Orientation |
| 868 | enum OrientationCalibration { |
| 869 | ORIENTATION_CALIBRATION_DEFAULT, |
| 870 | ORIENTATION_CALIBRATION_NONE, |
| 871 | ORIENTATION_CALIBRATION_INTERPOLATED, |
Jeff Brown | 517bb4c | 2011-01-14 19:09:23 -0800 | [diff] [blame] | 872 | ORIENTATION_CALIBRATION_VECTOR, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 873 | }; |
| 874 | |
| 875 | OrientationCalibration orientationCalibration; |
| 876 | } mCalibration; |
| 877 | |
| 878 | // Raw axis information from the driver. |
| 879 | struct RawAxes { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 880 | RawAbsoluteAxisInfo x; |
| 881 | RawAbsoluteAxisInfo y; |
| 882 | RawAbsoluteAxisInfo pressure; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 883 | RawAbsoluteAxisInfo touchMajor; |
| 884 | RawAbsoluteAxisInfo touchMinor; |
| 885 | RawAbsoluteAxisInfo toolMajor; |
| 886 | RawAbsoluteAxisInfo toolMinor; |
| 887 | RawAbsoluteAxisInfo orientation; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 888 | } mRawAxes; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 889 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 890 | // Current and previous touch sample data. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 891 | TouchData mCurrentTouch; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 892 | PointerCoords mCurrentTouchCoords[MAX_POINTERS]; |
| 893 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 894 | TouchData mLastTouch; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 895 | PointerCoords mLastTouchCoords[MAX_POINTERS]; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 896 | |
| 897 | // The time the primary pointer last went down. |
| 898 | nsecs_t mDownTime; |
| 899 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 900 | // The pointer controller, or null if the device is not a pointer. |
| 901 | sp<PointerControllerInterface> mPointerController; |
| 902 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 903 | struct LockedState { |
| 904 | Vector<VirtualKey> virtualKeys; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 905 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 906 | // The surface orientation and width and height set by configureSurfaceLocked(). |
| 907 | int32_t surfaceOrientation; |
| 908 | int32_t surfaceWidth, surfaceHeight; |
| 909 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 910 | // The associated display orientation and width and height set by configureSurfaceLocked(). |
| 911 | int32_t associatedDisplayOrientation; |
| 912 | int32_t associatedDisplayWidth, associatedDisplayHeight; |
| 913 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 914 | // Translation and scaling factors, orientation-independent. |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 915 | float xScale; |
| 916 | float xPrecision; |
| 917 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 918 | float yScale; |
| 919 | float yPrecision; |
| 920 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 921 | float geometricScale; |
| 922 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 923 | float toolSizeLinearScale; |
| 924 | float toolSizeLinearBias; |
| 925 | float toolSizeAreaScale; |
| 926 | float toolSizeAreaBias; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 927 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 928 | float pressureScale; |
| 929 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 930 | float sizeScale; |
| 931 | |
| 932 | float orientationScale; |
| 933 | |
| 934 | // Oriented motion ranges for input device info. |
| 935 | struct OrientedRanges { |
| 936 | InputDeviceInfo::MotionRange x; |
| 937 | InputDeviceInfo::MotionRange y; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 938 | |
| 939 | bool havePressure; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 940 | InputDeviceInfo::MotionRange pressure; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 941 | |
| 942 | bool haveSize; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 943 | InputDeviceInfo::MotionRange size; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 944 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 945 | bool haveTouchSize; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 946 | InputDeviceInfo::MotionRange touchMajor; |
| 947 | InputDeviceInfo::MotionRange touchMinor; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 948 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 949 | bool haveToolSize; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 950 | InputDeviceInfo::MotionRange toolMajor; |
| 951 | InputDeviceInfo::MotionRange toolMinor; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 952 | |
| 953 | bool haveOrientation; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 954 | InputDeviceInfo::MotionRange orientation; |
| 955 | } orientedRanges; |
| 956 | |
| 957 | // Oriented dimensions and precision. |
| 958 | float orientedSurfaceWidth, orientedSurfaceHeight; |
| 959 | float orientedXPrecision, orientedYPrecision; |
| 960 | |
| 961 | struct CurrentVirtualKeyState { |
| 962 | bool down; |
| 963 | nsecs_t downTime; |
| 964 | int32_t keyCode; |
| 965 | int32_t scanCode; |
| 966 | } currentVirtualKey; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 967 | |
| 968 | // Scale factor for gesture based pointer movements. |
| 969 | float pointerGestureXMovementScale; |
| 970 | float pointerGestureYMovementScale; |
| 971 | |
| 972 | // Scale factor for gesture based zooming and other freeform motions. |
| 973 | float pointerGestureXZoomScale; |
| 974 | float pointerGestureYZoomScale; |
| 975 | |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 976 | // The maximum swipe width. |
| 977 | float pointerGestureMaxSwipeWidth; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 978 | } mLocked; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 979 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 980 | virtual void configureParameters(); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 981 | virtual void dumpParameters(String8& dump); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 982 | virtual void configureRawAxes(); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 983 | virtual void dumpRawAxes(String8& dump); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 984 | virtual bool configureSurfaceLocked(); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 985 | virtual void dumpSurfaceLocked(String8& dump); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 986 | virtual void configureVirtualKeysLocked(); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 987 | virtual void dumpVirtualKeysLocked(String8& dump); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 988 | virtual void parseCalibration(); |
| 989 | virtual void resolveCalibration(); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 990 | virtual void dumpCalibration(String8& dump); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 991 | |
| 992 | enum TouchResult { |
| 993 | // Dispatch the touch normally. |
| 994 | DISPATCH_TOUCH, |
| 995 | // Do not dispatch the touch, but keep tracking the current stroke. |
| 996 | SKIP_TOUCH, |
| 997 | // Do not dispatch the touch, and drop all information associated with the current stoke |
| 998 | // so the next movement will appear as a new down. |
| 999 | DROP_STROKE |
| 1000 | }; |
| 1001 | |
| 1002 | void syncTouch(nsecs_t when, bool havePointerIds); |
| 1003 | |
| 1004 | private: |
| 1005 | /* Maximum number of historical samples to average. */ |
| 1006 | static const uint32_t AVERAGING_HISTORY_SIZE = 5; |
| 1007 | |
| 1008 | /* Slop distance for jumpy pointer detection. |
| 1009 | * The vertical range of the screen divided by this is our epsilon value. */ |
| 1010 | static const uint32_t JUMPY_EPSILON_DIVISOR = 212; |
| 1011 | |
| 1012 | /* Number of jumpy points to drop for touchscreens that need it. */ |
| 1013 | static const uint32_t JUMPY_TRANSITION_DROPS = 3; |
| 1014 | static const uint32_t JUMPY_DROP_LIMIT = 3; |
| 1015 | |
| 1016 | /* Maximum squared distance for averaging. |
| 1017 | * If moving farther than this, turn of averaging to avoid lag in response. */ |
| 1018 | static const uint64_t AVERAGING_DISTANCE_LIMIT = 75 * 75; |
| 1019 | |
| 1020 | struct AveragingTouchFilterState { |
| 1021 | // Individual history tracks are stored by pointer id |
| 1022 | uint32_t historyStart[MAX_POINTERS]; |
| 1023 | uint32_t historyEnd[MAX_POINTERS]; |
| 1024 | struct { |
| 1025 | struct { |
| 1026 | int32_t x; |
| 1027 | int32_t y; |
| 1028 | int32_t pressure; |
| 1029 | } pointers[MAX_POINTERS]; |
| 1030 | } historyData[AVERAGING_HISTORY_SIZE]; |
| 1031 | } mAveragingTouchFilter; |
| 1032 | |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 1033 | struct JumpyTouchFilterState { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1034 | uint32_t jumpyPointsDropped; |
| 1035 | } mJumpyTouchFilter; |
| 1036 | |
| 1037 | struct PointerDistanceHeapElement { |
| 1038 | uint32_t currentPointerIndex : 8; |
| 1039 | uint32_t lastPointerIndex : 8; |
| 1040 | uint64_t distance : 48; // squared distance |
| 1041 | }; |
| 1042 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1043 | struct PointerGesture { |
| 1044 | enum Mode { |
| 1045 | // No fingers, button is not pressed. |
| 1046 | // Nothing happening. |
| 1047 | NEUTRAL, |
| 1048 | |
| 1049 | // No fingers, button is not pressed. |
| 1050 | // Tap detected. |
| 1051 | // Emits DOWN and UP events at the pointer location. |
| 1052 | TAP, |
| 1053 | |
Jeff Brown | 325bd07 | 2011-04-19 21:20:10 -0700 | [diff] [blame] | 1054 | // Exactly one finger dragging following a tap. |
| 1055 | // Pointer follows the active finger. |
| 1056 | // Emits DOWN, MOVE and UP events at the pointer location. |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 1057 | // |
| 1058 | // Detect double-taps when the finger goes up while in TAP_DRAG mode. |
Jeff Brown | 325bd07 | 2011-04-19 21:20:10 -0700 | [diff] [blame] | 1059 | TAP_DRAG, |
| 1060 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1061 | // Button is pressed. |
| 1062 | // Pointer follows the active finger if there is one. Other fingers are ignored. |
| 1063 | // Emits DOWN, MOVE and UP events at the pointer location. |
Jeff Brown | 325bd07 | 2011-04-19 21:20:10 -0700 | [diff] [blame] | 1064 | BUTTON_CLICK_OR_DRAG, |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1065 | |
| 1066 | // Exactly one finger, button is not pressed. |
| 1067 | // Pointer follows the active finger. |
| 1068 | // Emits HOVER_MOVE events at the pointer location. |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 1069 | // |
| 1070 | // Detect taps when the finger goes up while in HOVER mode. |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1071 | HOVER, |
| 1072 | |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1073 | // Exactly two fingers but neither have moved enough to clearly indicate |
| 1074 | // whether a swipe or freeform gesture was intended. We consider the |
| 1075 | // pointer to be pressed so this enables clicking or long-pressing on buttons. |
| 1076 | // Pointer does not move. |
| 1077 | // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate. |
| 1078 | PRESS, |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1079 | |
| 1080 | // Exactly two fingers moving in the same direction, button is not pressed. |
| 1081 | // Pointer does not move. |
| 1082 | // Emits DOWN, MOVE and UP events with a single pointer coordinate that |
| 1083 | // follows the midpoint between both fingers. |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1084 | SWIPE, |
| 1085 | |
| 1086 | // Two or more fingers moving in arbitrary directions, button is not pressed. |
| 1087 | // Pointer does not move. |
| 1088 | // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow |
| 1089 | // each finger individually relative to the initial centroid of the finger. |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1090 | FREEFORM, |
| 1091 | |
| 1092 | // Waiting for quiet time to end before starting the next gesture. |
| 1093 | QUIET, |
| 1094 | }; |
| 1095 | |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1096 | // Time the first finger went down. |
| 1097 | nsecs_t firstTouchTime; |
| 1098 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1099 | // The active pointer id from the raw touch data. |
| 1100 | int32_t activeTouchId; // -1 if none |
| 1101 | |
| 1102 | // The active pointer id from the gesture last delivered to the application. |
| 1103 | int32_t activeGestureId; // -1 if none |
| 1104 | |
| 1105 | // Pointer coords and ids for the current and previous pointer gesture. |
| 1106 | Mode currentGestureMode; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1107 | BitSet32 currentGestureIdBits; |
| 1108 | uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1]; |
| 1109 | PointerCoords currentGestureCoords[MAX_POINTERS]; |
| 1110 | |
| 1111 | Mode lastGestureMode; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1112 | BitSet32 lastGestureIdBits; |
| 1113 | uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1]; |
| 1114 | PointerCoords lastGestureCoords[MAX_POINTERS]; |
| 1115 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1116 | // Time the pointer gesture last went down. |
| 1117 | nsecs_t downTime; |
| 1118 | |
Jeff Brown | 325bd07 | 2011-04-19 21:20:10 -0700 | [diff] [blame] | 1119 | // Time when the pointer went down for a TAP. |
| 1120 | nsecs_t tapDownTime; |
| 1121 | |
| 1122 | // Time when the pointer went up for a TAP. |
| 1123 | nsecs_t tapUpTime; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1124 | |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1125 | // Location of initial tap. |
| 1126 | float tapX, tapY; |
| 1127 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1128 | // Time we started waiting for quiescence. |
| 1129 | nsecs_t quietTime; |
| 1130 | |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1131 | // Reference points for multitouch gestures. |
| 1132 | float referenceTouchX; // reference touch X/Y coordinates in surface units |
| 1133 | float referenceTouchY; |
| 1134 | float referenceGestureX; // reference gesture X/Y coordinates in pixels |
| 1135 | float referenceGestureY; |
| 1136 | |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 1137 | // Distance that each pointer has traveled which has not yet been |
| 1138 | // subsumed into the reference gesture position. |
| 1139 | BitSet32 referenceIdBits; |
| 1140 | struct Delta { |
| 1141 | float dx, dy; |
| 1142 | }; |
| 1143 | Delta referenceDeltas[MAX_POINTER_ID + 1]; |
| 1144 | |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1145 | // Describes how touch ids are mapped to gesture ids for freeform gestures. |
| 1146 | uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1]; |
| 1147 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1148 | // A velocity tracker for determining whether to switch active pointers during drags. |
| 1149 | VelocityTracker velocityTracker; |
| 1150 | |
Jeff Brown | 19c97d46 | 2011-06-01 12:33:19 -0700 | [diff] [blame] | 1151 | // Velocity control for pointer movements. |
| 1152 | VelocityControl pointerVelocityControl; |
| 1153 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1154 | void reset() { |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1155 | firstTouchTime = LLONG_MIN; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1156 | activeTouchId = -1; |
| 1157 | activeGestureId = -1; |
| 1158 | currentGestureMode = NEUTRAL; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1159 | currentGestureIdBits.clear(); |
| 1160 | lastGestureMode = NEUTRAL; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1161 | lastGestureIdBits.clear(); |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1162 | downTime = 0; |
| 1163 | velocityTracker.clear(); |
Jeff Brown | 325bd07 | 2011-04-19 21:20:10 -0700 | [diff] [blame] | 1164 | resetTap(); |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1165 | resetQuietTime(); |
Jeff Brown | 19c97d46 | 2011-06-01 12:33:19 -0700 | [diff] [blame] | 1166 | pointerVelocityControl.reset(); |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1167 | } |
| 1168 | |
Jeff Brown | 325bd07 | 2011-04-19 21:20:10 -0700 | [diff] [blame] | 1169 | void resetTap() { |
| 1170 | tapDownTime = LLONG_MIN; |
| 1171 | tapUpTime = LLONG_MIN; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | void resetQuietTime() { |
| 1175 | quietTime = LLONG_MIN; |
| 1176 | } |
| 1177 | } mPointerGesture; |
| 1178 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1179 | void initializeLocked(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1180 | |
| 1181 | TouchResult consumeOffScreenTouches(nsecs_t when, uint32_t policyFlags); |
| 1182 | void dispatchTouches(nsecs_t when, uint32_t policyFlags); |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1183 | void prepareTouches(int32_t* outEdgeFlags, float* outXPrecision, float* outYPrecision); |
Jeff Brown | 325bd07 | 2011-04-19 21:20:10 -0700 | [diff] [blame] | 1184 | void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout); |
| 1185 | bool preparePointerGestures(nsecs_t when, |
| 1186 | bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, bool isTimeout); |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1187 | |
| 1188 | // Dispatches a motion event. |
| 1189 | // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the |
| 1190 | // method will take care of setting the index and transmuting the action to DOWN or UP |
| 1191 | // it is the first / last pointer to go down / up. |
| 1192 | void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source, |
| 1193 | int32_t action, int32_t flags, uint32_t metaState, int32_t edgeFlags, |
| 1194 | const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits, |
| 1195 | int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime); |
| 1196 | |
| 1197 | // Updates pointer coords for pointers with specified ids that have moved. |
| 1198 | // Returns true if any of them changed. |
| 1199 | bool updateMovedPointerCoords(const PointerCoords* inCoords, const uint32_t* inIdToIndex, |
| 1200 | PointerCoords* outCoords, const uint32_t* outIdToIndex, BitSet32 idBits) const; |
| 1201 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 1202 | void suppressSwipeOntoVirtualKeys(nsecs_t when); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1203 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1204 | bool isPointInsideSurfaceLocked(int32_t x, int32_t y); |
| 1205 | const VirtualKey* findVirtualKeyHitLocked(int32_t x, int32_t y); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1206 | |
| 1207 | bool applyBadTouchFilter(); |
| 1208 | bool applyJumpyTouchFilter(); |
| 1209 | void applyAveragingTouchFilter(); |
| 1210 | void calculatePointerIds(); |
| 1211 | }; |
| 1212 | |
| 1213 | |
| 1214 | class SingleTouchInputMapper : public TouchInputMapper { |
| 1215 | public: |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1216 | SingleTouchInputMapper(InputDevice* device); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1217 | virtual ~SingleTouchInputMapper(); |
| 1218 | |
| 1219 | virtual void reset(); |
| 1220 | virtual void process(const RawEvent* rawEvent); |
| 1221 | |
| 1222 | protected: |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1223 | virtual void configureRawAxes(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1224 | |
| 1225 | private: |
| 1226 | struct Accumulator { |
| 1227 | enum { |
| 1228 | FIELD_BTN_TOUCH = 1, |
| 1229 | FIELD_ABS_X = 2, |
| 1230 | FIELD_ABS_Y = 4, |
| 1231 | FIELD_ABS_PRESSURE = 8, |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 1232 | FIELD_ABS_TOOL_WIDTH = 16, |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1233 | FIELD_BUTTONS = 32, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1234 | }; |
| 1235 | |
| 1236 | uint32_t fields; |
| 1237 | |
| 1238 | bool btnTouch; |
| 1239 | int32_t absX; |
| 1240 | int32_t absY; |
| 1241 | int32_t absPressure; |
| 1242 | int32_t absToolWidth; |
| 1243 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1244 | uint32_t buttonDown; |
| 1245 | uint32_t buttonUp; |
| 1246 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1247 | inline void clear() { |
| 1248 | fields = 0; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1249 | buttonDown = 0; |
| 1250 | buttonUp = 0; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1251 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1252 | } mAccumulator; |
| 1253 | |
| 1254 | bool mDown; |
| 1255 | int32_t mX; |
| 1256 | int32_t mY; |
| 1257 | int32_t mPressure; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1258 | int32_t mToolWidth; |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1259 | uint32_t mButtonState; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1260 | |
| 1261 | void initialize(); |
| 1262 | |
| 1263 | void sync(nsecs_t when); |
| 1264 | }; |
| 1265 | |
| 1266 | |
| 1267 | class MultiTouchInputMapper : public TouchInputMapper { |
| 1268 | public: |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1269 | MultiTouchInputMapper(InputDevice* device); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1270 | virtual ~MultiTouchInputMapper(); |
| 1271 | |
| 1272 | virtual void reset(); |
| 1273 | virtual void process(const RawEvent* rawEvent); |
| 1274 | |
| 1275 | protected: |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1276 | virtual void configureRawAxes(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1277 | |
| 1278 | private: |
| 1279 | struct Accumulator { |
| 1280 | enum { |
| 1281 | FIELD_ABS_MT_POSITION_X = 1, |
| 1282 | FIELD_ABS_MT_POSITION_Y = 2, |
| 1283 | FIELD_ABS_MT_TOUCH_MAJOR = 4, |
| 1284 | FIELD_ABS_MT_TOUCH_MINOR = 8, |
| 1285 | FIELD_ABS_MT_WIDTH_MAJOR = 16, |
| 1286 | FIELD_ABS_MT_WIDTH_MINOR = 32, |
| 1287 | FIELD_ABS_MT_ORIENTATION = 64, |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 1288 | FIELD_ABS_MT_TRACKING_ID = 128, |
| 1289 | FIELD_ABS_MT_PRESSURE = 256, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1290 | }; |
| 1291 | |
| 1292 | uint32_t pointerCount; |
| 1293 | struct Pointer { |
| 1294 | uint32_t fields; |
| 1295 | |
| 1296 | int32_t absMTPositionX; |
| 1297 | int32_t absMTPositionY; |
| 1298 | int32_t absMTTouchMajor; |
| 1299 | int32_t absMTTouchMinor; |
| 1300 | int32_t absMTWidthMajor; |
| 1301 | int32_t absMTWidthMinor; |
| 1302 | int32_t absMTOrientation; |
| 1303 | int32_t absMTTrackingId; |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 1304 | int32_t absMTPressure; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1305 | |
| 1306 | inline void clear() { |
| 1307 | fields = 0; |
| 1308 | } |
| 1309 | } pointers[MAX_POINTERS + 1]; // + 1 to remove the need for extra range checks |
| 1310 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1311 | // Bitfield of buttons that went down or up. |
| 1312 | uint32_t buttonDown; |
| 1313 | uint32_t buttonUp; |
| 1314 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1315 | inline void clear() { |
| 1316 | pointerCount = 0; |
| 1317 | pointers[0].clear(); |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1318 | buttonDown = 0; |
| 1319 | buttonUp = 0; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1320 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1321 | } mAccumulator; |
| 1322 | |
Jeff Brown | 96ad397 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 1323 | uint32_t mButtonState; |
| 1324 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1325 | void initialize(); |
| 1326 | |
| 1327 | void sync(nsecs_t when); |
| 1328 | }; |
| 1329 | |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1330 | |
| 1331 | class JoystickInputMapper : public InputMapper { |
| 1332 | public: |
| 1333 | JoystickInputMapper(InputDevice* device); |
| 1334 | virtual ~JoystickInputMapper(); |
| 1335 | |
| 1336 | virtual uint32_t getSources(); |
| 1337 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
| 1338 | virtual void dump(String8& dump); |
| 1339 | virtual void configure(); |
| 1340 | virtual void reset(); |
| 1341 | virtual void process(const RawEvent* rawEvent); |
| 1342 | |
| 1343 | private: |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1344 | struct Axis { |
| 1345 | RawAbsoluteAxisInfo rawAxisInfo; |
Jeff Brown | 8529745 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1346 | AxisInfo axisInfo; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1347 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1348 | bool explicitlyMapped; // true if the axis was explicitly assigned an axis id |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1349 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1350 | float scale; // scale factor from raw to normalized values |
| 1351 | float offset; // offset to add after scaling for normalization |
Jeff Brown | 8529745 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1352 | float highScale; // scale factor from raw to normalized values of high split |
| 1353 | float highOffset; // offset to add after scaling for normalization of high split |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1354 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1355 | float min; // normalized inclusive minimum |
| 1356 | float max; // normalized inclusive maximum |
| 1357 | float flat; // normalized flat region size |
| 1358 | float fuzz; // normalized error tolerance |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1359 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1360 | float filter; // filter out small variations of this size |
Jeff Brown | 8529745 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1361 | float currentValue; // current value |
| 1362 | float newValue; // most recent value |
| 1363 | float highCurrentValue; // current value of high split |
| 1364 | float highNewValue; // most recent value of high split |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1365 | |
Jeff Brown | 8529745 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1366 | void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo, |
| 1367 | bool explicitlyMapped, float scale, float offset, |
| 1368 | float highScale, float highOffset, |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1369 | float min, float max, float flat, float fuzz) { |
| 1370 | this->rawAxisInfo = rawAxisInfo; |
Jeff Brown | 8529745 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1371 | this->axisInfo = axisInfo; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1372 | this->explicitlyMapped = explicitlyMapped; |
| 1373 | this->scale = scale; |
| 1374 | this->offset = offset; |
Jeff Brown | 8529745 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1375 | this->highScale = highScale; |
| 1376 | this->highOffset = highOffset; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1377 | this->min = min; |
| 1378 | this->max = max; |
| 1379 | this->flat = flat; |
| 1380 | this->fuzz = fuzz; |
| 1381 | this->filter = 0; |
Jeff Brown | 8529745 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1382 | resetValue(); |
| 1383 | } |
| 1384 | |
| 1385 | void resetValue() { |
| 1386 | this->currentValue = 0; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1387 | this->newValue = 0; |
Jeff Brown | 8529745 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1388 | this->highCurrentValue = 0; |
| 1389 | this->highNewValue = 0; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1390 | } |
| 1391 | }; |
| 1392 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1393 | // Axes indexed by raw ABS_* axis index. |
| 1394 | KeyedVector<int32_t, Axis> mAxes; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1395 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1396 | void sync(nsecs_t when, bool force); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1397 | |
Jeff Brown | 8529745 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1398 | bool haveAxis(int32_t axisId); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1399 | void pruneAxes(bool ignoreExplicitlyMappedAxes); |
Jeff Brown | 8529745 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1400 | bool filterAxes(bool force); |
| 1401 | |
| 1402 | static bool hasValueChangedSignificantly(float filter, |
| 1403 | float newValue, float currentValue, float min, float max); |
| 1404 | static bool hasMovedNearerToValueWithinFilteredRange(float filter, |
| 1405 | float newValue, float currentValue, float thresholdValue); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1406 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1407 | static bool isCenteredAxis(int32_t axis); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1408 | }; |
| 1409 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1410 | } // namespace android |
| 1411 | |
| 1412 | #endif // _UI_INPUT_READER_H |