1 #ifndef DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
2 #define DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
5 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
40 class TransformManager;
43 * This is the update-thread owned entity of the FrameCallbackInterface.
44 * @see Dali::FrameCallbackInterface
46 class FrameCallback final : public PropertyOwner::Observer
50 * A set of bit mask options that, when combined, define the requests from this FrameCallback
51 * after being called from the update-thread.
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
60 * Creates a new FrameCallback.
61 * @param[in] frameCallbackInterface A reference to the FrameCallbackInterface implementation
62 * @return A new FrameCallback.
64 static FrameCallback* New(FrameCallbackInterface& frameCallbackInterface);
67 * Non-virtual Destructor.
69 ~FrameCallback() override;
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
78 void ConnectToSceneGraph(UpdateManager& updateManager, TransformManager& transformManager, Node& rootNode, SceneGraphTravelerInterfacePtr traveler);
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
86 void ConnectToSceneGraph(UpdateManager& updateManager, TransformManager& transformManager, SceneGraphTravelerInterfacePtr traveler);
88 // Movable but not copyable
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.
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.
102 RequestFlags Update(BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged);
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
108 void Notify(Dali::UpdateProxy::NotifySyncPoint syncPoint);
111 * Invalidates this FrameCallback and will no longer be associated with the FrameCallbackInterface.
112 * @note This method is thread-safe.
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.
121 inline bool operator==(const FrameCallbackInterface* iFace)
123 return mFrameCallbackInterface == iFace;
127 // From PropertyOwner::Observer
130 * @copydoc PropertyOwner::Observer::PropertyOwnerConnected()
132 void PropertyOwnerConnected(PropertyOwner& owner) override
133 { /* Nothing to do */
137 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
139 NotifyReturnType PropertyOwnerDisconnected(BufferIndex updateBufferIndex, PropertyOwner& owner) override
140 { /* Nothing to do */
141 return NotifyReturnType::KEEP_OBSERVING;
145 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
147 * Will use this to disconnect the frame-callback if the accompanying node is destroyed
149 void PropertyOwnerDestroyed(PropertyOwner& owner) override;
155 * @param[in] frameCallbackInterface A pointer to the FrameCallbackInterface implementation
157 FrameCallback(FrameCallbackInterface* frameCallbackInterface);
161 std::unique_ptr<UpdateProxy> mUpdateProxy{nullptr}; ///< A unique pointer to the implementation of the UpdateProxy.
162 Node* mRootNode{nullptr}; ///< Connected root node for given FrameCallback. It could be nullptr if it is global callback.
163 FrameCallbackInterface* mFrameCallbackInterface;
164 std::list<Dali::UpdateProxy::NotifySyncPoint> mSyncPoints;
165 bool mValid{true}; ///< Set to false when Invalidate() is called.
169 * Checks if FrameCallback store iFace internally.
170 * @param[in] frameCallback Reference to the owner-pointer of frame-callback
171 * @param[in] iFace The FrameCallbackInterface pointer
172 * @return True if iFace matches the internally stored FrameCallbackInterface.
174 inline bool operator==(const OwnerPointer<FrameCallback>& frameCallback, const FrameCallbackInterface* iFace)
176 return *frameCallback == iFace;
179 } // namespace SceneGraph
181 } // namespace Internal
185 #endif // DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H