blob: 5bbc75d9570bf7e755b1a9e6b28b079ca6bd31b2 [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:
32 TouchSpotController(int32_t displayId, PointerControllerContext& context);
33 ~TouchSpotController();
34 void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
35 BitSet32 spotIdBits);
36 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
62 void updateSprite(const SpriteIcon* icon, float x, float y, int32_t displayId);
Michael Wright20f5fd82022-10-28 14:12:24 +010063 void dump(std::string& out, const char* prefix = "") const;
Liam Harringtonc782be62020-07-17 19:48:24 +000064
65 private:
66 const SpriteIcon* mLastIcon;
67 };
68
69 int32_t mDisplayId;
70
71 mutable std::mutex mLock;
72
73 PointerResources mResources;
74
75 PointerControllerContext& mContext;
76
77 static constexpr size_t MAX_RECYCLED_SPRITES = 12;
78 static constexpr size_t MAX_SPOTS = 12;
79
80 struct Locked {
81 std::vector<Spot*> displaySpots;
82 std::vector<sp<Sprite>> recycledSprites;
83
Liam Harringtonce637132020-08-14 04:00:11 +000084 bool animating{false};
85
Liam Harringtonc782be62020-07-17 19:48:24 +000086 } mLocked GUARDED_BY(mLock);
87
88 Spot* getSpot(uint32_t id, const std::vector<Spot*>& spots);
89 Spot* createAndAddSpotLocked(uint32_t id, std::vector<Spot*>& spots);
90 Spot* removeFirstFadingSpotLocked(std::vector<Spot*>& spots);
91 void releaseSpotLocked(Spot* spot);
92 void fadeOutAndReleaseSpotLocked(Spot* spot);
93 void fadeOutAndReleaseAllSpotsLocked();
Liam Harringtonce637132020-08-14 04:00:11 +000094 bool doFadingAnimationLocked(nsecs_t timestamp);
95 void startAnimationLocked();
Liam Harringtonc782be62020-07-17 19:48:24 +000096};
97
98} // namespace android
99
100#endif // _UI_TOUCH_SPOT_CONTROLLER_H