blob: 972e16841f49a1a163be9a06e8c68a23259ad7d5 [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) {
178 return FloatPoint{AMOTION_EVENT_INVALID_CURSOR_POSITION,
179 AMOTION_EVENT_INVALID_CURSOR_POSITION};
180 }
181
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000182 const int32_t displayId = mCursorController.getDisplayId();
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000183 const auto p = mCursorController.getPosition();
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000184 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800185 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000186 const auto& transform = getTransformForDisplayLocked(displayId);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000187 return FloatPoint{transform.inverse().transform(p.x, p.y)};
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000188 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800189}
190
Arthur Hungb9b32002018-12-18 17:39:43 +0800191int32_t PointerController::getDisplayId() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000192 if (!mEnabled) return ADISPLAY_ID_NONE;
193
Liam Harringtonc782be62020-07-17 19:48:24 +0000194 return mCursorController.getDisplayId();
Arthur Hungb9b32002018-12-18 17:39:43 +0800195}
196
Jeff Brown538881e2011-05-25 18:23:38 -0700197void PointerController::fade(Transition transition) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000198 if (!mEnabled) return;
199
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800200 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000201 mCursorController.fade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800202}
203
Jeff Brown538881e2011-05-25 18:23:38 -0700204void PointerController::unfade(Transition transition) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000205 if (!mEnabled) return;
206
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800207 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000208 mCursorController.unfade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800209}
210
Jeff Brown2352b972011-04-12 22:39:53 -0700211void PointerController::setPresentation(Presentation presentation) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000212 if (!mEnabled) return;
213
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800214 std::scoped_lock lock(getLock());
Jeff Brown05dc66a2011-03-02 14:41:58 -0800215
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800216 if (mLocked.presentation == presentation) {
217 return;
Jun Mukai1db53972015-09-11 18:08:31 -0700218 }
219
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800220 mLocked.presentation = presentation;
Jeff Brown2352b972011-04-12 22:39:53 -0700221
Liam Harringtonc782be62020-07-17 19:48:24 +0000222 if (!mCursorController.isViewportValid()) {
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800223 return;
224 }
225
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900226 if (presentation == Presentation::POINTER || presentation == Presentation::STYLUS_HOVER) {
227 // For now, we support stylus hover using the mouse cursor implementation.
228 // TODO: Add proper support for stylus hover icons.
229 mCursorController.setStylusHoverMode(presentation == Presentation::STYLUS_HOVER);
230
Liam Harringtonc782be62020-07-17 19:48:24 +0000231 mCursorController.getAdditionalMouseResources();
232 clearSpotsLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800233 }
234}
235
Liam Harringtonc782be62020-07-17 19:48:24 +0000236void PointerController::setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
237 BitSet32 spotIdBits, int32_t displayId) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000238 if (!mEnabled) return;
239
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800240 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000241 std::array<PointerCoords, MAX_POINTERS> outSpotCoords{};
242 const ui::Transform& transform = getTransformForDisplayLocked(displayId);
243
244 for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) {
245 const uint32_t index = spotIdToIndex[idBits.clearFirstMarkedBit()];
246
247 const vec2 xy = transform.transform(spotCoords[index].getXYValue());
248 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_X, xy.x);
249 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y);
250
251 float pressure = spotCoords[index].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE);
252 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure);
253 }
254
Liam Harringtonc782be62020-07-17 19:48:24 +0000255 auto it = mLocked.spotControllers.find(displayId);
256 if (it == mLocked.spotControllers.end()) {
257 mLocked.spotControllers.try_emplace(displayId, displayId, mContext);
Jeff Brown2352b972011-04-12 22:39:53 -0700258 }
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000259 mLocked.spotControllers.at(displayId).setSpots(outSpotCoords.data(), spotIdToIndex, spotIdBits);
Jeff Brown2352b972011-04-12 22:39:53 -0700260}
261
262void PointerController::clearSpots() {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000263 if (!mEnabled) return;
264
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800265 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000266 clearSpotsLocked();
267}
Jeff Brown2352b972011-04-12 22:39:53 -0700268
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800269void PointerController::clearSpotsLocked() {
Michael Wright21401ad92022-10-22 03:23:55 +0100270 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000271 spotController.clearSpots();
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800272 }
Jeff Brown2352b972011-04-12 22:39:53 -0700273}
274
275void PointerController::setInactivityTimeout(InactivityTimeout inactivityTimeout) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000276 mContext.setInactivityTimeout(inactivityTimeout);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800277}
278
Jun Mukai19a56012015-11-24 11:25:52 -0800279void PointerController::reloadPointerResources() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800280 std::scoped_lock lock(getLock());
Jun Mukai19a56012015-11-24 11:25:52 -0800281
Michael Wright21401ad92022-10-22 03:23:55 +0100282 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000283 spotController.reloadSpotResources();
284 }
Jun Mukai19a56012015-11-24 11:25:52 -0800285
Liam Harringtonc782be62020-07-17 19:48:24 +0000286 if (mCursorController.resourcesLoaded()) {
287 bool getAdditionalMouseResources = false;
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900288 if (mLocked.presentation == PointerController::Presentation::POINTER ||
289 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000290 getAdditionalMouseResources = true;
291 }
292 mCursorController.reloadPointerResources(getAdditionalMouseResources);
Arthur Hungb9b32002018-12-18 17:39:43 +0800293 }
294}
295
296void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000297 struct PointerDisplayChangeArgs {
298 int32_t displayId;
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000299 FloatPoint cursorPosition;
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000300 };
301 std::optional<PointerDisplayChangeArgs> pointerDisplayChanged;
Liam Harringtonc782be62020-07-17 19:48:24 +0000302
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000303 { // acquire lock
304 std::scoped_lock lock(getLock());
305
306 bool getAdditionalMouseResources = false;
307 if (mLocked.presentation == PointerController::Presentation::POINTER ||
308 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
309 getAdditionalMouseResources = true;
310 }
311 mCursorController.setDisplayViewport(viewport, getAdditionalMouseResources);
312 if (viewport.displayId != mLocked.pointerDisplayId) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000313 mLocked.pointerDisplayId = viewport.displayId;
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000314 pointerDisplayChanged = {viewport.displayId, mCursorController.getPosition()};
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000315 }
316 } // release lock
317
318 if (pointerDisplayChanged) {
319 // Notify the policy without holding the pointer controller lock.
320 mContext.getPolicy()->onPointerDisplayIdChanged(pointerDisplayChanged->displayId,
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000321 pointerDisplayChanged->cursorPosition);
Prabir Pradhan0e3d6652022-03-10 14:39:46 +0000322 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800323}
324
Brandon Pollack015f5d92022-06-02 06:59:33 +0000325void PointerController::updatePointerIcon(PointerIconStyle iconId) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000326 if (!mEnabled) return;
327
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800328 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000329 mCursorController.updatePointerIcon(iconId);
Jun Mukai1db53972015-09-11 18:08:31 -0700330}
331
Jun Mukaid4eaef72015-10-30 15:54:33 -0700332void PointerController::setCustomPointerIcon(const SpriteIcon& icon) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000333 if (!mEnabled) return;
334
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800335 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000336 mCursorController.setCustomPointerIcon(icon);
Jun Mukaic0c0ac32015-10-27 10:09:21 -0700337}
338
Jeff Brown2352b972011-04-12 22:39:53 -0700339void PointerController::doInactivityTimeout() {
Michael Wright6853fe62020-07-02 00:01:38 +0100340 fade(Transition::GRADUAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800341}
342
Prabir Pradhanc2200182023-06-09 23:39:15 +0000343void PointerController::onDisplayViewportsUpdated(const std::vector<DisplayViewport>& viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000344 std::unordered_set<int32_t> displayIdSet;
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000345 for (const DisplayViewport& viewport : viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000346 displayIdSet.insert(viewport.displayId);
Arthur Hungb9b32002018-12-18 17:39:43 +0800347 }
348
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800349 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000350 for (auto it = mLocked.spotControllers.begin(); it != mLocked.spotControllers.end();) {
Michael Wright21401ad92022-10-22 03:23:55 +0100351 int32_t displayId = it->first;
352 if (!displayIdSet.count(displayId)) {
Liam Harringtonce637132020-08-14 04:00:11 +0000353 /*
354 * Ensures that an in-progress animation won't dereference
355 * a null pointer to TouchSpotController.
356 */
Michael Wright21401ad92022-10-22 03:23:55 +0100357 mContext.removeAnimationCallback(displayId);
Liam Harringtonc782be62020-07-17 19:48:24 +0000358 it = mLocked.spotControllers.erase(it);
Jun Mukai1db53972015-09-11 18:08:31 -0700359 } else {
Liam Harringtonc782be62020-07-17 19:48:24 +0000360 ++it;
Jeff Brown2352b972011-04-12 22:39:53 -0700361 }
362 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800363}
364
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800365void PointerController::onDisplayInfosChangedLocked(
366 const std::vector<gui::DisplayInfo>& displayInfo) {
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000367 mLocked.mDisplayInfos = displayInfo;
368}
369
370const ui::Transform& PointerController::getTransformForDisplayLocked(int displayId) const {
371 const auto& di = mLocked.mDisplayInfos;
372 auto it = std::find_if(di.begin(), di.end(), [displayId](const gui::DisplayInfo& info) {
373 return info.displayId == displayId;
374 });
375 return it != di.end() ? it->transform : kIdentityTransform;
376}
377
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000378std::string PointerController::dump() {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000379 if (!mEnabled) {
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000380 return INDENT "PointerController: DISABLED due to ongoing PointerChoreographer refactor\n";
Prabir Pradhan3401d232023-06-15 23:15:32 +0000381 }
382
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000383 std::string dump = INDENT "PointerController:\n";
Michael Wright72a89132022-10-22 03:16:31 +0100384 std::scoped_lock lock(getLock());
385 dump += StringPrintf(INDENT2 "Presentation: %s\n",
386 ftl::enum_string(mLocked.presentation).c_str());
387 dump += StringPrintf(INDENT2 "Pointer Display ID: %" PRIu32 "\n", mLocked.pointerDisplayId);
Michael Wright83577752022-10-28 16:24:33 +0100388 dump += StringPrintf(INDENT2 "Viewports:\n");
389 for (const auto& info : mLocked.mDisplayInfos) {
390 info.dump(dump, INDENT3);
391 }
Michael Wright20f5fd82022-10-28 14:12:24 +0100392 dump += INDENT2 "Spot Controllers:\n";
393 for (const auto& [_, spotController] : mLocked.spotControllers) {
394 spotController.dump(dump, INDENT3);
395 }
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000396 return dump;
Michael Wright72a89132022-10-22 03:16:31 +0100397}
398
Byoungho Jung6a2ce942023-10-07 16:19:19 +0900399// --- MousePointerController ---
400
401MousePointerController::MousePointerController(const sp<PointerControllerPolicyInterface>& policy,
402 const sp<Looper>& looper,
403 SpriteController& spriteController, bool enabled)
404 : PointerController(policy, looper, spriteController, enabled) {
405 PointerController::setPresentation(Presentation::POINTER);
406}
407
Byoungho Jung51282e82023-10-27 18:15:41 +0900408// --- TouchPointerController ---
409
410TouchPointerController::TouchPointerController(const sp<PointerControllerPolicyInterface>& policy,
411 const sp<Looper>& looper,
412 SpriteController& spriteController, bool enabled)
413 : PointerController(policy, looper, spriteController, enabled) {
414 PointerController::setPresentation(Presentation::SPOT);
415}
416
Byoungho Jung08daa252023-10-27 20:55:18 +0900417// --- StylusPointerController ---
418
419StylusPointerController::StylusPointerController(const sp<PointerControllerPolicyInterface>& policy,
420 const sp<Looper>& looper,
421 SpriteController& spriteController, bool enabled)
422 : PointerController(policy, looper, spriteController, enabled) {
423 PointerController::setPresentation(Presentation::STYLUS_HOVER);
424}
425
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800426} // namespace android