Merge "DALi Version 2.3.2" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / offscreen / common / offscreen-application-impl.cpp
index 396dbc4..f1fc2e7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 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.
 #include <dali/internal/offscreen/common/offscreen-application-impl.h>
 
 // INTERNAL INCLUDES
-#include <dali/internal/adaptor/common/adaptor-impl.h>
-#include <dali/internal/offscreen/common/offscreen-window-impl.h>
-#include <dali/internal/adaptor/common/thread-controller-interface.h>
+#include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
+#include <dali/devel-api/adaptor-framework/environment-variable.h>
 #include <dali/integration-api/adaptor-framework/adaptor.h>
 #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>
+#include <dali/internal/window-system/common/window-system.h>
 
 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 )
+IntrusivePtr<OffscreenApplication> OffscreenApplication::New(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode)
 {
-  IntrusivePtr< OffscreenApplication > offscreenApplication = new OffscreenApplication( width, height, surface, isTranslucent, renderMode );
+  IntrusivePtr<OffscreenApplication> offscreenApplication = new OffscreenApplication(width, height, surface, isTranslucent, renderMode);
   return offscreenApplication;
 }
 
-OffscreenApplication::OffscreenApplication( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode )
+OffscreenApplication::OffscreenApplication(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode)
 {
+  // Disable partial update
+  EnvironmentVariable::SetEnvironmentVariable(DALI_ENV_DISABLE_PARTIAL_UPDATE, "1");
+
+  // Disable ATSPI
+  Dali::Accessibility::Bridge::DisableAutoInit();
+
+  // Now we assume separated main loop for the offscreen application
+  mFrameworkFactory = std::unique_ptr<Adaptor::FrameworkFactory>(Dali::Internal::Adaptor::CreateFrameworkFactory());
+  mFramework        = mFrameworkFactory->CreateFramework(Internal::Adaptor::FrameworkBackend::GLIB, *this, *this, nullptr, nullptr, Adaptor::Framework::NORMAL, false);
+
   // Generate a default window
-  IntrusivePtr< Internal::OffscreenWindow > impl = Internal::OffscreenWindow::New( width, height, surface, isTranslucent );
-  mDefaultWindow = Dali::OffscreenWindow( impl.Get() );
+  IntrusivePtr<Internal::OffscreenWindow> impl = Internal::OffscreenWindow::New(width, height, surface, isTranslucent);
+  mDefaultWindow                               = Dali::OffscreenWindow(impl.Get());
 
-  mAdaptor.reset( Dali::Internal::Adaptor::Adaptor::New( Dali::Integration::SceneHolder( impl.Get() ), impl->GetSurface(), NULL,
-                            renderMode == RenderMode::AUTO ? Dali::Internal::Adaptor::ThreadMode::NORMAL : Dali::Internal::Adaptor::ThreadMode::RUN_IF_REQUESTED ) );
+  mAdaptor.reset(Dali::Internal::Adaptor::Adaptor::New(Dali::Integration::SceneHolder(impl.Get()), impl->GetSurface(), NULL, renderMode == RenderMode::AUTO ? Dali::Internal::Adaptor::ThreadMode::NORMAL : Dali::Internal::Adaptor::ThreadMode::RUN_IF_REQUESTED));
 
   // Initialize default window
-  impl->Initialize( true );
+  impl->Initialize(true);
+}
+
+OffscreenApplication::~OffscreenApplication()
+{
+}
+
+void OffscreenApplication::MainLoop()
+{
+  mFramework->Run();
+}
+
+void OffscreenApplication::Quit()
+{
+  // Actually quit the application.
+  Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle(MakeCallback(this, &OffscreenApplication::QuitFromMainLoop), false);
+}
+
+Dali::OffscreenWindow OffscreenApplication::GetWindow()
+{
+  return mDefaultWindow;
+}
+
+void OffscreenApplication::RenderOnce()
+{
+  mAdaptor->RenderOnce();
 }
 
-void OffscreenApplication::Start()
+Any OffscreenApplication::GetFrameworkContext() const
+{
+  return mFramework->GetMainLoopContext();
+}
+
+void OffscreenApplication::OnInit()
 {
   // Start the adaptor
   mAdaptor->Start();
 
-  Dali::OffscreenApplication handle( this );
+  Dali::OffscreenApplication application(this);
   mInitSignal.Emit();
+  EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnInit);
+
   mAdaptor->NotifySceneCreated();
 }
 
-void OffscreenApplication::Stop()
+void OffscreenApplication::OnTerminate()
 {
+  Dali::OffscreenApplication application(this);
+  mTerminateSignal.Emit();
+  EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnTerminate);
+
   // Stop the adaptor
   mAdaptor->Stop();
 
-  Dali::OffscreenApplication handle( this );
-  mTerminateSignal.Emit();
+  mDefaultWindow.Reset();
 }
 
-Dali::OffscreenWindow OffscreenApplication::GetWindow()
+void OffscreenApplication::OnPause()
 {
-  return mDefaultWindow;
+  Dali::OffscreenApplication application(this);
+  mPauseSignal.Emit();
+  EmitLifecycleControllerSignal(&Internal::Adaptor::LifecycleController::OnPause);
 }
 
-void OffscreenApplication::RenderOnce()
+void OffscreenApplication::OnResume()
 {
-  mAdaptor->RenderOnce();
+  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();
+
+  mFramework->Quit();
+  // This will trigger OnTerminate(), below, after the main loop has completed.
 }
 
 } // namespace Internal