Keep node by id + Make SceneGraphTraveler don't travel anymore
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / frame-callback-processor.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_PROCESSOR_H
2 #define DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_PROCESSOR_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 #include <unordered_map>
24
25 // INTERNAL INCLUDES
26 #include <dali/internal/common/buffer-index.h>
27 #include <dali/internal/common/owner-pointer.h>
28 #include <dali/internal/update/manager/scene-graph-frame-callback.h>
29 #include <dali/internal/update/manager/scene-graph-traveler.h>
30 #include <dali/internal/update/manager/update-proxy-impl.h>
31 #include <dali/public-api/common/vector-wrapper.h>
32
33 namespace Dali
34 {
35 class FrameCallbackInterface;
36
37 namespace Internal
38 {
39 namespace SceneGraph
40 {
41 class Node;
42 class TransformManager;
43 class UpdateManager;
44
45 /**
46  * This class processes all the registered frame-callbacks.
47  */
48 class FrameCallbackProcessor
49 {
50 public:
51   /**
52    * Construct a new FrameCallbackProcessor.
53    * @param[in]  updateManager     A reference to the UpdateManager
54    * @param[in]  transformManager  A reference to the TransformManager
55    */
56   FrameCallbackProcessor(UpdateManager& updateManager, TransformManager& transformManager);
57
58   /**
59    * Non-virtual Destructor.
60    */
61   ~FrameCallbackProcessor();
62
63   // Movable but not copyable
64
65   FrameCallbackProcessor(const FrameCallbackProcessor&) = delete;            ///< Deleted copy constructor.
66   FrameCallbackProcessor(FrameCallbackProcessor&&)      = default;           ///< Default move constructor.
67   FrameCallbackProcessor& operator=(const FrameCallbackProcessor&) = delete; ///< Deleted copy assignment operator.
68   FrameCallbackProcessor& operator=(FrameCallbackProcessor&&) = delete;      ///< Deleted move assignment operator.
69
70   /**
71    * Adds an implementation of the FrameCallbackInterface.
72    * @param[in]  frameCallback  An OwnerPointer to the SceneGraph FrameCallback object
73    * @param[in]  rootNode       A pointer to the root node to apply the FrameCallback to. Or nullptr if given frame callback use globally.
74    */
75   void AddFrameCallback(OwnerPointer<FrameCallback>& frameCallback, const Node* rootNode);
76
77   /**
78    * Removes the specified implementation of FrameCallbackInterface.
79    * @param[in]  frameCallback  A pointer to the implementation of the FrameCallbackInterface to remove.
80    */
81   void RemoveFrameCallback(FrameCallbackInterface* frameCallback);
82
83   /**
84    * Notify the specified implementation of FrameCallbackInterface.
85    * @param[in]  frameCallback  A pointer to the implementation of the FrameCallbackInterface to notify.
86    * @param[in] syncPoint The unique sync point to notify with
87    */
88   void NotifyFrameCallback(FrameCallbackInterface* frameCallback, Dali::UpdateProxy::NotifySyncPoint syncPoint);
89
90   /**
91    * Called on Update by the UpdateManager.
92    * @param[in]  bufferIndex     The bufferIndex to use
93    * @param[in]  elapsedSeconds  Time elapsed time since the last frame (in seconds)
94    * @return Whether we should keep rendering.
95    */
96   bool Update(BufferIndex bufferIndex, float elapsedSeconds);
97
98   /**
99    * Called by the UpdateManager when the node hierarchy changes.
100    */
101   void NodeHierarchyChanged()
102   {
103     mNodeHierarchyChanged = true;
104   }
105
106 private:
107   SceneGraphTravelerPtr GetSceneGraphTraveler(Node* rootNode);
108
109 private:
110   std::vector<OwnerPointer<FrameCallback> > mFrameCallbacks; ///< A container of all the frame-callbacks & accompanying update-proxies.
111
112   UpdateManager& mUpdateManager;
113
114   TransformManager& mTransformManager;
115
116   using TravelerContainer = std::unordered_map<const Node*, SceneGraphTravelerPtr>;
117   TravelerContainer mRootNodeTravelerMap;
118
119   SceneGraphTravelerInterfacePtr mGlobalTraveler;
120
121   bool mNodeHierarchyChanged; ///< Set to true if the node hierarchy changes
122 };
123
124 } // namespace SceneGraph
125
126 } // namespace Internal
127
128 } // namespace Dali
129
130 #endif // DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_PROCESSOR_H