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