[dali_2.3.27] Merge branch 'devel/master'
[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 #if defined(LOW_SPEC_MEMORY_MANAGEMENT_ENABLED)
23 #include <dali/devel-api/common/map-wrapper.h>
24 #else
25 #include <unordered_map>
26 #endif
27
28 // INTERNAL INCLUDES
29 #include <dali/internal/update/manager/scene-graph-traveler-interface.h>
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35 class SceneGraphTraveler;
36 using SceneGraphTravelerPtr = IntrusivePtr<SceneGraphTraveler>;
37
38 /**
39  * @brief Helper class to travel scene graph under root node.
40  */
41 class SceneGraphTraveler : public SceneGraphTravelerInterface, public SceneGraph::PropertyOwner::Observer
42 {
43 public:
44   /**
45    * @brief Construct
46    * @param[in] updateManager The update manager.
47    * @param[in] rootNode The root node of this traveler. The traveler will find only under this rootNode.
48    */
49   SceneGraphTraveler(SceneGraph::UpdateManager& updateManager, SceneGraph::Node& rootNode);
50
51   /**
52    * @brief Destructor
53    */
54   ~SceneGraphTraveler() override;
55
56 public:
57   /**
58    * @brief Call this method if hierarchy was changed under root node.
59    */
60   void NodeHierarchyChanged()
61   {
62     Clear();
63   }
64
65   /**
66    * @brief Whether root node is invalidated or not.
67    *
68    * @return True if root node is invalidated.
69    */
70   bool IsInvalidated() const
71   {
72     return mInvalidated;
73   }
74
75 public: // From SceneGraphTravelerInterface
76   /**
77    * @copydoc Dali::Internal::SceneGraphTravelerInterface::FindNode()
78    */
79   SceneGraph::Node* FindNode(uint32_t id) override;
80
81 private: // From SceneGraph::PropertyOwner::Observer
82   /**
83    * @copydoc SceneGraph::PropertyOwner::Observer::PropertyOwnerConnected()
84    */
85   void PropertyOwnerConnected(SceneGraph::PropertyOwner& owner) override
86   { /* Nothing to do */
87   }
88
89   /**
90    * @copydoc SceneGraph::PropertyOwner::Observer::PropertyOwnerDisconnected()
91    */
92   NotifyReturnType PropertyOwnerDisconnected(BufferIndex updateBufferIndex, SceneGraph::PropertyOwner& owner) override
93   { /* Nothing to do */
94     return NotifyReturnType::KEEP_OBSERVING;
95   }
96
97   /**
98    * @copydoc SceneGraph::PropertyOwner::Observer::PropertyOwnerDisconnected()
99    */
100   void PropertyOwnerDestroyed(SceneGraph::PropertyOwner& owner) override
101   {
102     // Invalidate this traveler
103     mInvalidated = true;
104     Clear();
105   }
106
107 private:
108   void Clear();
109
110 private:
111   SceneGraph::Node& mRootNode;
112
113 #if defined(LOW_SPEC_MEMORY_MANAGEMENT_ENABLED)
114   using TraveledNodeMap = std::map<uint32_t, SceneGraph::Node*>;
115 #else
116   using TraveledNodeMap = std::unordered_map<uint32_t, SceneGraph::Node*>;
117 #endif
118   TraveledNodeMap mTravledNodeMap; ///< Used to store cached pointers to already searched for Nodes.
119
120   bool mInvalidated : 1; ///< True if root node was destroyed.
121 };
122
123 } // namespace Internal
124
125 } // namespace Dali
126
127 #endif // DALI_INTERNAL_UPDATE_PROXY_SCENE_GRAPH_TRAVELER_H