Keep node by id + Make SceneGraphTraveler don't travel anymore
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / scene-graph-frame-callback.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
2 #define DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_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 <memory>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/threading/mutex.h>
26 #include <dali/devel-api/update/frame-callback-interface.h>
27 #include <dali/internal/common/owner-pointer.h>
28 #include <dali/internal/update/common/property-owner.h>
29 #include <dali/internal/update/manager/scene-graph-traveler-interface.h>
30 #include <dali/internal/update/manager/update-proxy-impl.h>
31 #include <dali/public-api/common/list-wrapper.h>
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 namespace SceneGraph
38 {
39 class Node;
40 class TransformManager;
41
42 /**
43  * This is the update-thread owned entity of the FrameCallbackInterface.
44  * @see Dali::FrameCallbackInterface
45  */
46 class FrameCallback final : public PropertyOwner::Observer
47 {
48 public:
49   /**
50    * A set of bit mask options that, when combined, define the requests from this FrameCallback
51    * after being called from the update-thread.
52    */
53   enum RequestFlags
54   {
55     CONTINUE_CALLING = 1 << 0, ///< True if we request to continue calling this FrameCallback.
56     KEEP_RENDERING   = 1 << 1  ///< True if we request to keep rendering
57   };
58
59   /**
60    * Creates a new FrameCallback.
61    * @param[in]  frameCallbackInterface  A reference to the FrameCallbackInterface implementation
62    * @return A new FrameCallback.
63    */
64   static FrameCallback* New(FrameCallbackInterface& frameCallbackInterface);
65
66   /**
67    * Non-virtual Destructor.
68    */
69   ~FrameCallback() override;
70
71   /**
72    * Called from the update-thread when connecting to the scene-graph.
73    * @param[in]  updateManager     The Update Manager
74    * @param[in]  transformManager  The Transform Manager
75    * @param[in]  rootNode          The rootNode of this frame-callback
76    * @param[in]  traveler          The cache of traversal for given rootNode
77    */
78   void ConnectToSceneGraph(UpdateManager& updateManager, TransformManager& transformManager, Node& rootNode, SceneGraphTravelerInterfacePtr traveler);
79
80   /**
81    * Called from the update-thread when connecting to the scene-graph.
82    * @param[in]  updateManager     The Update Manager
83    * @param[in]  transformManager  The Transform Manager
84    * @param[in]  traveler          The cache of traversal
85    */
86   void ConnectToSceneGraph(UpdateManager& updateManager, TransformManager& transformManager, SceneGraphTravelerInterfacePtr traveler);
87
88   // Movable but not copyable
89
90   FrameCallback(const FrameCallback&) = delete;            ///< Deleted copy constructor.
91   FrameCallback(FrameCallback&&)      = default;           ///< Default move constructor.
92   FrameCallback& operator=(const FrameCallback&) = delete; ///< Deleted copy assignment operator.
93   FrameCallback& operator=(FrameCallback&&) = default;     ///< Default move assignment operator.
94
95   /**
96    * Called from the update-thread after the scene has been updated, and is ready to render.
97    * @param[in]  bufferIndex           The bufferIndex to use
98    * @param[in]  elapsedSeconds        Time elapsed time since the last frame (in seconds)
99    * @param[in]  nodeHierarchyChanged  Whether the node hierarchy has changed
100    * @return The requests from this FrameCallback.
101    */
102   RequestFlags Update(BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged);
103
104   /**
105    * Called from the update thread when there's a sync point to insert.
106    * @param[in] syncPoint The sync point to insert before the next update
107    */
108   void Notify(Dali::UpdateProxy::NotifySyncPoint syncPoint);
109
110   /**
111    * Invalidates this FrameCallback and will no longer be associated with the FrameCallbackInterface.
112    * @note This method is thread-safe.
113    */
114   void Invalidate();
115
116   /**
117    * Comparison operator between a FrameCallback and a FrameCallbackInterface pointer.
118    * @param[in]  iFace  The FrameCallbackInterface pointer to compare with
119    * @return True if iFace matches our internally stored FrameCallbackInterface.
120    */
121   inline bool operator==(const FrameCallbackInterface* iFace)
122   {
123     return mFrameCallbackInterface == iFace;
124   }
125
126 private:
127   // From PropertyOwner::Observer
128
129   /**
130    * @copydoc PropertyOwner::Observer::PropertyOwnerConnected()
131    */
132   void PropertyOwnerConnected(PropertyOwner& owner) override
133   { /* Nothing to do */
134   }
135
136   /**
137    * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
138    */
139   void PropertyOwnerDisconnected(BufferIndex updateBufferIndex, PropertyOwner& owner) override
140   { /* Nothing to do */
141   }
142
143   /**
144    * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
145    *
146    * Will use this to disconnect the frame-callback if the accompanying node is destroyed
147    */
148   void PropertyOwnerDestroyed(PropertyOwner& owner) override;
149
150   // Construction
151
152   /**
153    * Constructor.
154    * @param[in]  frameCallbackInterface  A pointer to the FrameCallbackInterface implementation
155    */
156   FrameCallback(FrameCallbackInterface* frameCallbackInterface);
157
158 private:
159   Mutex                                         mMutex;
160   std::unique_ptr<UpdateProxy>                  mUpdateProxy{nullptr}; ///< A unique pointer to the implementation of the UpdateProxy.
161   Node*                                         mRootNode{nullptr};    ///< Connected root node for given FrameCallback. It could be nullptr if it is global callback.
162   FrameCallbackInterface*                       mFrameCallbackInterface;
163   std::list<Dali::UpdateProxy::NotifySyncPoint> mSyncPoints;
164   bool                                          mValid{true}; ///< Set to false when Invalidate() is called.
165 };
166
167 /**
168  * Checks if FrameCallback store iFace internally.
169  * @param[in]  frameCallback  Reference to the owner-pointer of frame-callback
170  * @param[in]  iFace          The FrameCallbackInterface pointer
171  * @return True if iFace matches the internally stored FrameCallbackInterface.
172  */
173 inline bool operator==(const OwnerPointer<FrameCallback>& frameCallback, const FrameCallbackInterface* iFace)
174 {
175   return *frameCallback == iFace;
176 }
177
178 } // namespace SceneGraph
179
180 } // namespace Internal
181
182 } // namespace Dali
183
184 #endif // DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H