1 /* 2 * Copyright (c) 2021-2023 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_BASE_PIPELINE_RS_RENDER_NODE_MAP_H 16 #define RENDER_SERVICE_BASE_PIPELINE_RS_RENDER_NODE_MAP_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 "pipeline/rs_base_render_node.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 class RSRenderNode; 28 class RSSurfaceRenderNode; 29 class RSB_EXPORT RSRenderNodeMap final { 30 public: 31 bool RegisterRenderNode(const std::shared_ptr<RSBaseRenderNode>& nodePtr); 32 void UnregisterRenderNode(NodeId id); 33 34 // Get RenderNode with type T, return nullptr if not found or type mismatch 35 template<typename T = RSBaseRenderNode> GetRenderNode(NodeId id)36 const std::shared_ptr<T> GetRenderNode(NodeId id) const 37 { 38 auto renderNode = GetRenderNode<RSBaseRenderNode>(id); 39 return RSBaseRenderNode::ReinterpretCast<T>(renderNode); 40 } 41 template<> 42 const std::shared_ptr<RSBaseRenderNode> GetRenderNode(NodeId id) const; 43 44 const std::shared_ptr<RSRenderNode> GetAnimationFallbackNode() const; 45 46 void FilterNodeByPid(pid_t pid); 47 void TraversalNodes(std::function<void (const std::shared_ptr<RSBaseRenderNode>&)> func) const; 48 void TraverseSurfaceNodes(std::function<void (const std::shared_ptr<RSSurfaceRenderNode>&)> func) const; 49 private: 50 explicit RSRenderNodeMap(); 51 ~RSRenderNodeMap() = default; 52 RSRenderNodeMap(const RSRenderNodeMap&) = delete; 53 RSRenderNodeMap(const RSRenderNodeMap&&) = delete; 54 RSRenderNodeMap& operator=(const RSRenderNodeMap&) = delete; 55 RSRenderNodeMap& operator=(const RSRenderNodeMap&&) = delete; 56 57 private: 58 std::unordered_map<NodeId, std::shared_ptr<RSBaseRenderNode>> renderNodeMap_; 59 std::unordered_map<NodeId, std::shared_ptr<RSSurfaceRenderNode>> surfaceNodeMap_; 60 61 friend class RSContext; 62 friend class RSMainThread; 63 }; 64 } // namespace Rosen 65 } // namespace OHOS 66 67 #endif // RENDER_SERVICE_BASE_PIPELINE_RS_RENDER_NODE_MAP_H 68