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