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