Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -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 | |
| 17 | #ifndef _UI_INPUT_READER_H |
| 18 | #define _UI_INPUT_READER_H |
| 19 | |
| 20 | #include "EventHub.h" |
| 21 | #include "PointerControllerInterface.h" |
| 22 | #include "InputListener.h" |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 23 | #include "InputReaderBase.h" |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 24 | |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 25 | #include <input/DisplayViewport.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 26 | #include <input/Input.h> |
| 27 | #include <input/VelocityControl.h> |
| 28 | #include <input/VelocityTracker.h> |
| 29 | #include <ui/DisplayInfo.h> |
| 30 | #include <utils/KeyedVector.h> |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 31 | #include <utils/Condition.h> |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 32 | #include <utils/Mutex.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 33 | #include <utils/Timers.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 34 | #include <utils/BitSet.h> |
| 35 | |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 36 | #include <optional> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 37 | #include <stddef.h> |
| 38 | #include <unistd.h> |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 39 | #include <vector> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 40 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 41 | namespace android { |
| 42 | |
| 43 | class InputDevice; |
| 44 | class InputMapper; |
| 45 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 46 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 47 | struct StylusState { |
| 48 | /* Time the stylus event was received. */ |
| 49 | nsecs_t when; |
| 50 | /* Pressure as reported by the stylus, normalized to the range [0, 1.0]. */ |
| 51 | float pressure; |
| 52 | /* The state of the stylus buttons as a bitfield (e.g. AMOTION_EVENT_BUTTON_SECONDARY). */ |
| 53 | uint32_t buttons; |
| 54 | /* Which tool type the stylus is currently using (e.g. AMOTION_EVENT_TOOL_TYPE_ERASER). */ |
| 55 | int32_t toolType; |
| 56 | |
| 57 | void copyFrom(const StylusState& other) { |
| 58 | when = other.when; |
| 59 | pressure = other.pressure; |
| 60 | buttons = other.buttons; |
| 61 | toolType = other.toolType; |
| 62 | } |
| 63 | |
| 64 | void clear() { |
| 65 | when = LLONG_MAX; |
| 66 | pressure = 0.f; |
| 67 | buttons = 0; |
| 68 | toolType = AMOTION_EVENT_TOOL_TYPE_UNKNOWN; |
| 69 | } |
| 70 | }; |
| 71 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 72 | |
| 73 | /* Internal interface used by individual input devices to access global input device state |
| 74 | * and parameters maintained by the input reader. |
| 75 | */ |
| 76 | class InputReaderContext { |
| 77 | public: |
| 78 | InputReaderContext() { } |
| 79 | virtual ~InputReaderContext() { } |
| 80 | |
| 81 | virtual void updateGlobalMetaState() = 0; |
| 82 | virtual int32_t getGlobalMetaState() = 0; |
| 83 | |
| 84 | virtual void disableVirtualKeysUntil(nsecs_t time) = 0; |
| 85 | virtual bool shouldDropVirtualKey(nsecs_t now, |
| 86 | InputDevice* device, int32_t keyCode, int32_t scanCode) = 0; |
| 87 | |
| 88 | virtual void fadePointer() = 0; |
| 89 | |
| 90 | virtual void requestTimeoutAtTime(nsecs_t when) = 0; |
| 91 | virtual int32_t bumpGeneration() = 0; |
| 92 | |
Michael Wright | b85401d | 2015-04-17 18:35:15 +0100 | [diff] [blame] | 93 | virtual void getExternalStylusDevices(Vector<InputDeviceInfo>& outDevices) = 0; |
| 94 | virtual void dispatchExternalStylusState(const StylusState& outState) = 0; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 95 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 96 | virtual InputReaderPolicyInterface* getPolicy() = 0; |
| 97 | virtual InputListenerInterface* getListener() = 0; |
| 98 | virtual EventHubInterface* getEventHub() = 0; |
| 99 | }; |
| 100 | |
| 101 | |
| 102 | /* The input reader reads raw event data from the event hub and processes it into input events |
| 103 | * that it sends to the input listener. Some functions of the input reader, such as early |
| 104 | * event filtering in low power states, are controlled by a separate policy object. |
| 105 | * |
| 106 | * The InputReader owns a collection of InputMappers. Most of the work it does happens |
| 107 | * on the input reader thread but the InputReader can receive queries from other system |
| 108 | * components running on arbitrary threads. To keep things manageable, the InputReader |
| 109 | * uses a single Mutex to guard its state. The Mutex may be held while calling into the |
| 110 | * EventHub or the InputReaderPolicy but it is never held while calling into the |
| 111 | * InputListener. |
| 112 | */ |
| 113 | class InputReader : public InputReaderInterface { |
| 114 | public: |
| 115 | InputReader(const sp<EventHubInterface>& eventHub, |
| 116 | const sp<InputReaderPolicyInterface>& policy, |
| 117 | const sp<InputListenerInterface>& listener); |
| 118 | virtual ~InputReader(); |
| 119 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 120 | virtual void dump(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 121 | virtual void monitor(); |
| 122 | |
| 123 | virtual void loopOnce(); |
| 124 | |
| 125 | virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices); |
| 126 | |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 127 | virtual bool isInputDeviceEnabled(int32_t deviceId); |
| 128 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 129 | virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, |
| 130 | int32_t scanCode); |
| 131 | virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, |
| 132 | int32_t keyCode); |
| 133 | virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, |
| 134 | int32_t sw); |
| 135 | |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 136 | virtual void toggleCapsLockState(int32_t deviceId); |
| 137 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 138 | virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 139 | size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags); |
| 140 | |
| 141 | virtual void requestRefreshConfiguration(uint32_t changes); |
| 142 | |
| 143 | virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize, |
| 144 | ssize_t repeat, int32_t token); |
| 145 | virtual void cancelVibrate(int32_t deviceId, int32_t token); |
| 146 | |
| 147 | protected: |
| 148 | // These members are protected so they can be instrumented by test cases. |
| 149 | virtual InputDevice* createDeviceLocked(int32_t deviceId, int32_t controllerNumber, |
| 150 | const InputDeviceIdentifier& identifier, uint32_t classes); |
| 151 | |
| 152 | class ContextImpl : public InputReaderContext { |
| 153 | InputReader* mReader; |
| 154 | |
| 155 | public: |
Chih-Hung Hsieh | 6d2ede1 | 2016-09-01 11:28:23 -0700 | [diff] [blame] | 156 | explicit ContextImpl(InputReader* reader); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 157 | |
| 158 | virtual void updateGlobalMetaState(); |
| 159 | virtual int32_t getGlobalMetaState(); |
| 160 | virtual void disableVirtualKeysUntil(nsecs_t time); |
| 161 | virtual bool shouldDropVirtualKey(nsecs_t now, |
| 162 | InputDevice* device, int32_t keyCode, int32_t scanCode); |
| 163 | virtual void fadePointer(); |
| 164 | virtual void requestTimeoutAtTime(nsecs_t when); |
| 165 | virtual int32_t bumpGeneration(); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 166 | virtual void getExternalStylusDevices(Vector<InputDeviceInfo>& outDevices); |
| 167 | virtual void dispatchExternalStylusState(const StylusState& outState); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 168 | virtual InputReaderPolicyInterface* getPolicy(); |
| 169 | virtual InputListenerInterface* getListener(); |
| 170 | virtual EventHubInterface* getEventHub(); |
| 171 | } mContext; |
| 172 | |
| 173 | friend class ContextImpl; |
| 174 | |
| 175 | private: |
| 176 | Mutex mLock; |
| 177 | |
| 178 | Condition mReaderIsAliveCondition; |
| 179 | |
| 180 | sp<EventHubInterface> mEventHub; |
| 181 | sp<InputReaderPolicyInterface> mPolicy; |
| 182 | sp<QueuedInputListener> mQueuedListener; |
| 183 | |
| 184 | InputReaderConfiguration mConfig; |
| 185 | |
| 186 | // The event queue. |
| 187 | static const int EVENT_BUFFER_SIZE = 256; |
| 188 | RawEvent mEventBuffer[EVENT_BUFFER_SIZE]; |
| 189 | |
| 190 | KeyedVector<int32_t, InputDevice*> mDevices; |
| 191 | |
| 192 | // low-level input event decoding and device management |
| 193 | void processEventsLocked(const RawEvent* rawEvents, size_t count); |
| 194 | |
| 195 | void addDeviceLocked(nsecs_t when, int32_t deviceId); |
| 196 | void removeDeviceLocked(nsecs_t when, int32_t deviceId); |
| 197 | void processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, size_t count); |
| 198 | void timeoutExpiredLocked(nsecs_t when); |
| 199 | |
| 200 | void handleConfigurationChangedLocked(nsecs_t when); |
| 201 | |
| 202 | int32_t mGlobalMetaState; |
| 203 | void updateGlobalMetaStateLocked(); |
| 204 | int32_t getGlobalMetaStateLocked(); |
| 205 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 206 | void notifyExternalStylusPresenceChanged(); |
| 207 | void getExternalStylusDevicesLocked(Vector<InputDeviceInfo>& outDevices); |
| 208 | void dispatchExternalStylusState(const StylusState& state); |
| 209 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 210 | void fadePointerLocked(); |
| 211 | |
| 212 | int32_t mGeneration; |
| 213 | int32_t bumpGenerationLocked(); |
| 214 | |
| 215 | void getInputDevicesLocked(Vector<InputDeviceInfo>& outInputDevices); |
| 216 | |
| 217 | nsecs_t mDisableVirtualKeysTimeout; |
| 218 | void disableVirtualKeysUntilLocked(nsecs_t time); |
| 219 | bool shouldDropVirtualKeyLocked(nsecs_t now, |
| 220 | InputDevice* device, int32_t keyCode, int32_t scanCode); |
| 221 | |
| 222 | nsecs_t mNextTimeout; |
| 223 | void requestTimeoutAtTimeLocked(nsecs_t when); |
| 224 | |
| 225 | uint32_t mConfigurationChangesToRefresh; |
| 226 | void refreshConfigurationLocked(uint32_t changes); |
| 227 | |
| 228 | // state queries |
| 229 | typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code); |
| 230 | int32_t getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code, |
| 231 | GetStateFunc getStateFunc); |
| 232 | bool markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, size_t numCodes, |
| 233 | const int32_t* keyCodes, uint8_t* outFlags); |
| 234 | }; |
| 235 | |
| 236 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 237 | /* Represents the state of a single input device. */ |
| 238 | class InputDevice { |
| 239 | public: |
| 240 | InputDevice(InputReaderContext* context, int32_t id, int32_t generation, int32_t |
| 241 | controllerNumber, const InputDeviceIdentifier& identifier, uint32_t classes); |
| 242 | ~InputDevice(); |
| 243 | |
| 244 | inline InputReaderContext* getContext() { return mContext; } |
| 245 | inline int32_t getId() const { return mId; } |
| 246 | inline int32_t getControllerNumber() const { return mControllerNumber; } |
| 247 | inline int32_t getGeneration() const { return mGeneration; } |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 248 | inline const std::string getName() const { return mIdentifier.name; } |
| 249 | inline const std::string getDescriptor() { return mIdentifier.descriptor; } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 250 | inline uint32_t getClasses() const { return mClasses; } |
| 251 | inline uint32_t getSources() const { return mSources; } |
| 252 | |
| 253 | inline bool isExternal() { return mIsExternal; } |
| 254 | inline void setExternal(bool external) { mIsExternal = external; } |
| 255 | |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 256 | inline void setMic(bool hasMic) { mHasMic = hasMic; } |
| 257 | inline bool hasMic() const { return mHasMic; } |
| 258 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 259 | inline bool isIgnored() { return mMappers.isEmpty(); } |
| 260 | |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 261 | bool isEnabled(); |
| 262 | void setEnabled(bool enabled, nsecs_t when); |
| 263 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 264 | void dump(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 265 | void addMapper(InputMapper* mapper); |
| 266 | void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 267 | void reset(nsecs_t when); |
| 268 | void process(const RawEvent* rawEvents, size_t count); |
| 269 | void timeoutExpired(nsecs_t when); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 270 | void updateExternalStylusState(const StylusState& state); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 271 | |
| 272 | void getDeviceInfo(InputDeviceInfo* outDeviceInfo); |
| 273 | int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 274 | int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 275 | int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 276 | bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 277 | const int32_t* keyCodes, uint8_t* outFlags); |
| 278 | void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token); |
| 279 | void cancelVibrate(int32_t token); |
Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 280 | void cancelTouch(nsecs_t when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 281 | |
| 282 | int32_t getMetaState(); |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 283 | void updateMetaState(int32_t keyCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 284 | |
| 285 | void fadePointer(); |
| 286 | |
| 287 | void bumpGeneration(); |
| 288 | |
| 289 | void notifyReset(nsecs_t when); |
| 290 | |
| 291 | inline const PropertyMap& getConfiguration() { return mConfiguration; } |
| 292 | inline EventHubInterface* getEventHub() { return mContext->getEventHub(); } |
| 293 | |
| 294 | bool hasKey(int32_t code) { |
| 295 | return getEventHub()->hasScanCode(mId, code); |
| 296 | } |
| 297 | |
| 298 | bool hasAbsoluteAxis(int32_t code) { |
| 299 | RawAbsoluteAxisInfo info; |
| 300 | getEventHub()->getAbsoluteAxisInfo(mId, code, &info); |
| 301 | return info.valid; |
| 302 | } |
| 303 | |
| 304 | bool isKeyPressed(int32_t code) { |
| 305 | return getEventHub()->getScanCodeState(mId, code) == AKEY_STATE_DOWN; |
| 306 | } |
| 307 | |
| 308 | int32_t getAbsoluteAxisValue(int32_t code) { |
| 309 | int32_t value; |
| 310 | getEventHub()->getAbsoluteAxisValue(mId, code, &value); |
| 311 | return value; |
| 312 | } |
| 313 | |
| 314 | private: |
| 315 | InputReaderContext* mContext; |
| 316 | int32_t mId; |
| 317 | int32_t mGeneration; |
| 318 | int32_t mControllerNumber; |
| 319 | InputDeviceIdentifier mIdentifier; |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 320 | std::string mAlias; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 321 | uint32_t mClasses; |
| 322 | |
| 323 | Vector<InputMapper*> mMappers; |
| 324 | |
| 325 | uint32_t mSources; |
| 326 | bool mIsExternal; |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 327 | bool mHasMic; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 328 | bool mDropUntilNextSync; |
| 329 | |
| 330 | typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code); |
| 331 | int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc); |
| 332 | |
| 333 | PropertyMap mConfiguration; |
| 334 | }; |
| 335 | |
| 336 | |
| 337 | /* Keeps track of the state of mouse or touch pad buttons. */ |
| 338 | class CursorButtonAccumulator { |
| 339 | public: |
| 340 | CursorButtonAccumulator(); |
| 341 | void reset(InputDevice* device); |
| 342 | |
| 343 | void process(const RawEvent* rawEvent); |
| 344 | |
| 345 | uint32_t getButtonState() const; |
| 346 | |
| 347 | private: |
| 348 | bool mBtnLeft; |
| 349 | bool mBtnRight; |
| 350 | bool mBtnMiddle; |
| 351 | bool mBtnBack; |
| 352 | bool mBtnSide; |
| 353 | bool mBtnForward; |
| 354 | bool mBtnExtra; |
| 355 | bool mBtnTask; |
| 356 | |
| 357 | void clearButtons(); |
| 358 | }; |
| 359 | |
| 360 | |
| 361 | /* Keeps track of cursor movements. */ |
| 362 | |
| 363 | class CursorMotionAccumulator { |
| 364 | public: |
| 365 | CursorMotionAccumulator(); |
| 366 | void reset(InputDevice* device); |
| 367 | |
| 368 | void process(const RawEvent* rawEvent); |
| 369 | void finishSync(); |
| 370 | |
| 371 | inline int32_t getRelativeX() const { return mRelX; } |
| 372 | inline int32_t getRelativeY() const { return mRelY; } |
| 373 | |
| 374 | private: |
| 375 | int32_t mRelX; |
| 376 | int32_t mRelY; |
| 377 | |
| 378 | void clearRelativeAxes(); |
| 379 | }; |
| 380 | |
| 381 | |
| 382 | /* Keeps track of cursor scrolling motions. */ |
| 383 | |
| 384 | class CursorScrollAccumulator { |
| 385 | public: |
| 386 | CursorScrollAccumulator(); |
| 387 | void configure(InputDevice* device); |
| 388 | void reset(InputDevice* device); |
| 389 | |
| 390 | void process(const RawEvent* rawEvent); |
| 391 | void finishSync(); |
| 392 | |
| 393 | inline bool haveRelativeVWheel() const { return mHaveRelWheel; } |
| 394 | inline bool haveRelativeHWheel() const { return mHaveRelHWheel; } |
| 395 | |
| 396 | inline int32_t getRelativeX() const { return mRelX; } |
| 397 | inline int32_t getRelativeY() const { return mRelY; } |
| 398 | inline int32_t getRelativeVWheel() const { return mRelWheel; } |
| 399 | inline int32_t getRelativeHWheel() const { return mRelHWheel; } |
| 400 | |
| 401 | private: |
| 402 | bool mHaveRelWheel; |
| 403 | bool mHaveRelHWheel; |
| 404 | |
| 405 | int32_t mRelX; |
| 406 | int32_t mRelY; |
| 407 | int32_t mRelWheel; |
| 408 | int32_t mRelHWheel; |
| 409 | |
| 410 | void clearRelativeAxes(); |
| 411 | }; |
| 412 | |
| 413 | |
| 414 | /* Keeps track of the state of touch, stylus and tool buttons. */ |
| 415 | class TouchButtonAccumulator { |
| 416 | public: |
| 417 | TouchButtonAccumulator(); |
| 418 | void configure(InputDevice* device); |
| 419 | void reset(InputDevice* device); |
| 420 | |
| 421 | void process(const RawEvent* rawEvent); |
| 422 | |
| 423 | uint32_t getButtonState() const; |
| 424 | int32_t getToolType() const; |
| 425 | bool isToolActive() const; |
| 426 | bool isHovering() const; |
| 427 | bool hasStylus() const; |
| 428 | |
| 429 | private: |
| 430 | bool mHaveBtnTouch; |
| 431 | bool mHaveStylus; |
| 432 | |
| 433 | bool mBtnTouch; |
| 434 | bool mBtnStylus; |
| 435 | bool mBtnStylus2; |
| 436 | bool mBtnToolFinger; |
| 437 | bool mBtnToolPen; |
| 438 | bool mBtnToolRubber; |
| 439 | bool mBtnToolBrush; |
| 440 | bool mBtnToolPencil; |
| 441 | bool mBtnToolAirbrush; |
| 442 | bool mBtnToolMouse; |
| 443 | bool mBtnToolLens; |
| 444 | bool mBtnToolDoubleTap; |
| 445 | bool mBtnToolTripleTap; |
| 446 | bool mBtnToolQuadTap; |
| 447 | |
| 448 | void clearButtons(); |
| 449 | }; |
| 450 | |
| 451 | |
| 452 | /* Raw axis information from the driver. */ |
| 453 | struct RawPointerAxes { |
| 454 | RawAbsoluteAxisInfo x; |
| 455 | RawAbsoluteAxisInfo y; |
| 456 | RawAbsoluteAxisInfo pressure; |
| 457 | RawAbsoluteAxisInfo touchMajor; |
| 458 | RawAbsoluteAxisInfo touchMinor; |
| 459 | RawAbsoluteAxisInfo toolMajor; |
| 460 | RawAbsoluteAxisInfo toolMinor; |
| 461 | RawAbsoluteAxisInfo orientation; |
| 462 | RawAbsoluteAxisInfo distance; |
| 463 | RawAbsoluteAxisInfo tiltX; |
| 464 | RawAbsoluteAxisInfo tiltY; |
| 465 | RawAbsoluteAxisInfo trackingId; |
| 466 | RawAbsoluteAxisInfo slot; |
| 467 | |
| 468 | RawPointerAxes(); |
Siarhei Vishniakou | 26e34d9 | 2018-11-12 13:51:26 -0800 | [diff] [blame] | 469 | inline int32_t getRawWidth() const { return x.maxValue - x.minValue + 1; } |
| 470 | inline int32_t getRawHeight() const { return y.maxValue - y.minValue + 1; } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 471 | void clear(); |
| 472 | }; |
| 473 | |
| 474 | |
| 475 | /* Raw data for a collection of pointers including a pointer id mapping table. */ |
| 476 | struct RawPointerData { |
| 477 | struct Pointer { |
| 478 | uint32_t id; |
| 479 | int32_t x; |
| 480 | int32_t y; |
| 481 | int32_t pressure; |
| 482 | int32_t touchMajor; |
| 483 | int32_t touchMinor; |
| 484 | int32_t toolMajor; |
| 485 | int32_t toolMinor; |
| 486 | int32_t orientation; |
| 487 | int32_t distance; |
| 488 | int32_t tiltX; |
| 489 | int32_t tiltY; |
| 490 | int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant |
| 491 | bool isHovering; |
| 492 | }; |
| 493 | |
| 494 | uint32_t pointerCount; |
| 495 | Pointer pointers[MAX_POINTERS]; |
| 496 | BitSet32 hoveringIdBits, touchingIdBits; |
| 497 | uint32_t idToIndex[MAX_POINTER_ID + 1]; |
| 498 | |
| 499 | RawPointerData(); |
| 500 | void clear(); |
| 501 | void copyFrom(const RawPointerData& other); |
| 502 | void getCentroidOfTouchingPointers(float* outX, float* outY) const; |
| 503 | |
| 504 | inline void markIdBit(uint32_t id, bool isHovering) { |
| 505 | if (isHovering) { |
| 506 | hoveringIdBits.markBit(id); |
| 507 | } else { |
| 508 | touchingIdBits.markBit(id); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | inline void clearIdBits() { |
| 513 | hoveringIdBits.clear(); |
| 514 | touchingIdBits.clear(); |
| 515 | } |
| 516 | |
| 517 | inline const Pointer& pointerForId(uint32_t id) const { |
| 518 | return pointers[idToIndex[id]]; |
| 519 | } |
| 520 | |
| 521 | inline bool isHovering(uint32_t pointerIndex) { |
| 522 | return pointers[pointerIndex].isHovering; |
| 523 | } |
| 524 | }; |
| 525 | |
| 526 | |
| 527 | /* Cooked data for a collection of pointers including a pointer id mapping table. */ |
| 528 | struct CookedPointerData { |
| 529 | uint32_t pointerCount; |
| 530 | PointerProperties pointerProperties[MAX_POINTERS]; |
| 531 | PointerCoords pointerCoords[MAX_POINTERS]; |
| 532 | BitSet32 hoveringIdBits, touchingIdBits; |
| 533 | uint32_t idToIndex[MAX_POINTER_ID + 1]; |
| 534 | |
| 535 | CookedPointerData(); |
| 536 | void clear(); |
| 537 | void copyFrom(const CookedPointerData& other); |
| 538 | |
| 539 | inline const PointerCoords& pointerCoordsForId(uint32_t id) const { |
| 540 | return pointerCoords[idToIndex[id]]; |
| 541 | } |
| 542 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 543 | inline PointerCoords& editPointerCoordsWithId(uint32_t id) { |
| 544 | return pointerCoords[idToIndex[id]]; |
| 545 | } |
| 546 | |
| 547 | inline PointerProperties& editPointerPropertiesWithId(uint32_t id) { |
| 548 | return pointerProperties[idToIndex[id]]; |
| 549 | } |
| 550 | |
Michael Wright | 53dca3a | 2015-04-23 17:39:53 +0100 | [diff] [blame] | 551 | inline bool isHovering(uint32_t pointerIndex) const { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 552 | return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id); |
| 553 | } |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 554 | |
Michael Wright | 53dca3a | 2015-04-23 17:39:53 +0100 | [diff] [blame] | 555 | inline bool isTouching(uint32_t pointerIndex) const { |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 556 | return touchingIdBits.hasBit(pointerProperties[pointerIndex].id); |
| 557 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 558 | }; |
| 559 | |
| 560 | |
| 561 | /* Keeps track of the state of single-touch protocol. */ |
| 562 | class SingleTouchMotionAccumulator { |
| 563 | public: |
| 564 | SingleTouchMotionAccumulator(); |
| 565 | |
| 566 | void process(const RawEvent* rawEvent); |
| 567 | void reset(InputDevice* device); |
| 568 | |
| 569 | inline int32_t getAbsoluteX() const { return mAbsX; } |
| 570 | inline int32_t getAbsoluteY() const { return mAbsY; } |
| 571 | inline int32_t getAbsolutePressure() const { return mAbsPressure; } |
| 572 | inline int32_t getAbsoluteToolWidth() const { return mAbsToolWidth; } |
| 573 | inline int32_t getAbsoluteDistance() const { return mAbsDistance; } |
| 574 | inline int32_t getAbsoluteTiltX() const { return mAbsTiltX; } |
| 575 | inline int32_t getAbsoluteTiltY() const { return mAbsTiltY; } |
| 576 | |
| 577 | private: |
| 578 | int32_t mAbsX; |
| 579 | int32_t mAbsY; |
| 580 | int32_t mAbsPressure; |
| 581 | int32_t mAbsToolWidth; |
| 582 | int32_t mAbsDistance; |
| 583 | int32_t mAbsTiltX; |
| 584 | int32_t mAbsTiltY; |
| 585 | |
| 586 | void clearAbsoluteAxes(); |
| 587 | }; |
| 588 | |
| 589 | |
| 590 | /* Keeps track of the state of multi-touch protocol. */ |
| 591 | class MultiTouchMotionAccumulator { |
| 592 | public: |
| 593 | class Slot { |
| 594 | public: |
| 595 | inline bool isInUse() const { return mInUse; } |
| 596 | inline int32_t getX() const { return mAbsMTPositionX; } |
| 597 | inline int32_t getY() const { return mAbsMTPositionY; } |
| 598 | inline int32_t getTouchMajor() const { return mAbsMTTouchMajor; } |
| 599 | inline int32_t getTouchMinor() const { |
| 600 | return mHaveAbsMTTouchMinor ? mAbsMTTouchMinor : mAbsMTTouchMajor; } |
| 601 | inline int32_t getToolMajor() const { return mAbsMTWidthMajor; } |
| 602 | inline int32_t getToolMinor() const { |
| 603 | return mHaveAbsMTWidthMinor ? mAbsMTWidthMinor : mAbsMTWidthMajor; } |
| 604 | inline int32_t getOrientation() const { return mAbsMTOrientation; } |
| 605 | inline int32_t getTrackingId() const { return mAbsMTTrackingId; } |
| 606 | inline int32_t getPressure() const { return mAbsMTPressure; } |
| 607 | inline int32_t getDistance() const { return mAbsMTDistance; } |
| 608 | inline int32_t getToolType() const; |
| 609 | |
| 610 | private: |
| 611 | friend class MultiTouchMotionAccumulator; |
| 612 | |
| 613 | bool mInUse; |
| 614 | bool mHaveAbsMTTouchMinor; |
| 615 | bool mHaveAbsMTWidthMinor; |
| 616 | bool mHaveAbsMTToolType; |
| 617 | |
| 618 | int32_t mAbsMTPositionX; |
| 619 | int32_t mAbsMTPositionY; |
| 620 | int32_t mAbsMTTouchMajor; |
| 621 | int32_t mAbsMTTouchMinor; |
| 622 | int32_t mAbsMTWidthMajor; |
| 623 | int32_t mAbsMTWidthMinor; |
| 624 | int32_t mAbsMTOrientation; |
| 625 | int32_t mAbsMTTrackingId; |
| 626 | int32_t mAbsMTPressure; |
| 627 | int32_t mAbsMTDistance; |
| 628 | int32_t mAbsMTToolType; |
| 629 | |
| 630 | Slot(); |
| 631 | void clear(); |
| 632 | }; |
| 633 | |
| 634 | MultiTouchMotionAccumulator(); |
| 635 | ~MultiTouchMotionAccumulator(); |
| 636 | |
| 637 | void configure(InputDevice* device, size_t slotCount, bool usingSlotsProtocol); |
| 638 | void reset(InputDevice* device); |
| 639 | void process(const RawEvent* rawEvent); |
| 640 | void finishSync(); |
| 641 | bool hasStylus() const; |
| 642 | |
| 643 | inline size_t getSlotCount() const { return mSlotCount; } |
| 644 | inline const Slot* getSlot(size_t index) const { return &mSlots[index]; } |
Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 645 | inline uint32_t getDeviceTimestamp() const { return mDeviceTimestamp; } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 646 | |
| 647 | private: |
| 648 | int32_t mCurrentSlot; |
| 649 | Slot* mSlots; |
| 650 | size_t mSlotCount; |
| 651 | bool mUsingSlotsProtocol; |
| 652 | bool mHaveStylus; |
Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 653 | uint32_t mDeviceTimestamp; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 654 | |
| 655 | void clearSlots(int32_t initialSlot); |
| 656 | }; |
| 657 | |
| 658 | |
| 659 | /* An input mapper transforms raw input events into cooked event data. |
| 660 | * A single input device can have multiple associated input mappers in order to interpret |
| 661 | * different classes of events. |
| 662 | * |
| 663 | * InputMapper lifecycle: |
| 664 | * - create |
| 665 | * - configure with 0 changes |
| 666 | * - reset |
| 667 | * - process, process, process (may occasionally reconfigure with non-zero changes or reset) |
| 668 | * - reset |
| 669 | * - destroy |
| 670 | */ |
| 671 | class InputMapper { |
| 672 | public: |
Chih-Hung Hsieh | 6d2ede1 | 2016-09-01 11:28:23 -0700 | [diff] [blame] | 673 | explicit InputMapper(InputDevice* device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 674 | virtual ~InputMapper(); |
| 675 | |
| 676 | inline InputDevice* getDevice() { return mDevice; } |
| 677 | inline int32_t getDeviceId() { return mDevice->getId(); } |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 678 | inline const std::string getDeviceName() { return mDevice->getName(); } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 679 | inline InputReaderContext* getContext() { return mContext; } |
| 680 | inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); } |
| 681 | inline InputListenerInterface* getListener() { return mContext->getListener(); } |
| 682 | inline EventHubInterface* getEventHub() { return mContext->getEventHub(); } |
| 683 | |
| 684 | virtual uint32_t getSources() = 0; |
| 685 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 686 | virtual void dump(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 687 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 688 | virtual void reset(nsecs_t when); |
| 689 | virtual void process(const RawEvent* rawEvent) = 0; |
| 690 | virtual void timeoutExpired(nsecs_t when); |
| 691 | |
| 692 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 693 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 694 | virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 695 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 696 | const int32_t* keyCodes, uint8_t* outFlags); |
| 697 | virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, |
| 698 | int32_t token); |
| 699 | virtual void cancelVibrate(int32_t token); |
Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 700 | virtual void cancelTouch(nsecs_t when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 701 | |
| 702 | virtual int32_t getMetaState(); |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 703 | virtual void updateMetaState(int32_t keyCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 704 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 705 | virtual void updateExternalStylusState(const StylusState& state); |
| 706 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 707 | virtual void fadePointer(); |
| 708 | |
| 709 | protected: |
| 710 | InputDevice* mDevice; |
| 711 | InputReaderContext* mContext; |
| 712 | |
| 713 | status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo); |
| 714 | void bumpGeneration(); |
| 715 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 716 | static void dumpRawAbsoluteAxisInfo(std::string& dump, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 717 | const RawAbsoluteAxisInfo& axis, const char* name); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 718 | static void dumpStylusState(std::string& dump, const StylusState& state); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 719 | }; |
| 720 | |
| 721 | |
| 722 | class SwitchInputMapper : public InputMapper { |
| 723 | public: |
Chih-Hung Hsieh | 6d2ede1 | 2016-09-01 11:28:23 -0700 | [diff] [blame] | 724 | explicit SwitchInputMapper(InputDevice* device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 725 | virtual ~SwitchInputMapper(); |
| 726 | |
| 727 | virtual uint32_t getSources(); |
| 728 | virtual void process(const RawEvent* rawEvent); |
| 729 | |
| 730 | virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 731 | virtual void dump(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 732 | |
| 733 | private: |
Michael Wright | bcbf97e | 2014-08-29 14:31:32 -0700 | [diff] [blame] | 734 | uint32_t mSwitchValues; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 735 | uint32_t mUpdatedSwitchMask; |
| 736 | |
| 737 | void processSwitch(int32_t switchCode, int32_t switchValue); |
| 738 | void sync(nsecs_t when); |
| 739 | }; |
| 740 | |
| 741 | |
| 742 | class VibratorInputMapper : public InputMapper { |
| 743 | public: |
Chih-Hung Hsieh | 6d2ede1 | 2016-09-01 11:28:23 -0700 | [diff] [blame] | 744 | explicit VibratorInputMapper(InputDevice* device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 745 | virtual ~VibratorInputMapper(); |
| 746 | |
| 747 | virtual uint32_t getSources(); |
| 748 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
| 749 | virtual void process(const RawEvent* rawEvent); |
| 750 | |
| 751 | virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, |
| 752 | int32_t token); |
| 753 | virtual void cancelVibrate(int32_t token); |
| 754 | virtual void timeoutExpired(nsecs_t when); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 755 | virtual void dump(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 756 | |
| 757 | private: |
| 758 | bool mVibrating; |
| 759 | nsecs_t mPattern[MAX_VIBRATE_PATTERN_SIZE]; |
| 760 | size_t mPatternSize; |
| 761 | ssize_t mRepeat; |
| 762 | int32_t mToken; |
| 763 | ssize_t mIndex; |
| 764 | nsecs_t mNextStepTime; |
| 765 | |
| 766 | void nextStep(); |
| 767 | void stopVibrating(); |
| 768 | }; |
| 769 | |
| 770 | |
| 771 | class KeyboardInputMapper : public InputMapper { |
| 772 | public: |
| 773 | KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType); |
| 774 | virtual ~KeyboardInputMapper(); |
| 775 | |
| 776 | virtual uint32_t getSources(); |
| 777 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 778 | virtual void dump(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 779 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 780 | virtual void reset(nsecs_t when); |
| 781 | virtual void process(const RawEvent* rawEvent); |
| 782 | |
| 783 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 784 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 785 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 786 | const int32_t* keyCodes, uint8_t* outFlags); |
| 787 | |
| 788 | virtual int32_t getMetaState(); |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 789 | virtual void updateMetaState(int32_t keyCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 790 | |
| 791 | private: |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 792 | // The current viewport. |
| 793 | std::optional<DisplayViewport> mViewport; |
| 794 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 795 | struct KeyDown { |
| 796 | int32_t keyCode; |
| 797 | int32_t scanCode; |
| 798 | }; |
| 799 | |
| 800 | uint32_t mSource; |
| 801 | int32_t mKeyboardType; |
| 802 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 803 | Vector<KeyDown> mKeyDowns; // keys that are down |
| 804 | int32_t mMetaState; |
| 805 | nsecs_t mDownTime; // time of most recent key down |
| 806 | |
| 807 | int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none |
| 808 | |
| 809 | struct LedState { |
| 810 | bool avail; // led is available |
| 811 | bool on; // we think the led is currently on |
| 812 | }; |
| 813 | LedState mCapsLockLedState; |
| 814 | LedState mNumLockLedState; |
| 815 | LedState mScrollLockLedState; |
| 816 | |
| 817 | // Immutable configuration parameters. |
| 818 | struct Parameters { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 819 | bool orientationAware; |
Michael Wright | dcfcf5d | 2014-03-17 12:58:21 -0700 | [diff] [blame] | 820 | bool handlesKeyRepeat; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 821 | } mParameters; |
| 822 | |
| 823 | void configureParameters(); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 824 | void dumpParameters(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 825 | |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 826 | int32_t getOrientation(); |
| 827 | int32_t getDisplayId(); |
| 828 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 829 | bool isKeyboardOrGamepadKey(int32_t scanCode); |
Michael Wright | 58ba988 | 2017-07-26 16:19:11 +0100 | [diff] [blame] | 830 | bool isMediaKey(int32_t keyCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 831 | |
Dmitry Torokhov | 0faaa0b | 2015-09-24 13:13:55 -0700 | [diff] [blame] | 832 | void processKey(nsecs_t when, bool down, int32_t scanCode, int32_t usageCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 833 | |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 834 | bool updateMetaStateIfNeeded(int32_t keyCode, bool down); |
| 835 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 836 | ssize_t findKeyDown(int32_t scanCode); |
| 837 | |
| 838 | void resetLedState(); |
| 839 | void initializeLedState(LedState& ledState, int32_t led); |
| 840 | void updateLedState(bool reset); |
| 841 | void updateLedStateForModifier(LedState& ledState, int32_t led, |
| 842 | int32_t modifier, bool reset); |
| 843 | }; |
| 844 | |
| 845 | |
| 846 | class CursorInputMapper : public InputMapper { |
| 847 | public: |
Chih-Hung Hsieh | 6d2ede1 | 2016-09-01 11:28:23 -0700 | [diff] [blame] | 848 | explicit CursorInputMapper(InputDevice* device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 849 | virtual ~CursorInputMapper(); |
| 850 | |
| 851 | virtual uint32_t getSources(); |
| 852 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 853 | virtual void dump(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 854 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 855 | virtual void reset(nsecs_t when); |
| 856 | virtual void process(const RawEvent* rawEvent); |
| 857 | |
| 858 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 859 | |
| 860 | virtual void fadePointer(); |
| 861 | |
| 862 | private: |
| 863 | // Amount that trackball needs to move in order to generate a key event. |
| 864 | static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6; |
| 865 | |
| 866 | // Immutable configuration parameters. |
| 867 | struct Parameters { |
| 868 | enum Mode { |
| 869 | MODE_POINTER, |
Vladislav Kaznacheev | 78f97b3 | 2016-12-15 18:14:58 -0800 | [diff] [blame] | 870 | MODE_POINTER_RELATIVE, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 871 | MODE_NAVIGATION, |
| 872 | }; |
| 873 | |
| 874 | Mode mode; |
| 875 | bool hasAssociatedDisplay; |
| 876 | bool orientationAware; |
| 877 | } mParameters; |
| 878 | |
| 879 | CursorButtonAccumulator mCursorButtonAccumulator; |
| 880 | CursorMotionAccumulator mCursorMotionAccumulator; |
| 881 | CursorScrollAccumulator mCursorScrollAccumulator; |
| 882 | |
| 883 | int32_t mSource; |
| 884 | float mXScale; |
| 885 | float mYScale; |
| 886 | float mXPrecision; |
| 887 | float mYPrecision; |
| 888 | |
| 889 | float mVWheelScale; |
| 890 | float mHWheelScale; |
| 891 | |
| 892 | // Velocity controls for mouse pointer and wheel movements. |
| 893 | // The controls for X and Y wheel movements are separate to keep them decoupled. |
| 894 | VelocityControl mPointerVelocityControl; |
| 895 | VelocityControl mWheelXVelocityControl; |
| 896 | VelocityControl mWheelYVelocityControl; |
| 897 | |
| 898 | int32_t mOrientation; |
| 899 | |
| 900 | sp<PointerControllerInterface> mPointerController; |
| 901 | |
| 902 | int32_t mButtonState; |
| 903 | nsecs_t mDownTime; |
| 904 | |
| 905 | void configureParameters(); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 906 | void dumpParameters(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 907 | |
| 908 | void sync(nsecs_t when); |
| 909 | }; |
| 910 | |
| 911 | |
Prashant Malani | 1941ff5 | 2015-08-11 18:29:28 -0700 | [diff] [blame] | 912 | class RotaryEncoderInputMapper : public InputMapper { |
| 913 | public: |
Chih-Hung Hsieh | 6d2ede1 | 2016-09-01 11:28:23 -0700 | [diff] [blame] | 914 | explicit RotaryEncoderInputMapper(InputDevice* device); |
Prashant Malani | 1941ff5 | 2015-08-11 18:29:28 -0700 | [diff] [blame] | 915 | virtual ~RotaryEncoderInputMapper(); |
| 916 | |
| 917 | virtual uint32_t getSources(); |
| 918 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 919 | virtual void dump(std::string& dump); |
Prashant Malani | 1941ff5 | 2015-08-11 18:29:28 -0700 | [diff] [blame] | 920 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 921 | virtual void reset(nsecs_t when); |
| 922 | virtual void process(const RawEvent* rawEvent); |
| 923 | |
| 924 | private: |
| 925 | CursorScrollAccumulator mRotaryEncoderScrollAccumulator; |
| 926 | |
| 927 | int32_t mSource; |
Prashant Malani | dae627a | 2016-01-11 17:08:18 -0800 | [diff] [blame] | 928 | float mScalingFactor; |
Ivan Podogov | ad43725 | 2016-09-29 16:29:55 +0100 | [diff] [blame] | 929 | int32_t mOrientation; |
Prashant Malani | 1941ff5 | 2015-08-11 18:29:28 -0700 | [diff] [blame] | 930 | |
| 931 | void sync(nsecs_t when); |
| 932 | }; |
| 933 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 934 | class TouchInputMapper : public InputMapper { |
| 935 | public: |
Chih-Hung Hsieh | 6d2ede1 | 2016-09-01 11:28:23 -0700 | [diff] [blame] | 936 | explicit TouchInputMapper(InputDevice* device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 937 | virtual ~TouchInputMapper(); |
| 938 | |
| 939 | virtual uint32_t getSources(); |
| 940 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 941 | virtual void dump(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 942 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 943 | virtual void reset(nsecs_t when); |
| 944 | virtual void process(const RawEvent* rawEvent); |
| 945 | |
| 946 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 947 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 948 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 949 | const int32_t* keyCodes, uint8_t* outFlags); |
| 950 | |
| 951 | virtual void fadePointer(); |
Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 952 | virtual void cancelTouch(nsecs_t when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 953 | virtual void timeoutExpired(nsecs_t when); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 954 | virtual void updateExternalStylusState(const StylusState& state); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 955 | |
| 956 | protected: |
| 957 | CursorButtonAccumulator mCursorButtonAccumulator; |
| 958 | CursorScrollAccumulator mCursorScrollAccumulator; |
| 959 | TouchButtonAccumulator mTouchButtonAccumulator; |
| 960 | |
| 961 | struct VirtualKey { |
| 962 | int32_t keyCode; |
| 963 | int32_t scanCode; |
| 964 | uint32_t flags; |
| 965 | |
| 966 | // computed hit box, specified in touch screen coords based on known display size |
| 967 | int32_t hitLeft; |
| 968 | int32_t hitTop; |
| 969 | int32_t hitRight; |
| 970 | int32_t hitBottom; |
| 971 | |
| 972 | inline bool isHit(int32_t x, int32_t y) const { |
| 973 | return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom; |
| 974 | } |
| 975 | }; |
| 976 | |
| 977 | // Input sources and device mode. |
| 978 | uint32_t mSource; |
| 979 | |
| 980 | enum DeviceMode { |
| 981 | DEVICE_MODE_DISABLED, // input is disabled |
| 982 | DEVICE_MODE_DIRECT, // direct mapping (touchscreen) |
| 983 | DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad) |
| 984 | DEVICE_MODE_NAVIGATION, // unscaled mapping with assist gesture (touch navigation) |
| 985 | DEVICE_MODE_POINTER, // pointer mapping (pointer) |
| 986 | }; |
| 987 | DeviceMode mDeviceMode; |
| 988 | |
| 989 | // The reader's configuration. |
| 990 | InputReaderConfiguration mConfig; |
| 991 | |
| 992 | // Immutable configuration parameters. |
| 993 | struct Parameters { |
| 994 | enum DeviceType { |
| 995 | DEVICE_TYPE_TOUCH_SCREEN, |
| 996 | DEVICE_TYPE_TOUCH_PAD, |
| 997 | DEVICE_TYPE_TOUCH_NAVIGATION, |
| 998 | DEVICE_TYPE_POINTER, |
| 999 | }; |
| 1000 | |
| 1001 | DeviceType deviceType; |
| 1002 | bool hasAssociatedDisplay; |
| 1003 | bool associatedDisplayIsExternal; |
| 1004 | bool orientationAware; |
| 1005 | bool hasButtonUnderPad; |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 1006 | std::string uniqueDisplayId; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1007 | |
| 1008 | enum GestureMode { |
Amirhossein Simjour | 3dd617b | 2015-10-09 10:39:48 -0400 | [diff] [blame] | 1009 | GESTURE_MODE_SINGLE_TOUCH, |
| 1010 | GESTURE_MODE_MULTI_TOUCH, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1011 | }; |
| 1012 | GestureMode gestureMode; |
Jeff Brown | c5e2442 | 2014-02-26 18:48:51 -0800 | [diff] [blame] | 1013 | |
| 1014 | bool wake; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1015 | } mParameters; |
| 1016 | |
| 1017 | // Immutable calibration parameters in parsed form. |
| 1018 | struct Calibration { |
| 1019 | // Size |
| 1020 | enum SizeCalibration { |
| 1021 | SIZE_CALIBRATION_DEFAULT, |
| 1022 | SIZE_CALIBRATION_NONE, |
| 1023 | SIZE_CALIBRATION_GEOMETRIC, |
| 1024 | SIZE_CALIBRATION_DIAMETER, |
| 1025 | SIZE_CALIBRATION_BOX, |
| 1026 | SIZE_CALIBRATION_AREA, |
| 1027 | }; |
| 1028 | |
| 1029 | SizeCalibration sizeCalibration; |
| 1030 | |
| 1031 | bool haveSizeScale; |
| 1032 | float sizeScale; |
| 1033 | bool haveSizeBias; |
| 1034 | float sizeBias; |
| 1035 | bool haveSizeIsSummed; |
| 1036 | bool sizeIsSummed; |
| 1037 | |
| 1038 | // Pressure |
| 1039 | enum PressureCalibration { |
| 1040 | PRESSURE_CALIBRATION_DEFAULT, |
| 1041 | PRESSURE_CALIBRATION_NONE, |
| 1042 | PRESSURE_CALIBRATION_PHYSICAL, |
| 1043 | PRESSURE_CALIBRATION_AMPLITUDE, |
| 1044 | }; |
| 1045 | |
| 1046 | PressureCalibration pressureCalibration; |
| 1047 | bool havePressureScale; |
| 1048 | float pressureScale; |
| 1049 | |
| 1050 | // Orientation |
| 1051 | enum OrientationCalibration { |
| 1052 | ORIENTATION_CALIBRATION_DEFAULT, |
| 1053 | ORIENTATION_CALIBRATION_NONE, |
| 1054 | ORIENTATION_CALIBRATION_INTERPOLATED, |
| 1055 | ORIENTATION_CALIBRATION_VECTOR, |
| 1056 | }; |
| 1057 | |
| 1058 | OrientationCalibration orientationCalibration; |
| 1059 | |
| 1060 | // Distance |
| 1061 | enum DistanceCalibration { |
| 1062 | DISTANCE_CALIBRATION_DEFAULT, |
| 1063 | DISTANCE_CALIBRATION_NONE, |
| 1064 | DISTANCE_CALIBRATION_SCALED, |
| 1065 | }; |
| 1066 | |
| 1067 | DistanceCalibration distanceCalibration; |
| 1068 | bool haveDistanceScale; |
| 1069 | float distanceScale; |
| 1070 | |
| 1071 | enum CoverageCalibration { |
| 1072 | COVERAGE_CALIBRATION_DEFAULT, |
| 1073 | COVERAGE_CALIBRATION_NONE, |
| 1074 | COVERAGE_CALIBRATION_BOX, |
| 1075 | }; |
| 1076 | |
| 1077 | CoverageCalibration coverageCalibration; |
| 1078 | |
| 1079 | inline void applySizeScaleAndBias(float* outSize) const { |
| 1080 | if (haveSizeScale) { |
| 1081 | *outSize *= sizeScale; |
| 1082 | } |
| 1083 | if (haveSizeBias) { |
| 1084 | *outSize += sizeBias; |
| 1085 | } |
| 1086 | if (*outSize < 0) { |
| 1087 | *outSize = 0; |
| 1088 | } |
| 1089 | } |
| 1090 | } mCalibration; |
| 1091 | |
Jason Gerecke | af126fb | 2012-05-10 14:22:47 -0700 | [diff] [blame] | 1092 | // Affine location transformation/calibration |
| 1093 | struct TouchAffineTransformation mAffineTransform; |
| 1094 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1095 | RawPointerAxes mRawPointerAxes; |
| 1096 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1097 | struct RawState { |
| 1098 | nsecs_t when; |
Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 1099 | uint32_t deviceTimestamp; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1100 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1101 | // Raw pointer sample data. |
| 1102 | RawPointerData rawPointerData; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1103 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1104 | int32_t buttonState; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1105 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1106 | // Scroll state. |
| 1107 | int32_t rawVScroll; |
| 1108 | int32_t rawHScroll; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1109 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1110 | void copyFrom(const RawState& other) { |
| 1111 | when = other.when; |
Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 1112 | deviceTimestamp = other.deviceTimestamp; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1113 | rawPointerData.copyFrom(other.rawPointerData); |
| 1114 | buttonState = other.buttonState; |
| 1115 | rawVScroll = other.rawVScroll; |
| 1116 | rawHScroll = other.rawHScroll; |
| 1117 | } |
| 1118 | |
| 1119 | void clear() { |
| 1120 | when = 0; |
Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 1121 | deviceTimestamp = 0; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1122 | rawPointerData.clear(); |
| 1123 | buttonState = 0; |
| 1124 | rawVScroll = 0; |
| 1125 | rawHScroll = 0; |
| 1126 | } |
| 1127 | }; |
| 1128 | |
| 1129 | struct CookedState { |
Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 1130 | uint32_t deviceTimestamp; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1131 | // Cooked pointer sample data. |
| 1132 | CookedPointerData cookedPointerData; |
| 1133 | |
| 1134 | // Id bits used to differentiate fingers, stylus and mouse tools. |
| 1135 | BitSet32 fingerIdBits; |
| 1136 | BitSet32 stylusIdBits; |
| 1137 | BitSet32 mouseIdBits; |
| 1138 | |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 1139 | int32_t buttonState; |
| 1140 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1141 | void copyFrom(const CookedState& other) { |
Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 1142 | deviceTimestamp = other.deviceTimestamp; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1143 | cookedPointerData.copyFrom(other.cookedPointerData); |
| 1144 | fingerIdBits = other.fingerIdBits; |
| 1145 | stylusIdBits = other.stylusIdBits; |
| 1146 | mouseIdBits = other.mouseIdBits; |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 1147 | buttonState = other.buttonState; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | void clear() { |
Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 1151 | deviceTimestamp = 0; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1152 | cookedPointerData.clear(); |
| 1153 | fingerIdBits.clear(); |
| 1154 | stylusIdBits.clear(); |
| 1155 | mouseIdBits.clear(); |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 1156 | buttonState = 0; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1157 | } |
| 1158 | }; |
| 1159 | |
| 1160 | Vector<RawState> mRawStatesPending; |
| 1161 | RawState mCurrentRawState; |
| 1162 | CookedState mCurrentCookedState; |
| 1163 | RawState mLastRawState; |
| 1164 | CookedState mLastCookedState; |
| 1165 | |
| 1166 | // State provided by an external stylus |
| 1167 | StylusState mExternalStylusState; |
| 1168 | int64_t mExternalStylusId; |
Michael Wright | 43fd19f | 2015-04-21 19:02:58 +0100 | [diff] [blame] | 1169 | nsecs_t mExternalStylusFusionTimeout; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1170 | bool mExternalStylusDataPending; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1171 | |
| 1172 | // True if we sent a HOVER_ENTER event. |
| 1173 | bool mSentHoverEnter; |
| 1174 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1175 | // Have we assigned pointer IDs for this stream |
| 1176 | bool mHavePointerIds; |
| 1177 | |
Michael Wright | 8e81282 | 2015-06-22 16:18:21 +0100 | [diff] [blame] | 1178 | // Is the current stream of direct touch events aborted |
| 1179 | bool mCurrentMotionAborted; |
| 1180 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1181 | // The time the primary pointer last went down. |
| 1182 | nsecs_t mDownTime; |
| 1183 | |
| 1184 | // The pointer controller, or null if the device is not a pointer. |
| 1185 | sp<PointerControllerInterface> mPointerController; |
| 1186 | |
| 1187 | Vector<VirtualKey> mVirtualKeys; |
| 1188 | |
| 1189 | virtual void configureParameters(); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 1190 | virtual void dumpParameters(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1191 | virtual void configureRawPointerAxes(); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 1192 | virtual void dumpRawPointerAxes(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1193 | virtual void configureSurface(nsecs_t when, bool* outResetNeeded); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 1194 | virtual void dumpSurface(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1195 | virtual void configureVirtualKeys(); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 1196 | virtual void dumpVirtualKeys(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1197 | virtual void parseCalibration(); |
| 1198 | virtual void resolveCalibration(); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 1199 | virtual void dumpCalibration(std::string& dump); |
Jason Gerecke | 12d6baa | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 1200 | virtual void updateAffineTransformation(); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 1201 | virtual void dumpAffineTransformation(std::string& dump); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1202 | virtual void resolveExternalStylusPresence(); |
| 1203 | virtual bool hasStylus() const = 0; |
| 1204 | virtual bool hasExternalStylus() const; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1205 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1206 | virtual void syncTouch(nsecs_t when, RawState* outState) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1207 | |
| 1208 | private: |
| 1209 | // The current viewport. |
| 1210 | // The components of the viewport are specified in the display's rotated orientation. |
| 1211 | DisplayViewport mViewport; |
| 1212 | |
| 1213 | // The surface orientation, width and height set by configureSurface(). |
| 1214 | // The width and height are derived from the viewport but are specified |
| 1215 | // in the natural orientation. |
| 1216 | // The surface origin specifies how the surface coordinates should be translated |
| 1217 | // to align with the logical display coordinate space. |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1218 | int32_t mSurfaceWidth; |
| 1219 | int32_t mSurfaceHeight; |
| 1220 | int32_t mSurfaceLeft; |
| 1221 | int32_t mSurfaceTop; |
Michael Wright | 358bcc7 | 2018-08-21 04:01:07 +0100 | [diff] [blame] | 1222 | |
| 1223 | // Similar to the surface coordinates, but in the raw display coordinate space rather than in |
| 1224 | // the logical coordinate space. |
| 1225 | int32_t mPhysicalWidth; |
| 1226 | int32_t mPhysicalHeight; |
| 1227 | int32_t mPhysicalLeft; |
| 1228 | int32_t mPhysicalTop; |
| 1229 | |
| 1230 | // The orientation may be different from the viewport orientation as it specifies |
| 1231 | // the rotation of the surface coordinates required to produce the viewport's |
| 1232 | // requested orientation, so it will depend on whether the device is orientation aware. |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1233 | int32_t mSurfaceOrientation; |
| 1234 | |
| 1235 | // Translation and scaling factors, orientation-independent. |
| 1236 | float mXTranslate; |
| 1237 | float mXScale; |
| 1238 | float mXPrecision; |
| 1239 | |
| 1240 | float mYTranslate; |
| 1241 | float mYScale; |
| 1242 | float mYPrecision; |
| 1243 | |
| 1244 | float mGeometricScale; |
| 1245 | |
| 1246 | float mPressureScale; |
| 1247 | |
| 1248 | float mSizeScale; |
| 1249 | |
| 1250 | float mOrientationScale; |
| 1251 | |
| 1252 | float mDistanceScale; |
| 1253 | |
| 1254 | bool mHaveTilt; |
| 1255 | float mTiltXCenter; |
| 1256 | float mTiltXScale; |
| 1257 | float mTiltYCenter; |
| 1258 | float mTiltYScale; |
| 1259 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1260 | bool mExternalStylusConnected; |
| 1261 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1262 | // Oriented motion ranges for input device info. |
| 1263 | struct OrientedRanges { |
| 1264 | InputDeviceInfo::MotionRange x; |
| 1265 | InputDeviceInfo::MotionRange y; |
| 1266 | InputDeviceInfo::MotionRange pressure; |
| 1267 | |
| 1268 | bool haveSize; |
| 1269 | InputDeviceInfo::MotionRange size; |
| 1270 | |
| 1271 | bool haveTouchSize; |
| 1272 | InputDeviceInfo::MotionRange touchMajor; |
| 1273 | InputDeviceInfo::MotionRange touchMinor; |
| 1274 | |
| 1275 | bool haveToolSize; |
| 1276 | InputDeviceInfo::MotionRange toolMajor; |
| 1277 | InputDeviceInfo::MotionRange toolMinor; |
| 1278 | |
| 1279 | bool haveOrientation; |
| 1280 | InputDeviceInfo::MotionRange orientation; |
| 1281 | |
| 1282 | bool haveDistance; |
| 1283 | InputDeviceInfo::MotionRange distance; |
| 1284 | |
| 1285 | bool haveTilt; |
| 1286 | InputDeviceInfo::MotionRange tilt; |
| 1287 | |
| 1288 | OrientedRanges() { |
| 1289 | clear(); |
| 1290 | } |
| 1291 | |
| 1292 | void clear() { |
| 1293 | haveSize = false; |
| 1294 | haveTouchSize = false; |
| 1295 | haveToolSize = false; |
| 1296 | haveOrientation = false; |
| 1297 | haveDistance = false; |
| 1298 | haveTilt = false; |
| 1299 | } |
| 1300 | } mOrientedRanges; |
| 1301 | |
| 1302 | // Oriented dimensions and precision. |
| 1303 | float mOrientedXPrecision; |
| 1304 | float mOrientedYPrecision; |
| 1305 | |
| 1306 | struct CurrentVirtualKeyState { |
| 1307 | bool down; |
| 1308 | bool ignored; |
| 1309 | nsecs_t downTime; |
| 1310 | int32_t keyCode; |
| 1311 | int32_t scanCode; |
| 1312 | } mCurrentVirtualKey; |
| 1313 | |
| 1314 | // Scale factor for gesture or mouse based pointer movements. |
| 1315 | float mPointerXMovementScale; |
| 1316 | float mPointerYMovementScale; |
| 1317 | |
| 1318 | // Scale factor for gesture based zooming and other freeform motions. |
| 1319 | float mPointerXZoomScale; |
| 1320 | float mPointerYZoomScale; |
| 1321 | |
| 1322 | // The maximum swipe width. |
| 1323 | float mPointerGestureMaxSwipeWidth; |
| 1324 | |
| 1325 | struct PointerDistanceHeapElement { |
| 1326 | uint32_t currentPointerIndex : 8; |
| 1327 | uint32_t lastPointerIndex : 8; |
| 1328 | uint64_t distance : 48; // squared distance |
| 1329 | }; |
| 1330 | |
| 1331 | enum PointerUsage { |
| 1332 | POINTER_USAGE_NONE, |
| 1333 | POINTER_USAGE_GESTURES, |
| 1334 | POINTER_USAGE_STYLUS, |
| 1335 | POINTER_USAGE_MOUSE, |
| 1336 | }; |
| 1337 | PointerUsage mPointerUsage; |
| 1338 | |
| 1339 | struct PointerGesture { |
| 1340 | enum Mode { |
| 1341 | // No fingers, button is not pressed. |
| 1342 | // Nothing happening. |
| 1343 | NEUTRAL, |
| 1344 | |
| 1345 | // No fingers, button is not pressed. |
| 1346 | // Tap detected. |
| 1347 | // Emits DOWN and UP events at the pointer location. |
| 1348 | TAP, |
| 1349 | |
| 1350 | // Exactly one finger dragging following a tap. |
| 1351 | // Pointer follows the active finger. |
| 1352 | // Emits DOWN, MOVE and UP events at the pointer location. |
| 1353 | // |
| 1354 | // Detect double-taps when the finger goes up while in TAP_DRAG mode. |
| 1355 | TAP_DRAG, |
| 1356 | |
| 1357 | // Button is pressed. |
| 1358 | // Pointer follows the active finger if there is one. Other fingers are ignored. |
| 1359 | // Emits DOWN, MOVE and UP events at the pointer location. |
| 1360 | BUTTON_CLICK_OR_DRAG, |
| 1361 | |
| 1362 | // Exactly one finger, button is not pressed. |
| 1363 | // Pointer follows the active finger. |
| 1364 | // Emits HOVER_MOVE events at the pointer location. |
| 1365 | // |
| 1366 | // Detect taps when the finger goes up while in HOVER mode. |
| 1367 | HOVER, |
| 1368 | |
| 1369 | // Exactly two fingers but neither have moved enough to clearly indicate |
| 1370 | // whether a swipe or freeform gesture was intended. We consider the |
| 1371 | // pointer to be pressed so this enables clicking or long-pressing on buttons. |
| 1372 | // Pointer does not move. |
| 1373 | // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate. |
| 1374 | PRESS, |
| 1375 | |
| 1376 | // Exactly two fingers moving in the same direction, button is not pressed. |
| 1377 | // Pointer does not move. |
| 1378 | // Emits DOWN, MOVE and UP events with a single pointer coordinate that |
| 1379 | // follows the midpoint between both fingers. |
| 1380 | SWIPE, |
| 1381 | |
| 1382 | // Two or more fingers moving in arbitrary directions, button is not pressed. |
| 1383 | // Pointer does not move. |
| 1384 | // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow |
| 1385 | // each finger individually relative to the initial centroid of the finger. |
| 1386 | FREEFORM, |
| 1387 | |
| 1388 | // Waiting for quiet time to end before starting the next gesture. |
| 1389 | QUIET, |
| 1390 | }; |
| 1391 | |
| 1392 | // Time the first finger went down. |
| 1393 | nsecs_t firstTouchTime; |
| 1394 | |
| 1395 | // The active pointer id from the raw touch data. |
| 1396 | int32_t activeTouchId; // -1 if none |
| 1397 | |
| 1398 | // The active pointer id from the gesture last delivered to the application. |
| 1399 | int32_t activeGestureId; // -1 if none |
| 1400 | |
| 1401 | // Pointer coords and ids for the current and previous pointer gesture. |
| 1402 | Mode currentGestureMode; |
| 1403 | BitSet32 currentGestureIdBits; |
| 1404 | uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1]; |
| 1405 | PointerProperties currentGestureProperties[MAX_POINTERS]; |
| 1406 | PointerCoords currentGestureCoords[MAX_POINTERS]; |
| 1407 | |
| 1408 | Mode lastGestureMode; |
| 1409 | BitSet32 lastGestureIdBits; |
| 1410 | uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1]; |
| 1411 | PointerProperties lastGestureProperties[MAX_POINTERS]; |
| 1412 | PointerCoords lastGestureCoords[MAX_POINTERS]; |
| 1413 | |
| 1414 | // Time the pointer gesture last went down. |
| 1415 | nsecs_t downTime; |
| 1416 | |
| 1417 | // Time when the pointer went down for a TAP. |
| 1418 | nsecs_t tapDownTime; |
| 1419 | |
| 1420 | // Time when the pointer went up for a TAP. |
| 1421 | nsecs_t tapUpTime; |
| 1422 | |
| 1423 | // Location of initial tap. |
| 1424 | float tapX, tapY; |
| 1425 | |
| 1426 | // Time we started waiting for quiescence. |
| 1427 | nsecs_t quietTime; |
| 1428 | |
| 1429 | // Reference points for multitouch gestures. |
| 1430 | float referenceTouchX; // reference touch X/Y coordinates in surface units |
| 1431 | float referenceTouchY; |
| 1432 | float referenceGestureX; // reference gesture X/Y coordinates in pixels |
| 1433 | float referenceGestureY; |
| 1434 | |
| 1435 | // Distance that each pointer has traveled which has not yet been |
| 1436 | // subsumed into the reference gesture position. |
| 1437 | BitSet32 referenceIdBits; |
| 1438 | struct Delta { |
| 1439 | float dx, dy; |
| 1440 | }; |
| 1441 | Delta referenceDeltas[MAX_POINTER_ID + 1]; |
| 1442 | |
| 1443 | // Describes how touch ids are mapped to gesture ids for freeform gestures. |
| 1444 | uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1]; |
| 1445 | |
| 1446 | // A velocity tracker for determining whether to switch active pointers during drags. |
| 1447 | VelocityTracker velocityTracker; |
| 1448 | |
| 1449 | void reset() { |
| 1450 | firstTouchTime = LLONG_MIN; |
| 1451 | activeTouchId = -1; |
| 1452 | activeGestureId = -1; |
| 1453 | currentGestureMode = NEUTRAL; |
| 1454 | currentGestureIdBits.clear(); |
| 1455 | lastGestureMode = NEUTRAL; |
| 1456 | lastGestureIdBits.clear(); |
| 1457 | downTime = 0; |
| 1458 | velocityTracker.clear(); |
| 1459 | resetTap(); |
| 1460 | resetQuietTime(); |
| 1461 | } |
| 1462 | |
| 1463 | void resetTap() { |
| 1464 | tapDownTime = LLONG_MIN; |
| 1465 | tapUpTime = LLONG_MIN; |
| 1466 | } |
| 1467 | |
| 1468 | void resetQuietTime() { |
| 1469 | quietTime = LLONG_MIN; |
| 1470 | } |
| 1471 | } mPointerGesture; |
| 1472 | |
| 1473 | struct PointerSimple { |
| 1474 | PointerCoords currentCoords; |
| 1475 | PointerProperties currentProperties; |
| 1476 | PointerCoords lastCoords; |
| 1477 | PointerProperties lastProperties; |
| 1478 | |
| 1479 | // True if the pointer is down. |
| 1480 | bool down; |
| 1481 | |
| 1482 | // True if the pointer is hovering. |
| 1483 | bool hovering; |
| 1484 | |
| 1485 | // Time the pointer last went down. |
| 1486 | nsecs_t downTime; |
| 1487 | |
| 1488 | void reset() { |
| 1489 | currentCoords.clear(); |
| 1490 | currentProperties.clear(); |
| 1491 | lastCoords.clear(); |
| 1492 | lastProperties.clear(); |
| 1493 | down = false; |
| 1494 | hovering = false; |
| 1495 | downTime = 0; |
| 1496 | } |
| 1497 | } mPointerSimple; |
| 1498 | |
| 1499 | // The pointer and scroll velocity controls. |
| 1500 | VelocityControl mPointerVelocityControl; |
| 1501 | VelocityControl mWheelXVelocityControl; |
| 1502 | VelocityControl mWheelYVelocityControl; |
| 1503 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1504 | void resetExternalStylus(); |
Michael Wright | 43fd19f | 2015-04-21 19:02:58 +0100 | [diff] [blame] | 1505 | void clearStylusDataPendingFlags(); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1506 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1507 | void sync(nsecs_t when); |
| 1508 | |
| 1509 | bool consumeRawTouches(nsecs_t when, uint32_t policyFlags); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1510 | void processRawTouches(bool timeout); |
| 1511 | void cookAndDispatch(nsecs_t when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1512 | void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags, |
| 1513 | int32_t keyEventAction, int32_t keyEventFlags); |
| 1514 | |
| 1515 | void dispatchTouches(nsecs_t when, uint32_t policyFlags); |
| 1516 | void dispatchHoverExit(nsecs_t when, uint32_t policyFlags); |
| 1517 | void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags); |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 1518 | void dispatchButtonRelease(nsecs_t when, uint32_t policyFlags); |
| 1519 | void dispatchButtonPress(nsecs_t when, uint32_t policyFlags); |
| 1520 | const BitSet32& findActiveIdBits(const CookedPointerData& cookedPointerData); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1521 | void cookPointerData(); |
Michael Wright | 8e81282 | 2015-06-22 16:18:21 +0100 | [diff] [blame] | 1522 | void abortTouches(nsecs_t when, uint32_t policyFlags); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1523 | |
| 1524 | void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage); |
| 1525 | void abortPointerUsage(nsecs_t when, uint32_t policyFlags); |
| 1526 | |
| 1527 | void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout); |
| 1528 | void abortPointerGestures(nsecs_t when, uint32_t policyFlags); |
| 1529 | bool preparePointerGestures(nsecs_t when, |
| 1530 | bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, |
| 1531 | bool isTimeout); |
| 1532 | |
| 1533 | void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags); |
| 1534 | void abortPointerStylus(nsecs_t when, uint32_t policyFlags); |
| 1535 | |
| 1536 | void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags); |
| 1537 | void abortPointerMouse(nsecs_t when, uint32_t policyFlags); |
| 1538 | |
| 1539 | void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, |
| 1540 | bool down, bool hovering); |
| 1541 | void abortPointerSimple(nsecs_t when, uint32_t policyFlags); |
| 1542 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1543 | bool assignExternalStylusId(const RawState& state, bool timeout); |
| 1544 | void applyExternalStylusButtonState(nsecs_t when); |
| 1545 | void applyExternalStylusTouchState(nsecs_t when); |
| 1546 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1547 | // Dispatches a motion event. |
| 1548 | // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the |
| 1549 | // method will take care of setting the index and transmuting the action to DOWN or UP |
| 1550 | // it is the first / last pointer to go down / up. |
| 1551 | void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source, |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 1552 | int32_t action, int32_t actionButton, |
| 1553 | int32_t flags, int32_t metaState, int32_t buttonState, int32_t edgeFlags, |
Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 1554 | uint32_t deviceTimestamp, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1555 | const PointerProperties* properties, const PointerCoords* coords, |
| 1556 | const uint32_t* idToIndex, BitSet32 idBits, |
| 1557 | int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime); |
| 1558 | |
| 1559 | // Updates pointer coords and properties for pointers with specified ids that have moved. |
| 1560 | // Returns true if any of them changed. |
| 1561 | bool updateMovedPointers(const PointerProperties* inProperties, |
| 1562 | const PointerCoords* inCoords, const uint32_t* inIdToIndex, |
| 1563 | PointerProperties* outProperties, PointerCoords* outCoords, |
| 1564 | const uint32_t* outIdToIndex, BitSet32 idBits) const; |
| 1565 | |
| 1566 | bool isPointInsideSurface(int32_t x, int32_t y); |
| 1567 | const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y); |
| 1568 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1569 | static void assignPointerIds(const RawState* last, RawState* current); |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 1570 | |
| 1571 | const char* modeToString(DeviceMode deviceMode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1572 | }; |
| 1573 | |
| 1574 | |
| 1575 | class SingleTouchInputMapper : public TouchInputMapper { |
| 1576 | public: |
Chih-Hung Hsieh | 6d2ede1 | 2016-09-01 11:28:23 -0700 | [diff] [blame] | 1577 | explicit SingleTouchInputMapper(InputDevice* device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1578 | virtual ~SingleTouchInputMapper(); |
| 1579 | |
| 1580 | virtual void reset(nsecs_t when); |
| 1581 | virtual void process(const RawEvent* rawEvent); |
| 1582 | |
| 1583 | protected: |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1584 | virtual void syncTouch(nsecs_t when, RawState* outState); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1585 | virtual void configureRawPointerAxes(); |
| 1586 | virtual bool hasStylus() const; |
| 1587 | |
| 1588 | private: |
| 1589 | SingleTouchMotionAccumulator mSingleTouchMotionAccumulator; |
| 1590 | }; |
| 1591 | |
| 1592 | |
| 1593 | class MultiTouchInputMapper : public TouchInputMapper { |
| 1594 | public: |
Chih-Hung Hsieh | 6d2ede1 | 2016-09-01 11:28:23 -0700 | [diff] [blame] | 1595 | explicit MultiTouchInputMapper(InputDevice* device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1596 | virtual ~MultiTouchInputMapper(); |
| 1597 | |
| 1598 | virtual void reset(nsecs_t when); |
| 1599 | virtual void process(const RawEvent* rawEvent); |
| 1600 | |
| 1601 | protected: |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1602 | virtual void syncTouch(nsecs_t when, RawState* outState); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1603 | virtual void configureRawPointerAxes(); |
| 1604 | virtual bool hasStylus() const; |
| 1605 | |
| 1606 | private: |
| 1607 | MultiTouchMotionAccumulator mMultiTouchMotionAccumulator; |
| 1608 | |
| 1609 | // Specifies the pointer id bits that are in use, and their associated tracking id. |
| 1610 | BitSet32 mPointerIdBits; |
| 1611 | int32_t mPointerTrackingIdMap[MAX_POINTER_ID + 1]; |
| 1612 | }; |
| 1613 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1614 | class ExternalStylusInputMapper : public InputMapper { |
| 1615 | public: |
Chih-Hung Hsieh | 6d2ede1 | 2016-09-01 11:28:23 -0700 | [diff] [blame] | 1616 | explicit ExternalStylusInputMapper(InputDevice* device); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1617 | virtual ~ExternalStylusInputMapper() = default; |
| 1618 | |
| 1619 | virtual uint32_t getSources(); |
| 1620 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 1621 | virtual void dump(std::string& dump); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1622 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 1623 | virtual void reset(nsecs_t when); |
| 1624 | virtual void process(const RawEvent* rawEvent); |
| 1625 | virtual void sync(nsecs_t when); |
| 1626 | |
| 1627 | private: |
| 1628 | SingleTouchMotionAccumulator mSingleTouchMotionAccumulator; |
| 1629 | RawAbsoluteAxisInfo mRawPressureAxis; |
| 1630 | TouchButtonAccumulator mTouchButtonAccumulator; |
| 1631 | |
| 1632 | StylusState mStylusState; |
| 1633 | }; |
| 1634 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1635 | |
| 1636 | class JoystickInputMapper : public InputMapper { |
| 1637 | public: |
Chih-Hung Hsieh | 6d2ede1 | 2016-09-01 11:28:23 -0700 | [diff] [blame] | 1638 | explicit JoystickInputMapper(InputDevice* device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1639 | virtual ~JoystickInputMapper(); |
| 1640 | |
| 1641 | virtual uint32_t getSources(); |
| 1642 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 1643 | virtual void dump(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1644 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 1645 | virtual void reset(nsecs_t when); |
| 1646 | virtual void process(const RawEvent* rawEvent); |
| 1647 | |
| 1648 | private: |
| 1649 | struct Axis { |
| 1650 | RawAbsoluteAxisInfo rawAxisInfo; |
| 1651 | AxisInfo axisInfo; |
| 1652 | |
| 1653 | bool explicitlyMapped; // true if the axis was explicitly assigned an axis id |
| 1654 | |
| 1655 | float scale; // scale factor from raw to normalized values |
| 1656 | float offset; // offset to add after scaling for normalization |
| 1657 | float highScale; // scale factor from raw to normalized values of high split |
| 1658 | float highOffset; // offset to add after scaling for normalization of high split |
| 1659 | |
| 1660 | float min; // normalized inclusive minimum |
| 1661 | float max; // normalized inclusive maximum |
| 1662 | float flat; // normalized flat region size |
| 1663 | float fuzz; // normalized error tolerance |
| 1664 | float resolution; // normalized resolution in units/mm |
| 1665 | |
| 1666 | float filter; // filter out small variations of this size |
| 1667 | float currentValue; // current value |
| 1668 | float newValue; // most recent value |
| 1669 | float highCurrentValue; // current value of high split |
| 1670 | float highNewValue; // most recent value of high split |
| 1671 | |
| 1672 | void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo, |
| 1673 | bool explicitlyMapped, float scale, float offset, |
| 1674 | float highScale, float highOffset, |
| 1675 | float min, float max, float flat, float fuzz, float resolution) { |
| 1676 | this->rawAxisInfo = rawAxisInfo; |
| 1677 | this->axisInfo = axisInfo; |
| 1678 | this->explicitlyMapped = explicitlyMapped; |
| 1679 | this->scale = scale; |
| 1680 | this->offset = offset; |
| 1681 | this->highScale = highScale; |
| 1682 | this->highOffset = highOffset; |
| 1683 | this->min = min; |
| 1684 | this->max = max; |
| 1685 | this->flat = flat; |
| 1686 | this->fuzz = fuzz; |
| 1687 | this->resolution = resolution; |
| 1688 | this->filter = 0; |
| 1689 | resetValue(); |
| 1690 | } |
| 1691 | |
| 1692 | void resetValue() { |
| 1693 | this->currentValue = 0; |
| 1694 | this->newValue = 0; |
| 1695 | this->highCurrentValue = 0; |
| 1696 | this->highNewValue = 0; |
| 1697 | } |
| 1698 | }; |
| 1699 | |
| 1700 | // Axes indexed by raw ABS_* axis index. |
| 1701 | KeyedVector<int32_t, Axis> mAxes; |
| 1702 | |
| 1703 | void sync(nsecs_t when, bool force); |
| 1704 | |
| 1705 | bool haveAxis(int32_t axisId); |
| 1706 | void pruneAxes(bool ignoreExplicitlyMappedAxes); |
| 1707 | bool filterAxes(bool force); |
| 1708 | |
| 1709 | static bool hasValueChangedSignificantly(float filter, |
| 1710 | float newValue, float currentValue, float min, float max); |
| 1711 | static bool hasMovedNearerToValueWithinFilteredRange(float filter, |
| 1712 | float newValue, float currentValue, float thresholdValue); |
| 1713 | |
| 1714 | static bool isCenteredAxis(int32_t axis); |
| 1715 | static int32_t getCompatAxis(int32_t axis); |
| 1716 | |
| 1717 | static void addMotionRange(int32_t axisId, const Axis& axis, InputDeviceInfo* info); |
| 1718 | static void setPointerCoordsAxisValue(PointerCoords* pointerCoords, int32_t axis, |
| 1719 | float value); |
| 1720 | }; |
| 1721 | |
| 1722 | } // namespace android |
| 1723 | |
| 1724 | #endif // _UI_INPUT_READER_H |