Fix the crash when it assumes the platform does not support multiple windows as GL...
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / application-impl.cpp
index 94196b7..29e1b84 100755 (executable)
@@ -81,9 +81,7 @@ void Application::PreInitialize( int* argc, char** argv[] )
   if( !gPreInitializedApplication )
   {
     gPreInitializedApplication = new Application ( argc, argv, "", Dali::Application::OPAQUE, PositionSize(), Framework::NORMAL );
-
     gPreInitializedApplication->CreateWindow();    // Only create window
-
     gPreInitializedApplication->mLaunchpadState = Launchpad::PRE_INITIALIZED;
 
     //Make DefaultFontDescription cached
@@ -230,7 +228,6 @@ void Application::OnInit()
   mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
 
   CreateAdaptorBuilder();
-
   // If an application was pre-initialized, a window was made in advance
   if( mLaunchpadState == Launchpad::NONE )
   {
@@ -350,6 +347,30 @@ void Application::OnMemoryLow( Dali::DeviceStatus::Memory::Status status )
   mLowMemorySignal.Emit( status );
 }
 
+void Application::OnSurfaceCreated( Any newSurface )
+{
+  void* newWindow = AnyCast< void* >( newSurface );
+  void* oldWindow = AnyCast< void* >( mMainWindow.GetNativeHandle() );
+  if( oldWindow != newWindow )
+  {
+    auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
+    std::unique_ptr< WindowRenderSurface > newSurfacePtr
+      = renderSurfaceFactory->CreateWindowRenderSurface( PositionSize(), newSurface, true );
+
+    mAdaptor->ReplaceSurface( mMainWindow, *newSurfacePtr.release() );
+  }
+}
+
+void Application::OnSurfaceDestroyed( Any surface )
+{
+  void* windowToDelete = AnyCast< void* >( surface );
+  void* oldWindow = AnyCast< void* >( mMainWindow.GetNativeHandle() );
+  if( oldWindow == windowToDelete )
+  {
+    mAdaptor->DeleteSurface( mAdaptor->GetSurface() );
+  }
+}
+
 void Application::OnResize(Dali::Adaptor& adaptor)
 {
   Dali::Application application(this);