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_PIPELINE_RS_NODE_MAP_V2_H 16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_NODE_MAP_V2_H 17 18 #include <mutex> 19 #include <unordered_map> 20 21 #include "common/rs_common_def.h" 22 #include "common/rs_macros.h" 23 #include "ui/rs_base_node.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 class RSNode; 28 class RSC_EXPORT RSNodeMapV2 final { 29 public: 30 bool RegisterNode(const std::shared_ptr<RSBaseNode>& nodePtr); 31 bool RegisterNodeInstanceId(NodeId id, int32_t instanceId); 32 void UnregisterNode(NodeId id); 33 // Get RSNode with type T, return nullptr if not found or type mismatch 34 template<typename T = RSBaseNode> GetNode(NodeId id)35 const std::shared_ptr<T> GetNode(NodeId id) const 36 { 37 return RSBaseNode::ReinterpretCast<T>(GetNode<RSBaseNode>(id)); 38 } 39 template<> 40 const std::shared_ptr<RSBaseNode> GetNode(NodeId id) const; 41 42 private: 43 RSNodeMapV2(); 44 ~RSNodeMapV2() noexcept; 45 std::unordered_map<NodeId, std::weak_ptr<RSBaseNode>> nodeMapNew_; 46 mutable std::mutex mutex_; 47 48 friend class RSUIContext; 49 }; 50 } // namespace Rosen 51 } // namespace OHOS 52 53 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_NODE_MAP_V2_H