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