blob: debc65a08636841220b165fe9465f228ce9a3075 [file] [log] [blame]
Michael Wrightd02c5b62014-02-10 15:10:22 -08001/*
2 * Copyright (C) 2014 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
Prabir Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Michael Wrightd02c5b62014-02-10 15:10:22 -080018
Garfield Tan888a6a42020-01-09 11:39:16 -080019#include <input/DisplayViewport.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080020#include <input/Input.h>
21#include <utils/BitSet.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080022
23namespace android {
24
Byoungho Jung99326452023-11-03 20:19:17 +090025struct SpriteIcon;
26
Prabir Pradhan2719e822023-02-28 17:39:36 +000027struct FloatPoint {
28 float x;
29 float y;
30
31 inline FloatPoint(float x, float y) : x(x), y(y) {}
32
33 inline explicit FloatPoint(vec2 p) : x(p.x), y(p.y) {}
34
35 template <typename T, typename U>
36 operator std::tuple<T, U>() {
37 return {x, y};
38 }
39};
40
Michael Wrightd02c5b62014-02-10 15:10:22 -080041/**
42 * Interface for tracking a mouse / touch pad pointer and touch pad spots.
43 *
44 * The spots are sprites on screen that visually represent the positions of
45 * fingers
46 *
47 * The pointer controller is responsible for providing synchronization and for tracking
Prabir Pradhande69f8a2021-11-18 16:40:34 +000048 * display orientation changes if needed. It works in the display panel's coordinate space, which
49 * is the same coordinate space used by InputReader.
Michael Wrightd02c5b62014-02-10 15:10:22 -080050 */
Michael Wright17db18e2020-06-26 20:51:44 +010051class PointerControllerInterface {
Michael Wrightd02c5b62014-02-10 15:10:22 -080052protected:
Byoungho Jung6f5b16b2023-10-27 18:22:07 +090053 PointerControllerInterface() {}
54 virtual ~PointerControllerInterface() {}
Michael Wrightd02c5b62014-02-10 15:10:22 -080055
56public:
Byoungho Jungda10dd32023-10-06 17:03:45 +090057 /**
58 * Enum used to differentiate various types of PointerControllers for the transition to
59 * using PointerChoreographer.
60 *
61 * TODO(b/293587049): Refactor the PointerController class into different controller types.
62 */
63 enum class ControllerType {
Byoungho Jungda10dd32023-10-06 17:03:45 +090064 // Represents a single mouse pointer.
65 MOUSE,
Byoungho Jung6f5b16b2023-10-27 18:22:07 +090066 // Represents multiple touch spots.
67 TOUCH,
Byoungho Jungd6fe27b2023-10-27 20:49:38 +090068 // Represents a single stylus pointer.
69 STYLUS,
Byoungho Jungda10dd32023-10-06 17:03:45 +090070 };
71
72 /* Dumps the state of the pointer controller. */
73 virtual std::string dump() = 0;
74
Arpit Singha5ba9f12024-10-25 20:59:24 +000075 /* Move the pointer and return unconsumed delta if the pointer has crossed the current
76 * viewport bounds .
77 *
78 * Return value may be used to move pointer to corresponding adjacent display, if it exists in
79 * the display-topology */
80 [[nodiscard]] virtual vec2 move(float deltaX, float deltaY) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080081
Michael Wrightd02c5b62014-02-10 15:10:22 -080082 /* Sets the absolute location of the pointer. */
83 virtual void setPosition(float x, float y) = 0;
84
85 /* Gets the absolute location of the pointer. */
Prabir Pradhan2719e822023-02-28 17:39:36 +000086 virtual FloatPoint getPosition() const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080087
Michael Wrightca5bede2020-07-02 00:00:29 +010088 enum class Transition {
Michael Wrightd02c5b62014-02-10 15:10:22 -080089 // Fade/unfade immediately.
Michael Wrightca5bede2020-07-02 00:00:29 +010090 IMMEDIATE,
Michael Wrightd02c5b62014-02-10 15:10:22 -080091 // Fade/unfade gradually.
Michael Wrightca5bede2020-07-02 00:00:29 +010092 GRADUAL,
Michael Wrightd02c5b62014-02-10 15:10:22 -080093 };
94
95 /* Fades the pointer out now. */
96 virtual void fade(Transition transition) = 0;
97
98 /* Makes the pointer visible if it has faded out.
99 * The pointer never unfades itself automatically. This method must be called
100 * by the client whenever the pointer is moved or a button is pressed and it
101 * wants to ensure that the pointer becomes visible again. */
102 virtual void unfade(Transition transition) = 0;
103
Michael Wrightca5bede2020-07-02 00:00:29 +0100104 enum class Presentation {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800105 // Show the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +0100106 POINTER,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800107 // Show spots and a spot anchor in place of the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +0100108 SPOT,
Seunghwan Choi75789cd2023-01-13 20:31:59 +0900109 // Show the stylus hover pointer.
110 STYLUS_HOVER,
Michael Wright08f7a6a2022-10-22 03:14:39 +0100111
Seunghwan Choi75789cd2023-01-13 20:31:59 +0900112 ftl_last = STYLUS_HOVER,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800113 };
114
115 /* Sets the mode of the pointer controller. */
116 virtual void setPresentation(Presentation presentation) = 0;
117
118 /* Sets the spots for the current gesture.
119 * The spots are not subject to the inactivity timeout like the pointer
120 * itself it since they are expected to remain visible for so long as
121 * the fingers are on the touch pad.
122 *
123 * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant.
124 * For spotCoords, pressure != 0 indicates that the spot's location is being
125 * pressed (not hovering).
126 */
127 virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
Linnan Li13bf76a2024-05-05 19:18:02 +0800128 BitSet32 spotIdBits, ui::LogicalDisplayId displayId) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800129
130 /* Removes all spots. */
131 virtual void clearSpots() = 0;
Arthur Hungc7ad2d02018-12-18 17:41:29 +0800132
133 /* Gets the id of the display where the pointer should be shown. */
Linnan Li13bf76a2024-05-05 19:18:02 +0800134 virtual ui::LogicalDisplayId getDisplayId() const = 0;
Garfield Tan888a6a42020-01-09 11:39:16 -0800135
136 /* Sets the associated display of this pointer. Pointer should show on that display. */
137 virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
Byoungho Jung99326452023-11-03 20:19:17 +0900138
139 /* Sets the pointer icon type for mice or styluses. */
140 virtual void updatePointerIcon(PointerIconStyle iconId) = 0;
141
142 /* Sets the custom pointer icon for mice or styluses. */
143 virtual void setCustomPointerIcon(const SpriteIcon& icon) = 0;
Arpit Singh4b6ad2d2024-04-04 11:54:20 +0000144
Arpit Singh420d0742024-04-04 11:54:20 +0000145 /* Sets the flag to skip screenshot of the pointer indicators on the display for the specified
146 * displayId. This flag can only be reset with resetSkipScreenshotFlags()
Arpit Singh4b6ad2d2024-04-04 11:54:20 +0000147 */
Arpit Singh420d0742024-04-04 11:54:20 +0000148 virtual void setSkipScreenshotFlagForDisplay(ui::LogicalDisplayId displayId) = 0;
149
150 /* Resets the flag to skip screenshot of the pointer indicators for all displays. */
151 virtual void clearSkipScreenshotFlags() = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800152};
153
154} // namespace android