blob: bd464901b6f927d9787c27c40e89516cb5c5e937 [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
Michael Wrightd02c5b62014-02-10 15:10:22 -080027/**
28 * Interface for tracking a mouse / touch pad pointer and touch pad spots.
29 *
30 * The spots are sprites on screen that visually represent the positions of
31 * fingers
32 *
33 * The pointer controller is responsible for providing synchronization and for tracking
Prabir Pradhande69f8a2021-11-18 16:40:34 +000034 * display orientation changes if needed. It works in the display panel's coordinate space, which
35 * is the same coordinate space used by InputReader.
Michael Wrightd02c5b62014-02-10 15:10:22 -080036 */
Michael Wright17db18e2020-06-26 20:51:44 +010037class PointerControllerInterface {
Michael Wrightd02c5b62014-02-10 15:10:22 -080038protected:
Byoungho Jung6f5b16b2023-10-27 18:22:07 +090039 PointerControllerInterface() {}
40 virtual ~PointerControllerInterface() {}
Michael Wrightd02c5b62014-02-10 15:10:22 -080041
42public:
Byoungho Jungda10dd32023-10-06 17:03:45 +090043 /**
44 * Enum used to differentiate various types of PointerControllers for the transition to
45 * using PointerChoreographer.
46 *
47 * TODO(b/293587049): Refactor the PointerController class into different controller types.
48 */
49 enum class ControllerType {
Byoungho Jungda10dd32023-10-06 17:03:45 +090050 // Represents a single mouse pointer.
51 MOUSE,
Byoungho Jung6f5b16b2023-10-27 18:22:07 +090052 // Represents multiple touch spots.
53 TOUCH,
Byoungho Jungd6fe27b2023-10-27 20:49:38 +090054 // Represents a single stylus pointer.
55 STYLUS,
Byoungho Jungda10dd32023-10-06 17:03:45 +090056 };
57
58 /* Dumps the state of the pointer controller. */
59 virtual std::string dump() = 0;
60
Arpit Singhe33845c2024-10-25 20:59:24 +000061 /* Move the pointer and return unconsumed delta if the pointer has crossed the current
Arpit Singhf0169ab2024-11-18 20:44:35 +000062 * viewport bounds.
Arpit Singhe33845c2024-10-25 20:59:24 +000063 *
64 * Return value may be used to move pointer to corresponding adjacent display, if it exists in
65 * the display-topology */
Arpit Singh7f21fa32024-11-26 15:44:26 +000066 [[nodiscard]] virtual vec2 move(float deltaX, float deltaY) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080067
Michael Wrightd02c5b62014-02-10 15:10:22 -080068 /* Sets the absolute location of the pointer. */
69 virtual void setPosition(float x, float y) = 0;
70
71 /* Gets the absolute location of the pointer. */
Arpit Singh7f21fa32024-11-26 15:44:26 +000072 virtual vec2 getPosition() const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080073
Michael Wrightca5bede2020-07-02 00:00:29 +010074 enum class Transition {
Michael Wrightd02c5b62014-02-10 15:10:22 -080075 // Fade/unfade immediately.
Michael Wrightca5bede2020-07-02 00:00:29 +010076 IMMEDIATE,
Michael Wrightd02c5b62014-02-10 15:10:22 -080077 // Fade/unfade gradually.
Michael Wrightca5bede2020-07-02 00:00:29 +010078 GRADUAL,
Michael Wrightd02c5b62014-02-10 15:10:22 -080079 };
80
81 /* Fades the pointer out now. */
82 virtual void fade(Transition transition) = 0;
83
84 /* Makes the pointer visible if it has faded out.
85 * The pointer never unfades itself automatically. This method must be called
86 * by the client whenever the pointer is moved or a button is pressed and it
87 * wants to ensure that the pointer becomes visible again. */
88 virtual void unfade(Transition transition) = 0;
89
Michael Wrightca5bede2020-07-02 00:00:29 +010090 enum class Presentation {
Michael Wrightd02c5b62014-02-10 15:10:22 -080091 // Show the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +010092 POINTER,
Michael Wrightd02c5b62014-02-10 15:10:22 -080093 // Show spots and a spot anchor in place of the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +010094 SPOT,
Seunghwan Choi75789cd2023-01-13 20:31:59 +090095 // Show the stylus hover pointer.
96 STYLUS_HOVER,
Michael Wright08f7a6a2022-10-22 03:14:39 +010097
Seunghwan Choi75789cd2023-01-13 20:31:59 +090098 ftl_last = STYLUS_HOVER,
Michael Wrightd02c5b62014-02-10 15:10:22 -080099 };
100
101 /* Sets the mode of the pointer controller. */
102 virtual void setPresentation(Presentation presentation) = 0;
103
104 /* Sets the spots for the current gesture.
105 * The spots are not subject to the inactivity timeout like the pointer
106 * itself it since they are expected to remain visible for so long as
107 * the fingers are on the touch pad.
108 *
109 * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant.
110 * For spotCoords, pressure != 0 indicates that the spot's location is being
111 * pressed (not hovering).
112 */
113 virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
Linnan Li13bf76a2024-05-05 19:18:02 +0800114 BitSet32 spotIdBits, ui::LogicalDisplayId displayId) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800115
116 /* Removes all spots. */
117 virtual void clearSpots() = 0;
Arthur Hungc7ad2d02018-12-18 17:41:29 +0800118
119 /* Gets the id of the display where the pointer should be shown. */
Linnan Li13bf76a2024-05-05 19:18:02 +0800120 virtual ui::LogicalDisplayId getDisplayId() const = 0;
Garfield Tan888a6a42020-01-09 11:39:16 -0800121
122 /* Sets the associated display of this pointer. Pointer should show on that display. */
123 virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
Byoungho Jung99326452023-11-03 20:19:17 +0900124
125 /* Sets the pointer icon type for mice or styluses. */
126 virtual void updatePointerIcon(PointerIconStyle iconId) = 0;
127
128 /* Sets the custom pointer icon for mice or styluses. */
129 virtual void setCustomPointerIcon(const SpriteIcon& icon) = 0;
Arpit Singh4b6ad2d2024-04-04 11:54:20 +0000130
Arpit Singh420d0742024-04-04 11:54:20 +0000131 /* Sets the flag to skip screenshot of the pointer indicators on the display for the specified
132 * displayId. This flag can only be reset with resetSkipScreenshotFlags()
Arpit Singh4b6ad2d2024-04-04 11:54:20 +0000133 */
Arpit Singh420d0742024-04-04 11:54:20 +0000134 virtual void setSkipScreenshotFlagForDisplay(ui::LogicalDisplayId displayId) = 0;
135
136 /* Resets the flag to skip screenshot of the pointer indicators for all displays. */
137 virtual void clearSkipScreenshotFlags() = 0;
Arpit Singhf0169ab2024-11-18 20:44:35 +0000138
139 virtual ui::Transform getDisplayTransform() const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800140};
141
142} // namespace android