blob: 2e7452d780eb7eeeab8391b45ff93e0e0d9e53a8 [file] [log] [blame]
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001/*
2 * Copyright (C) 2010 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
17#define LOG_TAG "PointerController"
Jeff Brownb4ff35d2011-01-02 16:37:43 -080018//#define LOG_NDEBUG 0
19
Prabir Pradhan02b05452021-11-17 21:48:11 +000020#include "PointerController.h"
Prabir Pradhan02b05452021-11-17 21:48:11 +000021
Liam Harringtonc782be62020-07-17 19:48:24 +000022#include <SkBlendMode.h>
23#include <SkCanvas.h>
24#include <SkColor.h>
Michael Wright72a89132022-10-22 03:16:31 +010025#include <android-base/stringprintf.h>
Prabir Pradhan5693cee2021-12-31 06:51:15 -080026#include <android-base/thread_annotations.h>
Byoungho Jung6a2ce942023-10-07 16:19:19 +090027#include <com_android_input_flags.h>
Michael Wright72a89132022-10-22 03:16:31 +010028#include <ftl/enum.h>
29
30#include <mutex>
Prabir Pradhan5693cee2021-12-31 06:51:15 -080031
32#include "PointerControllerContext.h"
Jeff Brownb4ff35d2011-01-02 16:37:43 -080033
Michael Wright72a89132022-10-22 03:16:31 +010034#define INDENT " "
35#define INDENT2 " "
Michael Wright83577752022-10-28 16:24:33 +010036#define INDENT3 " "
Michael Wright72a89132022-10-22 03:16:31 +010037
Byoungho Jung6a2ce942023-10-07 16:19:19 +090038namespace input_flags = com::android::input::flags;
39
Jeff Brownb4ff35d2011-01-02 16:37:43 -080040namespace android {
41
Prabir Pradhanf97fac32021-11-18 16:40:34 +000042namespace {
43
44const ui::Transform kIdentityTransform;
45
46} // namespace
47
48// --- PointerController::DisplayInfoListener ---
49
50void PointerController::DisplayInfoListener::onWindowInfosChanged(
Patrick Williams8e47a672023-05-01 11:30:37 -050051 const gui::WindowInfosUpdate& update) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -080052 std::scoped_lock lock(mLock);
53 if (mPointerController == nullptr) return;
54
55 // PointerController uses DisplayInfoListener's lock.
56 base::ScopedLockAssertion assumeLocked(mPointerController->getLock());
Patrick Williams8e47a672023-05-01 11:30:37 -050057 mPointerController->onDisplayInfosChangedLocked(update.displayInfos);
Prabir Pradhan5693cee2021-12-31 06:51:15 -080058}
59
60void PointerController::DisplayInfoListener::onPointerControllerDestroyed() {
61 std::scoped_lock lock(mLock);
62 mPointerController = nullptr;
Prabir Pradhanf97fac32021-11-18 16:40:34 +000063}
64
Jeff Brownb4ff35d2011-01-02 16:37:43 -080065// --- PointerController ---
66
Michael Wrighta0bc6b12020-06-26 20:25:34 +010067std::shared_ptr<PointerController> PointerController::create(
68 const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper,
Byoungho Jung6a2ce942023-10-07 16:19:19 +090069 SpriteController& spriteController, bool enabled, ControllerType type) {
Liam Harringtonc782be62020-07-17 19:48:24 +000070 // using 'new' to access non-public constructor
Byoungho Jung6a2ce942023-10-07 16:19:19 +090071 std::shared_ptr<PointerController> controller;
72 switch (type) {
73 case ControllerType::MOUSE:
74 controller = std::shared_ptr<PointerController>(
75 new MousePointerController(policy, looper, spriteController, enabled));
76 break;
Byoungho Jung51282e82023-10-27 18:15:41 +090077 case ControllerType::TOUCH:
78 controller = std::shared_ptr<PointerController>(
79 new TouchPointerController(policy, looper, spriteController, enabled));
80 break;
Byoungho Jung08daa252023-10-27 20:55:18 +090081 case ControllerType::STYLUS:
82 controller = std::shared_ptr<PointerController>(
83 new StylusPointerController(policy, looper, spriteController, enabled));
84 break;
Byoungho Jung6a2ce942023-10-07 16:19:19 +090085 case ControllerType::LEGACY:
86 default:
87 controller = std::shared_ptr<PointerController>(
88 new PointerController(policy, looper, spriteController, enabled));
89 break;
90 }
Jeff Brown2352b972011-04-12 22:39:53 -070091
Michael Wrighta0bc6b12020-06-26 20:25:34 +010092 /*
93 * Now we need to hook up the constructed PointerController object to its callbacks.
94 *
95 * This must be executed after the constructor but before any other methods on PointerController
96 * in order to ensure that the fully constructed object is visible on the Looper thread, since
97 * that may be a different thread than where the PointerController is initially constructed.
98 *
99 * Unfortunately, this cannot be done as part of the constructor since we need to hand out
100 * weak_ptr's which themselves cannot be constructed until there's at least one shared_ptr.
101 */
Jeff Brown5541de92011-04-11 11:54:25 -0700102
Liam Harringtonc782be62020-07-17 19:48:24 +0000103 controller->mContext.setHandlerController(controller);
104 controller->mContext.setCallbackController(controller);
Michael Wrighta0bc6b12020-06-26 20:25:34 +0100105 return controller;
106}
Jun Mukaic0c0ac32015-10-27 10:09:21 -0700107
Michael Wrighta0bc6b12020-06-26 20:25:34 +0100108PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan3401d232023-06-15 23:15:32 +0000109 const sp<Looper>& looper, SpriteController& spriteController,
110 bool enabled)
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800111 : PointerController(
Prabir Pradhan3401d232023-06-15 23:15:32 +0000112 policy, looper, spriteController, enabled,
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800113 [](const sp<android::gui::WindowInfosListener>& listener) {
114 SurfaceComposerClient::getDefault()->addWindowInfosListener(listener);
115 },
116 [](const sp<android::gui::WindowInfosListener>& listener) {
117 SurfaceComposerClient::getDefault()->removeWindowInfosListener(listener);
118 }) {}
119
120PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan27c6d992023-08-18 19:44:55 +0000121 const sp<Looper>& looper, SpriteController& spriteController,
Prabir Pradhan3401d232023-06-15 23:15:32 +0000122 bool enabled, WindowListenerConsumer registerListener,
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800123 WindowListenerConsumer unregisterListener)
Prabir Pradhan3401d232023-06-15 23:15:32 +0000124 : mEnabled(enabled),
125 mContext(policy, looper, spriteController, *this),
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000126 mCursorController(mContext),
Prabir Pradhan4cc1a632023-06-09 21:31:26 +0000127 mDisplayInfoListener(sp<DisplayInfoListener>::make(this)),
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800128 mUnregisterWindowInfosListener(std::move(unregisterListener)) {
129 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000130 mLocked.presentation = Presentation::SPOT;
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800131 registerListener(mDisplayInfoListener);
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000132}
133
134PointerController::~PointerController() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800135 mDisplayInfoListener->onPointerControllerDestroyed();
136 mUnregisterWindowInfosListener(mDisplayInfoListener);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000137 mContext.getPolicy()->onPointerDisplayIdChanged(ADISPLAY_ID_NONE, FloatPoint{0, 0});
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800138}
139
140std::mutex& PointerController::getLock() const {
141 return mDisplayInfoListener->mLock;
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800142}
143
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000144std::optional<FloatRect> PointerController::getBounds() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000145 if (!mEnabled) return {};
146
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000147 return mCursorController.getBounds();
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800148}
149
150void PointerController::move(float deltaX, float deltaY) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000151 if (!mEnabled) return;
152
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000153 const int32_t displayId = mCursorController.getDisplayId();
154 vec2 transformed;
155 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800156 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000157 const auto& transform = getTransformForDisplayLocked(displayId);
158 transformed = transformWithoutTranslation(transform, {deltaX, deltaY});
159 }
160 mCursorController.move(transformed.x, transformed.y);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800161}
162
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800163void PointerController::setPosition(float x, float y) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000164 if (!mEnabled) return;
165
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000166 const int32_t displayId = mCursorController.getDisplayId();
167 vec2 transformed;
168 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800169 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000170 const auto& transform = getTransformForDisplayLocked(displayId);
171 transformed = transform.transform(x, y);
172 }
173 mCursorController.setPosition(transformed.x, transformed.y);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800174}
175
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000176FloatPoint PointerController::getPosition() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000177 if (!mEnabled) {
Byoungho Jung49f94b52023-10-30 17:41:28 +0900178 return FloatPoint{0, 0};
Prabir Pradhan3401d232023-06-15 23:15:32 +0000179 }
180
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000181 const int32_t displayId = mCursorController.getDisplayId();
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000182 const auto p = mCursorController.getPosition();
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000183 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800184 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000185 const auto& transform = getTransformForDisplayLocked(displayId);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000186 return FloatPoint{transform.inverse().transform(p.x, p.y)};
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000187 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800188}
189
Arthur Hungb9b32002018-12-18 17:39:43 +0800190int32_t PointerController::getDisplayId() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000191 if (!mEnabled) return ADISPLAY_ID_NONE;
192
Liam Harringtonc782be62020-07-17 19:48:24 +0000193 return mCursorController.getDisplayId();
Arthur Hungb9b32002018-12-18 17:39:43 +0800194}
195
Jeff Brown538881e2011-05-25 18:23:38 -0700196void PointerController::fade(Transition transition) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000197 if (!mEnabled) return;
198
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800199 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000200 mCursorController.fade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800201}
202
Jeff Brown538881e2011-05-25 18:23:38 -0700203void PointerController::unfade(Transition transition) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000204 if (!mEnabled) return;
205
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800206 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000207 mCursorController.unfade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800208}
209
Jeff Brown2352b972011-04-12 22:39:53 -0700210void PointerController::setPresentation(Presentation presentation) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000211 if (!mEnabled) return;
212
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800213 std::scoped_lock lock(getLock());
Jeff Brown05dc66a2011-03-02 14:41:58 -0800214
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800215 if (mLocked.presentation == presentation) {
216 return;
Jun Mukai1db53972015-09-11 18:08:31 -0700217 }
218
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800219 mLocked.presentation = presentation;
Jeff Brown2352b972011-04-12 22:39:53 -0700220
Liam Harringtonc782be62020-07-17 19:48:24 +0000221 if (!mCursorController.isViewportValid()) {
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800222 return;
223 }
224
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900225 if (presentation == Presentation::POINTER || presentation == Presentation::STYLUS_HOVER) {
226 // For now, we support stylus hover using the mouse cursor implementation.
227 // TODO: Add proper support for stylus hover icons.
228 mCursorController.setStylusHoverMode(presentation == Presentation::STYLUS_HOVER);
229
Liam Harringtonc782be62020-07-17 19:48:24 +0000230 mCursorController.getAdditionalMouseResources();
231 clearSpotsLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800232 }
233}
234
Liam Harringtonc782be62020-07-17 19:48:24 +0000235void PointerController::setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
236 BitSet32 spotIdBits, int32_t displayId) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000237 if (!mEnabled) return;
238
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800239 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000240 std::array<PointerCoords, MAX_POINTERS> outSpotCoords{};
241 const ui::Transform& transform = getTransformForDisplayLocked(displayId);
242
243 for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) {
244 const uint32_t index = spotIdToIndex[idBits.clearFirstMarkedBit()];
245
246 const vec2 xy = transform.transform(spotCoords[index].getXYValue());
247 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_X, xy.x);
248 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y);
249
250 float pressure = spotCoords[index].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE);
251 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure);
252 }
253
Liam Harringtonc782be62020-07-17 19:48:24 +0000254 auto it = mLocked.spotControllers.find(displayId);
255 if (it == mLocked.spotControllers.end()) {
256 mLocked.spotControllers.try_emplace(displayId, displayId, mContext);
Jeff Brown2352b972011-04-12 22:39:53 -0700257 }
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000258 mLocked.spotControllers.at(displayId).setSpots(outSpotCoords.data(), spotIdToIndex, spotIdBits);
Jeff Brown2352b972011-04-12 22:39:53 -0700259}
260
261void PointerController::clearSpots() {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000262 if (!mEnabled) return;
263
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800264 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000265 clearSpotsLocked();
266}
Jeff Brown2352b972011-04-12 22:39:53 -0700267
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800268void PointerController::clearSpotsLocked() {
Michael Wright21401ad92022-10-22 03:23:55 +0100269 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000270 spotController.clearSpots();
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800271 }
Jeff Brown2352b972011-04-12 22:39:53 -0700272}
273
274void PointerController::setInactivityTimeout(InactivityTimeout inactivityTimeout) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000275 mContext.setInactivityTimeout(inactivityTimeout);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800276}
277
Jun Mukai19a56012015-11-24 11:25:52 -0800278void PointerController::reloadPointerResources() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800279 std::scoped_lock lock(getLock());
Jun Mukai19a56012015-11-24 11:25:52 -0800280
Michael Wright21401ad92022-10-22 03:23:55 +0100281 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000282 spotController.reloadSpotResources();
283 }
Jun Mukai19a56012015-11-24 11:25:52 -0800284
Liam Harringtonc782be62020-07-17 19:48:24 +0000285 if (mCursorController.resourcesLoaded()) {
286 bool getAdditionalMouseResources = false;
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900287 if (mLocked.presentation == PointerController::Presentation::POINTER ||
288 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000289 getAdditionalMouseResources = true;
290 }
291 mCursorController.reloadPointerResources(getAdditionalMouseResources);
Arthur Hungb9b32002018-12-18 17:39:43 +0800292 }
293}
294
295void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000296 struct PointerDisplayChangeArgs {
297 int32_t displayId;
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000298 FloatPoint cursorPosition;
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000299 };
300 std::optional<PointerDisplayChangeArgs> pointerDisplayChanged;
Liam Harringtonc782be62020-07-17 19:48:24 +0000301
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000302 { // acquire lock
303 std::scoped_lock lock(getLock());
304
305 bool getAdditionalMouseResources = false;
306 if (mLocked.presentation == PointerController::Presentation::POINTER ||
307 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
308 getAdditionalMouseResources = true;
309 }
310 mCursorController.setDisplayViewport(viewport, getAdditionalMouseResources);
311 if (viewport.displayId != mLocked.pointerDisplayId) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000312 mLocked.pointerDisplayId = viewport.displayId;
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000313 pointerDisplayChanged = {viewport.displayId, mCursorController.getPosition()};
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000314 }
315 } // release lock
316
317 if (pointerDisplayChanged) {
318 // Notify the policy without holding the pointer controller lock.
319 mContext.getPolicy()->onPointerDisplayIdChanged(pointerDisplayChanged->displayId,
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000320 pointerDisplayChanged->cursorPosition);
Prabir Pradhan0e3d6652022-03-10 14:39:46 +0000321 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800322}
323
Brandon Pollack015f5d92022-06-02 06:59:33 +0000324void PointerController::updatePointerIcon(PointerIconStyle iconId) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000325 if (!mEnabled) return;
326
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800327 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000328 mCursorController.updatePointerIcon(iconId);
Jun Mukai1db53972015-09-11 18:08:31 -0700329}
330
Jun Mukaid4eaef72015-10-30 15:54:33 -0700331void PointerController::setCustomPointerIcon(const SpriteIcon& icon) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000332 if (!mEnabled) return;
333
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800334 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000335 mCursorController.setCustomPointerIcon(icon);
Jun Mukaic0c0ac32015-10-27 10:09:21 -0700336}
337
Jeff Brown2352b972011-04-12 22:39:53 -0700338void PointerController::doInactivityTimeout() {
Michael Wright6853fe62020-07-02 00:01:38 +0100339 fade(Transition::GRADUAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800340}
341
Prabir Pradhanc2200182023-06-09 23:39:15 +0000342void PointerController::onDisplayViewportsUpdated(const std::vector<DisplayViewport>& viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000343 std::unordered_set<int32_t> displayIdSet;
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000344 for (const DisplayViewport& viewport : viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000345 displayIdSet.insert(viewport.displayId);
Arthur Hungb9b32002018-12-18 17:39:43 +0800346 }
347
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800348 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000349 for (auto it = mLocked.spotControllers.begin(); it != mLocked.spotControllers.end();) {
Michael Wright21401ad92022-10-22 03:23:55 +0100350 int32_t displayId = it->first;
351 if (!displayIdSet.count(displayId)) {
Liam Harringtonce637132020-08-14 04:00:11 +0000352 /*
353 * Ensures that an in-progress animation won't dereference
354 * a null pointer to TouchSpotController.
355 */
Michael Wright21401ad92022-10-22 03:23:55 +0100356 mContext.removeAnimationCallback(displayId);
Liam Harringtonc782be62020-07-17 19:48:24 +0000357 it = mLocked.spotControllers.erase(it);
Jun Mukai1db53972015-09-11 18:08:31 -0700358 } else {
Liam Harringtonc782be62020-07-17 19:48:24 +0000359 ++it;
Jeff Brown2352b972011-04-12 22:39:53 -0700360 }
361 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800362}
363
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800364void PointerController::onDisplayInfosChangedLocked(
365 const std::vector<gui::DisplayInfo>& displayInfo) {
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000366 mLocked.mDisplayInfos = displayInfo;
367}
368
369const ui::Transform& PointerController::getTransformForDisplayLocked(int displayId) const {
370 const auto& di = mLocked.mDisplayInfos;
371 auto it = std::find_if(di.begin(), di.end(), [displayId](const gui::DisplayInfo& info) {
372 return info.displayId == displayId;
373 });
374 return it != di.end() ? it->transform : kIdentityTransform;
375}
376
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000377std::string PointerController::dump() {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000378 if (!mEnabled) {
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000379 return INDENT "PointerController: DISABLED due to ongoing PointerChoreographer refactor\n";
Prabir Pradhan3401d232023-06-15 23:15:32 +0000380 }
381
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000382 std::string dump = INDENT "PointerController:\n";
Michael Wright72a89132022-10-22 03:16:31 +0100383 std::scoped_lock lock(getLock());
384 dump += StringPrintf(INDENT2 "Presentation: %s\n",
385 ftl::enum_string(mLocked.presentation).c_str());
386 dump += StringPrintf(INDENT2 "Pointer Display ID: %" PRIu32 "\n", mLocked.pointerDisplayId);
Michael Wright83577752022-10-28 16:24:33 +0100387 dump += StringPrintf(INDENT2 "Viewports:\n");
388 for (const auto& info : mLocked.mDisplayInfos) {
389 info.dump(dump, INDENT3);
390 }
Michael Wright20f5fd82022-10-28 14:12:24 +0100391 dump += INDENT2 "Spot Controllers:\n";
392 for (const auto& [_, spotController] : mLocked.spotControllers) {
393 spotController.dump(dump, INDENT3);
394 }
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000395 return dump;
Michael Wright72a89132022-10-22 03:16:31 +0100396}
397
Byoungho Jung6a2ce942023-10-07 16:19:19 +0900398// --- MousePointerController ---
399
400MousePointerController::MousePointerController(const sp<PointerControllerPolicyInterface>& policy,
401 const sp<Looper>& looper,
402 SpriteController& spriteController, bool enabled)
403 : PointerController(policy, looper, spriteController, enabled) {
404 PointerController::setPresentation(Presentation::POINTER);
405}
406
Byoungho Jung51282e82023-10-27 18:15:41 +0900407// --- TouchPointerController ---
408
409TouchPointerController::TouchPointerController(const sp<PointerControllerPolicyInterface>& policy,
410 const sp<Looper>& looper,
411 SpriteController& spriteController, bool enabled)
412 : PointerController(policy, looper, spriteController, enabled) {
413 PointerController::setPresentation(Presentation::SPOT);
414}
415
Byoungho Jung08daa252023-10-27 20:55:18 +0900416// --- StylusPointerController ---
417
418StylusPointerController::StylusPointerController(const sp<PointerControllerPolicyInterface>& policy,
419 const sp<Looper>& looper,
420 SpriteController& spriteController, bool enabled)
421 : PointerController(policy, looper, spriteController, enabled) {
422 PointerController::setPresentation(Presentation::STYLUS_HOVER);
423}
424
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800425} // namespace android