1 #ifndef DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
2 #define DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
5 * Copyright (c) 2021 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/update-proxy-impl.h>
38 class TransformManager;
41 * This is the update-thread owned entity of the FrameCallbackInterface.
42 * @see Dali::FrameCallbackInterface
44 class FrameCallback final : public PropertyOwner::Observer
48 * Creates a new FrameCallback.
49 * @param[in] frameCallbackInterface A reference to the FrameCallbackInterface implementation
50 * @return A new FrameCallback.
52 static FrameCallback* New(FrameCallbackInterface& frameCallbackInterface);
55 * Non-virtual Destructor.
57 ~FrameCallback() override;
60 * Called from the update-thread when connecting to the scene-graph.
61 * @param[in] updateManager The Update Manager
62 * @param[in] transformManager The Transform Manager
63 * @param[in] rootNode The rootNode of this frame-callback
65 void ConnectToSceneGraph(UpdateManager& updateManager, TransformManager& transformManager, Node& rootNode);
67 // Movable but not copyable
69 FrameCallback(const FrameCallback&) = delete; ///< Deleted copy constructor.
70 FrameCallback(FrameCallback&&) = default; ///< Default move constructor.
71 FrameCallback& operator=(const FrameCallback&) = delete; ///< Deleted copy assignment operator.
72 FrameCallback& operator=(FrameCallback&&) = default; ///< Default move assignment operator.
75 * Called from the update-thread after the scene has been updated, and is ready to render.
76 * @param[in] bufferIndex The bufferIndex to use
77 * @param[in] elapsedSeconds Time elapsed time since the last frame (in seconds)
78 * @param[in] nodeHierarchyChanged Whether the node hierarchy has changed
79 * @return Whether to continue calling this FrameCallback or not.
81 bool Update(BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged);
84 * Invalidates this FrameCallback and will no longer be associated with the FrameCallbackInterface.
85 * @note This method is thread-safe.
90 * Comparison operator between a FrameCallback and a FrameCallbackInterface pointer.
91 * @param[in] iFace The FrameCallbackInterface pointer to compare with
92 * @return True if iFace matches our internally stored FrameCallbackInterface.
94 inline bool operator==(const FrameCallbackInterface* iFace)
96 return mFrameCallbackInterface == iFace;
100 // From PropertyOwner::Observer
103 * @copydoc PropertyOwner::Observer::PropertyOwnerConnected()
105 void PropertyOwnerConnected(PropertyOwner& owner) override
106 { /* Nothing to do */
110 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
112 void PropertyOwnerDisconnected(BufferIndex updateBufferIndex, PropertyOwner& owner) override
113 { /* Nothing to do */
117 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
119 * Will use this to disconnect the frame-callback if the accompanying node is destroyed
121 void PropertyOwnerDestroyed(PropertyOwner& owner) override;
127 * @param[in] frameCallbackInterface A pointer to the FrameCallbackInterface implementation
129 FrameCallback(FrameCallbackInterface* frameCallbackInterface);
133 std::unique_ptr<UpdateProxy> mUpdateProxy{nullptr}; ///< A unique pointer to the implementation of the UpdateProxy.
134 FrameCallbackInterface* mFrameCallbackInterface;
138 * Checks if FrameCallback store iFace internally.
139 * @param[in] frameCallback Reference to the owner-pointer of frame-callback
140 * @param[in] iFace The FrameCallbackInterface pointer
141 * @return True if iFace matches the internally stored FrameCallbackInterface.
143 inline bool operator==(const OwnerPointer<FrameCallback>& frameCallback, const FrameCallbackInterface* iFace)
145 return *frameCallback == iFace;
148 } // namespace SceneGraph
150 } // namespace Internal
154 #endif // DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H