• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FloatPoint {
26     float x;
27     float y;
28 
FloatPointFloatPoint29     inline FloatPoint(float x, float y) : x(x), y(y) {}
30 
FloatPointFloatPoint31     inline explicit FloatPoint(vec2 p) : x(p.x), y(p.y) {}
32 
33     template <typename T, typename U>
34     operator std::tuple<T, U>() {
35         return {x, y};
36     }
37 };
38 
39 /**
40  * Interface for tracking a mouse / touch pad pointer and touch pad spots.
41  *
42  * The spots are sprites on screen that visually represent the positions of
43  * fingers
44  *
45  * The pointer controller is responsible for providing synchronization and for tracking
46  * display orientation changes if needed. It works in the display panel's coordinate space, which
47  * is the same coordinate space used by InputReader.
48  */
49 class PointerControllerInterface {
50 protected:
PointerControllerInterface()51     PointerControllerInterface() { }
~PointerControllerInterface()52     virtual ~PointerControllerInterface() { }
53 
54 public:
55     /* Gets the bounds of the region that the pointer can traverse.
56      * Returns true if the bounds are available. */
57     virtual std::optional<FloatRect> getBounds() const = 0;
58 
59     /* Move the pointer. */
60     virtual void move(float deltaX, float deltaY) = 0;
61 
62     /* Sets the absolute location of the pointer. */
63     virtual void setPosition(float x, float y) = 0;
64 
65     /* Gets the absolute location of the pointer. */
66     virtual FloatPoint getPosition() const = 0;
67 
68     enum class Transition {
69         // Fade/unfade immediately.
70         IMMEDIATE,
71         // Fade/unfade gradually.
72         GRADUAL,
73     };
74 
75     /* Fades the pointer out now. */
76     virtual void fade(Transition transition) = 0;
77 
78     /* Makes the pointer visible if it has faded out.
79      * The pointer never unfades itself automatically.  This method must be called
80      * by the client whenever the pointer is moved or a button is pressed and it
81      * wants to ensure that the pointer becomes visible again. */
82     virtual void unfade(Transition transition) = 0;
83 
84     enum class Presentation {
85         // Show the mouse pointer.
86         POINTER,
87         // Show spots and a spot anchor in place of the mouse pointer.
88         SPOT,
89         // Show the stylus hover pointer.
90         STYLUS_HOVER,
91 
92         ftl_last = STYLUS_HOVER,
93     };
94 
95     /* Sets the mode of the pointer controller. */
96     virtual void setPresentation(Presentation presentation) = 0;
97 
98     /* Sets the spots for the current gesture.
99      * The spots are not subject to the inactivity timeout like the pointer
100      * itself it since they are expected to remain visible for so long as
101      * the fingers are on the touch pad.
102      *
103      * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant.
104      * For spotCoords, pressure != 0 indicates that the spot's location is being
105      * pressed (not hovering).
106      */
107     virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
108             BitSet32 spotIdBits, int32_t displayId) = 0;
109 
110     /* Removes all spots. */
111     virtual void clearSpots() = 0;
112 
113     /* Gets the id of the display where the pointer should be shown. */
114     virtual int32_t getDisplayId() const = 0;
115 
116     /* Sets the associated display of this pointer. Pointer should show on that display. */
117     virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
118 };
119 
120 } // namespace android
121