[3.0] Added sibling order property to Actor
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / node.h
index 3f8bbac..01bc76f 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
+#ifndef DALI_INTERNAL_SCENE_GRAPH_NODE_H
+#define DALI_INTERNAL_SCENE_GRAPH_NODE_H
 
 /*
  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
@@ -45,9 +45,10 @@ namespace Dali
 namespace Internal
 {
 
-// value types used by messages
+// Value types used by messages.
 template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {};
 template <> struct ParameterType< PositionInheritanceMode > : public BasicType< PositionInheritanceMode > {};
+template <> struct ParameterType< ClippingMode::Type > : public BasicType< ClippingMode::Type > {};
 
 namespace SceneGraph
 {
@@ -56,7 +57,6 @@ class DiscardQueue;
 class Layer;
 class RenderTask;
 class UpdateManager;
-class GeometryBatcher;
 
 /**
  * Flag whether property has changed, during the Update phase.
@@ -70,7 +70,7 @@ enum NodePropertyFlags
   SizeFlag             = 0x008,
   OverlayFlag          = 0x010,
   SortModifierFlag     = 0x020,
-  ChildDeletedFlag     = 0x040
+  ChildDeletedFlag     = 0x040,
 };
 
 static const int AllFlags = ( ChildDeletedFlag << 1 ) - 1; // all the flags
@@ -143,10 +143,90 @@ public:
   }
 
   /**
+   * This method sets clipping information on the node based on its hierarchy in the scene-graph.
+   * A value is calculated that can be used during sorting to increase sort speed.
+   * @param[in] clippingId The Clipping ID of the node to set
+   * @param[in] clippingDepth The Clipping Depth of the node to set
+   */
+  void SetClippingInformation( const uint32_t clippingId, const uint32_t clippingDepth )
+  {
+    // We only set up the sort value if we have a clipping depth, IE. At least 1 clipping node has been hit.
+    // If not, if we traverse down a clipping tree and back up, and there is another
+    // node on the parent, this will have a non-zero clipping ID that must be ignored
+    if( DALI_LIKELY( clippingDepth > 0u ) )
+    {
+      mClippingDepth = clippingDepth;
+
+      // Calculate the sort value here on write, as when read (during sort) it may be accessed several times.
+      // The items must be sorted by Clipping ID first (so the ID is kept in the most-significant bits).
+      // For the same ID, the clipping nodes must be first, so we negate the
+      // clipping enabled flag and set it as the least significant bit.
+      mClippingSortModifier = ( clippingId << 1u ) | ( mClippingMode == ClippingMode::DISABLED ? 1u : 0u );
+    }
+  }
+
+  /**
+   * Gets the Clipping ID for this node.
+   * @return The Clipping ID for this node.
+   */
+  uint32_t GetClippingId() const
+  {
+    return mClippingSortModifier >> 1u;
+  }
+
+  /**
+   * Gets the Clipping Depth for this node.
+   * @return The Clipping Depth for this node.
+   */
+  uint32_t GetClippingDepth() const
+  {
+    return mClippingDepth;
+  }
+
+  /**
+   * Sets the clipping mode for this node.
+   * @param[in] clippingMode The ClippingMode to set
+   */
+  void SetClippingMode( const ClippingMode::Type clippingMode )
+  {
+    mClippingMode = clippingMode;
+  }
+
+  /**
+   * Gets the Clipping Mode for this node.
+   * @return The ClippingMode of this node
+   */
+  ClippingMode::Type GetClippingMode() const
+  {
+    return mClippingMode;
+  }
+
+  /**
    * Add a renderer to the node
    * @param[in] renderer The renderer added to the node
    */
-  void AddRenderer( Renderer* renderer );
+  void AddRenderer( Renderer* renderer )
+  {
+    //Check that it has not been already added
+    unsigned int rendererCount( mRenderer.Size() );
+    for( unsigned int i(0); i<rendererCount; ++i )
+    {
+      if( mRenderer[i] == renderer )
+      {
+        //Renderer already in the list
+        return;
+      }
+    }
+
+    //If it is the first renderer added, make sure the world transform will be calculated
+    //in the next update as world transform is not computed if node has no renderers
+    if( rendererCount == 0 )
+    {
+      mDirtyFlags |= TransformFlag;
+    }
+
+    mRenderer.PushBack( renderer );
+  }
 
   /**
    * Remove a renderer from the node
@@ -158,7 +238,7 @@ public:
    * Get the renderer at the given index
    * @param[in] index
    */
-  Renderer* GetRendererAt( unsigned int index ) const
+  Renderer* GetRendererAt( unsigned int index )
   {
     return mRenderer[index];
   }
@@ -591,6 +671,7 @@ public:
            (mTransformManager->IsLocalMatrixDirty( mTransformId ));
   }
 
+
   /**
    * Retrieve the cached world-matrix of a node.
    * @param[in] bufferIndex The buffer to read from.
@@ -648,51 +729,25 @@ public:
 
   /**
    * Equality operator, checks for identity, not values.
-   *
+   * @param[in]
    */
   bool operator==( const Node* rhs ) const
   {
-    if ( this == rhs )
-    {
-      return true;
-    }
-    return false;
-  }
-
-  unsigned short GetDepth() const
-  {
-    return mDepth;
+    return ( this == rhs );
   }
 
   /**
-   * @brief Turns on or off being a batch parent for the node
-   * @param[in] enabled If true the node becomes a parent for batch of its children
-   */
-  void SetIsBatchParent( bool enabled );
-
-  /**
-   * @brief Tells if the node is a batch parent
-   * @return True if node is a batch parent, false otherwise.
+   * @brief Sets the sibling order of the node
+   * @param[in] order The new order
    */
-  inline bool GetIsBatchParent()
-  {
-    return mIsBatchParent;
-  }
+  void SetDepthIndex( unsigned int depthIndex ){ mDepthIndex = depthIndex; }
 
   /**
-   * Set the batch parent of a Node.
-   * @param[in] batchParentNode The new batch parent.
+   * @brief Get the depth index of the node
+   * @return Current depth index
    */
-  void SetBatchParent( Node* batchParentNode );
+  unsigned int GetDepthIndex(){ return mDepthIndex; }
 
-  /**
-   * Retrieve the batch parent of a Node.
-   * @return The batch parent node, or NULL if the Node has not been added to the scene-graph.
-   */
-  Node* GetBatchParent() const
-  {
-    return mBatchParent;
-  }
 
 public:
   /**
@@ -726,9 +781,7 @@ protected:
    * Set the parent of a Node.
    * @param[in] parentNode the new parent.
    */
-  void SetParent( Node& parentNode );
-
-protected:
+  void SetParent(Node& parentNode);
 
   /**
    * Protected constructor; See also Node::New()
@@ -792,52 +845,50 @@ private:
 
 public: // Default properties
 
-  TransformManager* mTransformManager;
-  TransformId mTransformId;
-  TransformManagerPropertyVector3    mParentOrigin;  ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
-  TransformManagerPropertyVector3    mAnchorPoint;   ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
-  TransformManagerPropertyVector3    mSize;          ///< Size is provided for layouting
-  TransformManagerPropertyVector3    mPosition;      ///< Local transform; distance between parent-origin & anchor-point
-  TransformManagerPropertyQuaternion mOrientation;   ///< Local transform; rotation relative to parent node
-  TransformManagerPropertyVector3    mScale;         ///< Local transform; scale relative to parent node
+  TransformManager*                  mTransformManager;
+  TransformId                        mTransformId;
+  TransformManagerPropertyVector3    mParentOrigin;           ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
+  TransformManagerPropertyVector3    mAnchorPoint;            ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
+  TransformManagerPropertyVector3    mSize;                   ///< Size is provided for layouting
+  TransformManagerPropertyVector3    mPosition;               ///< Local transform; distance between parent-origin & anchor-point
+  TransformManagerPropertyQuaternion mOrientation;            ///< Local transform; rotation relative to parent node
+  TransformManagerPropertyVector3    mScale;                  ///< Local transform; scale relative to parent node
 
-  AnimatableProperty<bool>           mVisible;       ///< Visibility can be inherited from the Node hierachy
-  AnimatableProperty<Vector4>        mColor;         ///< Color can be inherited from the Node hierarchy
+  AnimatableProperty<bool>           mVisible;                ///< Visibility can be inherited from the Node hierachy
+  AnimatableProperty<Vector4>        mColor;                  ///< Color can be inherited from the Node hierarchy
 
   // Inherited properties; read-only from public API
 
-  TransformManagerVector3Input    mWorldPosition;     ///< Full inherited position
-  TransformManagerVector3Input    mWorldScale;
-  TransformManagerQuaternionInput mWorldOrientation;  ///< Full inherited orientation
-  TransformManagerMatrixInput     mWorldMatrix;       ///< Full inherited world matrix
-  InheritedColor                  mWorldColor;        ///< Full inherited color
+  TransformManagerVector3Input       mWorldPosition;          ///< Full inherited position
+  TransformManagerVector3Input       mWorldScale;
+  TransformManagerQuaternionInput    mWorldOrientation;       ///< Full inherited orientation
+  TransformManagerMatrixInput        mWorldMatrix;            ///< Full inherited world matrix
+  InheritedColor                     mWorldColor;             ///< Full inherited color
 
-  GeometryBatcher*                mGeometryBatcher;  ///< A pointer to an instance of geometry batcher
-  uint32_t                        mBatchIndex;       ///< Batch 32bit handle, BATCH_NULL_HANDLE by default
-  bool                            mIsBatchParent:1;  ///< Marks node as a batch parent
+  uint32_t                           mClippingSortModifier;   ///< Contains bit-packed clipping information for quick access when sorting
 
 protected:
 
-  Node*               mParent;                       ///< Pointer to parent node (a child is owned by its parent)
-  Node*               mBatchParent;                  ///< Pointer to batch parent node
-  RenderTask*         mExclusiveRenderTask;          ///< Nodes can be marked as exclusive to a single RenderTask
+  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
 
-  RendererContainer   mRenderer;                     ///< Container of renderers; not owned
+  RendererContainer                  mRenderer;               ///< Container of renderers; not owned
 
-  NodeContainer       mChildren;                     ///< Container of children; not owned
+  NodeContainer                      mChildren;               ///< Container of children; not owned
 
-  CollectedUniformMap mCollectedUniformMap[2];      ///< Uniform maps of the node
-  unsigned int        mUniformMapChanged[2];        ///< Records if the uniform map has been altered this frame
-  unsigned int        mRegenerateUniformMap : 2;    ///< Indicate if the uniform map has to be regenerated this frame
+  CollectedUniformMap                mCollectedUniformMap[2]; ///< Uniform maps of the node
+  unsigned int                       mUniformMapChanged[2];   ///< Records if the uniform map has been altered this frame
+  uint32_t                           mClippingDepth;          ///< The number of clipping nodes deep this node is
 
-  // flags, compressed to bitfield
-  unsigned short mDepth: 12;                        ///< Depth in the hierarchy
-  int  mDirtyFlags:8;                               ///< A composite set of flags for each of the Node properties
-
-  bool mIsRoot:1;                                    ///< True if the node cannot have a parent
+  uint32_t                           mDepthIndex;             ///< Depth index of the node
 
-  DrawMode::Type          mDrawMode:2;               ///< How the Node and its children should be drawn
-  ColorMode               mColorMode:2;              ///< Determines whether mWorldColor is inherited, 2 bits is enough
+  // flags, compressed to bitfield
+  unsigned int                       mRegenerateUniformMap:2; ///< Indicate if the uniform map has to be regenerated this frame
+  int                                mDirtyFlags:8;           ///< A composite set of flags for each of the Node properties
+  DrawMode::Type                     mDrawMode:2;             ///< How the Node and its children should be drawn
+  ColorMode                          mColorMode:2;            ///< Determines whether mWorldColor is inherited, 2 bits is enough
+  ClippingMode::Type                 mClippingMode:2;         ///< The clipping mode of this node
+  bool                               mIsRoot:1;               ///< True if the node cannot have a parent
 
   // Changes scope, should be at end of class
   DALI_LOG_OBJECT_STRING_DECLARATION;
@@ -944,15 +995,26 @@ inline void RemoveRendererMessage( EventThreadServices& eventThreadServices, con
   new (slot) LocalType( &node, &Node::RemoveRenderer, renderer );
 }
 
-inline void SetIsBatchParentMessage( EventThreadServices& eventThreadServices, const Node& node, bool isBatchParent )
+inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Node& node, unsigned int depthIndex )
 {
-  typedef MessageValue1< Node, bool > LocalType;
+  typedef MessageValue1< Node, unsigned int > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* 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::SetDepthIndex, depthIndex );
+}
+
+inline void SetClippingModeMessage( EventThreadServices& eventThreadServices, const Node& node, ClippingMode::Type clippingMode )
+{
+  typedef MessageValue1< Node, ClippingMode::Type > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* 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::SetIsBatchParent, isBatchParent );
+  new (slot) LocalType( &node, &Node::SetClippingMode, clippingMode );
 }
 
 
@@ -962,4 +1024,4 @@ inline void SetIsBatchParentMessage( EventThreadServices& eventThreadServices, c
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_
+#endif // DALI_INTERNAL_SCENE_GRAPH_NODE_H