• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CLIENT_CORE_PIPELINE_RS_NODE_MAP_H
16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_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 "ui/rs_base_node.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class RSNode;
28 
29 class RSC_EXPORT RSNodeMap final {
30 public:
31     static const RSNodeMap& Instance();
32     static RSNodeMap& MutableInstance();
33 
34     bool RegisterNode(const std::shared_ptr<RSBaseNode>& nodePtr);
35     void UnregisterNode(NodeId id);
36 
37     // Get RSNode with type T, return nullptr if not found or type mismatch
38     template<typename T = RSBaseNode>
GetNode(NodeId id)39     const std::shared_ptr<T> GetNode(NodeId id) const
40     {
41         return RSBaseNode::ReinterpretCast<T>(GetNode<RSBaseNode>(id));
42     }
43     template<>
44     const std::shared_ptr<RSBaseNode> GetNode(NodeId id) const;
45 
46     const std::shared_ptr<RSNode> GetAnimationFallbackNode() const;
47 
48 private:
49     explicit RSNodeMap();
50     ~RSNodeMap() noexcept;
51     RSNodeMap(const RSNodeMap&) = delete;
52     RSNodeMap(const RSNodeMap&&) = delete;
53     RSNodeMap& operator=(const RSNodeMap&) = delete;
54     RSNodeMap& operator=(const RSNodeMap&&) = delete;
55 
56 private:
57     mutable std::mutex mutex_;
58     std::unordered_map<NodeId, std::weak_ptr<RSBaseNode>> nodeMap_;
59     std::shared_ptr<RSNode> animationFallbackNode_;
60 };
61 } // namespace Rosen
62 } // namespace OHOS
63 
64 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_NODE_MAP_H
65