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 | |
| 20 | #include <ui/EventHub.h> |
| 21 | #include <ui/Input.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 22 | #include <ui/InputDispatcher.h> |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame^] | 23 | #include <ui/PointerController.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 24 | #include <utils/KeyedVector.h> |
| 25 | #include <utils/threads.h> |
| 26 | #include <utils/Timers.h> |
| 27 | #include <utils/RefBase.h> |
| 28 | #include <utils/String8.h> |
| 29 | #include <utils/BitSet.h> |
| 30 | |
| 31 | #include <stddef.h> |
| 32 | #include <unistd.h> |
| 33 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 34 | namespace android { |
| 35 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 36 | class InputDevice; |
| 37 | class InputMapper; |
| 38 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 39 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Input reader policy interface. |
| 42 | * |
| 43 | * The input reader policy is used by the input reader to interact with the Window Manager |
| 44 | * and other system components. |
| 45 | * |
| 46 | * The actual implementation is partially supported by callbacks into the DVM |
| 47 | * via JNI. This interface is also mocked in the unit tests. |
| 48 | */ |
| 49 | class InputReaderPolicyInterface : public virtual RefBase { |
| 50 | protected: |
| 51 | InputReaderPolicyInterface() { } |
| 52 | virtual ~InputReaderPolicyInterface() { } |
| 53 | |
| 54 | public: |
| 55 | /* Display orientations. */ |
| 56 | enum { |
| 57 | ROTATION_0 = 0, |
| 58 | ROTATION_90 = 1, |
| 59 | ROTATION_180 = 2, |
| 60 | ROTATION_270 = 3 |
| 61 | }; |
| 62 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 63 | /* Gets information about the display with the specified id. |
| 64 | * Returns true if the display info is available, false otherwise. |
| 65 | */ |
| 66 | virtual bool getDisplayInfo(int32_t displayId, |
| 67 | int32_t* width, int32_t* height, int32_t* orientation) = 0; |
| 68 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 69 | /* Determines whether to turn on some hacks we have to improve the touch interaction with a |
| 70 | * certain device whose screen currently is not all that good. |
| 71 | */ |
| 72 | virtual bool filterTouchEvents() = 0; |
| 73 | |
| 74 | /* Determines whether to turn on some hacks to improve touch interaction with another device |
| 75 | * where touch coordinate data can get corrupted. |
| 76 | */ |
| 77 | virtual bool filterJumpyTouchEvents() = 0; |
| 78 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 79 | /* Gets the excluded device names for the platform. */ |
| 80 | virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) = 0; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame^] | 81 | |
| 82 | /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */ |
| 83 | virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | |
| 87 | /* 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] | 88 | class InputReaderInterface : public virtual RefBase { |
| 89 | protected: |
| 90 | InputReaderInterface() { } |
| 91 | virtual ~InputReaderInterface() { } |
| 92 | |
| 93 | public: |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 94 | /* Dumps the state of the input reader. |
| 95 | * |
| 96 | * This method may be called on any thread (usually by the input manager). */ |
| 97 | virtual void dump(String8& dump) = 0; |
| 98 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 99 | /* Runs a single iteration of the processing loop. |
| 100 | * Nominally reads and processes one incoming message from the EventHub. |
| 101 | * |
| 102 | * This method should be called on the input reader thread. |
| 103 | */ |
| 104 | virtual void loopOnce() = 0; |
| 105 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 106 | /* Gets the current input device configuration. |
| 107 | * |
| 108 | * This method may be called on any thread (usually by the input manager). |
| 109 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 110 | virtual void getInputConfiguration(InputConfiguration* outConfiguration) = 0; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 111 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 112 | /* Gets information about the specified input device. |
| 113 | * Returns OK if the device information was obtained or NAME_NOT_FOUND if there |
| 114 | * was no such device. |
| 115 | * |
| 116 | * 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] | 117 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 118 | virtual status_t getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo) = 0; |
| 119 | |
| 120 | /* Gets the list of all registered device ids. */ |
| 121 | virtual void getInputDeviceIds(Vector<int32_t>& outDeviceIds) = 0; |
| 122 | |
| 123 | /* Query current input state. */ |
| 124 | virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, |
| 125 | int32_t scanCode) = 0; |
| 126 | virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, |
| 127 | int32_t keyCode) = 0; |
| 128 | virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, |
| 129 | int32_t sw) = 0; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 130 | |
| 131 | /* Determine whether physical keys exist for the given framework-domain key codes. */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 132 | virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 133 | size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0; |
| 134 | }; |
| 135 | |
| 136 | |
| 137 | /* Internal interface used by individual input devices to access global input device state |
| 138 | * and parameters maintained by the input reader. |
| 139 | */ |
| 140 | class InputReaderContext { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 141 | public: |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 142 | InputReaderContext() { } |
| 143 | virtual ~InputReaderContext() { } |
| 144 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 145 | virtual void updateGlobalMetaState() = 0; |
| 146 | virtual int32_t getGlobalMetaState() = 0; |
| 147 | |
| 148 | virtual InputReaderPolicyInterface* getPolicy() = 0; |
| 149 | virtual InputDispatcherInterface* getDispatcher() = 0; |
| 150 | virtual EventHubInterface* getEventHub() = 0; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 153 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 154 | /* 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] | 155 | * that it sends to the input dispatcher. Some functions of the input reader, such as early |
| 156 | * event filtering in low power states, are controlled by a separate policy object. |
| 157 | * |
| 158 | * IMPORTANT INVARIANT: |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 159 | * Because the policy and dispatcher can potentially block or cause re-entrance into |
| 160 | * 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] | 161 | * an exclusive internal lock whenever re-entrance can happen. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 162 | */ |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 163 | class InputReader : public InputReaderInterface, protected InputReaderContext { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 164 | public: |
| 165 | InputReader(const sp<EventHubInterface>& eventHub, |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 166 | const sp<InputReaderPolicyInterface>& policy, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 167 | const sp<InputDispatcherInterface>& dispatcher); |
| 168 | virtual ~InputReader(); |
| 169 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 170 | virtual void dump(String8& dump); |
| 171 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 172 | virtual void loopOnce(); |
| 173 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 174 | virtual void getInputConfiguration(InputConfiguration* outConfiguration); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 175 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 176 | virtual status_t getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo); |
| 177 | virtual void getInputDeviceIds(Vector<int32_t>& outDeviceIds); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 178 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 179 | virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, |
| 180 | int32_t scanCode); |
| 181 | virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, |
| 182 | int32_t keyCode); |
| 183 | virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, |
| 184 | int32_t sw); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 185 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 186 | virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 187 | size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 188 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 189 | protected: |
| 190 | // These methods are protected virtual so they can be overridden and instrumented |
| 191 | // by test cases. |
| 192 | virtual InputDevice* createDevice(int32_t deviceId, const String8& name, uint32_t classes); |
| 193 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 194 | private: |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 195 | sp<EventHubInterface> mEventHub; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 196 | sp<InputReaderPolicyInterface> mPolicy; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 197 | sp<InputDispatcherInterface> mDispatcher; |
| 198 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 199 | virtual InputReaderPolicyInterface* getPolicy() { return mPolicy.get(); } |
| 200 | virtual InputDispatcherInterface* getDispatcher() { return mDispatcher.get(); } |
| 201 | virtual EventHubInterface* getEventHub() { return mEventHub.get(); } |
| 202 | |
| 203 | // This reader/writer lock guards the list of input devices. |
| 204 | // The writer lock must be held whenever the list of input devices is modified |
| 205 | // and then promptly released. |
| 206 | // The reader lock must be held whenever the list of input devices is traversed or an |
| 207 | // input device in the list is accessed. |
| 208 | // This lock only protects the registry and prevents inadvertent deletion of device objects |
| 209 | // that are in use. Individual devices are responsible for guarding their own internal state |
| 210 | // as needed for concurrent operation. |
| 211 | RWLock mDeviceRegistryLock; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 212 | KeyedVector<int32_t, InputDevice*> mDevices; |
| 213 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 214 | // low-level input event decoding and device management |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 215 | void process(const RawEvent* rawEvent); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 216 | |
Jeff Brown | 7342bb9 | 2010-10-01 18:55:43 -0700 | [diff] [blame] | 217 | void addDevice(int32_t deviceId); |
| 218 | void removeDevice(int32_t deviceId); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 219 | void configureExcludedDevices(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 220 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 221 | void consumeEvent(const RawEvent* rawEvent); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 222 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 223 | void handleConfigurationChanged(nsecs_t when); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 224 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 225 | // state management for all devices |
| 226 | Mutex mStateLock; |
| 227 | |
| 228 | int32_t mGlobalMetaState; |
| 229 | virtual void updateGlobalMetaState(); |
| 230 | virtual int32_t getGlobalMetaState(); |
| 231 | |
| 232 | InputConfiguration mInputConfiguration; |
| 233 | void updateInputConfiguration(); |
| 234 | |
| 235 | // state queries |
| 236 | typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code); |
| 237 | int32_t getState(int32_t deviceId, uint32_t sourceMask, int32_t code, |
| 238 | GetStateFunc getStateFunc); |
| 239 | bool markSupportedKeyCodes(int32_t deviceId, uint32_t sourceMask, size_t numCodes, |
| 240 | const int32_t* keyCodes, uint8_t* outFlags); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | |
| 244 | /* Reads raw events from the event hub and processes them, endlessly. */ |
| 245 | class InputReaderThread : public Thread { |
| 246 | public: |
| 247 | InputReaderThread(const sp<InputReaderInterface>& reader); |
| 248 | virtual ~InputReaderThread(); |
| 249 | |
| 250 | private: |
| 251 | sp<InputReaderInterface> mReader; |
| 252 | |
| 253 | virtual bool threadLoop(); |
| 254 | }; |
| 255 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 256 | |
| 257 | /* Represents the state of a single input device. */ |
| 258 | class InputDevice { |
| 259 | public: |
| 260 | InputDevice(InputReaderContext* context, int32_t id, const String8& name); |
| 261 | ~InputDevice(); |
| 262 | |
| 263 | inline InputReaderContext* getContext() { return mContext; } |
| 264 | inline int32_t getId() { return mId; } |
| 265 | inline const String8& getName() { return mName; } |
| 266 | inline uint32_t getSources() { return mSources; } |
| 267 | |
| 268 | inline bool isIgnored() { return mMappers.isEmpty(); } |
| 269 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 270 | void dump(String8& dump); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 271 | void addMapper(InputMapper* mapper); |
| 272 | void configure(); |
| 273 | void reset(); |
| 274 | void process(const RawEvent* rawEvent); |
| 275 | |
| 276 | void getDeviceInfo(InputDeviceInfo* outDeviceInfo); |
| 277 | int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 278 | int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 279 | int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 280 | bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 281 | const int32_t* keyCodes, uint8_t* outFlags); |
| 282 | |
| 283 | int32_t getMetaState(); |
| 284 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 285 | inline const PropertyMap& getConfiguration() { |
| 286 | return mConfiguration; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 289 | private: |
| 290 | InputReaderContext* mContext; |
| 291 | int32_t mId; |
| 292 | |
| 293 | Vector<InputMapper*> mMappers; |
| 294 | |
| 295 | String8 mName; |
| 296 | uint32_t mSources; |
| 297 | |
| 298 | typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code); |
| 299 | int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 300 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 301 | PropertyMap mConfiguration; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | |
| 305 | /* An input mapper transforms raw input events into cooked event data. |
| 306 | * A single input device can have multiple associated input mappers in order to interpret |
| 307 | * different classes of events. |
| 308 | */ |
| 309 | class InputMapper { |
| 310 | public: |
| 311 | InputMapper(InputDevice* device); |
| 312 | virtual ~InputMapper(); |
| 313 | |
| 314 | inline InputDevice* getDevice() { return mDevice; } |
| 315 | inline int32_t getDeviceId() { return mDevice->getId(); } |
| 316 | inline const String8 getDeviceName() { return mDevice->getName(); } |
| 317 | inline InputReaderContext* getContext() { return mContext; } |
| 318 | inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); } |
| 319 | inline InputDispatcherInterface* getDispatcher() { return mContext->getDispatcher(); } |
| 320 | inline EventHubInterface* getEventHub() { return mContext->getEventHub(); } |
| 321 | |
| 322 | virtual uint32_t getSources() = 0; |
| 323 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 324 | virtual void dump(String8& dump); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 325 | virtual void configure(); |
| 326 | virtual void reset(); |
| 327 | virtual void process(const RawEvent* rawEvent) = 0; |
| 328 | |
| 329 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 330 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 331 | virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 332 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 333 | const int32_t* keyCodes, uint8_t* outFlags); |
| 334 | |
| 335 | virtual int32_t getMetaState(); |
| 336 | |
| 337 | protected: |
| 338 | InputDevice* mDevice; |
| 339 | InputReaderContext* mContext; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 340 | }; |
| 341 | |
| 342 | |
| 343 | class SwitchInputMapper : public InputMapper { |
| 344 | public: |
| 345 | SwitchInputMapper(InputDevice* device); |
| 346 | virtual ~SwitchInputMapper(); |
| 347 | |
| 348 | virtual uint32_t getSources(); |
| 349 | virtual void process(const RawEvent* rawEvent); |
| 350 | |
| 351 | virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 352 | |
| 353 | private: |
| 354 | void processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue); |
| 355 | }; |
| 356 | |
| 357 | |
| 358 | class KeyboardInputMapper : public InputMapper { |
| 359 | public: |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 360 | KeyboardInputMapper(InputDevice* device, uint32_t sources, int32_t keyboardType); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 361 | virtual ~KeyboardInputMapper(); |
| 362 | |
| 363 | virtual uint32_t getSources(); |
| 364 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 365 | virtual void dump(String8& dump); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 366 | virtual void configure(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 367 | virtual void reset(); |
| 368 | virtual void process(const RawEvent* rawEvent); |
| 369 | |
| 370 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 371 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 372 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 373 | const int32_t* keyCodes, uint8_t* outFlags); |
| 374 | |
| 375 | virtual int32_t getMetaState(); |
| 376 | |
| 377 | private: |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 378 | Mutex mLock; |
| 379 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 380 | struct KeyDown { |
| 381 | int32_t keyCode; |
| 382 | int32_t scanCode; |
| 383 | }; |
| 384 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 385 | uint32_t mSources; |
| 386 | int32_t mKeyboardType; |
| 387 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 388 | // Immutable configuration parameters. |
| 389 | struct Parameters { |
| 390 | int32_t associatedDisplayId; |
| 391 | bool orientationAware; |
| 392 | } mParameters; |
| 393 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 394 | struct LockedState { |
| 395 | Vector<KeyDown> keyDowns; // keys that are down |
| 396 | int32_t metaState; |
| 397 | nsecs_t downTime; // time of most recent key down |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 398 | |
| 399 | struct LedState { |
| 400 | bool avail; // led is available |
| 401 | bool on; // we think the led is currently on |
| 402 | }; |
| 403 | LedState capsLockLedState; |
| 404 | LedState numLockLedState; |
| 405 | LedState scrollLockLedState; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 406 | } mLocked; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 407 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 408 | void initializeLocked(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 409 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 410 | void configureParameters(); |
| 411 | void dumpParameters(String8& dump); |
| 412 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 413 | bool isKeyboardOrGamepadKey(int32_t scanCode); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 414 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 415 | void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode, |
| 416 | uint32_t policyFlags); |
| 417 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 418 | ssize_t findKeyDownLocked(int32_t scanCode); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 419 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 420 | void resetLedStateLocked(); |
| 421 | void initializeLedStateLocked(LockedState::LedState& ledState, int32_t led); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 422 | void updateLedStateLocked(bool reset); |
| 423 | void updateLedStateForModifierLocked(LockedState::LedState& ledState, int32_t led, |
| 424 | int32_t modifier, bool reset); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 425 | }; |
| 426 | |
| 427 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame^] | 428 | class CursorInputMapper : public InputMapper { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 429 | public: |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame^] | 430 | CursorInputMapper(InputDevice* device); |
| 431 | virtual ~CursorInputMapper(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 432 | |
| 433 | virtual uint32_t getSources(); |
| 434 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 435 | virtual void dump(String8& dump); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 436 | virtual void configure(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 437 | virtual void reset(); |
| 438 | virtual void process(const RawEvent* rawEvent); |
| 439 | |
Jeff Brown | c3fc2d0 | 2010-08-10 15:47:53 -0700 | [diff] [blame] | 440 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 441 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 442 | private: |
| 443 | // Amount that trackball needs to move in order to generate a key event. |
| 444 | static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6; |
| 445 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 446 | Mutex mLock; |
| 447 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 448 | // Immutable configuration parameters. |
| 449 | struct Parameters { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame^] | 450 | enum Mode { |
| 451 | MODE_POINTER, |
| 452 | MODE_NAVIGATION, |
| 453 | }; |
| 454 | |
| 455 | Mode mode; |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 456 | int32_t associatedDisplayId; |
| 457 | bool orientationAware; |
| 458 | } mParameters; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 459 | |
| 460 | struct Accumulator { |
| 461 | enum { |
| 462 | FIELD_BTN_MOUSE = 1, |
| 463 | FIELD_REL_X = 2, |
| 464 | FIELD_REL_Y = 4 |
| 465 | }; |
| 466 | |
| 467 | uint32_t fields; |
| 468 | |
| 469 | bool btnMouse; |
| 470 | int32_t relX; |
| 471 | int32_t relY; |
| 472 | |
| 473 | inline void clear() { |
| 474 | fields = 0; |
| 475 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 476 | } mAccumulator; |
| 477 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame^] | 478 | int32_t mSources; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 479 | float mXScale; |
| 480 | float mYScale; |
| 481 | float mXPrecision; |
| 482 | float mYPrecision; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame^] | 483 | sp<PointerControllerInterface> mPointerController; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 484 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 485 | struct LockedState { |
| 486 | bool down; |
| 487 | nsecs_t downTime; |
| 488 | } mLocked; |
| 489 | |
| 490 | void initializeLocked(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 491 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 492 | void configureParameters(); |
| 493 | void dumpParameters(String8& dump); |
| 494 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 495 | void sync(nsecs_t when); |
| 496 | }; |
| 497 | |
| 498 | |
| 499 | class TouchInputMapper : public InputMapper { |
| 500 | public: |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 501 | TouchInputMapper(InputDevice* device); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 502 | virtual ~TouchInputMapper(); |
| 503 | |
| 504 | virtual uint32_t getSources(); |
| 505 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 506 | virtual void dump(String8& dump); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 507 | virtual void configure(); |
| 508 | virtual void reset(); |
| 509 | |
| 510 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 511 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 512 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 513 | const int32_t* keyCodes, uint8_t* outFlags); |
| 514 | |
| 515 | protected: |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 516 | Mutex mLock; |
| 517 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 518 | struct VirtualKey { |
| 519 | int32_t keyCode; |
| 520 | int32_t scanCode; |
| 521 | uint32_t flags; |
| 522 | |
| 523 | // computed hit box, specified in touch screen coords based on known display size |
| 524 | int32_t hitLeft; |
| 525 | int32_t hitTop; |
| 526 | int32_t hitRight; |
| 527 | int32_t hitBottom; |
| 528 | |
| 529 | inline bool isHit(int32_t x, int32_t y) const { |
| 530 | return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom; |
| 531 | } |
| 532 | }; |
| 533 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 534 | // Raw data for a single pointer. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 535 | struct PointerData { |
| 536 | uint32_t id; |
| 537 | int32_t x; |
| 538 | int32_t y; |
| 539 | int32_t pressure; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 540 | int32_t touchMajor; |
| 541 | int32_t touchMinor; |
| 542 | int32_t toolMajor; |
| 543 | int32_t toolMinor; |
| 544 | int32_t orientation; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 545 | |
| 546 | inline bool operator== (const PointerData& other) const { |
| 547 | return id == other.id |
| 548 | && x == other.x |
| 549 | && y == other.y |
| 550 | && pressure == other.pressure |
| 551 | && touchMajor == other.touchMajor |
| 552 | && touchMinor == other.touchMinor |
| 553 | && toolMajor == other.toolMajor |
| 554 | && toolMinor == other.toolMinor |
| 555 | && orientation == other.orientation; |
| 556 | } |
| 557 | inline bool operator!= (const PointerData& other) const { |
| 558 | return !(*this == other); |
| 559 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 560 | }; |
| 561 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 562 | // 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] | 563 | struct TouchData { |
| 564 | uint32_t pointerCount; |
| 565 | PointerData pointers[MAX_POINTERS]; |
| 566 | BitSet32 idBits; |
| 567 | uint32_t idToIndex[MAX_POINTER_ID + 1]; |
| 568 | |
| 569 | void copyFrom(const TouchData& other) { |
| 570 | pointerCount = other.pointerCount; |
| 571 | idBits = other.idBits; |
| 572 | |
| 573 | for (uint32_t i = 0; i < pointerCount; i++) { |
| 574 | pointers[i] = other.pointers[i]; |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame] | 575 | |
| 576 | int id = pointers[i].id; |
| 577 | idToIndex[id] = other.idToIndex[id]; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
| 581 | inline void clear() { |
| 582 | pointerCount = 0; |
| 583 | idBits.clear(); |
| 584 | } |
| 585 | }; |
| 586 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame^] | 587 | // Input sources supported by the device. |
| 588 | int32_t mSources; |
| 589 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 590 | // Immutable configuration parameters. |
| 591 | struct Parameters { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 592 | enum DeviceType { |
| 593 | DEVICE_TYPE_TOUCH_SCREEN, |
| 594 | DEVICE_TYPE_TOUCH_PAD, |
| 595 | }; |
| 596 | |
| 597 | DeviceType deviceType; |
| 598 | int32_t associatedDisplayId; |
| 599 | bool orientationAware; |
| 600 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 601 | bool useBadTouchFilter; |
| 602 | bool useJumpyTouchFilter; |
| 603 | bool useAveragingTouchFilter; |
| 604 | } mParameters; |
| 605 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 606 | // Immutable calibration parameters in parsed form. |
| 607 | struct Calibration { |
Jeff Brown | 511ee5f | 2010-10-18 13:32:20 -0700 | [diff] [blame] | 608 | // Position |
| 609 | bool haveXOrigin; |
| 610 | int32_t xOrigin; |
| 611 | bool haveYOrigin; |
| 612 | int32_t yOrigin; |
| 613 | bool haveXScale; |
| 614 | float xScale; |
| 615 | bool haveYScale; |
| 616 | float yScale; |
| 617 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 618 | // Touch Size |
| 619 | enum TouchSizeCalibration { |
| 620 | TOUCH_SIZE_CALIBRATION_DEFAULT, |
| 621 | TOUCH_SIZE_CALIBRATION_NONE, |
| 622 | TOUCH_SIZE_CALIBRATION_GEOMETRIC, |
| 623 | TOUCH_SIZE_CALIBRATION_PRESSURE, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 624 | }; |
| 625 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 626 | TouchSizeCalibration touchSizeCalibration; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 627 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 628 | // Tool Size |
| 629 | enum ToolSizeCalibration { |
| 630 | TOOL_SIZE_CALIBRATION_DEFAULT, |
| 631 | TOOL_SIZE_CALIBRATION_NONE, |
| 632 | TOOL_SIZE_CALIBRATION_GEOMETRIC, |
| 633 | TOOL_SIZE_CALIBRATION_LINEAR, |
| 634 | TOOL_SIZE_CALIBRATION_AREA, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 635 | }; |
| 636 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 637 | ToolSizeCalibration toolSizeCalibration; |
| 638 | bool haveToolSizeLinearScale; |
| 639 | float toolSizeLinearScale; |
| 640 | bool haveToolSizeLinearBias; |
| 641 | float toolSizeLinearBias; |
| 642 | bool haveToolSizeAreaScale; |
| 643 | float toolSizeAreaScale; |
| 644 | bool haveToolSizeAreaBias; |
| 645 | float toolSizeAreaBias; |
| 646 | bool haveToolSizeIsSummed; |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 647 | bool toolSizeIsSummed; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 648 | |
| 649 | // Pressure |
| 650 | enum PressureCalibration { |
| 651 | PRESSURE_CALIBRATION_DEFAULT, |
| 652 | PRESSURE_CALIBRATION_NONE, |
| 653 | PRESSURE_CALIBRATION_PHYSICAL, |
| 654 | PRESSURE_CALIBRATION_AMPLITUDE, |
| 655 | }; |
| 656 | enum PressureSource { |
| 657 | PRESSURE_SOURCE_DEFAULT, |
| 658 | PRESSURE_SOURCE_PRESSURE, |
| 659 | PRESSURE_SOURCE_TOUCH, |
| 660 | }; |
| 661 | |
| 662 | PressureCalibration pressureCalibration; |
| 663 | PressureSource pressureSource; |
| 664 | bool havePressureScale; |
| 665 | float pressureScale; |
| 666 | |
| 667 | // Size |
| 668 | enum SizeCalibration { |
| 669 | SIZE_CALIBRATION_DEFAULT, |
| 670 | SIZE_CALIBRATION_NONE, |
| 671 | SIZE_CALIBRATION_NORMALIZED, |
| 672 | }; |
| 673 | |
| 674 | SizeCalibration sizeCalibration; |
| 675 | |
| 676 | // Orientation |
| 677 | enum OrientationCalibration { |
| 678 | ORIENTATION_CALIBRATION_DEFAULT, |
| 679 | ORIENTATION_CALIBRATION_NONE, |
| 680 | ORIENTATION_CALIBRATION_INTERPOLATED, |
| 681 | }; |
| 682 | |
| 683 | OrientationCalibration orientationCalibration; |
| 684 | } mCalibration; |
| 685 | |
| 686 | // Raw axis information from the driver. |
| 687 | struct RawAxes { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 688 | RawAbsoluteAxisInfo x; |
| 689 | RawAbsoluteAxisInfo y; |
| 690 | RawAbsoluteAxisInfo pressure; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 691 | RawAbsoluteAxisInfo touchMajor; |
| 692 | RawAbsoluteAxisInfo touchMinor; |
| 693 | RawAbsoluteAxisInfo toolMajor; |
| 694 | RawAbsoluteAxisInfo toolMinor; |
| 695 | RawAbsoluteAxisInfo orientation; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 696 | } mRawAxes; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 697 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 698 | // Current and previous touch sample data. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 699 | TouchData mCurrentTouch; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 700 | TouchData mLastTouch; |
| 701 | |
| 702 | // The time the primary pointer last went down. |
| 703 | nsecs_t mDownTime; |
| 704 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 705 | struct LockedState { |
| 706 | Vector<VirtualKey> virtualKeys; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 707 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 708 | // The surface orientation and width and height set by configureSurfaceLocked(). |
| 709 | int32_t surfaceOrientation; |
| 710 | int32_t surfaceWidth, surfaceHeight; |
| 711 | |
| 712 | // Translation and scaling factors, orientation-independent. |
| 713 | int32_t xOrigin; |
| 714 | float xScale; |
| 715 | float xPrecision; |
| 716 | |
| 717 | int32_t yOrigin; |
| 718 | float yScale; |
| 719 | float yPrecision; |
| 720 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 721 | float geometricScale; |
| 722 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 723 | float toolSizeLinearScale; |
| 724 | float toolSizeLinearBias; |
| 725 | float toolSizeAreaScale; |
| 726 | float toolSizeAreaBias; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 727 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 728 | float pressureScale; |
| 729 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 730 | float sizeScale; |
| 731 | |
| 732 | float orientationScale; |
| 733 | |
| 734 | // Oriented motion ranges for input device info. |
| 735 | struct OrientedRanges { |
| 736 | InputDeviceInfo::MotionRange x; |
| 737 | InputDeviceInfo::MotionRange y; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 738 | |
| 739 | bool havePressure; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 740 | InputDeviceInfo::MotionRange pressure; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 741 | |
| 742 | bool haveSize; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 743 | InputDeviceInfo::MotionRange size; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 744 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 745 | bool haveTouchSize; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 746 | InputDeviceInfo::MotionRange touchMajor; |
| 747 | InputDeviceInfo::MotionRange touchMinor; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 748 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 749 | bool haveToolSize; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 750 | InputDeviceInfo::MotionRange toolMajor; |
| 751 | InputDeviceInfo::MotionRange toolMinor; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 752 | |
| 753 | bool haveOrientation; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 754 | InputDeviceInfo::MotionRange orientation; |
| 755 | } orientedRanges; |
| 756 | |
| 757 | // Oriented dimensions and precision. |
| 758 | float orientedSurfaceWidth, orientedSurfaceHeight; |
| 759 | float orientedXPrecision, orientedYPrecision; |
| 760 | |
| 761 | struct CurrentVirtualKeyState { |
| 762 | bool down; |
| 763 | nsecs_t downTime; |
| 764 | int32_t keyCode; |
| 765 | int32_t scanCode; |
| 766 | } currentVirtualKey; |
| 767 | } mLocked; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 768 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 769 | virtual void configureParameters(); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 770 | virtual void dumpParameters(String8& dump); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 771 | virtual void configureRawAxes(); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 772 | virtual void dumpRawAxes(String8& dump); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 773 | virtual bool configureSurfaceLocked(); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 774 | virtual void dumpSurfaceLocked(String8& dump); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 775 | virtual void configureVirtualKeysLocked(); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 776 | virtual void dumpVirtualKeysLocked(String8& dump); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 777 | virtual void parseCalibration(); |
| 778 | virtual void resolveCalibration(); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 779 | virtual void dumpCalibration(String8& dump); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 780 | |
| 781 | enum TouchResult { |
| 782 | // Dispatch the touch normally. |
| 783 | DISPATCH_TOUCH, |
| 784 | // Do not dispatch the touch, but keep tracking the current stroke. |
| 785 | SKIP_TOUCH, |
| 786 | // Do not dispatch the touch, and drop all information associated with the current stoke |
| 787 | // so the next movement will appear as a new down. |
| 788 | DROP_STROKE |
| 789 | }; |
| 790 | |
| 791 | void syncTouch(nsecs_t when, bool havePointerIds); |
| 792 | |
| 793 | private: |
| 794 | /* Maximum number of historical samples to average. */ |
| 795 | static const uint32_t AVERAGING_HISTORY_SIZE = 5; |
| 796 | |
| 797 | /* Slop distance for jumpy pointer detection. |
| 798 | * The vertical range of the screen divided by this is our epsilon value. */ |
| 799 | static const uint32_t JUMPY_EPSILON_DIVISOR = 212; |
| 800 | |
| 801 | /* Number of jumpy points to drop for touchscreens that need it. */ |
| 802 | static const uint32_t JUMPY_TRANSITION_DROPS = 3; |
| 803 | static const uint32_t JUMPY_DROP_LIMIT = 3; |
| 804 | |
| 805 | /* Maximum squared distance for averaging. |
| 806 | * If moving farther than this, turn of averaging to avoid lag in response. */ |
| 807 | static const uint64_t AVERAGING_DISTANCE_LIMIT = 75 * 75; |
| 808 | |
| 809 | struct AveragingTouchFilterState { |
| 810 | // Individual history tracks are stored by pointer id |
| 811 | uint32_t historyStart[MAX_POINTERS]; |
| 812 | uint32_t historyEnd[MAX_POINTERS]; |
| 813 | struct { |
| 814 | struct { |
| 815 | int32_t x; |
| 816 | int32_t y; |
| 817 | int32_t pressure; |
| 818 | } pointers[MAX_POINTERS]; |
| 819 | } historyData[AVERAGING_HISTORY_SIZE]; |
| 820 | } mAveragingTouchFilter; |
| 821 | |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 822 | struct JumpyTouchFilterState { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 823 | uint32_t jumpyPointsDropped; |
| 824 | } mJumpyTouchFilter; |
| 825 | |
| 826 | struct PointerDistanceHeapElement { |
| 827 | uint32_t currentPointerIndex : 8; |
| 828 | uint32_t lastPointerIndex : 8; |
| 829 | uint64_t distance : 48; // squared distance |
| 830 | }; |
| 831 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 832 | void initializeLocked(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 833 | |
| 834 | TouchResult consumeOffScreenTouches(nsecs_t when, uint32_t policyFlags); |
| 835 | void dispatchTouches(nsecs_t when, uint32_t policyFlags); |
| 836 | void dispatchTouch(nsecs_t when, uint32_t policyFlags, TouchData* touch, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 837 | BitSet32 idBits, uint32_t changedId, uint32_t pointerCount, |
| 838 | int32_t motionEventAction); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 839 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 840 | bool isPointInsideSurfaceLocked(int32_t x, int32_t y); |
| 841 | const VirtualKey* findVirtualKeyHitLocked(int32_t x, int32_t y); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 842 | |
| 843 | bool applyBadTouchFilter(); |
| 844 | bool applyJumpyTouchFilter(); |
| 845 | void applyAveragingTouchFilter(); |
| 846 | void calculatePointerIds(); |
| 847 | }; |
| 848 | |
| 849 | |
| 850 | class SingleTouchInputMapper : public TouchInputMapper { |
| 851 | public: |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 852 | SingleTouchInputMapper(InputDevice* device); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 853 | virtual ~SingleTouchInputMapper(); |
| 854 | |
| 855 | virtual void reset(); |
| 856 | virtual void process(const RawEvent* rawEvent); |
| 857 | |
| 858 | protected: |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 859 | virtual void configureRawAxes(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 860 | |
| 861 | private: |
| 862 | struct Accumulator { |
| 863 | enum { |
| 864 | FIELD_BTN_TOUCH = 1, |
| 865 | FIELD_ABS_X = 2, |
| 866 | FIELD_ABS_Y = 4, |
| 867 | FIELD_ABS_PRESSURE = 8, |
| 868 | FIELD_ABS_TOOL_WIDTH = 16 |
| 869 | }; |
| 870 | |
| 871 | uint32_t fields; |
| 872 | |
| 873 | bool btnTouch; |
| 874 | int32_t absX; |
| 875 | int32_t absY; |
| 876 | int32_t absPressure; |
| 877 | int32_t absToolWidth; |
| 878 | |
| 879 | inline void clear() { |
| 880 | fields = 0; |
| 881 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 882 | } mAccumulator; |
| 883 | |
| 884 | bool mDown; |
| 885 | int32_t mX; |
| 886 | int32_t mY; |
| 887 | int32_t mPressure; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 888 | int32_t mToolWidth; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 889 | |
| 890 | void initialize(); |
| 891 | |
| 892 | void sync(nsecs_t when); |
| 893 | }; |
| 894 | |
| 895 | |
| 896 | class MultiTouchInputMapper : public TouchInputMapper { |
| 897 | public: |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 898 | MultiTouchInputMapper(InputDevice* device); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 899 | virtual ~MultiTouchInputMapper(); |
| 900 | |
| 901 | virtual void reset(); |
| 902 | virtual void process(const RawEvent* rawEvent); |
| 903 | |
| 904 | protected: |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 905 | virtual void configureRawAxes(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 906 | |
| 907 | private: |
| 908 | struct Accumulator { |
| 909 | enum { |
| 910 | FIELD_ABS_MT_POSITION_X = 1, |
| 911 | FIELD_ABS_MT_POSITION_Y = 2, |
| 912 | FIELD_ABS_MT_TOUCH_MAJOR = 4, |
| 913 | FIELD_ABS_MT_TOUCH_MINOR = 8, |
| 914 | FIELD_ABS_MT_WIDTH_MAJOR = 16, |
| 915 | FIELD_ABS_MT_WIDTH_MINOR = 32, |
| 916 | FIELD_ABS_MT_ORIENTATION = 64, |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 917 | FIELD_ABS_MT_TRACKING_ID = 128, |
| 918 | FIELD_ABS_MT_PRESSURE = 256, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 919 | }; |
| 920 | |
| 921 | uint32_t pointerCount; |
| 922 | struct Pointer { |
| 923 | uint32_t fields; |
| 924 | |
| 925 | int32_t absMTPositionX; |
| 926 | int32_t absMTPositionY; |
| 927 | int32_t absMTTouchMajor; |
| 928 | int32_t absMTTouchMinor; |
| 929 | int32_t absMTWidthMajor; |
| 930 | int32_t absMTWidthMinor; |
| 931 | int32_t absMTOrientation; |
| 932 | int32_t absMTTrackingId; |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 933 | int32_t absMTPressure; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 934 | |
| 935 | inline void clear() { |
| 936 | fields = 0; |
| 937 | } |
| 938 | } pointers[MAX_POINTERS + 1]; // + 1 to remove the need for extra range checks |
| 939 | |
| 940 | inline void clear() { |
| 941 | pointerCount = 0; |
| 942 | pointers[0].clear(); |
| 943 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 944 | } mAccumulator; |
| 945 | |
| 946 | void initialize(); |
| 947 | |
| 948 | void sync(nsecs_t when); |
| 949 | }; |
| 950 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 951 | } // namespace android |
| 952 | |
| 953 | #endif // _UI_INPUT_READER_H |