Cache traveler only if the node was child of root node
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / scene-graph-traveler.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_TRAVELER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_TRAVELER_H
3
4 /*
5  * Copyright (c) 2024 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <unordered_map>
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/update/manager/scene-graph-traveler-interface.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class SceneGraphTraveler;
32 using SceneGraphTravelerPtr = IntrusivePtr<SceneGraphTraveler>;
33
34 /**
35  * @brief Helper class to travel scene graph under root node.
36  */
37 class SceneGraphTraveler : public SceneGraphTravelerInterface, public SceneGraph::PropertyOwner::Observer
38 {
39 public:
40   /**
41    * @brief Construct
42    * @param[in] updateManager The update manager.
43    * @param[in] rootNode The root node of this traveler. The traveler will find only under this rootNode.
44    */
45   SceneGraphTraveler(SceneGraph::UpdateManager& updateManager, SceneGraph::Node& rootNode);
46
47   /**
48    * @brief Destructor
49    */
50   ~SceneGraphTraveler() override;
51
52 public:
53   /**
54    * @brief Call this method if hierarchy was changed under root node.
55    */
56   void NodeHierarchyChanged()
57   {
58     Clear();
59   }
60
61   /**
62    * @brief Whether root node is invalidated or not.
63    *
64    * @return True if root node is invalidated.
65    */
66   bool IsInvalidated() const
67   {
68     return mInvalidated;
69   }
70
71 public: // From SceneGraphTravelerInterface
72   /**
73    * @copydoc Dali::Internal::SceneGraphTravelerInterface::FindNode()
74    */
75   SceneGraph::Node* FindNode(uint32_t id) override;
76
77 private: // From SceneGraph::PropertyOwner::Observer
78   /**
79    * @copydoc SceneGraph::PropertyOwner::Observer::PropertyOwnerConnected()
80    */
81   void PropertyOwnerConnected(SceneGraph::PropertyOwner& owner) override
82   { /* Nothing to do */
83   }
84
85   /**
86    * @copydoc SceneGraph::PropertyOwner::Observer::PropertyOwnerDisconnected()
87    */
88   void PropertyOwnerDisconnected(BufferIndex updateBufferIndex, SceneGraph::PropertyOwner& owner) override
89   { /* Nothing to do */
90   }
91
92   /**
93    * @copydoc SceneGraph::PropertyOwner::Observer::PropertyOwnerDisconnected()
94    */
95   void PropertyOwnerDestroyed(SceneGraph::PropertyOwner& owner) override
96   {
97     // Invalidate this traveler
98     mInvalidated = true;
99     Clear();
100   }
101
102 private:
103   void Clear();
104
105 private:
106   SceneGraph::Node& mRootNode;
107
108   std::unordered_map<uint32_t, SceneGraph::Node*> mTravledNodeMap; ///< Used to store cached pointers to already searched for Nodes.
109
110   bool mInvalidated : 1; ///< True if root node was destroyed.
111 };
112
113 } // namespace Internal
114
115 } // namespace Dali
116
117 #endif // DALI_INTERNAL_UPDATE_PROXY_SCENE_GRAPH_TRAVELER_H