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 5244025..8e334a7 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_APPLICATION_H
 
 /*
- * Copyright (c) 2021 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.
@@ -64,25 +64,28 @@ 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()
@@ -157,6 +160,11 @@ public:
    */
   void StoreWindowPositionSize(PositionSize positionSize);
 
+  /**
+   * @copydoc Dali::DevelApplication::GetRenderThreadId()
+   */
+  int32_t GetRenderThreadId() const;
+
 public: // From Framework::Observer
   /**
    * Called when the framework is initialised.
@@ -179,9 +187,9 @@ public: // From Framework::Observer
   void OnResume() override;
 
   /**
-  * Called when the framework received AppControlSignal.
-  * @param[in] The bundle data of AppControl event.
-  */
+   * Called when the framework received AppControlSignal.
+   * @param[in] The bundle data of AppControl event.
+   */
   void OnAppControl(void* data) override;
 
   /**
@@ -195,21 +203,26 @@ 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.
-  */
+   * 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.
-  */
+   * 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;
@@ -219,6 +232,52 @@ public: // From Framework::Observer
    */
   void OnSurfaceDestroyed(Any newSurface) override;
 
+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.
@@ -235,6 +294,13 @@ public:
    */
   void SetCommandLineOptions(int* argc, char** argv[]);
 
+  /**
+   * 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()
@@ -277,8 +343,8 @@ public: // Signals
   }
 
   /**
-  * @copydoc Dali::Application::AppControlSignal()
-  */
+   * @copydoc Dali::Application::AppControlSignal()
+   */
   Dali::Application::AppControlSignalType& AppControlSignal()
   {
     return mAppControlSignal;
@@ -293,55 +359,126 @@ public: // Signals
   }
 
   /**
-  * @copydoc Dali::Application::RegionChangedSignal()
-  */
+   * @copydoc Dali::Application::RegionChangedSignal()
+   */
   Dali::Application::AppSignalType& RegionChangedSignal()
   {
     return mRegionChangedSignal;
   }
 
   /**
-  * @copydoc Dali::Application::LowBatterySignal()
-  */
+   * @copydoc Dali::Application::LowBatterySignal()
+   */
   Dali::Application::LowBatterySignalType& LowBatterySignal()
   {
     return mLowBatterySignal;
   }
 
   /**
-  * @copydoc Dali::Application:::LowMemorySignal()
-  */
+   * @copydoc Dali::Application:::LowMemorySignal()
+   */
   Dali::Application::LowMemorySignalType& LowMemorySignal()
   {
     return mLowMemorySignal;
   }
 
-  // Temporary to test GFXApi
-  Graphics::Controller& GetController();
+  /**
+   * @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();
 
@@ -366,16 +503,26 @@ protected:
   void ChangePreInitializedWindowSize();
 
 private:
-  AppSignalType        mInitSignal;
-  AppSignalType        mTerminateSignal;
-  AppSignalType        mPauseSignal;
-  AppSignalType        mResumeSignal;
-  AppSignalType        mResetSignal;
-  AppControlSignalType mAppControlSignal;
-  AppSignalType        mLanguageChangedSignal;
-  AppSignalType        mRegionChangedSignal;
-  LowBatterySignalType mLowBatterySignal;
-  LowMemorySignalType  mLowMemorySignal;
+  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;
@@ -396,6 +543,8 @@ private:
   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;