1 #ifndef DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
2 #define DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
5 * Copyright (c) 2018 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>
41 class TransformManager;
44 * This is the update-thread owned entity of the FrameCallbackInterface.
45 * @see Dali::FrameCallbackInterface
47 class FrameCallback final : public PropertyOwner::Observer
52 * Creates a new FrameCallback.
53 * @param[in] frameCallbackInterface A reference to the FrameCallbackInterface implementation
54 * @return A new FrameCallback.
56 static FrameCallback* New( FrameCallbackInterface& frameCallbackInterface );
59 * Non-virtual Destructor.
64 * Called from the update-thread when connecting to the scene-graph.
65 * @param[in] updateManager The Update Manager
66 * @param[in] transformManager The Transform Manager
67 * @param[in] rootNode The rootNode of this frame-callback
69 void ConnectToSceneGraph( UpdateManager& updateManager, TransformManager& transformManager, Node& rootNode );
71 // Movable but not copyable
73 FrameCallback( const FrameCallback& ) = delete; ///< Deleted copy constructor.
74 FrameCallback( FrameCallback&& ) = default; ///< Default move constructor.
75 FrameCallback& operator=( const FrameCallback& ) = delete; ///< Deleted copy assignment operator.
76 FrameCallback& operator=( FrameCallback&& ) = default; ///< Default move assignment operator.
79 * Called from the update-thread after the scene has been updated, and is ready to render.
80 * @param[in] bufferIndex The bufferIndex to use
81 * @param[in] elapsedSeconds Time elapsed time since the last frame (in seconds)
82 * @param[in] nodeHierarchyChanged Whether the node hierarchy has changed
83 * @return Whether to continue calling this FrameCallback or not.
85 bool Update( BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged );
88 * Invalidates this FrameCallback and will no longer be associated with the FrameCallbackInterface.
89 * @note This method is thread-safe.
94 * Comparison operator between a FrameCallback and a FrameCallbackInterface pointer.
95 * @param[in] iFace The FrameCallbackInterface pointer to compare with
96 * @return True if iFace matches our internally stored FrameCallbackInterface.
98 inline bool operator==( const FrameCallbackInterface* iFace )
100 return mFrameCallbackInterface == iFace;
105 // From PropertyOwner::Observer
108 * @copydoc PropertyOwner::Observer::PropertyOwnerConnected()
110 virtual void PropertyOwnerConnected( PropertyOwner& owner ) { /* Nothing to do */ }
113 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
115 virtual void PropertyOwnerDisconnected( BufferIndex updateBufferIndex, PropertyOwner& owner ) { /* Nothing to do */ }
118 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
120 * Will use this to disconnect the frame-callback if the accompanying node is destroyed
122 virtual void PropertyOwnerDestroyed( PropertyOwner& owner );
128 * @param[in] frameCallbackInterface A pointer to the FrameCallbackInterface implementation
130 FrameCallback( FrameCallbackInterface* frameCallbackInterface );
135 std::unique_ptr< UpdateProxy > mUpdateProxy{ nullptr }; ///< A unique pointer to the implementation of the UpdateProxy.
136 FrameCallbackInterface* mFrameCallbackInterface;
140 * Checks if FrameCallback store iFace internally.
141 * @param[in] frameCallback Reference to the owner-pointer of frame-callback
142 * @param[in] iFace The FrameCallbackInterface pointer
143 * @return True if iFace matches the internally stored FrameCallbackInterface.
145 inline bool operator==( const OwnerPointer< FrameCallback >& frameCallback, const FrameCallbackInterface* iFace )
147 return *frameCallback == iFace;
150 } // namespace SceneGraph
152 } // namespace Internal
156 #endif // DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H