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 c0ccb13..e08b03d 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 d699f76..4fd36c1 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 d81c67b..9bad3be 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 8127322..914664a 100644 (file)
@@ -544,6 +544,7 @@ private:
 
   SlotDelegate<Application> mSlotDelegate;
 
+  UIThreadLoader* mUIThreadLoader;
   static ApplicationPtr gPreInitializedApplication;
 };
 
index 23244eb..894bb88 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 bce2382..cc32e05 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 cb7b71f..8f88f54 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 46fcc4b..ec679e3 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 ab4f353..7ad9005 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 90e3fa9..bc2c31e 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