• 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(ui::LogicalDisplayId displayId, PointerControllerContext& context);
33     ~TouchSpotController();
34     void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
35                   BitSet32 spotIdBits, bool skipScreenshot);
36     void clearSpots();
37 
38     void reloadSpotResources();
39     bool doAnimations(nsecs_t timestamp);
40 
41     void dump(std::string& out, const char* prefix = "") const;
42 
43 private:
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 
SpotSpot53         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, ui::LogicalDisplayId displayId,
63                           bool skipScreenshot);
64         void dump(std::string& out, const char* prefix = "") const;
65 
66     private:
67         const SpriteIcon* mLastIcon;
68     };
69 
70     ui::LogicalDisplayId mDisplayId;
71 
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 
85         bool animating{false};
86 
87     } 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();
95     bool doFadingAnimationLocked(nsecs_t timestamp);
96     void startAnimationLocked();
97 };
98 
99 } // namespace android
100 
101 #endif // _UI_TOUCH_SPOT_CONTROLLER_H
102