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 | |
| 25 | /** |
| 26 | * Interface for tracking a mouse / touch pad pointer and touch pad spots. |
| 27 | * |
| 28 | * The spots are sprites on screen that visually represent the positions of |
| 29 | * fingers |
| 30 | * |
| 31 | * The pointer controller is responsible for providing synchronization and for tracking |
Prabir Pradhan | de69f8a | 2021-11-18 16:40:34 +0000 | [diff] [blame] | 32 | * display orientation changes if needed. It works in the display panel's coordinate space, which |
| 33 | * is the same coordinate space used by InputReader. |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 34 | */ |
Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 35 | class PointerControllerInterface { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 36 | protected: |
| 37 | PointerControllerInterface() { } |
| 38 | virtual ~PointerControllerInterface() { } |
| 39 | |
| 40 | public: |
| 41 | /* Gets the bounds of the region that the pointer can traverse. |
| 42 | * Returns true if the bounds are available. */ |
| 43 | virtual bool getBounds(float* outMinX, float* outMinY, |
| 44 | float* outMaxX, float* outMaxY) const = 0; |
| 45 | |
| 46 | /* Move the pointer. */ |
| 47 | virtual void move(float deltaX, float deltaY) = 0; |
| 48 | |
| 49 | /* Sets a mask that indicates which buttons are pressed. */ |
| 50 | virtual void setButtonState(int32_t buttonState) = 0; |
| 51 | |
| 52 | /* Gets a mask that indicates which buttons are pressed. */ |
| 53 | virtual int32_t getButtonState() const = 0; |
| 54 | |
| 55 | /* Sets the absolute location of the pointer. */ |
| 56 | virtual void setPosition(float x, float y) = 0; |
| 57 | |
| 58 | /* Gets the absolute location of the pointer. */ |
| 59 | virtual void getPosition(float* outX, float* outY) const = 0; |
| 60 | |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 61 | enum class Transition { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 62 | // Fade/unfade immediately. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 63 | IMMEDIATE, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 64 | // Fade/unfade gradually. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 65 | GRADUAL, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | /* Fades the pointer out now. */ |
| 69 | virtual void fade(Transition transition) = 0; |
| 70 | |
| 71 | /* Makes the pointer visible if it has faded out. |
| 72 | * The pointer never unfades itself automatically. This method must be called |
| 73 | * by the client whenever the pointer is moved or a button is pressed and it |
| 74 | * wants to ensure that the pointer becomes visible again. */ |
| 75 | virtual void unfade(Transition transition) = 0; |
| 76 | |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 77 | enum class Presentation { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 78 | // Show the mouse pointer. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 79 | POINTER, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 80 | // Show spots and a spot anchor in place of the mouse pointer. |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 81 | SPOT, |
Michael Wright | 08f7a6a | 2022-10-22 03:14:39 +0100 | [diff] [blame^] | 82 | |
| 83 | ftl_last = SPOT, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | /* Sets the mode of the pointer controller. */ |
| 87 | virtual void setPresentation(Presentation presentation) = 0; |
| 88 | |
| 89 | /* Sets the spots for the current gesture. |
| 90 | * The spots are not subject to the inactivity timeout like the pointer |
| 91 | * itself it since they are expected to remain visible for so long as |
| 92 | * the fingers are on the touch pad. |
| 93 | * |
| 94 | * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant. |
| 95 | * For spotCoords, pressure != 0 indicates that the spot's location is being |
| 96 | * pressed (not hovering). |
| 97 | */ |
| 98 | virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, |
Arthur Hung | 7c64540 | 2019-01-25 17:45:42 +0800 | [diff] [blame] | 99 | BitSet32 spotIdBits, int32_t displayId) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 100 | |
| 101 | /* Removes all spots. */ |
| 102 | virtual void clearSpots() = 0; |
Arthur Hung | c7ad2d0 | 2018-12-18 17:41:29 +0800 | [diff] [blame] | 103 | |
| 104 | /* Gets the id of the display where the pointer should be shown. */ |
| 105 | virtual int32_t getDisplayId() const = 0; |
Garfield Tan | 888a6a4 | 2020-01-09 11:39:16 -0800 | [diff] [blame] | 106 | |
| 107 | /* Sets the associated display of this pointer. Pointer should show on that display. */ |
| 108 | virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | } // namespace android |