blob: e14a55d938e6d15454f1b6d1d6572ba5a9945777 [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
Liam Harringtonce637132020-08-14 04:00:11 +000024#include <functional>
Liam Harringtonc782be62020-07-17 19:48:24 +000025#include <map>
26#include <memory>
27#include <vector>
28
29#include "PointerControllerContext.h"
30#include "SpriteController.h"
31
32namespace android {
33
34/*
35 * Helper class for PointerController that specifically handles
36 * mouse cursor resources and actions.
37 */
38class MouseCursorController {
39public:
40 MouseCursorController(PointerControllerContext& context);
41 ~MouseCursorController();
42
Arpit Singh64a70882024-10-25 21:08:08 +000043 // Move the pointer and return unconsumed delta
44 FloatPoint move(float deltaX, float deltaY);
Liam Harringtonc782be62020-07-17 19:48:24 +000045 void setPosition(float x, float y);
Prabir Pradhanb5dadec2023-02-28 17:43:09 +000046 FloatPoint getPosition() const;
Linnan Li0defadf2024-05-05 19:17:05 +080047 ui::LogicalDisplayId getDisplayId() const;
Liam Harringtonc782be62020-07-17 19:48:24 +000048 void fade(PointerControllerInterface::Transition transition);
49 void unfade(PointerControllerInterface::Transition transition);
50 void setDisplayViewport(const DisplayViewport& viewport, bool getAdditionalMouseResources);
Seunghwan Choi670b33d2023-01-13 21:12:59 +090051 void setStylusHoverMode(bool stylusHoverMode);
Liam Harringtonc782be62020-07-17 19:48:24 +000052
Arpit Singhf4ae0ac2024-03-26 18:41:06 +000053 // Set/Unset flag to hide the mouse cursor on the mirrored display
54 void setSkipScreenshot(bool skip);
55
Brandon Pollack015f5d92022-06-02 06:59:33 +000056 void updatePointerIcon(PointerIconStyle iconId);
Liam Harringtonc782be62020-07-17 19:48:24 +000057 void setCustomPointerIcon(const SpriteIcon& icon);
58 void reloadPointerResources(bool getAdditionalMouseResources);
59
60 void getAdditionalMouseResources();
61 bool isViewportValid();
62
Liam Harringtonce637132020-08-14 04:00:11 +000063 bool doAnimations(nsecs_t timestamp);
Liam Harringtonc782be62020-07-17 19:48:24 +000064
65 bool resourcesLoaded();
66
Arpit Singh05215af2024-08-25 17:49:32 +000067 std::string dump() const;
68
Liam Harringtonc782be62020-07-17 19:48:24 +000069private:
70 mutable std::mutex mLock;
71
72 PointerResources mResources;
73
74 PointerControllerContext& mContext;
75
76 struct Locked {
77 DisplayViewport viewport;
Seunghwan Choi670b33d2023-01-13 21:12:59 +090078 bool stylusHoverMode;
Liam Harringtonc782be62020-07-17 19:48:24 +000079
80 size_t animationFrameIndex;
81 nsecs_t lastFrameUpdatedTime;
82
83 int32_t pointerFadeDirection;
84 float pointerX;
85 float pointerY;
86 float pointerAlpha;
87 sp<Sprite> pointerSprite;
88 SpriteIcon pointerIcon;
89 bool updatePointerIcon;
90
91 bool resourcesLoaded;
92
Brandon Pollack015f5d92022-06-02 06:59:33 +000093 std::map<PointerIconStyle, SpriteIcon> additionalMouseResources;
94 std::map<PointerIconStyle, PointerAnimation> animationResources;
Liam Harringtonc782be62020-07-17 19:48:24 +000095
Brandon Pollack015f5d92022-06-02 06:59:33 +000096 PointerIconStyle requestedPointerType;
Seunghwan Choi670b33d2023-01-13 21:12:59 +090097 PointerIconStyle resolvedPointerType;
Liam Harringtonc782be62020-07-17 19:48:24 +000098
Arpit Singhf4ae0ac2024-03-26 18:41:06 +000099 bool skipScreenshot{false};
Liam Harringtonce637132020-08-14 04:00:11 +0000100 bool animating{false};
101
Liam Harringtonc782be62020-07-17 19:48:24 +0000102 } mLocked GUARDED_BY(mLock);
103
Liam Harringtonc782be62020-07-17 19:48:24 +0000104 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();
Arpit Singh64a70882024-10-25 21:08:08 +0000114 FloatRect getBoundsLocked();
Liam Harringtonc782be62020-07-17 19:48:24 +0000115};
116
117} // namespace android
118
119#endif // _UI_MOUSE_CURSOR_CONTROLLER_H