blob: 576ebc1579ef1c676768c744fd800f53563a5397 [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;
77 case ControllerType::LEGACY:
78 default:
79 controller = std::shared_ptr<PointerController>(
80 new PointerController(policy, looper, spriteController, enabled));
81 break;
82 }
Jeff Brown2352b972011-04-12 22:39:53 -070083
Michael Wrighta0bc6b12020-06-26 20:25:34 +010084 /*
85 * Now we need to hook up the constructed PointerController object to its callbacks.
86 *
87 * This must be executed after the constructor but before any other methods on PointerController
88 * in order to ensure that the fully constructed object is visible on the Looper thread, since
89 * that may be a different thread than where the PointerController is initially constructed.
90 *
91 * Unfortunately, this cannot be done as part of the constructor since we need to hand out
92 * weak_ptr's which themselves cannot be constructed until there's at least one shared_ptr.
93 */
Jeff Brown5541de92011-04-11 11:54:25 -070094
Liam Harringtonc782be62020-07-17 19:48:24 +000095 controller->mContext.setHandlerController(controller);
96 controller->mContext.setCallbackController(controller);
Michael Wrighta0bc6b12020-06-26 20:25:34 +010097 return controller;
98}
Jun Mukaic0c0ac32015-10-27 10:09:21 -070099
Michael Wrighta0bc6b12020-06-26 20:25:34 +0100100PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan3401d232023-06-15 23:15:32 +0000101 const sp<Looper>& looper, SpriteController& spriteController,
102 bool enabled)
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800103 : PointerController(
Prabir Pradhan3401d232023-06-15 23:15:32 +0000104 policy, looper, spriteController, enabled,
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800105 [](const sp<android::gui::WindowInfosListener>& listener) {
106 SurfaceComposerClient::getDefault()->addWindowInfosListener(listener);
107 },
108 [](const sp<android::gui::WindowInfosListener>& listener) {
109 SurfaceComposerClient::getDefault()->removeWindowInfosListener(listener);
110 }) {}
111
112PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan27c6d992023-08-18 19:44:55 +0000113 const sp<Looper>& looper, SpriteController& spriteController,
Prabir Pradhan3401d232023-06-15 23:15:32 +0000114 bool enabled, WindowListenerConsumer registerListener,
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800115 WindowListenerConsumer unregisterListener)
Prabir Pradhan3401d232023-06-15 23:15:32 +0000116 : mEnabled(enabled),
117 mContext(policy, looper, spriteController, *this),
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000118 mCursorController(mContext),
Prabir Pradhan4cc1a632023-06-09 21:31:26 +0000119 mDisplayInfoListener(sp<DisplayInfoListener>::make(this)),
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800120 mUnregisterWindowInfosListener(std::move(unregisterListener)) {
121 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000122 mLocked.presentation = Presentation::SPOT;
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800123 registerListener(mDisplayInfoListener);
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000124}
125
126PointerController::~PointerController() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800127 mDisplayInfoListener->onPointerControllerDestroyed();
128 mUnregisterWindowInfosListener(mDisplayInfoListener);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000129 mContext.getPolicy()->onPointerDisplayIdChanged(ADISPLAY_ID_NONE, FloatPoint{0, 0});
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800130}
131
132std::mutex& PointerController::getLock() const {
133 return mDisplayInfoListener->mLock;
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800134}
135
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000136std::optional<FloatRect> PointerController::getBounds() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000137 if (!mEnabled) return {};
138
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000139 return mCursorController.getBounds();
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800140}
141
142void PointerController::move(float deltaX, float deltaY) {
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 = transformWithoutTranslation(transform, {deltaX, deltaY});
151 }
152 mCursorController.move(transformed.x, transformed.y);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800153}
154
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800155void PointerController::setPosition(float x, float y) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000156 if (!mEnabled) return;
157
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000158 const int32_t displayId = mCursorController.getDisplayId();
159 vec2 transformed;
160 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800161 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000162 const auto& transform = getTransformForDisplayLocked(displayId);
163 transformed = transform.transform(x, y);
164 }
165 mCursorController.setPosition(transformed.x, transformed.y);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800166}
167
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000168FloatPoint PointerController::getPosition() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000169 if (!mEnabled) {
170 return FloatPoint{AMOTION_EVENT_INVALID_CURSOR_POSITION,
171 AMOTION_EVENT_INVALID_CURSOR_POSITION};
172 }
173
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000174 const int32_t displayId = mCursorController.getDisplayId();
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000175 const auto p = mCursorController.getPosition();
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000176 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800177 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000178 const auto& transform = getTransformForDisplayLocked(displayId);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000179 return FloatPoint{transform.inverse().transform(p.x, p.y)};
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000180 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800181}
182
Arthur Hungb9b32002018-12-18 17:39:43 +0800183int32_t PointerController::getDisplayId() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000184 if (!mEnabled) return ADISPLAY_ID_NONE;
185
Liam Harringtonc782be62020-07-17 19:48:24 +0000186 return mCursorController.getDisplayId();
Arthur Hungb9b32002018-12-18 17:39:43 +0800187}
188
Jeff Brown538881e2011-05-25 18:23:38 -0700189void PointerController::fade(Transition transition) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000190 if (!mEnabled) return;
191
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800192 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000193 mCursorController.fade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800194}
195
Jeff Brown538881e2011-05-25 18:23:38 -0700196void PointerController::unfade(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.unfade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800201}
202
Jeff Brown2352b972011-04-12 22:39:53 -0700203void PointerController::setPresentation(Presentation presentation) {
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());
Jeff Brown05dc66a2011-03-02 14:41:58 -0800207
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800208 if (mLocked.presentation == presentation) {
209 return;
Jun Mukai1db53972015-09-11 18:08:31 -0700210 }
211
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800212 mLocked.presentation = presentation;
Jeff Brown2352b972011-04-12 22:39:53 -0700213
Liam Harringtonc782be62020-07-17 19:48:24 +0000214 if (!mCursorController.isViewportValid()) {
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800215 return;
216 }
217
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900218 if (presentation == Presentation::POINTER || presentation == Presentation::STYLUS_HOVER) {
219 // For now, we support stylus hover using the mouse cursor implementation.
220 // TODO: Add proper support for stylus hover icons.
221 mCursorController.setStylusHoverMode(presentation == Presentation::STYLUS_HOVER);
222
Liam Harringtonc782be62020-07-17 19:48:24 +0000223 mCursorController.getAdditionalMouseResources();
224 clearSpotsLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800225 }
226}
227
Liam Harringtonc782be62020-07-17 19:48:24 +0000228void PointerController::setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
229 BitSet32 spotIdBits, int32_t displayId) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000230 if (!mEnabled) return;
231
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800232 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000233 std::array<PointerCoords, MAX_POINTERS> outSpotCoords{};
234 const ui::Transform& transform = getTransformForDisplayLocked(displayId);
235
236 for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) {
237 const uint32_t index = spotIdToIndex[idBits.clearFirstMarkedBit()];
238
239 const vec2 xy = transform.transform(spotCoords[index].getXYValue());
240 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_X, xy.x);
241 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y);
242
243 float pressure = spotCoords[index].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE);
244 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure);
245 }
246
Liam Harringtonc782be62020-07-17 19:48:24 +0000247 auto it = mLocked.spotControllers.find(displayId);
248 if (it == mLocked.spotControllers.end()) {
249 mLocked.spotControllers.try_emplace(displayId, displayId, mContext);
Jeff Brown2352b972011-04-12 22:39:53 -0700250 }
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000251 mLocked.spotControllers.at(displayId).setSpots(outSpotCoords.data(), spotIdToIndex, spotIdBits);
Jeff Brown2352b972011-04-12 22:39:53 -0700252}
253
254void PointerController::clearSpots() {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000255 if (!mEnabled) return;
256
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800257 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000258 clearSpotsLocked();
259}
Jeff Brown2352b972011-04-12 22:39:53 -0700260
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800261void PointerController::clearSpotsLocked() {
Michael Wright21401ad92022-10-22 03:23:55 +0100262 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000263 spotController.clearSpots();
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800264 }
Jeff Brown2352b972011-04-12 22:39:53 -0700265}
266
267void PointerController::setInactivityTimeout(InactivityTimeout inactivityTimeout) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000268 mContext.setInactivityTimeout(inactivityTimeout);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800269}
270
Jun Mukai19a56012015-11-24 11:25:52 -0800271void PointerController::reloadPointerResources() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800272 std::scoped_lock lock(getLock());
Jun Mukai19a56012015-11-24 11:25:52 -0800273
Michael Wright21401ad92022-10-22 03:23:55 +0100274 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000275 spotController.reloadSpotResources();
276 }
Jun Mukai19a56012015-11-24 11:25:52 -0800277
Liam Harringtonc782be62020-07-17 19:48:24 +0000278 if (mCursorController.resourcesLoaded()) {
279 bool getAdditionalMouseResources = false;
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900280 if (mLocked.presentation == PointerController::Presentation::POINTER ||
281 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000282 getAdditionalMouseResources = true;
283 }
284 mCursorController.reloadPointerResources(getAdditionalMouseResources);
Arthur Hungb9b32002018-12-18 17:39:43 +0800285 }
286}
287
288void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000289 struct PointerDisplayChangeArgs {
290 int32_t displayId;
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000291 FloatPoint cursorPosition;
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000292 };
293 std::optional<PointerDisplayChangeArgs> pointerDisplayChanged;
Liam Harringtonc782be62020-07-17 19:48:24 +0000294
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000295 { // acquire lock
296 std::scoped_lock lock(getLock());
297
298 bool getAdditionalMouseResources = false;
299 if (mLocked.presentation == PointerController::Presentation::POINTER ||
300 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
301 getAdditionalMouseResources = true;
302 }
303 mCursorController.setDisplayViewport(viewport, getAdditionalMouseResources);
304 if (viewport.displayId != mLocked.pointerDisplayId) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000305 mLocked.pointerDisplayId = viewport.displayId;
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000306 pointerDisplayChanged = {viewport.displayId, mCursorController.getPosition()};
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000307 }
308 } // release lock
309
310 if (pointerDisplayChanged) {
311 // Notify the policy without holding the pointer controller lock.
312 mContext.getPolicy()->onPointerDisplayIdChanged(pointerDisplayChanged->displayId,
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000313 pointerDisplayChanged->cursorPosition);
Prabir Pradhan0e3d6652022-03-10 14:39:46 +0000314 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800315}
316
Brandon Pollack015f5d92022-06-02 06:59:33 +0000317void PointerController::updatePointerIcon(PointerIconStyle iconId) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000318 if (!mEnabled) return;
319
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800320 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000321 mCursorController.updatePointerIcon(iconId);
Jun Mukai1db53972015-09-11 18:08:31 -0700322}
323
Jun Mukaid4eaef72015-10-30 15:54:33 -0700324void PointerController::setCustomPointerIcon(const SpriteIcon& icon) {
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.setCustomPointerIcon(icon);
Jun Mukaic0c0ac32015-10-27 10:09:21 -0700329}
330
Jeff Brown2352b972011-04-12 22:39:53 -0700331void PointerController::doInactivityTimeout() {
Michael Wright6853fe62020-07-02 00:01:38 +0100332 fade(Transition::GRADUAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800333}
334
Prabir Pradhanc2200182023-06-09 23:39:15 +0000335void PointerController::onDisplayViewportsUpdated(const std::vector<DisplayViewport>& viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000336 std::unordered_set<int32_t> displayIdSet;
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000337 for (const DisplayViewport& viewport : viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000338 displayIdSet.insert(viewport.displayId);
Arthur Hungb9b32002018-12-18 17:39:43 +0800339 }
340
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800341 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000342 for (auto it = mLocked.spotControllers.begin(); it != mLocked.spotControllers.end();) {
Michael Wright21401ad92022-10-22 03:23:55 +0100343 int32_t displayId = it->first;
344 if (!displayIdSet.count(displayId)) {
Liam Harringtonce637132020-08-14 04:00:11 +0000345 /*
346 * Ensures that an in-progress animation won't dereference
347 * a null pointer to TouchSpotController.
348 */
Michael Wright21401ad92022-10-22 03:23:55 +0100349 mContext.removeAnimationCallback(displayId);
Liam Harringtonc782be62020-07-17 19:48:24 +0000350 it = mLocked.spotControllers.erase(it);
Jun Mukai1db53972015-09-11 18:08:31 -0700351 } else {
Liam Harringtonc782be62020-07-17 19:48:24 +0000352 ++it;
Jeff Brown2352b972011-04-12 22:39:53 -0700353 }
354 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800355}
356
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800357void PointerController::onDisplayInfosChangedLocked(
358 const std::vector<gui::DisplayInfo>& displayInfo) {
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000359 mLocked.mDisplayInfos = displayInfo;
360}
361
362const ui::Transform& PointerController::getTransformForDisplayLocked(int displayId) const {
363 const auto& di = mLocked.mDisplayInfos;
364 auto it = std::find_if(di.begin(), di.end(), [displayId](const gui::DisplayInfo& info) {
365 return info.displayId == displayId;
366 });
367 return it != di.end() ? it->transform : kIdentityTransform;
368}
369
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000370std::string PointerController::dump() {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000371 if (!mEnabled) {
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000372 return INDENT "PointerController: DISABLED due to ongoing PointerChoreographer refactor\n";
Prabir Pradhan3401d232023-06-15 23:15:32 +0000373 }
374
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000375 std::string dump = INDENT "PointerController:\n";
Michael Wright72a89132022-10-22 03:16:31 +0100376 std::scoped_lock lock(getLock());
377 dump += StringPrintf(INDENT2 "Presentation: %s\n",
378 ftl::enum_string(mLocked.presentation).c_str());
379 dump += StringPrintf(INDENT2 "Pointer Display ID: %" PRIu32 "\n", mLocked.pointerDisplayId);
Michael Wright83577752022-10-28 16:24:33 +0100380 dump += StringPrintf(INDENT2 "Viewports:\n");
381 for (const auto& info : mLocked.mDisplayInfos) {
382 info.dump(dump, INDENT3);
383 }
Michael Wright20f5fd82022-10-28 14:12:24 +0100384 dump += INDENT2 "Spot Controllers:\n";
385 for (const auto& [_, spotController] : mLocked.spotControllers) {
386 spotController.dump(dump, INDENT3);
387 }
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000388 return dump;
Michael Wright72a89132022-10-22 03:16:31 +0100389}
390
Byoungho Jung6a2ce942023-10-07 16:19:19 +0900391// --- MousePointerController ---
392
393MousePointerController::MousePointerController(const sp<PointerControllerPolicyInterface>& policy,
394 const sp<Looper>& looper,
395 SpriteController& spriteController, bool enabled)
396 : PointerController(policy, looper, spriteController, enabled) {
397 PointerController::setPresentation(Presentation::POINTER);
398}
399
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800400} // namespace android