blob: ac37fa4302495918a2885dd50cac73f2a1ab6fe7 [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_TOUCH_SPOT_CONTROLLER_H
18#define _UI_TOUCH_SPOT_CONTROLLER_H
19
Liam Harringtonce637132020-08-14 04:00:11 +000020#include <functional>
21
Liam Harringtonc782be62020-07-17 19:48:24 +000022#include "PointerControllerContext.h"
23
24namespace android {
25
26/*
27 * Helper class for PointerController that specifically handles
28 * touch spot resources and actions for a single display.
29 */
30class TouchSpotController {
31public:
Linnan Li0defadf2024-05-05 19:17:05 +080032 TouchSpotController(ui::LogicalDisplayId displayId, PointerControllerContext& context);
Liam Harringtonc782be62020-07-17 19:48:24 +000033 ~TouchSpotController();
34 void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
Arpit Singh80fd68a2024-03-26 18:41:06 +000035 BitSet32 spotIdBits, bool skipScreenshot);
Liam Harringtonc782be62020-07-17 19:48:24 +000036 void clearSpots();
37
38 void reloadSpotResources();
Liam Harringtonce637132020-08-14 04:00:11 +000039 bool doAnimations(nsecs_t timestamp);
Liam Harringtonc782be62020-07-17 19:48:24 +000040
Michael Wright20f5fd82022-10-28 14:12:24 +010041 void dump(std::string& out, const char* prefix = "") const;
42
Liam Harringtonc782be62020-07-17 19:48:24 +000043private:
44 struct Spot {
45 static const uint32_t INVALID_ID = 0xffffffff;
46
47 uint32_t id;
48 sp<Sprite> sprite;
49 float alpha;
50 float scale;
51 float x, y;
52
53 inline Spot(uint32_t id, const sp<Sprite>& sprite)
54 : id(id),
55 sprite(sprite),
56 alpha(1.0f),
57 scale(1.0f),
58 x(0.0f),
59 y(0.0f),
60 mLastIcon(nullptr) {}
61
Linnan Li0defadf2024-05-05 19:17:05 +080062 void updateSprite(const SpriteIcon* icon, float x, float y, ui::LogicalDisplayId displayId,
Arpit Singh80fd68a2024-03-26 18:41:06 +000063 bool skipScreenshot);
Michael Wright20f5fd82022-10-28 14:12:24 +010064 void dump(std::string& out, const char* prefix = "") const;
Liam Harringtonc782be62020-07-17 19:48:24 +000065
66 private:
67 const SpriteIcon* mLastIcon;
68 };
69
Linnan Li0defadf2024-05-05 19:17:05 +080070 ui::LogicalDisplayId mDisplayId;
Liam Harringtonc782be62020-07-17 19:48:24 +000071
72 mutable std::mutex mLock;
73
74 PointerResources mResources;
75
76 PointerControllerContext& mContext;
77
78 static constexpr size_t MAX_RECYCLED_SPRITES = 12;
79 static constexpr size_t MAX_SPOTS = 12;
80
81 struct Locked {
82 std::vector<Spot*> displaySpots;
83 std::vector<sp<Sprite>> recycledSprites;
84
Liam Harringtonce637132020-08-14 04:00:11 +000085 bool animating{false};
86
Liam Harringtonc782be62020-07-17 19:48:24 +000087 } mLocked GUARDED_BY(mLock);
88
89 Spot* getSpot(uint32_t id, const std::vector<Spot*>& spots);
90 Spot* createAndAddSpotLocked(uint32_t id, std::vector<Spot*>& spots);
91 Spot* removeFirstFadingSpotLocked(std::vector<Spot*>& spots);
92 void releaseSpotLocked(Spot* spot);
93 void fadeOutAndReleaseSpotLocked(Spot* spot);
94 void fadeOutAndReleaseAllSpotsLocked();
Liam Harringtonce637132020-08-14 04:00:11 +000095 bool doFadingAnimationLocked(nsecs_t timestamp);
96 void startAnimationLocked();
Liam Harringtonc782be62020-07-17 19:48:24 +000097};
98
99} // namespace android
100
101#endif // _UI_TOUCH_SPOT_CONTROLLER_H