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