1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_UI_CONTEXT_H 16 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_UI_CONTEXT_H 17 18 #include <functional> 19 #include <memory> 20 21 #include "animation/rs_animation.h" 22 #include "animation/rs_implicit_animator.h" 23 #include "common/rs_common_def.h" 24 #include "modifier/rs_modifier_manager.h" 25 #include "pipeline/rs_node_map_v2.h" 26 #include "transaction/rs_transaction_handler.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 using TaskRunner = std::function<void(const std::function<void()>&, uint32_t)>; 31 32 class RSC_EXPORT RSUIContext : public std::enable_shared_from_this<RSUIContext> { 33 public: 34 virtual ~RSUIContext(); 35 GetMutableNodeMap()36 inline RSNodeMapV2& GetMutableNodeMap() 37 { 38 return nodeMap_; 39 } GetNodeMap()40 inline const RSNodeMapV2& GetNodeMap() const 41 { 42 return nodeMap_; 43 } 44 GetRSTransaction()45 inline std::shared_ptr<RSTransactionHandler> GetRSTransaction() const 46 { 47 return rsTransactionHandler_; 48 } GetSyncTransactionHandler()49 inline std::shared_ptr<RSSyncTransactionHandler> GetSyncTransactionHandler() const 50 { 51 return rsSyncTransactionHandler_; 52 } 53 54 const std::shared_ptr<RSImplicitAnimator> GetRSImplicitAnimator(); 55 const std::shared_ptr<RSModifierManager> GetRSModifierManager(); 56 bool AnimationCallback(AnimationId animationId, AnimationCallbackEvent event); 57 void AddAnimationInner(const std::shared_ptr<RSAnimation>& animation); 58 void RemoveAnimationInner(const std::shared_ptr<RSAnimation>& animation); 59 GetToken()60 inline uint64_t GetToken() const 61 { 62 return token_; 63 } 64 65 void SetUITaskRunner(const TaskRunner& uiTaskRunner); 66 void PostTask(const std::function<void()>& task); 67 void PostDelayTask(const std::function<void()>& task, uint32_t delay); HasTaskRunner()68 inline bool HasTaskRunner() 69 { 70 return bool(taskRunner_); 71 } 72 73 private: 74 RSUIContext(); 75 RSUIContext(uint64_t token); 76 RSUIContext(const RSUIContext&) = delete; 77 RSUIContext(const RSUIContext&&) = delete; 78 RSUIContext& operator=(const RSUIContext&) = delete; 79 RSUIContext& operator=(const RSUIContext&&) = delete; 80 81 uint64_t token_; 82 83 RSNodeMapV2 nodeMap_; 84 std::shared_ptr<RSTransactionHandler> rsTransactionHandler_; 85 std::shared_ptr<RSSyncTransactionHandler> rsSyncTransactionHandler_; 86 std::shared_ptr<RSImplicitAnimator> rsImplicitAnimator_; 87 std::shared_ptr<RSModifierManager> rsModifierManager_; 88 89 std::unordered_map<AnimationId, std::shared_ptr<RSAnimation>> animations_; 90 std::unordered_map<PropertyId, uint32_t> animatingPropertyNum_; 91 std::recursive_mutex animationMutex_; 92 93 TaskRunner taskRunner_ = TaskRunner(); 94 95 friend class RSUIContextManager; 96 }; 97 98 } // namespace Rosen 99 } // namespace OHOS 100 101 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_UI_CONTEXT_H