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 17 #pragma once 18 19 #include <input/DisplayViewport.h> 20 #include <input/Input.h> 21 #include <utils/BitSet.h> 22 23 namespace android { 24 25 struct SpriteIcon; 26 27 struct FloatPoint { 28 float x; 29 float y; 30 FloatPointFloatPoint31 inline FloatPoint(float x, float y) : x(x), y(y) {} 32 FloatPointFloatPoint33 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 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 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. 50 */ 51 class PointerControllerInterface { 52 protected: PointerControllerInterface()53 PointerControllerInterface() {} ~PointerControllerInterface()54 virtual ~PointerControllerInterface() {} 55 56 public: 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 { 64 // Represents a single mouse pointer. 65 MOUSE, 66 // Represents multiple touch spots. 67 TOUCH, 68 // Represents a single stylus pointer. 69 STYLUS, 70 }; 71 72 /* Dumps the state of the pointer controller. */ 73 virtual std::string dump() = 0; 74 75 /* Gets the bounds of the region that the pointer can traverse. 76 * Returns true if the bounds are available. */ 77 virtual std::optional<FloatRect> getBounds() const = 0; 78 79 /* Move the pointer. */ 80 virtual void move(float deltaX, float deltaY) = 0; 81 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. */ 86 virtual FloatPoint getPosition() const = 0; 87 88 enum class Transition { 89 // Fade/unfade immediately. 90 IMMEDIATE, 91 // Fade/unfade gradually. 92 GRADUAL, 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 104 enum class Presentation { 105 // Show the mouse pointer. 106 POINTER, 107 // Show spots and a spot anchor in place of the mouse pointer. 108 SPOT, 109 // Show the stylus hover pointer. 110 STYLUS_HOVER, 111 112 ftl_last = STYLUS_HOVER, 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, 128 BitSet32 spotIdBits, ui::LogicalDisplayId displayId) = 0; 129 130 /* Removes all spots. */ 131 virtual void clearSpots() = 0; 132 133 /* Gets the id of the display where the pointer should be shown. */ 134 virtual ui::LogicalDisplayId getDisplayId() const = 0; 135 136 /* Sets the associated display of this pointer. Pointer should show on that display. */ 137 virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0; 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; 144 145 /* Sets the flag to skip screenshot of the pointer indicators on the display for the specified 146 * displayId. This flag can only be reset with resetSkipScreenshotFlags() 147 */ 148 virtual void setSkipScreenshotFlagForDisplay(ui::LogicalDisplayId displayId) = 0; 149 150 /* Resets the flag to skip screenshot of the pointer indicators for all displays. */ 151 virtual void clearSkipScreenshotFlags() = 0; 152 }; 153 154 } // namespace android 155