[5.0] Pause adaptor when the window is hidden while initailizing
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / adaptor-impl.cpp
index 4d1879f..959f6f5 100755 (executable)
@@ -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.
@@ -388,6 +388,12 @@ void Adaptor::Pause()
 
     // Ensure any messages queued during pause callbacks are processed by doing another update.
     RequestUpdateOnce();
+
+    DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Paused\n" );
+  }
+  else
+  {
+    DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Not paused [%d]\n", mState );
   }
 }
 
@@ -416,6 +422,12 @@ void Adaptor::Resume()
 
     // Do at end to ensure our first update/render after resumption includes the processed messages as well
     mThreadController->Resume();
+
+    DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Resumed\n");
+  }
+  else
+  {
+    DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Not resumed [%d]\n", mState );
   }
 }
 
@@ -456,6 +468,8 @@ void Adaptor::Stop()
     mCallbackManager->Stop();
 
     mState = STOPPED;
+
+    DALI_LOG_RELEASE_INFO( "Adaptor::Stop\n" );
   }
 }
 
@@ -500,9 +514,7 @@ void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& newSurface )
   newDefaultWindow.nativeWindow = nativeWindow;
   newDefaultWindow.surface = &newSurface;
 
-  // Must delete the old Window first before replacing it with the new one
   WindowPane oldDefaultWindow = mWindowFrame.front();
-  oldDefaultWindow.surface->DestroySurface();
 
   // Update WindowFrame
   std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
@@ -514,6 +526,10 @@ void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& newSurface )
 
   // This method blocks until the render thread has completed the replace.
   mThreadController->ReplaceSurface( newDefaultWindow.surface );
+
+  // Must delete the old Window only after the render thread has completed the replace
+  oldDefaultWindow.surface->DestroySurface();
+  oldDefaultWindow.surface = nullptr;
 }
 
 RenderSurface& Adaptor::GetSurface() const
@@ -861,7 +877,7 @@ void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
 
 void Adaptor::OnWindowShown()
 {
-  if ( PAUSED_WHILE_HIDDEN == mState )
+  if( PAUSED_WHILE_HIDDEN == mState )
   {
     // Adaptor can now be resumed
     mState = PAUSED;
@@ -871,16 +887,32 @@ void Adaptor::OnWindowShown()
     // Force a render task
     RequestUpdateOnce();
   }
+  else
+  {
+    DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState );
+  }
 }
 
 void Adaptor::OnWindowHidden()
 {
-  if ( RUNNING == mState )
+  if( RUNNING == mState || READY == mState )
   {
-    Pause();
+    if( mState == RUNNING )
+    {
+      Pause();
 
-    // Adaptor cannot be resumed until the window is shown
-    mState = PAUSED_WHILE_HIDDEN;
+      // Adaptor cannot be resumed until the window is shown
+      mState = PAUSED_WHILE_HIDDEN;
+    }
+    else  // mState is READY
+    {
+      // Pause the adaptor after the state gets RUNNING
+      mState = PAUSED_WHILE_INITIALIZING;
+    }
+  }
+  else
+  {
+    DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState );
   }
 }
 
@@ -918,7 +950,22 @@ void Adaptor::NotifySceneCreated()
   // Process after surface is created (registering to remote surface provider if required)
   SurfaceInitialized();
 
-  mState = RUNNING;
+  if( mState != PAUSED_WHILE_INITIALIZING )
+  {
+    mState = RUNNING;
+
+    DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is running\n" );
+  }
+  else
+  {
+    mState = RUNNING;
+
+    Pause();
+
+    mState = PAUSED_WHILE_HIDDEN;
+
+    DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is paused\n" );
+  }
 }
 
 void Adaptor::NotifyLanguageChanged()