Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 18 | |
Harry Cutts | 3f570c7 | 2024-04-05 16:44:28 +0000 | [diff] [blame] | 19 | #include <array> |
| 20 | #include <climits> |
| 21 | #include <limits> |
| 22 | #include <list> |
| 23 | #include <memory> |
Harry Cutts | f13161a | 2023-03-08 14:15:49 +0000 | [diff] [blame] | 24 | #include <optional> |
| 25 | #include <string> |
Harry Cutts | 3f570c7 | 2024-04-05 16:44:28 +0000 | [diff] [blame] | 26 | #include <utility> |
| 27 | #include <vector> |
Harry Cutts | f13161a | 2023-03-08 14:15:49 +0000 | [diff] [blame] | 28 | |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 29 | #include <stdint.h> |
Harry Cutts | 3f570c7 | 2024-04-05 16:44:28 +0000 | [diff] [blame] | 30 | #include <gui/constants.h> |
| 31 | #include <input/DisplayViewport.h> |
| 32 | #include <input/Input.h> |
| 33 | #include <input/InputDevice.h> |
| 34 | #include <input/VelocityControl.h> |
| 35 | #include <input/VelocityTracker.h> |
| 36 | #include <ui/Rect.h> |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 37 | #include <ui/Rotation.h> |
Harry Cutts | 3f570c7 | 2024-04-05 16:44:28 +0000 | [diff] [blame] | 38 | #include <ui/Size.h> |
| 39 | #include <ui/Transform.h> |
| 40 | #include <utils/BitSet.h> |
| 41 | #include <utils/Timers.h> |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 42 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 43 | #include "CursorButtonAccumulator.h" |
| 44 | #include "CursorScrollAccumulator.h" |
| 45 | #include "EventHub.h" |
| 46 | #include "InputMapper.h" |
| 47 | #include "InputReaderBase.h" |
Harry Cutts | 3f570c7 | 2024-04-05 16:44:28 +0000 | [diff] [blame] | 48 | #include "NotifyArgs.h" |
| 49 | #include "PointerControllerInterface.h" |
| 50 | #include "StylusState.h" |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 51 | #include "TouchButtonAccumulator.h" |
| 52 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 53 | namespace android { |
| 54 | |
Prabir Pradhan | 7d04c4b | 2022-10-28 19:23:26 +0000 | [diff] [blame] | 55 | // Maximum amount of latency to add to touch events while waiting for data from an |
| 56 | // external stylus. |
| 57 | static constexpr nsecs_t EXTERNAL_STYLUS_DATA_TIMEOUT = ms2ns(72); |
| 58 | |
| 59 | // Maximum amount of time to wait on touch data before pushing out new pressure data. |
| 60 | static constexpr nsecs_t TOUCH_DATA_TIMEOUT = ms2ns(20); |
| 61 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 62 | /* Raw axis information from the driver. */ |
| 63 | struct RawPointerAxes { |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 64 | RawAbsoluteAxisInfo x{}; |
| 65 | RawAbsoluteAxisInfo y{}; |
| 66 | RawAbsoluteAxisInfo pressure{}; |
| 67 | RawAbsoluteAxisInfo touchMajor{}; |
| 68 | RawAbsoluteAxisInfo touchMinor{}; |
| 69 | RawAbsoluteAxisInfo toolMajor{}; |
| 70 | RawAbsoluteAxisInfo toolMinor{}; |
| 71 | RawAbsoluteAxisInfo orientation{}; |
| 72 | RawAbsoluteAxisInfo distance{}; |
| 73 | RawAbsoluteAxisInfo tiltX{}; |
| 74 | RawAbsoluteAxisInfo tiltY{}; |
| 75 | RawAbsoluteAxisInfo trackingId{}; |
| 76 | RawAbsoluteAxisInfo slot{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 77 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 78 | inline int32_t getRawWidth() const { return x.maxValue - x.minValue + 1; } |
| 79 | inline int32_t getRawHeight() const { return y.maxValue - y.minValue + 1; } |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 80 | inline void clear() { *this = RawPointerAxes(); } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 83 | using PropertiesArray = std::array<PointerProperties, MAX_POINTERS>; |
| 84 | using CoordsArray = std::array<PointerCoords, MAX_POINTERS>; |
| 85 | using IdToIndexArray = std::array<uint32_t, MAX_POINTER_ID + 1>; |
| 86 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 87 | /* Raw data for a collection of pointers including a pointer id mapping table. */ |
| 88 | struct RawPointerData { |
| 89 | struct Pointer { |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 90 | uint32_t id{0xFFFFFFFF}; |
| 91 | int32_t x{}; |
| 92 | int32_t y{}; |
| 93 | int32_t pressure{}; |
| 94 | int32_t touchMajor{}; |
| 95 | int32_t touchMinor{}; |
| 96 | int32_t toolMajor{}; |
| 97 | int32_t toolMinor{}; |
| 98 | int32_t orientation{}; |
| 99 | int32_t distance{}; |
| 100 | int32_t tiltX{}; |
| 101 | int32_t tiltY{}; |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 102 | // A fully decoded ToolType constant. |
| 103 | ToolType toolType{ToolType::UNKNOWN}; |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 104 | bool isHovering{false}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 107 | uint32_t pointerCount{}; |
| 108 | std::array<Pointer, MAX_POINTERS> pointers{}; |
| 109 | BitSet32 hoveringIdBits{}, touchingIdBits{}, canceledIdBits{}; |
| 110 | IdToIndexArray idToIndex{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 111 | |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 112 | inline void clear() { *this = RawPointerData(); } |
| 113 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 114 | void getCentroidOfTouchingPointers(float* outX, float* outY) const; |
| 115 | |
| 116 | inline void markIdBit(uint32_t id, bool isHovering) { |
| 117 | if (isHovering) { |
| 118 | hoveringIdBits.markBit(id); |
| 119 | } else { |
| 120 | touchingIdBits.markBit(id); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | inline void clearIdBits() { |
| 125 | hoveringIdBits.clear(); |
| 126 | touchingIdBits.clear(); |
arthurhung | cc7f980 | 2020-04-30 17:55:40 +0800 | [diff] [blame] | 127 | canceledIdBits.clear(); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | inline const Pointer& pointerForId(uint32_t id) const { return pointers[idToIndex[id]]; } |
| 131 | |
| 132 | inline bool isHovering(uint32_t pointerIndex) { return pointers[pointerIndex].isHovering; } |
| 133 | }; |
| 134 | |
| 135 | /* Cooked data for a collection of pointers including a pointer id mapping table. */ |
| 136 | struct CookedPointerData { |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 137 | uint32_t pointerCount{}; |
| 138 | PropertiesArray pointerProperties{}; |
| 139 | CoordsArray pointerCoords{}; |
| 140 | BitSet32 hoveringIdBits{}, touchingIdBits{}, canceledIdBits{}, validIdBits{}; |
| 141 | IdToIndexArray idToIndex{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 142 | |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 143 | inline void clear() { *this = CookedPointerData(); } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 144 | |
| 145 | inline const PointerCoords& pointerCoordsForId(uint32_t id) const { |
| 146 | return pointerCoords[idToIndex[id]]; |
| 147 | } |
| 148 | |
| 149 | inline PointerCoords& editPointerCoordsWithId(uint32_t id) { |
| 150 | return pointerCoords[idToIndex[id]]; |
| 151 | } |
| 152 | |
| 153 | inline PointerProperties& editPointerPropertiesWithId(uint32_t id) { |
| 154 | return pointerProperties[idToIndex[id]]; |
| 155 | } |
| 156 | |
| 157 | inline bool isHovering(uint32_t pointerIndex) const { |
| 158 | return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id); |
| 159 | } |
| 160 | |
| 161 | inline bool isTouching(uint32_t pointerIndex) const { |
| 162 | return touchingIdBits.hasBit(pointerProperties[pointerIndex].id); |
| 163 | } |
Nathaniel R. Lewis | adb58ea | 2019-08-21 04:46:29 +0000 | [diff] [blame] | 164 | |
| 165 | inline bool hasPointerCoordsForId(uint32_t id) const { return validIdBits.hasBit(id); } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | class TouchInputMapper : public InputMapper { |
| 169 | public: |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 170 | ~TouchInputMapper() override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 171 | |
Philip Junker | 4af3b3d | 2021-12-14 10:36:55 +0100 | [diff] [blame] | 172 | uint32_t getSources() const override; |
Harry Cutts | d02ea10 | 2023-03-17 18:21:30 +0000 | [diff] [blame] | 173 | void populateDeviceInfo(InputDeviceInfo& deviceInfo) override; |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 174 | void dump(std::string& dump) override; |
Arpit Singh | 4be4eef | 2023-03-28 14:26:01 +0000 | [diff] [blame] | 175 | [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, |
Arpit Singh | ed6c3de | 2023-04-05 19:24:37 +0000 | [diff] [blame] | 176 | const InputReaderConfiguration& config, |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 177 | ConfigurationChanges changes) override; |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 178 | [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; |
| 179 | [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 180 | |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 181 | int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) override; |
| 182 | int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override; |
Siarhei Vishniakou | 7400794 | 2022-06-13 13:57:47 -0700 | [diff] [blame] | 183 | bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes, |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 184 | uint8_t* outFlags) override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 185 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 186 | [[nodiscard]] std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime) override; |
| 187 | [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when) override; |
| 188 | [[nodiscard]] std::list<NotifyArgs> updateExternalStylusState( |
| 189 | const StylusState& state) override; |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 190 | std::optional<int32_t> getAssociatedDisplayId() override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 191 | |
| 192 | protected: |
| 193 | CursorButtonAccumulator mCursorButtonAccumulator; |
| 194 | CursorScrollAccumulator mCursorScrollAccumulator; |
| 195 | TouchButtonAccumulator mTouchButtonAccumulator; |
| 196 | |
| 197 | struct VirtualKey { |
| 198 | int32_t keyCode; |
| 199 | int32_t scanCode; |
| 200 | uint32_t flags; |
| 201 | |
| 202 | // computed hit box, specified in touch screen coords based on known display size |
| 203 | int32_t hitLeft; |
| 204 | int32_t hitTop; |
| 205 | int32_t hitRight; |
| 206 | int32_t hitBottom; |
| 207 | |
| 208 | inline bool isHit(int32_t x, int32_t y) const { |
| 209 | return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom; |
| 210 | } |
| 211 | }; |
| 212 | |
| 213 | // Input sources and device mode. |
Arpit Singh | 403e53c | 2023-04-18 11:46:56 +0000 | [diff] [blame] | 214 | uint32_t mSource{0}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 215 | |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 216 | enum class DeviceMode { |
| 217 | DISABLED, // input is disabled |
| 218 | DIRECT, // direct mapping (touchscreen) |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 219 | NAVIGATION, // unscaled mapping with assist gesture (touch navigation) |
Harry Cutts | e3aaf39 | 2023-06-19 17:13:43 +0000 | [diff] [blame] | 220 | POINTER, // pointer mapping (e.g. uncaptured touchpad, drawing tablet) |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 221 | |
| 222 | ftl_last = POINTER |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 223 | }; |
Arpit Singh | 403e53c | 2023-04-18 11:46:56 +0000 | [diff] [blame] | 224 | DeviceMode mDeviceMode{DeviceMode::DISABLED}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 225 | |
| 226 | // The reader's configuration. |
| 227 | InputReaderConfiguration mConfig; |
| 228 | |
| 229 | // Immutable configuration parameters. |
| 230 | struct Parameters { |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 231 | enum class DeviceType { |
| 232 | TOUCH_SCREEN, |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 233 | TOUCH_NAVIGATION, |
| 234 | POINTER, |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 235 | |
| 236 | ftl_last = POINTER |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 237 | }; |
| 238 | |
| 239 | DeviceType deviceType; |
| 240 | bool hasAssociatedDisplay; |
| 241 | bool associatedDisplayIsExternal; |
| 242 | bool orientationAware; |
Prabir Pradhan | ac1c74f | 2021-08-20 16:09:32 -0700 | [diff] [blame] | 243 | |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 244 | ui::Rotation orientation; |
Prabir Pradhan | ac1c74f | 2021-08-20 16:09:32 -0700 | [diff] [blame] | 245 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 246 | bool hasButtonUnderPad; |
| 247 | std::string uniqueDisplayId; |
| 248 | |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 249 | enum class GestureMode { |
| 250 | SINGLE_TOUCH, |
| 251 | MULTI_TOUCH, |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 252 | |
| 253 | ftl_last = MULTI_TOUCH |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 254 | }; |
| 255 | GestureMode gestureMode; |
| 256 | |
| 257 | bool wake; |
Prabir Pradhan | 167c270 | 2022-09-14 00:37:24 +0000 | [diff] [blame] | 258 | |
Prabir Pradhan | e04ffaa | 2022-12-13 23:04:04 +0000 | [diff] [blame] | 259 | // The Universal Stylus Initiative (USI) protocol version supported by this device. |
| 260 | std::optional<InputDeviceUsiVersion> usiVersion; |
Yuncheol Heo | 50c19b1 | 2022-11-02 20:33:08 -0700 | [diff] [blame] | 261 | |
| 262 | // Allows touches while the display is off. |
| 263 | bool enableForInactiveViewport; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 264 | } mParameters; |
| 265 | |
| 266 | // Immutable calibration parameters in parsed form. |
| 267 | struct Calibration { |
| 268 | // Size |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 269 | enum class SizeCalibration { |
| 270 | DEFAULT, |
| 271 | NONE, |
| 272 | GEOMETRIC, |
| 273 | DIAMETER, |
| 274 | BOX, |
| 275 | AREA, |
Siarhei Vishniakou | 4e837cc | 2021-12-20 23:24:33 -0800 | [diff] [blame] | 276 | ftl_last = AREA |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | SizeCalibration sizeCalibration; |
| 280 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 281 | std::optional<float> sizeScale; |
| 282 | std::optional<float> sizeBias; |
| 283 | std::optional<bool> sizeIsSummed; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 284 | |
| 285 | // Pressure |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 286 | enum class PressureCalibration { |
| 287 | DEFAULT, |
| 288 | NONE, |
| 289 | PHYSICAL, |
| 290 | AMPLITUDE, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
| 293 | PressureCalibration pressureCalibration; |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 294 | std::optional<float> pressureScale; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 295 | |
| 296 | // Orientation |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 297 | enum class OrientationCalibration { |
| 298 | DEFAULT, |
| 299 | NONE, |
| 300 | INTERPOLATED, |
| 301 | VECTOR, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | OrientationCalibration orientationCalibration; |
| 305 | |
| 306 | // Distance |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 307 | enum class DistanceCalibration { |
| 308 | DEFAULT, |
| 309 | NONE, |
| 310 | SCALED, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | DistanceCalibration distanceCalibration; |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 314 | std::optional<float> distanceScale; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 315 | |
Siarhei Vishniakou | 0724734 | 2022-07-15 14:27:37 -0700 | [diff] [blame] | 316 | inline void applySizeScaleAndBias(float& outSize) const { |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 317 | if (sizeScale) { |
Siarhei Vishniakou | 0724734 | 2022-07-15 14:27:37 -0700 | [diff] [blame] | 318 | outSize *= *sizeScale; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 319 | } |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 320 | if (sizeBias) { |
Siarhei Vishniakou | 0724734 | 2022-07-15 14:27:37 -0700 | [diff] [blame] | 321 | outSize += *sizeBias; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 322 | } |
Siarhei Vishniakou | 0724734 | 2022-07-15 14:27:37 -0700 | [diff] [blame] | 323 | if (outSize < 0) { |
| 324 | outSize = 0; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | } mCalibration; |
| 328 | |
| 329 | // Affine location transformation/calibration |
| 330 | struct TouchAffineTransformation mAffineTransform; |
| 331 | |
| 332 | RawPointerAxes mRawPointerAxes; |
| 333 | |
| 334 | struct RawState { |
Prabir Pradhan | 2f37bcb | 2022-11-08 20:41:28 +0000 | [diff] [blame] | 335 | nsecs_t when{std::numeric_limits<nsecs_t>::min()}; |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 336 | nsecs_t readTime{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 337 | |
| 338 | // Raw pointer sample data. |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 339 | RawPointerData rawPointerData{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 340 | |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 341 | int32_t buttonState{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 342 | |
| 343 | // Scroll state. |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 344 | int32_t rawVScroll{}; |
| 345 | int32_t rawHScroll{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 346 | |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 347 | inline void clear() { *this = RawState(); } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 348 | }; |
| 349 | |
| 350 | struct CookedState { |
| 351 | // Cooked pointer sample data. |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 352 | CookedPointerData cookedPointerData{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 353 | |
| 354 | // Id bits used to differentiate fingers, stylus and mouse tools. |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 355 | BitSet32 fingerIdBits{}; |
| 356 | BitSet32 stylusIdBits{}; |
| 357 | BitSet32 mouseIdBits{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 358 | |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 359 | int32_t buttonState{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 360 | |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 361 | inline void clear() { *this = CookedState(); } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 362 | }; |
| 363 | |
| 364 | std::vector<RawState> mRawStatesPending; |
| 365 | RawState mCurrentRawState; |
| 366 | CookedState mCurrentCookedState; |
| 367 | RawState mLastRawState; |
| 368 | CookedState mLastCookedState; |
| 369 | |
| 370 | // State provided by an external stylus |
| 371 | StylusState mExternalStylusState; |
Prabir Pradhan | 8d9ba91 | 2022-11-11 22:26:33 +0000 | [diff] [blame] | 372 | // If an external stylus is capable of reporting pointer-specific data like pressure, we will |
| 373 | // attempt to fuse the pointer data reported by the stylus to the first touch pointer. This is |
| 374 | // the id of the pointer to which the external stylus data is fused. |
| 375 | std::optional<uint32_t> mFusedStylusPointerId; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 376 | nsecs_t mExternalStylusFusionTimeout; |
| 377 | bool mExternalStylusDataPending; |
Prabir Pradhan | 124ea44 | 2022-10-28 20:27:44 +0000 | [diff] [blame] | 378 | // A subset of the buttons in mCurrentRawState that came from an external stylus. |
Arpit Singh | a8c236b | 2023-04-25 13:56:05 +0000 | [diff] [blame] | 379 | int32_t mExternalStylusButtonsApplied{0}; |
Prabir Pradhan | b08a0e8 | 2023-09-14 22:28:32 +0000 | [diff] [blame] | 380 | // True if the current cooked pointer data was modified due to the state of an external stylus. |
| 381 | bool mCurrentStreamModifiedByExternalStylus{false}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 382 | |
| 383 | // True if we sent a HOVER_ENTER event. |
Arpit Singh | a8c236b | 2023-04-25 13:56:05 +0000 | [diff] [blame] | 384 | bool mSentHoverEnter{false}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 385 | |
| 386 | // Have we assigned pointer IDs for this stream |
Arpit Singh | a8c236b | 2023-04-25 13:56:05 +0000 | [diff] [blame] | 387 | bool mHavePointerIds{false}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 388 | |
| 389 | // Is the current stream of direct touch events aborted |
Arpit Singh | a8c236b | 2023-04-25 13:56:05 +0000 | [diff] [blame] | 390 | bool mCurrentMotionAborted{false}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 391 | |
| 392 | // The time the primary pointer last went down. |
Arpit Singh | a8c236b | 2023-04-25 13:56:05 +0000 | [diff] [blame] | 393 | nsecs_t mDownTime{0}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 394 | |
| 395 | // The pointer controller, or null if the device is not a pointer. |
Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 396 | std::shared_ptr<PointerControllerInterface> mPointerController; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 397 | |
| 398 | std::vector<VirtualKey> mVirtualKeys; |
| 399 | |
Arpit Singh | a8c236b | 2023-04-25 13:56:05 +0000 | [diff] [blame] | 400 | explicit TouchInputMapper(InputDeviceContext& deviceContext, |
| 401 | const InputReaderConfiguration& readerConfig); |
| 402 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 403 | virtual void dumpParameters(std::string& dump); |
| 404 | virtual void configureRawPointerAxes(); |
| 405 | virtual void dumpRawPointerAxes(std::string& dump); |
Prabir Pradhan | 1728b21 | 2021-10-19 16:00:03 -0700 | [diff] [blame] | 406 | virtual void configureInputDevice(nsecs_t when, bool* outResetNeeded); |
| 407 | virtual void dumpDisplay(std::string& dump); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 408 | virtual void configureVirtualKeys(); |
| 409 | virtual void dumpVirtualKeys(std::string& dump); |
| 410 | virtual void parseCalibration(); |
| 411 | virtual void resolveCalibration(); |
| 412 | virtual void dumpCalibration(std::string& dump); |
| 413 | virtual void updateAffineTransformation(); |
| 414 | virtual void dumpAffineTransformation(std::string& dump); |
| 415 | virtual void resolveExternalStylusPresence(); |
| 416 | virtual bool hasStylus() const = 0; |
| 417 | virtual bool hasExternalStylus() const; |
| 418 | |
| 419 | virtual void syncTouch(nsecs_t when, RawState* outState) = 0; |
| 420 | |
| 421 | private: |
| 422 | // The current viewport. |
| 423 | // The components of the viewport are specified in the display's rotated orientation. |
| 424 | DisplayViewport mViewport; |
| 425 | |
Prabir Pradhan | 2d613f4 | 2022-11-10 20:22:06 +0000 | [diff] [blame] | 426 | // We refer to the display as being in the "natural orientation" when there is no rotation |
| 427 | // applied. The display size obtained from the viewport in the natural orientation. |
Prabir Pradhan | 7ddbc95 | 2022-11-09 22:03:40 +0000 | [diff] [blame] | 428 | // Always starts at (0, 0). |
| 429 | ui::Size mDisplayBounds{ui::kInvalidSize}; |
Arthur Hung | 4197f6b | 2020-03-16 15:39:59 +0800 | [diff] [blame] | 430 | |
Prabir Pradhan | 675f25a | 2022-11-10 22:04:07 +0000 | [diff] [blame] | 431 | // The physical frame is the rectangle in the rotated display's coordinate space that maps to |
Prabir Pradhan | 1728b21 | 2021-10-19 16:00:03 -0700 | [diff] [blame] | 432 | // the logical display frame. |
Prabir Pradhan | 675f25a | 2022-11-10 22:04:07 +0000 | [diff] [blame] | 433 | Rect mPhysicalFrameInRotatedDisplay{Rect::INVALID_RECT}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 434 | |
Prabir Pradhan | 1728b21 | 2021-10-19 16:00:03 -0700 | [diff] [blame] | 435 | // The orientation of the input device relative to that of the display panel. It specifies |
| 436 | // the rotation of the input device coordinates required to produce the display panel |
| 437 | // orientation, so it will depend on whether the device is orientation aware. |
Arpit Singh | 403e53c | 2023-04-18 11:46:56 +0000 | [diff] [blame] | 438 | ui::Rotation mInputDeviceOrientation{ui::ROTATION_0}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 439 | |
Prabir Pradhan | ea31d4f | 2022-11-10 20:48:01 +0000 | [diff] [blame] | 440 | // The transform that maps the input device's raw coordinate space to the un-rotated display's |
| 441 | // coordinate space. InputReader generates events in the un-rotated display's coordinate space. |
| 442 | ui::Transform mRawToDisplay; |
| 443 | |
Prabir Pradhan | 675f25a | 2022-11-10 22:04:07 +0000 | [diff] [blame] | 444 | // The transform that maps the input device's raw coordinate space to the rotated display's |
| 445 | // coordinate space. This used to perform hit-testing of raw events with the physical frame in |
| 446 | // the rotated coordinate space. See mPhysicalFrameInRotatedDisplay. |
| 447 | ui::Transform mRawToRotatedDisplay; |
| 448 | |
Prabir Pradhan | e2e10b4 | 2022-11-17 20:59:36 +0000 | [diff] [blame] | 449 | // The transform used for non-planar raw axes, such as orientation and tilt. |
| 450 | ui::Transform mRawRotation; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 451 | |
| 452 | float mGeometricScale; |
| 453 | |
| 454 | float mPressureScale; |
| 455 | |
| 456 | float mSizeScale; |
| 457 | |
| 458 | float mOrientationScale; |
| 459 | |
| 460 | float mDistanceScale; |
| 461 | |
| 462 | bool mHaveTilt; |
| 463 | float mTiltXCenter; |
| 464 | float mTiltXScale; |
| 465 | float mTiltYCenter; |
| 466 | float mTiltYScale; |
| 467 | |
| 468 | bool mExternalStylusConnected; |
| 469 | |
| 470 | // Oriented motion ranges for input device info. |
| 471 | struct OrientedRanges { |
| 472 | InputDeviceInfo::MotionRange x; |
| 473 | InputDeviceInfo::MotionRange y; |
| 474 | InputDeviceInfo::MotionRange pressure; |
| 475 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 476 | std::optional<InputDeviceInfo::MotionRange> size; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 477 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 478 | std::optional<InputDeviceInfo::MotionRange> touchMajor; |
| 479 | std::optional<InputDeviceInfo::MotionRange> touchMinor; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 480 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 481 | std::optional<InputDeviceInfo::MotionRange> toolMajor; |
| 482 | std::optional<InputDeviceInfo::MotionRange> toolMinor; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 483 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 484 | std::optional<InputDeviceInfo::MotionRange> orientation; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 485 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 486 | std::optional<InputDeviceInfo::MotionRange> distance; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 487 | |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 488 | std::optional<InputDeviceInfo::MotionRange> tilt; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 489 | |
| 490 | void clear() { |
Siarhei Vishniakou | 2421088 | 2022-07-15 09:42:04 -0700 | [diff] [blame] | 491 | size = std::nullopt; |
| 492 | touchMajor = std::nullopt; |
| 493 | touchMinor = std::nullopt; |
| 494 | toolMajor = std::nullopt; |
| 495 | toolMinor = std::nullopt; |
| 496 | orientation = std::nullopt; |
| 497 | distance = std::nullopt; |
| 498 | tilt = std::nullopt; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 499 | } |
| 500 | } mOrientedRanges; |
| 501 | |
| 502 | // Oriented dimensions and precision. |
| 503 | float mOrientedXPrecision; |
| 504 | float mOrientedYPrecision; |
| 505 | |
| 506 | struct CurrentVirtualKeyState { |
| 507 | bool down; |
| 508 | bool ignored; |
| 509 | nsecs_t downTime; |
| 510 | int32_t keyCode; |
| 511 | int32_t scanCode; |
| 512 | } mCurrentVirtualKey; |
| 513 | |
| 514 | // Scale factor for gesture or mouse based pointer movements. |
| 515 | float mPointerXMovementScale; |
| 516 | float mPointerYMovementScale; |
| 517 | |
| 518 | // Scale factor for gesture based zooming and other freeform motions. |
| 519 | float mPointerXZoomScale; |
| 520 | float mPointerYZoomScale; |
| 521 | |
HQ Liu | e6983c7 | 2022-04-19 22:14:56 +0000 | [diff] [blame] | 522 | // The maximum swipe width between pointers to detect a swipe gesture |
| 523 | // in the number of pixels.Touches that are wider than this are translated |
| 524 | // into freeform gestures. |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 525 | float mPointerGestureMaxSwipeWidth; |
| 526 | |
| 527 | struct PointerDistanceHeapElement { |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 528 | uint32_t currentPointerIndex : 8 {}; |
| 529 | uint32_t lastPointerIndex : 8 {}; |
| 530 | uint64_t distance : 48 {}; // squared distance |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 531 | }; |
| 532 | |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 533 | enum class PointerUsage { |
| 534 | NONE, |
| 535 | GESTURES, |
| 536 | STYLUS, |
| 537 | MOUSE, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 538 | }; |
Arpit Singh | a8c236b | 2023-04-25 13:56:05 +0000 | [diff] [blame] | 539 | PointerUsage mPointerUsage{PointerUsage::NONE}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 540 | |
| 541 | struct PointerGesture { |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 542 | enum class Mode { |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 543 | // No fingers, button is not pressed. |
| 544 | // Nothing happening. |
| 545 | NEUTRAL, |
| 546 | |
| 547 | // No fingers, button is not pressed. |
| 548 | // Tap detected. |
| 549 | // Emits DOWN and UP events at the pointer location. |
| 550 | TAP, |
| 551 | |
| 552 | // Exactly one finger dragging following a tap. |
| 553 | // Pointer follows the active finger. |
| 554 | // Emits DOWN, MOVE and UP events at the pointer location. |
| 555 | // |
| 556 | // Detect double-taps when the finger goes up while in TAP_DRAG mode. |
| 557 | TAP_DRAG, |
| 558 | |
| 559 | // Button is pressed. |
| 560 | // Pointer follows the active finger if there is one. Other fingers are ignored. |
| 561 | // Emits DOWN, MOVE and UP events at the pointer location. |
| 562 | BUTTON_CLICK_OR_DRAG, |
| 563 | |
| 564 | // Exactly one finger, button is not pressed. |
| 565 | // Pointer follows the active finger. |
| 566 | // Emits HOVER_MOVE events at the pointer location. |
| 567 | // |
| 568 | // Detect taps when the finger goes up while in HOVER mode. |
| 569 | HOVER, |
| 570 | |
| 571 | // Exactly two fingers but neither have moved enough to clearly indicate |
| 572 | // whether a swipe or freeform gesture was intended. We consider the |
| 573 | // pointer to be pressed so this enables clicking or long-pressing on buttons. |
| 574 | // Pointer does not move. |
| 575 | // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate. |
| 576 | PRESS, |
| 577 | |
| 578 | // Exactly two fingers moving in the same direction, button is not pressed. |
| 579 | // Pointer does not move. |
| 580 | // Emits DOWN, MOVE and UP events with a single pointer coordinate that |
| 581 | // follows the midpoint between both fingers. |
| 582 | SWIPE, |
| 583 | |
| 584 | // Two or more fingers moving in arbitrary directions, button is not pressed. |
| 585 | // Pointer does not move. |
| 586 | // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow |
| 587 | // each finger individually relative to the initial centroid of the finger. |
| 588 | FREEFORM, |
| 589 | |
| 590 | // Waiting for quiet time to end before starting the next gesture. |
| 591 | QUIET, |
Harry Cutts | c57cd3c | 2024-04-24 13:52:55 +0000 | [diff] [blame^] | 592 | |
| 593 | ftl_last = QUIET, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 594 | }; |
| 595 | |
Prabir Pradhan | 47cf0a0 | 2021-03-11 20:30:57 -0800 | [diff] [blame] | 596 | // When a gesture is sent to an unfocused window, return true if it can bring that window |
| 597 | // into focus, false otherwise. |
| 598 | static bool canGestureAffectWindowFocus(Mode mode) { |
| 599 | switch (mode) { |
| 600 | case Mode::TAP: |
| 601 | case Mode::TAP_DRAG: |
| 602 | case Mode::BUTTON_CLICK_OR_DRAG: |
| 603 | // Taps can affect window focus. |
| 604 | return true; |
| 605 | case Mode::FREEFORM: |
| 606 | case Mode::HOVER: |
| 607 | case Mode::NEUTRAL: |
| 608 | case Mode::PRESS: |
| 609 | case Mode::QUIET: |
| 610 | case Mode::SWIPE: |
| 611 | // Most gestures can be performed on an unfocused window, so they should not |
| 612 | // not affect window focus. |
| 613 | return false; |
| 614 | } |
| 615 | } |
| 616 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 617 | // Time the first finger went down. |
| 618 | nsecs_t firstTouchTime; |
| 619 | |
| 620 | // The active pointer id from the raw touch data. |
| 621 | int32_t activeTouchId; // -1 if none |
| 622 | |
| 623 | // The active pointer id from the gesture last delivered to the application. |
| 624 | int32_t activeGestureId; // -1 if none |
| 625 | |
| 626 | // Pointer coords and ids for the current and previous pointer gesture. |
| 627 | Mode currentGestureMode; |
| 628 | BitSet32 currentGestureIdBits; |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 629 | IdToIndexArray currentGestureIdToIndex{}; |
| 630 | PropertiesArray currentGestureProperties{}; |
| 631 | CoordsArray currentGestureCoords{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 632 | |
| 633 | Mode lastGestureMode; |
| 634 | BitSet32 lastGestureIdBits; |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 635 | IdToIndexArray lastGestureIdToIndex{}; |
| 636 | PropertiesArray lastGestureProperties{}; |
| 637 | CoordsArray lastGestureCoords{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 638 | |
| 639 | // Time the pointer gesture last went down. |
| 640 | nsecs_t downTime; |
| 641 | |
| 642 | // Time when the pointer went down for a TAP. |
| 643 | nsecs_t tapDownTime; |
| 644 | |
| 645 | // Time when the pointer went up for a TAP. |
| 646 | nsecs_t tapUpTime; |
| 647 | |
| 648 | // Location of initial tap. |
| 649 | float tapX, tapY; |
| 650 | |
| 651 | // Time we started waiting for quiescence. |
| 652 | nsecs_t quietTime; |
| 653 | |
| 654 | // Reference points for multitouch gestures. |
| 655 | float referenceTouchX; // reference touch X/Y coordinates in surface units |
| 656 | float referenceTouchY; |
| 657 | float referenceGestureX; // reference gesture X/Y coordinates in pixels |
| 658 | float referenceGestureY; |
| 659 | |
| 660 | // Distance that each pointer has traveled which has not yet been |
| 661 | // subsumed into the reference gesture position. |
| 662 | BitSet32 referenceIdBits; |
| 663 | struct Delta { |
| 664 | float dx, dy; |
| 665 | }; |
| 666 | Delta referenceDeltas[MAX_POINTER_ID + 1]; |
| 667 | |
| 668 | // Describes how touch ids are mapped to gesture ids for freeform gestures. |
| 669 | uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1]; |
| 670 | |
| 671 | // A velocity tracker for determining whether to switch active pointers during drags. |
| 672 | VelocityTracker velocityTracker; |
| 673 | |
| 674 | void reset() { |
| 675 | firstTouchTime = LLONG_MIN; |
| 676 | activeTouchId = -1; |
| 677 | activeGestureId = -1; |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 678 | currentGestureMode = Mode::NEUTRAL; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 679 | currentGestureIdBits.clear(); |
Michael Wright | 227c554 | 2020-07-02 18:30:52 +0100 | [diff] [blame] | 680 | lastGestureMode = Mode::NEUTRAL; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 681 | lastGestureIdBits.clear(); |
| 682 | downTime = 0; |
| 683 | velocityTracker.clear(); |
| 684 | resetTap(); |
| 685 | resetQuietTime(); |
| 686 | } |
| 687 | |
| 688 | void resetTap() { |
| 689 | tapDownTime = LLONG_MIN; |
| 690 | tapUpTime = LLONG_MIN; |
| 691 | } |
| 692 | |
| 693 | void resetQuietTime() { quietTime = LLONG_MIN; } |
| 694 | } mPointerGesture; |
| 695 | |
| 696 | struct PointerSimple { |
| 697 | PointerCoords currentCoords; |
| 698 | PointerProperties currentProperties; |
| 699 | PointerCoords lastCoords; |
| 700 | PointerProperties lastProperties; |
| 701 | |
| 702 | // True if the pointer is down. |
| 703 | bool down; |
| 704 | |
| 705 | // True if the pointer is hovering. |
| 706 | bool hovering; |
| 707 | |
| 708 | // Time the pointer last went down. |
| 709 | nsecs_t downTime; |
| 710 | |
Prabir Pradhan | b80b6c0 | 2022-11-02 20:05:13 +0000 | [diff] [blame] | 711 | // Values reported for the last pointer event. |
| 712 | uint32_t source; |
| 713 | int32_t displayId; |
| 714 | float lastCursorX; |
| 715 | float lastCursorY; |
| 716 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 717 | void reset() { |
| 718 | currentCoords.clear(); |
| 719 | currentProperties.clear(); |
| 720 | lastCoords.clear(); |
| 721 | lastProperties.clear(); |
| 722 | down = false; |
| 723 | hovering = false; |
| 724 | downTime = 0; |
Prabir Pradhan | b80b6c0 | 2022-11-02 20:05:13 +0000 | [diff] [blame] | 725 | source = 0; |
| 726 | displayId = ADISPLAY_ID_NONE; |
| 727 | lastCursorX = 0.f; |
| 728 | lastCursorY = 0.f; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 729 | } |
| 730 | } mPointerSimple; |
| 731 | |
| 732 | // The pointer and scroll velocity controls. |
Harry Cutts | e78184b | 2024-01-08 15:54:58 +0000 | [diff] [blame] | 733 | SimpleVelocityControl mPointerVelocityControl; |
| 734 | SimpleVelocityControl mWheelXVelocityControl; |
| 735 | SimpleVelocityControl mWheelYVelocityControl; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 736 | |
| 737 | std::optional<DisplayViewport> findViewport(); |
| 738 | |
| 739 | void resetExternalStylus(); |
| 740 | void clearStylusDataPendingFlags(); |
| 741 | |
Siarhei Vishniakou | 12c0fcb | 2021-12-17 13:40:44 -0800 | [diff] [blame] | 742 | int32_t clampResolution(const char* axisName, int32_t resolution) const; |
Siarhei Vishniakou | 4e837cc | 2021-12-20 23:24:33 -0800 | [diff] [blame] | 743 | void initializeOrientedRanges(); |
| 744 | void initializeSizeRanges(); |
| 745 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 746 | [[nodiscard]] std::list<NotifyArgs> sync(nsecs_t when, nsecs_t readTime); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 747 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 748 | [[nodiscard]] std::list<NotifyArgs> consumeRawTouches(nsecs_t when, nsecs_t readTime, |
| 749 | uint32_t policyFlags, bool& outConsumed); |
| 750 | [[nodiscard]] std::list<NotifyArgs> processRawTouches(bool timeout); |
| 751 | [[nodiscard]] std::list<NotifyArgs> cookAndDispatch(nsecs_t when, nsecs_t readTime); |
| 752 | [[nodiscard]] NotifyKeyArgs dispatchVirtualKey(nsecs_t when, nsecs_t readTime, |
| 753 | uint32_t policyFlags, int32_t keyEventAction, |
| 754 | int32_t keyEventFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 755 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 756 | [[nodiscard]] std::list<NotifyArgs> dispatchTouches(nsecs_t when, nsecs_t readTime, |
| 757 | uint32_t policyFlags); |
| 758 | [[nodiscard]] std::list<NotifyArgs> dispatchHoverExit(nsecs_t when, nsecs_t readTime, |
| 759 | uint32_t policyFlags); |
| 760 | [[nodiscard]] std::list<NotifyArgs> dispatchHoverEnterAndMove(nsecs_t when, nsecs_t readTime, |
| 761 | uint32_t policyFlags); |
| 762 | [[nodiscard]] std::list<NotifyArgs> dispatchButtonRelease(nsecs_t when, nsecs_t readTime, |
| 763 | uint32_t policyFlags); |
| 764 | [[nodiscard]] std::list<NotifyArgs> dispatchButtonPress(nsecs_t when, nsecs_t readTime, |
| 765 | uint32_t policyFlags); |
LiZhihong | 758eb56 | 2022-11-03 15:28:29 +0800 | [diff] [blame] | 766 | [[nodiscard]] std::list<NotifyArgs> dispatchGestureButtonPress(nsecs_t when, |
| 767 | uint32_t policyFlags, |
| 768 | BitSet32 idBits, |
| 769 | nsecs_t readTime); |
| 770 | [[nodiscard]] std::list<NotifyArgs> dispatchGestureButtonRelease(nsecs_t when, |
| 771 | uint32_t policyFlags, |
| 772 | BitSet32 idBits, |
| 773 | nsecs_t readTime); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 774 | const BitSet32& findActiveIdBits(const CookedPointerData& cookedPointerData); |
| 775 | void cookPointerData(); |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 776 | [[nodiscard]] std::list<NotifyArgs> abortTouches(nsecs_t when, nsecs_t readTime, |
| 777 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 778 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 779 | [[nodiscard]] std::list<NotifyArgs> dispatchPointerUsage(nsecs_t when, nsecs_t readTime, |
| 780 | uint32_t policyFlags, |
| 781 | PointerUsage pointerUsage); |
| 782 | [[nodiscard]] std::list<NotifyArgs> abortPointerUsage(nsecs_t when, nsecs_t readTime, |
| 783 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 784 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 785 | [[nodiscard]] std::list<NotifyArgs> dispatchPointerGestures(nsecs_t when, nsecs_t readTime, |
| 786 | uint32_t policyFlags, |
| 787 | bool isTimeout); |
| 788 | [[nodiscard]] std::list<NotifyArgs> abortPointerGestures(nsecs_t when, nsecs_t readTime, |
| 789 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 790 | bool preparePointerGestures(nsecs_t when, bool* outCancelPreviousGesture, |
| 791 | bool* outFinishPreviousGesture, bool isTimeout); |
| 792 | |
Harry Cutts | bea6ce5 | 2022-10-14 15:17:30 +0000 | [diff] [blame] | 793 | // Returns true if we're in a period of "quiet time" when touchpad gestures should be ignored. |
| 794 | bool checkForTouchpadQuietTime(nsecs_t when); |
| 795 | |
| 796 | std::pair<int32_t, float> getFastestFinger(); |
| 797 | |
| 798 | void prepareMultiFingerPointerGestures(nsecs_t when, bool* outCancelPreviousGesture, |
| 799 | bool* outFinishPreviousGesture); |
| 800 | |
Harry Cutts | 714d1ad | 2022-08-24 16:36:43 +0000 | [diff] [blame] | 801 | // Moves the on-screen mouse pointer based on the movement of the pointer of the given ID |
| 802 | // between the last and current events. Uses a relative motion. |
| 803 | void moveMousePointerFromPointerDelta(nsecs_t when, uint32_t pointerId); |
| 804 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 805 | [[nodiscard]] std::list<NotifyArgs> dispatchPointerStylus(nsecs_t when, nsecs_t readTime, |
| 806 | uint32_t policyFlags); |
| 807 | [[nodiscard]] std::list<NotifyArgs> abortPointerStylus(nsecs_t when, nsecs_t readTime, |
| 808 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 809 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 810 | [[nodiscard]] std::list<NotifyArgs> dispatchPointerMouse(nsecs_t when, nsecs_t readTime, |
| 811 | uint32_t policyFlags); |
| 812 | [[nodiscard]] std::list<NotifyArgs> abortPointerMouse(nsecs_t when, nsecs_t readTime, |
| 813 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 814 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 815 | [[nodiscard]] std::list<NotifyArgs> dispatchPointerSimple(nsecs_t when, nsecs_t readTime, |
| 816 | uint32_t policyFlags, bool down, |
Prabir Pradhan | e71e570 | 2023-03-29 14:51:38 +0000 | [diff] [blame] | 817 | bool hovering, int32_t displayId); |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 818 | [[nodiscard]] std::list<NotifyArgs> abortPointerSimple(nsecs_t when, nsecs_t readTime, |
| 819 | uint32_t policyFlags); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 820 | |
Prabir Pradhan | 3f7545f | 2022-10-19 16:56:39 +0000 | [diff] [blame] | 821 | // Attempts to assign a pointer id to the external stylus. Returns true if the state should be |
| 822 | // withheld from further processing while waiting for data from the stylus. |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 823 | bool assignExternalStylusId(const RawState& state, bool timeout); |
| 824 | void applyExternalStylusButtonState(nsecs_t when); |
| 825 | void applyExternalStylusTouchState(nsecs_t when); |
| 826 | |
| 827 | // Dispatches a motion event. |
| 828 | // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the |
| 829 | // method will take care of setting the index and transmuting the action to DOWN or UP |
| 830 | // it is the first / last pointer to go down / up. |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 831 | [[nodiscard]] NotifyMotionArgs dispatchMotion( |
| 832 | nsecs_t when, nsecs_t readTime, uint32_t policyFlags, uint32_t source, int32_t action, |
| 833 | int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState, |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 834 | int32_t edgeFlags, const PropertiesArray& properties, const CoordsArray& coords, |
| 835 | const IdToIndexArray& idToIndex, BitSet32 idBits, int32_t changedId, float xPrecision, |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 836 | float yPrecision, nsecs_t downTime, MotionClassification classification); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 837 | |
Garfield Tan | c734e4f | 2021-01-15 20:01:39 -0800 | [diff] [blame] | 838 | // Returns if this touch device is a touch screen with an associated display. |
| 839 | bool isTouchScreen(); |
| 840 | // Updates touch spots if they are enabled. Should only be used when this device is a |
| 841 | // touchscreen. |
| 842 | void updateTouchSpots(); |
| 843 | |
Prabir Pradhan | 1728b21 | 2021-10-19 16:00:03 -0700 | [diff] [blame] | 844 | bool isPointInsidePhysicalFrame(int32_t x, int32_t y) const; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 845 | const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y); |
| 846 | |
Siarhei Vishniakou | 5747998 | 2021-03-03 01:32:21 +0000 | [diff] [blame] | 847 | static void assignPointerIds(const RawState& last, RawState& current); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 848 | |
Prabir Pradhan | 7d9cb5a | 2023-03-14 21:18:07 +0000 | [diff] [blame] | 849 | // Compute input transforms for DIRECT and POINTER modes. |
Prabir Pradhan | 675f25a | 2022-11-10 22:04:07 +0000 | [diff] [blame] | 850 | void computeInputTransforms(); |
Arpit Singh | 403e53c | 2023-04-18 11:46:56 +0000 | [diff] [blame] | 851 | static Parameters::DeviceType computeDeviceType(const InputDeviceContext& deviceContext); |
| 852 | static Parameters computeParameters(const InputDeviceContext& deviceContext); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 853 | }; |
| 854 | |
| 855 | } // namespace android |