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