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