blob: 448165b5ac46e29ffcc7f03159dae9bf56c6e5e7 [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>
23#include <ui/DisplayInfo.h>
24#include <utils/BitSet.h>
25#include <utils/Looper.h>
26#include <utils/RefBase.h>
27
28#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
46 bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const;
47 void move(float deltaX, float deltaY);
48 void setButtonState(int32_t buttonState);
49 int32_t getButtonState() const;
50 void setPosition(float x, float y);
51 void getPosition(float* outX, float* outY) const;
52 int32_t getDisplayId() const;
53 void fade(PointerControllerInterface::Transition transition);
54 void unfade(PointerControllerInterface::Transition transition);
55 void setDisplayViewport(const DisplayViewport& viewport, bool getAdditionalMouseResources);
56
57 void updatePointerIcon(int32_t iconId);
58 void setCustomPointerIcon(const SpriteIcon& icon);
59 void reloadPointerResources(bool getAdditionalMouseResources);
60
61 void getAdditionalMouseResources();
62 bool isViewportValid();
63
64 bool doBitmapAnimation(nsecs_t timestamp);
65 bool doFadingAnimation(nsecs_t timestamp, bool keepAnimating);
66
67 bool resourcesLoaded();
68
69private:
70 mutable std::mutex mLock;
71
72 PointerResources mResources;
73
74 PointerControllerContext& mContext;
75
76 struct Locked {
77 DisplayViewport viewport;
78
79 size_t animationFrameIndex;
80 nsecs_t lastFrameUpdatedTime;
81
82 int32_t pointerFadeDirection;
83 float pointerX;
84 float pointerY;
85 float pointerAlpha;
86 sp<Sprite> pointerSprite;
87 SpriteIcon pointerIcon;
88 bool updatePointerIcon;
89
90 bool resourcesLoaded;
91
92 std::map<int32_t, SpriteIcon> additionalMouseResources;
93 std::map<int32_t, PointerAnimation> animationResources;
94
95 int32_t requestedPointerType;
96
97 int32_t buttonState;
98
99 } mLocked GUARDED_BY(mLock);
100
101 bool getBoundsLocked(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const;
102 void setPositionLocked(float x, float y);
103
104 void updatePointerLocked();
105
106 void loadResourcesLocked(bool getAdditionalMouseResources);
107};
108
109} // namespace android
110
111#endif // _UI_MOUSE_CURSOR_CONTROLLER_H