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