Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 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 | |
Liam Harrington | ce63713 | 2020-08-14 04:00:11 +0000 | [diff] [blame] | 20 | #include <functional> |
| 21 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 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: |
Linnan Li | 0defadf | 2024-05-05 19:17:05 +0800 | [diff] [blame] | 32 | TouchSpotController(ui::LogicalDisplayId displayId, PointerControllerContext& context); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 33 | ~TouchSpotController(); |
| 34 | void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, |
Arpit Singh | 80fd68a | 2024-03-26 18:41:06 +0000 | [diff] [blame] | 35 | BitSet32 spotIdBits, bool skipScreenshot); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 36 | void clearSpots(); |
| 37 | |
| 38 | void reloadSpotResources(); |
Liam Harrington | ce63713 | 2020-08-14 04:00:11 +0000 | [diff] [blame] | 39 | bool doAnimations(nsecs_t timestamp); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 40 | |
Michael Wright | 20f5fd8 | 2022-10-28 14:12:24 +0100 | [diff] [blame] | 41 | void dump(std::string& out, const char* prefix = "") const; |
| 42 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 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 | |
| 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 Li | 0defadf | 2024-05-05 19:17:05 +0800 | [diff] [blame] | 62 | void updateSprite(const SpriteIcon* icon, float x, float y, ui::LogicalDisplayId displayId, |
Arpit Singh | 80fd68a | 2024-03-26 18:41:06 +0000 | [diff] [blame] | 63 | bool skipScreenshot); |
Michael Wright | 20f5fd8 | 2022-10-28 14:12:24 +0100 | [diff] [blame] | 64 | void dump(std::string& out, const char* prefix = "") const; |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 65 | |
| 66 | private: |
| 67 | const SpriteIcon* mLastIcon; |
| 68 | }; |
| 69 | |
Linnan Li | 0defadf | 2024-05-05 19:17:05 +0800 | [diff] [blame] | 70 | ui::LogicalDisplayId mDisplayId; |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 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 | |
Liam Harrington | ce63713 | 2020-08-14 04:00:11 +0000 | [diff] [blame] | 85 | bool animating{false}; |
| 86 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 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(); |
Liam Harrington | ce63713 | 2020-08-14 04:00:11 +0000 | [diff] [blame] | 95 | bool doFadingAnimationLocked(nsecs_t timestamp); |
| 96 | void startAnimationLocked(); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | } // namespace android |
| 100 | |
| 101 | #endif // _UI_TOUCH_SPOT_CONTROLLER_H |