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