[dali_1.4.8] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / relayout-controller-impl.cpp
index 91f0ad9..35190fe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 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.
  *
  */
 
-// FILE HEADER
-
+// CLASS HEADER
 #include "relayout-controller-impl.h"
 
 // EXTERNAL INCLUDES
 #if defined(DEBUG_ENABLED)
 #include <sstream>
-#include <dali/internal/event/common/system-overlay-impl.h>
 #endif // defined(DEBUG_ENABLED)
 
 // INTERNAL INCLUDES
-#include <dali/public-api/actors/layer.h>
-#include <dali/public-api/common/stage.h>
 #include <dali/integration-api/debug.h>
+#include <dali/integration-api/render-controller.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/public-api/object/object-registry.h>
 #include <dali/internal/event/actors/actor-impl.h>
+#include <dali/internal/event/common/stage-impl.h>
 #include <dali/internal/event/common/thread-local-storage.h>
 
 namespace Dali
@@ -76,8 +74,8 @@ void PrintChildren( Dali::Actor actor, int level )
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, output.str().c_str() );
 
   ++level;
-  unsigned int numChildren = actor.GetChildCount();
-  for( unsigned int i=0; i<numChildren; ++i )
+  uint32_t numChildren = actor.GetChildCount();
+  for( uint32_t i=0; i<numChildren; ++i )
   {
     PrintChildren( actor.GetChildAt(i), level );
   }
@@ -92,7 +90,7 @@ void PrintHierarchy()
   if ( gLogFilter->IsEnabledFor( Debug::Verbose ) )
   {
     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "---------- ROOT LAYER ----------\n" );
-    PrintChildren( Dali::Stage().GetCurrent().GetRootLayer(), 0 );
+    PrintChildren( Stage::GetCurrent()->GetRootLayer(), 0 );
   }
 }
 
@@ -106,19 +104,17 @@ void PrintHierarchy()
 
 } // unnamed namespace
 
-RelayoutController* RelayoutController::Get()
-{
-  return &ThreadLocalStorage::Get().GetRelayoutController();
-}
-
-RelayoutController::RelayoutController()
-: mRelayoutInfoAllocator(),
+RelayoutController::RelayoutController( Integration::RenderController& controller )
+: mRenderController( controller ),
+  mRelayoutInfoAllocator(),
   mSlotDelegate( this ),
   mRelayoutStack( new MemoryPoolRelayoutContainer( mRelayoutInfoAllocator ) ),
+  mStageSize(), // zero initialized
   mRelayoutConnection( false ),
   mRelayoutFlag( false ),
   mEnabled( false ),
-  mPerformingRelayout( false )
+  mPerformingRelayout( false ),
+  mProcessingCoreEvents( false )
 {
   // Make space for 32 controls to avoid having to copy construct a lot in the beginning
   mRelayoutStack->Reserve( 32 );
@@ -129,6 +125,17 @@ RelayoutController::~RelayoutController()
   delete mRelayoutStack;
 }
 
+RelayoutController* RelayoutController::Get()
+{
+  return &ThreadLocalStorage::Get().GetRelayoutController();
+}
+
+void RelayoutController::SetStageSize( uint32_t width, uint32_t height )
+{
+  mStageSize.width = static_cast<float>( width );
+  mStageSize.height = static_cast<float>( height );
+}
+
 void RelayoutController::QueueActor( Dali::Actor& actor, RelayoutContainer& actors, Vector2 size )
 {
   if( GetImplementation( actor ).RelayoutRequired() )
@@ -150,7 +157,7 @@ void RelayoutController::RequestRelayout( Dali::Actor& actor, Dimension::Type di
   topOfSubTreeStack.push_back( actor );
 
   // Propagate on all dimensions
-  for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+  for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i )
   {
     if( dimension & ( 1 << i ) )
     {
@@ -159,20 +166,25 @@ void RelayoutController::RequestRelayout( Dali::Actor& actor, Dimension::Type di
     }
   }
 
-  // Request this actor as head of sub-tree if it is not dependent on a parent that is dirty
-  Dali::Actor subTreeActor = topOfSubTreeStack.back();
-  Dali::Actor parent = subTreeActor.GetParent();
-  if( !parent || !( GetImplementation( subTreeActor ).RelayoutDependentOnParent() && GetImplementation( parent ).RelayoutRequired() ) )
+  while( !topOfSubTreeStack.empty() )
   {
-    // Add sub tree root to relayout list
-    AddRequest( subTreeActor );
+    // Request this actor as head of sub-tree if it is not dependent on a parent that is dirty
+    Dali::Actor subTreeActor = topOfSubTreeStack.back();
+    topOfSubTreeStack.pop_back();
 
-    // Flag request for end of frame
-    Request();
-  }
-  else
-  {
-    potentialRedundantSubRoots.push_back( subTreeActor );
+    Dali::Actor parent = subTreeActor.GetParent();
+    if( !parent || !( GetImplementation( subTreeActor ).RelayoutDependentOnParent() && GetImplementation( parent ).RelayoutRequired() ) )
+    {
+      // Add sub tree root to relayout list
+      AddRequest( subTreeActor );
+
+      // Flag request for end of frame
+      Request();
+    }
+    else
+    {
+      potentialRedundantSubRoots.push_back( subTreeActor );
+    }
   }
 
   // Remove any redundant sub-tree heads
@@ -182,6 +194,11 @@ void RelayoutController::RequestRelayout( Dali::Actor& actor, Dimension::Type di
 
     RemoveRequest( subRoot );
   }
+
+  if ( !mProcessingCoreEvents )
+  {
+    mRenderController.RequestProcessEventsOnIdle( false );
+  }
 }
 
 void RelayoutController::OnApplicationSceneCreated()
@@ -193,7 +210,8 @@ void RelayoutController::OnApplicationSceneCreated()
 
   // Spread the dirty flag through whole tree - don't need to explicity
   // add request on rootLayer as it will automatically be added below.
-  Dali::Actor rootLayer = Dali::Stage::GetCurrent().GetRootLayer();
+  Dali::Stage stage = Dali::Stage::GetCurrent();
+  Dali::Actor rootLayer = stage.GetRootLayer();
   RequestRelayoutTree( rootLayer );
 
   // Flag request for end of frame
@@ -224,7 +242,7 @@ void RelayoutController::RequestRelayoutTree( Dali::Actor& actor )
   }
 
   // Propagate down to children
-  for( unsigned int i = 0; i < actor.GetChildCount(); ++i )
+  for( uint32_t i = 0; i < actor.GetChildCount(); ++i )
   {
     Dali::Actor child = actor.GetChildAt( i );
 
@@ -244,7 +262,7 @@ void RelayoutController::PropagateAll( Dali::Actor& actor, Dimension::Type dimen
 
     // Check for dimension dependecy: width for height/height for width etc
     // Check each possible dimension and see if it is dependent on the input one
-    for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+    for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i )
     {
       Dimension::Type dimensionToCheck = static_cast< Dimension::Type >( 1 << i );
 
@@ -264,9 +282,9 @@ void RelayoutController::PropagateAll( Dali::Actor& actor, Dimension::Type dimen
       {
         // Store the highest parent reached
         bool found = false;
-        for( unsigned int i = 0, count = topOfSubTreeStack.size(); i < count; ++i )
+        for( auto&& element : topOfSubTreeStack )
         {
-          if( topOfSubTreeStack[ i ] == parent )
+          if( element == parent )
           {
             found = true;
             break;
@@ -318,7 +336,7 @@ void RelayoutController::PropagateFlags( Dali::Actor& actor, Dimension::Type dim
 
     // Check for dimension dependecy: width for height/height for width etc
     // Check each possible dimension and see if it is dependent on the input one
-    for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+    for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i )
     {
       Dimension::Type dimensionToCheck = static_cast< Dimension::Type >( 1 << i );
 
@@ -341,7 +359,7 @@ void RelayoutController::PropagateFlags( Dali::Actor& actor, Dimension::Type dim
     }
 
     // Propagate down to children
-    for( unsigned int i = 0, childCount = actor.GetChildCount(); i < childCount; ++i )
+    for( uint32_t i = 0, childCount = actor.GetChildCount(); i < childCount; ++i )
     {
       Dali::Actor child = actor.GetChildAt( i );
       Actor& childImpl = GetImplementation( child );
@@ -360,9 +378,9 @@ void RelayoutController::AddRequest( Dali::Actor& actor )
 
   // Only add the rootActor if it is not already recorded
   bool found = false;
-  for( unsigned int i = 0, count = mDirtyLayoutSubTrees.Size(); i < count; ++i )
+  for( auto&& item : mDirtyLayoutSubTrees )
   {
-    if( mDirtyLayoutSubTrees[ i ] == actorPtr )
+    if( item == actorPtr )
     {
       found = true;
       break;
@@ -421,8 +439,6 @@ void RelayoutController::Relayout()
 
     // 1. Finds all top-level controls from the dirty list and allocate them the size of the stage
     //    These controls are paired with the parent/stage size and added to the stack.
-    const Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
-
     for( RawActorList::Iterator it = mDirtyLayoutSubTrees.Begin(), itEnd = mDirtyLayoutSubTrees.End(); it != itEnd; ++it )
     {
       BaseObject* dirtyActor = *it;
@@ -437,7 +453,7 @@ void RelayoutController::Relayout()
         if( actor.OnStage() )
         {
           Dali::Actor parent = actor.GetParent();
-          QueueActor( actor, *mRelayoutStack, ( parent ) ? Vector2( parent.GetTargetSize() ) : stageSize );
+          QueueActor( actor, *mRelayoutStack, ( parent ) ? Vector2( parent.GetTargetSize() ) : mStageSize );
         }
       }
     }
@@ -463,7 +479,11 @@ void RelayoutController::Relayout()
 
           // 3. Negotiate the size with the current actor. Pass it an empty container which the actor
           //    has to fill with all the actors it has not done any size negotiation for.
+
           actorImpl.NegotiateSize( size, *mRelayoutStack );
+
+          // Reset the flag so that size negotiation will respect the actor's original resize policy
+          actorImpl.SetUseAssignedSize( false );
         }
       }
 
@@ -489,6 +509,11 @@ bool RelayoutController::IsPerformingRelayout() const
   return mPerformingRelayout;
 }
 
+void RelayoutController::SetProcessingCoreEvents( bool processingEvents )
+{
+  mProcessingCoreEvents = processingEvents;
+}
+
 void RelayoutController::FindAndZero( const RawActorList& list, const Dali::RefObject* object )
 {
   // Object has been destroyed so clear it from this list