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