Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2010 The Android Open Source Project |
| 3 | // |
| 4 | // The input reader. |
| 5 | // |
| 6 | #define LOG_TAG "InputReader" |
| 7 | |
| 8 | //#define LOG_NDEBUG 0 |
| 9 | |
| 10 | // Log debug messages for each raw event received from the EventHub. |
| 11 | #define DEBUG_RAW_EVENTS 0 |
| 12 | |
| 13 | // Log debug messages about touch screen filtering hacks. |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 14 | #define DEBUG_HACKS 0 |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 15 | |
| 16 | // Log debug messages about virtual key processing. |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 17 | #define DEBUG_VIRTUAL_KEYS 0 |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 18 | |
| 19 | // Log debug messages about pointers. |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 20 | #define DEBUG_POINTERS 0 |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 21 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 22 | // Log debug messages about pointer assignment calculations. |
| 23 | #define DEBUG_POINTER_ASSIGNMENT 0 |
| 24 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 25 | #include <cutils/log.h> |
| 26 | #include <ui/InputReader.h> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 27 | #include <ui/Keyboard.h> |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 28 | #include <ui/VirtualKeyMap.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 29 | |
| 30 | #include <stddef.h> |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 31 | #include <stdlib.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 32 | #include <unistd.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 33 | #include <errno.h> |
| 34 | #include <limits.h> |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 35 | #include <math.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 36 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 37 | #define INDENT " " |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 38 | #define INDENT2 " " |
| 39 | #define INDENT3 " " |
| 40 | #define INDENT4 " " |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 41 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 42 | namespace android { |
| 43 | |
| 44 | // --- Static Functions --- |
| 45 | |
| 46 | template<typename T> |
| 47 | inline static T abs(const T& value) { |
| 48 | return value < 0 ? - value : value; |
| 49 | } |
| 50 | |
| 51 | template<typename T> |
| 52 | inline static T min(const T& a, const T& b) { |
| 53 | return a < b ? a : b; |
| 54 | } |
| 55 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 56 | template<typename T> |
| 57 | inline static void swap(T& a, T& b) { |
| 58 | T temp = a; |
| 59 | a = b; |
| 60 | b = temp; |
| 61 | } |
| 62 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 63 | inline static float avg(float x, float y) { |
| 64 | return (x + y) / 2; |
| 65 | } |
| 66 | |
| 67 | inline static float pythag(float x, float y) { |
| 68 | return sqrtf(x * x + y * y); |
| 69 | } |
| 70 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 71 | static inline const char* toString(bool value) { |
| 72 | return value ? "true" : "false"; |
| 73 | } |
| 74 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 75 | static const int32_t keyCodeRotationMap[][4] = { |
| 76 | // key codes enumerated counter-clockwise with the original (unrotated) key first |
| 77 | // no rotation, 90 degree rotation, 180 degree rotation, 270 degree rotation |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 78 | { AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT }, |
| 79 | { AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN }, |
| 80 | { AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT }, |
| 81 | { AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP }, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 82 | }; |
| 83 | static const int keyCodeRotationMapSize = |
| 84 | sizeof(keyCodeRotationMap) / sizeof(keyCodeRotationMap[0]); |
| 85 | |
| 86 | int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 87 | if (orientation != InputReaderPolicyInterface::ROTATION_0) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 88 | for (int i = 0; i < keyCodeRotationMapSize; i++) { |
| 89 | if (keyCode == keyCodeRotationMap[i][0]) { |
| 90 | return keyCodeRotationMap[i][orientation]; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | return keyCode; |
| 95 | } |
| 96 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 97 | static inline bool sourcesMatchMask(uint32_t sources, uint32_t sourceMask) { |
| 98 | return (sources & sourceMask & ~ AINPUT_SOURCE_CLASS_MASK) != 0; |
| 99 | } |
| 100 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 101 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 102 | // --- InputReader --- |
| 103 | |
| 104 | InputReader::InputReader(const sp<EventHubInterface>& eventHub, |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 105 | const sp<InputReaderPolicyInterface>& policy, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 106 | const sp<InputDispatcherInterface>& dispatcher) : |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 107 | mEventHub(eventHub), mPolicy(policy), mDispatcher(dispatcher), |
| 108 | mGlobalMetaState(0) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 109 | configureExcludedDevices(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 110 | updateGlobalMetaState(); |
| 111 | updateInputConfiguration(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | InputReader::~InputReader() { |
| 115 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 116 | delete mDevices.valueAt(i); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | void InputReader::loopOnce() { |
| 121 | RawEvent rawEvent; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 122 | mEventHub->getEvent(& rawEvent); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 123 | |
| 124 | #if DEBUG_RAW_EVENTS |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 125 | LOGD("Input event: device=%d type=0x%x scancode=%d keycode=%d value=%d", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 126 | rawEvent.deviceId, rawEvent.type, rawEvent.scanCode, rawEvent.keyCode, |
| 127 | rawEvent.value); |
| 128 | #endif |
| 129 | |
| 130 | process(& rawEvent); |
| 131 | } |
| 132 | |
| 133 | void InputReader::process(const RawEvent* rawEvent) { |
| 134 | switch (rawEvent->type) { |
| 135 | case EventHubInterface::DEVICE_ADDED: |
Jeff Brown | 7342bb9 | 2010-10-01 18:55:43 -0700 | [diff] [blame] | 136 | addDevice(rawEvent->deviceId); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 137 | break; |
| 138 | |
| 139 | case EventHubInterface::DEVICE_REMOVED: |
Jeff Brown | 7342bb9 | 2010-10-01 18:55:43 -0700 | [diff] [blame] | 140 | removeDevice(rawEvent->deviceId); |
| 141 | break; |
| 142 | |
| 143 | case EventHubInterface::FINISHED_DEVICE_SCAN: |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 144 | handleConfigurationChanged(rawEvent->when); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 145 | break; |
| 146 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 147 | default: |
| 148 | consumeEvent(rawEvent); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 149 | break; |
| 150 | } |
| 151 | } |
| 152 | |
Jeff Brown | 7342bb9 | 2010-10-01 18:55:43 -0700 | [diff] [blame] | 153 | void InputReader::addDevice(int32_t deviceId) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 154 | String8 name = mEventHub->getDeviceName(deviceId); |
| 155 | uint32_t classes = mEventHub->getDeviceClasses(deviceId); |
| 156 | |
| 157 | InputDevice* device = createDevice(deviceId, name, classes); |
| 158 | device->configure(); |
| 159 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 160 | if (device->isIgnored()) { |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 161 | LOGI("Device added: id=%d, name='%s' (ignored non-input device)", deviceId, name.string()); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 162 | } else { |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 163 | LOGI("Device added: id=%d, name='%s', sources=0x%08x", deviceId, name.string(), |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 164 | device->getSources()); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 167 | bool added = false; |
| 168 | { // acquire device registry writer lock |
| 169 | RWLock::AutoWLock _wl(mDeviceRegistryLock); |
| 170 | |
| 171 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 172 | if (deviceIndex < 0) { |
| 173 | mDevices.add(deviceId, device); |
| 174 | added = true; |
| 175 | } |
| 176 | } // release device registry writer lock |
| 177 | |
| 178 | if (! added) { |
| 179 | LOGW("Ignoring spurious device added event for deviceId %d.", deviceId); |
| 180 | delete device; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 181 | return; |
| 182 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Jeff Brown | 7342bb9 | 2010-10-01 18:55:43 -0700 | [diff] [blame] | 185 | void InputReader::removeDevice(int32_t deviceId) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 186 | bool removed = false; |
| 187 | InputDevice* device = NULL; |
| 188 | { // acquire device registry writer lock |
| 189 | RWLock::AutoWLock _wl(mDeviceRegistryLock); |
| 190 | |
| 191 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 192 | if (deviceIndex >= 0) { |
| 193 | device = mDevices.valueAt(deviceIndex); |
| 194 | mDevices.removeItemsAt(deviceIndex, 1); |
| 195 | removed = true; |
| 196 | } |
| 197 | } // release device registry writer lock |
| 198 | |
| 199 | if (! removed) { |
| 200 | LOGW("Ignoring spurious device removed event for deviceId %d.", deviceId); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 201 | return; |
| 202 | } |
| 203 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 204 | if (device->isIgnored()) { |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 205 | LOGI("Device removed: id=%d, name='%s' (ignored non-input device)", |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 206 | device->getId(), device->getName().string()); |
| 207 | } else { |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 208 | LOGI("Device removed: id=%d, name='%s', sources=0x%08x", |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 209 | device->getId(), device->getName().string(), device->getSources()); |
| 210 | } |
| 211 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 212 | device->reset(); |
| 213 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 214 | delete device; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 217 | InputDevice* InputReader::createDevice(int32_t deviceId, const String8& name, uint32_t classes) { |
| 218 | InputDevice* device = new InputDevice(this, deviceId, name); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 219 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 220 | // Switch-like devices. |
| 221 | if (classes & INPUT_DEVICE_CLASS_SWITCH) { |
| 222 | device->addMapper(new SwitchInputMapper(device)); |
| 223 | } |
| 224 | |
| 225 | // Keyboard-like devices. |
| 226 | uint32_t keyboardSources = 0; |
| 227 | int32_t keyboardType = AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC; |
| 228 | if (classes & INPUT_DEVICE_CLASS_KEYBOARD) { |
| 229 | keyboardSources |= AINPUT_SOURCE_KEYBOARD; |
| 230 | } |
| 231 | if (classes & INPUT_DEVICE_CLASS_ALPHAKEY) { |
| 232 | keyboardType = AINPUT_KEYBOARD_TYPE_ALPHABETIC; |
| 233 | } |
| 234 | if (classes & INPUT_DEVICE_CLASS_DPAD) { |
| 235 | keyboardSources |= AINPUT_SOURCE_DPAD; |
| 236 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 237 | |
| 238 | if (keyboardSources != 0) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 239 | device->addMapper(new KeyboardInputMapper(device, keyboardSources, keyboardType)); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 242 | // Cursor-like devices. |
| 243 | if (classes & INPUT_DEVICE_CLASS_CURSOR) { |
| 244 | device->addMapper(new CursorInputMapper(device)); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | // Touchscreen-like devices. |
| 248 | if (classes & INPUT_DEVICE_CLASS_TOUCHSCREEN_MT) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 249 | device->addMapper(new MultiTouchInputMapper(device)); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 250 | } else if (classes & INPUT_DEVICE_CLASS_TOUCHSCREEN) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 251 | device->addMapper(new SingleTouchInputMapper(device)); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | return device; |
| 255 | } |
| 256 | |
| 257 | void InputReader::consumeEvent(const RawEvent* rawEvent) { |
| 258 | int32_t deviceId = rawEvent->deviceId; |
| 259 | |
| 260 | { // acquire device registry reader lock |
| 261 | RWLock::AutoRLock _rl(mDeviceRegistryLock); |
| 262 | |
| 263 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 264 | if (deviceIndex < 0) { |
| 265 | LOGW("Discarding event for unknown deviceId %d.", deviceId); |
| 266 | return; |
| 267 | } |
| 268 | |
| 269 | InputDevice* device = mDevices.valueAt(deviceIndex); |
| 270 | if (device->isIgnored()) { |
| 271 | //LOGD("Discarding event for ignored deviceId %d.", deviceId); |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | device->process(rawEvent); |
| 276 | } // release device registry reader lock |
| 277 | } |
| 278 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 279 | void InputReader::handleConfigurationChanged(nsecs_t when) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 280 | // Reset global meta state because it depends on the list of all configured devices. |
| 281 | updateGlobalMetaState(); |
| 282 | |
| 283 | // Update input configuration. |
| 284 | updateInputConfiguration(); |
| 285 | |
| 286 | // Enqueue configuration changed. |
| 287 | mDispatcher->notifyConfigurationChanged(when); |
| 288 | } |
| 289 | |
| 290 | void InputReader::configureExcludedDevices() { |
| 291 | Vector<String8> excludedDeviceNames; |
| 292 | mPolicy->getExcludedDeviceNames(excludedDeviceNames); |
| 293 | |
| 294 | for (size_t i = 0; i < excludedDeviceNames.size(); i++) { |
| 295 | mEventHub->addExcludedDevice(excludedDeviceNames[i]); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | void InputReader::updateGlobalMetaState() { |
| 300 | { // acquire state lock |
| 301 | AutoMutex _l(mStateLock); |
| 302 | |
| 303 | mGlobalMetaState = 0; |
| 304 | |
| 305 | { // acquire device registry reader lock |
| 306 | RWLock::AutoRLock _rl(mDeviceRegistryLock); |
| 307 | |
| 308 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 309 | InputDevice* device = mDevices.valueAt(i); |
| 310 | mGlobalMetaState |= device->getMetaState(); |
| 311 | } |
| 312 | } // release device registry reader lock |
| 313 | } // release state lock |
| 314 | } |
| 315 | |
| 316 | int32_t InputReader::getGlobalMetaState() { |
| 317 | { // acquire state lock |
| 318 | AutoMutex _l(mStateLock); |
| 319 | |
| 320 | return mGlobalMetaState; |
| 321 | } // release state lock |
| 322 | } |
| 323 | |
| 324 | void InputReader::updateInputConfiguration() { |
| 325 | { // acquire state lock |
| 326 | AutoMutex _l(mStateLock); |
| 327 | |
| 328 | int32_t touchScreenConfig = InputConfiguration::TOUCHSCREEN_NOTOUCH; |
| 329 | int32_t keyboardConfig = InputConfiguration::KEYBOARD_NOKEYS; |
| 330 | int32_t navigationConfig = InputConfiguration::NAVIGATION_NONAV; |
| 331 | { // acquire device registry reader lock |
| 332 | RWLock::AutoRLock _rl(mDeviceRegistryLock); |
| 333 | |
| 334 | InputDeviceInfo deviceInfo; |
| 335 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 336 | InputDevice* device = mDevices.valueAt(i); |
| 337 | device->getDeviceInfo(& deviceInfo); |
| 338 | uint32_t sources = deviceInfo.getSources(); |
| 339 | |
| 340 | if ((sources & AINPUT_SOURCE_TOUCHSCREEN) == AINPUT_SOURCE_TOUCHSCREEN) { |
| 341 | touchScreenConfig = InputConfiguration::TOUCHSCREEN_FINGER; |
| 342 | } |
| 343 | if ((sources & AINPUT_SOURCE_TRACKBALL) == AINPUT_SOURCE_TRACKBALL) { |
| 344 | navigationConfig = InputConfiguration::NAVIGATION_TRACKBALL; |
| 345 | } else if ((sources & AINPUT_SOURCE_DPAD) == AINPUT_SOURCE_DPAD) { |
| 346 | navigationConfig = InputConfiguration::NAVIGATION_DPAD; |
| 347 | } |
| 348 | if (deviceInfo.getKeyboardType() == AINPUT_KEYBOARD_TYPE_ALPHABETIC) { |
| 349 | keyboardConfig = InputConfiguration::KEYBOARD_QWERTY; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 352 | } // release device registry reader lock |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 353 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 354 | mInputConfiguration.touchScreen = touchScreenConfig; |
| 355 | mInputConfiguration.keyboard = keyboardConfig; |
| 356 | mInputConfiguration.navigation = navigationConfig; |
| 357 | } // release state lock |
| 358 | } |
| 359 | |
| 360 | void InputReader::getInputConfiguration(InputConfiguration* outConfiguration) { |
| 361 | { // acquire state lock |
| 362 | AutoMutex _l(mStateLock); |
| 363 | |
| 364 | *outConfiguration = mInputConfiguration; |
| 365 | } // release state lock |
| 366 | } |
| 367 | |
| 368 | status_t InputReader::getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo) { |
| 369 | { // acquire device registry reader lock |
| 370 | RWLock::AutoRLock _rl(mDeviceRegistryLock); |
| 371 | |
| 372 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 373 | if (deviceIndex < 0) { |
| 374 | return NAME_NOT_FOUND; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 377 | InputDevice* device = mDevices.valueAt(deviceIndex); |
| 378 | if (device->isIgnored()) { |
| 379 | return NAME_NOT_FOUND; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 380 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 381 | |
| 382 | device->getDeviceInfo(outDeviceInfo); |
| 383 | return OK; |
| 384 | } // release device registy reader lock |
| 385 | } |
| 386 | |
| 387 | void InputReader::getInputDeviceIds(Vector<int32_t>& outDeviceIds) { |
| 388 | outDeviceIds.clear(); |
| 389 | |
| 390 | { // acquire device registry reader lock |
| 391 | RWLock::AutoRLock _rl(mDeviceRegistryLock); |
| 392 | |
| 393 | size_t numDevices = mDevices.size(); |
| 394 | for (size_t i = 0; i < numDevices; i++) { |
| 395 | InputDevice* device = mDevices.valueAt(i); |
| 396 | if (! device->isIgnored()) { |
| 397 | outDeviceIds.add(device->getId()); |
| 398 | } |
| 399 | } |
| 400 | } // release device registy reader lock |
| 401 | } |
| 402 | |
| 403 | int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, |
| 404 | int32_t keyCode) { |
| 405 | return getState(deviceId, sourceMask, keyCode, & InputDevice::getKeyCodeState); |
| 406 | } |
| 407 | |
| 408 | int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask, |
| 409 | int32_t scanCode) { |
| 410 | return getState(deviceId, sourceMask, scanCode, & InputDevice::getScanCodeState); |
| 411 | } |
| 412 | |
| 413 | int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t switchCode) { |
| 414 | return getState(deviceId, sourceMask, switchCode, & InputDevice::getSwitchState); |
| 415 | } |
| 416 | |
| 417 | int32_t InputReader::getState(int32_t deviceId, uint32_t sourceMask, int32_t code, |
| 418 | GetStateFunc getStateFunc) { |
| 419 | { // acquire device registry reader lock |
| 420 | RWLock::AutoRLock _rl(mDeviceRegistryLock); |
| 421 | |
| 422 | int32_t result = AKEY_STATE_UNKNOWN; |
| 423 | if (deviceId >= 0) { |
| 424 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 425 | if (deviceIndex >= 0) { |
| 426 | InputDevice* device = mDevices.valueAt(deviceIndex); |
| 427 | if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
| 428 | result = (device->*getStateFunc)(sourceMask, code); |
| 429 | } |
| 430 | } |
| 431 | } else { |
| 432 | size_t numDevices = mDevices.size(); |
| 433 | for (size_t i = 0; i < numDevices; i++) { |
| 434 | InputDevice* device = mDevices.valueAt(i); |
| 435 | if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
| 436 | result = (device->*getStateFunc)(sourceMask, code); |
| 437 | if (result >= AKEY_STATE_DOWN) { |
| 438 | return result; |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | return result; |
| 444 | } // release device registy reader lock |
| 445 | } |
| 446 | |
| 447 | bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 448 | size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) { |
| 449 | memset(outFlags, 0, numCodes); |
| 450 | return markSupportedKeyCodes(deviceId, sourceMask, numCodes, keyCodes, outFlags); |
| 451 | } |
| 452 | |
| 453 | bool InputReader::markSupportedKeyCodes(int32_t deviceId, uint32_t sourceMask, size_t numCodes, |
| 454 | const int32_t* keyCodes, uint8_t* outFlags) { |
| 455 | { // acquire device registry reader lock |
| 456 | RWLock::AutoRLock _rl(mDeviceRegistryLock); |
| 457 | bool result = false; |
| 458 | if (deviceId >= 0) { |
| 459 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 460 | if (deviceIndex >= 0) { |
| 461 | InputDevice* device = mDevices.valueAt(deviceIndex); |
| 462 | if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
| 463 | result = device->markSupportedKeyCodes(sourceMask, |
| 464 | numCodes, keyCodes, outFlags); |
| 465 | } |
| 466 | } |
| 467 | } else { |
| 468 | size_t numDevices = mDevices.size(); |
| 469 | for (size_t i = 0; i < numDevices; i++) { |
| 470 | InputDevice* device = mDevices.valueAt(i); |
| 471 | if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
| 472 | result |= device->markSupportedKeyCodes(sourceMask, |
| 473 | numCodes, keyCodes, outFlags); |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | return result; |
| 478 | } // release device registy reader lock |
| 479 | } |
| 480 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 481 | void InputReader::dump(String8& dump) { |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 482 | mEventHub->dump(dump); |
| 483 | dump.append("\n"); |
| 484 | |
| 485 | dump.append("Input Reader State:\n"); |
| 486 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 487 | { // acquire device registry reader lock |
| 488 | RWLock::AutoRLock _rl(mDeviceRegistryLock); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 489 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 490 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 491 | mDevices.valueAt(i)->dump(dump); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 492 | } |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 493 | } // release device registy reader lock |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 496 | |
| 497 | // --- InputReaderThread --- |
| 498 | |
| 499 | InputReaderThread::InputReaderThread(const sp<InputReaderInterface>& reader) : |
| 500 | Thread(/*canCallJava*/ true), mReader(reader) { |
| 501 | } |
| 502 | |
| 503 | InputReaderThread::~InputReaderThread() { |
| 504 | } |
| 505 | |
| 506 | bool InputReaderThread::threadLoop() { |
| 507 | mReader->loopOnce(); |
| 508 | return true; |
| 509 | } |
| 510 | |
| 511 | |
| 512 | // --- InputDevice --- |
| 513 | |
| 514 | InputDevice::InputDevice(InputReaderContext* context, int32_t id, const String8& name) : |
| 515 | mContext(context), mId(id), mName(name), mSources(0) { |
| 516 | } |
| 517 | |
| 518 | InputDevice::~InputDevice() { |
| 519 | size_t numMappers = mMappers.size(); |
| 520 | for (size_t i = 0; i < numMappers; i++) { |
| 521 | delete mMappers[i]; |
| 522 | } |
| 523 | mMappers.clear(); |
| 524 | } |
| 525 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 526 | static void dumpMotionRange(String8& dump, const InputDeviceInfo& deviceInfo, |
| 527 | int32_t rangeType, const char* name) { |
| 528 | const InputDeviceInfo::MotionRange* range = deviceInfo.getMotionRange(rangeType); |
| 529 | if (range) { |
| 530 | dump.appendFormat(INDENT3 "%s: min=%0.3f, max=%0.3f, flat=%0.3f, fuzz=%0.3f\n", |
| 531 | name, range->min, range->max, range->flat, range->fuzz); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | void InputDevice::dump(String8& dump) { |
| 536 | InputDeviceInfo deviceInfo; |
| 537 | getDeviceInfo(& deviceInfo); |
| 538 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 539 | dump.appendFormat(INDENT "Device %d: %s\n", deviceInfo.getId(), |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 540 | deviceInfo.getName().string()); |
| 541 | dump.appendFormat(INDENT2 "Sources: 0x%08x\n", deviceInfo.getSources()); |
| 542 | dump.appendFormat(INDENT2 "KeyboardType: %d\n", deviceInfo.getKeyboardType()); |
| 543 | if (!deviceInfo.getMotionRanges().isEmpty()) { |
| 544 | dump.append(INDENT2 "Motion Ranges:\n"); |
| 545 | dumpMotionRange(dump, deviceInfo, AINPUT_MOTION_RANGE_X, "X"); |
| 546 | dumpMotionRange(dump, deviceInfo, AINPUT_MOTION_RANGE_Y, "Y"); |
| 547 | dumpMotionRange(dump, deviceInfo, AINPUT_MOTION_RANGE_PRESSURE, "Pressure"); |
| 548 | dumpMotionRange(dump, deviceInfo, AINPUT_MOTION_RANGE_SIZE, "Size"); |
| 549 | dumpMotionRange(dump, deviceInfo, AINPUT_MOTION_RANGE_TOUCH_MAJOR, "TouchMajor"); |
| 550 | dumpMotionRange(dump, deviceInfo, AINPUT_MOTION_RANGE_TOUCH_MINOR, "TouchMinor"); |
| 551 | dumpMotionRange(dump, deviceInfo, AINPUT_MOTION_RANGE_TOOL_MAJOR, "ToolMajor"); |
| 552 | dumpMotionRange(dump, deviceInfo, AINPUT_MOTION_RANGE_TOOL_MINOR, "ToolMinor"); |
| 553 | dumpMotionRange(dump, deviceInfo, AINPUT_MOTION_RANGE_ORIENTATION, "Orientation"); |
| 554 | } |
| 555 | |
| 556 | size_t numMappers = mMappers.size(); |
| 557 | for (size_t i = 0; i < numMappers; i++) { |
| 558 | InputMapper* mapper = mMappers[i]; |
| 559 | mapper->dump(dump); |
| 560 | } |
| 561 | } |
| 562 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 563 | void InputDevice::addMapper(InputMapper* mapper) { |
| 564 | mMappers.add(mapper); |
| 565 | } |
| 566 | |
| 567 | void InputDevice::configure() { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 568 | if (! isIgnored()) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 569 | mContext->getEventHub()->getConfiguration(mId, &mConfiguration); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 572 | mSources = 0; |
| 573 | |
| 574 | size_t numMappers = mMappers.size(); |
| 575 | for (size_t i = 0; i < numMappers; i++) { |
| 576 | InputMapper* mapper = mMappers[i]; |
| 577 | mapper->configure(); |
| 578 | mSources |= mapper->getSources(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 582 | void InputDevice::reset() { |
| 583 | size_t numMappers = mMappers.size(); |
| 584 | for (size_t i = 0; i < numMappers; i++) { |
| 585 | InputMapper* mapper = mMappers[i]; |
| 586 | mapper->reset(); |
| 587 | } |
| 588 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 589 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 590 | void InputDevice::process(const RawEvent* rawEvent) { |
| 591 | size_t numMappers = mMappers.size(); |
| 592 | for (size_t i = 0; i < numMappers; i++) { |
| 593 | InputMapper* mapper = mMappers[i]; |
| 594 | mapper->process(rawEvent); |
| 595 | } |
| 596 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 597 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 598 | void InputDevice::getDeviceInfo(InputDeviceInfo* outDeviceInfo) { |
| 599 | outDeviceInfo->initialize(mId, mName); |
| 600 | |
| 601 | size_t numMappers = mMappers.size(); |
| 602 | for (size_t i = 0; i < numMappers; i++) { |
| 603 | InputMapper* mapper = mMappers[i]; |
| 604 | mapper->populateDeviceInfo(outDeviceInfo); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | int32_t InputDevice::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) { |
| 609 | return getState(sourceMask, keyCode, & InputMapper::getKeyCodeState); |
| 610 | } |
| 611 | |
| 612 | int32_t InputDevice::getScanCodeState(uint32_t sourceMask, int32_t scanCode) { |
| 613 | return getState(sourceMask, scanCode, & InputMapper::getScanCodeState); |
| 614 | } |
| 615 | |
| 616 | int32_t InputDevice::getSwitchState(uint32_t sourceMask, int32_t switchCode) { |
| 617 | return getState(sourceMask, switchCode, & InputMapper::getSwitchState); |
| 618 | } |
| 619 | |
| 620 | int32_t InputDevice::getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc) { |
| 621 | int32_t result = AKEY_STATE_UNKNOWN; |
| 622 | size_t numMappers = mMappers.size(); |
| 623 | for (size_t i = 0; i < numMappers; i++) { |
| 624 | InputMapper* mapper = mMappers[i]; |
| 625 | if (sourcesMatchMask(mapper->getSources(), sourceMask)) { |
| 626 | result = (mapper->*getStateFunc)(sourceMask, code); |
| 627 | if (result >= AKEY_STATE_DOWN) { |
| 628 | return result; |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | return result; |
| 633 | } |
| 634 | |
| 635 | bool InputDevice::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 636 | const int32_t* keyCodes, uint8_t* outFlags) { |
| 637 | bool result = false; |
| 638 | size_t numMappers = mMappers.size(); |
| 639 | for (size_t i = 0; i < numMappers; i++) { |
| 640 | InputMapper* mapper = mMappers[i]; |
| 641 | if (sourcesMatchMask(mapper->getSources(), sourceMask)) { |
| 642 | result |= mapper->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags); |
| 643 | } |
| 644 | } |
| 645 | return result; |
| 646 | } |
| 647 | |
| 648 | int32_t InputDevice::getMetaState() { |
| 649 | int32_t result = 0; |
| 650 | size_t numMappers = mMappers.size(); |
| 651 | for (size_t i = 0; i < numMappers; i++) { |
| 652 | InputMapper* mapper = mMappers[i]; |
| 653 | result |= mapper->getMetaState(); |
| 654 | } |
| 655 | return result; |
| 656 | } |
| 657 | |
| 658 | |
| 659 | // --- InputMapper --- |
| 660 | |
| 661 | InputMapper::InputMapper(InputDevice* device) : |
| 662 | mDevice(device), mContext(device->getContext()) { |
| 663 | } |
| 664 | |
| 665 | InputMapper::~InputMapper() { |
| 666 | } |
| 667 | |
| 668 | void InputMapper::populateDeviceInfo(InputDeviceInfo* info) { |
| 669 | info->addSource(getSources()); |
| 670 | } |
| 671 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 672 | void InputMapper::dump(String8& dump) { |
| 673 | } |
| 674 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 675 | void InputMapper::configure() { |
| 676 | } |
| 677 | |
| 678 | void InputMapper::reset() { |
| 679 | } |
| 680 | |
| 681 | int32_t InputMapper::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) { |
| 682 | return AKEY_STATE_UNKNOWN; |
| 683 | } |
| 684 | |
| 685 | int32_t InputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) { |
| 686 | return AKEY_STATE_UNKNOWN; |
| 687 | } |
| 688 | |
| 689 | int32_t InputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) { |
| 690 | return AKEY_STATE_UNKNOWN; |
| 691 | } |
| 692 | |
| 693 | bool InputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 694 | const int32_t* keyCodes, uint8_t* outFlags) { |
| 695 | return false; |
| 696 | } |
| 697 | |
| 698 | int32_t InputMapper::getMetaState() { |
| 699 | return 0; |
| 700 | } |
| 701 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 702 | |
| 703 | // --- SwitchInputMapper --- |
| 704 | |
| 705 | SwitchInputMapper::SwitchInputMapper(InputDevice* device) : |
| 706 | InputMapper(device) { |
| 707 | } |
| 708 | |
| 709 | SwitchInputMapper::~SwitchInputMapper() { |
| 710 | } |
| 711 | |
| 712 | uint32_t SwitchInputMapper::getSources() { |
| 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | void SwitchInputMapper::process(const RawEvent* rawEvent) { |
| 717 | switch (rawEvent->type) { |
| 718 | case EV_SW: |
| 719 | processSwitch(rawEvent->when, rawEvent->scanCode, rawEvent->value); |
| 720 | break; |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | void SwitchInputMapper::processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 725 | getDispatcher()->notifySwitch(when, switchCode, switchValue, 0); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | int32_t SwitchInputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) { |
| 729 | return getEventHub()->getSwitchState(getDeviceId(), switchCode); |
| 730 | } |
| 731 | |
| 732 | |
| 733 | // --- KeyboardInputMapper --- |
| 734 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 735 | KeyboardInputMapper::KeyboardInputMapper(InputDevice* device, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 736 | uint32_t sources, int32_t keyboardType) : |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 737 | InputMapper(device), mSources(sources), |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 738 | mKeyboardType(keyboardType) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 739 | initializeLocked(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | KeyboardInputMapper::~KeyboardInputMapper() { |
| 743 | } |
| 744 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 745 | void KeyboardInputMapper::initializeLocked() { |
| 746 | mLocked.metaState = AMETA_NONE; |
| 747 | mLocked.downTime = 0; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | uint32_t KeyboardInputMapper::getSources() { |
| 751 | return mSources; |
| 752 | } |
| 753 | |
| 754 | void KeyboardInputMapper::populateDeviceInfo(InputDeviceInfo* info) { |
| 755 | InputMapper::populateDeviceInfo(info); |
| 756 | |
| 757 | info->setKeyboardType(mKeyboardType); |
| 758 | } |
| 759 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 760 | void KeyboardInputMapper::dump(String8& dump) { |
| 761 | { // acquire lock |
| 762 | AutoMutex _l(mLock); |
| 763 | dump.append(INDENT2 "Keyboard Input Mapper:\n"); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 764 | dumpParameters(dump); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 765 | dump.appendFormat(INDENT3 "KeyboardType: %d\n", mKeyboardType); |
| 766 | dump.appendFormat(INDENT3 "KeyDowns: %d keys currently down\n", mLocked.keyDowns.size()); |
| 767 | dump.appendFormat(INDENT3 "MetaState: 0x%0x\n", mLocked.metaState); |
| 768 | dump.appendFormat(INDENT3 "DownTime: %lld\n", mLocked.downTime); |
| 769 | } // release lock |
| 770 | } |
| 771 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 772 | |
| 773 | void KeyboardInputMapper::configure() { |
| 774 | InputMapper::configure(); |
| 775 | |
| 776 | // Configure basic parameters. |
| 777 | configureParameters(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 778 | |
| 779 | // Reset LEDs. |
| 780 | { |
| 781 | AutoMutex _l(mLock); |
| 782 | resetLedStateLocked(); |
| 783 | } |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | void KeyboardInputMapper::configureParameters() { |
| 787 | mParameters.orientationAware = false; |
| 788 | getDevice()->getConfiguration().tryGetProperty(String8("keyboard.orientationAware"), |
| 789 | mParameters.orientationAware); |
| 790 | |
| 791 | mParameters.associatedDisplayId = mParameters.orientationAware ? 0 : -1; |
| 792 | } |
| 793 | |
| 794 | void KeyboardInputMapper::dumpParameters(String8& dump) { |
| 795 | dump.append(INDENT3 "Parameters:\n"); |
| 796 | dump.appendFormat(INDENT4 "AssociatedDisplayId: %d\n", |
| 797 | mParameters.associatedDisplayId); |
| 798 | dump.appendFormat(INDENT4 "OrientationAware: %s\n", |
| 799 | toString(mParameters.orientationAware)); |
| 800 | } |
| 801 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 802 | void KeyboardInputMapper::reset() { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 803 | for (;;) { |
| 804 | int32_t keyCode, scanCode; |
| 805 | { // acquire lock |
| 806 | AutoMutex _l(mLock); |
| 807 | |
| 808 | // Synthesize key up event on reset if keys are currently down. |
| 809 | if (mLocked.keyDowns.isEmpty()) { |
| 810 | initializeLocked(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 811 | resetLedStateLocked(); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 812 | break; // done |
| 813 | } |
| 814 | |
| 815 | const KeyDown& keyDown = mLocked.keyDowns.top(); |
| 816 | keyCode = keyDown.keyCode; |
| 817 | scanCode = keyDown.scanCode; |
| 818 | } // release lock |
| 819 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 820 | nsecs_t when = systemTime(SYSTEM_TIME_MONOTONIC); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 821 | processKey(when, false, keyCode, scanCode, 0); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | InputMapper::reset(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 825 | getContext()->updateGlobalMetaState(); |
| 826 | } |
| 827 | |
| 828 | void KeyboardInputMapper::process(const RawEvent* rawEvent) { |
| 829 | switch (rawEvent->type) { |
| 830 | case EV_KEY: { |
| 831 | int32_t scanCode = rawEvent->scanCode; |
| 832 | if (isKeyboardOrGamepadKey(scanCode)) { |
| 833 | processKey(rawEvent->when, rawEvent->value != 0, rawEvent->keyCode, scanCode, |
| 834 | rawEvent->flags); |
| 835 | } |
| 836 | break; |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | bool KeyboardInputMapper::isKeyboardOrGamepadKey(int32_t scanCode) { |
| 842 | return scanCode < BTN_MOUSE |
| 843 | || scanCode >= KEY_OK |
| 844 | || (scanCode >= BTN_GAMEPAD && scanCode < BTN_DIGI); |
| 845 | } |
| 846 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 847 | void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode, |
| 848 | int32_t scanCode, uint32_t policyFlags) { |
| 849 | int32_t newMetaState; |
| 850 | nsecs_t downTime; |
| 851 | bool metaStateChanged = false; |
| 852 | |
| 853 | { // acquire lock |
| 854 | AutoMutex _l(mLock); |
| 855 | |
| 856 | if (down) { |
| 857 | // Rotate key codes according to orientation if needed. |
| 858 | // Note: getDisplayInfo is non-reentrant so we can continue holding the lock. |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 859 | if (mParameters.orientationAware && mParameters.associatedDisplayId >= 0) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 860 | int32_t orientation; |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 861 | if (!getPolicy()->getDisplayInfo(mParameters.associatedDisplayId, |
| 862 | NULL, NULL, & orientation)) { |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 863 | orientation = InputReaderPolicyInterface::ROTATION_0; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | keyCode = rotateKeyCode(keyCode, orientation); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 869 | // Add key down. |
| 870 | ssize_t keyDownIndex = findKeyDownLocked(scanCode); |
| 871 | if (keyDownIndex >= 0) { |
| 872 | // key repeat, be sure to use same keycode as before in case of rotation |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 873 | keyCode = mLocked.keyDowns.itemAt(keyDownIndex).keyCode; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 874 | } else { |
| 875 | // key down |
| 876 | mLocked.keyDowns.push(); |
| 877 | KeyDown& keyDown = mLocked.keyDowns.editTop(); |
| 878 | keyDown.keyCode = keyCode; |
| 879 | keyDown.scanCode = scanCode; |
| 880 | } |
| 881 | |
| 882 | mLocked.downTime = when; |
| 883 | } else { |
| 884 | // Remove key down. |
| 885 | ssize_t keyDownIndex = findKeyDownLocked(scanCode); |
| 886 | if (keyDownIndex >= 0) { |
| 887 | // key up, be sure to use same keycode as before in case of rotation |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 888 | keyCode = mLocked.keyDowns.itemAt(keyDownIndex).keyCode; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 889 | mLocked.keyDowns.removeAt(size_t(keyDownIndex)); |
| 890 | } else { |
| 891 | // key was not actually down |
| 892 | LOGI("Dropping key up from device %s because the key was not down. " |
| 893 | "keyCode=%d, scanCode=%d", |
| 894 | getDeviceName().string(), keyCode, scanCode); |
| 895 | return; |
| 896 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 899 | int32_t oldMetaState = mLocked.metaState; |
| 900 | newMetaState = updateMetaState(keyCode, down, oldMetaState); |
| 901 | if (oldMetaState != newMetaState) { |
| 902 | mLocked.metaState = newMetaState; |
| 903 | metaStateChanged = true; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 904 | updateLedStateLocked(false); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 905 | } |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 906 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 907 | downTime = mLocked.downTime; |
| 908 | } // release lock |
| 909 | |
| 910 | if (metaStateChanged) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 911 | getContext()->updateGlobalMetaState(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 914 | if (policyFlags & POLICY_FLAG_FUNCTION) { |
| 915 | newMetaState |= AMETA_FUNCTION_ON; |
| 916 | } |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 917 | getDispatcher()->notifyKey(when, getDeviceId(), mSources, policyFlags, |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 918 | down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP, |
| 919 | AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, newMetaState, downTime); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 922 | ssize_t KeyboardInputMapper::findKeyDownLocked(int32_t scanCode) { |
| 923 | size_t n = mLocked.keyDowns.size(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 924 | for (size_t i = 0; i < n; i++) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 925 | if (mLocked.keyDowns[i].scanCode == scanCode) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 926 | return i; |
| 927 | } |
| 928 | } |
| 929 | return -1; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 930 | } |
| 931 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 932 | int32_t KeyboardInputMapper::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) { |
| 933 | return getEventHub()->getKeyCodeState(getDeviceId(), keyCode); |
| 934 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 935 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 936 | int32_t KeyboardInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) { |
| 937 | return getEventHub()->getScanCodeState(getDeviceId(), scanCode); |
| 938 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 939 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 940 | bool KeyboardInputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 941 | const int32_t* keyCodes, uint8_t* outFlags) { |
| 942 | return getEventHub()->markSupportedKeyCodes(getDeviceId(), numCodes, keyCodes, outFlags); |
| 943 | } |
| 944 | |
| 945 | int32_t KeyboardInputMapper::getMetaState() { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 946 | { // acquire lock |
| 947 | AutoMutex _l(mLock); |
| 948 | return mLocked.metaState; |
| 949 | } // release lock |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 952 | void KeyboardInputMapper::resetLedStateLocked() { |
| 953 | initializeLedStateLocked(mLocked.capsLockLedState, LED_CAPSL); |
| 954 | initializeLedStateLocked(mLocked.numLockLedState, LED_NUML); |
| 955 | initializeLedStateLocked(mLocked.scrollLockLedState, LED_SCROLLL); |
| 956 | |
| 957 | updateLedStateLocked(true); |
| 958 | } |
| 959 | |
| 960 | void KeyboardInputMapper::initializeLedStateLocked(LockedState::LedState& ledState, int32_t led) { |
| 961 | ledState.avail = getEventHub()->hasLed(getDeviceId(), led); |
| 962 | ledState.on = false; |
| 963 | } |
| 964 | |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 965 | void KeyboardInputMapper::updateLedStateLocked(bool reset) { |
| 966 | updateLedStateForModifierLocked(mLocked.capsLockLedState, LED_CAPSL, |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 967 | AMETA_CAPS_LOCK_ON, reset); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 968 | updateLedStateForModifierLocked(mLocked.numLockLedState, LED_NUML, |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 969 | AMETA_NUM_LOCK_ON, reset); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 970 | updateLedStateForModifierLocked(mLocked.scrollLockLedState, LED_SCROLLL, |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 971 | AMETA_SCROLL_LOCK_ON, reset); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | void KeyboardInputMapper::updateLedStateForModifierLocked(LockedState::LedState& ledState, |
| 975 | int32_t led, int32_t modifier, bool reset) { |
| 976 | if (ledState.avail) { |
| 977 | bool desiredState = (mLocked.metaState & modifier) != 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 978 | if (reset || ledState.on != desiredState) { |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 979 | getEventHub()->setLedState(getDeviceId(), led, desiredState); |
| 980 | ledState.on = desiredState; |
| 981 | } |
| 982 | } |
| 983 | } |
| 984 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 985 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 986 | // --- CursorInputMapper --- |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 987 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 988 | CursorInputMapper::CursorInputMapper(InputDevice* device) : |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 989 | InputMapper(device) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 990 | initializeLocked(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 993 | CursorInputMapper::~CursorInputMapper() { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 994 | } |
| 995 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 996 | uint32_t CursorInputMapper::getSources() { |
| 997 | return mSources; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 998 | } |
| 999 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1000 | void CursorInputMapper::populateDeviceInfo(InputDeviceInfo* info) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1001 | InputMapper::populateDeviceInfo(info); |
| 1002 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1003 | if (mParameters.mode == Parameters::MODE_POINTER) { |
| 1004 | float minX, minY, maxX, maxY; |
| 1005 | if (mPointerController->getBounds(&minX, &minY, &maxX, &maxY)) { |
| 1006 | info->addMotionRange(AINPUT_MOTION_RANGE_X, minX, maxX, 0.0f, 0.0f); |
| 1007 | info->addMotionRange(AINPUT_MOTION_RANGE_Y, minY, maxY, 0.0f, 0.0f); |
| 1008 | } |
| 1009 | } else { |
| 1010 | info->addMotionRange(AINPUT_MOTION_RANGE_X, -1.0f, 1.0f, 0.0f, mXScale); |
| 1011 | info->addMotionRange(AINPUT_MOTION_RANGE_Y, -1.0f, 1.0f, 0.0f, mYScale); |
| 1012 | } |
| 1013 | info->addMotionRange(AINPUT_MOTION_RANGE_PRESSURE, 0.0f, 1.0f, 0.0f, 0.0f); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1016 | void CursorInputMapper::dump(String8& dump) { |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1017 | { // acquire lock |
| 1018 | AutoMutex _l(mLock); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1019 | dump.append(INDENT2 "Cursor Input Mapper:\n"); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1020 | dumpParameters(dump); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1021 | dump.appendFormat(INDENT3 "XPrecision: %0.3f\n", mXPrecision); |
| 1022 | dump.appendFormat(INDENT3 "YPrecision: %0.3f\n", mYPrecision); |
| 1023 | dump.appendFormat(INDENT3 "Down: %s\n", toString(mLocked.down)); |
| 1024 | dump.appendFormat(INDENT3 "DownTime: %lld\n", mLocked.downTime); |
| 1025 | } // release lock |
| 1026 | } |
| 1027 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1028 | void CursorInputMapper::configure() { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1029 | InputMapper::configure(); |
| 1030 | |
| 1031 | // Configure basic parameters. |
| 1032 | configureParameters(); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1033 | |
| 1034 | // Configure device mode. |
| 1035 | switch (mParameters.mode) { |
| 1036 | case Parameters::MODE_POINTER: |
| 1037 | mSources = AINPUT_SOURCE_MOUSE; |
| 1038 | mXPrecision = 1.0f; |
| 1039 | mYPrecision = 1.0f; |
| 1040 | mXScale = 1.0f; |
| 1041 | mYScale = 1.0f; |
| 1042 | mPointerController = getPolicy()->obtainPointerController(getDeviceId()); |
| 1043 | break; |
| 1044 | case Parameters::MODE_NAVIGATION: |
| 1045 | mSources = AINPUT_SOURCE_TRACKBALL; |
| 1046 | mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD; |
| 1047 | mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD; |
| 1048 | mXScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD; |
| 1049 | mYScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD; |
| 1050 | break; |
| 1051 | } |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1052 | } |
| 1053 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1054 | void CursorInputMapper::configureParameters() { |
| 1055 | mParameters.mode = Parameters::MODE_POINTER; |
| 1056 | String8 cursorModeString; |
| 1057 | if (getDevice()->getConfiguration().tryGetProperty(String8("cursor.mode"), cursorModeString)) { |
| 1058 | if (cursorModeString == "navigation") { |
| 1059 | mParameters.mode = Parameters::MODE_NAVIGATION; |
| 1060 | } else if (cursorModeString != "pointer" && cursorModeString != "default") { |
| 1061 | LOGW("Invalid value for cursor.mode: '%s'", cursorModeString.string()); |
| 1062 | } |
| 1063 | } |
| 1064 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1065 | mParameters.orientationAware = false; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1066 | getDevice()->getConfiguration().tryGetProperty(String8("cursor.orientationAware"), |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1067 | mParameters.orientationAware); |
| 1068 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1069 | mParameters.associatedDisplayId = mParameters.mode == Parameters::MODE_POINTER |
| 1070 | || mParameters.orientationAware ? 0 : -1; |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1071 | } |
| 1072 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1073 | void CursorInputMapper::dumpParameters(String8& dump) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1074 | dump.append(INDENT3 "Parameters:\n"); |
| 1075 | dump.appendFormat(INDENT4 "AssociatedDisplayId: %d\n", |
| 1076 | mParameters.associatedDisplayId); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1077 | |
| 1078 | switch (mParameters.mode) { |
| 1079 | case Parameters::MODE_POINTER: |
| 1080 | dump.append(INDENT4 "Mode: pointer\n"); |
| 1081 | break; |
| 1082 | case Parameters::MODE_NAVIGATION: |
| 1083 | dump.append(INDENT4 "Mode: navigation\n"); |
| 1084 | break; |
| 1085 | default: |
| 1086 | assert(false); |
| 1087 | } |
| 1088 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1089 | dump.appendFormat(INDENT4 "OrientationAware: %s\n", |
| 1090 | toString(mParameters.orientationAware)); |
| 1091 | } |
| 1092 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1093 | void CursorInputMapper::initializeLocked() { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1094 | mAccumulator.clear(); |
| 1095 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1096 | mLocked.down = false; |
| 1097 | mLocked.downTime = 0; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1100 | void CursorInputMapper::reset() { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1101 | for (;;) { |
| 1102 | { // acquire lock |
| 1103 | AutoMutex _l(mLock); |
| 1104 | |
| 1105 | if (! mLocked.down) { |
| 1106 | initializeLocked(); |
| 1107 | break; // done |
| 1108 | } |
| 1109 | } // release lock |
| 1110 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1111 | // Synthesize button up event on reset. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1112 | nsecs_t when = systemTime(SYSTEM_TIME_MONOTONIC); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1113 | mAccumulator.fields = Accumulator::FIELD_BTN_MOUSE; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1114 | mAccumulator.btnMouse = false; |
| 1115 | sync(when); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1118 | InputMapper::reset(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1119 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1120 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1121 | void CursorInputMapper::process(const RawEvent* rawEvent) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1122 | switch (rawEvent->type) { |
| 1123 | case EV_KEY: |
| 1124 | switch (rawEvent->scanCode) { |
| 1125 | case BTN_MOUSE: |
| 1126 | mAccumulator.fields |= Accumulator::FIELD_BTN_MOUSE; |
| 1127 | mAccumulator.btnMouse = rawEvent->value != 0; |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 1128 | // Sync now since BTN_MOUSE is not necessarily followed by SYN_REPORT and |
| 1129 | // we need to ensure that we report the up/down promptly. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1130 | sync(rawEvent->when); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1131 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1132 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1133 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1134 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1135 | case EV_REL: |
| 1136 | switch (rawEvent->scanCode) { |
| 1137 | case REL_X: |
| 1138 | mAccumulator.fields |= Accumulator::FIELD_REL_X; |
| 1139 | mAccumulator.relX = rawEvent->value; |
| 1140 | break; |
| 1141 | case REL_Y: |
| 1142 | mAccumulator.fields |= Accumulator::FIELD_REL_Y; |
| 1143 | mAccumulator.relY = rawEvent->value; |
| 1144 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1145 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1146 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1147 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1148 | case EV_SYN: |
| 1149 | switch (rawEvent->scanCode) { |
| 1150 | case SYN_REPORT: |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 1151 | sync(rawEvent->when); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1152 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1153 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1154 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1155 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1158 | void CursorInputMapper::sync(nsecs_t when) { |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 1159 | uint32_t fields = mAccumulator.fields; |
| 1160 | if (fields == 0) { |
| 1161 | return; // no new state changes, so nothing to do |
| 1162 | } |
| 1163 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1164 | int motionEventAction; |
| 1165 | PointerCoords pointerCoords; |
| 1166 | nsecs_t downTime; |
| 1167 | { // acquire lock |
| 1168 | AutoMutex _l(mLock); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1169 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1170 | bool downChanged = fields & Accumulator::FIELD_BTN_MOUSE; |
| 1171 | |
| 1172 | if (downChanged) { |
| 1173 | if (mAccumulator.btnMouse) { |
| 1174 | mLocked.down = true; |
| 1175 | mLocked.downTime = when; |
| 1176 | } else { |
| 1177 | mLocked.down = false; |
| 1178 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1179 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1180 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1181 | downTime = mLocked.downTime; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1182 | float deltaX = fields & Accumulator::FIELD_REL_X ? mAccumulator.relX * mXScale : 0.0f; |
| 1183 | float deltaY = fields & Accumulator::FIELD_REL_Y ? mAccumulator.relY * mYScale : 0.0f; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1184 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1185 | if (downChanged) { |
| 1186 | motionEventAction = mLocked.down ? AMOTION_EVENT_ACTION_DOWN : AMOTION_EVENT_ACTION_UP; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1187 | } else { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1188 | motionEventAction = AMOTION_EVENT_ACTION_MOVE; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1189 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1190 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1191 | if (mParameters.orientationAware && mParameters.associatedDisplayId >= 0 |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1192 | && (deltaX != 0.0f || deltaY != 0.0f)) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1193 | // Rotate motion based on display orientation if needed. |
| 1194 | // Note: getDisplayInfo is non-reentrant so we can continue holding the lock. |
| 1195 | int32_t orientation; |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1196 | if (! getPolicy()->getDisplayInfo(mParameters.associatedDisplayId, |
| 1197 | NULL, NULL, & orientation)) { |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1198 | orientation = InputReaderPolicyInterface::ROTATION_0; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | float temp; |
| 1202 | switch (orientation) { |
| 1203 | case InputReaderPolicyInterface::ROTATION_90: |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1204 | temp = deltaX; |
| 1205 | deltaX = deltaY; |
| 1206 | deltaY = -temp; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1207 | break; |
| 1208 | |
| 1209 | case InputReaderPolicyInterface::ROTATION_180: |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1210 | deltaX = -deltaX; |
| 1211 | deltaY = -deltaY; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1212 | break; |
| 1213 | |
| 1214 | case InputReaderPolicyInterface::ROTATION_270: |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1215 | temp = deltaX; |
| 1216 | deltaX = -deltaY; |
| 1217 | deltaY = temp; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1218 | break; |
| 1219 | } |
| 1220 | } |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1221 | |
| 1222 | if (mPointerController != NULL) { |
| 1223 | mPointerController->move(deltaX, deltaY); |
| 1224 | if (downChanged) { |
| 1225 | mPointerController->setButtonState(mLocked.down ? POINTER_BUTTON_1 : 0); |
| 1226 | } |
| 1227 | mPointerController->getPosition(&pointerCoords.x, &pointerCoords.y); |
| 1228 | } else { |
| 1229 | pointerCoords.x = deltaX; |
| 1230 | pointerCoords.y = deltaY; |
| 1231 | } |
| 1232 | |
| 1233 | pointerCoords.pressure = mLocked.down ? 1.0f : 0.0f; |
| 1234 | pointerCoords.size = 0; |
| 1235 | pointerCoords.touchMajor = 0; |
| 1236 | pointerCoords.touchMinor = 0; |
| 1237 | pointerCoords.toolMajor = 0; |
| 1238 | pointerCoords.toolMinor = 0; |
| 1239 | pointerCoords.orientation = 0; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1240 | } // release lock |
| 1241 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1242 | int32_t metaState = mContext->getGlobalMetaState(); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1243 | int32_t pointerId = 0; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1244 | getDispatcher()->notifyMotion(when, getDeviceId(), mSources, 0, |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1245 | motionEventAction, 0, metaState, AMOTION_EVENT_EDGE_FLAG_NONE, |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1246 | 1, &pointerId, &pointerCoords, mXPrecision, mYPrecision, downTime); |
| 1247 | |
| 1248 | mAccumulator.clear(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1251 | int32_t CursorInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) { |
Jeff Brown | c3fc2d0 | 2010-08-10 15:47:53 -0700 | [diff] [blame] | 1252 | if (scanCode >= BTN_MOUSE && scanCode < BTN_JOYSTICK) { |
| 1253 | return getEventHub()->getScanCodeState(getDeviceId(), scanCode); |
| 1254 | } else { |
| 1255 | return AKEY_STATE_UNKNOWN; |
| 1256 | } |
| 1257 | } |
| 1258 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1259 | |
| 1260 | // --- TouchInputMapper --- |
| 1261 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1262 | TouchInputMapper::TouchInputMapper(InputDevice* device) : |
| 1263 | InputMapper(device) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1264 | mLocked.surfaceOrientation = -1; |
| 1265 | mLocked.surfaceWidth = -1; |
| 1266 | mLocked.surfaceHeight = -1; |
| 1267 | |
| 1268 | initializeLocked(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | TouchInputMapper::~TouchInputMapper() { |
| 1272 | } |
| 1273 | |
| 1274 | uint32_t TouchInputMapper::getSources() { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1275 | return mSources; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | void TouchInputMapper::populateDeviceInfo(InputDeviceInfo* info) { |
| 1279 | InputMapper::populateDeviceInfo(info); |
| 1280 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1281 | { // acquire lock |
| 1282 | AutoMutex _l(mLock); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1283 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1284 | // Ensure surface information is up to date so that orientation changes are |
| 1285 | // noticed immediately. |
| 1286 | configureSurfaceLocked(); |
| 1287 | |
| 1288 | info->addMotionRange(AINPUT_MOTION_RANGE_X, mLocked.orientedRanges.x); |
| 1289 | info->addMotionRange(AINPUT_MOTION_RANGE_Y, mLocked.orientedRanges.y); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1290 | |
| 1291 | if (mLocked.orientedRanges.havePressure) { |
| 1292 | info->addMotionRange(AINPUT_MOTION_RANGE_PRESSURE, |
| 1293 | mLocked.orientedRanges.pressure); |
| 1294 | } |
| 1295 | |
| 1296 | if (mLocked.orientedRanges.haveSize) { |
| 1297 | info->addMotionRange(AINPUT_MOTION_RANGE_SIZE, |
| 1298 | mLocked.orientedRanges.size); |
| 1299 | } |
| 1300 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1301 | if (mLocked.orientedRanges.haveTouchSize) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1302 | info->addMotionRange(AINPUT_MOTION_RANGE_TOUCH_MAJOR, |
| 1303 | mLocked.orientedRanges.touchMajor); |
| 1304 | info->addMotionRange(AINPUT_MOTION_RANGE_TOUCH_MINOR, |
| 1305 | mLocked.orientedRanges.touchMinor); |
| 1306 | } |
| 1307 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1308 | if (mLocked.orientedRanges.haveToolSize) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1309 | info->addMotionRange(AINPUT_MOTION_RANGE_TOOL_MAJOR, |
| 1310 | mLocked.orientedRanges.toolMajor); |
| 1311 | info->addMotionRange(AINPUT_MOTION_RANGE_TOOL_MINOR, |
| 1312 | mLocked.orientedRanges.toolMinor); |
| 1313 | } |
| 1314 | |
| 1315 | if (mLocked.orientedRanges.haveOrientation) { |
| 1316 | info->addMotionRange(AINPUT_MOTION_RANGE_ORIENTATION, |
| 1317 | mLocked.orientedRanges.orientation); |
| 1318 | } |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1319 | } // release lock |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1322 | void TouchInputMapper::dump(String8& dump) { |
| 1323 | { // acquire lock |
| 1324 | AutoMutex _l(mLock); |
| 1325 | dump.append(INDENT2 "Touch Input Mapper:\n"); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1326 | dumpParameters(dump); |
| 1327 | dumpVirtualKeysLocked(dump); |
| 1328 | dumpRawAxes(dump); |
| 1329 | dumpCalibration(dump); |
| 1330 | dumpSurfaceLocked(dump); |
Jeff Brown | 511ee5f | 2010-10-18 13:32:20 -0700 | [diff] [blame] | 1331 | dump.appendFormat(INDENT3 "Translation and Scaling Factors:\n"); |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1332 | dump.appendFormat(INDENT4 "XOrigin: %d\n", mLocked.xOrigin); |
| 1333 | dump.appendFormat(INDENT4 "YOrigin: %d\n", mLocked.yOrigin); |
| 1334 | dump.appendFormat(INDENT4 "XScale: %0.3f\n", mLocked.xScale); |
| 1335 | dump.appendFormat(INDENT4 "YScale: %0.3f\n", mLocked.yScale); |
| 1336 | dump.appendFormat(INDENT4 "XPrecision: %0.3f\n", mLocked.xPrecision); |
| 1337 | dump.appendFormat(INDENT4 "YPrecision: %0.3f\n", mLocked.yPrecision); |
| 1338 | dump.appendFormat(INDENT4 "GeometricScale: %0.3f\n", mLocked.geometricScale); |
| 1339 | dump.appendFormat(INDENT4 "ToolSizeLinearScale: %0.3f\n", mLocked.toolSizeLinearScale); |
| 1340 | dump.appendFormat(INDENT4 "ToolSizeLinearBias: %0.3f\n", mLocked.toolSizeLinearBias); |
| 1341 | dump.appendFormat(INDENT4 "ToolSizeAreaScale: %0.3f\n", mLocked.toolSizeAreaScale); |
| 1342 | dump.appendFormat(INDENT4 "ToolSizeAreaBias: %0.3f\n", mLocked.toolSizeAreaBias); |
| 1343 | dump.appendFormat(INDENT4 "PressureScale: %0.3f\n", mLocked.pressureScale); |
| 1344 | dump.appendFormat(INDENT4 "SizeScale: %0.3f\n", mLocked.sizeScale); |
| 1345 | dump.appendFormat(INDENT4 "OrientationSCale: %0.3f\n", mLocked.orientationScale); |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1346 | } // release lock |
| 1347 | } |
| 1348 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1349 | void TouchInputMapper::initializeLocked() { |
| 1350 | mCurrentTouch.clear(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1351 | mLastTouch.clear(); |
| 1352 | mDownTime = 0; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1353 | |
| 1354 | for (uint32_t i = 0; i < MAX_POINTERS; i++) { |
| 1355 | mAveragingTouchFilter.historyStart[i] = 0; |
| 1356 | mAveragingTouchFilter.historyEnd[i] = 0; |
| 1357 | } |
| 1358 | |
| 1359 | mJumpyTouchFilter.jumpyPointsDropped = 0; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1360 | |
| 1361 | mLocked.currentVirtualKey.down = false; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1362 | |
| 1363 | mLocked.orientedRanges.havePressure = false; |
| 1364 | mLocked.orientedRanges.haveSize = false; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1365 | mLocked.orientedRanges.haveTouchSize = false; |
| 1366 | mLocked.orientedRanges.haveToolSize = false; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1367 | mLocked.orientedRanges.haveOrientation = false; |
| 1368 | } |
| 1369 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1370 | void TouchInputMapper::configure() { |
| 1371 | InputMapper::configure(); |
| 1372 | |
| 1373 | // Configure basic parameters. |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1374 | configureParameters(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1375 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1376 | // Configure sources. |
| 1377 | switch (mParameters.deviceType) { |
| 1378 | case Parameters::DEVICE_TYPE_TOUCH_SCREEN: |
| 1379 | mSources = AINPUT_SOURCE_TOUCHSCREEN; |
| 1380 | break; |
| 1381 | case Parameters::DEVICE_TYPE_TOUCH_PAD: |
| 1382 | mSources = AINPUT_SOURCE_TOUCHPAD; |
| 1383 | break; |
| 1384 | default: |
| 1385 | assert(false); |
| 1386 | } |
| 1387 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1388 | // Configure absolute axis information. |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1389 | configureRawAxes(); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1390 | |
| 1391 | // Prepare input device calibration. |
| 1392 | parseCalibration(); |
| 1393 | resolveCalibration(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1394 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1395 | { // acquire lock |
| 1396 | AutoMutex _l(mLock); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1397 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1398 | // Configure surface dimensions and orientation. |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1399 | configureSurfaceLocked(); |
| 1400 | } // release lock |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1403 | void TouchInputMapper::configureParameters() { |
| 1404 | mParameters.useBadTouchFilter = getPolicy()->filterTouchEvents(); |
| 1405 | mParameters.useAveragingTouchFilter = getPolicy()->filterTouchEvents(); |
| 1406 | mParameters.useJumpyTouchFilter = getPolicy()->filterJumpyTouchEvents(); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1407 | |
| 1408 | String8 deviceTypeString; |
| 1409 | mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_SCREEN; |
| 1410 | if (getDevice()->getConfiguration().tryGetProperty(String8("touch.deviceType"), |
| 1411 | deviceTypeString)) { |
| 1412 | if (deviceTypeString == "touchPad") { |
| 1413 | mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_PAD; |
| 1414 | } else if (deviceTypeString != "touchScreen") { |
| 1415 | LOGW("Invalid value for touch.deviceType: '%s'", deviceTypeString.string()); |
| 1416 | } |
| 1417 | } |
| 1418 | bool isTouchScreen = mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN; |
| 1419 | |
| 1420 | mParameters.orientationAware = isTouchScreen; |
| 1421 | getDevice()->getConfiguration().tryGetProperty(String8("touch.orientationAware"), |
| 1422 | mParameters.orientationAware); |
| 1423 | |
| 1424 | mParameters.associatedDisplayId = mParameters.orientationAware || isTouchScreen ? 0 : -1; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1427 | void TouchInputMapper::dumpParameters(String8& dump) { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1428 | dump.append(INDENT3 "Parameters:\n"); |
| 1429 | |
| 1430 | switch (mParameters.deviceType) { |
| 1431 | case Parameters::DEVICE_TYPE_TOUCH_SCREEN: |
| 1432 | dump.append(INDENT4 "DeviceType: touchScreen\n"); |
| 1433 | break; |
| 1434 | case Parameters::DEVICE_TYPE_TOUCH_PAD: |
| 1435 | dump.append(INDENT4 "DeviceType: touchPad\n"); |
| 1436 | break; |
| 1437 | default: |
| 1438 | assert(false); |
| 1439 | } |
| 1440 | |
| 1441 | dump.appendFormat(INDENT4 "AssociatedDisplayId: %d\n", |
| 1442 | mParameters.associatedDisplayId); |
| 1443 | dump.appendFormat(INDENT4 "OrientationAware: %s\n", |
| 1444 | toString(mParameters.orientationAware)); |
| 1445 | |
| 1446 | dump.appendFormat(INDENT4 "UseBadTouchFilter: %s\n", |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1447 | toString(mParameters.useBadTouchFilter)); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1448 | dump.appendFormat(INDENT4 "UseAveragingTouchFilter: %s\n", |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1449 | toString(mParameters.useAveragingTouchFilter)); |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1450 | dump.appendFormat(INDENT4 "UseJumpyTouchFilter: %s\n", |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1451 | toString(mParameters.useJumpyTouchFilter)); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1454 | void TouchInputMapper::configureRawAxes() { |
| 1455 | mRawAxes.x.clear(); |
| 1456 | mRawAxes.y.clear(); |
| 1457 | mRawAxes.pressure.clear(); |
| 1458 | mRawAxes.touchMajor.clear(); |
| 1459 | mRawAxes.touchMinor.clear(); |
| 1460 | mRawAxes.toolMajor.clear(); |
| 1461 | mRawAxes.toolMinor.clear(); |
| 1462 | mRawAxes.orientation.clear(); |
| 1463 | } |
| 1464 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1465 | static void dumpAxisInfo(String8& dump, RawAbsoluteAxisInfo axis, const char* name) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1466 | if (axis.valid) { |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1467 | dump.appendFormat(INDENT4 "%s: min=%d, max=%d, flat=%d, fuzz=%d\n", |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1468 | name, axis.minValue, axis.maxValue, axis.flat, axis.fuzz); |
| 1469 | } else { |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1470 | dump.appendFormat(INDENT4 "%s: unknown range\n", name); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1474 | void TouchInputMapper::dumpRawAxes(String8& dump) { |
| 1475 | dump.append(INDENT3 "Raw Axes:\n"); |
| 1476 | dumpAxisInfo(dump, mRawAxes.x, "X"); |
| 1477 | dumpAxisInfo(dump, mRawAxes.y, "Y"); |
| 1478 | dumpAxisInfo(dump, mRawAxes.pressure, "Pressure"); |
| 1479 | dumpAxisInfo(dump, mRawAxes.touchMajor, "TouchMajor"); |
| 1480 | dumpAxisInfo(dump, mRawAxes.touchMinor, "TouchMinor"); |
| 1481 | dumpAxisInfo(dump, mRawAxes.toolMajor, "ToolMajor"); |
| 1482 | dumpAxisInfo(dump, mRawAxes.toolMinor, "ToolMinor"); |
| 1483 | dumpAxisInfo(dump, mRawAxes.orientation, "Orientation"); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1486 | bool TouchInputMapper::configureSurfaceLocked() { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1487 | // Update orientation and dimensions if needed. |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1488 | int32_t orientation = InputReaderPolicyInterface::ROTATION_0; |
| 1489 | int32_t width = mRawAxes.x.getRange(); |
| 1490 | int32_t height = mRawAxes.y.getRange(); |
| 1491 | |
| 1492 | if (mParameters.associatedDisplayId >= 0) { |
| 1493 | bool wantSize = mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN; |
| 1494 | bool wantOrientation = mParameters.orientationAware; |
| 1495 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1496 | // Note: getDisplayInfo is non-reentrant so we can continue holding the lock. |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1497 | if (! getPolicy()->getDisplayInfo(mParameters.associatedDisplayId, |
| 1498 | wantSize ? &width : NULL, wantSize ? &height : NULL, |
| 1499 | wantOrientation ? &orientation : NULL)) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1500 | return false; |
| 1501 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1504 | bool orientationChanged = mLocked.surfaceOrientation != orientation; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1505 | if (orientationChanged) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1506 | mLocked.surfaceOrientation = orientation; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1509 | bool sizeChanged = mLocked.surfaceWidth != width || mLocked.surfaceHeight != height; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1510 | if (sizeChanged) { |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 1511 | LOGI("Device reconfigured: id=%d, name='%s', display size is now %dx%d", |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1512 | getDeviceId(), getDeviceName().string(), width, height); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1513 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1514 | mLocked.surfaceWidth = width; |
| 1515 | mLocked.surfaceHeight = height; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1516 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1517 | // Configure X and Y factors. |
| 1518 | if (mRawAxes.x.valid && mRawAxes.y.valid) { |
Jeff Brown | 511ee5f | 2010-10-18 13:32:20 -0700 | [diff] [blame] | 1519 | mLocked.xOrigin = mCalibration.haveXOrigin |
| 1520 | ? mCalibration.xOrigin |
| 1521 | : mRawAxes.x.minValue; |
| 1522 | mLocked.yOrigin = mCalibration.haveYOrigin |
| 1523 | ? mCalibration.yOrigin |
| 1524 | : mRawAxes.y.minValue; |
| 1525 | mLocked.xScale = mCalibration.haveXScale |
| 1526 | ? mCalibration.xScale |
| 1527 | : float(width) / mRawAxes.x.getRange(); |
| 1528 | mLocked.yScale = mCalibration.haveYScale |
| 1529 | ? mCalibration.yScale |
| 1530 | : float(height) / mRawAxes.y.getRange(); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1531 | mLocked.xPrecision = 1.0f / mLocked.xScale; |
| 1532 | mLocked.yPrecision = 1.0f / mLocked.yScale; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1533 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1534 | configureVirtualKeysLocked(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1535 | } else { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1536 | LOGW(INDENT "Touch device did not report support for X or Y axis!"); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1537 | mLocked.xOrigin = 0; |
| 1538 | mLocked.yOrigin = 0; |
| 1539 | mLocked.xScale = 1.0f; |
| 1540 | mLocked.yScale = 1.0f; |
| 1541 | mLocked.xPrecision = 1.0f; |
| 1542 | mLocked.yPrecision = 1.0f; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1543 | } |
| 1544 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1545 | // Scale factor for terms that are not oriented in a particular axis. |
| 1546 | // If the pixels are square then xScale == yScale otherwise we fake it |
| 1547 | // by choosing an average. |
| 1548 | mLocked.geometricScale = avg(mLocked.xScale, mLocked.yScale); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1549 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1550 | // Size of diagonal axis. |
| 1551 | float diagonalSize = pythag(width, height); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1552 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1553 | // TouchMajor and TouchMinor factors. |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1554 | if (mCalibration.touchSizeCalibration != Calibration::TOUCH_SIZE_CALIBRATION_NONE) { |
| 1555 | mLocked.orientedRanges.haveTouchSize = true; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1556 | mLocked.orientedRanges.touchMajor.min = 0; |
| 1557 | mLocked.orientedRanges.touchMajor.max = diagonalSize; |
| 1558 | mLocked.orientedRanges.touchMajor.flat = 0; |
| 1559 | mLocked.orientedRanges.touchMajor.fuzz = 0; |
| 1560 | mLocked.orientedRanges.touchMinor = mLocked.orientedRanges.touchMajor; |
| 1561 | } |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1562 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1563 | // ToolMajor and ToolMinor factors. |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1564 | mLocked.toolSizeLinearScale = 0; |
| 1565 | mLocked.toolSizeLinearBias = 0; |
| 1566 | mLocked.toolSizeAreaScale = 0; |
| 1567 | mLocked.toolSizeAreaBias = 0; |
| 1568 | if (mCalibration.toolSizeCalibration != Calibration::TOOL_SIZE_CALIBRATION_NONE) { |
| 1569 | if (mCalibration.toolSizeCalibration == Calibration::TOOL_SIZE_CALIBRATION_LINEAR) { |
| 1570 | if (mCalibration.haveToolSizeLinearScale) { |
| 1571 | mLocked.toolSizeLinearScale = mCalibration.toolSizeLinearScale; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1572 | } else if (mRawAxes.toolMajor.valid && mRawAxes.toolMajor.maxValue != 0) { |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1573 | mLocked.toolSizeLinearScale = float(min(width, height)) |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1574 | / mRawAxes.toolMajor.maxValue; |
| 1575 | } |
| 1576 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1577 | if (mCalibration.haveToolSizeLinearBias) { |
| 1578 | mLocked.toolSizeLinearBias = mCalibration.toolSizeLinearBias; |
| 1579 | } |
| 1580 | } else if (mCalibration.toolSizeCalibration == |
| 1581 | Calibration::TOOL_SIZE_CALIBRATION_AREA) { |
| 1582 | if (mCalibration.haveToolSizeLinearScale) { |
| 1583 | mLocked.toolSizeLinearScale = mCalibration.toolSizeLinearScale; |
| 1584 | } else { |
| 1585 | mLocked.toolSizeLinearScale = min(width, height); |
| 1586 | } |
| 1587 | |
| 1588 | if (mCalibration.haveToolSizeLinearBias) { |
| 1589 | mLocked.toolSizeLinearBias = mCalibration.toolSizeLinearBias; |
| 1590 | } |
| 1591 | |
| 1592 | if (mCalibration.haveToolSizeAreaScale) { |
| 1593 | mLocked.toolSizeAreaScale = mCalibration.toolSizeAreaScale; |
| 1594 | } else if (mRawAxes.toolMajor.valid && mRawAxes.toolMajor.maxValue != 0) { |
| 1595 | mLocked.toolSizeAreaScale = 1.0f / mRawAxes.toolMajor.maxValue; |
| 1596 | } |
| 1597 | |
| 1598 | if (mCalibration.haveToolSizeAreaBias) { |
| 1599 | mLocked.toolSizeAreaBias = mCalibration.toolSizeAreaBias; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1600 | } |
| 1601 | } |
| 1602 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1603 | mLocked.orientedRanges.haveToolSize = true; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1604 | mLocked.orientedRanges.toolMajor.min = 0; |
| 1605 | mLocked.orientedRanges.toolMajor.max = diagonalSize; |
| 1606 | mLocked.orientedRanges.toolMajor.flat = 0; |
| 1607 | mLocked.orientedRanges.toolMajor.fuzz = 0; |
| 1608 | mLocked.orientedRanges.toolMinor = mLocked.orientedRanges.toolMajor; |
| 1609 | } |
| 1610 | |
| 1611 | // Pressure factors. |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1612 | mLocked.pressureScale = 0; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1613 | if (mCalibration.pressureCalibration != Calibration::PRESSURE_CALIBRATION_NONE) { |
| 1614 | RawAbsoluteAxisInfo rawPressureAxis; |
| 1615 | switch (mCalibration.pressureSource) { |
| 1616 | case Calibration::PRESSURE_SOURCE_PRESSURE: |
| 1617 | rawPressureAxis = mRawAxes.pressure; |
| 1618 | break; |
| 1619 | case Calibration::PRESSURE_SOURCE_TOUCH: |
| 1620 | rawPressureAxis = mRawAxes.touchMajor; |
| 1621 | break; |
| 1622 | default: |
| 1623 | rawPressureAxis.clear(); |
| 1624 | } |
| 1625 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1626 | if (mCalibration.pressureCalibration == Calibration::PRESSURE_CALIBRATION_PHYSICAL |
| 1627 | || mCalibration.pressureCalibration |
| 1628 | == Calibration::PRESSURE_CALIBRATION_AMPLITUDE) { |
| 1629 | if (mCalibration.havePressureScale) { |
| 1630 | mLocked.pressureScale = mCalibration.pressureScale; |
| 1631 | } else if (rawPressureAxis.valid && rawPressureAxis.maxValue != 0) { |
| 1632 | mLocked.pressureScale = 1.0f / rawPressureAxis.maxValue; |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | mLocked.orientedRanges.havePressure = true; |
| 1637 | mLocked.orientedRanges.pressure.min = 0; |
| 1638 | mLocked.orientedRanges.pressure.max = 1.0; |
| 1639 | mLocked.orientedRanges.pressure.flat = 0; |
| 1640 | mLocked.orientedRanges.pressure.fuzz = 0; |
| 1641 | } |
| 1642 | |
| 1643 | // Size factors. |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1644 | mLocked.sizeScale = 0; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1645 | if (mCalibration.sizeCalibration != Calibration::SIZE_CALIBRATION_NONE) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1646 | if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_NORMALIZED) { |
| 1647 | if (mRawAxes.toolMajor.valid && mRawAxes.toolMajor.maxValue != 0) { |
| 1648 | mLocked.sizeScale = 1.0f / mRawAxes.toolMajor.maxValue; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | mLocked.orientedRanges.haveSize = true; |
| 1653 | mLocked.orientedRanges.size.min = 0; |
| 1654 | mLocked.orientedRanges.size.max = 1.0; |
| 1655 | mLocked.orientedRanges.size.flat = 0; |
| 1656 | mLocked.orientedRanges.size.fuzz = 0; |
| 1657 | } |
| 1658 | |
| 1659 | // Orientation |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1660 | mLocked.orientationScale = 0; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1661 | if (mCalibration.orientationCalibration != Calibration::ORIENTATION_CALIBRATION_NONE) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1662 | if (mCalibration.orientationCalibration |
| 1663 | == Calibration::ORIENTATION_CALIBRATION_INTERPOLATED) { |
| 1664 | if (mRawAxes.orientation.valid && mRawAxes.orientation.maxValue != 0) { |
| 1665 | mLocked.orientationScale = float(M_PI_2) / mRawAxes.orientation.maxValue; |
| 1666 | } |
| 1667 | } |
| 1668 | |
| 1669 | mLocked.orientedRanges.orientation.min = - M_PI_2; |
| 1670 | mLocked.orientedRanges.orientation.max = M_PI_2; |
| 1671 | mLocked.orientedRanges.orientation.flat = 0; |
| 1672 | mLocked.orientedRanges.orientation.fuzz = 0; |
| 1673 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | if (orientationChanged || sizeChanged) { |
| 1677 | // Compute oriented surface dimensions, precision, and scales. |
| 1678 | float orientedXScale, orientedYScale; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1679 | switch (mLocked.surfaceOrientation) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1680 | case InputReaderPolicyInterface::ROTATION_90: |
| 1681 | case InputReaderPolicyInterface::ROTATION_270: |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1682 | mLocked.orientedSurfaceWidth = mLocked.surfaceHeight; |
| 1683 | mLocked.orientedSurfaceHeight = mLocked.surfaceWidth; |
| 1684 | mLocked.orientedXPrecision = mLocked.yPrecision; |
| 1685 | mLocked.orientedYPrecision = mLocked.xPrecision; |
| 1686 | orientedXScale = mLocked.yScale; |
| 1687 | orientedYScale = mLocked.xScale; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1688 | break; |
| 1689 | default: |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1690 | mLocked.orientedSurfaceWidth = mLocked.surfaceWidth; |
| 1691 | mLocked.orientedSurfaceHeight = mLocked.surfaceHeight; |
| 1692 | mLocked.orientedXPrecision = mLocked.xPrecision; |
| 1693 | mLocked.orientedYPrecision = mLocked.yPrecision; |
| 1694 | orientedXScale = mLocked.xScale; |
| 1695 | orientedYScale = mLocked.yScale; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1696 | break; |
| 1697 | } |
| 1698 | |
| 1699 | // Configure position ranges. |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1700 | mLocked.orientedRanges.x.min = 0; |
| 1701 | mLocked.orientedRanges.x.max = mLocked.orientedSurfaceWidth; |
| 1702 | mLocked.orientedRanges.x.flat = 0; |
| 1703 | mLocked.orientedRanges.x.fuzz = orientedXScale; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1704 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1705 | mLocked.orientedRanges.y.min = 0; |
| 1706 | mLocked.orientedRanges.y.max = mLocked.orientedSurfaceHeight; |
| 1707 | mLocked.orientedRanges.y.flat = 0; |
| 1708 | mLocked.orientedRanges.y.fuzz = orientedYScale; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | return true; |
| 1712 | } |
| 1713 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1714 | void TouchInputMapper::dumpSurfaceLocked(String8& dump) { |
| 1715 | dump.appendFormat(INDENT3 "SurfaceWidth: %dpx\n", mLocked.surfaceWidth); |
| 1716 | dump.appendFormat(INDENT3 "SurfaceHeight: %dpx\n", mLocked.surfaceHeight); |
| 1717 | dump.appendFormat(INDENT3 "SurfaceOrientation: %d\n", mLocked.surfaceOrientation); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1720 | void TouchInputMapper::configureVirtualKeysLocked() { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1721 | assert(mRawAxes.x.valid && mRawAxes.y.valid); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1722 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1723 | Vector<VirtualKeyDefinition> virtualKeyDefinitions; |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 1724 | getEventHub()->getVirtualKeyDefinitions(getDeviceId(), virtualKeyDefinitions); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1725 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1726 | mLocked.virtualKeys.clear(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1727 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1728 | if (virtualKeyDefinitions.size() == 0) { |
| 1729 | return; |
| 1730 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1731 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1732 | mLocked.virtualKeys.setCapacity(virtualKeyDefinitions.size()); |
| 1733 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1734 | int32_t touchScreenLeft = mRawAxes.x.minValue; |
| 1735 | int32_t touchScreenTop = mRawAxes.y.minValue; |
| 1736 | int32_t touchScreenWidth = mRawAxes.x.getRange(); |
| 1737 | int32_t touchScreenHeight = mRawAxes.y.getRange(); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1738 | |
| 1739 | for (size_t i = 0; i < virtualKeyDefinitions.size(); i++) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1740 | const VirtualKeyDefinition& virtualKeyDefinition = |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1741 | virtualKeyDefinitions[i]; |
| 1742 | |
| 1743 | mLocked.virtualKeys.add(); |
| 1744 | VirtualKey& virtualKey = mLocked.virtualKeys.editTop(); |
| 1745 | |
| 1746 | virtualKey.scanCode = virtualKeyDefinition.scanCode; |
| 1747 | int32_t keyCode; |
| 1748 | uint32_t flags; |
| 1749 | if (getEventHub()->scancodeToKeycode(getDeviceId(), virtualKey.scanCode, |
| 1750 | & keyCode, & flags)) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1751 | LOGW(INDENT "VirtualKey %d: could not obtain key code, ignoring", |
| 1752 | virtualKey.scanCode); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1753 | mLocked.virtualKeys.pop(); // drop the key |
| 1754 | continue; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1757 | virtualKey.keyCode = keyCode; |
| 1758 | virtualKey.flags = flags; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1759 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1760 | // convert the key definition's display coordinates into touch coordinates for a hit box |
| 1761 | int32_t halfWidth = virtualKeyDefinition.width / 2; |
| 1762 | int32_t halfHeight = virtualKeyDefinition.height / 2; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1763 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1764 | virtualKey.hitLeft = (virtualKeyDefinition.centerX - halfWidth) |
| 1765 | * touchScreenWidth / mLocked.surfaceWidth + touchScreenLeft; |
| 1766 | virtualKey.hitRight= (virtualKeyDefinition.centerX + halfWidth) |
| 1767 | * touchScreenWidth / mLocked.surfaceWidth + touchScreenLeft; |
| 1768 | virtualKey.hitTop = (virtualKeyDefinition.centerY - halfHeight) |
| 1769 | * touchScreenHeight / mLocked.surfaceHeight + touchScreenTop; |
| 1770 | virtualKey.hitBottom = (virtualKeyDefinition.centerY + halfHeight) |
| 1771 | * touchScreenHeight / mLocked.surfaceHeight + touchScreenTop; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1772 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 1773 | } |
| 1774 | } |
| 1775 | |
| 1776 | void TouchInputMapper::dumpVirtualKeysLocked(String8& dump) { |
| 1777 | if (!mLocked.virtualKeys.isEmpty()) { |
| 1778 | dump.append(INDENT3 "Virtual Keys:\n"); |
| 1779 | |
| 1780 | for (size_t i = 0; i < mLocked.virtualKeys.size(); i++) { |
| 1781 | const VirtualKey& virtualKey = mLocked.virtualKeys.itemAt(i); |
| 1782 | dump.appendFormat(INDENT4 "%d: scanCode=%d, keyCode=%d, " |
| 1783 | "hitLeft=%d, hitRight=%d, hitTop=%d, hitBottom=%d\n", |
| 1784 | i, virtualKey.scanCode, virtualKey.keyCode, |
| 1785 | virtualKey.hitLeft, virtualKey.hitRight, |
| 1786 | virtualKey.hitTop, virtualKey.hitBottom); |
| 1787 | } |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 1788 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1791 | void TouchInputMapper::parseCalibration() { |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 1792 | const PropertyMap& in = getDevice()->getConfiguration(); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1793 | Calibration& out = mCalibration; |
| 1794 | |
Jeff Brown | 511ee5f | 2010-10-18 13:32:20 -0700 | [diff] [blame] | 1795 | // Position |
| 1796 | out.haveXOrigin = in.tryGetProperty(String8("touch.position.xOrigin"), out.xOrigin); |
| 1797 | out.haveYOrigin = in.tryGetProperty(String8("touch.position.yOrigin"), out.yOrigin); |
| 1798 | out.haveXScale = in.tryGetProperty(String8("touch.position.xScale"), out.xScale); |
| 1799 | out.haveYScale = in.tryGetProperty(String8("touch.position.yScale"), out.yScale); |
| 1800 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1801 | // Touch Size |
| 1802 | out.touchSizeCalibration = Calibration::TOUCH_SIZE_CALIBRATION_DEFAULT; |
| 1803 | String8 touchSizeCalibrationString; |
| 1804 | if (in.tryGetProperty(String8("touch.touchSize.calibration"), touchSizeCalibrationString)) { |
| 1805 | if (touchSizeCalibrationString == "none") { |
| 1806 | out.touchSizeCalibration = Calibration::TOUCH_SIZE_CALIBRATION_NONE; |
| 1807 | } else if (touchSizeCalibrationString == "geometric") { |
| 1808 | out.touchSizeCalibration = Calibration::TOUCH_SIZE_CALIBRATION_GEOMETRIC; |
| 1809 | } else if (touchSizeCalibrationString == "pressure") { |
| 1810 | out.touchSizeCalibration = Calibration::TOUCH_SIZE_CALIBRATION_PRESSURE; |
| 1811 | } else if (touchSizeCalibrationString != "default") { |
| 1812 | LOGW("Invalid value for touch.touchSize.calibration: '%s'", |
| 1813 | touchSizeCalibrationString.string()); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1814 | } |
| 1815 | } |
| 1816 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1817 | // Tool Size |
| 1818 | out.toolSizeCalibration = Calibration::TOOL_SIZE_CALIBRATION_DEFAULT; |
| 1819 | String8 toolSizeCalibrationString; |
| 1820 | if (in.tryGetProperty(String8("touch.toolSize.calibration"), toolSizeCalibrationString)) { |
| 1821 | if (toolSizeCalibrationString == "none") { |
| 1822 | out.toolSizeCalibration = Calibration::TOOL_SIZE_CALIBRATION_NONE; |
| 1823 | } else if (toolSizeCalibrationString == "geometric") { |
| 1824 | out.toolSizeCalibration = Calibration::TOOL_SIZE_CALIBRATION_GEOMETRIC; |
| 1825 | } else if (toolSizeCalibrationString == "linear") { |
| 1826 | out.toolSizeCalibration = Calibration::TOOL_SIZE_CALIBRATION_LINEAR; |
| 1827 | } else if (toolSizeCalibrationString == "area") { |
| 1828 | out.toolSizeCalibration = Calibration::TOOL_SIZE_CALIBRATION_AREA; |
| 1829 | } else if (toolSizeCalibrationString != "default") { |
| 1830 | LOGW("Invalid value for touch.toolSize.calibration: '%s'", |
| 1831 | toolSizeCalibrationString.string()); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1835 | out.haveToolSizeLinearScale = in.tryGetProperty(String8("touch.toolSize.linearScale"), |
| 1836 | out.toolSizeLinearScale); |
| 1837 | out.haveToolSizeLinearBias = in.tryGetProperty(String8("touch.toolSize.linearBias"), |
| 1838 | out.toolSizeLinearBias); |
| 1839 | out.haveToolSizeAreaScale = in.tryGetProperty(String8("touch.toolSize.areaScale"), |
| 1840 | out.toolSizeAreaScale); |
| 1841 | out.haveToolSizeAreaBias = in.tryGetProperty(String8("touch.toolSize.areaBias"), |
| 1842 | out.toolSizeAreaBias); |
| 1843 | out.haveToolSizeIsSummed = in.tryGetProperty(String8("touch.toolSize.isSummed"), |
| 1844 | out.toolSizeIsSummed); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1845 | |
| 1846 | // Pressure |
| 1847 | out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_DEFAULT; |
| 1848 | String8 pressureCalibrationString; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1849 | if (in.tryGetProperty(String8("touch.pressure.calibration"), pressureCalibrationString)) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1850 | if (pressureCalibrationString == "none") { |
| 1851 | out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_NONE; |
| 1852 | } else if (pressureCalibrationString == "physical") { |
| 1853 | out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_PHYSICAL; |
| 1854 | } else if (pressureCalibrationString == "amplitude") { |
| 1855 | out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_AMPLITUDE; |
| 1856 | } else if (pressureCalibrationString != "default") { |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1857 | LOGW("Invalid value for touch.pressure.calibration: '%s'", |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1858 | pressureCalibrationString.string()); |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | out.pressureSource = Calibration::PRESSURE_SOURCE_DEFAULT; |
| 1863 | String8 pressureSourceString; |
| 1864 | if (in.tryGetProperty(String8("touch.pressure.source"), pressureSourceString)) { |
| 1865 | if (pressureSourceString == "pressure") { |
| 1866 | out.pressureSource = Calibration::PRESSURE_SOURCE_PRESSURE; |
| 1867 | } else if (pressureSourceString == "touch") { |
| 1868 | out.pressureSource = Calibration::PRESSURE_SOURCE_TOUCH; |
| 1869 | } else if (pressureSourceString != "default") { |
| 1870 | LOGW("Invalid value for touch.pressure.source: '%s'", |
| 1871 | pressureSourceString.string()); |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | out.havePressureScale = in.tryGetProperty(String8("touch.pressure.scale"), |
| 1876 | out.pressureScale); |
| 1877 | |
| 1878 | // Size |
| 1879 | out.sizeCalibration = Calibration::SIZE_CALIBRATION_DEFAULT; |
| 1880 | String8 sizeCalibrationString; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1881 | if (in.tryGetProperty(String8("touch.size.calibration"), sizeCalibrationString)) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1882 | if (sizeCalibrationString == "none") { |
| 1883 | out.sizeCalibration = Calibration::SIZE_CALIBRATION_NONE; |
| 1884 | } else if (sizeCalibrationString == "normalized") { |
| 1885 | out.sizeCalibration = Calibration::SIZE_CALIBRATION_NORMALIZED; |
| 1886 | } else if (sizeCalibrationString != "default") { |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1887 | LOGW("Invalid value for touch.size.calibration: '%s'", |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1888 | sizeCalibrationString.string()); |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | // Orientation |
| 1893 | out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_DEFAULT; |
| 1894 | String8 orientationCalibrationString; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1895 | if (in.tryGetProperty(String8("touch.orientation.calibration"), orientationCalibrationString)) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1896 | if (orientationCalibrationString == "none") { |
| 1897 | out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_NONE; |
| 1898 | } else if (orientationCalibrationString == "interpolated") { |
| 1899 | out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_INTERPOLATED; |
| 1900 | } else if (orientationCalibrationString != "default") { |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1901 | LOGW("Invalid value for touch.orientation.calibration: '%s'", |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1902 | orientationCalibrationString.string()); |
| 1903 | } |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | void TouchInputMapper::resolveCalibration() { |
| 1908 | // Pressure |
| 1909 | switch (mCalibration.pressureSource) { |
| 1910 | case Calibration::PRESSURE_SOURCE_DEFAULT: |
| 1911 | if (mRawAxes.pressure.valid) { |
| 1912 | mCalibration.pressureSource = Calibration::PRESSURE_SOURCE_PRESSURE; |
| 1913 | } else if (mRawAxes.touchMajor.valid) { |
| 1914 | mCalibration.pressureSource = Calibration::PRESSURE_SOURCE_TOUCH; |
| 1915 | } |
| 1916 | break; |
| 1917 | |
| 1918 | case Calibration::PRESSURE_SOURCE_PRESSURE: |
| 1919 | if (! mRawAxes.pressure.valid) { |
| 1920 | LOGW("Calibration property touch.pressure.source is 'pressure' but " |
| 1921 | "the pressure axis is not available."); |
| 1922 | } |
| 1923 | break; |
| 1924 | |
| 1925 | case Calibration::PRESSURE_SOURCE_TOUCH: |
| 1926 | if (! mRawAxes.touchMajor.valid) { |
| 1927 | LOGW("Calibration property touch.pressure.source is 'touch' but " |
| 1928 | "the touchMajor axis is not available."); |
| 1929 | } |
| 1930 | break; |
| 1931 | |
| 1932 | default: |
| 1933 | break; |
| 1934 | } |
| 1935 | |
| 1936 | switch (mCalibration.pressureCalibration) { |
| 1937 | case Calibration::PRESSURE_CALIBRATION_DEFAULT: |
| 1938 | if (mCalibration.pressureSource != Calibration::PRESSURE_SOURCE_DEFAULT) { |
| 1939 | mCalibration.pressureCalibration = Calibration::PRESSURE_CALIBRATION_AMPLITUDE; |
| 1940 | } else { |
| 1941 | mCalibration.pressureCalibration = Calibration::PRESSURE_CALIBRATION_NONE; |
| 1942 | } |
| 1943 | break; |
| 1944 | |
| 1945 | default: |
| 1946 | break; |
| 1947 | } |
| 1948 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1949 | // Tool Size |
| 1950 | switch (mCalibration.toolSizeCalibration) { |
| 1951 | case Calibration::TOOL_SIZE_CALIBRATION_DEFAULT: |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1952 | if (mRawAxes.toolMajor.valid) { |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1953 | mCalibration.toolSizeCalibration = Calibration::TOOL_SIZE_CALIBRATION_LINEAR; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1954 | } else { |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1955 | mCalibration.toolSizeCalibration = Calibration::TOOL_SIZE_CALIBRATION_NONE; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1956 | } |
| 1957 | break; |
| 1958 | |
| 1959 | default: |
| 1960 | break; |
| 1961 | } |
| 1962 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1963 | // Touch Size |
| 1964 | switch (mCalibration.touchSizeCalibration) { |
| 1965 | case Calibration::TOUCH_SIZE_CALIBRATION_DEFAULT: |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1966 | if (mCalibration.pressureCalibration != Calibration::PRESSURE_CALIBRATION_NONE |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1967 | && mCalibration.toolSizeCalibration != Calibration::TOOL_SIZE_CALIBRATION_NONE) { |
| 1968 | mCalibration.touchSizeCalibration = Calibration::TOUCH_SIZE_CALIBRATION_PRESSURE; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1969 | } else { |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 1970 | mCalibration.touchSizeCalibration = Calibration::TOUCH_SIZE_CALIBRATION_NONE; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1971 | } |
| 1972 | break; |
| 1973 | |
| 1974 | default: |
| 1975 | break; |
| 1976 | } |
| 1977 | |
| 1978 | // Size |
| 1979 | switch (mCalibration.sizeCalibration) { |
| 1980 | case Calibration::SIZE_CALIBRATION_DEFAULT: |
| 1981 | if (mRawAxes.toolMajor.valid) { |
| 1982 | mCalibration.sizeCalibration = Calibration::SIZE_CALIBRATION_NORMALIZED; |
| 1983 | } else { |
| 1984 | mCalibration.sizeCalibration = Calibration::SIZE_CALIBRATION_NONE; |
| 1985 | } |
| 1986 | break; |
| 1987 | |
| 1988 | default: |
| 1989 | break; |
| 1990 | } |
| 1991 | |
| 1992 | // Orientation |
| 1993 | switch (mCalibration.orientationCalibration) { |
| 1994 | case Calibration::ORIENTATION_CALIBRATION_DEFAULT: |
| 1995 | if (mRawAxes.orientation.valid) { |
| 1996 | mCalibration.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_INTERPOLATED; |
| 1997 | } else { |
| 1998 | mCalibration.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_NONE; |
| 1999 | } |
| 2000 | break; |
| 2001 | |
| 2002 | default: |
| 2003 | break; |
| 2004 | } |
| 2005 | } |
| 2006 | |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 2007 | void TouchInputMapper::dumpCalibration(String8& dump) { |
| 2008 | dump.append(INDENT3 "Calibration:\n"); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2009 | |
Jeff Brown | 511ee5f | 2010-10-18 13:32:20 -0700 | [diff] [blame] | 2010 | // Position |
| 2011 | if (mCalibration.haveXOrigin) { |
| 2012 | dump.appendFormat(INDENT4 "touch.position.xOrigin: %d\n", mCalibration.xOrigin); |
| 2013 | } |
| 2014 | if (mCalibration.haveYOrigin) { |
| 2015 | dump.appendFormat(INDENT4 "touch.position.yOrigin: %d\n", mCalibration.yOrigin); |
| 2016 | } |
| 2017 | if (mCalibration.haveXScale) { |
| 2018 | dump.appendFormat(INDENT4 "touch.position.xScale: %0.3f\n", mCalibration.xScale); |
| 2019 | } |
| 2020 | if (mCalibration.haveYScale) { |
| 2021 | dump.appendFormat(INDENT4 "touch.position.yScale: %0.3f\n", mCalibration.yScale); |
| 2022 | } |
| 2023 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2024 | // Touch Size |
| 2025 | switch (mCalibration.touchSizeCalibration) { |
| 2026 | case Calibration::TOUCH_SIZE_CALIBRATION_NONE: |
| 2027 | dump.append(INDENT4 "touch.touchSize.calibration: none\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2028 | break; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2029 | case Calibration::TOUCH_SIZE_CALIBRATION_GEOMETRIC: |
| 2030 | dump.append(INDENT4 "touch.touchSize.calibration: geometric\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2031 | break; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2032 | case Calibration::TOUCH_SIZE_CALIBRATION_PRESSURE: |
| 2033 | dump.append(INDENT4 "touch.touchSize.calibration: pressure\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2034 | break; |
| 2035 | default: |
| 2036 | assert(false); |
| 2037 | } |
| 2038 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2039 | // Tool Size |
| 2040 | switch (mCalibration.toolSizeCalibration) { |
| 2041 | case Calibration::TOOL_SIZE_CALIBRATION_NONE: |
| 2042 | dump.append(INDENT4 "touch.toolSize.calibration: none\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2043 | break; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2044 | case Calibration::TOOL_SIZE_CALIBRATION_GEOMETRIC: |
| 2045 | dump.append(INDENT4 "touch.toolSize.calibration: geometric\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2046 | break; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2047 | case Calibration::TOOL_SIZE_CALIBRATION_LINEAR: |
| 2048 | dump.append(INDENT4 "touch.toolSize.calibration: linear\n"); |
| 2049 | break; |
| 2050 | case Calibration::TOOL_SIZE_CALIBRATION_AREA: |
| 2051 | dump.append(INDENT4 "touch.toolSize.calibration: area\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2052 | break; |
| 2053 | default: |
| 2054 | assert(false); |
| 2055 | } |
| 2056 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2057 | if (mCalibration.haveToolSizeLinearScale) { |
| 2058 | dump.appendFormat(INDENT4 "touch.toolSize.linearScale: %0.3f\n", |
| 2059 | mCalibration.toolSizeLinearScale); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2062 | if (mCalibration.haveToolSizeLinearBias) { |
| 2063 | dump.appendFormat(INDENT4 "touch.toolSize.linearBias: %0.3f\n", |
| 2064 | mCalibration.toolSizeLinearBias); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2067 | if (mCalibration.haveToolSizeAreaScale) { |
| 2068 | dump.appendFormat(INDENT4 "touch.toolSize.areaScale: %0.3f\n", |
| 2069 | mCalibration.toolSizeAreaScale); |
| 2070 | } |
| 2071 | |
| 2072 | if (mCalibration.haveToolSizeAreaBias) { |
| 2073 | dump.appendFormat(INDENT4 "touch.toolSize.areaBias: %0.3f\n", |
| 2074 | mCalibration.toolSizeAreaBias); |
| 2075 | } |
| 2076 | |
| 2077 | if (mCalibration.haveToolSizeIsSummed) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2078 | dump.appendFormat(INDENT4 "touch.toolSize.isSummed: %s\n", |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 2079 | toString(mCalibration.toolSizeIsSummed)); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | // Pressure |
| 2083 | switch (mCalibration.pressureCalibration) { |
| 2084 | case Calibration::PRESSURE_CALIBRATION_NONE: |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 2085 | dump.append(INDENT4 "touch.pressure.calibration: none\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2086 | break; |
| 2087 | case Calibration::PRESSURE_CALIBRATION_PHYSICAL: |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 2088 | dump.append(INDENT4 "touch.pressure.calibration: physical\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2089 | break; |
| 2090 | case Calibration::PRESSURE_CALIBRATION_AMPLITUDE: |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 2091 | dump.append(INDENT4 "touch.pressure.calibration: amplitude\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2092 | break; |
| 2093 | default: |
| 2094 | assert(false); |
| 2095 | } |
| 2096 | |
| 2097 | switch (mCalibration.pressureSource) { |
| 2098 | case Calibration::PRESSURE_SOURCE_PRESSURE: |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 2099 | dump.append(INDENT4 "touch.pressure.source: pressure\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2100 | break; |
| 2101 | case Calibration::PRESSURE_SOURCE_TOUCH: |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 2102 | dump.append(INDENT4 "touch.pressure.source: touch\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2103 | break; |
| 2104 | case Calibration::PRESSURE_SOURCE_DEFAULT: |
| 2105 | break; |
| 2106 | default: |
| 2107 | assert(false); |
| 2108 | } |
| 2109 | |
| 2110 | if (mCalibration.havePressureScale) { |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 2111 | dump.appendFormat(INDENT4 "touch.pressure.scale: %0.3f\n", |
| 2112 | mCalibration.pressureScale); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | // Size |
| 2116 | switch (mCalibration.sizeCalibration) { |
| 2117 | case Calibration::SIZE_CALIBRATION_NONE: |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 2118 | dump.append(INDENT4 "touch.size.calibration: none\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2119 | break; |
| 2120 | case Calibration::SIZE_CALIBRATION_NORMALIZED: |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 2121 | dump.append(INDENT4 "touch.size.calibration: normalized\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2122 | break; |
| 2123 | default: |
| 2124 | assert(false); |
| 2125 | } |
| 2126 | |
| 2127 | // Orientation |
| 2128 | switch (mCalibration.orientationCalibration) { |
| 2129 | case Calibration::ORIENTATION_CALIBRATION_NONE: |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 2130 | dump.append(INDENT4 "touch.orientation.calibration: none\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2131 | break; |
| 2132 | case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED: |
Jeff Brown | ef3d7e8 | 2010-09-30 14:33:04 -0700 | [diff] [blame] | 2133 | dump.append(INDENT4 "touch.orientation.calibration: interpolated\n"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2134 | break; |
| 2135 | default: |
| 2136 | assert(false); |
| 2137 | } |
| 2138 | } |
| 2139 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2140 | void TouchInputMapper::reset() { |
| 2141 | // Synthesize touch up event if touch is currently down. |
| 2142 | // This will also take care of finishing virtual key processing if needed. |
| 2143 | if (mLastTouch.pointerCount != 0) { |
| 2144 | nsecs_t when = systemTime(SYSTEM_TIME_MONOTONIC); |
| 2145 | mCurrentTouch.clear(); |
| 2146 | syncTouch(when, true); |
| 2147 | } |
| 2148 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2149 | { // acquire lock |
| 2150 | AutoMutex _l(mLock); |
| 2151 | initializeLocked(); |
| 2152 | } // release lock |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2153 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2154 | InputMapper::reset(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | void TouchInputMapper::syncTouch(nsecs_t when, bool havePointerIds) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2158 | uint32_t policyFlags = 0; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2159 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2160 | // Preprocess pointer data. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2161 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2162 | if (mParameters.useBadTouchFilter) { |
| 2163 | if (applyBadTouchFilter()) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2164 | havePointerIds = false; |
| 2165 | } |
| 2166 | } |
| 2167 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2168 | if (mParameters.useJumpyTouchFilter) { |
| 2169 | if (applyJumpyTouchFilter()) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2170 | havePointerIds = false; |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | if (! havePointerIds) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2175 | calculatePointerIds(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2178 | TouchData temp; |
| 2179 | TouchData* savedTouch; |
| 2180 | if (mParameters.useAveragingTouchFilter) { |
| 2181 | temp.copyFrom(mCurrentTouch); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2182 | savedTouch = & temp; |
| 2183 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2184 | applyAveragingTouchFilter(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2185 | } else { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2186 | savedTouch = & mCurrentTouch; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2189 | // Process touches and virtual keys. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2190 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2191 | TouchResult touchResult = consumeOffScreenTouches(when, policyFlags); |
| 2192 | if (touchResult == DISPATCH_TOUCH) { |
| 2193 | dispatchTouches(when, policyFlags); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2196 | // Copy current touch to last touch in preparation for the next cycle. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2197 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2198 | if (touchResult == DROP_STROKE) { |
| 2199 | mLastTouch.clear(); |
| 2200 | } else { |
| 2201 | mLastTouch.copyFrom(*savedTouch); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2202 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2203 | } |
| 2204 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2205 | TouchInputMapper::TouchResult TouchInputMapper::consumeOffScreenTouches( |
| 2206 | nsecs_t when, uint32_t policyFlags) { |
| 2207 | int32_t keyEventAction, keyEventFlags; |
| 2208 | int32_t keyCode, scanCode, downTime; |
| 2209 | TouchResult touchResult; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2210 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2211 | { // acquire lock |
| 2212 | AutoMutex _l(mLock); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2213 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2214 | // Update surface size and orientation, including virtual key positions. |
| 2215 | if (! configureSurfaceLocked()) { |
| 2216 | return DROP_STROKE; |
| 2217 | } |
| 2218 | |
| 2219 | // Check for virtual key press. |
| 2220 | if (mLocked.currentVirtualKey.down) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2221 | if (mCurrentTouch.pointerCount == 0) { |
| 2222 | // Pointer went up while virtual key was down. |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2223 | mLocked.currentVirtualKey.down = false; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2224 | #if DEBUG_VIRTUAL_KEYS |
| 2225 | LOGD("VirtualKeys: Generating key up: keyCode=%d, scanCode=%d", |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2226 | mLocked.currentVirtualKey.keyCode, mLocked.currentVirtualKey.scanCode); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2227 | #endif |
| 2228 | keyEventAction = AKEY_EVENT_ACTION_UP; |
| 2229 | keyEventFlags = AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY; |
| 2230 | touchResult = SKIP_TOUCH; |
| 2231 | goto DispatchVirtualKey; |
| 2232 | } |
| 2233 | |
| 2234 | if (mCurrentTouch.pointerCount == 1) { |
| 2235 | int32_t x = mCurrentTouch.pointers[0].x; |
| 2236 | int32_t y = mCurrentTouch.pointers[0].y; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2237 | const VirtualKey* virtualKey = findVirtualKeyHitLocked(x, y); |
| 2238 | if (virtualKey && virtualKey->keyCode == mLocked.currentVirtualKey.keyCode) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2239 | // Pointer is still within the space of the virtual key. |
| 2240 | return SKIP_TOUCH; |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | // Pointer left virtual key area or another pointer also went down. |
| 2245 | // Send key cancellation and drop the stroke so subsequent motions will be |
| 2246 | // considered fresh downs. This is useful when the user swipes away from the |
| 2247 | // virtual key area into the main display surface. |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2248 | mLocked.currentVirtualKey.down = false; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2249 | #if DEBUG_VIRTUAL_KEYS |
| 2250 | LOGD("VirtualKeys: Canceling key: keyCode=%d, scanCode=%d", |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2251 | mLocked.currentVirtualKey.keyCode, mLocked.currentVirtualKey.scanCode); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2252 | #endif |
| 2253 | keyEventAction = AKEY_EVENT_ACTION_UP; |
| 2254 | keyEventFlags = AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY |
| 2255 | | AKEY_EVENT_FLAG_CANCELED; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2256 | |
| 2257 | // Check whether the pointer moved inside the display area where we should |
| 2258 | // start a new stroke. |
| 2259 | int32_t x = mCurrentTouch.pointers[0].x; |
| 2260 | int32_t y = mCurrentTouch.pointers[0].y; |
| 2261 | if (isPointInsideSurfaceLocked(x, y)) { |
| 2262 | mLastTouch.clear(); |
| 2263 | touchResult = DISPATCH_TOUCH; |
| 2264 | } else { |
| 2265 | touchResult = DROP_STROKE; |
| 2266 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2267 | } else { |
| 2268 | if (mCurrentTouch.pointerCount >= 1 && mLastTouch.pointerCount == 0) { |
| 2269 | // Pointer just went down. Handle off-screen touches, if needed. |
| 2270 | int32_t x = mCurrentTouch.pointers[0].x; |
| 2271 | int32_t y = mCurrentTouch.pointers[0].y; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2272 | if (! isPointInsideSurfaceLocked(x, y)) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2273 | // If exactly one pointer went down, check for virtual key hit. |
| 2274 | // Otherwise we will drop the entire stroke. |
| 2275 | if (mCurrentTouch.pointerCount == 1) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2276 | const VirtualKey* virtualKey = findVirtualKeyHitLocked(x, y); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2277 | if (virtualKey) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2278 | mLocked.currentVirtualKey.down = true; |
| 2279 | mLocked.currentVirtualKey.downTime = when; |
| 2280 | mLocked.currentVirtualKey.keyCode = virtualKey->keyCode; |
| 2281 | mLocked.currentVirtualKey.scanCode = virtualKey->scanCode; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2282 | #if DEBUG_VIRTUAL_KEYS |
| 2283 | LOGD("VirtualKeys: Generating key down: keyCode=%d, scanCode=%d", |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2284 | mLocked.currentVirtualKey.keyCode, |
| 2285 | mLocked.currentVirtualKey.scanCode); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2286 | #endif |
| 2287 | keyEventAction = AKEY_EVENT_ACTION_DOWN; |
| 2288 | keyEventFlags = AKEY_EVENT_FLAG_FROM_SYSTEM |
| 2289 | | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY; |
| 2290 | touchResult = SKIP_TOUCH; |
| 2291 | goto DispatchVirtualKey; |
| 2292 | } |
| 2293 | } |
| 2294 | return DROP_STROKE; |
| 2295 | } |
| 2296 | } |
| 2297 | return DISPATCH_TOUCH; |
| 2298 | } |
| 2299 | |
| 2300 | DispatchVirtualKey: |
| 2301 | // Collect remaining state needed to dispatch virtual key. |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2302 | keyCode = mLocked.currentVirtualKey.keyCode; |
| 2303 | scanCode = mLocked.currentVirtualKey.scanCode; |
| 2304 | downTime = mLocked.currentVirtualKey.downTime; |
| 2305 | } // release lock |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2306 | |
| 2307 | // Dispatch virtual key. |
| 2308 | int32_t metaState = mContext->getGlobalMetaState(); |
Jeff Brown | 0eaf393 | 2010-10-01 14:55:30 -0700 | [diff] [blame] | 2309 | policyFlags |= POLICY_FLAG_VIRTUAL; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2310 | getDispatcher()->notifyKey(when, getDeviceId(), AINPUT_SOURCE_KEYBOARD, policyFlags, |
| 2311 | keyEventAction, keyEventFlags, keyCode, scanCode, metaState, downTime); |
| 2312 | return touchResult; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2315 | void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { |
| 2316 | uint32_t currentPointerCount = mCurrentTouch.pointerCount; |
| 2317 | uint32_t lastPointerCount = mLastTouch.pointerCount; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2318 | if (currentPointerCount == 0 && lastPointerCount == 0) { |
| 2319 | return; // nothing to do! |
| 2320 | } |
| 2321 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2322 | BitSet32 currentIdBits = mCurrentTouch.idBits; |
| 2323 | BitSet32 lastIdBits = mLastTouch.idBits; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2324 | |
| 2325 | if (currentIdBits == lastIdBits) { |
| 2326 | // No pointer id changes so this is a move event. |
| 2327 | // The dispatcher takes care of batching moves so we don't have to deal with that here. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2328 | int32_t motionEventAction = AMOTION_EVENT_ACTION_MOVE; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2329 | dispatchTouch(when, policyFlags, & mCurrentTouch, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2330 | currentIdBits, -1, currentPointerCount, motionEventAction); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2331 | } else { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2332 | // There may be pointers going up and pointers going down and pointers moving |
| 2333 | // all at the same time. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2334 | BitSet32 upIdBits(lastIdBits.value & ~ currentIdBits.value); |
| 2335 | BitSet32 downIdBits(currentIdBits.value & ~ lastIdBits.value); |
| 2336 | BitSet32 activeIdBits(lastIdBits.value); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2337 | uint32_t pointerCount = lastPointerCount; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2338 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2339 | // Produce an intermediate representation of the touch data that consists of the |
| 2340 | // old location of pointers that have just gone up and the new location of pointers that |
| 2341 | // have just moved but omits the location of pointers that have just gone down. |
| 2342 | TouchData interimTouch; |
| 2343 | interimTouch.copyFrom(mLastTouch); |
| 2344 | |
| 2345 | BitSet32 moveIdBits(lastIdBits.value & currentIdBits.value); |
| 2346 | bool moveNeeded = false; |
| 2347 | while (!moveIdBits.isEmpty()) { |
| 2348 | uint32_t moveId = moveIdBits.firstMarkedBit(); |
| 2349 | moveIdBits.clearBit(moveId); |
| 2350 | |
| 2351 | int32_t oldIndex = mLastTouch.idToIndex[moveId]; |
| 2352 | int32_t newIndex = mCurrentTouch.idToIndex[moveId]; |
| 2353 | if (mLastTouch.pointers[oldIndex] != mCurrentTouch.pointers[newIndex]) { |
| 2354 | interimTouch.pointers[oldIndex] = mCurrentTouch.pointers[newIndex]; |
| 2355 | moveNeeded = true; |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | // Dispatch pointer up events using the interim pointer locations. |
| 2360 | while (!upIdBits.isEmpty()) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2361 | uint32_t upId = upIdBits.firstMarkedBit(); |
| 2362 | upIdBits.clearBit(upId); |
| 2363 | BitSet32 oldActiveIdBits = activeIdBits; |
| 2364 | activeIdBits.clearBit(upId); |
| 2365 | |
| 2366 | int32_t motionEventAction; |
| 2367 | if (activeIdBits.isEmpty()) { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2368 | motionEventAction = AMOTION_EVENT_ACTION_UP; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2369 | } else { |
Jeff Brown | 00ba884 | 2010-07-16 15:01:56 -0700 | [diff] [blame] | 2370 | motionEventAction = AMOTION_EVENT_ACTION_POINTER_UP; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2373 | dispatchTouch(when, policyFlags, &interimTouch, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2374 | oldActiveIdBits, upId, pointerCount, motionEventAction); |
| 2375 | pointerCount -= 1; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2378 | // Dispatch move events if any of the remaining pointers moved from their old locations. |
| 2379 | // Although applications receive new locations as part of individual pointer up |
| 2380 | // events, they do not generally handle them except when presented in a move event. |
| 2381 | if (moveNeeded) { |
| 2382 | dispatchTouch(when, policyFlags, &mCurrentTouch, |
| 2383 | activeIdBits, -1, pointerCount, AMOTION_EVENT_ACTION_MOVE); |
| 2384 | } |
| 2385 | |
| 2386 | // Dispatch pointer down events using the new pointer locations. |
| 2387 | while (!downIdBits.isEmpty()) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2388 | uint32_t downId = downIdBits.firstMarkedBit(); |
| 2389 | downIdBits.clearBit(downId); |
| 2390 | BitSet32 oldActiveIdBits = activeIdBits; |
| 2391 | activeIdBits.markBit(downId); |
| 2392 | |
| 2393 | int32_t motionEventAction; |
| 2394 | if (oldActiveIdBits.isEmpty()) { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2395 | motionEventAction = AMOTION_EVENT_ACTION_DOWN; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2396 | mDownTime = when; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2397 | } else { |
Jeff Brown | 00ba884 | 2010-07-16 15:01:56 -0700 | [diff] [blame] | 2398 | motionEventAction = AMOTION_EVENT_ACTION_POINTER_DOWN; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2401 | pointerCount += 1; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 2402 | dispatchTouch(when, policyFlags, &mCurrentTouch, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2403 | activeIdBits, downId, pointerCount, motionEventAction); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2404 | } |
| 2405 | } |
| 2406 | } |
| 2407 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2408 | void TouchInputMapper::dispatchTouch(nsecs_t when, uint32_t policyFlags, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2409 | TouchData* touch, BitSet32 idBits, uint32_t changedId, uint32_t pointerCount, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2410 | int32_t motionEventAction) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2411 | int32_t pointerIds[MAX_POINTERS]; |
| 2412 | PointerCoords pointerCoords[MAX_POINTERS]; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2413 | int32_t motionEventEdgeFlags = 0; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2414 | float xPrecision, yPrecision; |
| 2415 | |
| 2416 | { // acquire lock |
| 2417 | AutoMutex _l(mLock); |
| 2418 | |
| 2419 | // Walk through the the active pointers and map touch screen coordinates (TouchData) into |
| 2420 | // display coordinates (PointerCoords) and adjust for display orientation. |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2421 | for (uint32_t outIndex = 0; ! idBits.isEmpty(); outIndex++) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2422 | uint32_t id = idBits.firstMarkedBit(); |
| 2423 | idBits.clearBit(id); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2424 | uint32_t inIndex = touch->idToIndex[id]; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2425 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2426 | const PointerData& in = touch->pointers[inIndex]; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2427 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2428 | // X and Y |
| 2429 | float x = float(in.x - mLocked.xOrigin) * mLocked.xScale; |
| 2430 | float y = float(in.y - mLocked.yOrigin) * mLocked.yScale; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2431 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2432 | // ToolMajor and ToolMinor |
| 2433 | float toolMajor, toolMinor; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2434 | switch (mCalibration.toolSizeCalibration) { |
| 2435 | case Calibration::TOOL_SIZE_CALIBRATION_GEOMETRIC: |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2436 | toolMajor = in.toolMajor * mLocked.geometricScale; |
| 2437 | if (mRawAxes.toolMinor.valid) { |
| 2438 | toolMinor = in.toolMinor * mLocked.geometricScale; |
| 2439 | } else { |
| 2440 | toolMinor = toolMajor; |
| 2441 | } |
| 2442 | break; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2443 | case Calibration::TOOL_SIZE_CALIBRATION_LINEAR: |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2444 | toolMajor = in.toolMajor != 0 |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2445 | ? in.toolMajor * mLocked.toolSizeLinearScale + mLocked.toolSizeLinearBias |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2446 | : 0; |
| 2447 | if (mRawAxes.toolMinor.valid) { |
| 2448 | toolMinor = in.toolMinor != 0 |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2449 | ? in.toolMinor * mLocked.toolSizeLinearScale |
| 2450 | + mLocked.toolSizeLinearBias |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2451 | : 0; |
| 2452 | } else { |
| 2453 | toolMinor = toolMajor; |
| 2454 | } |
| 2455 | break; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2456 | case Calibration::TOOL_SIZE_CALIBRATION_AREA: |
| 2457 | if (in.toolMajor != 0) { |
| 2458 | float diameter = sqrtf(in.toolMajor |
| 2459 | * mLocked.toolSizeAreaScale + mLocked.toolSizeAreaBias); |
| 2460 | toolMajor = diameter * mLocked.toolSizeLinearScale + mLocked.toolSizeLinearBias; |
| 2461 | } else { |
| 2462 | toolMajor = 0; |
| 2463 | } |
| 2464 | toolMinor = toolMajor; |
| 2465 | break; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2466 | default: |
| 2467 | toolMajor = 0; |
| 2468 | toolMinor = 0; |
| 2469 | break; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2472 | if (mCalibration.haveToolSizeIsSummed && mCalibration.toolSizeIsSummed) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2473 | toolMajor /= pointerCount; |
| 2474 | toolMinor /= pointerCount; |
| 2475 | } |
| 2476 | |
| 2477 | // Pressure |
| 2478 | float rawPressure; |
| 2479 | switch (mCalibration.pressureSource) { |
| 2480 | case Calibration::PRESSURE_SOURCE_PRESSURE: |
| 2481 | rawPressure = in.pressure; |
| 2482 | break; |
| 2483 | case Calibration::PRESSURE_SOURCE_TOUCH: |
| 2484 | rawPressure = in.touchMajor; |
| 2485 | break; |
| 2486 | default: |
| 2487 | rawPressure = 0; |
| 2488 | } |
| 2489 | |
| 2490 | float pressure; |
| 2491 | switch (mCalibration.pressureCalibration) { |
| 2492 | case Calibration::PRESSURE_CALIBRATION_PHYSICAL: |
| 2493 | case Calibration::PRESSURE_CALIBRATION_AMPLITUDE: |
| 2494 | pressure = rawPressure * mLocked.pressureScale; |
| 2495 | break; |
| 2496 | default: |
| 2497 | pressure = 1; |
| 2498 | break; |
| 2499 | } |
| 2500 | |
| 2501 | // TouchMajor and TouchMinor |
| 2502 | float touchMajor, touchMinor; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2503 | switch (mCalibration.touchSizeCalibration) { |
| 2504 | case Calibration::TOUCH_SIZE_CALIBRATION_GEOMETRIC: |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2505 | touchMajor = in.touchMajor * mLocked.geometricScale; |
| 2506 | if (mRawAxes.touchMinor.valid) { |
| 2507 | touchMinor = in.touchMinor * mLocked.geometricScale; |
| 2508 | } else { |
| 2509 | touchMinor = touchMajor; |
| 2510 | } |
| 2511 | break; |
Jeff Brown | c6d282b | 2010-10-14 21:42:15 -0700 | [diff] [blame] | 2512 | case Calibration::TOUCH_SIZE_CALIBRATION_PRESSURE: |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2513 | touchMajor = toolMajor * pressure; |
| 2514 | touchMinor = toolMinor * pressure; |
| 2515 | break; |
| 2516 | default: |
| 2517 | touchMajor = 0; |
| 2518 | touchMinor = 0; |
| 2519 | break; |
| 2520 | } |
| 2521 | |
| 2522 | if (touchMajor > toolMajor) { |
| 2523 | touchMajor = toolMajor; |
| 2524 | } |
| 2525 | if (touchMinor > toolMinor) { |
| 2526 | touchMinor = toolMinor; |
| 2527 | } |
| 2528 | |
| 2529 | // Size |
| 2530 | float size; |
| 2531 | switch (mCalibration.sizeCalibration) { |
| 2532 | case Calibration::SIZE_CALIBRATION_NORMALIZED: { |
| 2533 | float rawSize = mRawAxes.toolMinor.valid |
| 2534 | ? avg(in.toolMajor, in.toolMinor) |
| 2535 | : in.toolMajor; |
| 2536 | size = rawSize * mLocked.sizeScale; |
| 2537 | break; |
| 2538 | } |
| 2539 | default: |
| 2540 | size = 0; |
| 2541 | break; |
| 2542 | } |
| 2543 | |
| 2544 | // Orientation |
| 2545 | float orientation; |
| 2546 | switch (mCalibration.orientationCalibration) { |
| 2547 | case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED: |
| 2548 | orientation = in.orientation * mLocked.orientationScale; |
| 2549 | break; |
| 2550 | default: |
| 2551 | orientation = 0; |
| 2552 | } |
| 2553 | |
| 2554 | // Adjust coords for orientation. |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2555 | switch (mLocked.surfaceOrientation) { |
| 2556 | case InputReaderPolicyInterface::ROTATION_90: { |
| 2557 | float xTemp = x; |
| 2558 | x = y; |
| 2559 | y = mLocked.surfaceWidth - xTemp; |
| 2560 | orientation -= M_PI_2; |
| 2561 | if (orientation < - M_PI_2) { |
| 2562 | orientation += M_PI; |
| 2563 | } |
| 2564 | break; |
| 2565 | } |
| 2566 | case InputReaderPolicyInterface::ROTATION_180: { |
| 2567 | x = mLocked.surfaceWidth - x; |
| 2568 | y = mLocked.surfaceHeight - y; |
| 2569 | orientation = - orientation; |
| 2570 | break; |
| 2571 | } |
| 2572 | case InputReaderPolicyInterface::ROTATION_270: { |
| 2573 | float xTemp = x; |
| 2574 | x = mLocked.surfaceHeight - y; |
| 2575 | y = xTemp; |
| 2576 | orientation += M_PI_2; |
| 2577 | if (orientation > M_PI_2) { |
| 2578 | orientation -= M_PI; |
| 2579 | } |
| 2580 | break; |
| 2581 | } |
| 2582 | } |
| 2583 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2584 | // Write output coords. |
| 2585 | PointerCoords& out = pointerCoords[outIndex]; |
| 2586 | out.x = x; |
| 2587 | out.y = y; |
| 2588 | out.pressure = pressure; |
| 2589 | out.size = size; |
| 2590 | out.touchMajor = touchMajor; |
| 2591 | out.touchMinor = touchMinor; |
| 2592 | out.toolMajor = toolMajor; |
| 2593 | out.toolMinor = toolMinor; |
| 2594 | out.orientation = orientation; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2595 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2596 | pointerIds[outIndex] = int32_t(id); |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2597 | |
| 2598 | if (id == changedId) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2599 | motionEventAction |= outIndex << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2600 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2601 | } |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2602 | |
| 2603 | // Check edge flags by looking only at the first pointer since the flags are |
| 2604 | // global to the event. |
| 2605 | if (motionEventAction == AMOTION_EVENT_ACTION_DOWN) { |
| 2606 | if (pointerCoords[0].x <= 0) { |
| 2607 | motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_LEFT; |
| 2608 | } else if (pointerCoords[0].x >= mLocked.orientedSurfaceWidth) { |
| 2609 | motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_RIGHT; |
| 2610 | } |
| 2611 | if (pointerCoords[0].y <= 0) { |
| 2612 | motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_TOP; |
| 2613 | } else if (pointerCoords[0].y >= mLocked.orientedSurfaceHeight) { |
| 2614 | motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_BOTTOM; |
| 2615 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2616 | } |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2617 | |
| 2618 | xPrecision = mLocked.orientedXPrecision; |
| 2619 | yPrecision = mLocked.orientedYPrecision; |
| 2620 | } // release lock |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2621 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 2622 | getDispatcher()->notifyMotion(when, getDeviceId(), mSources, policyFlags, |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 2623 | motionEventAction, 0, getContext()->getGlobalMetaState(), motionEventEdgeFlags, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2624 | pointerCount, pointerIds, pointerCoords, |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2625 | xPrecision, yPrecision, mDownTime); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2628 | bool TouchInputMapper::isPointInsideSurfaceLocked(int32_t x, int32_t y) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2629 | if (mRawAxes.x.valid && mRawAxes.y.valid) { |
| 2630 | return x >= mRawAxes.x.minValue && x <= mRawAxes.x.maxValue |
| 2631 | && y >= mRawAxes.y.minValue && y <= mRawAxes.y.maxValue; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2632 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2633 | return true; |
| 2634 | } |
| 2635 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 2636 | const TouchInputMapper::VirtualKey* TouchInputMapper::findVirtualKeyHitLocked( |
| 2637 | int32_t x, int32_t y) { |
| 2638 | size_t numVirtualKeys = mLocked.virtualKeys.size(); |
| 2639 | for (size_t i = 0; i < numVirtualKeys; i++) { |
| 2640 | const VirtualKey& virtualKey = mLocked.virtualKeys[i]; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2641 | |
| 2642 | #if DEBUG_VIRTUAL_KEYS |
| 2643 | LOGD("VirtualKeys: Hit test (%d, %d): keyCode=%d, scanCode=%d, " |
| 2644 | "left=%d, top=%d, right=%d, bottom=%d", |
| 2645 | x, y, |
| 2646 | virtualKey.keyCode, virtualKey.scanCode, |
| 2647 | virtualKey.hitLeft, virtualKey.hitTop, |
| 2648 | virtualKey.hitRight, virtualKey.hitBottom); |
| 2649 | #endif |
| 2650 | |
| 2651 | if (virtualKey.isHit(x, y)) { |
| 2652 | return & virtualKey; |
| 2653 | } |
| 2654 | } |
| 2655 | |
| 2656 | return NULL; |
| 2657 | } |
| 2658 | |
| 2659 | void TouchInputMapper::calculatePointerIds() { |
| 2660 | uint32_t currentPointerCount = mCurrentTouch.pointerCount; |
| 2661 | uint32_t lastPointerCount = mLastTouch.pointerCount; |
| 2662 | |
| 2663 | if (currentPointerCount == 0) { |
| 2664 | // No pointers to assign. |
| 2665 | mCurrentTouch.idBits.clear(); |
| 2666 | } else if (lastPointerCount == 0) { |
| 2667 | // All pointers are new. |
| 2668 | mCurrentTouch.idBits.clear(); |
| 2669 | for (uint32_t i = 0; i < currentPointerCount; i++) { |
| 2670 | mCurrentTouch.pointers[i].id = i; |
| 2671 | mCurrentTouch.idToIndex[i] = i; |
| 2672 | mCurrentTouch.idBits.markBit(i); |
| 2673 | } |
| 2674 | } else if (currentPointerCount == 1 && lastPointerCount == 1) { |
| 2675 | // Only one pointer and no change in count so it must have the same id as before. |
| 2676 | uint32_t id = mLastTouch.pointers[0].id; |
| 2677 | mCurrentTouch.pointers[0].id = id; |
| 2678 | mCurrentTouch.idToIndex[id] = 0; |
| 2679 | mCurrentTouch.idBits.value = BitSet32::valueForBit(id); |
| 2680 | } else { |
| 2681 | // General case. |
| 2682 | // We build a heap of squared euclidean distances between current and last pointers |
| 2683 | // associated with the current and last pointer indices. Then, we find the best |
| 2684 | // match (by distance) for each current pointer. |
| 2685 | PointerDistanceHeapElement heap[MAX_POINTERS * MAX_POINTERS]; |
| 2686 | |
| 2687 | uint32_t heapSize = 0; |
| 2688 | for (uint32_t currentPointerIndex = 0; currentPointerIndex < currentPointerCount; |
| 2689 | currentPointerIndex++) { |
| 2690 | for (uint32_t lastPointerIndex = 0; lastPointerIndex < lastPointerCount; |
| 2691 | lastPointerIndex++) { |
| 2692 | int64_t deltaX = mCurrentTouch.pointers[currentPointerIndex].x |
| 2693 | - mLastTouch.pointers[lastPointerIndex].x; |
| 2694 | int64_t deltaY = mCurrentTouch.pointers[currentPointerIndex].y |
| 2695 | - mLastTouch.pointers[lastPointerIndex].y; |
| 2696 | |
| 2697 | uint64_t distance = uint64_t(deltaX * deltaX + deltaY * deltaY); |
| 2698 | |
| 2699 | // Insert new element into the heap (sift up). |
| 2700 | heap[heapSize].currentPointerIndex = currentPointerIndex; |
| 2701 | heap[heapSize].lastPointerIndex = lastPointerIndex; |
| 2702 | heap[heapSize].distance = distance; |
| 2703 | heapSize += 1; |
| 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | // Heapify |
| 2708 | for (uint32_t startIndex = heapSize / 2; startIndex != 0; ) { |
| 2709 | startIndex -= 1; |
| 2710 | for (uint32_t parentIndex = startIndex; ;) { |
| 2711 | uint32_t childIndex = parentIndex * 2 + 1; |
| 2712 | if (childIndex >= heapSize) { |
| 2713 | break; |
| 2714 | } |
| 2715 | |
| 2716 | if (childIndex + 1 < heapSize |
| 2717 | && heap[childIndex + 1].distance < heap[childIndex].distance) { |
| 2718 | childIndex += 1; |
| 2719 | } |
| 2720 | |
| 2721 | if (heap[parentIndex].distance <= heap[childIndex].distance) { |
| 2722 | break; |
| 2723 | } |
| 2724 | |
| 2725 | swap(heap[parentIndex], heap[childIndex]); |
| 2726 | parentIndex = childIndex; |
| 2727 | } |
| 2728 | } |
| 2729 | |
| 2730 | #if DEBUG_POINTER_ASSIGNMENT |
| 2731 | LOGD("calculatePointerIds - initial distance min-heap: size=%d", heapSize); |
| 2732 | for (size_t i = 0; i < heapSize; i++) { |
| 2733 | LOGD(" heap[%d]: cur=%d, last=%d, distance=%lld", |
| 2734 | i, heap[i].currentPointerIndex, heap[i].lastPointerIndex, |
| 2735 | heap[i].distance); |
| 2736 | } |
| 2737 | #endif |
| 2738 | |
| 2739 | // Pull matches out by increasing order of distance. |
| 2740 | // To avoid reassigning pointers that have already been matched, the loop keeps track |
| 2741 | // of which last and current pointers have been matched using the matchedXXXBits variables. |
| 2742 | // It also tracks the used pointer id bits. |
| 2743 | BitSet32 matchedLastBits(0); |
| 2744 | BitSet32 matchedCurrentBits(0); |
| 2745 | BitSet32 usedIdBits(0); |
| 2746 | bool first = true; |
| 2747 | for (uint32_t i = min(currentPointerCount, lastPointerCount); i > 0; i--) { |
| 2748 | for (;;) { |
| 2749 | if (first) { |
| 2750 | // The first time through the loop, we just consume the root element of |
| 2751 | // the heap (the one with smallest distance). |
| 2752 | first = false; |
| 2753 | } else { |
| 2754 | // Previous iterations consumed the root element of the heap. |
| 2755 | // Pop root element off of the heap (sift down). |
| 2756 | heapSize -= 1; |
| 2757 | assert(heapSize > 0); |
| 2758 | |
| 2759 | // Sift down. |
| 2760 | heap[0] = heap[heapSize]; |
| 2761 | for (uint32_t parentIndex = 0; ;) { |
| 2762 | uint32_t childIndex = parentIndex * 2 + 1; |
| 2763 | if (childIndex >= heapSize) { |
| 2764 | break; |
| 2765 | } |
| 2766 | |
| 2767 | if (childIndex + 1 < heapSize |
| 2768 | && heap[childIndex + 1].distance < heap[childIndex].distance) { |
| 2769 | childIndex += 1; |
| 2770 | } |
| 2771 | |
| 2772 | if (heap[parentIndex].distance <= heap[childIndex].distance) { |
| 2773 | break; |
| 2774 | } |
| 2775 | |
| 2776 | swap(heap[parentIndex], heap[childIndex]); |
| 2777 | parentIndex = childIndex; |
| 2778 | } |
| 2779 | |
| 2780 | #if DEBUG_POINTER_ASSIGNMENT |
| 2781 | LOGD("calculatePointerIds - reduced distance min-heap: size=%d", heapSize); |
| 2782 | for (size_t i = 0; i < heapSize; i++) { |
| 2783 | LOGD(" heap[%d]: cur=%d, last=%d, distance=%lld", |
| 2784 | i, heap[i].currentPointerIndex, heap[i].lastPointerIndex, |
| 2785 | heap[i].distance); |
| 2786 | } |
| 2787 | #endif |
| 2788 | } |
| 2789 | |
| 2790 | uint32_t currentPointerIndex = heap[0].currentPointerIndex; |
| 2791 | if (matchedCurrentBits.hasBit(currentPointerIndex)) continue; // already matched |
| 2792 | |
| 2793 | uint32_t lastPointerIndex = heap[0].lastPointerIndex; |
| 2794 | if (matchedLastBits.hasBit(lastPointerIndex)) continue; // already matched |
| 2795 | |
| 2796 | matchedCurrentBits.markBit(currentPointerIndex); |
| 2797 | matchedLastBits.markBit(lastPointerIndex); |
| 2798 | |
| 2799 | uint32_t id = mLastTouch.pointers[lastPointerIndex].id; |
| 2800 | mCurrentTouch.pointers[currentPointerIndex].id = id; |
| 2801 | mCurrentTouch.idToIndex[id] = currentPointerIndex; |
| 2802 | usedIdBits.markBit(id); |
| 2803 | |
| 2804 | #if DEBUG_POINTER_ASSIGNMENT |
| 2805 | LOGD("calculatePointerIds - matched: cur=%d, last=%d, id=%d, distance=%lld", |
| 2806 | lastPointerIndex, currentPointerIndex, id, heap[0].distance); |
| 2807 | #endif |
| 2808 | break; |
| 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | // Assign fresh ids to new pointers. |
| 2813 | if (currentPointerCount > lastPointerCount) { |
| 2814 | for (uint32_t i = currentPointerCount - lastPointerCount; ;) { |
| 2815 | uint32_t currentPointerIndex = matchedCurrentBits.firstUnmarkedBit(); |
| 2816 | uint32_t id = usedIdBits.firstUnmarkedBit(); |
| 2817 | |
| 2818 | mCurrentTouch.pointers[currentPointerIndex].id = id; |
| 2819 | mCurrentTouch.idToIndex[id] = currentPointerIndex; |
| 2820 | usedIdBits.markBit(id); |
| 2821 | |
| 2822 | #if DEBUG_POINTER_ASSIGNMENT |
| 2823 | LOGD("calculatePointerIds - assigned: cur=%d, id=%d", |
| 2824 | currentPointerIndex, id); |
| 2825 | #endif |
| 2826 | |
| 2827 | if (--i == 0) break; // done |
| 2828 | matchedCurrentBits.markBit(currentPointerIndex); |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | // Fix id bits. |
| 2833 | mCurrentTouch.idBits = usedIdBits; |
| 2834 | } |
| 2835 | } |
| 2836 | |
| 2837 | /* Special hack for devices that have bad screen data: if one of the |
| 2838 | * points has moved more than a screen height from the last position, |
| 2839 | * then drop it. */ |
| 2840 | bool TouchInputMapper::applyBadTouchFilter() { |
| 2841 | // This hack requires valid axis parameters. |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2842 | if (! mRawAxes.y.valid) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2843 | return false; |
| 2844 | } |
| 2845 | |
| 2846 | uint32_t pointerCount = mCurrentTouch.pointerCount; |
| 2847 | |
| 2848 | // Nothing to do if there are no points. |
| 2849 | if (pointerCount == 0) { |
| 2850 | return false; |
| 2851 | } |
| 2852 | |
| 2853 | // Don't do anything if a finger is going down or up. We run |
| 2854 | // here before assigning pointer IDs, so there isn't a good |
| 2855 | // way to do per-finger matching. |
| 2856 | if (pointerCount != mLastTouch.pointerCount) { |
| 2857 | return false; |
| 2858 | } |
| 2859 | |
| 2860 | // We consider a single movement across more than a 7/16 of |
| 2861 | // the long size of the screen to be bad. This was a magic value |
| 2862 | // determined by looking at the maximum distance it is feasible |
| 2863 | // to actually move in one sample. |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2864 | int32_t maxDeltaY = mRawAxes.y.getRange() * 7 / 16; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2865 | |
| 2866 | // XXX The original code in InputDevice.java included commented out |
| 2867 | // code for testing the X axis. Note that when we drop a point |
| 2868 | // we don't actually restore the old X either. Strange. |
| 2869 | // The old code also tries to track when bad points were previously |
| 2870 | // detected but it turns out that due to the placement of a "break" |
| 2871 | // at the end of the loop, we never set mDroppedBadPoint to true |
| 2872 | // so it is effectively dead code. |
| 2873 | // Need to figure out if the old code is busted or just overcomplicated |
| 2874 | // but working as intended. |
| 2875 | |
| 2876 | // Look through all new points and see if any are farther than |
| 2877 | // acceptable from all previous points. |
| 2878 | for (uint32_t i = pointerCount; i-- > 0; ) { |
| 2879 | int32_t y = mCurrentTouch.pointers[i].y; |
| 2880 | int32_t closestY = INT_MAX; |
| 2881 | int32_t closestDeltaY = 0; |
| 2882 | |
| 2883 | #if DEBUG_HACKS |
| 2884 | LOGD("BadTouchFilter: Looking at next point #%d: y=%d", i, y); |
| 2885 | #endif |
| 2886 | |
| 2887 | for (uint32_t j = pointerCount; j-- > 0; ) { |
| 2888 | int32_t lastY = mLastTouch.pointers[j].y; |
| 2889 | int32_t deltaY = abs(y - lastY); |
| 2890 | |
| 2891 | #if DEBUG_HACKS |
| 2892 | LOGD("BadTouchFilter: Comparing with last point #%d: y=%d deltaY=%d", |
| 2893 | j, lastY, deltaY); |
| 2894 | #endif |
| 2895 | |
| 2896 | if (deltaY < maxDeltaY) { |
| 2897 | goto SkipSufficientlyClosePoint; |
| 2898 | } |
| 2899 | if (deltaY < closestDeltaY) { |
| 2900 | closestDeltaY = deltaY; |
| 2901 | closestY = lastY; |
| 2902 | } |
| 2903 | } |
| 2904 | |
| 2905 | // Must not have found a close enough match. |
| 2906 | #if DEBUG_HACKS |
| 2907 | LOGD("BadTouchFilter: Dropping bad point #%d: newY=%d oldY=%d deltaY=%d maxDeltaY=%d", |
| 2908 | i, y, closestY, closestDeltaY, maxDeltaY); |
| 2909 | #endif |
| 2910 | |
| 2911 | mCurrentTouch.pointers[i].y = closestY; |
| 2912 | return true; // XXX original code only corrects one point |
| 2913 | |
| 2914 | SkipSufficientlyClosePoint: ; |
| 2915 | } |
| 2916 | |
| 2917 | // No change. |
| 2918 | return false; |
| 2919 | } |
| 2920 | |
| 2921 | /* Special hack for devices that have bad screen data: drop points where |
| 2922 | * the coordinate value for one axis has jumped to the other pointer's location. |
| 2923 | */ |
| 2924 | bool TouchInputMapper::applyJumpyTouchFilter() { |
| 2925 | // This hack requires valid axis parameters. |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2926 | if (! mRawAxes.y.valid) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2927 | return false; |
| 2928 | } |
| 2929 | |
| 2930 | uint32_t pointerCount = mCurrentTouch.pointerCount; |
| 2931 | if (mLastTouch.pointerCount != pointerCount) { |
| 2932 | #if DEBUG_HACKS |
| 2933 | LOGD("JumpyTouchFilter: Different pointer count %d -> %d", |
| 2934 | mLastTouch.pointerCount, pointerCount); |
| 2935 | for (uint32_t i = 0; i < pointerCount; i++) { |
| 2936 | LOGD(" Pointer %d (%d, %d)", i, |
| 2937 | mCurrentTouch.pointers[i].x, mCurrentTouch.pointers[i].y); |
| 2938 | } |
| 2939 | #endif |
| 2940 | |
| 2941 | if (mJumpyTouchFilter.jumpyPointsDropped < JUMPY_TRANSITION_DROPS) { |
| 2942 | if (mLastTouch.pointerCount == 1 && pointerCount == 2) { |
| 2943 | // Just drop the first few events going from 1 to 2 pointers. |
| 2944 | // They're bad often enough that they're not worth considering. |
| 2945 | mCurrentTouch.pointerCount = 1; |
| 2946 | mJumpyTouchFilter.jumpyPointsDropped += 1; |
| 2947 | |
| 2948 | #if DEBUG_HACKS |
| 2949 | LOGD("JumpyTouchFilter: Pointer 2 dropped"); |
| 2950 | #endif |
| 2951 | return true; |
| 2952 | } else if (mLastTouch.pointerCount == 2 && pointerCount == 1) { |
| 2953 | // The event when we go from 2 -> 1 tends to be messed up too |
| 2954 | mCurrentTouch.pointerCount = 2; |
| 2955 | mCurrentTouch.pointers[0] = mLastTouch.pointers[0]; |
| 2956 | mCurrentTouch.pointers[1] = mLastTouch.pointers[1]; |
| 2957 | mJumpyTouchFilter.jumpyPointsDropped += 1; |
| 2958 | |
| 2959 | #if DEBUG_HACKS |
| 2960 | for (int32_t i = 0; i < 2; i++) { |
| 2961 | LOGD("JumpyTouchFilter: Pointer %d replaced (%d, %d)", i, |
| 2962 | mCurrentTouch.pointers[i].x, mCurrentTouch.pointers[i].y); |
| 2963 | } |
| 2964 | #endif |
| 2965 | return true; |
| 2966 | } |
| 2967 | } |
| 2968 | // Reset jumpy points dropped on other transitions or if limit exceeded. |
| 2969 | mJumpyTouchFilter.jumpyPointsDropped = 0; |
| 2970 | |
| 2971 | #if DEBUG_HACKS |
| 2972 | LOGD("JumpyTouchFilter: Transition - drop limit reset"); |
| 2973 | #endif |
| 2974 | return false; |
| 2975 | } |
| 2976 | |
| 2977 | // We have the same number of pointers as last time. |
| 2978 | // A 'jumpy' point is one where the coordinate value for one axis |
| 2979 | // has jumped to the other pointer's location. No need to do anything |
| 2980 | // else if we only have one pointer. |
| 2981 | if (pointerCount < 2) { |
| 2982 | return false; |
| 2983 | } |
| 2984 | |
| 2985 | if (mJumpyTouchFilter.jumpyPointsDropped < JUMPY_DROP_LIMIT) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2986 | int jumpyEpsilon = mRawAxes.y.getRange() / JUMPY_EPSILON_DIVISOR; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2987 | |
| 2988 | // We only replace the single worst jumpy point as characterized by pointer distance |
| 2989 | // in a single axis. |
| 2990 | int32_t badPointerIndex = -1; |
| 2991 | int32_t badPointerReplacementIndex = -1; |
| 2992 | int32_t badPointerDistance = INT_MIN; // distance to be corrected |
| 2993 | |
| 2994 | for (uint32_t i = pointerCount; i-- > 0; ) { |
| 2995 | int32_t x = mCurrentTouch.pointers[i].x; |
| 2996 | int32_t y = mCurrentTouch.pointers[i].y; |
| 2997 | |
| 2998 | #if DEBUG_HACKS |
| 2999 | LOGD("JumpyTouchFilter: Point %d (%d, %d)", i, x, y); |
| 3000 | #endif |
| 3001 | |
| 3002 | // Check if a touch point is too close to another's coordinates |
| 3003 | bool dropX = false, dropY = false; |
| 3004 | for (uint32_t j = 0; j < pointerCount; j++) { |
| 3005 | if (i == j) { |
| 3006 | continue; |
| 3007 | } |
| 3008 | |
| 3009 | if (abs(x - mCurrentTouch.pointers[j].x) <= jumpyEpsilon) { |
| 3010 | dropX = true; |
| 3011 | break; |
| 3012 | } |
| 3013 | |
| 3014 | if (abs(y - mCurrentTouch.pointers[j].y) <= jumpyEpsilon) { |
| 3015 | dropY = true; |
| 3016 | break; |
| 3017 | } |
| 3018 | } |
| 3019 | if (! dropX && ! dropY) { |
| 3020 | continue; // not jumpy |
| 3021 | } |
| 3022 | |
| 3023 | // Find a replacement candidate by comparing with older points on the |
| 3024 | // complementary (non-jumpy) axis. |
| 3025 | int32_t distance = INT_MIN; // distance to be corrected |
| 3026 | int32_t replacementIndex = -1; |
| 3027 | |
| 3028 | if (dropX) { |
| 3029 | // X looks too close. Find an older replacement point with a close Y. |
| 3030 | int32_t smallestDeltaY = INT_MAX; |
| 3031 | for (uint32_t j = 0; j < pointerCount; j++) { |
| 3032 | int32_t deltaY = abs(y - mLastTouch.pointers[j].y); |
| 3033 | if (deltaY < smallestDeltaY) { |
| 3034 | smallestDeltaY = deltaY; |
| 3035 | replacementIndex = j; |
| 3036 | } |
| 3037 | } |
| 3038 | distance = abs(x - mLastTouch.pointers[replacementIndex].x); |
| 3039 | } else { |
| 3040 | // Y looks too close. Find an older replacement point with a close X. |
| 3041 | int32_t smallestDeltaX = INT_MAX; |
| 3042 | for (uint32_t j = 0; j < pointerCount; j++) { |
| 3043 | int32_t deltaX = abs(x - mLastTouch.pointers[j].x); |
| 3044 | if (deltaX < smallestDeltaX) { |
| 3045 | smallestDeltaX = deltaX; |
| 3046 | replacementIndex = j; |
| 3047 | } |
| 3048 | } |
| 3049 | distance = abs(y - mLastTouch.pointers[replacementIndex].y); |
| 3050 | } |
| 3051 | |
| 3052 | // If replacing this pointer would correct a worse error than the previous ones |
| 3053 | // considered, then use this replacement instead. |
| 3054 | if (distance > badPointerDistance) { |
| 3055 | badPointerIndex = i; |
| 3056 | badPointerReplacementIndex = replacementIndex; |
| 3057 | badPointerDistance = distance; |
| 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | // Correct the jumpy pointer if one was found. |
| 3062 | if (badPointerIndex >= 0) { |
| 3063 | #if DEBUG_HACKS |
| 3064 | LOGD("JumpyTouchFilter: Replacing bad pointer %d with (%d, %d)", |
| 3065 | badPointerIndex, |
| 3066 | mLastTouch.pointers[badPointerReplacementIndex].x, |
| 3067 | mLastTouch.pointers[badPointerReplacementIndex].y); |
| 3068 | #endif |
| 3069 | |
| 3070 | mCurrentTouch.pointers[badPointerIndex].x = |
| 3071 | mLastTouch.pointers[badPointerReplacementIndex].x; |
| 3072 | mCurrentTouch.pointers[badPointerIndex].y = |
| 3073 | mLastTouch.pointers[badPointerReplacementIndex].y; |
| 3074 | mJumpyTouchFilter.jumpyPointsDropped += 1; |
| 3075 | return true; |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | mJumpyTouchFilter.jumpyPointsDropped = 0; |
| 3080 | return false; |
| 3081 | } |
| 3082 | |
| 3083 | /* Special hack for devices that have bad screen data: aggregate and |
| 3084 | * compute averages of the coordinate data, to reduce the amount of |
| 3085 | * jitter seen by applications. */ |
| 3086 | void TouchInputMapper::applyAveragingTouchFilter() { |
| 3087 | for (uint32_t currentIndex = 0; currentIndex < mCurrentTouch.pointerCount; currentIndex++) { |
| 3088 | uint32_t id = mCurrentTouch.pointers[currentIndex].id; |
| 3089 | int32_t x = mCurrentTouch.pointers[currentIndex].x; |
| 3090 | int32_t y = mCurrentTouch.pointers[currentIndex].y; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3091 | int32_t pressure; |
| 3092 | switch (mCalibration.pressureSource) { |
| 3093 | case Calibration::PRESSURE_SOURCE_PRESSURE: |
| 3094 | pressure = mCurrentTouch.pointers[currentIndex].pressure; |
| 3095 | break; |
| 3096 | case Calibration::PRESSURE_SOURCE_TOUCH: |
| 3097 | pressure = mCurrentTouch.pointers[currentIndex].touchMajor; |
| 3098 | break; |
| 3099 | default: |
| 3100 | pressure = 1; |
| 3101 | break; |
| 3102 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3103 | |
| 3104 | if (mLastTouch.idBits.hasBit(id)) { |
| 3105 | // Pointer was down before and is still down now. |
| 3106 | // Compute average over history trace. |
| 3107 | uint32_t start = mAveragingTouchFilter.historyStart[id]; |
| 3108 | uint32_t end = mAveragingTouchFilter.historyEnd[id]; |
| 3109 | |
| 3110 | int64_t deltaX = x - mAveragingTouchFilter.historyData[end].pointers[id].x; |
| 3111 | int64_t deltaY = y - mAveragingTouchFilter.historyData[end].pointers[id].y; |
| 3112 | uint64_t distance = uint64_t(deltaX * deltaX + deltaY * deltaY); |
| 3113 | |
| 3114 | #if DEBUG_HACKS |
| 3115 | LOGD("AveragingTouchFilter: Pointer id %d - Distance from last sample: %lld", |
| 3116 | id, distance); |
| 3117 | #endif |
| 3118 | |
| 3119 | if (distance < AVERAGING_DISTANCE_LIMIT) { |
| 3120 | // Increment end index in preparation for recording new historical data. |
| 3121 | end += 1; |
| 3122 | if (end > AVERAGING_HISTORY_SIZE) { |
| 3123 | end = 0; |
| 3124 | } |
| 3125 | |
| 3126 | // If the end index has looped back to the start index then we have filled |
| 3127 | // the historical trace up to the desired size so we drop the historical |
| 3128 | // data at the start of the trace. |
| 3129 | if (end == start) { |
| 3130 | start += 1; |
| 3131 | if (start > AVERAGING_HISTORY_SIZE) { |
| 3132 | start = 0; |
| 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | // Add the raw data to the historical trace. |
| 3137 | mAveragingTouchFilter.historyStart[id] = start; |
| 3138 | mAveragingTouchFilter.historyEnd[id] = end; |
| 3139 | mAveragingTouchFilter.historyData[end].pointers[id].x = x; |
| 3140 | mAveragingTouchFilter.historyData[end].pointers[id].y = y; |
| 3141 | mAveragingTouchFilter.historyData[end].pointers[id].pressure = pressure; |
| 3142 | |
| 3143 | // Average over all historical positions in the trace by total pressure. |
| 3144 | int32_t averagedX = 0; |
| 3145 | int32_t averagedY = 0; |
| 3146 | int32_t totalPressure = 0; |
| 3147 | for (;;) { |
| 3148 | int32_t historicalX = mAveragingTouchFilter.historyData[start].pointers[id].x; |
| 3149 | int32_t historicalY = mAveragingTouchFilter.historyData[start].pointers[id].y; |
| 3150 | int32_t historicalPressure = mAveragingTouchFilter.historyData[start] |
| 3151 | .pointers[id].pressure; |
| 3152 | |
| 3153 | averagedX += historicalX * historicalPressure; |
| 3154 | averagedY += historicalY * historicalPressure; |
| 3155 | totalPressure += historicalPressure; |
| 3156 | |
| 3157 | if (start == end) { |
| 3158 | break; |
| 3159 | } |
| 3160 | |
| 3161 | start += 1; |
| 3162 | if (start > AVERAGING_HISTORY_SIZE) { |
| 3163 | start = 0; |
| 3164 | } |
| 3165 | } |
| 3166 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3167 | if (totalPressure != 0) { |
| 3168 | averagedX /= totalPressure; |
| 3169 | averagedY /= totalPressure; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3170 | |
| 3171 | #if DEBUG_HACKS |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3172 | LOGD("AveragingTouchFilter: Pointer id %d - " |
| 3173 | "totalPressure=%d, averagedX=%d, averagedY=%d", id, totalPressure, |
| 3174 | averagedX, averagedY); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3175 | #endif |
| 3176 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3177 | mCurrentTouch.pointers[currentIndex].x = averagedX; |
| 3178 | mCurrentTouch.pointers[currentIndex].y = averagedY; |
| 3179 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3180 | } else { |
| 3181 | #if DEBUG_HACKS |
| 3182 | LOGD("AveragingTouchFilter: Pointer id %d - Exceeded max distance", id); |
| 3183 | #endif |
| 3184 | } |
| 3185 | } else { |
| 3186 | #if DEBUG_HACKS |
| 3187 | LOGD("AveragingTouchFilter: Pointer id %d - Pointer went up", id); |
| 3188 | #endif |
| 3189 | } |
| 3190 | |
| 3191 | // Reset pointer history. |
| 3192 | mAveragingTouchFilter.historyStart[id] = 0; |
| 3193 | mAveragingTouchFilter.historyEnd[id] = 0; |
| 3194 | mAveragingTouchFilter.historyData[0].pointers[id].x = x; |
| 3195 | mAveragingTouchFilter.historyData[0].pointers[id].y = y; |
| 3196 | mAveragingTouchFilter.historyData[0].pointers[id].pressure = pressure; |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | int32_t TouchInputMapper::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 3201 | { // acquire lock |
| 3202 | AutoMutex _l(mLock); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3203 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 3204 | if (mLocked.currentVirtualKey.down && mLocked.currentVirtualKey.keyCode == keyCode) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3205 | return AKEY_STATE_VIRTUAL; |
| 3206 | } |
| 3207 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 3208 | size_t numVirtualKeys = mLocked.virtualKeys.size(); |
| 3209 | for (size_t i = 0; i < numVirtualKeys; i++) { |
| 3210 | const VirtualKey& virtualKey = mLocked.virtualKeys[i]; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3211 | if (virtualKey.keyCode == keyCode) { |
| 3212 | return AKEY_STATE_UP; |
| 3213 | } |
| 3214 | } |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 3215 | } // release lock |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3216 | |
| 3217 | return AKEY_STATE_UNKNOWN; |
| 3218 | } |
| 3219 | |
| 3220 | int32_t TouchInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 3221 | { // acquire lock |
| 3222 | AutoMutex _l(mLock); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3223 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 3224 | if (mLocked.currentVirtualKey.down && mLocked.currentVirtualKey.scanCode == scanCode) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3225 | return AKEY_STATE_VIRTUAL; |
| 3226 | } |
| 3227 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 3228 | size_t numVirtualKeys = mLocked.virtualKeys.size(); |
| 3229 | for (size_t i = 0; i < numVirtualKeys; i++) { |
| 3230 | const VirtualKey& virtualKey = mLocked.virtualKeys[i]; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3231 | if (virtualKey.scanCode == scanCode) { |
| 3232 | return AKEY_STATE_UP; |
| 3233 | } |
| 3234 | } |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 3235 | } // release lock |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3236 | |
| 3237 | return AKEY_STATE_UNKNOWN; |
| 3238 | } |
| 3239 | |
| 3240 | bool TouchInputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 3241 | const int32_t* keyCodes, uint8_t* outFlags) { |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 3242 | { // acquire lock |
| 3243 | AutoMutex _l(mLock); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3244 | |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 3245 | size_t numVirtualKeys = mLocked.virtualKeys.size(); |
| 3246 | for (size_t i = 0; i < numVirtualKeys; i++) { |
| 3247 | const VirtualKey& virtualKey = mLocked.virtualKeys[i]; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3248 | |
| 3249 | for (size_t i = 0; i < numCodes; i++) { |
| 3250 | if (virtualKey.keyCode == keyCodes[i]) { |
| 3251 | outFlags[i] = 1; |
| 3252 | } |
| 3253 | } |
| 3254 | } |
Jeff Brown | 6328cdc | 2010-07-29 18:18:33 -0700 | [diff] [blame] | 3255 | } // release lock |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3256 | |
| 3257 | return true; |
| 3258 | } |
| 3259 | |
| 3260 | |
| 3261 | // --- SingleTouchInputMapper --- |
| 3262 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 3263 | SingleTouchInputMapper::SingleTouchInputMapper(InputDevice* device) : |
| 3264 | TouchInputMapper(device) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3265 | initialize(); |
| 3266 | } |
| 3267 | |
| 3268 | SingleTouchInputMapper::~SingleTouchInputMapper() { |
| 3269 | } |
| 3270 | |
| 3271 | void SingleTouchInputMapper::initialize() { |
| 3272 | mAccumulator.clear(); |
| 3273 | |
| 3274 | mDown = false; |
| 3275 | mX = 0; |
| 3276 | mY = 0; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3277 | mPressure = 0; // default to 0 for devices that don't report pressure |
| 3278 | mToolWidth = 0; // default to 0 for devices that don't report tool width |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | void SingleTouchInputMapper::reset() { |
| 3282 | TouchInputMapper::reset(); |
| 3283 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3284 | initialize(); |
| 3285 | } |
| 3286 | |
| 3287 | void SingleTouchInputMapper::process(const RawEvent* rawEvent) { |
| 3288 | switch (rawEvent->type) { |
| 3289 | case EV_KEY: |
| 3290 | switch (rawEvent->scanCode) { |
| 3291 | case BTN_TOUCH: |
| 3292 | mAccumulator.fields |= Accumulator::FIELD_BTN_TOUCH; |
| 3293 | mAccumulator.btnTouch = rawEvent->value != 0; |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3294 | // Don't sync immediately. Wait until the next SYN_REPORT since we might |
| 3295 | // not have received valid position information yet. This logic assumes that |
| 3296 | // BTN_TOUCH is always followed by SYN_REPORT as part of a complete packet. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3297 | break; |
| 3298 | } |
| 3299 | break; |
| 3300 | |
| 3301 | case EV_ABS: |
| 3302 | switch (rawEvent->scanCode) { |
| 3303 | case ABS_X: |
| 3304 | mAccumulator.fields |= Accumulator::FIELD_ABS_X; |
| 3305 | mAccumulator.absX = rawEvent->value; |
| 3306 | break; |
| 3307 | case ABS_Y: |
| 3308 | mAccumulator.fields |= Accumulator::FIELD_ABS_Y; |
| 3309 | mAccumulator.absY = rawEvent->value; |
| 3310 | break; |
| 3311 | case ABS_PRESSURE: |
| 3312 | mAccumulator.fields |= Accumulator::FIELD_ABS_PRESSURE; |
| 3313 | mAccumulator.absPressure = rawEvent->value; |
| 3314 | break; |
| 3315 | case ABS_TOOL_WIDTH: |
| 3316 | mAccumulator.fields |= Accumulator::FIELD_ABS_TOOL_WIDTH; |
| 3317 | mAccumulator.absToolWidth = rawEvent->value; |
| 3318 | break; |
| 3319 | } |
| 3320 | break; |
| 3321 | |
| 3322 | case EV_SYN: |
| 3323 | switch (rawEvent->scanCode) { |
| 3324 | case SYN_REPORT: |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3325 | sync(rawEvent->when); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3326 | break; |
| 3327 | } |
| 3328 | break; |
| 3329 | } |
| 3330 | } |
| 3331 | |
| 3332 | void SingleTouchInputMapper::sync(nsecs_t when) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3333 | uint32_t fields = mAccumulator.fields; |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3334 | if (fields == 0) { |
| 3335 | return; // no new state changes, so nothing to do |
| 3336 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3337 | |
| 3338 | if (fields & Accumulator::FIELD_BTN_TOUCH) { |
| 3339 | mDown = mAccumulator.btnTouch; |
| 3340 | } |
| 3341 | |
| 3342 | if (fields & Accumulator::FIELD_ABS_X) { |
| 3343 | mX = mAccumulator.absX; |
| 3344 | } |
| 3345 | |
| 3346 | if (fields & Accumulator::FIELD_ABS_Y) { |
| 3347 | mY = mAccumulator.absY; |
| 3348 | } |
| 3349 | |
| 3350 | if (fields & Accumulator::FIELD_ABS_PRESSURE) { |
| 3351 | mPressure = mAccumulator.absPressure; |
| 3352 | } |
| 3353 | |
| 3354 | if (fields & Accumulator::FIELD_ABS_TOOL_WIDTH) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3355 | mToolWidth = mAccumulator.absToolWidth; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | mCurrentTouch.clear(); |
| 3359 | |
| 3360 | if (mDown) { |
| 3361 | mCurrentTouch.pointerCount = 1; |
| 3362 | mCurrentTouch.pointers[0].id = 0; |
| 3363 | mCurrentTouch.pointers[0].x = mX; |
| 3364 | mCurrentTouch.pointers[0].y = mY; |
| 3365 | mCurrentTouch.pointers[0].pressure = mPressure; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3366 | mCurrentTouch.pointers[0].touchMajor = 0; |
| 3367 | mCurrentTouch.pointers[0].touchMinor = 0; |
| 3368 | mCurrentTouch.pointers[0].toolMajor = mToolWidth; |
| 3369 | mCurrentTouch.pointers[0].toolMinor = mToolWidth; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3370 | mCurrentTouch.pointers[0].orientation = 0; |
| 3371 | mCurrentTouch.idToIndex[0] = 0; |
| 3372 | mCurrentTouch.idBits.markBit(0); |
| 3373 | } |
| 3374 | |
| 3375 | syncTouch(when, true); |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3376 | |
| 3377 | mAccumulator.clear(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3378 | } |
| 3379 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3380 | void SingleTouchInputMapper::configureRawAxes() { |
| 3381 | TouchInputMapper::configureRawAxes(); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3382 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3383 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_X, & mRawAxes.x); |
| 3384 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_Y, & mRawAxes.y); |
| 3385 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_PRESSURE, & mRawAxes.pressure); |
| 3386 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_TOOL_WIDTH, & mRawAxes.toolMajor); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | |
| 3390 | // --- MultiTouchInputMapper --- |
| 3391 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 3392 | MultiTouchInputMapper::MultiTouchInputMapper(InputDevice* device) : |
| 3393 | TouchInputMapper(device) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3394 | initialize(); |
| 3395 | } |
| 3396 | |
| 3397 | MultiTouchInputMapper::~MultiTouchInputMapper() { |
| 3398 | } |
| 3399 | |
| 3400 | void MultiTouchInputMapper::initialize() { |
| 3401 | mAccumulator.clear(); |
| 3402 | } |
| 3403 | |
| 3404 | void MultiTouchInputMapper::reset() { |
| 3405 | TouchInputMapper::reset(); |
| 3406 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3407 | initialize(); |
| 3408 | } |
| 3409 | |
| 3410 | void MultiTouchInputMapper::process(const RawEvent* rawEvent) { |
| 3411 | switch (rawEvent->type) { |
| 3412 | case EV_ABS: { |
| 3413 | uint32_t pointerIndex = mAccumulator.pointerCount; |
| 3414 | Accumulator::Pointer* pointer = & mAccumulator.pointers[pointerIndex]; |
| 3415 | |
| 3416 | switch (rawEvent->scanCode) { |
| 3417 | case ABS_MT_POSITION_X: |
| 3418 | pointer->fields |= Accumulator::FIELD_ABS_MT_POSITION_X; |
| 3419 | pointer->absMTPositionX = rawEvent->value; |
| 3420 | break; |
| 3421 | case ABS_MT_POSITION_Y: |
| 3422 | pointer->fields |= Accumulator::FIELD_ABS_MT_POSITION_Y; |
| 3423 | pointer->absMTPositionY = rawEvent->value; |
| 3424 | break; |
| 3425 | case ABS_MT_TOUCH_MAJOR: |
| 3426 | pointer->fields |= Accumulator::FIELD_ABS_MT_TOUCH_MAJOR; |
| 3427 | pointer->absMTTouchMajor = rawEvent->value; |
| 3428 | break; |
| 3429 | case ABS_MT_TOUCH_MINOR: |
| 3430 | pointer->fields |= Accumulator::FIELD_ABS_MT_TOUCH_MINOR; |
| 3431 | pointer->absMTTouchMinor = rawEvent->value; |
| 3432 | break; |
| 3433 | case ABS_MT_WIDTH_MAJOR: |
| 3434 | pointer->fields |= Accumulator::FIELD_ABS_MT_WIDTH_MAJOR; |
| 3435 | pointer->absMTWidthMajor = rawEvent->value; |
| 3436 | break; |
| 3437 | case ABS_MT_WIDTH_MINOR: |
| 3438 | pointer->fields |= Accumulator::FIELD_ABS_MT_WIDTH_MINOR; |
| 3439 | pointer->absMTWidthMinor = rawEvent->value; |
| 3440 | break; |
| 3441 | case ABS_MT_ORIENTATION: |
| 3442 | pointer->fields |= Accumulator::FIELD_ABS_MT_ORIENTATION; |
| 3443 | pointer->absMTOrientation = rawEvent->value; |
| 3444 | break; |
| 3445 | case ABS_MT_TRACKING_ID: |
| 3446 | pointer->fields |= Accumulator::FIELD_ABS_MT_TRACKING_ID; |
| 3447 | pointer->absMTTrackingId = rawEvent->value; |
| 3448 | break; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3449 | case ABS_MT_PRESSURE: |
| 3450 | pointer->fields |= Accumulator::FIELD_ABS_MT_PRESSURE; |
| 3451 | pointer->absMTPressure = rawEvent->value; |
| 3452 | break; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3453 | } |
| 3454 | break; |
| 3455 | } |
| 3456 | |
| 3457 | case EV_SYN: |
| 3458 | switch (rawEvent->scanCode) { |
| 3459 | case SYN_MT_REPORT: { |
| 3460 | // MultiTouch Sync: The driver has returned all data for *one* of the pointers. |
| 3461 | uint32_t pointerIndex = mAccumulator.pointerCount; |
| 3462 | |
| 3463 | if (mAccumulator.pointers[pointerIndex].fields) { |
| 3464 | if (pointerIndex == MAX_POINTERS) { |
| 3465 | LOGW("MultiTouch device driver returned more than maximum of %d pointers.", |
| 3466 | MAX_POINTERS); |
| 3467 | } else { |
| 3468 | pointerIndex += 1; |
| 3469 | mAccumulator.pointerCount = pointerIndex; |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | mAccumulator.pointers[pointerIndex].clear(); |
| 3474 | break; |
| 3475 | } |
| 3476 | |
| 3477 | case SYN_REPORT: |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3478 | sync(rawEvent->when); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3479 | break; |
| 3480 | } |
| 3481 | break; |
| 3482 | } |
| 3483 | } |
| 3484 | |
| 3485 | void MultiTouchInputMapper::sync(nsecs_t when) { |
| 3486 | static const uint32_t REQUIRED_FIELDS = |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3487 | Accumulator::FIELD_ABS_MT_POSITION_X | Accumulator::FIELD_ABS_MT_POSITION_Y; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3488 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3489 | uint32_t inCount = mAccumulator.pointerCount; |
| 3490 | uint32_t outCount = 0; |
| 3491 | bool havePointerIds = true; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3492 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3493 | mCurrentTouch.clear(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3494 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3495 | for (uint32_t inIndex = 0; inIndex < inCount; inIndex++) { |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3496 | const Accumulator::Pointer& inPointer = mAccumulator.pointers[inIndex]; |
| 3497 | uint32_t fields = inPointer.fields; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3498 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3499 | if ((fields & REQUIRED_FIELDS) != REQUIRED_FIELDS) { |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3500 | // Some drivers send empty MT sync packets without X / Y to indicate a pointer up. |
| 3501 | // Drop this finger. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3502 | continue; |
| 3503 | } |
| 3504 | |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3505 | PointerData& outPointer = mCurrentTouch.pointers[outCount]; |
| 3506 | outPointer.x = inPointer.absMTPositionX; |
| 3507 | outPointer.y = inPointer.absMTPositionY; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3508 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3509 | if (fields & Accumulator::FIELD_ABS_MT_PRESSURE) { |
| 3510 | if (inPointer.absMTPressure <= 0) { |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 3511 | // Some devices send sync packets with X / Y but with a 0 pressure to indicate |
| 3512 | // a pointer going up. Drop this finger. |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3513 | continue; |
| 3514 | } |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3515 | outPointer.pressure = inPointer.absMTPressure; |
| 3516 | } else { |
| 3517 | // Default pressure to 0 if absent. |
| 3518 | outPointer.pressure = 0; |
| 3519 | } |
| 3520 | |
| 3521 | if (fields & Accumulator::FIELD_ABS_MT_TOUCH_MAJOR) { |
| 3522 | if (inPointer.absMTTouchMajor <= 0) { |
| 3523 | // Some devices send sync packets with X / Y but with a 0 touch major to indicate |
| 3524 | // a pointer going up. Drop this finger. |
| 3525 | continue; |
| 3526 | } |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3527 | outPointer.touchMajor = inPointer.absMTTouchMajor; |
| 3528 | } else { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3529 | // Default touch area to 0 if absent. |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3530 | outPointer.touchMajor = 0; |
| 3531 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3532 | |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3533 | if (fields & Accumulator::FIELD_ABS_MT_TOUCH_MINOR) { |
| 3534 | outPointer.touchMinor = inPointer.absMTTouchMinor; |
| 3535 | } else { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3536 | // Assume touch area is circular. |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3537 | outPointer.touchMinor = outPointer.touchMajor; |
| 3538 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3539 | |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3540 | if (fields & Accumulator::FIELD_ABS_MT_WIDTH_MAJOR) { |
| 3541 | outPointer.toolMajor = inPointer.absMTWidthMajor; |
| 3542 | } else { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3543 | // Default tool area to 0 if absent. |
| 3544 | outPointer.toolMajor = 0; |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3545 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3546 | |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3547 | if (fields & Accumulator::FIELD_ABS_MT_WIDTH_MINOR) { |
| 3548 | outPointer.toolMinor = inPointer.absMTWidthMinor; |
| 3549 | } else { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3550 | // Assume tool area is circular. |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3551 | outPointer.toolMinor = outPointer.toolMajor; |
| 3552 | } |
| 3553 | |
| 3554 | if (fields & Accumulator::FIELD_ABS_MT_ORIENTATION) { |
| 3555 | outPointer.orientation = inPointer.absMTOrientation; |
| 3556 | } else { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3557 | // Default orientation to vertical if absent. |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3558 | outPointer.orientation = 0; |
| 3559 | } |
| 3560 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3561 | // Assign pointer id using tracking id if available. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3562 | if (havePointerIds) { |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3563 | if (fields & Accumulator::FIELD_ABS_MT_TRACKING_ID) { |
| 3564 | uint32_t id = uint32_t(inPointer.absMTTrackingId); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3565 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3566 | if (id > MAX_POINTER_ID) { |
| 3567 | #if DEBUG_POINTERS |
| 3568 | LOGD("Pointers: Ignoring driver provided pointer id %d because " |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 3569 | "it is larger than max supported id %d", |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3570 | id, MAX_POINTER_ID); |
| 3571 | #endif |
| 3572 | havePointerIds = false; |
| 3573 | } |
| 3574 | else { |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3575 | outPointer.id = id; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3576 | mCurrentTouch.idToIndex[id] = outCount; |
| 3577 | mCurrentTouch.idBits.markBit(id); |
| 3578 | } |
| 3579 | } else { |
| 3580 | havePointerIds = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3581 | } |
| 3582 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3583 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3584 | outCount += 1; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3587 | mCurrentTouch.pointerCount = outCount; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3588 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3589 | syncTouch(when, havePointerIds); |
Jeff Brown | 2dfd7a7 | 2010-08-17 20:38:35 -0700 | [diff] [blame] | 3590 | |
| 3591 | mAccumulator.clear(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3594 | void MultiTouchInputMapper::configureRawAxes() { |
| 3595 | TouchInputMapper::configureRawAxes(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3596 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 3597 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_MT_POSITION_X, & mRawAxes.x); |
| 3598 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_MT_POSITION_Y, & mRawAxes.y); |
| 3599 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_MT_TOUCH_MAJOR, & mRawAxes.touchMajor); |
| 3600 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_MT_TOUCH_MINOR, & mRawAxes.touchMinor); |
| 3601 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_MT_WIDTH_MAJOR, & mRawAxes.toolMajor); |
| 3602 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_MT_WIDTH_MINOR, & mRawAxes.toolMinor); |
| 3603 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_MT_ORIENTATION, & mRawAxes.orientation); |
| 3604 | getEventHub()->getAbsoluteAxisInfo(getDeviceId(), ABS_MT_PRESSURE, & mRawAxes.pressure); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3607 | |
| 3608 | } // namespace android |