blob: 9038056538c2ad60724b33416dbce511d93ccf92 [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
Prabir Pradhan2719e822023-02-28 17:39:36 +000025struct FloatPoint {
26 float x;
27 float y;
28
29 inline FloatPoint(float x, float y) : x(x), y(y) {}
30
31 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
Michael Wrightd02c5b62014-02-10 15:10:22 -080039/**
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
Prabir Pradhande69f8a2021-11-18 16:40:34 +000046 * display orientation changes if needed. It works in the display panel's coordinate space, which
47 * is the same coordinate space used by InputReader.
Michael Wrightd02c5b62014-02-10 15:10:22 -080048 */
Michael Wright17db18e2020-06-26 20:51:44 +010049class PointerControllerInterface {
Michael Wrightd02c5b62014-02-10 15:10:22 -080050protected:
Byoungho Jung6f5b16b2023-10-27 18:22:07 +090051 PointerControllerInterface() {}
52 virtual ~PointerControllerInterface() {}
Michael Wrightd02c5b62014-02-10 15:10:22 -080053
54public:
Byoungho Jungda10dd32023-10-06 17:03:45 +090055 /**
56 * Enum used to differentiate various types of PointerControllers for the transition to
57 * using PointerChoreographer.
58 *
59 * TODO(b/293587049): Refactor the PointerController class into different controller types.
60 */
61 enum class ControllerType {
62 // The PointerController that is responsible for drawing all icons.
63 LEGACY,
64 // Represents a single mouse pointer.
65 MOUSE,
Byoungho Jung6f5b16b2023-10-27 18:22:07 +090066 // Represents multiple touch spots.
67 TOUCH,
Byoungho Jungda10dd32023-10-06 17:03:45 +090068 };
69
70 /* Dumps the state of the pointer controller. */
71 virtual std::string dump() = 0;
72
Michael Wrightd02c5b62014-02-10 15:10:22 -080073 /* Gets the bounds of the region that the pointer can traverse.
74 * Returns true if the bounds are available. */
Prabir Pradhan2719e822023-02-28 17:39:36 +000075 virtual std::optional<FloatRect> getBounds() const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080076
77 /* Move the pointer. */
78 virtual void move(float deltaX, float deltaY) = 0;
79
Michael Wrightd02c5b62014-02-10 15:10:22 -080080 /* Sets the absolute location of the pointer. */
81 virtual void setPosition(float x, float y) = 0;
82
83 /* Gets the absolute location of the pointer. */
Prabir Pradhan2719e822023-02-28 17:39:36 +000084 virtual FloatPoint getPosition() const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080085
Michael Wrightca5bede2020-07-02 00:00:29 +010086 enum class Transition {
Michael Wrightd02c5b62014-02-10 15:10:22 -080087 // Fade/unfade immediately.
Michael Wrightca5bede2020-07-02 00:00:29 +010088 IMMEDIATE,
Michael Wrightd02c5b62014-02-10 15:10:22 -080089 // Fade/unfade gradually.
Michael Wrightca5bede2020-07-02 00:00:29 +010090 GRADUAL,
Michael Wrightd02c5b62014-02-10 15:10:22 -080091 };
92
93 /* Fades the pointer out now. */
94 virtual void fade(Transition transition) = 0;
95
96 /* Makes the pointer visible if it has faded out.
97 * The pointer never unfades itself automatically. This method must be called
98 * by the client whenever the pointer is moved or a button is pressed and it
99 * wants to ensure that the pointer becomes visible again. */
100 virtual void unfade(Transition transition) = 0;
101
Michael Wrightca5bede2020-07-02 00:00:29 +0100102 enum class Presentation {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800103 // Show the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +0100104 POINTER,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800105 // Show spots and a spot anchor in place of the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +0100106 SPOT,
Seunghwan Choi75789cd2023-01-13 20:31:59 +0900107 // Show the stylus hover pointer.
108 STYLUS_HOVER,
Michael Wright08f7a6a2022-10-22 03:14:39 +0100109
Seunghwan Choi75789cd2023-01-13 20:31:59 +0900110 ftl_last = STYLUS_HOVER,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800111 };
112
113 /* Sets the mode of the pointer controller. */
114 virtual void setPresentation(Presentation presentation) = 0;
115
116 /* Sets the spots for the current gesture.
117 * The spots are not subject to the inactivity timeout like the pointer
118 * itself it since they are expected to remain visible for so long as
119 * the fingers are on the touch pad.
120 *
121 * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant.
122 * For spotCoords, pressure != 0 indicates that the spot's location is being
123 * pressed (not hovering).
124 */
125 virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
Byoungho Jung6f5b16b2023-10-27 18:22:07 +0900126 BitSet32 spotIdBits, int32_t displayId) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800127
128 /* Removes all spots. */
129 virtual void clearSpots() = 0;
Arthur Hungc7ad2d02018-12-18 17:41:29 +0800130
131 /* Gets the id of the display where the pointer should be shown. */
132 virtual int32_t getDisplayId() const = 0;
Garfield Tan888a6a42020-01-09 11:39:16 -0800133
134 /* Sets the associated display of this pointer. Pointer should show on that display. */
135 virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800136};
137
138} // namespace android