[3.0] Support screen rotation
[platform/core/uifw/dali-adaptor.git] / adaptors / common / application-impl.cpp
index 4e93bfd..6e2c03c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -51,13 +51,15 @@ ApplicationPtr Application::New(
   int* argc,
   char **argv[],
   const std::string& stylesheet,
-  Dali::Application::WINDOW_MODE windowMode)
+  Dali::Application::WINDOW_MODE windowMode,
+  Framework::Type applicationType)
 {
-  ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode ) );
+  ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, applicationType ) );
   return application;
 }
 
-Application::Application( int* argc, char** argv[], const std::string& stylesheet, Dali::Application::WINDOW_MODE windowMode )
+Application::Application( int* argc, char** argv[], const std::string& stylesheet,
+  Dali::Application::WINDOW_MODE windowMode, Framework::Type applicationType )
 : mInitSignal(),
   mTerminateSignal(),
   mPauseSignal(),
@@ -80,7 +82,6 @@ Application::Application( int* argc, char** argv[], const std::string& styleshee
   mName(),
   mStylesheet( stylesheet ),
   mEnvironmentOptions(),
-  mInitialized( false ),
   mSlotDelegate( this )
 {
   // Get mName from environment options
@@ -92,18 +93,18 @@ Application::Application( int* argc, char** argv[], const std::string& styleshee
   }
 
   mCommandLineOptions = new CommandLineOptions(argc, argv);
-
-  mFramework = new Framework( *this, argc, argv );
+  mFramework = new Framework( *this, argc, argv, applicationType );
+  mUseRemoteSurface = (applicationType == Framework::WATCH);
 }
 
 Application::~Application()
 {
   mSingletonService.UnregisterAll();
 
-  delete mFramework;
-  delete mCommandLineOptions;
-  delete mAdaptor;
   mWindow.Reset();
+  delete mAdaptor;
+  delete mCommandLineOptions;
+  delete mFramework;
 }
 
 void Application::CreateWindow()
@@ -121,14 +122,11 @@ void Application::CreateWindow()
     windowPosition = PositionSize( 0, 0, mEnvironmentOptions.GetWindowWidth(), mEnvironmentOptions.GetWindowHeight() );
   }
 
-  mWindow = Dali::Window::New( windowPosition, mName, mWindowMode == Dali::Application::TRANSPARENT );
-
-  // Set the window class name if available
   const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
-  if( ! windowClassName.empty() )
-  {
-    mWindow.SetClass( mName, windowClassName );
-  }
+  mWindow = Dali::Window::New( windowPosition, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
+
+  // Quit the application when the window is closed
+  GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
 }
 
 void Application::CreateAdaptor()
@@ -138,6 +136,8 @@ void Application::CreateAdaptor()
   mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
 
   mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
+
+  Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
 }
 
 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
@@ -164,12 +164,8 @@ void Application::QuitFromMainLoop()
 {
   mAdaptor->Stop();
 
-  Dali::Application application(this);
-  mTerminateSignal.Emit( application );
-
   mFramework->Quit();
   // This will trigger OnTerminate(), below, after the main loop has completed.
-  mInitialized = false;
 }
 
 void Application::OnInit()
@@ -177,9 +173,9 @@ void Application::OnInit()
   mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
 
   CreateWindow();
-  CreateAdaptor();
 
-  // Run the adaptor
+  // Start the adaptor
+  CreateAdaptor();
   mAdaptor->Start();
 
   // Check if user requires no vsyncing and set on X11 Adaptor
@@ -204,8 +200,6 @@ void Application::OnInit()
     Dali::StyleMonitor::Get().SetTheme( mStylesheet );
   }
 
-  mInitialized = true;
-
   // Wire up the LifecycleController
   Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
 
@@ -220,7 +214,7 @@ void Application::OnInit()
   Dali::Application application(this);
   mInitSignal.Emit( application );
 
-  Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetCore().SceneCreated();
+  mAdaptor->NotifySceneCreated();
 }
 
 void Application::OnTerminate()
@@ -228,22 +222,36 @@ void Application::OnTerminate()
   // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
   // delete the window as ecore_x has been destroyed by AppCore
 
+  Dali::Application application(this);
+  mTerminateSignal.Emit( application );
+
+  if( mAdaptor )
+  {
+    // Ensure that the render-thread is not using the surface(window) after we delete it
+    mAdaptor->Stop();
+  }
+
   mWindow.Reset();
-  mInitialized = false;
 }
 
 void Application::OnPause()
 {
-  mAdaptor->Pause();
+  // A DALi app should handle Pause/Resume events.
+  // DALi just delivers the framework Pause event to the application, but not actually pause DALi core
+  // Pausing DALi core only occurs on the Window Hidden framework event
   Dali::Application application(this);
   mPauseSignal.Emit( application );
 }
 
 void Application::OnResume()
 {
-  mAdaptor->Resume();
+  // Emit the signal first so the application can queue any messages before we do an update/render
+  // This ensures we do not just redraw the last frame before pausing if that's not required
   Dali::Application application(this);
   mResumeSignal.Emit( application );
+
+  // DALi just delivers the framework Resume event to the application.
+  // Resuming DALi core only occurs on the Window Show framework event
 }
 
 void Application::OnReset()
@@ -254,8 +262,6 @@ void Application::OnReset()
    */
   Dali::Application application(this);
   mResetSignal.Emit( application );
-
-  mWindow.Raise();
 }
 
 void Application::OnAppControl(void *data)