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