Allow to use LifecycleController for OffscreenApplication 36/302136/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Fri, 1 Dec 2023 02:34:51 +0000 (11:34 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Fri, 1 Dec 2023 03:09:31 +0000 (12:09 +0900)
Some OffscreenApplication have some usage for LifecycleController signal.
But previously, we didn't attach this signal for app lifecycle correctly.

Now let we connect it so we can know the app's lifecycle

Change-Id: I75a2757ea17fcf6e21041302923b83b5964a3a83
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/devel-api/adaptor-framework/offscreen-application.cpp
dali/devel-api/adaptor-framework/offscreen-application.h
dali/internal/offscreen/common/offscreen-application-impl.cpp
dali/internal/offscreen/common/offscreen-application-impl.h

index e6b4aae..8504420 100644 (file)
@@ -85,6 +85,26 @@ OffscreenApplication::OffscreenApplicationSignalType& OffscreenApplication::Term
   return Internal::GetImplementation(*this).TerminateSignal();
 }
 
+OffscreenApplication::OffscreenApplicationSignalType& OffscreenApplication::PauseSignal()
+{
+  return Internal::GetImplementation(*this).PauseSignal();
+}
+
+OffscreenApplication::OffscreenApplicationSignalType& OffscreenApplication::ResumeSignal()
+{
+  return Internal::GetImplementation(*this).ResumeSignal();
+}
+
+OffscreenApplication::OffscreenApplicationSignalType& OffscreenApplication::ResetSignal()
+{
+  return Internal::GetImplementation(*this).ResetSignal();
+}
+
+OffscreenApplication::OffscreenApplicationSignalType& OffscreenApplication::LanguageChangedSignal()
+{
+  return Internal::GetImplementation(*this).LanguageChangedSignal();
+}
+
 OffscreenApplication::OffscreenApplication(Internal::OffscreenApplication* offscreenApplication)
 : BaseHandle(offscreenApplication)
 {
index f31cd2d..5634a61 100644 (file)
@@ -131,7 +131,7 @@ public:
   Any GetFrameworkContext() const;
 
 public: // Signals
-        /**
+  /**
    * @brief Signal to notify the client when the application is ready to be initialized
    *
    * @note OffscreenApplication::Start() should be called to be initialized
@@ -147,6 +147,34 @@ public: // Signals
    */
   OffscreenApplicationSignalType& TerminateSignal();
 
+  /**
+   * @brief Signal to notify the user when the application is about to be paused
+   *
+   * @return The signal
+   */
+  OffscreenApplicationSignalType& PauseSignal();
+
+  /**
+   * @brief Signal to notify the user when the application is about to be resumed
+   *
+   * @return The signal
+   */
+  OffscreenApplicationSignalType& ResumeSignal();
+
+  /**
+   * @brief Signal to notify the user when the application is about to be reinitialized
+   *
+   * @return The signal
+   */
+  OffscreenApplicationSignalType& ResetSignal();
+
+  /**
+   * @brief Signal to notify the user when the application is about to be language is changed on the device.
+   *
+   * @return The signal
+   */
+  OffscreenApplicationSignalType& LanguageChangedSignal();
+
 public: // Not intended for application developers
   /**
    * @brief Internal constructor
index 0b2682c..1b2545a 100644 (file)
@@ -25,6 +25,7 @@
 #include <dali/integration-api/adaptor-framework/native-render-surface.h>
 #include <dali/internal/adaptor/common/adaptor-impl.h>
 #include <dali/internal/adaptor/common/framework-factory.h>
+#include <dali/internal/adaptor/common/lifecycle-controller-impl.h>
 #include <dali/internal/adaptor/common/thread-controller-interface.h>
 #include <dali/internal/offscreen/common/offscreen-window-impl.h>
 #include <dali/internal/system/common/environment-variables.h>
@@ -34,6 +35,18 @@ namespace Dali
 {
 namespace Internal
 {
+namespace
+{
+void EmitLifecycleControllerSignal(void (Internal::Adaptor::LifecycleController::*member)(Dali::Application&))
+{
+  Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
+  if(DALI_LIKELY(lifecycleController))
+  {
+    Dali::Application dummyApplication;
+    (GetImplementation(lifecycleController).*member)(dummyApplication);
+  }
+}
+} // namespace
 using RenderMode = Dali::OffscreenApplication::RenderMode;
 
 IntrusivePtr<OffscreenApplication> OffscreenApplication::New(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode)
@@ -100,14 +113,18 @@ void OffscreenApplication::OnInit()
   // Start the adaptor
   mAdaptor->Start();
 
+  Dali::OffscreenApplication application(this);
   mInitSignal.Emit();
+  EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnInit);
 
   mAdaptor->NotifySceneCreated();
 }
 
 void OffscreenApplication::OnTerminate()
 {
+  Dali::OffscreenApplication application(this);
   mTerminateSignal.Emit();
+  EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnTerminate);
 
   // Stop the adaptor
   mAdaptor->Stop();
@@ -115,6 +132,47 @@ void OffscreenApplication::OnTerminate()
   mDefaultWindow.Reset();
 }
 
+void OffscreenApplication::OnPause()
+{
+  Dali::OffscreenApplication application(this);
+  mPauseSignal.Emit();
+  EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnPause);
+}
+
+void OffscreenApplication::OnResume()
+{
+  Dali::OffscreenApplication application(this);
+  mResumeSignal.Emit();
+  EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnResume);
+
+  // DALi just delivers the framework Resume event to the application.
+  // Resuming DALi core only occurs on the Window Show framework event
+
+  // Trigger processing of events queued up while paused
+  Internal::Adaptor::CoreEventInterface& coreEventInterface = Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor);
+  coreEventInterface.ProcessCoreEvents();
+}
+
+void OffscreenApplication::OnReset()
+{
+  /*
+   * usually, reset callback was called when a caller request to launch this application via aul.
+   * because Application class already handled initialization in OnInit(), OnReset do nothing.
+   */
+  Dali::OffscreenApplication application(this);
+  mResetSignal.Emit();
+  EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnReset);
+}
+
+void OffscreenApplication::OnLanguageChanged()
+{
+  mAdaptor->NotifyLanguageChanged();
+
+  Dali::OffscreenApplication application(this);
+  mLanguageChangedSignal.Emit();
+  EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnLanguageChanged);
+}
+
 void OffscreenApplication::QuitFromMainLoop()
 {
   mAdaptor->Stop();
index f12ce4d..5e568a3 100644 (file)
@@ -106,6 +106,38 @@ public: // Signals
     return mTerminateSignal;
   }
 
+  /**
+   * @copydoc Dali::OffscreenApplication::PauseSignal()
+   */
+  OffscreenApplicationSignalType& PauseSignal()
+  {
+    return mPauseSignal;
+  }
+
+  /**
+   * @copydoc Dali::OffscreenApplication::ResumeSignal()
+   */
+  OffscreenApplicationSignalType& ResumeSignal()
+  {
+    return mResumeSignal;
+  }
+
+  /**
+   * @copydoc Dali::OffscreenApplication::ResetSignal()
+   */
+  OffscreenApplicationSignalType& ResetSignal()
+  {
+    return mResetSignal;
+  }
+
+  /**
+   * @copydoc Dali::OffscreenApplication::LanguageChangedSignal()
+   */
+  OffscreenApplicationSignalType& LanguageChangedSignal()
+  {
+    return mLanguageChangedSignal;
+  }
+
 public: // From Framework::Observer
   /**
    * Called when the framework is initialised.
@@ -117,6 +149,26 @@ public: // From Framework::Observer
    */
   void OnTerminate() override;
 
+  /**
+   * Called when the framework is paused.
+   */
+  void OnPause() override;
+
+  /**
+   * Called when the framework resumes from a paused state.
+   */
+  void OnResume() override;
+
+  /**
+   * Called when the framework informs the application that it should reset itself.
+   */
+  void OnReset() override;
+
+  /**
+   * Called when the framework informs the application that the language of the device has changed.
+   */
+  void OnLanguageChanged() override;
+
 private:
   /**
    * Private constructor
@@ -148,6 +200,10 @@ private:
 
   OffscreenApplicationSignalType mInitSignal;
   OffscreenApplicationSignalType mTerminateSignal;
+  OffscreenApplicationSignalType mPauseSignal;
+  OffscreenApplicationSignalType mResumeSignal;
+  OffscreenApplicationSignalType mResetSignal;
+  OffscreenApplicationSignalType mLanguageChangedSignal;
 };
 
 inline OffscreenApplication& GetImplementation(Dali::OffscreenApplication& offscreenApplication)