Supports Pre-Initialized for UI Threading 40/295040/8
authorWonsik Jung <sidein@samsung.com>
Fri, 30 Jun 2023 07:53:19 +0000 (16:53 +0900)
committerWonsik Jung <sidein@samsung.com>
Tue, 4 Jul 2023 01:48:51 +0000 (10:48 +0900)
This patch is to support pre-initialized using Tizen Preloader for UI Threading.
Next step, the related feature will be refactoring using factory pattern.

Change-Id: Ib143b02906970fb878ef21c423e5aaebad3d967b

dali/internal/adaptor/android/framework-android.cpp
dali/internal/adaptor/androidjni/framework-androidjni.cpp
dali/internal/adaptor/common/application-impl.cpp
dali/internal/adaptor/common/application-impl.h
dali/internal/adaptor/common/framework.h
dali/internal/adaptor/libuv/framework-libuv.cpp
dali/internal/adaptor/macos/framework-mac.mm
dali/internal/adaptor/tizen-wayland/framework-tizen.cpp
dali/internal/adaptor/ubuntu/framework-ubuntu.cpp
dali/internal/adaptor/windows/framework-win.cpp

index c0ccb137598754954a8902117721b94df7034029..e08b03d55964bdff2dc1c62e0ca1bd48646563c4 100644 (file)
@@ -668,6 +668,49 @@ bool FrameworkAndroid::AppStatusHandler(int type, void* data)
   return true;
 }
 
+/**
+ * Impl for Pre-Initailized using UI Thread.
+ */
+struct UIThreadLoader::Impl
+{
+  // Constructor
+
+  Impl(void *data)
+  {
+  }
+
+  ~Impl()
+  {
+  }
+
+  void Run(Runner runner)
+  {
+  }
+
+private:
+  // Undefined
+  Impl(const Impl& impl);
+  Impl& operator=(const Impl& impl);
+};
+
+/**
+ * UI Thread loader to support Pre-Initailized using UI Thread.
+ */
+UIThreadLoader::UIThreadLoader(int* argc, char*** argv)
+: mArgc(argc),
+  mArgv(argv),
+  mImpl(nullptr)
+{
+}
+
+UIThreadLoader::~UIThreadLoader()
+{
+}
+
+void UIThreadLoader::Run(Runner runner)
+{
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index d699f7625eea80e76dd20a0ab154dc51773dd082..4fd36c1d1f46a02062369cc895b9d2b458d0901d 100644 (file)
@@ -191,6 +191,49 @@ bool FrameworkAndroidJni::AppStatusHandler(int type, void* data)
   return true;
 }
 
+/**
+ * Impl for Pre-Initailized using UI Thread.
+ */
+struct UIThreadLoader::Impl
+{
+  // Constructor
+
+  Impl(void *data)
+  {
+  }
+
+  ~Impl()
+  {
+  }
+
+  void Run(Runner runner)
+  {
+  }
+
+private:
+  // Undefined
+  Impl(const Impl& impl);
+  Impl& operator=(const Impl& impl);
+};
+
+/**
+ * UI Thread loader to support Pre-Initailized using UI Thread.
+ */
+UIThreadLoader::UIThreadLoader(int* argc, char*** argv)
+: mArgc(argc),
+  mArgv(argv),
+  mImpl(nullptr)
+{
+}
+
+UIThreadLoader::~UIThreadLoader()
+{
+}
+
+void UIThreadLoader::Run(Runner runner)
+{
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index d81c67b7e987fbaf543bf21979325e9a7383b2bc..9bad3be00722d5fa0ed04e640913b03c587b9b55 100644 (file)
@@ -81,11 +81,35 @@ void Application::PreInitialize(int* argc, char** argv[])
 {
   if(!gPreInitializedApplication)
   {
+    char* retEnv = std::getenv("TIZEN_UI_THREAD");
+    bool isUseUIThread = false;
+    if(retEnv)
+    {
+      std::string uiThreadEnv = retEnv;
+      std::string enabledString = "true";
+      if(uiThreadEnv == enabledString)
+      {
+        isUseUIThread = true;
+      }
+    }
+
     Dali::TextAbstraction::FontClientPreInitialize();
     WindowData windowData;
-    gPreInitializedApplication                  = new Application(argc, argv, "", Framework::NORMAL, false, windowData);
+    gPreInitializedApplication                  = new Application(argc, argv, "", Framework::NORMAL, isUseUIThread, windowData);
     gPreInitializedApplication->mLaunchpadState = Launchpad::PRE_INITIALIZED;
-    gPreInitializedApplication->CreateWindow(); // Only create window
+    if(isUseUIThread)
+    {
+      DALI_LOG_RELEASE_INFO("PRE_INITIALIZED with UI Threading");
+      gPreInitializedApplication->mUIThreadLoader = new UIThreadLoader(argc, argv);
+      gPreInitializedApplication->mUIThreadLoader->Run([&](){gPreInitializedApplication->CreateWindow();});
+    }
+    else
+    {
+      DALI_LOG_RELEASE_INFO("Only PRE_INITIALIZED");
+      gPreInitializedApplication->CreateWindow(); // Only create window
+    }
+
+
   }
 }
 
@@ -112,7 +136,8 @@ Application::Application(int* argc, char** argv[], const std::string& stylesheet
   mDefaultWindowType(windowData.GetWindowType()),
   mUseUiThread(useUiThread),
   mIsSystemInitialized(false),
-  mSlotDelegate(this)
+  mSlotDelegate(this),
+  mUIThreadLoader(nullptr)
 {
   // Set mName from command-line args
   if(argc && (*argc > 0))
@@ -157,6 +182,13 @@ Application::~Application()
       WindowSystem::Shutdown();
     }
   }
+  else
+  {
+    if(mUIThreadLoader)
+    {
+      delete mUIThreadLoader;
+    }
+  }
 }
 
 void Application::StoreWindowPositionSize(PositionSize positionSize)
@@ -216,6 +248,8 @@ void Application::CreateWindow()
   windowData.SetTransparency(mMainWindowMode);
   windowData.SetWindowType(mDefaultWindowType);
 
+  DALI_LOG_RELEASE_INFO("Create Default Window");
+
   WindowSystem::Initialize();
   mIsSystemInitialized = true;
 
@@ -318,6 +352,7 @@ void Application::OnInit()
   // If an application was pre-initialized, a window was made in advance
   if(mLaunchpadState == Launchpad::NONE)
   {
+    DALI_LOG_RELEASE_INFO("default Window is created in standalone");
     CreateWindow();
   }
 
index 8127322607505046b33431fca532c60034c0362c..914664a9f4c3bb9e04d7240215770bac7c6e993a 100644 (file)
@@ -544,6 +544,7 @@ private:
 
   SlotDelegate<Application> mSlotDelegate;
 
+  UIThreadLoader* mUIThreadLoader;
   static ApplicationPtr gPreInitializedApplication;
 };
 
index 23244ebc0114748fc93328270158357fea38354a..894bb8839f3b467dcd77632902a9821c552343b2 100644 (file)
@@ -332,7 +332,7 @@ private:
 
 private:
   // Undefined
-  Framework(const Framework&) = delete;
+  Framework(const Framework&)      = delete;
   Framework& operator=(Framework&) = delete;
 
 protected:
@@ -345,6 +345,43 @@ protected:
   bool                          mRunning;
 };
 
+class UIThreadLoader
+{
+public:
+  using Runner = std::function<void()>;
+
+  /**
+   * Constructor
+   * @param[in] argc A pointer to the number of arguments.
+   * @param[in] argv A pointer the the argument list.
+   */
+  UIThreadLoader(int* argc, char*** argv);
+
+  /**
+   * Destructor
+   */
+  ~UIThreadLoader();
+
+public:
+  /**
+   * Runs the main loop of framework
+   */
+  void Run(Runner runner);
+
+private:
+  // Undefined
+  UIThreadLoader(const UIThreadLoader&);
+  UIThreadLoader& operator=(UIThreadLoader&);
+
+private:
+  int*    mArgc;
+  char*** mArgv;
+
+private: // impl members
+  struct Impl;
+  Impl* mImpl;
+};
+
 } // namespace Adaptor
 
 } // namespace Internal
index bce2382662ec346005ff494ec499d77807e9353b..cc32e058afb7186d955aa8687d6981e2a5d8f8fc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -109,6 +109,49 @@ void FrameworkLibuv::Quit()
   mImpl->Quit();
 }
 
+/**
+ * Impl for Pre-Initailized using UI Thread.
+ */
+struct UIThreadLoader::Impl
+{
+  // Constructor
+
+  Impl(void *data)
+  {
+  }
+
+  ~Impl()
+  {
+  }
+
+  void Run(Runner runner)
+  {
+  }
+
+private:
+  // Undefined
+  Impl(const Impl& impl);
+  Impl& operator=(const Impl& impl);
+};
+
+/**
+ * UI Thread loader to support Pre-Initailized using UI Thread.
+ */
+UIThreadLoader::UIThreadLoader(int* argc, char*** argv)
+: mArgc(argc),
+  mArgv(argv),
+  mImpl(nullptr)
+{
+}
+
+UIThreadLoader::~UIThreadLoader()
+{
+}
+
+void UIThreadLoader::Run(Runner runner)
+{
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index cb7b71fe78c173b9f6dfbe6c502575ef3e2b6343..8f88f547a1fd765ad1df483aeb2d3152c6acf0f6 100644 (file)
@@ -120,6 +120,49 @@ bool FrameworkMac::AppStatusHandler(int type, void *)
   return true;
 }
 
+/**
+ * Impl for Pre-Initailized using UI Thread.
+ */
+struct UIThreadLoader::Impl
+{
+  // Constructor
+
+  Impl(void *data)
+  {
+  }
+
+  ~Impl()
+  {
+  }
+
+  void Run(Runner runner)
+  {
+  }
+
+private:
+  // Undefined
+  Impl(const Impl& impl);
+  Impl& operator=(const Impl& impl);
+};
+
+/**
+ * UI Thread loader to support Pre-Initailized using UI Thread.
+ */
+UIThreadLoader::UIThreadLoader(int* argc, char*** argv)
+: mArgc(argc),
+  mArgv(argv),
+  mImpl(nullptr)
+{
+}
+
+UIThreadLoader::~UIThreadLoader()
+{
+}
+
+void UIThreadLoader::Run(Runner runner)
+{
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index 46fcc4bf6771dd2bc2f066e5945d3b4c38a5c720..ec679e3e5ce8ac26471a3c4f9cf440ea19550e5e 100644 (file)
@@ -29,6 +29,7 @@
 #include <widget_base.h>
 #include <app_core_ui_base.hh>
 #include <app_event_internal.hh>
+#include <app_core_ui_thread_base.hh>
 
 // CONDITIONAL INCLUDES
 #ifdef APPCORE_WATCH_AVAILABLE
@@ -1396,6 +1397,81 @@ std::string FrameworkTizen::GetRegion() const
   return mImpl->GetRegion();
 }
 
+/**
+ * Impl for Pre-Initailized using UI Thread.
+ */
+struct UIThreadLoader::Impl
+{
+  // Constructor
+  Impl(void *data)
+  {
+    mUIThreadLoader = static_cast<UIThreadLoader*>(data);
+    mAppCoreUiThreadBase = new AppCoreUiThreadBase();
+    print_log(DLOG_INFO, "DALI", "%s: %s(%d) > Create mAppCoreUiThreadBase(%p)", __MODULE__, __func__, __LINE__, mAppCoreUiThreadBase);
+  }
+
+  // Destructor
+  ~Impl()
+  {
+    if(mAppCoreUiThreadBase)
+    {
+      mAppCoreUiThreadBase->Exit();
+      delete mAppCoreUiThreadBase;
+    }
+  }
+
+  /**
+   * Runs to work create window in UI thread when application is pre-initialized.
+   */
+  void Run(Runner runner)
+  {
+    mAppCoreUiThreadBase->Post(runner);
+    mAppCoreUiThreadBase->Run(*(mUIThreadLoader->mArgc), *(mUIThreadLoader->mArgv));
+  }
+
+private:
+  // Undefined
+  Impl(const Impl& impl);
+  Impl& operator=(const Impl& impl);
+
+  // Data
+  AppCoreUiThreadBase* mAppCoreUiThreadBase;
+  UIThreadLoader*      mUIThreadLoader;
+};
+
+/**
+ * UI Thread loader to support Pre-Initailized using UI Thread.
+ */
+UIThreadLoader::UIThreadLoader(int* argc, char*** argv)
+: mArgc(argc),
+  mArgv(argv),
+  mImpl(nullptr)
+{
+  if(mArgc == nullptr || mArgv == nullptr)
+  {
+    mArgc = const_cast<int*>(&gTizenDummyArgc);
+    mArgv = const_cast<char***>(reinterpret_cast<const char***>(&gTizenDummyArgv));
+  }
+
+  mImpl = new Impl(this);
+}
+
+UIThreadLoader::~UIThreadLoader()
+{
+  if(mImpl)
+  {
+    delete mImpl;
+  }
+}
+
+/**
+ * Runs to work create window in UI thread when application is pre-initialized.
+ */
+void UIThreadLoader::Run(Runner runner)
+{
+  mImpl->Run(runner);
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index ab4f3535b550e2eaf381272328809043a059e984..7ad9005aac122da561cba34ef9bc60aa0b36647e 100644 (file)
@@ -71,6 +71,48 @@ void FrameworkUbuntu::InitThreads()
   XInitThreads();
 }
 
+/**
+ * Impl for Pre-Initailized using UI Thread.
+ */
+struct UIThreadLoader::Impl
+{
+  // Constructor
+  Impl(void *data)
+  {
+  }
+
+  ~Impl()
+  {
+  }
+
+  void Run(Runner runner)
+  {
+  }
+
+private:
+  // Undefined
+  Impl(const Impl& impl);
+  Impl& operator=(const Impl& impl);
+};
+
+/**
+ * UI Thread loader to support Pre-Initailized using UI Thread.
+ */
+UIThreadLoader::UIThreadLoader(int* argc, char*** argv)
+: mArgc(argc),
+  mArgv(argv),
+  mImpl(nullptr)
+{
+}
+
+UIThreadLoader::~UIThreadLoader()
+{
+}
+
+void UIThreadLoader::Run(Runner runner)
+{
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index 90e3fa91d271debeedc85f504b7bce834859d142..bc2c31e15ba45d5c3112d09430bcbc36b7a3780f 100644 (file)
@@ -106,6 +106,51 @@ void FrameworkWin::Quit()
   mObserver.OnTerminate();\r
 }\r
 \r
+/**\r
+ * Impl for Pre-Initailized using UI Thread.\r
+ */\r
+struct UIThreadLoader::Impl\r
+{\r
+  // Constructor\r
+  Impl(void *data)\r
+  {\r
+  }\r
+\r
+  ~Impl()\r
+  {\r
+  }\r
+\r
+  /**\r
+   * Runs the main loop of framework\r
+   */\r
+  void Run(Runner runner)\r
+  {\r
+  }\r
+\r
+private:\r
+  // Undefined\r
+  Impl(const Impl& impl);\r
+  Impl& operator=(const Impl& impl);\r
+};\r
+\r
+/**\r
+ * UI Thread loader to support Pre-Initailized using UI Thread.\r
+ */\r
+UIThreadLoader::UIThreadLoader(int* argc, char*** argv)\r
+: mArgc(argc),\r
+  mArgv(argv),\r
+  mImpl(nullptr)\r
+{\r
+}\r
+\r
+UIThreadLoader::~UIThreadLoader()\r
+{\r
+}\r
+\r
+void UIThreadLoader::Run(Runner runner)\r
+{\r
+}\r
+\r
 } // namespace Adaptor\r
 \r
 } // namespace Internal\r