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 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 27 | /** |
| 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 Pradhan | de69f8a | 2021-11-18 16:40:34 +0000 | [diff] [blame] | 34 | * 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 Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 36 | */ |
Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 37 | class PointerControllerInterface { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 38 | protected: |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 39 | PointerControllerInterface() {} |
| 40 | virtual ~PointerControllerInterface() {} |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 41 | |
| 42 | public: |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 43 | /** |
| 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 Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 50 | // Represents a single mouse pointer. |
| 51 | MOUSE, |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 52 | // Represents multiple touch spots. |
| 53 | TOUCH, |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 54 | // Represents a single stylus pointer. |
| 55 | STYLUS, |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /* Dumps the state of the pointer controller. */ |
| 59 | virtual std::string dump() = 0; |
| 60 | |
Arpit Singh | e33845c | 2024-10-25 20:59:24 +0000 | [diff] [blame] | 61 | /* Move the pointer and return unconsumed delta if the pointer has crossed the current |
Arpit Singh | f0169ab | 2024-11-18 20:44:35 +0000 | [diff] [blame] | 62 | * viewport bounds. |
Arpit Singh | e33845c | 2024-10-25 20:59:24 +0000 | [diff] [blame] | 63 | * |
| 64 | * Return value may be used to move pointer to corresponding adjacent display, if it exists in |
| 65 | * the display-topology */ |
Arpit Singh | 7f21fa3 | 2024-11-26 15:44:26 +0000 | [diff] [blame] | 66 | [[nodiscard]] virtual vec2 move(float deltaX, float deltaY) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 67 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 68 | /* 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 Singh | 7f21fa3 | 2024-11-26 15:44:26 +0000 | [diff] [blame] | 72 | virtual vec2 getPosition() const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 73 | |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 74 | enum class Transition { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 75 | // Fade/unfade immediately. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 76 | IMMEDIATE, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 77 | // Fade/unfade gradually. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 78 | GRADUAL, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 79 | }; |
| 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 Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 90 | enum class Presentation { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 91 | // Show the mouse pointer. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 92 | POINTER, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 93 | // Show spots and a spot anchor in place of the mouse pointer. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 94 | SPOT, |
Seunghwan Choi | 75789cd | 2023-01-13 20:31:59 +0900 | [diff] [blame] | 95 | // Show the stylus hover pointer. |
| 96 | STYLUS_HOVER, |
Michael Wright | 08f7a6a | 2022-10-22 03:14:39 +0100 | [diff] [blame] | 97 | |
Seunghwan Choi | 75789cd | 2023-01-13 20:31:59 +0900 | [diff] [blame] | 98 | ftl_last = STYLUS_HOVER, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 99 | }; |
| 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 Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 114 | BitSet32 spotIdBits, ui::LogicalDisplayId displayId) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 115 | |
| 116 | /* Removes all spots. */ |
| 117 | virtual void clearSpots() = 0; |
Arthur Hung | c7ad2d0 | 2018-12-18 17:41:29 +0800 | [diff] [blame] | 118 | |
| 119 | /* Gets the id of the display where the pointer should be shown. */ |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 120 | virtual ui::LogicalDisplayId getDisplayId() const = 0; |
Garfield Tan | 888a6a4 | 2020-01-09 11:39:16 -0800 | [diff] [blame] | 121 | |
| 122 | /* Sets the associated display of this pointer. Pointer should show on that display. */ |
| 123 | virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0; |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 124 | |
| 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 Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 130 | |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 131 | /* 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 Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 133 | */ |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 134 | 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 Singh | f0169ab | 2024-11-18 20:44:35 +0000 | [diff] [blame] | 138 | |
| 139 | virtual ui::Transform getDisplayTransform() const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | } // namespace android |