2f876e24144ed487e300f7a1608d5d41ce144e05
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / scene-graph-frame-callback.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
2 #define DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <memory>
23
24 // INTERNAL INCLUDES
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>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace SceneGraph
38 {
39
40 class Node;
41 class TransformManager;
42
43 /**
44  * This is the update-thread owned entity of the FrameCallbackInterface.
45  * @see Dali::FrameCallbackInterface
46  */
47 class FrameCallback final : public PropertyOwner::Observer
48 {
49 public:
50
51   /**
52    * Creates a new FrameCallback.
53    * @param[in]  frameCallbackInterface  A reference to the FrameCallbackInterface implementation
54    * @return A new FrameCallback.
55    */
56   static FrameCallback* New( FrameCallbackInterface& frameCallbackInterface );
57
58   /**
59    * Non-virtual Destructor.
60    */
61   ~FrameCallback();
62
63   /**
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
68    */
69   void ConnectToSceneGraph( UpdateManager& updateManager, TransformManager& transformManager, Node& rootNode );
70
71   // Movable but not copyable
72
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.
77
78   /**
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.
84    */
85   bool Update( BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged );
86
87   /**
88    * Invalidates this FrameCallback and will no longer be associated with the FrameCallbackInterface.
89    * @note This method is thread-safe.
90    */
91   void Invalidate();
92
93   /**
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.
97    */
98   inline bool operator==( const FrameCallbackInterface* iFace )
99   {
100     return mFrameCallbackInterface == iFace;
101   }
102
103 private:
104
105   // From PropertyOwner::Observer
106
107   /**
108    * @copydoc PropertyOwner::Observer::PropertyOwnerConnected()
109    */
110   virtual void PropertyOwnerConnected( PropertyOwner& owner ) { /* Nothing to do */ }
111
112   /**
113    * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
114    */
115   virtual void PropertyOwnerDisconnected( BufferIndex updateBufferIndex, PropertyOwner& owner ) { /* Nothing to do */ }
116
117   /**
118    * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
119    *
120    * Will use this to disconnect the frame-callback if the accompanying node is destroyed
121    */
122   virtual void PropertyOwnerDestroyed( PropertyOwner& owner );
123
124   // Construction
125
126   /**
127    * Constructor.
128    * @param[in]  frameCallbackInterface  A pointer to the FrameCallbackInterface implementation
129    */
130   FrameCallback( FrameCallbackInterface* frameCallbackInterface );
131
132 private:
133
134   Mutex mMutex;
135   std::unique_ptr< UpdateProxy > mUpdateProxy{ nullptr }; ///< A unique pointer to the implementation of the UpdateProxy.
136   FrameCallbackInterface* mFrameCallbackInterface;
137 };
138
139 /**
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.
144  */
145 inline bool operator==( const OwnerPointer< FrameCallback >& frameCallback, const FrameCallbackInterface* iFace )
146 {
147   return *frameCallback == iFace;
148 }
149
150 } // namespace SceneGraph
151
152 } // namespace Internal
153
154 } // namespace Dali
155
156 #endif // DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H