Add Window System's Initialize() and ShutDown() 48/294048/8
authorWonsik Jung <sidein@samsung.com>
Mon, 12 Jun 2023 07:03:26 +0000 (16:03 +0900)
committerWonsik Jung <sidein@samsung.com>
Tue, 13 Jun 2023 05:07:58 +0000 (14:07 +0900)
Add Window System's Initailize() and ShutDown() for UI Threading.
Because Window's Initialize() and ShutDown() should be called in UI Thread when UI Threading is enabled.

Change-Id: I8d1a4e8e85366d31efa1c0690d436b409f4c791d

dali/internal/adaptor/common/application-impl.cpp

index 6590889..fa6abcf 100644 (file)
@@ -125,8 +125,6 @@ Application::Application(int* argc, char** argv[], const std::string& stylesheet
     mUseUiThread = true;
   }
 
-  WindowSystem::Initialize();
-
   mCommandLineOptions = new CommandLineOptions(argc, argv);
   mFramework          = new Framework(*this, *this, argc, argv, applicationType, mUseUiThread);
   mUseRemoteSurface   = (applicationType == Framework::WATCH);
@@ -142,12 +140,19 @@ Application::~Application()
   }
 
   mMainWindow.Reset();
-  delete mAdaptor;
-  delete mAdaptorBuilder;
+
   delete mCommandLineOptions;
   delete mFramework;
 
-  WindowSystem::Shutdown();
+  // Application is created in Main thread whether UI Threading is enabled or not.
+  // But some resources are created in Main thread or UI thread.
+  // The below code is for the resource are created in Main thread.
+  if(!mUseUiThread)
+  {
+    delete mAdaptor;
+    delete mAdaptorBuilder;
+    WindowSystem::Shutdown();
+  }
 }
 
 void Application::StoreWindowPositionSize(PositionSize positionSize)
@@ -204,6 +209,8 @@ void Application::CreateWindow()
 {
   Internal::Adaptor::Window* window;
 
+  WindowSystem::Initialize();
+
   if(mLaunchpadState != Launchpad::PRE_INITIALIZED)
   {
     if(mWindowPositionSize.width == 0 && mWindowPositionSize.height == 0)
@@ -356,6 +363,15 @@ void Application::OnTerminate()
   }
 
   mMainWindow.Reset(); // This only resets (clears) the default Window
+
+  // If DALi's UI Thread works, some resources are created in UI Thread, not Main thread.
+  // For that case, these resource should be deleted in UI Thread.
+  if(mUseUiThread)
+  {
+    delete mAdaptor;
+    delete mAdaptorBuilder;
+    WindowSystem::Shutdown();
+  }
 }
 
 void Application::OnPause()