blob: abd9284866071c47b6133713dcc47f8f6925f432 [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>
28
29#include <mutex>
Prabir Pradhan5693cee2021-12-31 06:51:15 -080030
31#include "PointerControllerContext.h"
Jeff Brownb4ff35d2011-01-02 16:37:43 -080032
Michael Wright72a89132022-10-22 03:16:31 +010033#define INDENT " "
34#define INDENT2 " "
Michael Wright83577752022-10-28 16:24:33 +010035#define INDENT3 " "
Michael Wright72a89132022-10-22 03:16:31 +010036
Jeff Brownb4ff35d2011-01-02 16:37:43 -080037namespace android {
38
Prabir Pradhanf97fac32021-11-18 16:40:34 +000039namespace {
40
41const ui::Transform kIdentityTransform;
42
43} // namespace
44
45// --- PointerController::DisplayInfoListener ---
46
47void PointerController::DisplayInfoListener::onWindowInfosChanged(
Patrick Williams8e47a672023-05-01 11:30:37 -050048 const gui::WindowInfosUpdate& update) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -080049 std::scoped_lock lock(mLock);
50 if (mPointerController == nullptr) return;
51
52 // PointerController uses DisplayInfoListener's lock.
53 base::ScopedLockAssertion assumeLocked(mPointerController->getLock());
Patrick Williams8e47a672023-05-01 11:30:37 -050054 mPointerController->onDisplayInfosChangedLocked(update.displayInfos);
Prabir Pradhan5693cee2021-12-31 06:51:15 -080055}
56
57void PointerController::DisplayInfoListener::onPointerControllerDestroyed() {
58 std::scoped_lock lock(mLock);
59 mPointerController = nullptr;
Prabir Pradhanf97fac32021-11-18 16:40:34 +000060}
61
Jeff Brownb4ff35d2011-01-02 16:37:43 -080062// --- PointerController ---
63
Michael Wrighta0bc6b12020-06-26 20:25:34 +010064std::shared_ptr<PointerController> PointerController::create(
65 const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper,
Prabir Pradhan3401d232023-06-15 23:15:32 +000066 SpriteController& spriteController, bool enabled) {
Liam Harringtonc782be62020-07-17 19:48:24 +000067 // using 'new' to access non-public constructor
Michael Wrighta0bc6b12020-06-26 20:25:34 +010068 std::shared_ptr<PointerController> controller = std::shared_ptr<PointerController>(
Prabir Pradhan3401d232023-06-15 23:15:32 +000069 new PointerController(policy, looper, spriteController, enabled));
Jeff Brown2352b972011-04-12 22:39:53 -070070
Michael Wrighta0bc6b12020-06-26 20:25:34 +010071 /*
72 * Now we need to hook up the constructed PointerController object to its callbacks.
73 *
74 * This must be executed after the constructor but before any other methods on PointerController
75 * in order to ensure that the fully constructed object is visible on the Looper thread, since
76 * that may be a different thread than where the PointerController is initially constructed.
77 *
78 * Unfortunately, this cannot be done as part of the constructor since we need to hand out
79 * weak_ptr's which themselves cannot be constructed until there's at least one shared_ptr.
80 */
Jeff Brown5541de92011-04-11 11:54:25 -070081
Liam Harringtonc782be62020-07-17 19:48:24 +000082 controller->mContext.setHandlerController(controller);
83 controller->mContext.setCallbackController(controller);
Michael Wrighta0bc6b12020-06-26 20:25:34 +010084 return controller;
85}
Jun Mukaic0c0ac32015-10-27 10:09:21 -070086
Michael Wrighta0bc6b12020-06-26 20:25:34 +010087PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan3401d232023-06-15 23:15:32 +000088 const sp<Looper>& looper, SpriteController& spriteController,
89 bool enabled)
Prabir Pradhan5693cee2021-12-31 06:51:15 -080090 : PointerController(
Prabir Pradhan3401d232023-06-15 23:15:32 +000091 policy, looper, spriteController, enabled,
Prabir Pradhan5693cee2021-12-31 06:51:15 -080092 [](const sp<android::gui::WindowInfosListener>& listener) {
93 SurfaceComposerClient::getDefault()->addWindowInfosListener(listener);
94 },
95 [](const sp<android::gui::WindowInfosListener>& listener) {
96 SurfaceComposerClient::getDefault()->removeWindowInfosListener(listener);
97 }) {}
98
99PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan27c6d992023-08-18 19:44:55 +0000100 const sp<Looper>& looper, SpriteController& spriteController,
Prabir Pradhan3401d232023-06-15 23:15:32 +0000101 bool enabled, WindowListenerConsumer registerListener,
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800102 WindowListenerConsumer unregisterListener)
Prabir Pradhan3401d232023-06-15 23:15:32 +0000103 : mEnabled(enabled),
104 mContext(policy, looper, spriteController, *this),
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000105 mCursorController(mContext),
Prabir Pradhan4cc1a632023-06-09 21:31:26 +0000106 mDisplayInfoListener(sp<DisplayInfoListener>::make(this)),
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800107 mUnregisterWindowInfosListener(std::move(unregisterListener)) {
108 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000109 mLocked.presentation = Presentation::SPOT;
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800110 registerListener(mDisplayInfoListener);
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000111}
112
113PointerController::~PointerController() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800114 mDisplayInfoListener->onPointerControllerDestroyed();
115 mUnregisterWindowInfosListener(mDisplayInfoListener);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000116 mContext.getPolicy()->onPointerDisplayIdChanged(ADISPLAY_ID_NONE, FloatPoint{0, 0});
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800117}
118
119std::mutex& PointerController::getLock() const {
120 return mDisplayInfoListener->mLock;
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800121}
122
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000123std::optional<FloatRect> PointerController::getBounds() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000124 if (!mEnabled) return {};
125
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000126 return mCursorController.getBounds();
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800127}
128
129void PointerController::move(float deltaX, float deltaY) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000130 if (!mEnabled) return;
131
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000132 const int32_t displayId = mCursorController.getDisplayId();
133 vec2 transformed;
134 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800135 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000136 const auto& transform = getTransformForDisplayLocked(displayId);
137 transformed = transformWithoutTranslation(transform, {deltaX, deltaY});
138 }
139 mCursorController.move(transformed.x, transformed.y);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800140}
141
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800142void PointerController::setPosition(float x, float y) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000143 if (!mEnabled) return;
144
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000145 const int32_t displayId = mCursorController.getDisplayId();
146 vec2 transformed;
147 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800148 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000149 const auto& transform = getTransformForDisplayLocked(displayId);
150 transformed = transform.transform(x, y);
151 }
152 mCursorController.setPosition(transformed.x, transformed.y);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800153}
154
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000155FloatPoint PointerController::getPosition() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000156 if (!mEnabled) {
157 return FloatPoint{AMOTION_EVENT_INVALID_CURSOR_POSITION,
158 AMOTION_EVENT_INVALID_CURSOR_POSITION};
159 }
160
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000161 const int32_t displayId = mCursorController.getDisplayId();
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000162 const auto p = mCursorController.getPosition();
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000163 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800164 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000165 const auto& transform = getTransformForDisplayLocked(displayId);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000166 return FloatPoint{transform.inverse().transform(p.x, p.y)};
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000167 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800168}
169
Arthur Hungb9b32002018-12-18 17:39:43 +0800170int32_t PointerController::getDisplayId() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000171 if (!mEnabled) return ADISPLAY_ID_NONE;
172
Liam Harringtonc782be62020-07-17 19:48:24 +0000173 return mCursorController.getDisplayId();
Arthur Hungb9b32002018-12-18 17:39:43 +0800174}
175
Jeff Brown538881e2011-05-25 18:23:38 -0700176void PointerController::fade(Transition transition) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000177 if (!mEnabled) return;
178
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800179 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000180 mCursorController.fade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800181}
182
Jeff Brown538881e2011-05-25 18:23:38 -0700183void PointerController::unfade(Transition transition) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000184 if (!mEnabled) return;
185
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800186 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000187 mCursorController.unfade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800188}
189
Jeff Brown2352b972011-04-12 22:39:53 -0700190void PointerController::setPresentation(Presentation presentation) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000191 if (!mEnabled) return;
192
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800193 std::scoped_lock lock(getLock());
Jeff Brown05dc66a2011-03-02 14:41:58 -0800194
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800195 if (mLocked.presentation == presentation) {
196 return;
Jun Mukai1db53972015-09-11 18:08:31 -0700197 }
198
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800199 mLocked.presentation = presentation;
Jeff Brown2352b972011-04-12 22:39:53 -0700200
Liam Harringtonc782be62020-07-17 19:48:24 +0000201 if (!mCursorController.isViewportValid()) {
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800202 return;
203 }
204
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900205 if (presentation == Presentation::POINTER || presentation == Presentation::STYLUS_HOVER) {
206 // For now, we support stylus hover using the mouse cursor implementation.
207 // TODO: Add proper support for stylus hover icons.
208 mCursorController.setStylusHoverMode(presentation == Presentation::STYLUS_HOVER);
209
Liam Harringtonc782be62020-07-17 19:48:24 +0000210 mCursorController.getAdditionalMouseResources();
211 clearSpotsLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800212 }
213}
214
Liam Harringtonc782be62020-07-17 19:48:24 +0000215void PointerController::setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
216 BitSet32 spotIdBits, int32_t displayId) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000217 if (!mEnabled) return;
218
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800219 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000220 std::array<PointerCoords, MAX_POINTERS> outSpotCoords{};
221 const ui::Transform& transform = getTransformForDisplayLocked(displayId);
222
223 for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) {
224 const uint32_t index = spotIdToIndex[idBits.clearFirstMarkedBit()];
225
226 const vec2 xy = transform.transform(spotCoords[index].getXYValue());
227 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_X, xy.x);
228 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y);
229
230 float pressure = spotCoords[index].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE);
231 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure);
232 }
233
Liam Harringtonc782be62020-07-17 19:48:24 +0000234 auto it = mLocked.spotControllers.find(displayId);
235 if (it == mLocked.spotControllers.end()) {
236 mLocked.spotControllers.try_emplace(displayId, displayId, mContext);
Jeff Brown2352b972011-04-12 22:39:53 -0700237 }
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000238 mLocked.spotControllers.at(displayId).setSpots(outSpotCoords.data(), spotIdToIndex, spotIdBits);
Jeff Brown2352b972011-04-12 22:39:53 -0700239}
240
241void PointerController::clearSpots() {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000242 if (!mEnabled) return;
243
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800244 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000245 clearSpotsLocked();
246}
Jeff Brown2352b972011-04-12 22:39:53 -0700247
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800248void PointerController::clearSpotsLocked() {
Michael Wright21401ad92022-10-22 03:23:55 +0100249 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000250 spotController.clearSpots();
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800251 }
Jeff Brown2352b972011-04-12 22:39:53 -0700252}
253
254void PointerController::setInactivityTimeout(InactivityTimeout inactivityTimeout) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000255 mContext.setInactivityTimeout(inactivityTimeout);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800256}
257
Jun Mukai19a56012015-11-24 11:25:52 -0800258void PointerController::reloadPointerResources() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800259 std::scoped_lock lock(getLock());
Jun Mukai19a56012015-11-24 11:25:52 -0800260
Michael Wright21401ad92022-10-22 03:23:55 +0100261 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000262 spotController.reloadSpotResources();
263 }
Jun Mukai19a56012015-11-24 11:25:52 -0800264
Liam Harringtonc782be62020-07-17 19:48:24 +0000265 if (mCursorController.resourcesLoaded()) {
266 bool getAdditionalMouseResources = false;
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900267 if (mLocked.presentation == PointerController::Presentation::POINTER ||
268 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000269 getAdditionalMouseResources = true;
270 }
271 mCursorController.reloadPointerResources(getAdditionalMouseResources);
Arthur Hungb9b32002018-12-18 17:39:43 +0800272 }
273}
274
275void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000276 struct PointerDisplayChangeArgs {
277 int32_t displayId;
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000278 FloatPoint cursorPosition;
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000279 };
280 std::optional<PointerDisplayChangeArgs> pointerDisplayChanged;
Liam Harringtonc782be62020-07-17 19:48:24 +0000281
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000282 { // acquire lock
283 std::scoped_lock lock(getLock());
284
285 bool getAdditionalMouseResources = false;
286 if (mLocked.presentation == PointerController::Presentation::POINTER ||
287 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
288 getAdditionalMouseResources = true;
289 }
290 mCursorController.setDisplayViewport(viewport, getAdditionalMouseResources);
291 if (viewport.displayId != mLocked.pointerDisplayId) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000292 mLocked.pointerDisplayId = viewport.displayId;
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000293 pointerDisplayChanged = {viewport.displayId, mCursorController.getPosition()};
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000294 }
295 } // release lock
296
297 if (pointerDisplayChanged) {
298 // Notify the policy without holding the pointer controller lock.
299 mContext.getPolicy()->onPointerDisplayIdChanged(pointerDisplayChanged->displayId,
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000300 pointerDisplayChanged->cursorPosition);
Prabir Pradhan0e3d6652022-03-10 14:39:46 +0000301 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800302}
303
Brandon Pollack015f5d92022-06-02 06:59:33 +0000304void PointerController::updatePointerIcon(PointerIconStyle iconId) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000305 if (!mEnabled) return;
306
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800307 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000308 mCursorController.updatePointerIcon(iconId);
Jun Mukai1db53972015-09-11 18:08:31 -0700309}
310
Jun Mukaid4eaef72015-10-30 15:54:33 -0700311void PointerController::setCustomPointerIcon(const SpriteIcon& icon) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000312 if (!mEnabled) return;
313
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800314 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000315 mCursorController.setCustomPointerIcon(icon);
Jun Mukaic0c0ac32015-10-27 10:09:21 -0700316}
317
Jeff Brown2352b972011-04-12 22:39:53 -0700318void PointerController::doInactivityTimeout() {
Michael Wright6853fe62020-07-02 00:01:38 +0100319 fade(Transition::GRADUAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800320}
321
Prabir Pradhanc2200182023-06-09 23:39:15 +0000322void PointerController::onDisplayViewportsUpdated(const std::vector<DisplayViewport>& viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000323 std::unordered_set<int32_t> displayIdSet;
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000324 for (const DisplayViewport& viewport : viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000325 displayIdSet.insert(viewport.displayId);
Arthur Hungb9b32002018-12-18 17:39:43 +0800326 }
327
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800328 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000329 for (auto it = mLocked.spotControllers.begin(); it != mLocked.spotControllers.end();) {
Michael Wright21401ad92022-10-22 03:23:55 +0100330 int32_t displayId = it->first;
331 if (!displayIdSet.count(displayId)) {
Liam Harringtonce637132020-08-14 04:00:11 +0000332 /*
333 * Ensures that an in-progress animation won't dereference
334 * a null pointer to TouchSpotController.
335 */
Michael Wright21401ad92022-10-22 03:23:55 +0100336 mContext.removeAnimationCallback(displayId);
Liam Harringtonc782be62020-07-17 19:48:24 +0000337 it = mLocked.spotControllers.erase(it);
Jun Mukai1db53972015-09-11 18:08:31 -0700338 } else {
Liam Harringtonc782be62020-07-17 19:48:24 +0000339 ++it;
Jeff Brown2352b972011-04-12 22:39:53 -0700340 }
341 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800342}
343
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800344void PointerController::onDisplayInfosChangedLocked(
345 const std::vector<gui::DisplayInfo>& displayInfo) {
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000346 mLocked.mDisplayInfos = displayInfo;
347}
348
349const ui::Transform& PointerController::getTransformForDisplayLocked(int displayId) const {
350 const auto& di = mLocked.mDisplayInfos;
351 auto it = std::find_if(di.begin(), di.end(), [displayId](const gui::DisplayInfo& info) {
352 return info.displayId == displayId;
353 });
354 return it != di.end() ? it->transform : kIdentityTransform;
355}
356
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000357std::string PointerController::dump() {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000358 if (!mEnabled) {
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000359 return INDENT "PointerController: DISABLED due to ongoing PointerChoreographer refactor\n";
Prabir Pradhan3401d232023-06-15 23:15:32 +0000360 }
361
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000362 std::string dump = INDENT "PointerController:\n";
Michael Wright72a89132022-10-22 03:16:31 +0100363 std::scoped_lock lock(getLock());
364 dump += StringPrintf(INDENT2 "Presentation: %s\n",
365 ftl::enum_string(mLocked.presentation).c_str());
366 dump += StringPrintf(INDENT2 "Pointer Display ID: %" PRIu32 "\n", mLocked.pointerDisplayId);
Michael Wright83577752022-10-28 16:24:33 +0100367 dump += StringPrintf(INDENT2 "Viewports:\n");
368 for (const auto& info : mLocked.mDisplayInfos) {
369 info.dump(dump, INDENT3);
370 }
Michael Wright20f5fd82022-10-28 14:12:24 +0100371 dump += INDENT2 "Spot Controllers:\n";
372 for (const auto& [_, spotController] : mLocked.spotControllers) {
373 spotController.dump(dump, INDENT3);
374 }
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000375 return dump;
Michael Wright72a89132022-10-22 03:16:31 +0100376}
377
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800378} // namespace android