blob: e6dfc4c6f99a522c7b3eeabea7cd4da18fb23bfc [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
Liam Harringtonce637132020-08-14 04:00:11 +000028#include <functional>
Liam Harringtonc782be62020-07-17 19:48:24 +000029#include <map>
30#include <memory>
31#include <vector>
32
33#include "PointerControllerContext.h"
34#include "SpriteController.h"
35
36namespace android {
37
38/*
39 * Helper class for PointerController that specifically handles
40 * mouse cursor resources and actions.
41 */
42class MouseCursorController {
43public:
44 MouseCursorController(PointerControllerContext& context);
45 ~MouseCursorController();
46
47 bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const;
48 void move(float deltaX, float deltaY);
49 void setButtonState(int32_t buttonState);
50 int32_t getButtonState() const;
51 void setPosition(float x, float y);
52 void getPosition(float* outX, float* outY) const;
53 int32_t getDisplayId() const;
54 void fade(PointerControllerInterface::Transition transition);
55 void unfade(PointerControllerInterface::Transition transition);
56 void setDisplayViewport(const DisplayViewport& viewport, bool getAdditionalMouseResources);
57
58 void updatePointerIcon(int32_t iconId);
59 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
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
Liam Harringtonce637132020-08-14 04:00:11 +000099 bool animating{false};
100
Liam Harringtonc782be62020-07-17 19:48:24 +0000101 } mLocked GUARDED_BY(mLock);
102
103 bool getBoundsLocked(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const;
104 void setPositionLocked(float x, float y);
105
106 void updatePointerLocked();
107
108 void loadResourcesLocked(bool getAdditionalMouseResources);
Liam Harringtonce637132020-08-14 04:00:11 +0000109
110 bool doBitmapAnimationLocked(nsecs_t timestamp);
111 bool doFadingAnimationLocked(nsecs_t timestamp);
112
113 void startAnimationLocked();
Liam Harringtonc782be62020-07-17 19:48:24 +0000114};
115
116} // namespace android
117
118#endif // _UI_MOUSE_CURSOR_CONTROLLER_H