Added parameter in OnStageConnection method indicating the depth of the actor 31/40431/10
authorFerran Sole <ferran.sole@samsung.com>
Wed, 3 Jun 2015 13:46:05 +0000 (14:46 +0100)
committerFerran Sole <ferran.sole@samsung.com>
Tue, 9 Jun 2015 10:12:51 +0000 (11:12 +0100)
in the hierarchy.

Change-Id: I68965e1df12840953e416221f1c539d0fa4004c1

automated-tests/src/dali/utc-Dali-CustomActor.cpp
automated-tests/src/dali/utc-Dali-TypeRegistry.cpp
dali/internal/event/actors/actor-impl.cpp
dali/internal/event/actors/actor-impl.h
dali/internal/event/actors/custom-actor-internal.h
dali/public-api/actors/custom-actor-impl.h

index 00da4c1..afc9fcd 100644 (file)
@@ -61,7 +61,8 @@ struct TestCustomActor : public CustomActorImpl
     mDaliProperty( Property::INVALID_INDEX ),
     mSizeSet( Vector3::ZERO ),
     mTargetSize( Vector3::ZERO ),
-    mNego( false )
+    mNego( false ),
+    mDepth(0u)
   {
   }
 
@@ -119,9 +120,10 @@ struct TestCustomActor : public CustomActorImpl
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection()
+  virtual void OnStageConnection( unsigned int depth )
   {
     AddToCallStacks("OnStageConnection");
+    mDepth = depth;
   }
   virtual void OnStageDisconnection()
   {
@@ -253,6 +255,7 @@ struct TestCustomActor : public CustomActorImpl
   Vector3 mSizeSet;
   Vector3 mTargetSize;
   bool mNego;
+  unsigned int mDepth;
 };
 
 /**
@@ -269,10 +272,10 @@ struct TestCustomActorVariant1 : public TestCustomActor
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection()
+  virtual void OnStageConnection( unsigned int depth )
   {
     // Chain up first
-    TestCustomActor::OnStageConnection();
+    TestCustomActor::OnStageConnection( depth );
 
     // Add the child
     Self().Add( mChildToAdd );
@@ -294,10 +297,10 @@ struct TestCustomActorVariant2 : public TestCustomActor
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection()
+  virtual void OnStageConnection( unsigned int depth )
   {
     // Chain up first
-    TestCustomActor::OnStageConnection();
+    TestCustomActor::OnStageConnection( depth );
 
     // Remove all the children
     for( unsigned int i=0, num=Self().GetChildCount(); i<num; ++i )
@@ -372,10 +375,10 @@ struct TestCustomActorVariant5 : public TestCustomActor
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection()
+  virtual void OnStageConnection( unsigned int depth )
   {
     // Chain up first
-    TestCustomActor::OnStageConnection();
+    TestCustomActor::OnStageConnection( depth );
 
     // Take parent off-stage
     Actor parent = Self().GetParent();
@@ -497,7 +500,7 @@ public:
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection()
+  virtual void OnStageConnection( unsigned int depth )
   {
   }
   virtual void OnStageDisconnection()
@@ -780,6 +783,10 @@ public:
     return GetImpl().TestRelayoutDependentOnChildrenBase( dimension );
   }
 
+  unsigned int GetDepth()
+  {
+    return GetImpl().mDepth;
+  }
 private:
 
   TestCustomActor( Impl::TestCustomActor& impl ) : CustomActor( impl )
@@ -1949,3 +1956,56 @@ int UtcDaliCustomActorGetExtensionP(void)
 
   END_TEST;
 }
+
+int UtcDaliCustomActorOnConnectionDepth(void)
+{
+  TestApplication application;
+  tet_infoline("Testing Dali::CustomActor::OnStageConnection() hierarchy depth");
+
+  Stage stage = Stage::GetCurrent();
+
+  /* Build tree of actors:
+   *
+   *                      Depth
+   *
+   *       A (parent)       1
+   *      / \
+   *     B   C              2
+   *    / \   \
+   *   D   E   F            3
+   *
+   * OnStageConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
+   */
+
+  TestCustomActor actorA = TestCustomActor::New();
+  stage.Add( actorA );
+
+  TestCustomActor actorB = TestCustomActor::New();
+  actorA.Add( actorB );
+
+  TestCustomActor actorC = TestCustomActor::New();
+  actorA.Add( actorC );
+
+  TestCustomActor actorD = TestCustomActor::New();
+  actorB.Add( actorD );
+
+  TestCustomActor actorE = TestCustomActor::New();
+  actorB.Add( actorE );
+
+  TestCustomActor actorF = TestCustomActor::New();
+  actorC.Add( actorF );
+
+  // Excercise the message passing to Update thread
+  application.SendNotification();
+  application.Render();
+  application.Render();
+
+  DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION );
+  DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION );
+  DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION );
+  DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION );
+  DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION );
+  DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION );
+
+  END_TEST;
+}
index 7175643..db28d47 100644 (file)
@@ -203,7 +203,7 @@ struct MyTestCustomActor : public CustomActorImpl
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection()
+  virtual void OnStageConnection( unsigned int depth )
   {
   }
   virtual void OnStageDisconnection()
index d4e7398..86a9cc3 100644 (file)
@@ -2377,14 +2377,15 @@ Actor::~Actor()
   }
 }
 
-void Actor::ConnectToStage( int index )
+void Actor::ConnectToStage( unsigned int parentDepth, int index )
 {
   // This container is used instead of walking the Actor hierachy.
   // It protects us when the Actor hierachy is modified during OnStageConnectionExternal callbacks.
   ActorContainer connectionList;
 
+
   // This stage is atomic i.e. not interrupted by user callbacks
-  RecursiveConnectToStage( connectionList, index );
+  RecursiveConnectToStage( connectionList, parentDepth+1, index );
 
   // Notify applications about the newly connected actors.
   const ActorIter endIter = connectionList.end();
@@ -2397,11 +2398,12 @@ void Actor::ConnectToStage( int index )
   RelayoutRequest();
 }
 
-void Actor::RecursiveConnectToStage( ActorContainer& connectionList, int index )
+void Actor::RecursiveConnectToStage( ActorContainer& connectionList, unsigned int depth, int index )
 {
   DALI_ASSERT_ALWAYS( !OnStage() );
 
   mIsOnStage = true;
+  mDepth = depth;
 
   ConnectToSceneGraph( index );
 
@@ -2418,7 +2420,7 @@ void Actor::RecursiveConnectToStage( ActorContainer& connectionList, int index )
     for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter )
     {
       Actor& actor = GetImplementation( *iter );
-      actor.RecursiveConnectToStage( connectionList );
+      actor.RecursiveConnectToStage( connectionList, depth+1 );
     }
   }
 }
@@ -2467,7 +2469,7 @@ void Actor::NotifyStageConnection()
   if( OnStage() && !mOnStageSignalled )
   {
     // Notification for external (CustomActor) derived classes
-    OnStageConnectionExternal();
+    OnStageConnectionExternal( mDepth );
 
     if( !mOnStageSignal.Empty() )
     {
@@ -3843,7 +3845,7 @@ void Actor::SetParent( Actor* parent, int index )
          parent->OnStage() )
     {
       // Instruct each actor to create a corresponding node in the scene graph
-      ConnectToStage( index );
+      ConnectToStage( parent->GetDepth(), index );
     }
   }
   else // parent being set to NULL
index a81c32e..9a45897 100644 (file)
@@ -1581,17 +1581,19 @@ protected:
   /**
    * Called on a child during Add() when the parent actor is connected to the Stage.
    * @param[in] stage The stage.
+   * @param[in] parentDepth The depth of the parent in the hierarchy
    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
    */
-  void ConnectToStage( int index = -1 );
+  void ConnectToStage( unsigned int parentDepth, int index = -1 );
 
   /**
    * Helper for ConnectToStage, to recursively connect a tree of actors.
    * This is atomic i.e. not interrupted by user callbacks.
    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
+   * @param[in] depth The depth in the hierarchy of the actor
    * @param[out] connectionList On return, the list of connected actors which require notification.
    */
-  void RecursiveConnectToStage( ActorContainer& connectionList, int index = -1 );
+  void RecursiveConnectToStage( ActorContainer& connectionList, unsigned int depth, int index = -1 );
 
   /**
    * Connect the Node associated with this Actor to the scene-graph.
@@ -1641,6 +1643,17 @@ protected:
    */
   float CalculateSizeZ( const Vector2& size ) const;
 
+  /**
+   * Return the depth in the hierarchy of the actor.
+   * The value returned is only valid if the actor is on the stage.
+   *
+   * @return Depth of the actor in the hierarchy
+   */
+  unsigned int GetDepth() const
+  {
+    return mDepth;
+  }
+
 public:
   // Default property extensions from Object
 
@@ -1778,7 +1791,7 @@ private:
    * For use in external (CustomActor) derived classes.
    * This is called after the atomic ConnectToStage() traversal has been completed.
    */
-  virtual void OnStageConnectionExternal()
+  virtual void OnStageConnectionExternal( unsigned int depth )
   {
   }
 
@@ -1894,6 +1907,7 @@ protected:
   std::string     mName;      ///< Name of the actor
   unsigned int    mId;        ///< A unique ID to identify the actor starting from 1, and 0 is reserved
 
+  unsigned int mDepth                              :12; ///< The depth in the hierarchy of the actor. Only 4096 levels of depth are supported
   const bool mIsRoot                               : 1; ///< Flag to identify the root actor
   const bool mIsRenderable                         : 1; ///< Flag to identify that this is a renderable actor
   const bool mIsLayer                              : 1; ///< Flag to identify that this is a layer
index ade7a27..2c5eaba 100644 (file)
@@ -70,9 +70,9 @@ private:
   /**
    * @copydoc Internal::Actor::OnStageConnectionExternal
    */
-  virtual void OnStageConnectionExternal()
+  virtual void OnStageConnectionExternal( unsigned int depth )
   {
-    mImpl->OnStageConnection();
+    mImpl->OnStageConnection( depth );
   }
 
   /**
index 32cf1b5..b54e57f 100644 (file)
@@ -90,8 +90,10 @@ public:
    *     B   C
    *    / \   \
    *   D   E   F
+   *
+   *   @param[in] depth The depth in the hierarchy for the actor
    */
-  virtual void OnStageConnection() = 0;
+  virtual void OnStageConnection( unsigned int depth ) = 0;
 
   /**
    * @brief Called after the actor has been disconnected from the stage.