blob: 12b31a8c531a4094a9dc248135d0c17fd4dddf88 [file] [log] [blame]
Liam Harringtonc782be62020-07-17 19:48:24 +00001/*
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 Harringtonc782be62020-07-17 19:48:24 +000023#include <utils/BitSet.h>
24#include <utils/Looper.h>
25#include <utils/RefBase.h>
26
Liam Harringtonce637132020-08-14 04:00:11 +000027#include <functional>
Liam Harringtonc782be62020-07-17 19:48:24 +000028#include <map>
29#include <memory>
30#include <vector>
31
32#include "PointerControllerContext.h"
33#include "SpriteController.h"
34
35namespace android {
36
37/*
38 * Helper class for PointerController that specifically handles
39 * mouse cursor resources and actions.
40 */
41class MouseCursorController {
42public:
43 MouseCursorController(PointerControllerContext& context);
44 ~MouseCursorController();
45
Liam Harringtonc782be62020-07-17 19:48:24 +000046 void move(float deltaX, float deltaY);
Liam Harringtonc782be62020-07-17 19:48:24 +000047 void setPosition(float x, float y);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +000048 FloatPoint getPosition() const;
Linnan Li0defadf2024-05-05 19:17:05 +080049 ui::LogicalDisplayId getDisplayId() const;
Liam Harringtonc782be62020-07-17 19:48:24 +000050 void fade(PointerControllerInterface::Transition transition);
51 void unfade(PointerControllerInterface::Transition transition);
52 void setDisplayViewport(const DisplayViewport& viewport, bool getAdditionalMouseResources);
Seunghwan Choi670b33d2023-01-13 21:12:59 +090053 void setStylusHoverMode(bool stylusHoverMode);
Liam Harringtonc782be62020-07-17 19:48:24 +000054
Arpit Singhf4ae0ac2024-03-26 18:41:06 +000055 // Set/Unset flag to hide the mouse cursor on the mirrored display
56 void setSkipScreenshot(bool skip);
57
Brandon Pollack015f5d92022-06-02 06:59:33 +000058 void updatePointerIcon(PointerIconStyle iconId);
Liam Harringtonc782be62020-07-17 19:48:24 +000059 void setCustomPointerIcon(const SpriteIcon& icon);
60 void reloadPointerResources(bool getAdditionalMouseResources);
61
62 void getAdditionalMouseResources();
63 bool isViewportValid();
64
Liam Harringtonce637132020-08-14 04:00:11 +000065 bool doAnimations(nsecs_t timestamp);
Liam Harringtonc782be62020-07-17 19:48:24 +000066
67 bool resourcesLoaded();
68
Arpit Singh05215af2024-08-25 17:49:32 +000069 std::string dump() const;
70
Liam Harringtonc782be62020-07-17 19:48:24 +000071private:
72 mutable std::mutex mLock;
73
74 PointerResources mResources;
75
76 PointerControllerContext& mContext;
77
78 struct Locked {
79 DisplayViewport viewport;
Seunghwan Choi670b33d2023-01-13 21:12:59 +090080 bool stylusHoverMode;
Liam Harringtonc782be62020-07-17 19:48:24 +000081
82 size_t animationFrameIndex;
83 nsecs_t lastFrameUpdatedTime;
84
85 int32_t pointerFadeDirection;
86 float pointerX;
87 float pointerY;
88 float pointerAlpha;
89 sp<Sprite> pointerSprite;
90 SpriteIcon pointerIcon;
91 bool updatePointerIcon;
92
93 bool resourcesLoaded;
94
Brandon Pollack015f5d92022-06-02 06:59:33 +000095 std::map<PointerIconStyle, SpriteIcon> additionalMouseResources;
96 std::map<PointerIconStyle, PointerAnimation> animationResources;
Liam Harringtonc782be62020-07-17 19:48:24 +000097
Brandon Pollack015f5d92022-06-02 06:59:33 +000098 PointerIconStyle requestedPointerType;
Seunghwan Choi670b33d2023-01-13 21:12:59 +090099 PointerIconStyle resolvedPointerType;
Liam Harringtonc782be62020-07-17 19:48:24 +0000100
Arpit Singhf4ae0ac2024-03-26 18:41:06 +0000101 bool skipScreenshot{false};
Liam Harringtonce637132020-08-14 04:00:11 +0000102 bool animating{false};
103
Liam Harringtonc782be62020-07-17 19:48:24 +0000104 } mLocked GUARDED_BY(mLock);
105
Liam Harringtonc782be62020-07-17 19:48:24 +0000106 void setPositionLocked(float x, float y);
107
108 void updatePointerLocked();
109
110 void loadResourcesLocked(bool getAdditionalMouseResources);
Liam Harringtonce637132020-08-14 04:00:11 +0000111
112 bool doBitmapAnimationLocked(nsecs_t timestamp);
113 bool doFadingAnimationLocked(nsecs_t timestamp);
114
115 void startAnimationLocked();
Liam Harringtonc782be62020-07-17 19:48:24 +0000116};
117
118} // namespace android
119
120#endif // _UI_MOUSE_CURSOR_CONTROLLER_H