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