Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | #ifndef _UI_MOUSE_CURSOR_CONTROLLER_H |
| 18 | #define _UI_MOUSE_CURSOR_CONTROLLER_H |
| 19 | |
| 20 | #include <gui/DisplayEventReceiver.h> |
| 21 | #include <input/DisplayViewport.h> |
| 22 | #include <input/Input.h> |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 23 | #include <utils/BitSet.h> |
| 24 | #include <utils/Looper.h> |
| 25 | #include <utils/RefBase.h> |
| 26 | |
Liam Harrington | ce63713 | 2020-08-14 04:00:11 +0000 | [diff] [blame] | 27 | #include <functional> |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 28 | #include <map> |
| 29 | #include <memory> |
| 30 | #include <vector> |
| 31 | |
| 32 | #include "PointerControllerContext.h" |
| 33 | #include "SpriteController.h" |
| 34 | |
| 35 | namespace android { |
| 36 | |
| 37 | /* |
| 38 | * Helper class for PointerController that specifically handles |
| 39 | * mouse cursor resources and actions. |
| 40 | */ |
| 41 | class MouseCursorController { |
| 42 | public: |
| 43 | MouseCursorController(PointerControllerContext& context); |
| 44 | ~MouseCursorController(); |
| 45 | |
Prabir Pradhan | b5dadec | 2023-02-28 17:43:09 +0000 | [diff] [blame] | 46 | std::optional<FloatRect> getBounds() const; |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 47 | void move(float deltaX, float deltaY); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 48 | void setPosition(float x, float y); |
Prabir Pradhan | b5dadec | 2023-02-28 17:43:09 +0000 | [diff] [blame] | 49 | FloatPoint getPosition() const; |
Linnan Li | 0defadf | 2024-05-05 19:17:05 +0800 | [diff] [blame] | 50 | ui::LogicalDisplayId getDisplayId() const; |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 51 | void fade(PointerControllerInterface::Transition transition); |
| 52 | void unfade(PointerControllerInterface::Transition transition); |
| 53 | void setDisplayViewport(const DisplayViewport& viewport, bool getAdditionalMouseResources); |
Seunghwan Choi | 670b33d | 2023-01-13 21:12:59 +0900 | [diff] [blame] | 54 | void setStylusHoverMode(bool stylusHoverMode); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 55 | |
Arpit Singh | f4ae0ac | 2024-03-26 18:41:06 +0000 | [diff] [blame] | 56 | // Set/Unset flag to hide the mouse cursor on the mirrored display |
| 57 | void setSkipScreenshot(bool skip); |
| 58 | |
Brandon Pollack | 015f5d9 | 2022-06-02 06:59:33 +0000 | [diff] [blame] | 59 | void updatePointerIcon(PointerIconStyle iconId); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 60 | void setCustomPointerIcon(const SpriteIcon& icon); |
| 61 | void reloadPointerResources(bool getAdditionalMouseResources); |
| 62 | |
| 63 | void getAdditionalMouseResources(); |
| 64 | bool isViewportValid(); |
| 65 | |
Liam Harrington | ce63713 | 2020-08-14 04:00:11 +0000 | [diff] [blame] | 66 | bool doAnimations(nsecs_t timestamp); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 67 | |
| 68 | bool resourcesLoaded(); |
| 69 | |
Arpit Singh | 05215af | 2024-08-25 17:49:32 +0000 | [diff] [blame^] | 70 | std::string dump() const; |
| 71 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 72 | private: |
| 73 | mutable std::mutex mLock; |
| 74 | |
| 75 | PointerResources mResources; |
| 76 | |
| 77 | PointerControllerContext& mContext; |
| 78 | |
| 79 | struct Locked { |
| 80 | DisplayViewport viewport; |
Seunghwan Choi | 670b33d | 2023-01-13 21:12:59 +0900 | [diff] [blame] | 81 | bool stylusHoverMode; |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 82 | |
| 83 | size_t animationFrameIndex; |
| 84 | nsecs_t lastFrameUpdatedTime; |
| 85 | |
| 86 | int32_t pointerFadeDirection; |
| 87 | float pointerX; |
| 88 | float pointerY; |
| 89 | float pointerAlpha; |
| 90 | sp<Sprite> pointerSprite; |
| 91 | SpriteIcon pointerIcon; |
| 92 | bool updatePointerIcon; |
| 93 | |
| 94 | bool resourcesLoaded; |
| 95 | |
Brandon Pollack | 015f5d9 | 2022-06-02 06:59:33 +0000 | [diff] [blame] | 96 | std::map<PointerIconStyle, SpriteIcon> additionalMouseResources; |
| 97 | std::map<PointerIconStyle, PointerAnimation> animationResources; |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 98 | |
Brandon Pollack | 015f5d9 | 2022-06-02 06:59:33 +0000 | [diff] [blame] | 99 | PointerIconStyle requestedPointerType; |
Seunghwan Choi | 670b33d | 2023-01-13 21:12:59 +0900 | [diff] [blame] | 100 | PointerIconStyle resolvedPointerType; |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 101 | |
Arpit Singh | f4ae0ac | 2024-03-26 18:41:06 +0000 | [diff] [blame] | 102 | bool skipScreenshot{false}; |
Liam Harrington | ce63713 | 2020-08-14 04:00:11 +0000 | [diff] [blame] | 103 | bool animating{false}; |
| 104 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 105 | } mLocked GUARDED_BY(mLock); |
| 106 | |
Prabir Pradhan | b5dadec | 2023-02-28 17:43:09 +0000 | [diff] [blame] | 107 | std::optional<FloatRect> getBoundsLocked() const; |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 108 | void setPositionLocked(float x, float y); |
| 109 | |
| 110 | void updatePointerLocked(); |
| 111 | |
| 112 | void loadResourcesLocked(bool getAdditionalMouseResources); |
Liam Harrington | ce63713 | 2020-08-14 04:00:11 +0000 | [diff] [blame] | 113 | |
| 114 | bool doBitmapAnimationLocked(nsecs_t timestamp); |
| 115 | bool doFadingAnimationLocked(nsecs_t timestamp); |
| 116 | |
| 117 | void startAnimationLocked(); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | } // namespace android |
| 121 | |
| 122 | #endif // _UI_MOUSE_CURSOR_CONTROLLER_H |