blob: f3b355010bee6f22e78d9843e57e272a5dc0adb0 [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
20#include "PointerControllerContext.h"
21
22namespace android {
23
24/*
25 * Helper class for PointerController that specifically handles
26 * touch spot resources and actions for a single display.
27 */
28class TouchSpotController {
29public:
30 TouchSpotController(int32_t displayId, PointerControllerContext& context);
31 ~TouchSpotController();
32 void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
33 BitSet32 spotIdBits);
34 void clearSpots();
35
36 void reloadSpotResources();
37 bool doFadingAnimation(nsecs_t timestamp, bool keepAnimating);
38
39private:
40 struct Spot {
41 static const uint32_t INVALID_ID = 0xffffffff;
42
43 uint32_t id;
44 sp<Sprite> sprite;
45 float alpha;
46 float scale;
47 float x, y;
48
49 inline Spot(uint32_t id, const sp<Sprite>& sprite)
50 : id(id),
51 sprite(sprite),
52 alpha(1.0f),
53 scale(1.0f),
54 x(0.0f),
55 y(0.0f),
56 mLastIcon(nullptr) {}
57
58 void updateSprite(const SpriteIcon* icon, float x, float y, int32_t displayId);
59
60 private:
61 const SpriteIcon* mLastIcon;
62 };
63
64 int32_t mDisplayId;
65
66 mutable std::mutex mLock;
67
68 PointerResources mResources;
69
70 PointerControllerContext& mContext;
71
72 static constexpr size_t MAX_RECYCLED_SPRITES = 12;
73 static constexpr size_t MAX_SPOTS = 12;
74
75 struct Locked {
76 std::vector<Spot*> displaySpots;
77 std::vector<sp<Sprite>> recycledSprites;
78
79 } mLocked GUARDED_BY(mLock);
80
81 Spot* getSpot(uint32_t id, const std::vector<Spot*>& spots);
82 Spot* createAndAddSpotLocked(uint32_t id, std::vector<Spot*>& spots);
83 Spot* removeFirstFadingSpotLocked(std::vector<Spot*>& spots);
84 void releaseSpotLocked(Spot* spot);
85 void fadeOutAndReleaseSpotLocked(Spot* spot);
86 void fadeOutAndReleaseAllSpotsLocked();
87};
88
89} // namespace android
90
91#endif // _UI_TOUCH_SPOT_CONTROLLER_H