Merge "Added memory pool logging" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / relayout-controller-impl.cpp
index 653b20a..dd0f98d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -26,6 +26,7 @@
 // INTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/render-controller.h>
+#include <dali/integration-api/trace.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>
@@ -38,6 +39,8 @@ namespace Internal
 {
 namespace
 {
+DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
+
 #if defined(DEBUG_ENABLED)
 
 Integration::Log::Filter* gLogFilter(Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_RELAYOUT_CONTROLLER"));
@@ -125,7 +128,15 @@ RelayoutController::~RelayoutController()
 
 RelayoutController* RelayoutController::Get()
 {
-  return &ThreadLocalStorage::Get().GetRelayoutController();
+  // There was crash when destroying actors and the ResizePolicy is USE_NATURAL_SIZE
+  // The ThreadLocalStorage::Get() only retrieve STL without checking if it exists.
+  // The caller of RelayoutController::Get() should check if RelayoutController is not null.
+  if(ThreadLocalStorage::Created())
+  {
+    return &ThreadLocalStorage::Get().GetRelayoutController();
+  }
+
+  return nullptr;
 }
 
 void RelayoutController::QueueActor(Internal::Actor* actor, RelayoutContainer& actors, Vector2 size)
@@ -428,6 +439,7 @@ void RelayoutController::Relayout()
     // 2. Iterate through the stack until it's empty.
     if(mRelayoutStack->Size() > 0)
     {
+      DALI_TRACE_BEGIN(gTraceFilter, "DALI_RELAYOUT");
       PRINT_HIERARCHY;
 
       while(mRelayoutStack->Size() > 0)
@@ -438,17 +450,13 @@ void RelayoutController::Relayout()
         Actor& actorImpl = GetImplementation(actor);
         mRelayoutStack->PopBack();
 
-        if(actorImpl.RelayoutRequired())
+        if(actorImpl.RelayoutRequired() && actorImpl.OnScene())
         {
           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.
-
           actorImpl.NegotiateSize(size, *mRelayoutStack);
-
-          // Reset the flag so that size negotiation will respect the actor's original resize policy
-          actorImpl.SetUseAssignedSize(false);
         }
       }
 
@@ -456,6 +464,7 @@ void RelayoutController::Relayout()
       mRelayoutInfoAllocator.ResetMemoryPool();
 
       PRINT_HIERARCHY;
+      DALI_TRACE_END(gTraceFilter, "DALI_RELAYOUT");
     }
 
     mPerformingRelayout = false;
@@ -491,6 +500,11 @@ void RelayoutController::FindAndZero(const RawActorList& list, const Dali::RefOb
   }
 }
 
+uint32_t RelayoutController::GetMemoryPoolCapacity()
+{
+  return mRelayoutInfoAllocator.GetCapacity();
+}
+
 } // namespace Internal
 
 } // namespace Dali