xref: /aosp_15_r20/frameworks/native/services/inputflinger/include/PointerControllerInterface.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
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 
17 #pragma once
18 
19 #include <input/DisplayViewport.h>
20 #include <input/Input.h>
21 #include <utils/BitSet.h>
22 
23 namespace android {
24 
25 struct SpriteIcon;
26 
27 /**
28  * Interface for tracking a mouse / touch pad pointer and touch pad spots.
29  *
30  * The spots are sprites on screen that visually represent the positions of
31  * fingers
32  *
33  * The pointer controller is responsible for providing synchronization and for tracking
34  * display orientation changes if needed. It works in the display panel's coordinate space, which
35  * is the same coordinate space used by InputReader.
36  */
37 class PointerControllerInterface {
38 protected:
PointerControllerInterface()39     PointerControllerInterface() {}
~PointerControllerInterface()40     virtual ~PointerControllerInterface() {}
41 
42 public:
43     /**
44      * Enum used to differentiate various types of PointerControllers for the transition to
45      * using PointerChoreographer.
46      *
47      * TODO(b/293587049): Refactor the PointerController class into different controller types.
48      */
49     enum class ControllerType {
50         // Represents a single mouse pointer.
51         MOUSE,
52         // Represents multiple touch spots.
53         TOUCH,
54         // Represents a single stylus pointer.
55         STYLUS,
56     };
57 
58     /* Dumps the state of the pointer controller. */
59     virtual std::string dump() = 0;
60 
61     /* Move the pointer and return unconsumed delta if the pointer has crossed the current
62      * viewport bounds.
63      *
64      * Return value may be used to move pointer to corresponding adjacent display, if it exists in
65      * the display-topology */
66     [[nodiscard]] virtual vec2 move(float deltaX, float deltaY) = 0;
67 
68     /* Sets the absolute location of the pointer. */
69     virtual void setPosition(float x, float y) = 0;
70 
71     /* Gets the absolute location of the pointer. */
72     virtual vec2 getPosition() const = 0;
73 
74     enum class Transition {
75         // Fade/unfade immediately.
76         IMMEDIATE,
77         // Fade/unfade gradually.
78         GRADUAL,
79     };
80 
81     /* Fades the pointer out now. */
82     virtual void fade(Transition transition) = 0;
83 
84     /* Makes the pointer visible if it has faded out.
85      * The pointer never unfades itself automatically.  This method must be called
86      * by the client whenever the pointer is moved or a button is pressed and it
87      * wants to ensure that the pointer becomes visible again. */
88     virtual void unfade(Transition transition) = 0;
89 
90     enum class Presentation {
91         // Show the mouse pointer.
92         POINTER,
93         // Show spots and a spot anchor in place of the mouse pointer.
94         SPOT,
95         // Show the stylus hover pointer.
96         STYLUS_HOVER,
97 
98         ftl_last = STYLUS_HOVER,
99     };
100 
101     /* Sets the mode of the pointer controller. */
102     virtual void setPresentation(Presentation presentation) = 0;
103 
104     /* Sets the spots for the current gesture.
105      * The spots are not subject to the inactivity timeout like the pointer
106      * itself it since they are expected to remain visible for so long as
107      * the fingers are on the touch pad.
108      *
109      * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant.
110      * For spotCoords, pressure != 0 indicates that the spot's location is being
111      * pressed (not hovering).
112      */
113     virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
114                           BitSet32 spotIdBits, ui::LogicalDisplayId displayId) = 0;
115 
116     /* Removes all spots. */
117     virtual void clearSpots() = 0;
118 
119     /* Gets the id of the display where the pointer should be shown. */
120     virtual ui::LogicalDisplayId getDisplayId() const = 0;
121 
122     /* Sets the associated display of this pointer. Pointer should show on that display. */
123     virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
124 
125     /* Sets the pointer icon type for mice or styluses. */
126     virtual void updatePointerIcon(PointerIconStyle iconId) = 0;
127 
128     /* Sets the custom pointer icon for mice or styluses. */
129     virtual void setCustomPointerIcon(const SpriteIcon& icon) = 0;
130 
131     /* Sets the flag to skip screenshot of the pointer indicators on the display for the specified
132      * displayId. This flag can only be reset with resetSkipScreenshotFlags()
133      */
134     virtual void setSkipScreenshotFlagForDisplay(ui::LogicalDisplayId displayId) = 0;
135 
136     /* Resets the flag to skip screenshot of the pointer indicators for all displays. */
137     virtual void clearSkipScreenshotFlags() = 0;
138 
139     virtual ui::Transform getDisplayTransform() const = 0;
140 };
141 
142 } // namespace android
143