blob: 0b81211ee666f79e6e006ead1ec5c4874f2bc9ee [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>
Michael Wright72a89132022-10-22 03:16:31 +010027#include <ftl/enum.h>
Arpit Singh05215af2024-08-25 17:49:32 +000028#include <input/PrintTools.h>
Michael Wright72a89132022-10-22 03:16:31 +010029
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
Jeff Brownb4ff35d2011-01-02 16:37:43 -080038namespace android {
39
Prabir Pradhanf97fac32021-11-18 16:40:34 +000040namespace {
41
42const ui::Transform kIdentityTransform;
43
44} // namespace
45
46// --- PointerController::DisplayInfoListener ---
47
48void PointerController::DisplayInfoListener::onWindowInfosChanged(
Patrick Williams8e47a672023-05-01 11:30:37 -050049 const gui::WindowInfosUpdate& update) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -080050 std::scoped_lock lock(mLock);
51 if (mPointerController == nullptr) return;
52
53 // PointerController uses DisplayInfoListener's lock.
54 base::ScopedLockAssertion assumeLocked(mPointerController->getLock());
Patrick Williams8e47a672023-05-01 11:30:37 -050055 mPointerController->onDisplayInfosChangedLocked(update.displayInfos);
Prabir Pradhan5693cee2021-12-31 06:51:15 -080056}
57
58void PointerController::DisplayInfoListener::onPointerControllerDestroyed() {
59 std::scoped_lock lock(mLock);
60 mPointerController = nullptr;
Prabir Pradhanf97fac32021-11-18 16:40:34 +000061}
62
Jeff Brownb4ff35d2011-01-02 16:37:43 -080063// --- PointerController ---
64
Michael Wrighta0bc6b12020-06-26 20:25:34 +010065std::shared_ptr<PointerController> PointerController::create(
66 const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper,
Prabir Pradhan7dff1422024-05-03 23:33:28 +000067 SpriteController& spriteController, ControllerType type) {
Liam Harringtonc782be62020-07-17 19:48:24 +000068 // using 'new' to access non-public constructor
Byoungho Jung6a2ce942023-10-07 16:19:19 +090069 std::shared_ptr<PointerController> controller;
70 switch (type) {
71 case ControllerType::MOUSE:
72 controller = std::shared_ptr<PointerController>(
Prabir Pradhan7dff1422024-05-03 23:33:28 +000073 new MousePointerController(policy, looper, spriteController));
Byoungho Jung6a2ce942023-10-07 16:19:19 +090074 break;
Byoungho Jung51282e82023-10-27 18:15:41 +090075 case ControllerType::TOUCH:
76 controller = std::shared_ptr<PointerController>(
Prabir Pradhan7dff1422024-05-03 23:33:28 +000077 new TouchPointerController(policy, looper, spriteController));
Byoungho Jung51282e82023-10-27 18:15:41 +090078 break;
Byoungho Jung08daa252023-10-27 20:55:18 +090079 case ControllerType::STYLUS:
80 controller = std::shared_ptr<PointerController>(
Prabir Pradhan7dff1422024-05-03 23:33:28 +000081 new StylusPointerController(policy, looper, spriteController));
Byoungho Jung08daa252023-10-27 20:55:18 +090082 break;
Byoungho Jung6a2ce942023-10-07 16:19:19 +090083 default:
Prabir Pradhan7dff1422024-05-03 23:33:28 +000084 LOG_ALWAYS_FATAL("Invalid ControllerType: %d", static_cast<int>(type));
Byoungho Jung6a2ce942023-10-07 16:19:19 +090085 }
Jeff Brown2352b972011-04-12 22:39:53 -070086
Michael Wrighta0bc6b12020-06-26 20:25:34 +010087 /*
88 * Now we need to hook up the constructed PointerController object to its callbacks.
89 *
90 * This must be executed after the constructor but before any other methods on PointerController
91 * in order to ensure that the fully constructed object is visible on the Looper thread, since
92 * that may be a different thread than where the PointerController is initially constructed.
93 *
94 * Unfortunately, this cannot be done as part of the constructor since we need to hand out
95 * weak_ptr's which themselves cannot be constructed until there's at least one shared_ptr.
96 */
Jeff Brown5541de92011-04-11 11:54:25 -070097
Liam Harringtonc782be62020-07-17 19:48:24 +000098 controller->mContext.setHandlerController(controller);
99 controller->mContext.setCallbackController(controller);
Michael Wrighta0bc6b12020-06-26 20:25:34 +0100100 return controller;
101}
Jun Mukaic0c0ac32015-10-27 10:09:21 -0700102
Michael Wrighta0bc6b12020-06-26 20:25:34 +0100103PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000104 const sp<Looper>& looper, SpriteController& spriteController)
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800105 : PointerController(
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000106 policy, looper, spriteController,
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800107 [](const sp<android::gui::WindowInfosListener>& listener) {
Linnan Li37c1b992023-11-24 13:05:13 +0800108 auto initialInfo = std::make_pair(std::vector<android::gui::WindowInfo>{},
109 std::vector<android::gui::DisplayInfo>{});
110 SurfaceComposerClient::getDefault()->addWindowInfosListener(listener,
111 &initialInfo);
Prabir Pradhanbdf93692024-01-23 18:08:28 +0000112 return initialInfo.second;
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800113 },
114 [](const sp<android::gui::WindowInfosListener>& listener) {
115 SurfaceComposerClient::getDefault()->removeWindowInfosListener(listener);
116 }) {}
117
118PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan27c6d992023-08-18 19:44:55 +0000119 const sp<Looper>& looper, SpriteController& spriteController,
Linnan Li37c1b992023-11-24 13:05:13 +0800120 const WindowListenerRegisterConsumer& registerListener,
121 WindowListenerUnregisterConsumer unregisterListener)
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000122 : mContext(policy, looper, spriteController, *this),
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000123 mCursorController(mContext),
Prabir Pradhan4cc1a632023-06-09 21:31:26 +0000124 mDisplayInfoListener(sp<DisplayInfoListener>::make(this)),
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800125 mUnregisterWindowInfosListener(std::move(unregisterListener)) {
126 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000127 mLocked.presentation = Presentation::SPOT;
Prabir Pradhanbdf93692024-01-23 18:08:28 +0000128 const auto& initialDisplayInfos = registerListener(mDisplayInfoListener);
Linnan Li37c1b992023-11-24 13:05:13 +0800129 onDisplayInfosChangedLocked(initialDisplayInfos);
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000130}
131
132PointerController::~PointerController() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800133 mDisplayInfoListener->onPointerControllerDestroyed();
134 mUnregisterWindowInfosListener(mDisplayInfoListener);
135}
136
137std::mutex& PointerController::getLock() const {
138 return mDisplayInfoListener->mLock;
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800139}
140
Arpit Singha09a94d2024-11-26 15:50:17 +0000141vec2 PointerController::move(float deltaX, float deltaY) {
Linnan Li0defadf2024-05-05 19:17:05 +0800142 const ui::LogicalDisplayId displayId = mCursorController.getDisplayId();
Arpit Singh64a70882024-10-25 21:08:08 +0000143 ui::Transform transform;
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000144 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800145 std::scoped_lock lock(getLock());
Arpit Singh64a70882024-10-25 21:08:08 +0000146 transform = getTransformForDisplayLocked(displayId);
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000147 }
Arpit Singh64a70882024-10-25 21:08:08 +0000148
149 const vec2 transformed = transformWithoutTranslation(transform, {deltaX, deltaY});
Arpit Singha09a94d2024-11-26 15:50:17 +0000150 return transformWithoutTranslation(transform.inverse(), mCursorController.move(transformed));
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800151}
152
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800153void PointerController::setPosition(float x, float y) {
Linnan Li0defadf2024-05-05 19:17:05 +0800154 const ui::LogicalDisplayId displayId = mCursorController.getDisplayId();
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000155 vec2 transformed;
156 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800157 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000158 const auto& transform = getTransformForDisplayLocked(displayId);
159 transformed = transform.transform(x, y);
160 }
Arpit Singha09a94d2024-11-26 15:50:17 +0000161 mCursorController.setPosition(transformed);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800162}
163
Arpit Singha09a94d2024-11-26 15:50:17 +0000164vec2 PointerController::getPosition() const {
Linnan Li0defadf2024-05-05 19:17:05 +0800165 const ui::LogicalDisplayId displayId = mCursorController.getDisplayId();
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000166 const auto p = mCursorController.getPosition();
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000167 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800168 std::scoped_lock lock(getLock());
Arpit Singha09a94d2024-11-26 15:50:17 +0000169 return getTransformForDisplayLocked(displayId).inverse().transform(p.x, p.y);
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000170 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800171}
172
Linnan Li0defadf2024-05-05 19:17:05 +0800173ui::LogicalDisplayId PointerController::getDisplayId() const {
Liam Harringtonc782be62020-07-17 19:48:24 +0000174 return mCursorController.getDisplayId();
Arthur Hungb9b32002018-12-18 17:39:43 +0800175}
176
Jeff Brown538881e2011-05-25 18:23:38 -0700177void PointerController::fade(Transition transition) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800178 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000179 mCursorController.fade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800180}
181
Jeff Brown538881e2011-05-25 18:23:38 -0700182void PointerController::unfade(Transition transition) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800183 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000184 mCursorController.unfade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800185}
186
Jeff Brown2352b972011-04-12 22:39:53 -0700187void PointerController::setPresentation(Presentation presentation) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800188 std::scoped_lock lock(getLock());
Jeff Brown05dc66a2011-03-02 14:41:58 -0800189
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800190 if (mLocked.presentation == presentation) {
191 return;
Jun Mukai1db53972015-09-11 18:08:31 -0700192 }
193
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800194 mLocked.presentation = presentation;
Jeff Brown2352b972011-04-12 22:39:53 -0700195
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000196 // The presentation mode is only set once when the PointerController is constructed,
197 // before the display viewport is provided.
198 mCursorController.setStylusHoverMode(presentation == Presentation::STYLUS_HOVER);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800199}
200
Liam Harringtonc782be62020-07-17 19:48:24 +0000201void PointerController::setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
Linnan Li0defadf2024-05-05 19:17:05 +0800202 BitSet32 spotIdBits, ui::LogicalDisplayId displayId) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800203 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000204 std::array<PointerCoords, MAX_POINTERS> outSpotCoords{};
205 const ui::Transform& transform = getTransformForDisplayLocked(displayId);
206
207 for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) {
208 const uint32_t index = spotIdToIndex[idBits.clearFirstMarkedBit()];
209
210 const vec2 xy = transform.transform(spotCoords[index].getXYValue());
211 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_X, xy.x);
212 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y);
213
214 float pressure = spotCoords[index].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE);
215 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure);
216 }
217
Liam Harringtonc782be62020-07-17 19:48:24 +0000218 auto it = mLocked.spotControllers.find(displayId);
219 if (it == mLocked.spotControllers.end()) {
220 mLocked.spotControllers.try_emplace(displayId, displayId, mContext);
Jeff Brown2352b972011-04-12 22:39:53 -0700221 }
Arpit Singh80fd68a2024-03-26 18:41:06 +0000222 bool skipScreenshot = mLocked.displaysToSkipScreenshot.find(displayId) !=
223 mLocked.displaysToSkipScreenshot.end();
224 mLocked.spotControllers.at(displayId).setSpots(outSpotCoords.data(), spotIdToIndex, spotIdBits,
225 skipScreenshot);
Jeff Brown2352b972011-04-12 22:39:53 -0700226}
227
228void PointerController::clearSpots() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800229 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000230 clearSpotsLocked();
231}
Jeff Brown2352b972011-04-12 22:39:53 -0700232
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800233void PointerController::clearSpotsLocked() {
Michael Wright21401ad92022-10-22 03:23:55 +0100234 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000235 spotController.clearSpots();
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800236 }
Jeff Brown2352b972011-04-12 22:39:53 -0700237}
238
239void PointerController::setInactivityTimeout(InactivityTimeout inactivityTimeout) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000240 mContext.setInactivityTimeout(inactivityTimeout);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800241}
242
Jun Mukai19a56012015-11-24 11:25:52 -0800243void PointerController::reloadPointerResources() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800244 std::scoped_lock lock(getLock());
Jun Mukai19a56012015-11-24 11:25:52 -0800245
Michael Wright21401ad92022-10-22 03:23:55 +0100246 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000247 spotController.reloadSpotResources();
248 }
Jun Mukai19a56012015-11-24 11:25:52 -0800249
Liam Harringtonc782be62020-07-17 19:48:24 +0000250 if (mCursorController.resourcesLoaded()) {
251 bool getAdditionalMouseResources = false;
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900252 if (mLocked.presentation == PointerController::Presentation::POINTER ||
253 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000254 getAdditionalMouseResources = true;
255 }
256 mCursorController.reloadPointerResources(getAdditionalMouseResources);
Arthur Hungb9b32002018-12-18 17:39:43 +0800257 }
258}
259
260void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000261 { // acquire lock
262 std::scoped_lock lock(getLock());
263
264 bool getAdditionalMouseResources = false;
265 if (mLocked.presentation == PointerController::Presentation::POINTER ||
266 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
267 getAdditionalMouseResources = true;
268 }
269 mCursorController.setDisplayViewport(viewport, getAdditionalMouseResources);
270 if (viewport.displayId != mLocked.pointerDisplayId) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000271 mLocked.pointerDisplayId = viewport.displayId;
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000272 }
273 } // release lock
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800274}
275
Brandon Pollack015f5d92022-06-02 06:59:33 +0000276void PointerController::updatePointerIcon(PointerIconStyle iconId) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800277 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000278 mCursorController.updatePointerIcon(iconId);
Jun Mukai1db53972015-09-11 18:08:31 -0700279}
280
Jun Mukaid4eaef72015-10-30 15:54:33 -0700281void PointerController::setCustomPointerIcon(const SpriteIcon& icon) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800282 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000283 mCursorController.setCustomPointerIcon(icon);
Jun Mukaic0c0ac32015-10-27 10:09:21 -0700284}
285
Arpit Singhf4ae0ac2024-03-26 18:41:06 +0000286void PointerController::setSkipScreenshotFlagForDisplay(ui::LogicalDisplayId displayId) {
Arpit Singh80fd68a2024-03-26 18:41:06 +0000287 std::scoped_lock lock(getLock());
Arpit Singhf4ae0ac2024-03-26 18:41:06 +0000288 mLocked.displaysToSkipScreenshot.insert(displayId);
289 mCursorController.setSkipScreenshot(true);
290}
291
292void PointerController::clearSkipScreenshotFlags() {
293 std::scoped_lock lock(getLock());
294 mLocked.displaysToSkipScreenshot.clear();
295 mCursorController.setSkipScreenshot(false);
Arpit Singh80fd68a2024-03-26 18:41:06 +0000296}
297
Arpit Singh1886eea2024-11-18 20:42:54 +0000298ui::Transform PointerController::getDisplayTransform() const {
299 std::scoped_lock lock(getLock());
300 return getTransformForDisplayLocked(mLocked.pointerDisplayId);
301}
302
Jeff Brown2352b972011-04-12 22:39:53 -0700303void PointerController::doInactivityTimeout() {
Michael Wright6853fe62020-07-02 00:01:38 +0100304 fade(Transition::GRADUAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800305}
306
Prabir Pradhanc2200182023-06-09 23:39:15 +0000307void PointerController::onDisplayViewportsUpdated(const std::vector<DisplayViewport>& viewports) {
Linnan Li0defadf2024-05-05 19:17:05 +0800308 std::unordered_set<ui::LogicalDisplayId> displayIdSet;
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000309 for (const DisplayViewport& viewport : viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000310 displayIdSet.insert(viewport.displayId);
Arthur Hungb9b32002018-12-18 17:39:43 +0800311 }
312
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800313 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000314 for (auto it = mLocked.spotControllers.begin(); it != mLocked.spotControllers.end();) {
Linnan Li0defadf2024-05-05 19:17:05 +0800315 ui::LogicalDisplayId displayId = it->first;
Michael Wright21401ad92022-10-22 03:23:55 +0100316 if (!displayIdSet.count(displayId)) {
Liam Harringtonce637132020-08-14 04:00:11 +0000317 /*
318 * Ensures that an in-progress animation won't dereference
319 * a null pointer to TouchSpotController.
320 */
Michael Wright21401ad92022-10-22 03:23:55 +0100321 mContext.removeAnimationCallback(displayId);
Liam Harringtonc782be62020-07-17 19:48:24 +0000322 it = mLocked.spotControllers.erase(it);
Jun Mukai1db53972015-09-11 18:08:31 -0700323 } else {
Liam Harringtonc782be62020-07-17 19:48:24 +0000324 ++it;
Jeff Brown2352b972011-04-12 22:39:53 -0700325 }
326 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800327}
328
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800329void PointerController::onDisplayInfosChangedLocked(
330 const std::vector<gui::DisplayInfo>& displayInfo) {
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000331 mLocked.mDisplayInfos = displayInfo;
332}
333
Linnan Li0defadf2024-05-05 19:17:05 +0800334const ui::Transform& PointerController::getTransformForDisplayLocked(
335 ui::LogicalDisplayId displayId) const {
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000336 const auto& di = mLocked.mDisplayInfos;
337 auto it = std::find_if(di.begin(), di.end(), [displayId](const gui::DisplayInfo& info) {
338 return info.displayId == displayId;
339 });
340 return it != di.end() ? it->transform : kIdentityTransform;
341}
342
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000343std::string PointerController::dump() {
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000344 std::string dump = INDENT "PointerController:\n";
Michael Wright72a89132022-10-22 03:16:31 +0100345 std::scoped_lock lock(getLock());
346 dump += StringPrintf(INDENT2 "Presentation: %s\n",
347 ftl::enum_string(mLocked.presentation).c_str());
Linnan Li0defadf2024-05-05 19:17:05 +0800348 dump += StringPrintf(INDENT2 "Pointer Display ID: %s\n",
349 mLocked.pointerDisplayId.toString().c_str());
Michael Wright83577752022-10-28 16:24:33 +0100350 dump += StringPrintf(INDENT2 "Viewports:\n");
351 for (const auto& info : mLocked.mDisplayInfos) {
352 info.dump(dump, INDENT3);
353 }
Michael Wright20f5fd82022-10-28 14:12:24 +0100354 dump += INDENT2 "Spot Controllers:\n";
355 for (const auto& [_, spotController] : mLocked.spotControllers) {
356 spotController.dump(dump, INDENT3);
357 }
Arpit Singh05215af2024-08-25 17:49:32 +0000358 dump += INDENT2 "Cursor Controller:\n";
359 dump += addLinePrefix(mCursorController.dump(), INDENT3);
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000360 return dump;
Michael Wright72a89132022-10-22 03:16:31 +0100361}
362
Byoungho Jung6a2ce942023-10-07 16:19:19 +0900363// --- MousePointerController ---
364
365MousePointerController::MousePointerController(const sp<PointerControllerPolicyInterface>& policy,
366 const sp<Looper>& looper,
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000367 SpriteController& spriteController)
368 : PointerController(policy, looper, spriteController) {
Byoungho Jung6a2ce942023-10-07 16:19:19 +0900369 PointerController::setPresentation(Presentation::POINTER);
370}
371
Prabir Pradhanb0e28072023-11-08 21:09:34 +0000372MousePointerController::~MousePointerController() {
373 MousePointerController::fade(Transition::IMMEDIATE);
374}
375
Byoungho Jung51282e82023-10-27 18:15:41 +0900376// --- TouchPointerController ---
377
378TouchPointerController::TouchPointerController(const sp<PointerControllerPolicyInterface>& policy,
379 const sp<Looper>& looper,
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000380 SpriteController& spriteController)
381 : PointerController(policy, looper, spriteController) {
Byoungho Jung51282e82023-10-27 18:15:41 +0900382 PointerController::setPresentation(Presentation::SPOT);
383}
384
Prabir Pradhanb0e28072023-11-08 21:09:34 +0000385TouchPointerController::~TouchPointerController() {
386 TouchPointerController::clearSpots();
387}
388
Byoungho Jung08daa252023-10-27 20:55:18 +0900389// --- StylusPointerController ---
390
391StylusPointerController::StylusPointerController(const sp<PointerControllerPolicyInterface>& policy,
392 const sp<Looper>& looper,
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000393 SpriteController& spriteController)
394 : PointerController(policy, looper, spriteController) {
Byoungho Jung08daa252023-10-27 20:55:18 +0900395 PointerController::setPresentation(Presentation::STYLUS_HOVER);
396}
397
Prabir Pradhanb0e28072023-11-08 21:09:34 +0000398StylusPointerController::~StylusPointerController() {
399 StylusPointerController::fade(Transition::IMMEDIATE);
400}
401
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800402} // namespace android