Ensure a FrameCallback is removed properly from a FrameCallbackInterface
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / scene-graph-frame-callback.h
index ae801da..4d3a061 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_FRAME_CALLBACK_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 namespace SceneGraph
 {
-
 class Node;
 class TransformManager;
 
@@ -47,32 +44,32 @@ class TransformManager;
 class FrameCallback final : public PropertyOwner::Observer
 {
 public:
-
   /**
    * Creates a new FrameCallback.
    * @param[in]  frameCallbackInterface  A reference to the FrameCallbackInterface implementation
    * @return A new FrameCallback.
    */
-  static FrameCallback* New( FrameCallbackInterface& frameCallbackInterface );
+  static FrameCallback* New(FrameCallbackInterface& frameCallbackInterface);
 
   /**
    * Non-virtual Destructor.
    */
-  ~FrameCallback();
+  ~FrameCallback() override;
 
   /**
    * Called from the update-thread when connecting to the scene-graph.
-   * @param[in]  transformManager  The transform Manager
+   * @param[in]  updateManager     The Update Manager
+   * @param[in]  transformManager  The Transform Manager
    * @param[in]  rootNode          The rootNode of this frame-callback
    */
-  void ConnectToSceneGraph( TransformManager& transformManager, Node& rootNode );
+  void ConnectToSceneGraph(UpdateManager& updateManager, TransformManager& transformManager, Node& rootNode);
 
   // Movable but not copyable
 
-  FrameCallback( const FrameCallback& )            = delete;  ///< Deleted copy constructor.
-  FrameCallback( FrameCallback&& )                 = default; ///< Default move constructor.
-  FrameCallback& operator=( const FrameCallback& ) = delete;  ///< Deleted copy assignment operator.
-  FrameCallback& operator=( FrameCallback&& )      = default; ///< Default move assignment operator.
+  FrameCallback(const FrameCallback&) = delete;            ///< Deleted copy constructor.
+  FrameCallback(FrameCallback&&)      = default;           ///< Default move constructor.
+  FrameCallback& operator=(const FrameCallback&) = delete; ///< Deleted copy assignment operator.
+  FrameCallback& operator=(FrameCallback&&) = default;     ///< Default move assignment operator.
 
   /**
    * Called from the update-thread after the scene has been updated, and is ready to render.
@@ -81,7 +78,7 @@ public:
    * @param[in]  nodeHierarchyChanged  Whether the node hierarchy has changed
    * @return Whether to continue calling this FrameCallback or not.
    */
-  bool Update( BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged );
+  bool Update(BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged);
 
   /**
    * Invalidates this FrameCallback and will no longer be associated with the FrameCallbackInterface.
@@ -94,31 +91,34 @@ public:
    * @param[in]  iFace  The FrameCallbackInterface pointer to compare with
    * @return True if iFace matches our internally stored FrameCallbackInterface.
    */
-  inline bool operator==( const FrameCallbackInterface* iFace )
+  inline bool operator==(const FrameCallbackInterface* iFace)
   {
     return mFrameCallbackInterface == iFace;
   }
 
 private:
-
   // From PropertyOwner::Observer
 
   /**
    * @copydoc PropertyOwner::Observer::PropertyOwnerConnected()
    */
-  virtual void PropertyOwnerConnected( PropertyOwner& owner ) { /* Nothing to do */ }
+  void PropertyOwnerConnected(PropertyOwner& owner) override
+  { /* Nothing to do */
+  }
 
   /**
    * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
    */
-  virtual void PropertyOwnerDisconnected( BufferIndex updateBufferIndex, PropertyOwner& owner ) { /* Nothing to do */ }
+  void PropertyOwnerDisconnected(BufferIndex updateBufferIndex, PropertyOwner& owner) override
+  { /* Nothing to do */
+  }
 
   /**
    * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
    *
    * Will use this to disconnect the frame-callback if the accompanying node is destroyed
    */
-  virtual void PropertyOwnerDestroyed( PropertyOwner& owner );
+  void PropertyOwnerDestroyed(PropertyOwner& owner) override;
 
   // Construction
 
@@ -126,13 +126,13 @@ private:
    * Constructor.
    * @param[in]  frameCallbackInterface  A pointer to the FrameCallbackInterface implementation
    */
-  FrameCallback( FrameCallbackInterface* frameCallbackInterface );
+  FrameCallback(FrameCallbackInterface* frameCallbackInterface);
 
 private:
-
-  Mutex mMutex;
-  std::unique_ptr< UpdateProxy > mUpdateProxy{ nullptr }; ///< A unique pointer to the implementation of the UpdateProxy.
-  FrameCallbackInterface* mFrameCallbackInterface;
+  Mutex                        mMutex;
+  std::unique_ptr<UpdateProxy> mUpdateProxy{nullptr}; ///< A unique pointer to the implementation of the UpdateProxy.
+  FrameCallbackInterface*      mFrameCallbackInterface;
+  bool                         mValid{true}; ///< Set to false when Invalidate() is called.
 };
 
 /**
@@ -141,7 +141,7 @@ private:
  * @param[in]  iFace          The FrameCallbackInterface pointer
  * @return True if iFace matches the internally stored FrameCallbackInterface.
  */
-inline bool operator==( const OwnerPointer< FrameCallback >& frameCallback, const FrameCallbackInterface* iFace )
+inline bool operator==(const OwnerPointer<FrameCallback>& frameCallback, const FrameCallbackInterface* iFace)
 {
   return *frameCallback == iFace;
 }