Merge "Added memory pool logging" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / node.h
index 6026c00..be26b7a 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_NODE_H
 
 /*
- * Copyright (c) 2021 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.
@@ -30,6 +30,8 @@
 #include <dali/internal/update/manager/transform-manager-property.h>
 #include <dali/internal/update/manager/transform-manager.h>
 #include <dali/internal/update/nodes/node-declarations.h>
+#include <dali/internal/update/nodes/node-helper.h>
+#include <dali/internal/update/nodes/partial-rendering-data.h>
 #include <dali/internal/update/rendering/scene-graph-renderer.h>
 #include <dali/public-api/actors/actor-enumerations.h>
 #include <dali/public-api/actors/draw-mode.h>
@@ -57,6 +59,7 @@ class DiscardQueue;
 class Layer;
 class RenderTask;
 class UpdateManager;
+class Node;
 
 // Flags which require the scene renderable lists to be updated
 static NodePropertyFlags RenderableUpdateFlags = NodePropertyFlags::TRANSFORM | NodePropertyFlags::CHILD_DELETED;
@@ -103,7 +106,7 @@ public:
    * Query whether the node is a layer.
    * @return True if the node is a layer.
    */
-  bool IsLayer()
+  bool IsLayer() const
   {
     return mIsLayer;
   }
@@ -117,18 +120,29 @@ public:
     return nullptr;
   }
 
+  // Camera interface
+
+  /**
+   * Query whether the node is a camera.
+   * @return True if the node is a camera.
+   */
+  bool IsCamera() const
+  {
+    return mIsCamera;
+  }
+
   /**
    * Mark an node and its sub tree according to the updated flag.
    * @param[in] updated The updated flag
    * (used for partial rendering to mark an animating sub tree for example).
    */
-  void SetUpdated(bool updated) override
+  void SetUpdatedTree(bool updated)
   {
     mUpdated = updated;
 
     for(Node* child : mChildren)
     {
-      child->SetUpdated(updated);
+      child->SetUpdatedTree(updated);
     }
   }
 
@@ -199,6 +213,7 @@ public:
   void SetClippingMode(const ClippingMode::Type clippingMode)
   {
     mClippingMode = clippingMode;
+    SetDirtyFlag(NodePropertyFlags::TRANSFORM);
   }
 
   /**
@@ -360,7 +375,12 @@ public:
    */
   const Vector3& GetParentOrigin() const
   {
-    return mParentOrigin.Get(0);
+    if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
+    {
+      return mParentOrigin.Get(0);
+    }
+
+    return Vector3::ZERO;
   }
 
   /**
@@ -378,7 +398,12 @@ public:
    */
   const Vector3& GetAnchorPoint() const
   {
-    return mAnchorPoint.Get(0);
+    if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
+    {
+      return mAnchorPoint.Get(0);
+    }
+
+    return Vector3::ZERO;
   }
 
   /**
@@ -411,7 +436,11 @@ public:
    */
   const Vector3& GetWorldPosition(BufferIndex bufferIndex) const
   {
-    return mWorldPosition.Get(bufferIndex);
+    if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
+    {
+      return mWorldPosition.Get(bufferIndex);
+    }
+    return Vector3::ZERO;
   }
 
   /**
@@ -448,7 +477,11 @@ public:
    */
   const Quaternion& GetWorldOrientation(BufferIndex bufferIndex) const
   {
-    return mWorldOrientation.Get(0);
+    if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
+    {
+      return mWorldOrientation.Get(0);
+    }
+    return Quaternion::IDENTITY;
   }
 
   /**
@@ -485,7 +518,11 @@ public:
    */
   const Vector3& GetWorldScale(BufferIndex bufferIndex) const
   {
-    return mWorldScale.Get(0);
+    if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
+    {
+      return mWorldScale.Get(0);
+    }
+    return Vector3::ONE;
   }
 
   /**
@@ -629,17 +666,17 @@ public:
   }
 
   /**
-   * Retrieve the update size hint of the node.
-   * @return The update size hint.
+   * Retrieve the update area hint of the node.
+   * @return The update area hint.
    */
-  const Vector3& GetUpdateSizeHint() const
+  const Vector4& GetUpdateAreaHint() const
   {
     if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
     {
-      return mUpdateSizeHint.Get(0);
+      return mUpdateAreaHint.Get(0);
     }
 
-    return Vector3::ZERO;
+    return Vector4::ZERO;
   }
 
   /**
@@ -686,7 +723,12 @@ public:
    */
   const Matrix& GetWorldMatrix(BufferIndex bufferIndex) const
   {
-    return mWorldMatrix.Get(bufferIndex);
+    if(mTransformManagerData.Id() != INVALID_TRANSFORM_ID)
+    {
+      return mWorldMatrix.Get(bufferIndex);
+    }
+
+    return Matrix::IDENTITY;
   }
 
   /**
@@ -725,6 +767,16 @@ public:
     return mDrawMode;
   }
 
+  void SetTransparent(bool transparent)
+  {
+    mTransparent = transparent;
+  }
+
+  bool IsTransparent() const
+  {
+    return mTransparent;
+  }
+
   /*
    * Returns the transform id of the node
    * @return The transform component id of the node
@@ -749,7 +801,12 @@ public:
    */
   void SetDepthIndex(uint32_t depthIndex)
   {
-    mDepthIndex = depthIndex;
+    if(depthIndex != mDepthIndex)
+    {
+      SetDirtyFlag(NodePropertyFlags::DEPTH_INDEX);
+      SetUpdated(true);
+      mDepthIndex = depthIndex;
+    }
   }
 
   /**
@@ -794,30 +851,30 @@ public:
     return mCulled[bufferIndex];
   }
 
-public:
   /**
-   * @copydoc UniformMap::Add
+   * @brief Get the total capacity of the memory pools
+   * @return The capacity of the memory pools
+   *
+   * @note This is different to the node count.
    */
-  void AddUniformMapping(const UniformPropertyMapping& map) override;
+  static uint32_t GetMemoryPoolCapacity();
 
   /**
-   * @copydoc UniformMap::Remove
+   * @brief Returns partial rendering data associated with the node.
+   * @return The partial rendering data
    */
-  void RemoveUniformMapping(const ConstString& uniformName) override;
+  PartialRenderingData& GetPartialRenderingData()
+  {
+    return mPartialRenderingData;
+  }
 
+public:
   /**
    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::IsAnimationPossible
    */
   bool IsAnimationPossible() const override;
 
   /**
-   * Prepare the node for rendering.
-   * This is called by the UpdateManager when an object is due to be rendered in the current frame.
-   * @param[in] updateBufferIndex The current update buffer index.
-   */
-  void PrepareRender(BufferIndex bufferIndex);
-
-  /**
    * Called by UpdateManager when the node is added.
    * Creates a new transform component in the transform manager and initialize all the properties
    * related to the transformation
@@ -830,6 +887,12 @@ public:
    */
   void ResetDirtyFlags(BufferIndex updateBufferIndex);
 
+  /**
+   * Update uniform hash
+   * @param[in] bufferIndex The buffer to read from.
+   */
+  void UpdateUniformHash(BufferIndex bufferIndex);
+
 protected:
   /**
    * Set the parent of a Node.
@@ -851,14 +914,6 @@ protected:
 
 private: // from NodeDataProvider
   /**
-   * @copydoc NodeDataProvider::GetModelMatrix
-   */
-  const Matrix& GetModelMatrix(BufferIndex bufferIndex) const override
-  {
-    return GetWorldMatrix(bufferIndex);
-  }
-
-  /**
    * @copydoc NodeDataProvider::GetRenderColor
    */
   const Vector4& GetRenderColor(BufferIndex bufferIndex) const override
@@ -866,29 +921,20 @@ private: // from NodeDataProvider
     return GetWorldColor(bufferIndex);
   }
 
-public: // From UniformMapDataProvider
-  /**
-   * @copydoc UniformMapDataProvider::GetUniformMapChanged
-   */
-  bool GetUniformMapChanged(BufferIndex bufferIndex) const override
-  {
-    return mUniformMapChanged[bufferIndex];
-  }
-
   /**
-   * @copydoc UniformMapDataProvider::GetUniformMap
+   * @copydoc NodeDataProvider::GetNodeUniformMap
    */
-  const CollectedUniformMap& GetUniformMap(BufferIndex bufferIndex) const override
+  const UniformMap& GetNodeUniformMap() const override
   {
-    return mCollectedUniformMap[bufferIndex];
+    return GetUniformMap();
   }
 
 private:
-  // Undefined
-  Node(const Node&);
-
-  // Undefined
-  Node& operator=(const Node& rhs);
+  // Delete copy and move
+  Node(const Node&)                = delete;
+  Node(Node&&)                     = delete;
+  Node& operator=(const Node& rhs) = delete;
+  Node& operator=(Node&& rhs)      = delete;
 
   /**
    * Recursive helper to disconnect a Node and its children.
@@ -898,39 +944,48 @@ private:
   void RecursiveDisconnectFromSceneGraph(BufferIndex updateBufferIndex);
 
 public: // Default properties
-  using TransformManagerParentsOrigin = TransformManagerPropertyVector3<TRANSFORM_PROPERTY_PARENT_ORIGIN>;
-  using TransformManagerAnchorPoint   = TransformManagerPropertyVector3<TRANSFORM_PROPERTY_ANCHOR_POINT>;
-  using TransformManagerSize          = TransformManagerPropertyVector3<TRANSFORM_PROPERTY_SIZE>;
-  using TransformManagerPosition      = TransformManagerPropertyVector3<TRANSFORM_PROPERTY_POSITION>;
-  using TransformManagerScale         = TransformManagerPropertyVector3<TRANSFORM_PROPERTY_SCALE>;
-
-  TransformManagerData               mTransformManagerData;
-  TransformManagerParentsOrigin      mParentOrigin; ///< Local transform; the position is relative to this. Sets the Transform flag dirty when changed
-  TransformManagerAnchorPoint        mAnchorPoint;  ///< Local transform; local center of rotation. Sets the Transform flag dirty when changed
-  TransformManagerSize               mSize;         ///< Size is provided for layouting
-  TransformManagerPosition           mPosition;     ///< Local transform; distance between parent-origin & anchor-point
-  TransformManagerScale              mScale;        ///< Local transform; scale relative to parent node
-  TransformManagerPropertyQuaternion mOrientation;  ///< Local transform; rotation relative to parent node
+  // Define a base offset for the following wrappers. The wrapper macros calculate offsets from the previous
+  // element such that each wrapper type generates a compile time offset to the transform manager data.
+  BASE(TransformManagerData, mTransformManagerData);
+  PROPERTY_WRAPPER(mTransformManagerData, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_PARENT_ORIGIN,
+                   mParentOrigin); // Local transform; the position is relative to this. Sets the Transform flag dirty when changed
 
-  AnimatableProperty<bool>    mVisible;        ///< Visibility can be inherited from the Node hierachy
-  AnimatableProperty<bool>    mCulled;         ///< True if the node is culled. This is not animatable. It is just double-buffered.
-  AnimatableProperty<Vector4> mColor;          ///< Color can be inherited from the Node hierarchy
-  AnimatableProperty<Vector3> mUpdateSizeHint; ///< Update size hint is provided for damaged area calculation. This is not animatable. It is just double-buffered. (Because all these bloody properties are).
+  PROPERTY_WRAPPER(mParentOrigin, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_ANCHOR_POINT,
+                   mAnchorPoint); // Local transform; local center of rotation. Sets the Transform flag dirty when changed
+
+  PROPERTY_WRAPPER(mAnchorPoint, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_SIZE,
+                   mSize); // Size is provided for layouting
+
+  PROPERTY_WRAPPER(mSize, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_POSITION,
+                   mPosition); // Local transform; distance between parent-origin & anchor-point
+  PROPERTY_WRAPPER(mPosition, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_SCALE,
+                   mScale); // Local transform; scale relative to parent node
+
+  TEMPLATE_WRAPPER(mScale, TransformManagerPropertyQuaternion,
+                   mOrientation); // Local transform; rotation relative to parent node
 
   // Inherited properties; read-only from public API
+  TEMPLATE_WRAPPER(mOrientation, TransformManagerVector3Input, mWorldPosition);      // Full inherited position
+  TEMPLATE_WRAPPER(mWorldPosition, TransformManagerVector3Input, mWorldScale);       // Full inherited scale
+  TEMPLATE_WRAPPER(mWorldScale, TransformManagerQuaternionInput, mWorldOrientation); // Full inherited orientation
+  TEMPLATE_WRAPPER(mWorldOrientation, TransformManagerMatrixInput, mWorldMatrix);    // Full inherited world matrix
 
-  TransformManagerVector3Input    mWorldPosition; ///< Full inherited position
-  TransformManagerVector3Input    mWorldScale;
-  TransformManagerQuaternionInput mWorldOrientation; ///< Full inherited orientation
-  TransformManagerMatrixInput     mWorldMatrix;      ///< Full inherited world matrix
-  InheritedColor                  mWorldColor;       ///< Full inherited color
+  AnimatableProperty<bool>    mVisible;        ///< Visibility can be inherited from the Node hierachy
+  AnimatableProperty<bool>    mCulled;         ///< True if the node is culled. This is not animatable. It is just double-buffered.
+  AnimatableProperty<Vector4> mColor;          ///< Color can be inherited from the Node hierarchy
+  InheritedColor              mWorldColor;     ///< Full inherited color
+  AnimatableProperty<Vector4> mUpdateAreaHint; ///< Update area hint is provided for damaged area calculation. (x, y, width, height)
+                                               ///< This is not animatable. It is just double-buffered. (Because all these bloody properties are).
 
+  uint64_t       mUniformsHash{0u};     ///< Hash of uniform map property values
   uint32_t       mClippingSortModifier; ///< Contains bit-packed clipping information for quick access when sorting
   const uint32_t mId;                   ///< The Unique ID of the node.
 
 protected:
   static uint32_t mNodeCounter; ///< count of total nodes, used for unique ids
 
+  PartialRenderingData mPartialRenderingData; ///< Cache to determine if this should be rendered again
+
   Node*       mParent;              ///< Pointer to parent node (a child is owned by its parent)
   RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask
 
@@ -938,22 +993,20 @@ protected:
 
   NodeContainer mChildren; ///< Container of children; not owned
 
-  CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps of the node
-  uint32_t            mUniformMapChanged[2];   ///< Records if the uniform map has been altered this frame
-  uint32_t            mClippingDepth;          ///< The number of stencil clipping nodes deep this node is
-  uint32_t            mScissorDepth;           ///< The number of scissor clipping nodes deep this node is
-
-  uint32_t mDepthIndex; ///< Depth index of the node
+  uint32_t mClippingDepth; ///< The number of stencil clipping nodes deep this node is
+  uint32_t mScissorDepth;  ///< The number of scissor clipping nodes deep this node is
+  uint32_t mDepthIndex;    ///< Depth index of the node
 
   // flags, compressed to bitfield
   NodePropertyFlags  mDirtyFlags;                  ///< Dirty flags for each of the Node properties
-  uint32_t           mRegenerateUniformMap : 2;    ///< Indicate if the uniform map has to be regenerated this frame
   DrawMode::Type     mDrawMode : 3;                ///< How the Node and its children should be drawn
   ColorMode          mColorMode : 3;               ///< Determines whether mWorldColor is inherited, 2 bits is enough
   ClippingMode::Type mClippingMode : 3;            ///< The clipping mode of this node
   bool               mIsRoot : 1;                  ///< True if the node cannot have a parent
   bool               mIsLayer : 1;                 ///< True if the node is a layer
+  bool               mIsCamera : 1;                ///< True if the node is a camera
   bool               mPositionUsesAnchorPoint : 1; ///< True if the node should use the anchor-point when calculating the position
+  bool               mTransparent : 1;             ///< True if this node is transparent. This value do not affect children.
 
   // Changes scope, should be at end of class
   DALI_LOG_OBJECT_STRING_DECLARATION;
@@ -1038,15 +1091,15 @@ inline void SetDrawModeMessage(EventThreadServices& eventThreadServices, const N
   new(slot) LocalType(&node, &Node::SetDrawMode, drawMode);
 }
 
-inline void AttachRendererMessage(EventThreadServices& eventThreadServices, const Node& node, const Renderer& renderer)
+inline void SetTransparentMessage(EventThreadServices& eventThreadServices, const Node& node, bool transparent)
 {
-  using LocalType = MessageValue1<Node, Renderer*>;
+  using LocalType = MessageValue1<Node, bool>;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new(slot) LocalType(&node, &Node::AddRenderer, const_cast<Renderer*>(&renderer));
+  new(slot) LocalType(&node, &Node::SetTransparent, transparent);
 }
 
 inline void DetachRendererMessage(EventThreadServices& eventThreadServices, const Node& node, const Renderer& renderer)