1 #ifndef DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
2 #define DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
5 * Copyright (c) 2023 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.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, SceneGraphTravelerPtr traveler);
80 // Movable but not copyable
82 FrameCallback(const FrameCallback&) = delete; ///< Deleted copy constructor.
83 FrameCallback(FrameCallback&&) = default; ///< Default move constructor.
84 FrameCallback& operator=(const FrameCallback&) = delete; ///< Deleted copy assignment operator.
85 FrameCallback& operator=(FrameCallback&&) = default; ///< Default move assignment operator.
88 * Called from the update-thread after the scene has been updated, and is ready to render.
89 * @param[in] bufferIndex The bufferIndex to use
90 * @param[in] elapsedSeconds Time elapsed time since the last frame (in seconds)
91 * @param[in] nodeHierarchyChanged Whether the node hierarchy has changed
92 * @return The requests from this FrameCallback.
94 RequestFlags Update(BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged);
97 * Called from the update thread when there's a sync point to insert.
98 * @param[in] syncPoint The sync point to insert before the next update
100 void Notify(Dali::UpdateProxy::NotifySyncPoint syncPoint);
103 * Invalidates this FrameCallback and will no longer be associated with the FrameCallbackInterface.
104 * @note This method is thread-safe.
109 * Comparison operator between a FrameCallback and a FrameCallbackInterface pointer.
110 * @param[in] iFace The FrameCallbackInterface pointer to compare with
111 * @return True if iFace matches our internally stored FrameCallbackInterface.
113 inline bool operator==(const FrameCallbackInterface* iFace)
115 return mFrameCallbackInterface == iFace;
119 // From PropertyOwner::Observer
122 * @copydoc PropertyOwner::Observer::PropertyOwnerConnected()
124 void PropertyOwnerConnected(PropertyOwner& owner) override
125 { /* Nothing to do */
129 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
131 void PropertyOwnerDisconnected(BufferIndex updateBufferIndex, PropertyOwner& owner) override
132 { /* Nothing to do */
136 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
138 * Will use this to disconnect the frame-callback if the accompanying node is destroyed
140 void PropertyOwnerDestroyed(PropertyOwner& owner) override;
146 * @param[in] frameCallbackInterface A pointer to the FrameCallbackInterface implementation
148 FrameCallback(FrameCallbackInterface* frameCallbackInterface);
152 std::unique_ptr<UpdateProxy> mUpdateProxy{nullptr}; ///< A unique pointer to the implementation of the UpdateProxy.
153 FrameCallbackInterface* mFrameCallbackInterface;
154 std::list<Dali::UpdateProxy::NotifySyncPoint> mSyncPoints;
155 bool mValid{true}; ///< Set to false when Invalidate() is called.
159 * Checks if FrameCallback store iFace internally.
160 * @param[in] frameCallback Reference to the owner-pointer of frame-callback
161 * @param[in] iFace The FrameCallbackInterface pointer
162 * @return True if iFace matches the internally stored FrameCallbackInterface.
164 inline bool operator==(const OwnerPointer<FrameCallback>& frameCallback, const FrameCallbackInterface* iFace)
166 return *frameCallback == iFace;
169 } // namespace SceneGraph
171 } // namespace Internal
175 #endif // DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H