• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 <functional>
21 
22 #include "PointerControllerContext.h"
23 
24 namespace android {
25 
26 /*
27  * Helper class for PointerController that specifically handles
28  * touch spot resources and actions for a single display.
29  */
30 class TouchSpotController {
31 public:
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();
39     bool doAnimations(nsecs_t timestamp);
40 
41 private:
42     struct Spot {
43         static const uint32_t INVALID_ID = 0xffffffff;
44 
45         uint32_t id;
46         sp<Sprite> sprite;
47         float alpha;
48         float scale;
49         float x, y;
50 
SpotSpot51         inline Spot(uint32_t id, const sp<Sprite>& sprite)
52               : id(id),
53                 sprite(sprite),
54                 alpha(1.0f),
55                 scale(1.0f),
56                 x(0.0f),
57                 y(0.0f),
58                 mLastIcon(nullptr) {}
59 
60         void updateSprite(const SpriteIcon* icon, float x, float y, int32_t displayId);
61 
62     private:
63         const SpriteIcon* mLastIcon;
64     };
65 
66     int32_t mDisplayId;
67 
68     mutable std::mutex mLock;
69 
70     PointerResources mResources;
71 
72     PointerControllerContext& mContext;
73 
74     static constexpr size_t MAX_RECYCLED_SPRITES = 12;
75     static constexpr size_t MAX_SPOTS = 12;
76 
77     struct Locked {
78         std::vector<Spot*> displaySpots;
79         std::vector<sp<Sprite>> recycledSprites;
80 
81         bool animating{false};
82 
83     } mLocked GUARDED_BY(mLock);
84 
85     Spot* getSpot(uint32_t id, const std::vector<Spot*>& spots);
86     Spot* createAndAddSpotLocked(uint32_t id, std::vector<Spot*>& spots);
87     Spot* removeFirstFadingSpotLocked(std::vector<Spot*>& spots);
88     void releaseSpotLocked(Spot* spot);
89     void fadeOutAndReleaseSpotLocked(Spot* spot);
90     void fadeOutAndReleaseAllSpotsLocked();
91     bool doFadingAnimationLocked(nsecs_t timestamp);
92     void startAnimationLocked();
93 };
94 
95 } // namespace android
96 
97 #endif // _UI_TOUCH_SPOT_CONTROLLER_H
98