blob: 6b26e816370ee5377dbab72050234b6b4601125a [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 {
64 // The PointerController that is responsible for drawing all icons.
65 LEGACY,
66 // Represents a single mouse pointer.
67 MOUSE,
Byoungho Jung6f5b16b2023-10-27 18:22:07 +090068 // Represents multiple touch spots.
69 TOUCH,
Byoungho Jungd6fe27b2023-10-27 20:49:38 +090070 // Represents a single stylus pointer.
71 STYLUS,
Byoungho Jungda10dd32023-10-06 17:03:45 +090072 };
73
74 /* Dumps the state of the pointer controller. */
75 virtual std::string dump() = 0;
76
Michael Wrightd02c5b62014-02-10 15:10:22 -080077 /* Gets the bounds of the region that the pointer can traverse.
78 * Returns true if the bounds are available. */
Prabir Pradhan2719e822023-02-28 17:39:36 +000079 virtual std::optional<FloatRect> getBounds() const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080080
81 /* Move the pointer. */
82 virtual void move(float deltaX, float deltaY) = 0;
83
Michael Wrightd02c5b62014-02-10 15:10:22 -080084 /* Sets the absolute location of the pointer. */
85 virtual void setPosition(float x, float y) = 0;
86
87 /* Gets the absolute location of the pointer. */
Prabir Pradhan2719e822023-02-28 17:39:36 +000088 virtual FloatPoint getPosition() const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080089
Michael Wrightca5bede2020-07-02 00:00:29 +010090 enum class Transition {
Michael Wrightd02c5b62014-02-10 15:10:22 -080091 // Fade/unfade immediately.
Michael Wrightca5bede2020-07-02 00:00:29 +010092 IMMEDIATE,
Michael Wrightd02c5b62014-02-10 15:10:22 -080093 // Fade/unfade gradually.
Michael Wrightca5bede2020-07-02 00:00:29 +010094 GRADUAL,
Michael Wrightd02c5b62014-02-10 15:10:22 -080095 };
96
97 /* Fades the pointer out now. */
98 virtual void fade(Transition transition) = 0;
99
100 /* Makes the pointer visible if it has faded out.
101 * The pointer never unfades itself automatically. This method must be called
102 * by the client whenever the pointer is moved or a button is pressed and it
103 * wants to ensure that the pointer becomes visible again. */
104 virtual void unfade(Transition transition) = 0;
105
Michael Wrightca5bede2020-07-02 00:00:29 +0100106 enum class Presentation {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800107 // Show the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +0100108 POINTER,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800109 // Show spots and a spot anchor in place of the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +0100110 SPOT,
Seunghwan Choi75789cd2023-01-13 20:31:59 +0900111 // Show the stylus hover pointer.
112 STYLUS_HOVER,
Michael Wright08f7a6a2022-10-22 03:14:39 +0100113
Seunghwan Choi75789cd2023-01-13 20:31:59 +0900114 ftl_last = STYLUS_HOVER,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800115 };
116
117 /* Sets the mode of the pointer controller. */
118 virtual void setPresentation(Presentation presentation) = 0;
119
120 /* Sets the spots for the current gesture.
121 * The spots are not subject to the inactivity timeout like the pointer
122 * itself it since they are expected to remain visible for so long as
123 * the fingers are on the touch pad.
124 *
125 * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant.
126 * For spotCoords, pressure != 0 indicates that the spot's location is being
127 * pressed (not hovering).
128 */
129 virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
Byoungho Jung6f5b16b2023-10-27 18:22:07 +0900130 BitSet32 spotIdBits, int32_t displayId) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800131
132 /* Removes all spots. */
133 virtual void clearSpots() = 0;
Arthur Hungc7ad2d02018-12-18 17:41:29 +0800134
135 /* Gets the id of the display where the pointer should be shown. */
136 virtual int32_t getDisplayId() const = 0;
Garfield Tan888a6a42020-01-09 11:39:16 -0800137
138 /* Sets the associated display of this pointer. Pointer should show on that display. */
139 virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
Byoungho Jung99326452023-11-03 20:19:17 +0900140
141 /* Sets the pointer icon type for mice or styluses. */
142 virtual void updatePointerIcon(PointerIconStyle iconId) = 0;
143
144 /* Sets the custom pointer icon for mice or styluses. */
145 virtual void setCustomPointerIcon(const SpriteIcon& icon) = 0;
Arpit Singh4b6ad2d2024-04-04 11:54:20 +0000146
147 /* Sets the flag to skip screenshot of the pointer indicators on the display matching the
148 * provided displayId.
149 */
150 virtual void setSkipScreenshot(int32_t displayId, bool skip) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800151};
152
153} // namespace android