Merge "Trace use scope macro instead of begin-end" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / application-impl.h
index 4d3a4eb..8e334a7 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_APPLICATION_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
 #include <dali/public-api/object/base-object.h>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/adaptor-framework/application.h>
 #include <dali/devel-api/common/singleton-service.h>
+#include <dali/public-api/adaptor-framework/application.h>
 
+#include <dali/internal/adaptor/common/adaptor-builder-impl.h>
 #include <dali/internal/adaptor/common/framework.h>
 #include <dali/internal/system/common/environment-options.h>
-#include <dali/internal/adaptor/common/adaptor-builder-impl.h>
 
 namespace Dali
 {
@@ -37,21 +37,18 @@ class Window;
 
 namespace Internal
 {
-
 namespace Adaptor
 {
-
 namespace Launchpad
 {
-
 /**
  * @brief Launchpad is used to improve application launch performance.
  * When an application is pre-initialized, so files are preloaded, some functions are initialized and a window is made in advance.
  */
 enum State
 {
-  NONE,              ///< The default state
-  PRE_INITIALIZED    ///< Application is pre-initialized.
+  NONE,           ///< The default state
+  PRE_INITIALIZED ///< Application is pre-initialized.
 };
 
 } // namespace Launchpad
@@ -67,35 +64,35 @@ typedef IntrusivePtr<Application> ApplicationPtr;
 /**
  * Implementation of the Application class.
  */
-class Application : public BaseObject, public Framework::Observer
+class Application : public BaseObject, public Framework::Observer, public Framework::TaskObserver
 {
 public:
-
-  typedef Dali::Application::LowBatterySignalType LowBatterySignalType;
-  typedef Dali::Application::LowMemorySignalType LowMemorySignalType;
-  typedef Dali::Application::AppSignalType AppSignalType;
-  typedef Dali::Application::AppControlSignalType AppControlSignalType;
-  typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
+  typedef Dali::Application::LowBatterySignalType               LowBatterySignalType;
+  typedef Dali::Application::LowMemorySignalType                LowMemorySignalType;
+  typedef Dali::Application::DeviceOrientationChangedSignalType DeviceOrientationChangedSignalType;
+  typedef Dali::Application::AppSignalType                      AppSignalType;
+  typedef Dali::Application::AppControlSignalType               AppControlSignalType;
+  typedef Dali::Application::WINDOW_MODE                        WINDOW_MODE;
 
   /**
    * Create a new application
-   * @param[in]  argc         A pointer to the number of arguments
-   * @param[in]  argv         A pointer to the argument list
-   * @param[in]  stylesheet   The path to user defined theme file
-   * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
-   * @param[in]  positionSize A position and a size of the window
-   * @param[in]  applicationType  A member of Dali::Framework::Type
+   * @param[in]  argc              A pointer to the number of arguments
+   * @param[in]  argv              A pointer to the argument list
+   * @param[in]  stylesheet        The path to user defined theme file
+   * @param[in]  windowMode        A member of Dali::Application::WINDOW_MODE
+   * @param[in]  positionSize      A position and a size of the window
+   * @param[in]  applicationType   A member of Dali::Framework::Type
+   * @param[in]  type              It is window type for default window.
+   * @param[in]  useUiThread       True if the application would create a UI thread
    */
-  static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet,
-    WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
+  static ApplicationPtr New(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType, WindowType type, bool useUiThread);
 
   /**
    * @copydoc Dali::DevelApplication::PreInitialize()
    */
-  static void PreInitialize( int* argc, char** argv[] );
+  static void PreInitialize(int* argc, char** argv[]);
 
 public:
-
   /**
    * @copydoc Dali::Application::MainLoop()
    */
@@ -114,7 +111,7 @@ public:
   /**
    * @copydoc Dali::Application::AddIdle()
    */
-  bool AddIdle( CallbackBase* callback, bool hasReturnValue );
+  bool AddIdle(CallbackBase* callback, bool hasReturnValue);
 
   /**
    * @copydoc Dali::Application::GetAdaptor();
@@ -158,9 +155,18 @@ public:
    */
   static ApplicationPtr GetPreInitializedApplication();
 
-public: // From Framework::Observer
+  /**
+   * Stores PositionSize of window
+   */
+  void StoreWindowPositionSize(PositionSize positionSize);
 
   /**
+   * @copydoc Dali::DevelApplication::GetRenderThreadId()
+   */
+  int32_t GetRenderThreadId() const;
+
+public: // From Framework::Observer
+  /**
    * Called when the framework is initialised.
    */
   void OnInit() override;
@@ -181,10 +187,10 @@ public: // From Framework::Observer
   void OnResume() override;
 
   /**
-  * Called when the framework received AppControlSignal.
-  * @param[in] The bundle data of AppControl event.
-  */
-  void OnAppControl(void *data) override;
+   * Called when the framework received AppControlSignal.
+   * @param[in] The bundle data of AppControl event.
+   */
+  void OnAppControl(voiddata) override;
 
   /**
    * Called when the framework informs the application that it should reset itself.
@@ -197,38 +203,88 @@ public: // From Framework::Observer
   void OnLanguageChanged() override;
 
   /**
-  * Called when the framework informs the application that the region of the device has changed.
-  */
+   * Called when the framework informs the application that the region of the device has changed.
+   */
   void OnRegionChanged() override;
 
   /**
-  * Called when the framework informs the application that the battery level of the device is low.
-  */
-  void OnBatteryLow( Dali::DeviceStatus::Battery::Status status ) override;
+   * Called when the framework informs the application that the battery level of the device is low.
+   */
+  void OnBatteryLow(Dali::DeviceStatus::Battery::Status status) override;
+
+  /**
+   * Called when the framework informs the application that the memory level of the device is low.
+   */
+  void OnMemoryLow(Dali::DeviceStatus::Memory::Status status) override;
 
   /**
-  * Called when the framework informs the application that the memory level of the device is low.
-  */
-  void OnMemoryLow( Dali::DeviceStatus::Memory::Status status ) override;
+   * Called when the framework informs the application that device orientation is changed.
+   */
+  void OnDeviceOrientationChanged(Dali::DeviceStatus::Orientation::Status status) override;
 
   /**
    * Called when the framework informs the application that the platform surface is created.
    */
-  void OnSurfaceCreated( Any newSurface ) override;
+  void OnSurfaceCreated(Any newSurface) override;
 
   /**
    * Called when the framework informs the application that the platform surface is destroyed.
    */
-  void OnSurfaceDestroyed( Any newSurface ) override;
+  void OnSurfaceDestroyed(Any newSurface) override;
 
-public:
+public: // From Framework::TaskObserver
+  /**
+   * Called when the framework is initialised.
+   */
+  void OnTaskInit() override;
+
+  /**
+   * Called when the framework is terminated.
+   */
+  void OnTaskTerminate() override;
+
+  /**
+   * Called when the framework received AppControlSignal.
+   * @param[in] The bundle data of AppControl event.
+   */
+  void OnTaskAppControl(void* data) override;
+
+  /**
+   * Called when the framework informs the application that the language of the device has changed.
+   */
+  void OnTaskLanguageChanged() override;
+
+  /**
+   * Called when the framework informs the application that the region of the device has changed.
+   */
+  void OnTaskRegionChanged() override;
+
+  /**
+   * Called when the framework informs the application that the battery level of the device is low.
+   */
+  void OnTaskBatteryLow(Dali::DeviceStatus::Battery::Status status) override;
+
+  /**
+   * Called when the framework informs the application that the memory level of the device is low.
+   */
+  void OnTaskMemoryLow(Dali::DeviceStatus::Memory::Status status) override;
 
   /**
+   * Called when the framework informs the application that the device orientation is changed.
+   *
+   * Device orientation changed event is from Application Framework(Sensor Framework), it means it is system event.
+   * If UIThreading is enable, DALI application has the main thread and UI thread.
+   * This event is emitted in main thread, then it is posted to the UI thread in this callback function.
+   */
+  void OnTaskDeviceOrientationChanged(Dali::DeviceStatus::Orientation::Status status) override;
+
+public:
+  /**
    * Sets a user defined theme file.
    * This should be called before initialization.
    * @param[in] stylesheet The path to user defined theme file
    */
-  void SetStyleSheet( const std::string& stylesheet );
+  void SetStyleSheet(const std::string& stylesheet);
 
   /**
    * Sets a command line options.
@@ -236,85 +292,193 @@ public:
    * @param[in] argc A pointer to the number of arguments
    * @param[in] argv A pointer to the argument list
    */
-  void SetCommandLineOptions( int* argc, char **argv[] );
+  void SetCommandLineOptions(int* argc, char** argv[]);
 
-public:  // Signals
+  /**
+   * Sets default window type.
+   * This is used in case of the preinitialized application.
+   * @param[in] type the window type for default window
+   */
+  void SetDefaultWindowType(WindowType type);
 
+public: // Signals
   /**
    * @copydoc Dali::Application::InitSignal()
    */
-  Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
+  Dali::Application::AppSignalType& InitSignal()
+  {
+    return mInitSignal;
+  }
 
   /**
    * @copydoc Dali::Application::TerminateSignal()
    */
-  Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
+  Dali::Application::AppSignalType& TerminateSignal()
+  {
+    return mTerminateSignal;
+  }
 
   /**
    * @copydoc Dali::Application::PauseSignal()
    */
-  Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
+  Dali::Application::AppSignalType& PauseSignal()
+  {
+    return mPauseSignal;
+  }
 
   /**
    * @copydoc Dali::Application::ResumeSignal()
    */
-  Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
+  Dali::Application::AppSignalType& ResumeSignal()
+  {
+    return mResumeSignal;
+  }
 
   /**
    * @copydoc Dali::Application::ResetSignal()
    */
-  Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
+  Dali::Application::AppSignalType& ResetSignal()
+  {
+    return mResetSignal;
+  }
 
   /**
-  * @copydoc Dali::Application::AppControlSignal()
-  */
-  Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
+   * @copydoc Dali::Application::AppControlSignal()
+   */
+  Dali::Application::AppControlSignalType& AppControlSignal()
+  {
+    return mAppControlSignal;
+  }
 
   /**
    * @copydoc Dali::Application::LanguageChangedSignal()
    */
-  Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
+  Dali::Application::AppSignalType& LanguageChangedSignal()
+  {
+    return mLanguageChangedSignal;
+  }
 
   /**
-  * @copydoc Dali::Application::RegionChangedSignal()
-  */
-  Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
+   * @copydoc Dali::Application::RegionChangedSignal()
+   */
+  Dali::Application::AppSignalType& RegionChangedSignal()
+  {
+    return mRegionChangedSignal;
+  }
 
   /**
-  * @copydoc Dali::Application::LowBatterySignal()
-  */
-  Dali::Application::LowBatterySignalType& LowBatterySignal() { return mLowBatterySignal; }
+   * @copydoc Dali::Application::LowBatterySignal()
+   */
+  Dali::Application::LowBatterySignalType& LowBatterySignal()
+  {
+    return mLowBatterySignal;
+  }
 
   /**
-  * @copydoc Dali::Application:::LowMemorySignal()
-  */
-  Dali::Application::LowMemorySignalType& LowMemorySignal() { return mLowMemorySignal; }
+   * @copydoc Dali::Application:::LowMemorySignal()
+   */
+  Dali::Application::LowMemorySignalType& LowMemorySignal()
+  {
+    return mLowMemorySignal;
+  }
 
-protected:
+  /**
+   * @copydoc Dali::Application:::DeviceOrientationChangedSignalType()
+   */
+  Dali::Application::DeviceOrientationChangedSignalType& DeviceOrientationChangedSignal()
+  {
+    return mDeviceOrientationChangedSignal;
+  }
+
+  /**
+   * @copydoc Dali::Application::TaskInitSignal()
+   */
+  Dali::Application::AppSignalType& TaskInitSignal()
+  {
+    return mTaskInitSignal;
+  }
+
+  /**
+   * @copydoc Dali::Application::TaskTerminateSignal()
+   */
+  Dali::Application::AppSignalType& TaskTerminateSignal()
+  {
+    return mTaskTerminateSignal;
+  }
+
+  /**
+   * @copydoc Dali::Application::TaskAppControlSignal()
+   */
+  Dali::Application::AppControlSignalType& TaskAppControlSignal()
+  {
+    return mTaskAppControlSignal;
+  }
 
   /**
+   * @copydoc Dali::Application::TaskLanguageChangedSignal()
+   */
+  Dali::Application::AppSignalType& TaskLanguageChangedSignal()
+  {
+    return mTaskLanguageChangedSignal;
+  }
+
+  /**
+   * @copydoc Dali::Application::TaskRegionChangedSignal()
+   */
+  Dali::Application::AppSignalType& TaskRegionChangedSignal()
+  {
+    return mTaskRegionChangedSignal;
+  }
+
+  /**
+   * @copydoc Dali::Application::TaskLowBatterySignal()
+   */
+  Dali::Application::LowBatterySignalType& TaskLowBatterySignal()
+  {
+    return mTaskLowBatterySignal;
+  }
+
+  /**
+   * @copydoc Dali::Application::TaskLowMemorySignal()
+   */
+  Dali::Application::LowMemorySignalType& TaskLowMemorySignal()
+  {
+    return mTaskLowMemorySignal;
+  }
+
+  /**
+   * @copydoc Dali::Application::TaskDeviceOrientationChangedSignal()
+   */
+  Dali::Application::DeviceOrientationChangedSignalType& TaskDeviceOrientationChangedSignal()
+  {
+    return mTaskDeviceOrientationChangedSignal;
+  }
+
+protected:
+  /**
    * Private Constructor
-   * @param[in]  argc         A pointer to the number of arguments
-   * @param[in]  argv         A pointer to the argument list
-   * @param[in]  stylesheet   The path to user defined theme file
-   * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
-   * @param[in]  positionSize A position and a size of the window
-   * @param[in]  applicationType  A member of Dali::Framework::Type
+   * @param[in]  argc               A pointer to the number of arguments
+   * @param[in]  argv               A pointer to the argument list
+   * @param[in]  stylesheet         The path to user defined theme file
+   * @param[in]  windowMode         A member of Dali::Application::WINDOW_MODE
+   * @param[in]  positionSize       A position and a size of the window
+   * @param[in]  applicationType    A member of Dali::Framework::Type
+   * @param[in]  type               The default window's type.
+   * @param[in]  useUiThread         True if the application would create UI thread
    */
-  Application( int* argc, char **argv[], const std::string& stylesheet,
-      WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
+  Application(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType, WindowType type, bool useUiThread);
 
   /**
    * Destructor
    */
-  ~Application() override;
+  virtual ~Application() override;
 
   // Undefined
   Application(const Application&);
   Application& operator=(Application&);
 
   /**
-   * Creates the window
+   * Creates the default window
    */
   void CreateWindow();
 
@@ -333,42 +497,58 @@ protected:
    */
   void QuitFromMainLoop();
 
-private:
-
-  AppSignalType                         mInitSignal;
-  AppSignalType                         mTerminateSignal;
-  AppSignalType                         mPauseSignal;
-  AppSignalType                         mResumeSignal;
-  AppSignalType                         mResetSignal;
-  AppControlSignalType                  mAppControlSignal;
-  AppSignalType                         mLanguageChangedSignal;
-  AppSignalType                         mRegionChangedSignal;
-  LowBatterySignalType                  mLowBatterySignal;
-  LowMemorySignalType                   mLowMemorySignal;
-
-  EventLoop*                            mEventLoop;
-  Framework*                            mFramework;
-
-  CommandLineOptions*                   mCommandLineOptions;
+  /**
+   * Changes size of preInitialized window
+   */
+  void ChangePreInitializedWindowSize();
 
-  Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder;   ///< The adaptor builder
+private:
+  AppSignalType                      mInitSignal;
+  AppSignalType                      mTerminateSignal;
+  AppSignalType                      mPauseSignal;
+  AppSignalType                      mResumeSignal;
+  AppSignalType                      mResetSignal;
+  AppControlSignalType               mAppControlSignal;
+  AppSignalType                      mLanguageChangedSignal;
+  AppSignalType                      mRegionChangedSignal;
+  LowBatterySignalType               mLowBatterySignal;
+  LowMemorySignalType                mLowMemorySignal;
+  DeviceOrientationChangedSignalType mDeviceOrientationChangedSignal;
+
+  AppSignalType                      mTaskInitSignal;
+  AppSignalType                      mTaskTerminateSignal;
+  AppControlSignalType               mTaskAppControlSignal;
+  AppSignalType                      mTaskLanguageChangedSignal;
+  AppSignalType                      mTaskRegionChangedSignal;
+  LowBatterySignalType               mTaskLowBatterySignal;
+  LowMemorySignalType                mTaskLowMemorySignal;
+  DeviceOrientationChangedSignalType mTaskDeviceOrientationChangedSignal;
+
+  EventLoop* mEventLoop;
+  Framework* mFramework;
+
+  CommandLineOptions* mCommandLineOptions;
+
+  Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder; ///< The adaptor builder
   Dali::Adaptor*                           mAdaptor;
 
   // The Main Window is that window created by the Application during initial startup
   // (previously this was the only window)
-  Dali::Window                             mMainWindow;       ///< Main Window instance
-  Dali::Application::WINDOW_MODE           mMainWindowMode;   ///< Window mode of the main window
-  std::string                              mMainWindowName;   ///< Name of the main window as obtained from environment options
+  Dali::Window                   mMainWindow;     ///< Main Window instance
+  Dali::Application::WINDOW_MODE mMainWindowMode; ///< Window mode of the main window
+  std::string                    mMainWindowName; ///< Name of the main window as obtained from environment options
 
-  std::string                              mStylesheet;
-  EnvironmentOptions                       mEnvironmentOptions;
-  PositionSize                             mWindowPositionSize;
-  Launchpad::State                         mLaunchpadState;
-  bool                                     mUseRemoteSurface;
+  std::string        mStylesheet;
+  EnvironmentOptions mEnvironmentOptions;
+  PositionSize       mWindowPositionSize;
+  Launchpad::State   mLaunchpadState;
+  bool               mUseRemoteSurface;
+  WindowType         mDefaultWindowType; ///< Default window's type. It is used when Application is created.
+  bool               mUseUiThread;
 
-  SlotDelegate< Application >              mSlotDelegate;
+  SlotDelegate<Application> mSlotDelegate;
 
-  static ApplicationPtr                    gPreInitializedApplication;
+  static ApplicationPtr gPreInitializedApplication;
 };
 
 inline Application& GetImplementation(Dali::Application& application)
@@ -389,7 +569,6 @@ inline const Application& GetImplementation(const Dali::Application& application
   return static_cast<const Internal::Adaptor::Application&>(handle);
 }
 
-
 } // namespace Adaptor
 
 } // namespace Internal