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