Delete the Scene when requested
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / layer-impl.cpp
index 11f835a..5d184b0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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,7 +26,8 @@
 #include <dali/public-api/object/type-registry.h>
 #include <dali/internal/event/actors/layer-list.h>
 #include <dali/internal/event/common/property-helper.h>
-#include <dali/internal/event/common/stage-impl.h>
+#include <dali/internal/event/common/scene-impl.h>
+#include <dali/internal/event/common/event-thread-services.h>
 
 using Dali::Internal::SceneGraph::UpdateManager;
 
@@ -87,7 +88,7 @@ LayerPtr Layer::New()
   // create node, nodes are owned by UpdateManager
   SceneGraph::Layer* layerNode = SceneGraph::Layer::New();
   OwnerPointer< SceneGraph::Node > transferOwnership( layerNode );
-  AddNodeMessage( Stage::GetCurrent()->GetUpdateManager(), transferOwnership );
+  AddNodeMessage( EventThreadServices::Get().GetUpdateManager(), transferOwnership );
   LayerPtr layer( new Layer( Actor::LAYER, *layerNode ) );
 
   // Second-phase construction
@@ -96,12 +97,12 @@ LayerPtr Layer::New()
   return layer;
 }
 
-LayerPtr Layer::NewRoot( LayerList& layerList, UpdateManager& manager )
+LayerPtr Layer::NewRoot( LayerList& layerList )
 {
   // create node, nodes are owned by UpdateManager
   SceneGraph::Layer* rootLayer = SceneGraph::Layer::New();
   OwnerPointer< SceneGraph::Layer > transferOwnership( rootLayer );
-  InstallRootMessage( manager, transferOwnership );
+  InstallRootMessage( EventThreadServices::Get().GetUpdateManager(), transferOwnership );
 
   LayerPtr root( new Layer( Actor::ROOT_LAYER, *rootLayer ) );
 
@@ -138,6 +139,16 @@ void Layer::OnInitialize()
 
 Layer::~Layer()
 {
+  if ( mIsRoot )
+  {
+    // Guard to allow handle destruction after Core has been destroyed
+    if( EventThreadServices::IsCoreRunning() )
+    {
+      UninstallRootMessage( GetEventThreadServices().GetUpdateManager(), &GetSceneLayerOnStage() );
+
+      GetEventThreadServices().UnregisterObject( this );
+    }
+  }
 }
 
 unsigned int Layer::GetDepth() const
@@ -257,10 +268,9 @@ void Layer::SetClippingBox(int x, int y, int width, int height)
     // Convert mClippingBox to GL based coordinates (from bottom-left)
     ClippingBox clippingBox( mClippingBox );
 
-    StagePtr stage = Stage::GetCurrent();
-    if( stage )
+    if( mScene )
     {
-      clippingBox.y = static_cast<int32_t>( stage->GetSize().height ) - clippingBox.y - clippingBox.height;
+      clippingBox.y = static_cast<int32_t>( mScene->GetSize().height ) - clippingBox.y - clippingBox.height;
 
       // layerNode is being used in a separate thread; queue a message to set the value
       SetClippingBoxMessage( GetEventThreadServices(), GetSceneLayerOnStage(), clippingBox );
@@ -323,7 +333,6 @@ void Layer::OnStageConnectionInternal()
     DALI_ASSERT_DEBUG( NULL == mLayerList );
 
     // Find the ordered layer-list
-    // This is different for Layers added via Integration::GetSystemOverlay()
     for ( Actor* parent = mParent; parent != NULL; parent = parent->GetParent() )
     {
       if( parent->IsLayer() )