blob: 8837b2537823fd65aae6baefd603131e98c73279 [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:
51 PointerControllerInterface() { }
52 virtual ~PointerControllerInterface() { }
53
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,
66 };
67
68 /* Dumps the state of the pointer controller. */
69 virtual std::string dump() = 0;
70
Michael Wrightd02c5b62014-02-10 15:10:22 -080071 /* Gets the bounds of the region that the pointer can traverse.
72 * Returns true if the bounds are available. */
Prabir Pradhan2719e822023-02-28 17:39:36 +000073 virtual std::optional<FloatRect> getBounds() const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080074
75 /* Move the pointer. */
76 virtual void move(float deltaX, float deltaY) = 0;
77
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,
Arthur Hung7c645402019-01-25 17:45:42 +0800124 BitSet32 spotIdBits, int32_t 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. */
130 virtual int32_t 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;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800134};
135
136} // namespace android