Merge "Added memory pool logging" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-owner.h
index b3dfa12..f4329fa 100644 (file)
@@ -1,49 +1,43 @@
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
-
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-// EXTERNAL INCLUDES
-#include <set>
+#ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H
+#define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H
+
+/*
+ * Copyright (c) 2022 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/dali-vector.h>
+#include <dali/devel-api/common/owner-container.h>
+#include <dali/internal/common/const-string.h>
 #include <dali/internal/common/message.h>
-#include <dali/internal/common/owner-container.h>
+#include <dali/internal/update/animation/scene-graph-constraint-declarations.h>
 #include <dali/internal/update/common/property-base.h>
 #include <dali/internal/update/common/scene-graph-buffers.h>
-#include <dali/internal/update/animation/scene-graph-constraint-declarations.h>
+#include <dali/internal/update/common/uniform-map.h>
+#include <dali/public-api/common/dali-vector.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 namespace SceneGraph
 {
-
 class PropertyOwner;
 
-typedef std::set<PropertyOwner*>   PropertyOwnerSet;
-typedef PropertyOwnerSet::iterator PropertyOwnerIter;
-
-typedef OwnerContainer< PropertyBase* > OwnedPropertyContainer;
-typedef OwnedPropertyContainer::Iterator  OwnedPropertyIter;
+using OwnedPropertyContainer = OwnerContainer<PropertyBase*>;
+using OwnedPropertyIter      = OwnedPropertyContainer::Iterator;
 
 /**
  * An update-thread object which own properties.
@@ -52,15 +46,35 @@ typedef OwnedPropertyContainer::Iterator  OwnedPropertyIter;
 class PropertyOwner
 {
 public:
-
   class Observer
   {
   public:
+    /**
+     * Called when the observable object is connected to the scene graph.
+     * @param[in] owner A reference to the connected PropertyOwner
+     */
+    virtual void PropertyOwnerConnected(PropertyOwner& owner) = 0;
+
+    /**
+     * Called when the observable object is disconnected from the scene graph.
+     * @param[in] currentBufferIndex The buffer to reset.
+     * @param[in] owner A reference to the disconnected PropertyOwner
+     */
+    virtual void PropertyOwnerDisconnected(BufferIndex updateBufferIndex, PropertyOwner& owner) = 0;
 
     /**
      * Called shortly before the observable object is destroyed.
+     *
+     * @note Cleanup should be done in both this and PropertyOwnerDisconnected as PropertyOwnerDisconnected
+     * may not be called (i.e. when shutting down).
      */
-    virtual void PropertyOwnerDestroyed( PropertyOwner& owner ) = 0;
+    virtual void PropertyOwnerDestroyed(PropertyOwner& owner) = 0;
+
+  protected:
+    /**
+     * Virtual destructor, no deletion through this interface
+     */
+    virtual ~Observer() = default;
   };
 
   /**
@@ -96,17 +110,35 @@ public:
   bool IsObserved();
 
   /**
-   * Disconnect all observers and remove constraints.
+   * Called just before destruction to disconnect all observers and remove constraints.
+   * This occurs when the object is in the process of being destroyed.
+   */
+  void Destroy();
+
+  /**
+   * Notify all observers that the object has been connected
+   * This occurs when the object is connected to the scene-graph during UpdateManager::Update().
+   */
+  void ConnectToSceneGraph();
+
+  /**
+   * Notify all observers that the object has been disconnected and remove constraints.
    * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
+   * @param[in] currentBufferIndex The current update buffer.
    */
-  void DisconnectFromSceneGraph();
+  void DisconnectFromSceneGraph(BufferIndex updateBufferIndex);
+
+  /**
+   * Reserve the given number of properties
+   */
+  void ReserveProperties(int propertyCount);
 
   /**
    * Install a custom property.
    * @post The PropertyOwner takes ownership of the property.
    * @param[in] property A pointer to a newly allocated property.
    */
-  void InstallCustomProperty(PropertyBase* property);
+  void InstallCustomProperty(OwnerPointer<PropertyBase>& property);
 
   /**
    * Retrieve the custom properties owned by the object.
@@ -127,11 +159,22 @@ public:
   }
 
   /**
-   * Reset animatable properties to the corresponding base values.
-   * @param[in] currentBufferIndex The buffer to reset.
-   * @post The ResetDefaultProperties method is called, during which derived classes can reset default properties.
+   * Mark an property owner with the updated flag.
+   * @param[in] updated The updated flag
+   */
+  void SetUpdated(bool updated)
+  {
+    mUpdated = updated;
+  }
+
+  /**
+   * Retrieve if the property owner is updated due to the property is being animating.
+   * @return An updated flag
    */
-  void ResetToBaseValues( BufferIndex updateBufferIndex );
+  bool Updated() const
+  {
+    return mUpdated;
+  }
 
   // Constraints
 
@@ -139,13 +182,13 @@ public:
    * Apply a constraint.
    * @param[in] constraint The constraint to apply.
    */
-  void ApplyConstraint( ConstraintBase* constraint );
+  void ApplyConstraint(OwnerPointer<ConstraintBase>& constraint);
 
   /**
    * Begin removal of constraints.
    * @param[in] constraint The constraint to remove.
    */
-  void RemoveConstraint( ConstraintBase* constraint );
+  void RemoveConstraint(ConstraintBase* constraint);
 
   /**
    * Retrieve the constraints that are currently applied.
@@ -153,41 +196,67 @@ public:
    */
   ConstraintOwnerContainer& GetConstraints();
 
-protected:
+  /**
+   * @copydoc UniformMap::Add
+   */
+  virtual void AddUniformMapping(const UniformPropertyMapping& map);
+
+  /**
+   * @copydoc UniformMap::Remove
+   */
+  virtual void RemoveUniformMapping(const ConstString& uniformName);
+
+  /**
+   * Get the mappings table
+   */
+  const UniformMap& GetUniformMap() const;
 
   /**
+   * @copydoc UniformMap::AddUniformMapObserver
+   */
+  void AddUniformMapObserver(UniformMap::Observer& observer);
+
+  /**
+   * @copydoc UniformMap::RemoveUniformMapObserver
+   */
+  void RemoveUniformMapObserver(UniformMap::Observer& observer);
+
+  /**
+   * Query whether playing an animation is possible or not.
+   * @return true if playing an animation is possible.
+   */
+  virtual bool IsAnimationPossible() const
+  {
+    return true;
+  }
+
+protected:
+  /**
    * Protected constructor.
    */
   PropertyOwner();
 
 private:
-
   // Undefined
   PropertyOwner(const PropertyOwner&);
 
   // Undefined
   PropertyOwner& operator=(const PropertyOwner& rhs);
 
-  /**
-   * Called after ResetToBaseValues; derived classes should reset any default properties.
-   * @param[in] currentBufferIndex The buffer to reset.
-   */
-  virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ) {}
-
 protected:
-
   OwnedPropertyContainer mCustomProperties; ///< Properties provided with InstallCustomProperty()
+  UniformMap             mUniformMaps;      ///< Container of owned uniform maps
+  bool                   mUpdated;
+  bool                   mIsConnectedToSceneGraph;
 
 private:
-
-  typedef Dali::Vector<PropertyOwner::Observer*> ObserverContainer;
-  typedef ObserverContainer::Iterator ObserverIter;
-  typedef ObserverContainer::ConstIterator ConstObserverIter;
+  using ObserverContainer = Dali::Vector<PropertyOwner::Observer*>;
+  using ObserverIter      = ObserverContainer::Iterator;
+  using ConstObserverIter = ObserverContainer::ConstIterator;
 
   ObserverContainer mObservers; ///< Container of observer raw-pointers (not owned)
 
   ConstraintOwnerContainer mConstraints; ///< Container of owned constraints
-
 };
 
 } // namespace SceneGraph
@@ -196,4 +265,4 @@ private:
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
+#endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H