blob: 246db6c64c7f6dc22d53e904b026aef0415a4e5b [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 Jung6a2ce942023-10-07 16:19:19 +090081 case ControllerType::LEGACY:
82 default:
83 controller = std::shared_ptr<PointerController>(
84 new PointerController(policy, looper, spriteController, enabled));
85 break;
86 }
Jeff Brown2352b972011-04-12 22:39:53 -070087
Michael Wrighta0bc6b12020-06-26 20:25:34 +010088 /*
89 * Now we need to hook up the constructed PointerController object to its callbacks.
90 *
91 * This must be executed after the constructor but before any other methods on PointerController
92 * in order to ensure that the fully constructed object is visible on the Looper thread, since
93 * that may be a different thread than where the PointerController is initially constructed.
94 *
95 * Unfortunately, this cannot be done as part of the constructor since we need to hand out
96 * weak_ptr's which themselves cannot be constructed until there's at least one shared_ptr.
97 */
Jeff Brown5541de92011-04-11 11:54:25 -070098
Liam Harringtonc782be62020-07-17 19:48:24 +000099 controller->mContext.setHandlerController(controller);
100 controller->mContext.setCallbackController(controller);
Michael Wrighta0bc6b12020-06-26 20:25:34 +0100101 return controller;
102}
Jun Mukaic0c0ac32015-10-27 10:09:21 -0700103
Michael Wrighta0bc6b12020-06-26 20:25:34 +0100104PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan3401d232023-06-15 23:15:32 +0000105 const sp<Looper>& looper, SpriteController& spriteController,
106 bool enabled)
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800107 : PointerController(
Prabir Pradhan3401d232023-06-15 23:15:32 +0000108 policy, looper, spriteController, enabled,
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800109 [](const sp<android::gui::WindowInfosListener>& listener) {
110 SurfaceComposerClient::getDefault()->addWindowInfosListener(listener);
111 },
112 [](const sp<android::gui::WindowInfosListener>& listener) {
113 SurfaceComposerClient::getDefault()->removeWindowInfosListener(listener);
114 }) {}
115
116PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan27c6d992023-08-18 19:44:55 +0000117 const sp<Looper>& looper, SpriteController& spriteController,
Prabir Pradhan3401d232023-06-15 23:15:32 +0000118 bool enabled, WindowListenerConsumer registerListener,
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800119 WindowListenerConsumer unregisterListener)
Prabir Pradhan3401d232023-06-15 23:15:32 +0000120 : mEnabled(enabled),
121 mContext(policy, looper, spriteController, *this),
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000122 mCursorController(mContext),
Prabir Pradhan4cc1a632023-06-09 21:31:26 +0000123 mDisplayInfoListener(sp<DisplayInfoListener>::make(this)),
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800124 mUnregisterWindowInfosListener(std::move(unregisterListener)) {
125 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000126 mLocked.presentation = Presentation::SPOT;
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800127 registerListener(mDisplayInfoListener);
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000128}
129
130PointerController::~PointerController() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800131 mDisplayInfoListener->onPointerControllerDestroyed();
132 mUnregisterWindowInfosListener(mDisplayInfoListener);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000133 mContext.getPolicy()->onPointerDisplayIdChanged(ADISPLAY_ID_NONE, FloatPoint{0, 0});
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800134}
135
136std::mutex& PointerController::getLock() const {
137 return mDisplayInfoListener->mLock;
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800138}
139
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000140std::optional<FloatRect> PointerController::getBounds() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000141 if (!mEnabled) return {};
142
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000143 return mCursorController.getBounds();
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800144}
145
146void PointerController::move(float deltaX, float deltaY) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000147 if (!mEnabled) return;
148
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000149 const int32_t displayId = mCursorController.getDisplayId();
150 vec2 transformed;
151 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800152 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000153 const auto& transform = getTransformForDisplayLocked(displayId);
154 transformed = transformWithoutTranslation(transform, {deltaX, deltaY});
155 }
156 mCursorController.move(transformed.x, transformed.y);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800157}
158
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800159void PointerController::setPosition(float x, float y) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000160 if (!mEnabled) return;
161
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000162 const int32_t displayId = mCursorController.getDisplayId();
163 vec2 transformed;
164 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800165 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000166 const auto& transform = getTransformForDisplayLocked(displayId);
167 transformed = transform.transform(x, y);
168 }
169 mCursorController.setPosition(transformed.x, transformed.y);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800170}
171
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000172FloatPoint PointerController::getPosition() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000173 if (!mEnabled) {
174 return FloatPoint{AMOTION_EVENT_INVALID_CURSOR_POSITION,
175 AMOTION_EVENT_INVALID_CURSOR_POSITION};
176 }
177
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000178 const int32_t displayId = mCursorController.getDisplayId();
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000179 const auto p = mCursorController.getPosition();
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000180 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800181 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000182 const auto& transform = getTransformForDisplayLocked(displayId);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000183 return FloatPoint{transform.inverse().transform(p.x, p.y)};
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000184 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800185}
186
Arthur Hungb9b32002018-12-18 17:39:43 +0800187int32_t PointerController::getDisplayId() const {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000188 if (!mEnabled) return ADISPLAY_ID_NONE;
189
Liam Harringtonc782be62020-07-17 19:48:24 +0000190 return mCursorController.getDisplayId();
Arthur Hungb9b32002018-12-18 17:39:43 +0800191}
192
Jeff Brown538881e2011-05-25 18:23:38 -0700193void PointerController::fade(Transition transition) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000194 if (!mEnabled) return;
195
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800196 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000197 mCursorController.fade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800198}
199
Jeff Brown538881e2011-05-25 18:23:38 -0700200void PointerController::unfade(Transition transition) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000201 if (!mEnabled) return;
202
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800203 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000204 mCursorController.unfade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800205}
206
Jeff Brown2352b972011-04-12 22:39:53 -0700207void PointerController::setPresentation(Presentation presentation) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000208 if (!mEnabled) return;
209
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800210 std::scoped_lock lock(getLock());
Jeff Brown05dc66a2011-03-02 14:41:58 -0800211
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800212 if (mLocked.presentation == presentation) {
213 return;
Jun Mukai1db53972015-09-11 18:08:31 -0700214 }
215
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800216 mLocked.presentation = presentation;
Jeff Brown2352b972011-04-12 22:39:53 -0700217
Liam Harringtonc782be62020-07-17 19:48:24 +0000218 if (!mCursorController.isViewportValid()) {
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800219 return;
220 }
221
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900222 if (presentation == Presentation::POINTER || presentation == Presentation::STYLUS_HOVER) {
223 // For now, we support stylus hover using the mouse cursor implementation.
224 // TODO: Add proper support for stylus hover icons.
225 mCursorController.setStylusHoverMode(presentation == Presentation::STYLUS_HOVER);
226
Liam Harringtonc782be62020-07-17 19:48:24 +0000227 mCursorController.getAdditionalMouseResources();
228 clearSpotsLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800229 }
230}
231
Liam Harringtonc782be62020-07-17 19:48:24 +0000232void PointerController::setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
233 BitSet32 spotIdBits, int32_t displayId) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000234 if (!mEnabled) return;
235
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800236 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000237 std::array<PointerCoords, MAX_POINTERS> outSpotCoords{};
238 const ui::Transform& transform = getTransformForDisplayLocked(displayId);
239
240 for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) {
241 const uint32_t index = spotIdToIndex[idBits.clearFirstMarkedBit()];
242
243 const vec2 xy = transform.transform(spotCoords[index].getXYValue());
244 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_X, xy.x);
245 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y);
246
247 float pressure = spotCoords[index].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE);
248 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure);
249 }
250
Liam Harringtonc782be62020-07-17 19:48:24 +0000251 auto it = mLocked.spotControllers.find(displayId);
252 if (it == mLocked.spotControllers.end()) {
253 mLocked.spotControllers.try_emplace(displayId, displayId, mContext);
Jeff Brown2352b972011-04-12 22:39:53 -0700254 }
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000255 mLocked.spotControllers.at(displayId).setSpots(outSpotCoords.data(), spotIdToIndex, spotIdBits);
Jeff Brown2352b972011-04-12 22:39:53 -0700256}
257
258void PointerController::clearSpots() {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000259 if (!mEnabled) return;
260
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800261 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000262 clearSpotsLocked();
263}
Jeff Brown2352b972011-04-12 22:39:53 -0700264
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800265void PointerController::clearSpotsLocked() {
Michael Wright21401ad92022-10-22 03:23:55 +0100266 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000267 spotController.clearSpots();
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800268 }
Jeff Brown2352b972011-04-12 22:39:53 -0700269}
270
271void PointerController::setInactivityTimeout(InactivityTimeout inactivityTimeout) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000272 mContext.setInactivityTimeout(inactivityTimeout);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800273}
274
Jun Mukai19a56012015-11-24 11:25:52 -0800275void PointerController::reloadPointerResources() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800276 std::scoped_lock lock(getLock());
Jun Mukai19a56012015-11-24 11:25:52 -0800277
Michael Wright21401ad92022-10-22 03:23:55 +0100278 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000279 spotController.reloadSpotResources();
280 }
Jun Mukai19a56012015-11-24 11:25:52 -0800281
Liam Harringtonc782be62020-07-17 19:48:24 +0000282 if (mCursorController.resourcesLoaded()) {
283 bool getAdditionalMouseResources = false;
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900284 if (mLocked.presentation == PointerController::Presentation::POINTER ||
285 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000286 getAdditionalMouseResources = true;
287 }
288 mCursorController.reloadPointerResources(getAdditionalMouseResources);
Arthur Hungb9b32002018-12-18 17:39:43 +0800289 }
290}
291
292void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000293 struct PointerDisplayChangeArgs {
294 int32_t displayId;
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000295 FloatPoint cursorPosition;
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000296 };
297 std::optional<PointerDisplayChangeArgs> pointerDisplayChanged;
Liam Harringtonc782be62020-07-17 19:48:24 +0000298
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000299 { // acquire lock
300 std::scoped_lock lock(getLock());
301
302 bool getAdditionalMouseResources = false;
303 if (mLocked.presentation == PointerController::Presentation::POINTER ||
304 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
305 getAdditionalMouseResources = true;
306 }
307 mCursorController.setDisplayViewport(viewport, getAdditionalMouseResources);
308 if (viewport.displayId != mLocked.pointerDisplayId) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000309 mLocked.pointerDisplayId = viewport.displayId;
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000310 pointerDisplayChanged = {viewport.displayId, mCursorController.getPosition()};
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000311 }
312 } // release lock
313
314 if (pointerDisplayChanged) {
315 // Notify the policy without holding the pointer controller lock.
316 mContext.getPolicy()->onPointerDisplayIdChanged(pointerDisplayChanged->displayId,
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000317 pointerDisplayChanged->cursorPosition);
Prabir Pradhan0e3d6652022-03-10 14:39:46 +0000318 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800319}
320
Brandon Pollack015f5d92022-06-02 06:59:33 +0000321void PointerController::updatePointerIcon(PointerIconStyle iconId) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000322 if (!mEnabled) return;
323
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800324 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000325 mCursorController.updatePointerIcon(iconId);
Jun Mukai1db53972015-09-11 18:08:31 -0700326}
327
Jun Mukaid4eaef72015-10-30 15:54:33 -0700328void PointerController::setCustomPointerIcon(const SpriteIcon& icon) {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000329 if (!mEnabled) return;
330
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800331 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000332 mCursorController.setCustomPointerIcon(icon);
Jun Mukaic0c0ac32015-10-27 10:09:21 -0700333}
334
Jeff Brown2352b972011-04-12 22:39:53 -0700335void PointerController::doInactivityTimeout() {
Michael Wright6853fe62020-07-02 00:01:38 +0100336 fade(Transition::GRADUAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800337}
338
Prabir Pradhanc2200182023-06-09 23:39:15 +0000339void PointerController::onDisplayViewportsUpdated(const std::vector<DisplayViewport>& viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000340 std::unordered_set<int32_t> displayIdSet;
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000341 for (const DisplayViewport& viewport : viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000342 displayIdSet.insert(viewport.displayId);
Arthur Hungb9b32002018-12-18 17:39:43 +0800343 }
344
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800345 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000346 for (auto it = mLocked.spotControllers.begin(); it != mLocked.spotControllers.end();) {
Michael Wright21401ad92022-10-22 03:23:55 +0100347 int32_t displayId = it->first;
348 if (!displayIdSet.count(displayId)) {
Liam Harringtonce637132020-08-14 04:00:11 +0000349 /*
350 * Ensures that an in-progress animation won't dereference
351 * a null pointer to TouchSpotController.
352 */
Michael Wright21401ad92022-10-22 03:23:55 +0100353 mContext.removeAnimationCallback(displayId);
Liam Harringtonc782be62020-07-17 19:48:24 +0000354 it = mLocked.spotControllers.erase(it);
Jun Mukai1db53972015-09-11 18:08:31 -0700355 } else {
Liam Harringtonc782be62020-07-17 19:48:24 +0000356 ++it;
Jeff Brown2352b972011-04-12 22:39:53 -0700357 }
358 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800359}
360
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800361void PointerController::onDisplayInfosChangedLocked(
362 const std::vector<gui::DisplayInfo>& displayInfo) {
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000363 mLocked.mDisplayInfos = displayInfo;
364}
365
366const ui::Transform& PointerController::getTransformForDisplayLocked(int displayId) const {
367 const auto& di = mLocked.mDisplayInfos;
368 auto it = std::find_if(di.begin(), di.end(), [displayId](const gui::DisplayInfo& info) {
369 return info.displayId == displayId;
370 });
371 return it != di.end() ? it->transform : kIdentityTransform;
372}
373
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000374std::string PointerController::dump() {
Prabir Pradhan3401d232023-06-15 23:15:32 +0000375 if (!mEnabled) {
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000376 return INDENT "PointerController: DISABLED due to ongoing PointerChoreographer refactor\n";
Prabir Pradhan3401d232023-06-15 23:15:32 +0000377 }
378
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000379 std::string dump = INDENT "PointerController:\n";
Michael Wright72a89132022-10-22 03:16:31 +0100380 std::scoped_lock lock(getLock());
381 dump += StringPrintf(INDENT2 "Presentation: %s\n",
382 ftl::enum_string(mLocked.presentation).c_str());
383 dump += StringPrintf(INDENT2 "Pointer Display ID: %" PRIu32 "\n", mLocked.pointerDisplayId);
Michael Wright83577752022-10-28 16:24:33 +0100384 dump += StringPrintf(INDENT2 "Viewports:\n");
385 for (const auto& info : mLocked.mDisplayInfos) {
386 info.dump(dump, INDENT3);
387 }
Michael Wright20f5fd82022-10-28 14:12:24 +0100388 dump += INDENT2 "Spot Controllers:\n";
389 for (const auto& [_, spotController] : mLocked.spotControllers) {
390 spotController.dump(dump, INDENT3);
391 }
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000392 return dump;
Michael Wright72a89132022-10-22 03:16:31 +0100393}
394
Byoungho Jung6a2ce942023-10-07 16:19:19 +0900395// --- MousePointerController ---
396
397MousePointerController::MousePointerController(const sp<PointerControllerPolicyInterface>& policy,
398 const sp<Looper>& looper,
399 SpriteController& spriteController, bool enabled)
400 : PointerController(policy, looper, spriteController, enabled) {
401 PointerController::setPresentation(Presentation::POINTER);
402}
403
Byoungho Jung51282e82023-10-27 18:15:41 +0900404// --- TouchPointerController ---
405
406TouchPointerController::TouchPointerController(const sp<PointerControllerPolicyInterface>& policy,
407 const sp<Looper>& looper,
408 SpriteController& spriteController, bool enabled)
409 : PointerController(policy, looper, spriteController, enabled) {
410 PointerController::setPresentation(Presentation::SPOT);
411}
412
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800413} // namespace android