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