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 void PropertyOwnerDisconnected(BufferIndex updateBufferIndex, PropertyOwner& owner) override
140 { /* Nothing to do */
144 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
146 * Will use this to disconnect the frame-callback if the accompanying node is destroyed
148 void PropertyOwnerDestroyed(PropertyOwner& owner) override;
154 * @param[in] frameCallbackInterface A pointer to the FrameCallbackInterface implementation
156 FrameCallback(FrameCallbackInterface* frameCallbackInterface);
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.
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.
173 inline bool operator==(const OwnerPointer<FrameCallback>& frameCallback, const FrameCallbackInterface* iFace)
175 return *frameCallback == iFace;
178 } // namespace SceneGraph
180 } // namespace Internal
184 #endif // DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H