[Tizen] Add codes for Dali Windows Backend
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / node.h
old mode 100644 (file)
new mode 100755 (executable)
index e354b32..3850580
@@ -1,8 +1,8 @@
-#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.
+ * Copyright (c) 2018 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.
@@ -21,7 +21,6 @@
 // INTERNAL INCLUDES
 #include <dali/public-api/actors/actor-enumerations.h>
 #include <dali/public-api/actors/draw-mode.h>
-#include <dali/devel-api/common/set-wrapper.h>
 #include <dali/public-api/math/quaternion.h>
 #include <dali/public-api/math/math-utils.h>
 #include <dali/public-api/math/vector3.h>
@@ -45,9 +44,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
 {
@@ -69,7 +69,7 @@ enum NodePropertyFlags
   SizeFlag             = 0x008,
   OverlayFlag          = 0x010,
   SortModifierFlag     = 0x020,
-  ChildDeletedFlag     = 0x040
+  ChildDeletedFlag     = 0x040,
 };
 
 static const int AllFlags = ( ChildDeletedFlag << 1 ) - 1; // all the flags
@@ -106,15 +106,9 @@ public:
   static Node* New();
 
   /**
-   * Virtual destructor
+   * Deletes a Node.
    */
-  virtual ~Node();
-
-  /**
-   * Overriden delete operator
-   * Deletes the node from its global memory pool
-   */
-  void operator delete( void* ptr );
+  static void Delete( Node* node );
 
   /**
    * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
@@ -129,7 +123,7 @@ public:
    */
   bool IsLayer()
   {
-    return (GetLayer() != NULL);
+    return mIsLayer;
   }
 
   /**
@@ -142,33 +136,90 @@ public:
   }
 
   /**
-   * Add a renderer to the node
-   * @param[in] renderer The renderer added to the node
+   * 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
+   * @param[in] scissorDepth The Scissor Clipping Depth of the node to set
    */
-  void AddRenderer( Renderer* renderer )
+  void SetClippingInformation( const uint32_t clippingId, const uint32_t clippingDepth, const uint32_t scissorDepth )
   {
-    //Check that it has not been already added
-    unsigned int rendererCount( mRenderer.Size() );
-    for( unsigned int i(0); i<rendererCount; ++i )
+    // We only set up the sort value if we have a stencil 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( clippingDepth > 0u )
     {
-      if( mRenderer[i] == renderer )
-      {
-        //Renderer already in the list
-        return;
-      }
-    }
+      mClippingDepth = clippingDepth;
 
-    //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 )
+      // 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 );
+    }
+    else
     {
-      mDirtyFlags |= TransformFlag;
+      // If we do not have a clipping depth, then set this to 0 so we do not have a Clipping ID either.
+      mClippingSortModifier = 0u;
     }
 
-    mRenderer.PushBack( renderer );
+    // The scissor depth does not modify the clipping sort modifier (as scissor clips are 2D only).
+    // For this reason we can always update the member variable.
+    mScissorDepth = scissorDepth;
   }
 
   /**
+   * 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;
+  }
+
+  /**
+   * Gets the Scissor Clipping Depth for this node.
+   * @return The Scissor Clipping Depth for this node.
+   */
+  uint32_t GetScissorDepth() const
+  {
+    return mScissorDepth;
+  }
+
+  /**
+   * 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 );
+
+  /**
    * Remove a renderer from the node
    * @param[in] renderer The renderer to be removed
    */
@@ -178,7 +229,7 @@ public:
    * Get the renderer at the given index
    * @param[in] index
    */
-  Renderer* GetRendererAt( unsigned int index )
+  Renderer* GetRendererAt( unsigned int index ) const
   {
     return mRenderer[index];
   }
@@ -291,15 +342,6 @@ public:
   int GetDirtyFlags() const;
 
   /**
-   * Query whether a node is clean.
-   * @return True if the node is clean.
-   */
-  bool IsClean() const
-  {
-    return ( NothingFlag == GetDirtyFlags() );
-  }
-
-  /**
    * Retrieve the parent-origin of the node.
    * @return The parent-origin.
    */
@@ -590,17 +632,15 @@ public:
 
   /**
    * Retrieve world matrix and size of the node
-   *
+   * @param[out] The local to world matrix of the node
    * @param[out] size The current size of the node
-   * @return The local to world matrix of the node
    */
-  const Matrix& GetWorldMatrixAndSize( Vector3& size ) const
+  void GetWorldMatrixAndSize( Matrix& worldMatrix, Vector3& size ) const
   {
     if( mTransformId != INVALID_TRANSFORM_ID )
     {
-      return mTransformManager->GetWorldMatrixAndSize( mTransformId, size );
+      mTransformManager->GetWorldMatrixAndSize( mTransformId, worldMatrix, size );
     }
-    return Matrix::IDENTITY;
   }
 
   /**
@@ -613,7 +653,6 @@ public:
            (mTransformManager->IsLocalMatrixDirty( mTransformId ));
   }
 
-
   /**
    * Retrieve the cached world-matrix of a node.
    * @param[in] bufferIndex The buffer to read from.
@@ -671,27 +710,43 @@ public:
 
   /**
    * Equality operator, checks for identity, not values.
-   *
+   * @param[in]
    */
   bool operator==( const Node* rhs ) const
   {
-    if ( this == rhs )
-    {
-      return true;
-    }
-    return false;
+    return ( this == rhs );
   }
 
-  unsigned short GetDepth() const
+  /**
+   * @brief Sets the sibling order of the node
+   * @param[in] order The new order
+   */
+  void SetDepthIndex( unsigned int depthIndex ){ mDepthIndex = depthIndex; }
+
+  /**
+   * @brief Get the depth index of the node
+   * @return Current depth index
+   */
+  unsigned int GetDepthIndex(){ return mDepthIndex; }
+
+  /**
+   * @brief Sets the boolean which states whether the position should use the anchor-point.
+   * @param[in] positionUsesAnchorPoint True if the position should use the anchor-point
+   */
+  void SetPositionUsesAnchorPoint( bool positionUsesAnchorPoint )
   {
-    return mDepth;
+    if( mTransformId != INVALID_TRANSFORM_ID && mPositionUsesAnchorPoint != positionUsesAnchorPoint )
+    {
+      mPositionUsesAnchorPoint = positionUsesAnchorPoint;
+      mTransformManager->SetPositionUsesAnchorPoint( mTransformId, mPositionUsesAnchorPoint );
+    }
   }
 
 public:
   /**
    * @copydoc UniformMap::Add
    */
-  void AddUniformMapping( UniformPropertyMapping* map );
+  void AddUniformMapping( OwnerPointer< UniformPropertyMapping >& map );
 
   /**
    * @copydoc UniformMap::Remove
@@ -713,19 +768,32 @@ public:
    */
   void CreateTransform( SceneGraph::TransformManager* transformManager );
 
+  /**
+   * Reset dirty flags
+   */
+  void ResetDirtyFlags( BufferIndex updateBufferIndex );
+
 protected:
 
   /**
    * Set the parent of a Node.
    * @param[in] parentNode the new parent.
    */
-  void SetParent(Node& parentNode);
+  void SetParent( Node& parentNode );
+
+protected:
 
   /**
    * Protected constructor; See also Node::New()
    */
   Node();
 
+  /**
+   * Protected virtual destructor; See also Node::Delete( Node* )
+   * Kept protected to allow destructor chaining from layer
+   */
+  virtual ~Node();
+
 private: // from NodeDataProvider
 
   /**
@@ -770,11 +838,6 @@ private:
   Node& operator=(const Node& rhs);
 
   /**
-   * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
-   */
-  virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
-
-  /**
    * Recursive helper to disconnect a Node and its children.
    * Disconnected Nodes have no parent or children.
    * @param[in] updateBufferIndex The current update buffer index.
@@ -783,48 +846,53 @@ 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
-
-protected:
+  TransformManagerVector3Input       mWorldPosition;          ///< Full inherited position
+  TransformManagerVector3Input       mWorldScale;
+  TransformManagerQuaternionInput    mWorldOrientation;       ///< Full inherited orientation
+  TransformManagerMatrixInput        mWorldMatrix;            ///< Full inherited world matrix
+  InheritedColor                     mWorldColor;             ///< Full inherited color
 
-  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
+  uint32_t                           mClippingSortModifier;   ///< Contains bit-packed clipping information for quick access when sorting
 
-  RendererContainer   mRenderer;                     ///< Container of renderers; not owned
+protected:
 
-  NodeContainer       mChildren;                     ///< Container of children; not owned
+  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
 
-  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
+  RendererContainer                  mRenderer;               ///< Container of renderers; not owned
 
-  // 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
+  NodeContainer                      mChildren;               ///< Container of children; not owned
 
-  bool mIsRoot:1;                                    ///< True if the node cannot have a parent
+  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 stencil clipping nodes deep this node is
+  uint32_t                           mScissorDepth;           ///< The number of scissor clipping nodes deep this node is
 
-  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
+  uint32_t                           mDepthIndex;             ///< Depth index of the node
 
+  // 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: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                               mPositionUsesAnchorPoint:1; ///< True if the node should use the anchor-point when calculating the position
   // Changes scope, should be at end of class
   DALI_LOG_OBJECT_STRING_DECLARATION;
 };
@@ -929,10 +997,60 @@ inline void RemoveRendererMessage( EventThreadServices& eventThreadServices, con
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &node, &Node::RemoveRenderer, renderer );
 }
+
+inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Node& node, unsigned int depthIndex )
+{
+  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::SetClippingMode, clippingMode );
+}
+
+inline void SetPositionUsesAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, bool positionUsesAnchorPoint )
+{
+  typedef MessageValue1< Node, bool > 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::SetPositionUsesAnchorPoint, positionUsesAnchorPoint );
+}
+
 } // namespace SceneGraph
 
+// Template specialisation for OwnerPointer<Node>, because delete is protected
+template <>
+inline void OwnerPointer<Dali::Internal::SceneGraph::Node>::Reset()
+{
+  if (mObject != NULL)
+  {
+    Dali::Internal::SceneGraph::Node::Delete(mObject);
+    mObject = NULL;
+  }
+}
 } // namespace Internal
 
+// Template specialisations for OwnerContainer<Node*>, because delete is protected
+template <>
+inline void OwnerContainer<Dali::Internal::SceneGraph::Node*>::Delete( Dali::Internal::SceneGraph::Node* pointer )
+{
+  Dali::Internal::SceneGraph::Node::Delete(pointer);
+}
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_
+#endif // DALI_INTERNAL_SCENE_GRAPH_NODE_H