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