blob: 11b27a2149840723489bc81e21753977c610cf70 [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 Pradhan7dff1422024-05-03 23:33:28 +000066 SpriteController& spriteController, ControllerType type) {
Liam Harringtonc782be62020-07-17 19:48:24 +000067 // using 'new' to access non-public constructor
Byoungho Jung6a2ce942023-10-07 16:19:19 +090068 std::shared_ptr<PointerController> controller;
69 switch (type) {
70 case ControllerType::MOUSE:
71 controller = std::shared_ptr<PointerController>(
Prabir Pradhan7dff1422024-05-03 23:33:28 +000072 new MousePointerController(policy, looper, spriteController));
Byoungho Jung6a2ce942023-10-07 16:19:19 +090073 break;
Byoungho Jung51282e82023-10-27 18:15:41 +090074 case ControllerType::TOUCH:
75 controller = std::shared_ptr<PointerController>(
Prabir Pradhan7dff1422024-05-03 23:33:28 +000076 new TouchPointerController(policy, looper, spriteController));
Byoungho Jung51282e82023-10-27 18:15:41 +090077 break;
Byoungho Jung08daa252023-10-27 20:55:18 +090078 case ControllerType::STYLUS:
79 controller = std::shared_ptr<PointerController>(
Prabir Pradhan7dff1422024-05-03 23:33:28 +000080 new StylusPointerController(policy, looper, spriteController));
Byoungho Jung08daa252023-10-27 20:55:18 +090081 break;
Byoungho Jung6a2ce942023-10-07 16:19:19 +090082 default:
Prabir Pradhan7dff1422024-05-03 23:33:28 +000083 LOG_ALWAYS_FATAL("Invalid ControllerType: %d", static_cast<int>(type));
Byoungho Jung6a2ce942023-10-07 16:19:19 +090084 }
Jeff Brown2352b972011-04-12 22:39:53 -070085
Michael Wrighta0bc6b12020-06-26 20:25:34 +010086 /*
87 * Now we need to hook up the constructed PointerController object to its callbacks.
88 *
89 * This must be executed after the constructor but before any other methods on PointerController
90 * in order to ensure that the fully constructed object is visible on the Looper thread, since
91 * that may be a different thread than where the PointerController is initially constructed.
92 *
93 * Unfortunately, this cannot be done as part of the constructor since we need to hand out
94 * weak_ptr's which themselves cannot be constructed until there's at least one shared_ptr.
95 */
Jeff Brown5541de92011-04-11 11:54:25 -070096
Liam Harringtonc782be62020-07-17 19:48:24 +000097 controller->mContext.setHandlerController(controller);
98 controller->mContext.setCallbackController(controller);
Michael Wrighta0bc6b12020-06-26 20:25:34 +010099 return controller;
100}
Jun Mukaic0c0ac32015-10-27 10:09:21 -0700101
Michael Wrighta0bc6b12020-06-26 20:25:34 +0100102PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000103 const sp<Looper>& looper, SpriteController& spriteController)
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800104 : PointerController(
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000105 policy, looper, spriteController,
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800106 [](const sp<android::gui::WindowInfosListener>& listener) {
Linnan Li37c1b992023-11-24 13:05:13 +0800107 auto initialInfo = std::make_pair(std::vector<android::gui::WindowInfo>{},
108 std::vector<android::gui::DisplayInfo>{});
109 SurfaceComposerClient::getDefault()->addWindowInfosListener(listener,
110 &initialInfo);
Prabir Pradhanbdf93692024-01-23 18:08:28 +0000111 return initialInfo.second;
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800112 },
113 [](const sp<android::gui::WindowInfosListener>& listener) {
114 SurfaceComposerClient::getDefault()->removeWindowInfosListener(listener);
115 }) {}
116
117PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy,
Prabir Pradhan27c6d992023-08-18 19:44:55 +0000118 const sp<Looper>& looper, SpriteController& spriteController,
Linnan Li37c1b992023-11-24 13:05:13 +0800119 const WindowListenerRegisterConsumer& registerListener,
120 WindowListenerUnregisterConsumer unregisterListener)
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000121 : 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 Pradhanbdf93692024-01-23 18:08:28 +0000127 const auto& initialDisplayInfos = registerListener(mDisplayInfoListener);
Linnan Li37c1b992023-11-24 13:05:13 +0800128 onDisplayInfosChangedLocked(initialDisplayInfos);
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000129}
130
131PointerController::~PointerController() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800132 mDisplayInfoListener->onPointerControllerDestroyed();
133 mUnregisterWindowInfosListener(mDisplayInfoListener);
134}
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 {
141 return mCursorController.getBounds();
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800142}
143
144void PointerController::move(float deltaX, float deltaY) {
Linnan Li0defadf2024-05-05 19:17:05 +0800145 const ui::LogicalDisplayId displayId = mCursorController.getDisplayId();
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000146 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) {
Linnan Li0defadf2024-05-05 19:17:05 +0800156 const ui::LogicalDisplayId displayId = mCursorController.getDisplayId();
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000157 vec2 transformed;
158 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800159 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000160 const auto& transform = getTransformForDisplayLocked(displayId);
161 transformed = transform.transform(x, y);
162 }
163 mCursorController.setPosition(transformed.x, transformed.y);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800164}
165
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000166FloatPoint PointerController::getPosition() const {
Linnan Li0defadf2024-05-05 19:17:05 +0800167 const ui::LogicalDisplayId displayId = mCursorController.getDisplayId();
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000168 const auto p = mCursorController.getPosition();
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000169 {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800170 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000171 const auto& transform = getTransformForDisplayLocked(displayId);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +0000172 return FloatPoint{transform.inverse().transform(p.x, p.y)};
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000173 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800174}
175
Linnan Li0defadf2024-05-05 19:17:05 +0800176ui::LogicalDisplayId PointerController::getDisplayId() const {
Liam Harringtonc782be62020-07-17 19:48:24 +0000177 return mCursorController.getDisplayId();
Arthur Hungb9b32002018-12-18 17:39:43 +0800178}
179
Jeff Brown538881e2011-05-25 18:23:38 -0700180void PointerController::fade(Transition transition) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800181 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000182 mCursorController.fade(transition);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800183}
184
Jeff Brown538881e2011-05-25 18:23:38 -0700185void PointerController::unfade(Transition transition) {
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 Pradhan5693cee2021-12-31 06:51:15 -0800191 std::scoped_lock lock(getLock());
Jeff Brown05dc66a2011-03-02 14:41:58 -0800192
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800193 if (mLocked.presentation == presentation) {
194 return;
Jun Mukai1db53972015-09-11 18:08:31 -0700195 }
196
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800197 mLocked.presentation = presentation;
Jeff Brown2352b972011-04-12 22:39:53 -0700198
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000199 // The presentation mode is only set once when the PointerController is constructed,
200 // before the display viewport is provided.
201 mCursorController.setStylusHoverMode(presentation == Presentation::STYLUS_HOVER);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800202}
203
Liam Harringtonc782be62020-07-17 19:48:24 +0000204void PointerController::setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
Linnan Li0defadf2024-05-05 19:17:05 +0800205 BitSet32 spotIdBits, ui::LogicalDisplayId displayId) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800206 std::scoped_lock lock(getLock());
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000207 std::array<PointerCoords, MAX_POINTERS> outSpotCoords{};
208 const ui::Transform& transform = getTransformForDisplayLocked(displayId);
209
210 for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) {
211 const uint32_t index = spotIdToIndex[idBits.clearFirstMarkedBit()];
212
213 const vec2 xy = transform.transform(spotCoords[index].getXYValue());
214 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_X, xy.x);
215 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y);
216
217 float pressure = spotCoords[index].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE);
218 outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure);
219 }
220
Liam Harringtonc782be62020-07-17 19:48:24 +0000221 auto it = mLocked.spotControllers.find(displayId);
222 if (it == mLocked.spotControllers.end()) {
223 mLocked.spotControllers.try_emplace(displayId, displayId, mContext);
Jeff Brown2352b972011-04-12 22:39:53 -0700224 }
Arpit Singh80fd68a2024-03-26 18:41:06 +0000225 bool skipScreenshot = mLocked.displaysToSkipScreenshot.find(displayId) !=
226 mLocked.displaysToSkipScreenshot.end();
227 mLocked.spotControllers.at(displayId).setSpots(outSpotCoords.data(), spotIdToIndex, spotIdBits,
228 skipScreenshot);
Jeff Brown2352b972011-04-12 22:39:53 -0700229}
230
231void PointerController::clearSpots() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800232 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000233 clearSpotsLocked();
234}
Jeff Brown2352b972011-04-12 22:39:53 -0700235
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800236void PointerController::clearSpotsLocked() {
Michael Wright21401ad92022-10-22 03:23:55 +0100237 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000238 spotController.clearSpots();
Prabir Pradhanca7d7232020-01-31 17:42:34 -0800239 }
Jeff Brown2352b972011-04-12 22:39:53 -0700240}
241
242void PointerController::setInactivityTimeout(InactivityTimeout inactivityTimeout) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000243 mContext.setInactivityTimeout(inactivityTimeout);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800244}
245
Jun Mukai19a56012015-11-24 11:25:52 -0800246void PointerController::reloadPointerResources() {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800247 std::scoped_lock lock(getLock());
Jun Mukai19a56012015-11-24 11:25:52 -0800248
Michael Wright21401ad92022-10-22 03:23:55 +0100249 for (auto& [displayId, spotController] : mLocked.spotControllers) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000250 spotController.reloadSpotResources();
251 }
Jun Mukai19a56012015-11-24 11:25:52 -0800252
Liam Harringtonc782be62020-07-17 19:48:24 +0000253 if (mCursorController.resourcesLoaded()) {
254 bool getAdditionalMouseResources = false;
Seunghwan Choi670b33d2023-01-13 21:12:59 +0900255 if (mLocked.presentation == PointerController::Presentation::POINTER ||
256 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000257 getAdditionalMouseResources = true;
258 }
259 mCursorController.reloadPointerResources(getAdditionalMouseResources);
Arthur Hungb9b32002018-12-18 17:39:43 +0800260 }
261}
262
263void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000264 { // acquire lock
265 std::scoped_lock lock(getLock());
266
267 bool getAdditionalMouseResources = false;
268 if (mLocked.presentation == PointerController::Presentation::POINTER ||
269 mLocked.presentation == PointerController::Presentation::STYLUS_HOVER) {
270 getAdditionalMouseResources = true;
271 }
272 mCursorController.setDisplayViewport(viewport, getAdditionalMouseResources);
273 if (viewport.displayId != mLocked.pointerDisplayId) {
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000274 mLocked.pointerDisplayId = viewport.displayId;
Prabir Pradhan692bbdb2023-02-24 01:52:13 +0000275 }
276 } // release lock
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800277}
278
Brandon Pollack015f5d92022-06-02 06:59:33 +0000279void PointerController::updatePointerIcon(PointerIconStyle iconId) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800280 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000281 mCursorController.updatePointerIcon(iconId);
Jun Mukai1db53972015-09-11 18:08:31 -0700282}
283
Jun Mukaid4eaef72015-10-30 15:54:33 -0700284void PointerController::setCustomPointerIcon(const SpriteIcon& icon) {
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800285 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000286 mCursorController.setCustomPointerIcon(icon);
Jun Mukaic0c0ac32015-10-27 10:09:21 -0700287}
288
Arpit Singhf4ae0ac2024-03-26 18:41:06 +0000289void PointerController::setSkipScreenshotFlagForDisplay(ui::LogicalDisplayId displayId) {
Arpit Singh80fd68a2024-03-26 18:41:06 +0000290 std::scoped_lock lock(getLock());
Arpit Singhf4ae0ac2024-03-26 18:41:06 +0000291 mLocked.displaysToSkipScreenshot.insert(displayId);
292 mCursorController.setSkipScreenshot(true);
293}
294
295void PointerController::clearSkipScreenshotFlags() {
296 std::scoped_lock lock(getLock());
297 mLocked.displaysToSkipScreenshot.clear();
298 mCursorController.setSkipScreenshot(false);
Arpit Singh80fd68a2024-03-26 18:41:06 +0000299}
300
Jeff Brown2352b972011-04-12 22:39:53 -0700301void PointerController::doInactivityTimeout() {
Michael Wright6853fe62020-07-02 00:01:38 +0100302 fade(Transition::GRADUAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800303}
304
Prabir Pradhanc2200182023-06-09 23:39:15 +0000305void PointerController::onDisplayViewportsUpdated(const std::vector<DisplayViewport>& viewports) {
Linnan Li0defadf2024-05-05 19:17:05 +0800306 std::unordered_set<ui::LogicalDisplayId> displayIdSet;
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000307 for (const DisplayViewport& viewport : viewports) {
Liam Harringtonc782be62020-07-17 19:48:24 +0000308 displayIdSet.insert(viewport.displayId);
Arthur Hungb9b32002018-12-18 17:39:43 +0800309 }
310
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800311 std::scoped_lock lock(getLock());
Liam Harringtonc782be62020-07-17 19:48:24 +0000312 for (auto it = mLocked.spotControllers.begin(); it != mLocked.spotControllers.end();) {
Linnan Li0defadf2024-05-05 19:17:05 +0800313 ui::LogicalDisplayId displayId = it->first;
Michael Wright21401ad92022-10-22 03:23:55 +0100314 if (!displayIdSet.count(displayId)) {
Liam Harringtonce637132020-08-14 04:00:11 +0000315 /*
316 * Ensures that an in-progress animation won't dereference
317 * a null pointer to TouchSpotController.
318 */
Michael Wright21401ad92022-10-22 03:23:55 +0100319 mContext.removeAnimationCallback(displayId);
Liam Harringtonc782be62020-07-17 19:48:24 +0000320 it = mLocked.spotControllers.erase(it);
Jun Mukai1db53972015-09-11 18:08:31 -0700321 } else {
Liam Harringtonc782be62020-07-17 19:48:24 +0000322 ++it;
Jeff Brown2352b972011-04-12 22:39:53 -0700323 }
324 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800325}
326
Prabir Pradhan5693cee2021-12-31 06:51:15 -0800327void PointerController::onDisplayInfosChangedLocked(
328 const std::vector<gui::DisplayInfo>& displayInfo) {
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000329 mLocked.mDisplayInfos = displayInfo;
330}
331
Linnan Li0defadf2024-05-05 19:17:05 +0800332const ui::Transform& PointerController::getTransformForDisplayLocked(
333 ui::LogicalDisplayId displayId) const {
Prabir Pradhanf97fac32021-11-18 16:40:34 +0000334 const auto& di = mLocked.mDisplayInfos;
335 auto it = std::find_if(di.begin(), di.end(), [displayId](const gui::DisplayInfo& info) {
336 return info.displayId == displayId;
337 });
338 return it != di.end() ? it->transform : kIdentityTransform;
339}
340
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000341std::string PointerController::dump() {
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000342 std::string dump = INDENT "PointerController:\n";
Michael Wright72a89132022-10-22 03:16:31 +0100343 std::scoped_lock lock(getLock());
344 dump += StringPrintf(INDENT2 "Presentation: %s\n",
345 ftl::enum_string(mLocked.presentation).c_str());
Linnan Li0defadf2024-05-05 19:17:05 +0800346 dump += StringPrintf(INDENT2 "Pointer Display ID: %s\n",
347 mLocked.pointerDisplayId.toString().c_str());
Michael Wright83577752022-10-28 16:24:33 +0100348 dump += StringPrintf(INDENT2 "Viewports:\n");
349 for (const auto& info : mLocked.mDisplayInfos) {
350 info.dump(dump, INDENT3);
351 }
Michael Wright20f5fd82022-10-28 14:12:24 +0100352 dump += INDENT2 "Spot Controllers:\n";
353 for (const auto& [_, spotController] : mLocked.spotControllers) {
354 spotController.dump(dump, INDENT3);
355 }
Prabir Pradhanb41c2192023-09-06 00:48:22 +0000356 return dump;
Michael Wright72a89132022-10-22 03:16:31 +0100357}
358
Byoungho Jung6a2ce942023-10-07 16:19:19 +0900359// --- MousePointerController ---
360
361MousePointerController::MousePointerController(const sp<PointerControllerPolicyInterface>& policy,
362 const sp<Looper>& looper,
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000363 SpriteController& spriteController)
364 : PointerController(policy, looper, spriteController) {
Byoungho Jung6a2ce942023-10-07 16:19:19 +0900365 PointerController::setPresentation(Presentation::POINTER);
366}
367
Prabir Pradhanb0e28072023-11-08 21:09:34 +0000368MousePointerController::~MousePointerController() {
369 MousePointerController::fade(Transition::IMMEDIATE);
370}
371
Byoungho Jung51282e82023-10-27 18:15:41 +0900372// --- TouchPointerController ---
373
374TouchPointerController::TouchPointerController(const sp<PointerControllerPolicyInterface>& policy,
375 const sp<Looper>& looper,
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000376 SpriteController& spriteController)
377 : PointerController(policy, looper, spriteController) {
Byoungho Jung51282e82023-10-27 18:15:41 +0900378 PointerController::setPresentation(Presentation::SPOT);
379}
380
Prabir Pradhanb0e28072023-11-08 21:09:34 +0000381TouchPointerController::~TouchPointerController() {
382 TouchPointerController::clearSpots();
383}
384
Byoungho Jung08daa252023-10-27 20:55:18 +0900385// --- StylusPointerController ---
386
387StylusPointerController::StylusPointerController(const sp<PointerControllerPolicyInterface>& policy,
388 const sp<Looper>& looper,
Prabir Pradhan7dff1422024-05-03 23:33:28 +0000389 SpriteController& spriteController)
390 : PointerController(policy, looper, spriteController) {
Byoungho Jung08daa252023-10-27 20:55:18 +0900391 PointerController::setPresentation(Presentation::STYLUS_HOVER);
392}
393
Prabir Pradhanb0e28072023-11-08 21:09:34 +0000394StylusPointerController::~StylusPointerController() {
395 StylusPointerController::fade(Transition::IMMEDIATE);
396}
397
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800398} // namespace android