Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1 | /* |
| 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 Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 18 | |
Garfield Tan | 888a6a4 | 2020-01-09 11:39:16 -0800 | [diff] [blame] | 19 | #include <input/DisplayViewport.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 20 | #include <input/Input.h> |
| 21 | #include <utils/BitSet.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 25 | struct SpriteIcon; |
| 26 | |
Prabir Pradhan | 2719e82 | 2023-02-28 17:39:36 +0000 | [diff] [blame] | 27 | struct 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 Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 41 | /** |
| 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 Pradhan | de69f8a | 2021-11-18 16:40:34 +0000 | [diff] [blame] | 48 | * 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 Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 50 | */ |
Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 51 | class PointerControllerInterface { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 52 | protected: |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 53 | PointerControllerInterface() {} |
| 54 | virtual ~PointerControllerInterface() {} |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 55 | |
| 56 | public: |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 57 | /** |
| 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 Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 64 | // Represents a single mouse pointer. |
| 65 | MOUSE, |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 66 | // Represents multiple touch spots. |
| 67 | TOUCH, |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 68 | // Represents a single stylus pointer. |
| 69 | STYLUS, |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* Dumps the state of the pointer controller. */ |
| 73 | virtual std::string dump() = 0; |
| 74 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 75 | /* Gets the bounds of the region that the pointer can traverse. |
| 76 | * Returns true if the bounds are available. */ |
Prabir Pradhan | 2719e82 | 2023-02-28 17:39:36 +0000 | [diff] [blame] | 77 | virtual std::optional<FloatRect> getBounds() const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 78 | |
| 79 | /* Move the pointer. */ |
| 80 | virtual void move(float deltaX, float deltaY) = 0; |
| 81 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 82 | /* Sets the absolute location of the pointer. */ |
| 83 | virtual void setPosition(float x, float y) = 0; |
| 84 | |
| 85 | /* Gets the absolute location of the pointer. */ |
Prabir Pradhan | 2719e82 | 2023-02-28 17:39:36 +0000 | [diff] [blame] | 86 | virtual FloatPoint getPosition() const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 87 | |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 88 | enum class Transition { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 89 | // Fade/unfade immediately. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 90 | IMMEDIATE, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 91 | // Fade/unfade gradually. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 92 | GRADUAL, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /* Fades the pointer out now. */ |
| 96 | virtual void fade(Transition transition) = 0; |
| 97 | |
| 98 | /* Makes the pointer visible if it has faded out. |
| 99 | * The pointer never unfades itself automatically. This method must be called |
| 100 | * by the client whenever the pointer is moved or a button is pressed and it |
| 101 | * wants to ensure that the pointer becomes visible again. */ |
| 102 | virtual void unfade(Transition transition) = 0; |
| 103 | |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 104 | enum class Presentation { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 105 | // Show the mouse pointer. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 106 | POINTER, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 107 | // Show spots and a spot anchor in place of the mouse pointer. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 108 | SPOT, |
Seunghwan Choi | 75789cd | 2023-01-13 20:31:59 +0900 | [diff] [blame] | 109 | // Show the stylus hover pointer. |
| 110 | STYLUS_HOVER, |
Michael Wright | 08f7a6a | 2022-10-22 03:14:39 +0100 | [diff] [blame] | 111 | |
Seunghwan Choi | 75789cd | 2023-01-13 20:31:59 +0900 | [diff] [blame] | 112 | ftl_last = STYLUS_HOVER, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | /* Sets the mode of the pointer controller. */ |
| 116 | virtual void setPresentation(Presentation presentation) = 0; |
| 117 | |
| 118 | /* Sets the spots for the current gesture. |
| 119 | * The spots are not subject to the inactivity timeout like the pointer |
| 120 | * itself it since they are expected to remain visible for so long as |
| 121 | * the fingers are on the touch pad. |
| 122 | * |
| 123 | * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant. |
| 124 | * For spotCoords, pressure != 0 indicates that the spot's location is being |
| 125 | * pressed (not hovering). |
| 126 | */ |
| 127 | virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 128 | BitSet32 spotIdBits, ui::LogicalDisplayId displayId) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 129 | |
| 130 | /* Removes all spots. */ |
| 131 | virtual void clearSpots() = 0; |
Arthur Hung | c7ad2d0 | 2018-12-18 17:41:29 +0800 | [diff] [blame] | 132 | |
| 133 | /* Gets the id of the display where the pointer should be shown. */ |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 134 | virtual ui::LogicalDisplayId getDisplayId() const = 0; |
Garfield Tan | 888a6a4 | 2020-01-09 11:39:16 -0800 | [diff] [blame] | 135 | |
| 136 | /* Sets the associated display of this pointer. Pointer should show on that display. */ |
| 137 | virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0; |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 138 | |
| 139 | /* Sets the pointer icon type for mice or styluses. */ |
| 140 | virtual void updatePointerIcon(PointerIconStyle iconId) = 0; |
| 141 | |
| 142 | /* Sets the custom pointer icon for mice or styluses. */ |
| 143 | virtual void setCustomPointerIcon(const SpriteIcon& icon) = 0; |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 144 | |
| 145 | /* Sets the flag to skip screenshot of the pointer indicators on the display matching the |
| 146 | * provided displayId. |
| 147 | */ |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 148 | virtual void setSkipScreenshot(ui::LogicalDisplayId displayId, bool skip) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | } // namespace android |