[Tizen] Add OffscreenApplication
[platform/core/uifw/dali-adaptor.git] / dali / internal / offscreen / common / offscreen-application-impl.cpp
index eedf1b8..f2a9ed1 100644 (file)
 
 // EXTERNAL INCLUDES
 #include <dali/integration-api/adaptor-framework/adaptor.h>
+#include <dali/internal/adaptor/common/adaptor-impl.h>
 #include <dali/integration-api/adaptor-framework/native-render-surface.h>
 
 // INTERNAL INCLUDES
 #include <dali/internal/offscreen/common/offscreen-window-impl.h>
 #include <dali/internal/offscreen/common/offscreen-window-factory.h>
+#include <dali/internal/adaptor/common/thread-controller-interface.h>
 
 // CLASS HEADER
 #include <dali/internal/offscreen/common/offscreen-application-impl.h>
 
+using Dali::Internal::Adaptor::ThreadMode;
+
 namespace Dali
 {
 
 namespace Internal
 {
 
-IntrusivePtr< OffscreenApplication > OffscreenApplication::New( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent)
+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 );
+  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 )
-: mState( READY )
+OffscreenApplication::OffscreenApplication( uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, RenderMode renderMode )
 {
   // Generate a default window
   auto windowFactory = Dali::Internal::GetOffscreenWindowFactory();
   IntrusivePtr <Internal::OffscreenWindow > windowPtr = windowFactory->CreateOffscreenWindow( width, height, surface, isTranslucent ).release();
   mDefaultWindow = Dali::OffscreenWindow( windowPtr.Get() );
 
-  // Generate DALi adaptor
-  NativeRenderSurface* naitveSurface = static_cast<NativeRenderSurface*>( windowPtr->GetSurface() );
-
-  mAdaptor = &Dali::Adaptor::New( Dali::Integration::SceneHolder( windowPtr.Get() ), *naitveSurface, Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS );
+  mAdaptor = Dali::Internal::Adaptor::Adaptor::New( Dali::Integration::SceneHolder( windowPtr.Get() ), windowPtr->GetSurface(),
+                            Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS, NULL,
+                            renderMode == RenderMode::AUTO ? ThreadMode::NORMAL : ThreadMode::RUN_IF_REQUESTED );
 
   // Initialize default window
-  windowPtr->Initialize( this, true );
+  windowPtr->Initialize( true );
 }
 
 OffscreenApplication::~OffscreenApplication()
@@ -61,38 +63,19 @@ OffscreenApplication::~OffscreenApplication()
   mAdaptor = nullptr;
 }
 
-Dali::Adaptor* OffscreenApplication::GetAdaptor()
-{
-  return mAdaptor;
-}
-
-void OffscreenApplication::Run()
+void OffscreenApplication::Start()
 {
-  if( READY == mState )
-  {
-    // Start the adaptor
-    mAdaptor->Start();
-
-    mState = RUNNING;
-
-    mPreInitSignal.Emit();
-
-    mInitSignal.Emit();
-
-    mAdaptor->NotifySceneCreated();
-  }
+   // Start the adaptor
+   mAdaptor->Start();
+   mInitSignal.Emit();
+   mAdaptor->NotifySceneCreated();
 }
 
 void OffscreenApplication::Stop()
 {
-  if( mState != STOPPED )
-  {
-    // Stop the adaptor
-    mAdaptor->Stop();
-    mState = STOPPED;
-
-    mTerminateSignal.Emit();
-  }
+  // Stop the adaptor
+  mAdaptor->Stop();
+  mTerminateSignal.Emit();
 }
 
 Dali::OffscreenWindow OffscreenApplication::GetWindow()
@@ -100,6 +83,11 @@ Dali::OffscreenWindow OffscreenApplication::GetWindow()
   return mDefaultWindow;
 }
 
+void OffscreenApplication::RenderOnce()
+{
+  mAdaptor->RenderOnce();
+}
+
 } // namespace Internal
 
 } // namespace Dali