blob: 8f3d9ca778a7a950657394adb470a29f87342cf4 [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
Liana Kazanova (xWF)ff80e302024-11-18 19:14:42 +000075 /* Move the pointer. */
76 virtual void move(float deltaX, float deltaY) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080077
Michael Wrightd02c5b62014-02-10 15:10:22 -080078 /* Sets the absolute location of the pointer. */
79 virtual void setPosition(float x, float y) = 0;
80
81 /* Gets the absolute location of the pointer. */
Prabir Pradhan2719e822023-02-28 17:39:36 +000082 virtual FloatPoint getPosition() const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080083
Michael Wrightca5bede2020-07-02 00:00:29 +010084 enum class Transition {
Michael Wrightd02c5b62014-02-10 15:10:22 -080085 // Fade/unfade immediately.
Michael Wrightca5bede2020-07-02 00:00:29 +010086 IMMEDIATE,
Michael Wrightd02c5b62014-02-10 15:10:22 -080087 // Fade/unfade gradually.
Michael Wrightca5bede2020-07-02 00:00:29 +010088 GRADUAL,
Michael Wrightd02c5b62014-02-10 15:10:22 -080089 };
90
91 /* Fades the pointer out now. */
92 virtual void fade(Transition transition) = 0;
93
94 /* Makes the pointer visible if it has faded out.
95 * The pointer never unfades itself automatically. This method must be called
96 * by the client whenever the pointer is moved or a button is pressed and it
97 * wants to ensure that the pointer becomes visible again. */
98 virtual void unfade(Transition transition) = 0;
99
Michael Wrightca5bede2020-07-02 00:00:29 +0100100 enum class Presentation {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800101 // Show the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +0100102 POINTER,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800103 // Show spots and a spot anchor in place of the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +0100104 SPOT,
Seunghwan Choi75789cd2023-01-13 20:31:59 +0900105 // Show the stylus hover pointer.
106 STYLUS_HOVER,
Michael Wright08f7a6a2022-10-22 03:14:39 +0100107
Seunghwan Choi75789cd2023-01-13 20:31:59 +0900108 ftl_last = STYLUS_HOVER,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800109 };
110
111 /* Sets the mode of the pointer controller. */
112 virtual void setPresentation(Presentation presentation) = 0;
113
114 /* Sets the spots for the current gesture.
115 * The spots are not subject to the inactivity timeout like the pointer
116 * itself it since they are expected to remain visible for so long as
117 * the fingers are on the touch pad.
118 *
119 * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant.
120 * For spotCoords, pressure != 0 indicates that the spot's location is being
121 * pressed (not hovering).
122 */
123 virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
Linnan Li13bf76a2024-05-05 19:18:02 +0800124 BitSet32 spotIdBits, ui::LogicalDisplayId displayId) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800125
126 /* Removes all spots. */
127 virtual void clearSpots() = 0;
Arthur Hungc7ad2d02018-12-18 17:41:29 +0800128
129 /* Gets the id of the display where the pointer should be shown. */
Linnan Li13bf76a2024-05-05 19:18:02 +0800130 virtual ui::LogicalDisplayId getDisplayId() const = 0;
Garfield Tan888a6a42020-01-09 11:39:16 -0800131
132 /* Sets the associated display of this pointer. Pointer should show on that display. */
133 virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
Byoungho Jung99326452023-11-03 20:19:17 +0900134
135 /* Sets the pointer icon type for mice or styluses. */
136 virtual void updatePointerIcon(PointerIconStyle iconId) = 0;
137
138 /* Sets the custom pointer icon for mice or styluses. */
139 virtual void setCustomPointerIcon(const SpriteIcon& icon) = 0;
Arpit Singh4b6ad2d2024-04-04 11:54:20 +0000140
Arpit Singh420d0742024-04-04 11:54:20 +0000141 /* Sets the flag to skip screenshot of the pointer indicators on the display for the specified
142 * displayId. This flag can only be reset with resetSkipScreenshotFlags()
Arpit Singh4b6ad2d2024-04-04 11:54:20 +0000143 */
Arpit Singh420d0742024-04-04 11:54:20 +0000144 virtual void setSkipScreenshotFlagForDisplay(ui::LogicalDisplayId displayId) = 0;
145
146 /* Resets the flag to skip screenshot of the pointer indicators for all displays. */
147 virtual void clearSkipScreenshotFlags() = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800148};
149
150} // namespace android