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 | 9244aea | 2020-02-05 20:31:40 -0800 | [diff] [blame] | 17 | #include "../Macros.h" |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 18 | |
| 19 | #include "MultiTouchInputMapper.h" |
| 20 | |
Prabir Pradhan | f4d65b1 | 2022-02-10 07:15:38 -0800 | [diff] [blame] | 21 | #include <android/sysprop/InputProperties.sysprop.h> |
| 22 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 23 | namespace android { |
| 24 | |
| 25 | // --- Constants --- |
| 26 | |
| 27 | // Maximum number of slots supported when using the slot-based Multitouch Protocol B. |
| 28 | static constexpr size_t MAX_SLOTS = 32; |
| 29 | |
| 30 | // --- MultiTouchMotionAccumulator --- |
| 31 | |
| 32 | MultiTouchMotionAccumulator::MultiTouchMotionAccumulator() |
| 33 | : mCurrentSlot(-1), |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 34 | mUsingSlotsProtocol(false), |
| 35 | mHaveStylus(false) {} |
| 36 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 37 | void MultiTouchMotionAccumulator::configure(InputDeviceContext& deviceContext, size_t slotCount, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 38 | bool usingSlotsProtocol) { |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 39 | mUsingSlotsProtocol = usingSlotsProtocol; |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 40 | mHaveStylus = deviceContext.hasAbsoluteAxis(ABS_MT_TOOL_TYPE); |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 41 | mSlots = std::vector<Slot>(slotCount); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 42 | |
Prabir Pradhan | afabcde | 2022-09-27 19:32:43 +0000 | [diff] [blame^] | 43 | mCurrentSlot = -1; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 44 | if (mUsingSlotsProtocol) { |
| 45 | // Query the driver for the current slot index and use it as the initial slot |
| 46 | // before we start reading events from the device. It is possible that the |
| 47 | // current slot index will not be the same as it was when the first event was |
| 48 | // written into the evdev buffer, which means the input mapper could start |
| 49 | // out of sync with the initial state of the events in the evdev buffer. |
| 50 | // In the extremely unlikely case that this happens, the data from |
| 51 | // two slots will be confused until the next ABS_MT_SLOT event is received. |
| 52 | // This can cause the touch point to "jump", but at least there will be |
| 53 | // no stuck touches. |
| 54 | int32_t initialSlot; |
Prabir Pradhan | afabcde | 2022-09-27 19:32:43 +0000 | [diff] [blame^] | 55 | if (const auto status = deviceContext.getAbsoluteAxisValue(ABS_MT_SLOT, &initialSlot); |
| 56 | status == OK) { |
| 57 | mCurrentSlot = initialSlot; |
| 58 | } else { |
| 59 | ALOGD("Could not retrieve current multi-touch slot index. status=%d", status); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 60 | } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
Prabir Pradhan | afabcde | 2022-09-27 19:32:43 +0000 | [diff] [blame^] | 64 | void MultiTouchMotionAccumulator::resetSlots() { |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 65 | for (Slot& slot : mSlots) { |
| 66 | slot.clear(); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 67 | } |
Prabir Pradhan | afabcde | 2022-09-27 19:32:43 +0000 | [diff] [blame^] | 68 | mCurrentSlot = -1; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void MultiTouchMotionAccumulator::process(const RawEvent* rawEvent) { |
| 72 | if (rawEvent->type == EV_ABS) { |
| 73 | bool newSlot = false; |
| 74 | if (mUsingSlotsProtocol) { |
| 75 | if (rawEvent->code == ABS_MT_SLOT) { |
| 76 | mCurrentSlot = rawEvent->value; |
| 77 | newSlot = true; |
| 78 | } |
| 79 | } else if (mCurrentSlot < 0) { |
| 80 | mCurrentSlot = 0; |
| 81 | } |
| 82 | |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 83 | if (mCurrentSlot < 0 || size_t(mCurrentSlot) >= mSlots.size()) { |
Siarhei Vishniakou | e3ce49d | 2020-09-29 19:08:13 -0500 | [diff] [blame] | 84 | if (DEBUG_POINTERS) { |
| 85 | if (newSlot) { |
| 86 | ALOGW("MultiTouch device emitted invalid slot index %d but it " |
| 87 | "should be between 0 and %zd; ignoring this slot.", |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 88 | mCurrentSlot, mSlots.size() - 1); |
Siarhei Vishniakou | e3ce49d | 2020-09-29 19:08:13 -0500 | [diff] [blame] | 89 | } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 90 | } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 91 | } else { |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 92 | Slot& slot = mSlots[mCurrentSlot]; |
Arthur Hung | 9ad1894 | 2021-06-19 02:04:46 +0000 | [diff] [blame] | 93 | // If mUsingSlotsProtocol is true, it means the raw pointer has axis info of |
| 94 | // ABS_MT_TRACKING_ID and ABS_MT_SLOT, so driver should send a valid trackingId while |
| 95 | // updating the slot. |
| 96 | if (!mUsingSlotsProtocol) { |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 97 | slot.mInUse = true; |
Arthur Hung | 9ad1894 | 2021-06-19 02:04:46 +0000 | [diff] [blame] | 98 | } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 99 | |
| 100 | switch (rawEvent->code) { |
| 101 | case ABS_MT_POSITION_X: |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 102 | slot.mAbsMTPositionX = rawEvent->value; |
| 103 | warnIfNotInUse(*rawEvent, slot); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 104 | break; |
| 105 | case ABS_MT_POSITION_Y: |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 106 | slot.mAbsMTPositionY = rawEvent->value; |
| 107 | warnIfNotInUse(*rawEvent, slot); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 108 | break; |
| 109 | case ABS_MT_TOUCH_MAJOR: |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 110 | slot.mAbsMTTouchMajor = rawEvent->value; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 111 | break; |
| 112 | case ABS_MT_TOUCH_MINOR: |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 113 | slot.mAbsMTTouchMinor = rawEvent->value; |
| 114 | slot.mHaveAbsMTTouchMinor = true; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 115 | break; |
| 116 | case ABS_MT_WIDTH_MAJOR: |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 117 | slot.mAbsMTWidthMajor = rawEvent->value; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 118 | break; |
| 119 | case ABS_MT_WIDTH_MINOR: |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 120 | slot.mAbsMTWidthMinor = rawEvent->value; |
| 121 | slot.mHaveAbsMTWidthMinor = true; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 122 | break; |
| 123 | case ABS_MT_ORIENTATION: |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 124 | slot.mAbsMTOrientation = rawEvent->value; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 125 | break; |
| 126 | case ABS_MT_TRACKING_ID: |
| 127 | if (mUsingSlotsProtocol && rawEvent->value < 0) { |
| 128 | // The slot is no longer in use but it retains its previous contents, |
| 129 | // which may be reused for subsequent touches. |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 130 | slot.mInUse = false; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 131 | } else { |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 132 | slot.mInUse = true; |
| 133 | slot.mAbsMTTrackingId = rawEvent->value; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 134 | } |
| 135 | break; |
| 136 | case ABS_MT_PRESSURE: |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 137 | slot.mAbsMTPressure = rawEvent->value; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 138 | break; |
| 139 | case ABS_MT_DISTANCE: |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 140 | slot.mAbsMTDistance = rawEvent->value; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 141 | break; |
| 142 | case ABS_MT_TOOL_TYPE: |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 143 | slot.mAbsMTToolType = rawEvent->value; |
| 144 | slot.mHaveAbsMTToolType = true; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 145 | break; |
| 146 | } |
| 147 | } |
| 148 | } else if (rawEvent->type == EV_SYN && rawEvent->code == SYN_MT_REPORT) { |
| 149 | // MultiTouch Sync: The driver has returned all data for *one* of the pointers. |
| 150 | mCurrentSlot += 1; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | void MultiTouchMotionAccumulator::finishSync() { |
| 155 | if (!mUsingSlotsProtocol) { |
Prabir Pradhan | afabcde | 2022-09-27 19:32:43 +0000 | [diff] [blame^] | 156 | resetSlots(); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
| 160 | bool MultiTouchMotionAccumulator::hasStylus() const { |
| 161 | return mHaveStylus; |
| 162 | } |
| 163 | |
Arthur Hung | 9ad1894 | 2021-06-19 02:04:46 +0000 | [diff] [blame] | 164 | void MultiTouchMotionAccumulator::warnIfNotInUse(const RawEvent& event, const Slot& slot) { |
| 165 | if (!slot.mInUse) { |
| 166 | ALOGW("Received unexpected event (0x%0x, 0x%0x) for slot %i with tracking id %i", |
| 167 | event.code, event.value, mCurrentSlot, slot.mAbsMTTrackingId); |
| 168 | } |
| 169 | } |
| 170 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 171 | // --- MultiTouchMotionAccumulator::Slot --- |
| 172 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 173 | int32_t MultiTouchMotionAccumulator::Slot::getToolType() const { |
| 174 | if (mHaveAbsMTToolType) { |
| 175 | switch (mAbsMTToolType) { |
| 176 | case MT_TOOL_FINGER: |
| 177 | return AMOTION_EVENT_TOOL_TYPE_FINGER; |
| 178 | case MT_TOOL_PEN: |
| 179 | return AMOTION_EVENT_TOOL_TYPE_STYLUS; |
Arthur Hung | 421eb1c | 2020-01-16 00:09:42 +0800 | [diff] [blame] | 180 | case MT_TOOL_PALM: |
| 181 | return AMOTION_EVENT_TOOL_TYPE_PALM; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | return AMOTION_EVENT_TOOL_TYPE_UNKNOWN; |
| 185 | } |
| 186 | |
| 187 | // --- MultiTouchInputMapper --- |
| 188 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 189 | MultiTouchInputMapper::MultiTouchInputMapper(InputDeviceContext& deviceContext) |
| 190 | : TouchInputMapper(deviceContext) {} |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 191 | |
| 192 | MultiTouchInputMapper::~MultiTouchInputMapper() {} |
| 193 | |
| 194 | void MultiTouchInputMapper::reset(nsecs_t when) { |
Prabir Pradhan | afabcde | 2022-09-27 19:32:43 +0000 | [diff] [blame^] | 195 | // The evdev multi-touch protocol does not allow userspace applications to query the initial or |
| 196 | // current state of the pointers at any time. This means if we clear our accumulated state when |
| 197 | // resetting the input mapper, there's no way to rebuild the full initial state of the pointers. |
| 198 | // We can only wait for updates to all the pointers and axes. Rather than clearing the state and |
| 199 | // rebuilding the state from scratch, we work around this kernel API limitation by never |
| 200 | // fully clearing any state specific to the multi-touch protocol. |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 201 | TouchInputMapper::reset(when); |
| 202 | } |
| 203 | |
| 204 | void MultiTouchInputMapper::process(const RawEvent* rawEvent) { |
| 205 | TouchInputMapper::process(rawEvent); |
| 206 | |
| 207 | mMultiTouchMotionAccumulator.process(rawEvent); |
| 208 | } |
| 209 | |
arthurhung | cc7f980 | 2020-04-30 17:55:40 +0800 | [diff] [blame] | 210 | std::optional<int32_t> MultiTouchInputMapper::getActiveBitId( |
| 211 | const MultiTouchMotionAccumulator::Slot& inSlot) { |
| 212 | if (mHavePointerIds) { |
| 213 | int32_t trackingId = inSlot.getTrackingId(); |
| 214 | for (BitSet32 idBits(mPointerIdBits); !idBits.isEmpty();) { |
| 215 | int32_t n = idBits.clearFirstMarkedBit(); |
| 216 | if (mPointerTrackingIdMap[n] == trackingId) { |
| 217 | return std::make_optional(n); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | return std::nullopt; |
| 222 | } |
| 223 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 224 | void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { |
| 225 | size_t inCount = mMultiTouchMotionAccumulator.getSlotCount(); |
| 226 | size_t outCount = 0; |
| 227 | BitSet32 newPointerIdBits; |
| 228 | mHavePointerIds = true; |
| 229 | |
| 230 | for (size_t inIndex = 0; inIndex < inCount; inIndex++) { |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 231 | const MultiTouchMotionAccumulator::Slot& inSlot = |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 232 | mMultiTouchMotionAccumulator.getSlot(inIndex); |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 233 | if (!inSlot.isInUse()) { |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 234 | continue; |
| 235 | } |
| 236 | |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 237 | if (inSlot.getToolType() == AMOTION_EVENT_TOOL_TYPE_PALM) { |
| 238 | std::optional<int32_t> id = getActiveBitId(inSlot); |
arthurhung | cc7f980 | 2020-04-30 17:55:40 +0800 | [diff] [blame] | 239 | if (id) { |
| 240 | outState->rawPointerData.canceledIdBits.markBit(id.value()); |
Arthur Hung | 421eb1c | 2020-01-16 00:09:42 +0800 | [diff] [blame] | 241 | } |
Siarhei Vishniakou | e3ce49d | 2020-09-29 19:08:13 -0500 | [diff] [blame] | 242 | if (DEBUG_POINTERS) { |
| 243 | ALOGI("Stop processing slot %zu for it received a palm event from device %s", |
| 244 | inIndex, getDeviceName().c_str()); |
| 245 | } |
arthurhung | bf89a48 | 2020-04-17 17:37:55 +0800 | [diff] [blame] | 246 | continue; |
Arthur Hung | 421eb1c | 2020-01-16 00:09:42 +0800 | [diff] [blame] | 247 | } |
| 248 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 249 | if (outCount >= MAX_POINTERS) { |
Siarhei Vishniakou | e3ce49d | 2020-09-29 19:08:13 -0500 | [diff] [blame] | 250 | if (DEBUG_POINTERS) { |
Siarhei Vishniakou | 0174738 | 2022-01-20 13:23:27 -0800 | [diff] [blame] | 251 | ALOGD("MultiTouch device %s emitted more than maximum of %zu pointers; " |
Siarhei Vishniakou | e3ce49d | 2020-09-29 19:08:13 -0500 | [diff] [blame] | 252 | "ignoring the rest.", |
| 253 | getDeviceName().c_str(), MAX_POINTERS); |
| 254 | } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 255 | break; // too many fingers! |
| 256 | } |
| 257 | |
| 258 | RawPointerData::Pointer& outPointer = outState->rawPointerData.pointers[outCount]; |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 259 | outPointer.x = inSlot.getX(); |
| 260 | outPointer.y = inSlot.getY(); |
| 261 | outPointer.pressure = inSlot.getPressure(); |
| 262 | outPointer.touchMajor = inSlot.getTouchMajor(); |
| 263 | outPointer.touchMinor = inSlot.getTouchMinor(); |
| 264 | outPointer.toolMajor = inSlot.getToolMajor(); |
| 265 | outPointer.toolMinor = inSlot.getToolMinor(); |
| 266 | outPointer.orientation = inSlot.getOrientation(); |
| 267 | outPointer.distance = inSlot.getDistance(); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 268 | outPointer.tiltX = 0; |
| 269 | outPointer.tiltY = 0; |
| 270 | |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 271 | outPointer.toolType = inSlot.getToolType(); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 272 | if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { |
| 273 | outPointer.toolType = mTouchButtonAccumulator.getToolType(); |
| 274 | if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { |
| 275 | outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; |
| 276 | } |
| 277 | } |
Prabir Pradhan | f4d65b1 | 2022-02-10 07:15:38 -0800 | [diff] [blame] | 278 | if (shouldSimulateStylusWithTouch() && |
| 279 | outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) { |
| 280 | outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; |
| 281 | } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 282 | |
| 283 | bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE && |
| 284 | (mTouchButtonAccumulator.isHovering() || |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 285 | (mRawPointerAxes.pressure.valid && inSlot.getPressure() <= 0)); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 286 | outPointer.isHovering = isHovering; |
| 287 | |
| 288 | // Assign pointer id using tracking id if available. |
| 289 | if (mHavePointerIds) { |
Siarhei Vishniakou | baf0b16 | 2022-02-16 11:12:36 -0800 | [diff] [blame] | 290 | int32_t trackingId = inSlot.getTrackingId(); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 291 | int32_t id = -1; |
| 292 | if (trackingId >= 0) { |
| 293 | for (BitSet32 idBits(mPointerIdBits); !idBits.isEmpty();) { |
| 294 | uint32_t n = idBits.clearFirstMarkedBit(); |
| 295 | if (mPointerTrackingIdMap[n] == trackingId) { |
| 296 | id = n; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | if (id < 0 && !mPointerIdBits.isFull()) { |
| 301 | id = mPointerIdBits.markFirstUnmarkedBit(); |
| 302 | mPointerTrackingIdMap[id] = trackingId; |
| 303 | } |
| 304 | } |
| 305 | if (id < 0) { |
| 306 | mHavePointerIds = false; |
| 307 | outState->rawPointerData.clearIdBits(); |
| 308 | newPointerIdBits.clear(); |
| 309 | } else { |
| 310 | outPointer.id = id; |
| 311 | outState->rawPointerData.idToIndex[id] = outCount; |
| 312 | outState->rawPointerData.markIdBit(id, isHovering); |
| 313 | newPointerIdBits.markBit(id); |
| 314 | } |
| 315 | } |
| 316 | outCount += 1; |
| 317 | } |
| 318 | |
| 319 | outState->rawPointerData.pointerCount = outCount; |
| 320 | mPointerIdBits = newPointerIdBits; |
| 321 | |
| 322 | mMultiTouchMotionAccumulator.finishSync(); |
| 323 | } |
| 324 | |
| 325 | void MultiTouchInputMapper::configureRawPointerAxes() { |
| 326 | TouchInputMapper::configureRawPointerAxes(); |
| 327 | |
| 328 | getAbsoluteAxisInfo(ABS_MT_POSITION_X, &mRawPointerAxes.x); |
| 329 | getAbsoluteAxisInfo(ABS_MT_POSITION_Y, &mRawPointerAxes.y); |
| 330 | getAbsoluteAxisInfo(ABS_MT_TOUCH_MAJOR, &mRawPointerAxes.touchMajor); |
| 331 | getAbsoluteAxisInfo(ABS_MT_TOUCH_MINOR, &mRawPointerAxes.touchMinor); |
| 332 | getAbsoluteAxisInfo(ABS_MT_WIDTH_MAJOR, &mRawPointerAxes.toolMajor); |
| 333 | getAbsoluteAxisInfo(ABS_MT_WIDTH_MINOR, &mRawPointerAxes.toolMinor); |
| 334 | getAbsoluteAxisInfo(ABS_MT_ORIENTATION, &mRawPointerAxes.orientation); |
| 335 | getAbsoluteAxisInfo(ABS_MT_PRESSURE, &mRawPointerAxes.pressure); |
| 336 | getAbsoluteAxisInfo(ABS_MT_DISTANCE, &mRawPointerAxes.distance); |
| 337 | getAbsoluteAxisInfo(ABS_MT_TRACKING_ID, &mRawPointerAxes.trackingId); |
| 338 | getAbsoluteAxisInfo(ABS_MT_SLOT, &mRawPointerAxes.slot); |
| 339 | |
| 340 | if (mRawPointerAxes.trackingId.valid && mRawPointerAxes.slot.valid && |
| 341 | mRawPointerAxes.slot.minValue == 0 && mRawPointerAxes.slot.maxValue > 0) { |
| 342 | size_t slotCount = mRawPointerAxes.slot.maxValue + 1; |
| 343 | if (slotCount > MAX_SLOTS) { |
| 344 | ALOGW("MultiTouch Device %s reported %zu slots but the framework " |
| 345 | "only supports a maximum of %zu slots at this time.", |
| 346 | getDeviceName().c_str(), slotCount, MAX_SLOTS); |
| 347 | slotCount = MAX_SLOTS; |
| 348 | } |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 349 | mMultiTouchMotionAccumulator.configure(getDeviceContext(), slotCount, |
| 350 | true /*usingSlotsProtocol*/); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 351 | } else { |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 352 | mMultiTouchMotionAccumulator.configure(getDeviceContext(), MAX_POINTERS, |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 353 | false /*usingSlotsProtocol*/); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | bool MultiTouchInputMapper::hasStylus() const { |
Prabir Pradhan | f4d65b1 | 2022-02-10 07:15:38 -0800 | [diff] [blame] | 358 | return mMultiTouchMotionAccumulator.hasStylus() || mTouchButtonAccumulator.hasStylus() || |
| 359 | shouldSimulateStylusWithTouch(); |
| 360 | } |
| 361 | |
| 362 | bool MultiTouchInputMapper::shouldSimulateStylusWithTouch() const { |
| 363 | static const bool SIMULATE_STYLUS_WITH_TOUCH = |
| 364 | sysprop::InputProperties::simulate_stylus_with_touch().value_or(false); |
| 365 | return SIMULATE_STYLUS_WITH_TOUCH && |
| 366 | mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | } // namespace android |