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