Level up Dali::Internal::FreeList as Dali::FreeList
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / transform-manager.h
index f259a13..97294e2 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_TRANSFORM_MANAGER_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * 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.
  */
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/common/free-list.h>
+#include <dali/public-api/common/constants.h>
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/math/matrix.h>
 #include <dali/public-api/math/quaternion.h>
 #include <dali/public-api/math/vector3.h>
-#include <dali/public-api/common/constants.h>
-#include <dali/internal/update/manager/free-list.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 namespace SceneGraph
 {
-
 /**
  * Struct to store the animatable part of a component (Scale, orientation and position)
  */
 struct TransformComponentAnimatable
 {
   TransformComponentAnimatable()
-  : mScale( Vector3::ONE ),
-    mOrientation( Quaternion::IDENTITY ),
-    mPosition( Vector3::ZERO )
+  : mScale(Vector3::ONE),
+    mOrientation(Quaternion::IDENTITY),
+    mPosition(Vector3::ZERO)
   {
   }
 
-  Vector3 mScale;
+  Vector3    mScale;
   Quaternion mOrientation;
-  Vector3 mPosition;
+  Vector3    mPosition;
 };
 
 /**
@@ -58,24 +55,24 @@ struct TransformComponentAnimatable
 struct TransformComponentStatic
 {
   TransformComponentStatic()
-  : mAnchorPoint( AnchorPoint::DEFAULT ),
-    mParentOrigin( ParentOrigin::DEFAULT ),
-    mPositionUsesAnchorPoint( true )
+  : mAnchorPoint(AnchorPoint::DEFAULT),
+    mParentOrigin(ParentOrigin::DEFAULT),
+    mPositionUsesAnchorPoint(true)
   {
   }
 
   Vector3 mAnchorPoint;
   Vector3 mParentOrigin;
-  bool mPositionUsesAnchorPoint;
+  bool    mPositionUsesAnchorPoint;
 };
 
 enum InheritanceMode
 {
-  DONT_INHERIT_TRANSFORM  = 0,
-  INHERIT_POSITION        = 1,
-  INHERIT_SCALE           = 2,
-  INHERIT_ORIENTATION     = 4,
-  INHERIT_ALL             = INHERIT_POSITION | INHERIT_SCALE | INHERIT_ORIENTATION,
+  DONT_INHERIT_TRANSFORM = 0,
+  INHERIT_POSITION       = 1,
+  INHERIT_SCALE          = 2,
+  INHERIT_ORIENTATION    = 4,
+  INHERIT_ALL            = INHERIT_POSITION | INHERIT_SCALE | INHERIT_ORIENTATION,
 };
 
 enum TransformManagerProperty
@@ -92,21 +89,44 @@ enum TransformManagerProperty
   TRANSFORM_PROPERTY_COUNT,
 };
 
-typedef unsigned int TransformId;
+using TransformId                             = uint32_t; // 4,294,967,295 transforms supported
 static const TransformId INVALID_TRANSFORM_ID = -1;
 
-} //SceneGraph
-} //Internal
+class TransformManager;
+
+struct TransformManagerData
+{
+  TransformManager* Manager() const
+  {
+    return mManager;
+  }
+
+  TransformId Id() const
+  {
+    return mId;
+  }
+
+  TransformManager* mManager{nullptr};
+  TransformId       mId{INVALID_TRANSFORM_ID};
+};
+
+} // namespace SceneGraph
+} // namespace Internal
 
 // Allow TransformComponentAnimatable to be treated as a POD type
-template <> struct TypeTraits< Dali::Internal::SceneGraph::TransformComponentAnimatable >: public Dali::BasicTypes< Dali::Internal::SceneGraph::TransformComponentAnimatable > { enum { IS_TRIVIAL_TYPE = true }; };
+template<>
+struct TypeTraits<Dali::Internal::SceneGraph::TransformComponentAnimatable> : public Dali::BasicTypes<Dali::Internal::SceneGraph::TransformComponentAnimatable>
+{
+  enum
+  {
+    IS_TRIVIAL_TYPE = true
+  };
+};
 
 namespace Internal
 {
-
 namespace SceneGraph
 {
-
 /**
  * Transform manager computes the local to world transformations
  * of all the nodes in the scene. All the transformation data is stored contiguously
@@ -115,7 +135,6 @@ namespace SceneGraph
 class TransformManager
 {
 public:
-
   /**
    * Default constructor
    */
@@ -143,28 +162,28 @@ public:
    * @param[in] id Id of the transform
    * @param[in] parentId Id of the new parent
    */
-  void SetParent( TransformId id, TransformId parentId );
+  void SetParent(TransformId id, TransformId parentId);
 
   /**
    * Gets the world transform matrix of an exisiting transform component
    * @param[in] id Id of the transform component
    * @return The local to world transformation matrix of the component
    */
-  const Matrix& GetWorldMatrix( TransformId id ) const;
+  const Matrix& GetWorldMatrix(TransformId id) const;
 
   /**
    * Gets the world transform matrix of an exisiting transform component
    * @param[in] id Id of the transform component
    * @return The local to world transformation matrix of the component
    */
-  Matrix& GetWorldMatrix( TransformId id );
+  Matrix& GetWorldMatrix(TransformId id);
 
   /**
    * Checks if the local transform was updated in the last Update
    * @param[in] id Id of the transform
    * @return true if local matrix changed in the last update, false otherwise
    */
-  bool IsLocalMatrixDirty( TransformId id ) const
+  bool IsLocalMatrixDirty(TransformId id) const
   {
     return mLocalMatrixDirty[mIds[id]];
   }
@@ -174,26 +193,27 @@ public:
    * @param[in] id Id of the transform
    * @param[in] inherit True if position is inherited from parent, false otherwise
    */
-  void SetInheritPosition( TransformId id, bool inherit );
+  void SetInheritPosition(TransformId id, bool inherit);
 
   /**
    * Sets scale inheritance mode.
    * @param[in] id Id of the transform
    * @param[in] inherit True if scale is inherited from parent, false otherwise
    */
-  void SetInheritScale( TransformId id, bool inherit );
+  void SetInheritScale(TransformId id, bool inherit);
 
   /**
    * Sets orientation inheritance mode.
    * @param[in] id Id of the transform
    * @param[in] inherit True if orientation is inherited from parent, false otherwise
    */
-  void SetInheritOrientation( TransformId id, bool inherit );
+  void SetInheritOrientation(TransformId id, bool inherit);
 
   /**
    * Recomputes all world transform matrices
+   * @return true if any component has been changed in this frame, false otherwise
    */
-  void Update();
+  bool Update();
 
   /**
    * Resets all the animatable properties to its base value
@@ -205,14 +225,14 @@ public:
    * @param[in] id Id of the transform component
    * @param[in] property The property
    */
-  Vector3& GetVector3PropertyValue( TransformId id, TransformManagerProperty property );
+  Vector3& GetVector3PropertyValue(TransformId id, TransformManagerProperty property);
 
   /**
    * Get the value of a Vector3 property
    * @param[in] id Id of the transform component
    * @param[in] property The property
    */
-  const Vector3& GetVector3PropertyValue( TransformId id, TransformManagerProperty property ) const;
+  const Vector3& GetVector3PropertyValue(TransformId id, TransformManagerProperty property) const;
 
   /**
    * Get the value of a component of Vector3 property
@@ -220,7 +240,7 @@ public:
    * @param[in] property The property
    * param[in] component The component (0,1,2)
    */
-  const float& GetVector3PropertyComponentValue(TransformId id, TransformManagerProperty property, unsigned int component ) const;
+  const float& GetVector3PropertyComponentValue(TransformId id, TransformManagerProperty property, uint32_t component) const;
 
   /**
    * Set the value of a Vector3 property
@@ -228,7 +248,7 @@ public:
    * @param[in] property The property
    * @param[in] value The new value
    */
-  void SetVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value );
+  void SetVector3PropertyValue(TransformId id, TransformManagerProperty property, const Vector3& value);
 
   /**
    * Set the value of a component of a Vector3 property
@@ -237,7 +257,7 @@ public:
    * @param[in] value The new value
    * param[in] component The component (0,1,2)
    */
-  void SetVector3PropertyComponentValue( TransformId id, TransformManagerProperty property, float value, unsigned int component );
+  void SetVector3PropertyComponentValue(TransformId id, TransformManagerProperty property, float value, uint32_t component);
 
   /**
    * Bakes the value of a Vector3 property
@@ -245,7 +265,7 @@ public:
    * @param[in] property The property
    * @param[in] value The new value
    */
-  void BakeVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value );
+  void BakeVector3PropertyValue(TransformId id, TransformManagerProperty property, const Vector3& value);
 
   /**
    * Bakes the value of a Vector3 property relative to the current value
@@ -253,7 +273,7 @@ public:
    * @param[in] property The property
    * @param[in] value The new value
    */
-  void BakeRelativeVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value );
+  void BakeRelativeVector3PropertyValue(TransformId id, TransformManagerProperty property, const Vector3& value);
 
   /**
    * Bakes the value of a Vector3 property by multiplying the current value and the new value
@@ -261,7 +281,7 @@ public:
    * @param[in] property The property
    * @param[in] value The new value
    */
-  void BakeMultiplyVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value );
+  void BakeMultiplyVector3PropertyValue(TransformId id, TransformManagerProperty property, const Vector3& value);
 
   /**
    * Bakes the value of a component of Vector3 property
@@ -269,7 +289,7 @@ public:
    * @param[in] property The property
    * @param[in] value The new value
    */
-  void BakeVector3PropertyComponentValue( TransformId id, TransformManagerProperty property, float value, unsigned int component );
+  void BakeVector3PropertyComponentValue(TransformId id, TransformManagerProperty property, float value, uint32_t component);
 
   /**
    * Bakes the value of the x component of Vector3 property
@@ -277,7 +297,7 @@ public:
    * @param[in] property The property
    * @param[in] value The new value
    */
-  void BakeXVector3PropertyValue( TransformId id, TransformManagerProperty property, float value );
+  void BakeXVector3PropertyValue(TransformId id, TransformManagerProperty property, float value);
 
   /**
    * Bakes the value of the y component of Vector3 property
@@ -285,7 +305,7 @@ public:
    * @param[in] property The property
    * @param[in] value The new value
    */
-  void BakeYVector3PropertyValue( TransformId id, TransformManagerProperty property, float value );
+  void BakeYVector3PropertyValue(TransformId id, TransformManagerProperty property, float value);
 
   /**
    * Bakes the value of the z component of Vector3 property
@@ -293,47 +313,47 @@ public:
    * @param[in] property The property
    * @param[in] value The new value
    */
-  void BakeZVector3PropertyValue( TransformId id, TransformManagerProperty property, float value );
+  void BakeZVector3PropertyValue(TransformId id, TransformManagerProperty property, float value);
 
   /**
    * Get the value of a quaternion property
    * @param[in] id Id of the transform component
    */
-  Quaternion& GetQuaternionPropertyValue( TransformId id );
+  Quaternion& GetQuaternionPropertyValue(TransformId id);
 
   /**
    * Get the value of a quaternion property
    * @param[in] id Id of the transform component
    */
-  const Quaternion& GetQuaternionPropertyValue( TransformId id ) const;
+  const Quaternion& GetQuaternionPropertyValue(TransformId id) const;
 
   /**
    * Set the value of a quaternion property
    * @param[in] id Id of the transform component
    * @param[in] q The new value
    */
-  void SetQuaternionPropertyValue( TransformId id, const Quaternion& q );
+  void SetQuaternionPropertyValue(TransformId id, const Quaternion& q);
 
   /**
    * Bake the value of a quaternion property
    * @param[in] id Id of the transform component
    * @param[in] q The new value
    */
-  void BakeQuaternionPropertyValue( TransformId id, const Quaternion& q );
+  void BakeQuaternionPropertyValue(TransformId id, const Quaternion& q);
 
   /**
    * Bake the value of a quaternion property relative to its current value
    * @param[in] id Id of the transform component
    * @param[in] q The new value
    */
-  void BakeRelativeQuaternionPropertyValue( TransformId id, const Quaternion& q );
+  void BakeRelativeQuaternionPropertyValue(TransformId id, const Quaternion& q);
 
   /**
    * Get the bounding sphere, in world coordinates, of a given component
    * @param[in] id Id of the transform component
    * @return The world space bounding sphere of the component
    */
-  const Vector4& GetBoundingSphere( TransformId id ) const;
+  const Vector4& GetBoundingSphere(TransformId id) const;
 
   /**
    * Get the world matrix and size of a given component
@@ -341,24 +361,34 @@ public:
    * @param[out] The world matrix of the component
    * @param[out] size size of the component
    */
-  void GetWorldMatrixAndSize( TransformId id, Matrix& worldMatrix, Vector3& size ) const;
+  void GetWorldMatrixAndSize(TransformId id, Matrix& worldMatrix, Vector3& size) const;
 
   /**
    * @brief Sets the boolean which states whether the position should use the anchor-point on the given transform component.
    * @param[in] id Id of the transform component
    * @param[in] value True if the position should use the anchor-point
    */
-  void SetPositionUsesAnchorPoint( TransformId id, bool value );
+  void SetPositionUsesAnchorPoint(TransformId id, bool value);
 
 private:
-
   //Helper struct to order components
   struct SOrderItem
   {
-    bool operator<(const SOrderItem& item) const {return level < item.level;}
-
-    TransformId  id;
-    unsigned int level;
+    bool operator<(const SOrderItem& item) const
+    {
+      if(sceneId != item.sceneId)
+      {
+        return sceneId < item.sceneId;
+      }
+      else
+      {
+        return level < item.level;
+      }
+    }
+
+    TransformId id;
+    uint16_t    sceneId;
+    uint16_t    level;
   };
 
   /**
@@ -366,39 +396,38 @@ private:
    * @param[in] i Index of a component
    * @param[in] j Index of a component
    */
-  void SwapComponents( unsigned int i, unsigned int j );
+  void SwapComponents(uint32_t i, uint32_t j);
 
   /**
    * Reorders components in hierarchical order so update can iterate sequentially
-   * updating the world transforms
+   * updating the world transforms. The components are sorted in the breadth first
+   * order for each scene and grouped per scene.
    */
   void ReorderComponents();
 
-  unsigned int mComponentCount;                                            ///< Total number of components
-  FreeList mIds;                                                           ///< FreeList of Ids
-  Vector< TransformComponentAnimatable > mTxComponentAnimatable;           ///< Animatable part of the components
-  Vector< TransformComponentStatic > mTxComponentStatic;                   ///< Static part of the components
-  Vector< unsigned int > mInheritanceMode;                                 ///< Inheritance mode of the components
-  Vector< TransformId > mComponentId;                                      ///< Ids of the components
-  Vector< Vector3 > mSize;                                                 ///< Size of the components
-  Vector< TransformId > mParent;                                           ///< Parent of the components
-  Vector< Matrix > mWorld;                                                 ///< Local to world transform of the components
-  Vector< Matrix > mLocal;                                                 ///< Local to parent space transform of the components
-  Vector< Vector4 > mBoundingSpheres;                                      ///< Bounding spheres. xyz is the center and w is the radius
-  Vector< TransformComponentAnimatable > mTxComponentAnimatableBaseValue;  ///< Base values for the animatable part of the components
-  Vector< Vector3 > mSizeBase;                                             ///< Base value for the size of the components
-  Vector< bool > mComponentDirty;                                          ///< 1u if some of the parts of the component has changed in this frame, 0 otherwise
-  Vector< bool > mLocalMatrixDirty;                                        ///< 1u if the local matrix has been updated in this frame, 0 otherwise
-  Vector< SOrderItem > mOrderedComponents;                                 ///< Used to reorder components when hierarchy changes
-  bool mReorder;                                                           ///< Flag to determine if the components have to reordered in the next Update
+  uint32_t                             mComponentCount;                 ///< Total number of components
+  FreeList                             mIds;                            ///< FreeList of Ids
+  Vector<TransformComponentAnimatable> mTxComponentAnimatable;          ///< Animatable part of the components
+  Vector<TransformComponentStatic>     mTxComponentStatic;              ///< Static part of the components
+  Vector<uint32_t>                     mInheritanceMode;                ///< Inheritance mode of the components
+  Vector<TransformId>                  mComponentId;                    ///< Ids of the components
+  Vector<Vector3>                      mSize;                           ///< Size of the components
+  Vector<TransformId>                  mParent;                         ///< Parent of the components
+  Vector<Matrix>                       mWorld;                          ///< Local to world transform of the components
+  Vector<Matrix>                       mLocal;                          ///< Local to parent space transform of the components
+  Vector<Vector4>                      mBoundingSpheres;                ///< Bounding spheres. xyz is the center and w is the radius
+  Vector<TransformComponentAnimatable> mTxComponentAnimatableBaseValue; ///< Base values for the animatable part of the components
+  Vector<Vector3>                      mSizeBase;                       ///< Base value for the size of the components
+  Vector<bool>                         mComponentDirty;                 ///< 1u if some of the parts of the component has changed in this frame, 0 otherwise
+  Vector<bool>                         mLocalMatrixDirty;               ///< 1u if the local matrix has been updated in this frame, 0 otherwise
+  Vector<SOrderItem>                   mOrderedComponents;              ///< Used to reorder components when hierarchy changes
+  bool                                 mReorder;                        ///< Flag to determine if the components have to reordered in the next Update
 };
 
 } //namespace SceneGraph
 
 } //namespace Internal
 
-
 } //namespace Dali
 
-
 #endif // DALI_INTERNAL_TRANSFORM_MANAGER_H