(FrameCallback) Ensure the callback is removed if the implementation is deleted
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / frame-callback-processor.h
index 90d9c7d..440227d 100644 (file)
  *
  */
 
+// EXTERNAL INCLUDES
+#include <memory>
+
 // INTERNAL INCLUDES
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/internal/common/buffer-index.h>
 #include <dali/internal/update/common/property-owner.h>
+#include <dali/internal/update/manager/update-proxy-impl.h>
 
 namespace Dali
 {
@@ -31,8 +35,6 @@ class FrameCallbackInterface;
 namespace Internal
 {
 
-class UpdateProxy;
-
 namespace SceneGraph
 {
 
@@ -49,7 +51,7 @@ public:
   /**
    * Construct a new FrameCallbackProcessor.
    */
-  FrameCallbackProcessor( TransformManager& transformManager, Node& rootNode );
+  FrameCallbackProcessor( TransformManager& transformManager );
 
   /**
    * Non-virtual Destructor.
@@ -83,6 +85,14 @@ public:
    */
   void Update( BufferIndex bufferIndex, float elapsedSeconds );
 
+  /**
+   * Called by the UpdateManager when the node hierarchy changes.
+   */
+  void NodeHierarchyChanged()
+  {
+    mNodeHierarchyChanged = true;
+  }
+
 private:
 
   // From PropertyOwner::Observer
@@ -108,14 +118,36 @@ private:
 
   struct FrameCallbackInfo
   {
-    FrameCallbackInterface* frameCallback;
-    UpdateProxy* updateProxyImpl;
+    /**
+     * Default Constructor
+     * @param[in]  frameCallbackObject  A pointer to the frame-callback object
+     * @param[in]  updateProxyPtr       A raw pointer to the newly created updateProxy
+     * @note Ownership of @updateProxyPtr is passed to this class.
+     */
+    FrameCallbackInfo( FrameCallbackInterface* frameCallbackObject, UpdateProxy* updateProxyPtr )
+    : frameCallback( frameCallbackObject ),
+      updateProxyImpl( updateProxyPtr )
+    {
+    }
+
+    ~FrameCallbackInfo() = default; ///< Default destructor.
+
+    // Movable but not copyable
+    FrameCallbackInfo( const FrameCallbackInfo& )            = delete;  ///< Deleted copy constructor.
+    FrameCallbackInfo( FrameCallbackInfo&& )                 = default; ///< Default move constructor.
+    FrameCallbackInfo& operator=( const FrameCallbackInfo& ) = delete;  ///< Deleted copy assignment operator.
+    FrameCallbackInfo& operator=( FrameCallbackInfo&& )      = default; ///< Default move assignment operator.
+
+    // Data
+    FrameCallbackInterface* frameCallback{ nullptr }; ///< Pointer to the implementation of the FrameCallbackInterface.
+    std::unique_ptr< UpdateProxy > updateProxyImpl{ nullptr }; ///< A unique pointer to the implementation of the UpdateProxy.
   };
 
-  std::vector< FrameCallbackInfo > mFrameCallbacks;
+  std::vector< FrameCallbackInfo > mFrameCallbacks; ///< A container of all the frame-callbacks & accompanying update-proxies.
 
   TransformManager& mTransformManager;
-  Node& mRootNode;
+
+  bool mNodeHierarchyChanged; ///< Set to true if the node hierarchy changes
 };
 
 } // namespace SceneGraph