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