Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / relayout-controller-impl.cpp
index 3d064a9..5f81a1a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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 @@
 // EXTERNAL INCLUDES
 #if defined(DEBUG_ENABLED)
 #include <sstream>
-#include <dali/internal/event/common/system-overlay-impl.h>
 #endif // defined(DEBUG_ENABLED)
 
 // INTERNAL INCLUDES
@@ -31,7 +30,6 @@
 #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/system-overlay-impl.h>
 #include <dali/internal/event/common/thread-local-storage.h>
 
 namespace Dali
@@ -63,9 +61,9 @@ void PrintChildren( Dali::Actor actor, int level )
 
   output << actor.GetTypeName();
 
-  output << ", " << actor.GetName();
+  output << ", " << actor.GetProperty< std::string >( Dali::Actor::Property::NAME );
 
-  output << " - Pos: " << actor.GetCurrentPosition() << " Size: " << actor.GetTargetSize();
+  output << " - Pos: " << actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ) << " Size: " << actor.GetTargetSize();
 
   output << ", Dirty: (" << ( GetImplementation( actor ).IsLayoutDirty( Dimension::WIDTH ) ? "TRUE" : "FALSE" ) << "," << ( GetImplementation( actor ).IsLayoutDirty( Dimension::HEIGHT ) ? "TRUE" : "FALSE" ) << ")";
   output << ", Negotiated: (" << ( GetImplementation( actor ).IsLayoutNegotiated( Dimension::WIDTH ) ? "TRUE" : "FALSE" ) << "," << ( GetImplementation( actor ).IsLayoutNegotiated( Dimension::HEIGHT ) ? "TRUE" : "FALSE" ) << ")";
@@ -92,6 +90,7 @@ void PrintHierarchy()
   if ( gLogFilter->IsEnabledFor( Debug::Verbose ) )
   {
     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "---------- ROOT LAYER ----------\n" );
+
     PrintChildren( Stage::GetCurrent()->GetRootLayer(), 0 );
   }
 }
@@ -111,7 +110,6 @@ RelayoutController::RelayoutController( Integration::RenderController& controlle
   mRelayoutInfoAllocator(),
   mSlotDelegate( this ),
   mRelayoutStack( new MemoryPoolRelayoutContainer( mRelayoutInfoAllocator ) ),
-  mStageSize(), // zero initialized
   mRelayoutConnection( false ),
   mRelayoutFlag( false ),
   mEnabled( false ),
@@ -132,17 +130,12 @@ RelayoutController* RelayoutController::Get()
   return &ThreadLocalStorage::Get().GetRelayoutController();
 }
 
-void RelayoutController::SetStageSize( uint32_t width, uint32_t height )
+void RelayoutController::QueueActor( Internal::Actor* actor, RelayoutContainer& actors, Vector2 size )
 {
-  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() )
+  if( actor && actor->RelayoutRequired() )
   {
-    actors.Add( actor, size );
+    Dali::Actor actorHandle = Dali::Actor( actor );
+    actors.Add( actorHandle, size );
   }
 }
 
@@ -190,10 +183,8 @@ void RelayoutController::RequestRelayout( Dali::Actor& actor, Dimension::Type di
   }
 
   // Remove any redundant sub-tree heads
-  for( std::vector< Dali::Actor >::iterator it = potentialRedundantSubRoots.begin(), itEnd = potentialRedundantSubRoots.end(); it != itEnd; ++it )
+  for( auto& subRoot : potentialRedundantSubRoots )
   {
-    Dali::Actor subRoot = *it;
-
     RemoveRequest( subRoot );
   }
 
@@ -210,21 +201,6 @@ void RelayoutController::OnApplicationSceneCreated()
   // Open relayout controller to receive relayout requests
   mEnabled = true;
 
-  // Spread the dirty flag through whole tree - don't need to explicity
-  // add request on rootLayer as it will automatically be added below.
-  Dali::Stage stage = Dali::Stage::GetCurrent();
-  Dali::Actor rootLayer = stage.GetRootLayer();
-  RequestRelayoutTree( rootLayer );
-
-  // Also add request on the root of system overlay
-  Dali::Internal::SystemOverlay* systemOverlay = GetImplementation(stage).GetSystemOverlayInternal();
-  if( systemOverlay )
-  {
-    Dali::Internal::Actor& systemOverlayInternalRoot = systemOverlay->GetDefaultRootActor();
-    Dali::Actor systemOverlayRoot = Dali::Actor(&systemOverlayInternalRoot);
-    RequestRelayoutTree( systemOverlayRoot );
-  }
-
   // Flag request for end of frame
   Request();
 }
@@ -385,20 +361,12 @@ void RelayoutController::PropagateFlags( Dali::Actor& actor, Dimension::Type dim
 
 void RelayoutController::AddRequest( Dali::Actor& actor )
 {
-  BaseObject* actorPtr = &GetImplementation( actor );
+  Internal::Actor* actorPtr = &GetImplementation( actor );
 
   // Only add the rootActor if it is not already recorded
-  bool found = false;
-  for( auto&& item : mDirtyLayoutSubTrees )
-  {
-    if( item == actorPtr )
-    {
-      found = true;
-      break;
-    }
-  }
+  auto itr = std::find( mDirtyLayoutSubTrees.begin(), mDirtyLayoutSubTrees.end(), actorPtr );
 
-  if( !found )
+  if( itr == mDirtyLayoutSubTrees.end() )
   {
     mDirtyLayoutSubTrees.PushBack( actorPtr );
   }
@@ -406,17 +374,12 @@ void RelayoutController::AddRequest( Dali::Actor& actor )
 
 void RelayoutController::RemoveRequest( Dali::Actor& actor )
 {
-  BaseObject* actorPtr = &GetImplementation( actor );
+  Internal::Actor* actorPtr = &GetImplementation( actor );
 
-  // Remove actor from dirty sub trees
-  for( RawActorList::Iterator it = mDirtyLayoutSubTrees.Begin(), itEnd = mDirtyLayoutSubTrees.End(); it != itEnd; ++it )
-  {
-    if( *it == actorPtr )
-    {
-      mDirtyLayoutSubTrees.Erase( it );
-      break;
-    }
-  }
+  mDirtyLayoutSubTrees.Erase( std::remove( mDirtyLayoutSubTrees.begin(),
+                                           mDirtyLayoutSubTrees.end(),
+                                           actorPtr ),
+                              mDirtyLayoutSubTrees.end() );
 }
 
 void RelayoutController::Request()
@@ -425,8 +388,7 @@ void RelayoutController::Request()
 
   if( !mRelayoutConnection )
   {
-    Dali::Stage stage = Dali::Stage::GetCurrent();
-    stage.GetObjectRegistry().ObjectDestroyedSignal().Connect( mSlotDelegate, &RelayoutController::OnObjectDestroyed );
+    ThreadLocalStorage::Get().GetObjectRegistry().ObjectDestroyedSignal().Connect( mSlotDelegate, &RelayoutController::OnObjectDestroyed );
 
     mRelayoutConnection = true;
   }
@@ -448,23 +410,18 @@ void RelayoutController::Relayout()
     // Clear the flag as we're now doing the relayout
     mRelayoutFlag = false;
 
-    // 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.
-    for( RawActorList::Iterator it = mDirtyLayoutSubTrees.Begin(), itEnd = mDirtyLayoutSubTrees.End(); it != itEnd; ++it )
+    // 1. Finds all top-level controls from the dirty list and allocate them the size of the scene
+    //    These controls are paired with the parent/scene size and added to the stack.
+    for( auto& dirtyActor : mDirtyLayoutSubTrees )
     {
-      BaseObject* dirtyActor = *it;
-
       // Need to test if actor is valid (could have been deleted and had the pointer cleared)
       if( dirtyActor )
       {
-        // We know that BaseObject is a base class of Internal::Actor but need to instruct the compiler to do the cast
-        Dali::Actor actor = Dali::Actor( reinterpret_cast<Dali::Internal::Actor*>( dirtyActor ) );
-
-        // Only negotiate actors that are on stage
-        if( actor.OnStage() )
+        // Only negotiate actors that are on the scene
+        if( dirtyActor->OnScene() )
         {
-          Dali::Actor parent = actor.GetParent();
-          QueueActor( actor, *mRelayoutStack, ( parent ) ? Vector2( parent.GetTargetSize() ) : mStageSize );
+          Internal::Actor* parent = dirtyActor->GetParent();
+          QueueActor( dirtyActor, *mRelayoutStack, ( parent ) ? Vector2( parent->GetTargetSize() ) : dirtyActor->GetScene().GetSize() );
         }
       }
     }
@@ -486,7 +443,7 @@ void RelayoutController::Relayout()
 
         if( actorImpl.RelayoutRequired() )
         {
-          DALI_LOG_INFO( gLogFilter, Debug::General, "[Internal::RelayoutController::Relayout] Negotiating %p %s %s (%.2f, %.2f)\n", &actorImpl, actor.GetTypeName().c_str(), actor.GetName().c_str(), size.width, size.height );
+          DALI_LOG_INFO( gLogFilter, Debug::General, "[Internal::RelayoutController::Relayout] Negotiating %p %s %s (%.2f, %.2f)\n", &actorImpl, actor.GetTypeName().c_str(), actor.GetProperty< std::string >( Dali::Actor::Property::NAME ).c_str(), size.width, size.height );
 
           // 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.
@@ -528,13 +485,11 @@ void RelayoutController::SetProcessingCoreEvents( bool processingEvents )
 void RelayoutController::FindAndZero( const RawActorList& list, const Dali::RefObject* object )
 {
   // Object has been destroyed so clear it from this list
-  for( RawActorList::Iterator it = list.Begin(), itEnd = list.End(); it != itEnd; ++it )
+  for( auto& actor : list )
   {
-    BaseObject* actor = *it;
-
     if( actor && ( actor == object ) )
     {
-      *it = NULL;    // Reset the pointer in the list. We don't want to remove it in case something is iterating over the list.
+      actor = nullptr; // Reset the pointer in the list. We don't want to remove it in case something is iterating over the list.
     }
   }
 }