[AT-SPI] Squashed implementation
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / adaptor-impl.cpp
index 1e66048..502ec75 100755 (executable)
 
 // CLASS HEADER
 #include <dali/internal/adaptor/common/adaptor-impl.h>
+#include <dali/internal/addons/common/addon-manager-impl.h>
+#include <dali/internal/addons/common/addon-manager-factory.h>
 #include <dali/internal/adaptor/common/adaptor-builder-impl.h>
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/common/stage.h>
+#include <errno.h>
+#include <sys/stat.h>
 #include <dali/public-api/actors/layer.h>
 #include <dali/public-api/object/any.h>
+#include <dali/public-api/object/object-registry.h>
+#include <dali/public-api/events/wheel-event.h>
 #include <dali/devel-api/actors/actor-devel.h>
+#include <dali/devel-api/common/stage.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/core.h>
 #include <dali/integration-api/context-notifier.h>
@@ -33,6 +39,7 @@
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali/integration-api/events/wheel-event-integ.h>
 #include <dali/integration-api/processor-interface.h>
+#include <dali/integration-api/addon-manager.h>
 
 // INTERNAL INCLUDES
 #include <dali/public-api/dali-adaptor-common.h>
@@ -48,7 +55,6 @@
 
 #include <dali/internal/system/common/callback-manager.h>
 #include <dali/internal/accessibility/common/tts-player-impl.h>
-#include <dali/internal/accessibility/common/accessibility-adaptor-impl.h>
 #include <dali/internal/window-system/common/event-handler.h>
 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
 #include <dali/internal/graphics/gles/gl-implementation.h>
@@ -61,6 +67,7 @@
 #include <dali/internal/window-system/common/window-impl.h>
 #include <dali/internal/window-system/common/window-render-surface.h>
 
+#include <dali/devel-api/adaptor-framework/accessibility-impl.h>
 #include <dali/internal/system/common/logging.h>
 
 #include <dali/internal/system/common/locale-utils.h>
@@ -90,49 +97,49 @@ thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer
 
 } // unnamed namespace
 
-Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
+Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode )
 {
   Dali::Adaptor* adaptor = new Dali::Adaptor;
-  Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions );
+  Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions, threadMode );
   adaptor->mImpl = impl;
 
   Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder();
   auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
 
-  impl->Initialize( graphicsFactory, configuration );
+  impl->Initialize( graphicsFactory );
   delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
 
   return adaptor;
 }
 
-Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
+Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions )
 {
   Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
-  Dali::Adaptor* adaptor = New( window, windowImpl.GetSurface(), configuration, environmentOptions );
+  Dali::Adaptor* adaptor = New( window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL );
   windowImpl.SetAdaptor( *adaptor );
   return adaptor;
 }
 
-Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
+Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode )
 {
   Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
-  Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions ); // Impl adaptor
+  Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions, threadMode ); // Impl adaptor
   adaptor->mImpl = impl;
 
-  impl->Initialize( graphicsFactory, configuration );
+  impl->Initialize( graphicsFactory );
 
   return adaptor;
 } // Called second
 
-Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
+Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions )
 {
   Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
-  Dali::Adaptor* adaptor = New( graphicsFactory, window, windowImpl.GetSurface(), configuration, environmentOptions );
+  Dali::Adaptor* adaptor = New( graphicsFactory, window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL );
   windowImpl.SetAdaptor( *adaptor );
   return adaptor;
 } // Called first
 
-void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration )
+void Adaptor::Initialize( GraphicsFactory& graphicsFactory )
 {
   // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
   Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
@@ -159,10 +166,11 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
 
   DALI_ASSERT_DEBUG( defaultWindow->GetSurface() && "Surface not initialized" );
 
-  mGraphics = &( graphicsFactory.Create() );
+  mGraphics = std::unique_ptr< GraphicsInterface >( &graphicsFactory.Create() );
   mGraphics->Initialize( mEnvironmentOptions );
 
-  auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
+  GraphicsInterface* graphics = mGraphics.get(); // This interface is temporary until Core has been updated to match
+  auto eglGraphics = static_cast<EglGraphics *>( graphics );
 
   // This will only be created once
   eglGraphics->Create();
@@ -171,6 +179,9 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
   EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
   EglContextHelperImplementation& eglContextHelperImpl = eglGraphics->GetContextHelperImplementation();
 
+  // Create the AddOnManager
+  mAddOnManager.reset( Dali::Internal::AddOnManagerFactory::CreateAddOnManager() );
+
   mCore = Integration::Core::New( *this,
                                   *mPlatformAbstraction,
                                   mGLES,
@@ -178,7 +189,9 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
                                   eglContextHelperImpl,
                                   ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
                                   mGraphics->GetDepthBufferRequired(),
-                                  mGraphics->GetStencilBufferRequired() );
+                                  mGraphics->GetStencilBufferRequired(),
+                                  mGraphics->GetPartialUpdateRequired() );
+
 
   defaultWindow->SetAdaptor( Get() );
 
@@ -189,14 +202,14 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
   const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
   if( 0u < timeInterval )
   {
-    mObjectProfiler = new ObjectProfiler( timeInterval );
+    mObjectProfiler = new ObjectProfiler( mCore->GetObjectRegistry(), timeInterval );
   }
 
   mNotificationTrigger = TriggerEventFactory::CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
 
   mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow->GetSurface()->GetSurfaceType() );
 
-  mThreadController = new ThreadController( *this, *mEnvironmentOptions );
+  mThreadController = new ThreadController( *this, *mEnvironmentOptions, mThreadMode );
 
   // Should be called after Core creation
   if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
@@ -299,19 +312,45 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
   std::string systemCachePath = GetSystemCachePath();
   if( ! systemCachePath.empty() )
   {
-    const int dir_err = system( std::string( "mkdir " + systemCachePath ).c_str() );
-    if (-1 == dir_err)
+    const int dir_err = mkdir( systemCachePath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH );
+    if ( 0 != dir_err && errno != EEXIST )
     {
-        printf( "Error creating system cache directory: %s!\n", systemCachePath.c_str() );
-        exit(1);
+      DALI_LOG_ERROR( "Error creating system cache directory: %s!\n", systemCachePath.c_str() );
+      exit( 1 );
     }
   }
 
   mConfigurationManager = Utils::MakeUnique<ConfigurationManager>( systemCachePath, eglGraphics, mThreadController );
+
+  auto appName = GetApplicationPackageName();
+  auto bridge = Accessibility::Bridge::GetCurrentBridge();
+  bridge->SetApplicationName( appName );
+  bridge->Initialize();
+  Dali::Stage::GetCurrent().KeyEventSignal().Connect( &accessibilityObserver, &AccessibilityObserver::OnAccessibleKeyEvent );
+}
+
+void Adaptor::AccessibilityObserver::OnAccessibleKeyEvent( const Dali::KeyEvent& event )
+{
+  Accessibility::KeyEventType type;
+  if( event.GetState() == Dali::KeyEvent::DOWN )
+  {
+    type = Accessibility::KeyEventType::KEY_PRESSED;
+  }
+  else if( event.GetState() == Dali::KeyEvent::UP )
+  {
+    type = Accessibility::KeyEventType::KEY_RELEASED;
+  }
+  else
+  {
+    return;
+  }
+  Dali::Accessibility::Bridge::GetCurrentBridge()->Emit( type, event.GetKeyCode(), event.GetKeyName(), event.GetTime(), !event.GetKeyString().empty() );
 }
 
 Adaptor::~Adaptor()
 {
+  Accessibility::Bridge::GetCurrentBridge()->Terminate();
+
   // Ensure stop status
   Stop();
 
@@ -385,7 +424,6 @@ void Adaptor::Start()
   else
   {
     unsigned int maxTextureSize = mConfigurationManager->GetMaxTextureSize();
-    setenv( DALI_ENV_MAX_TEXTURE_SIZE, std::to_string( maxTextureSize ).c_str(), 1 );
     Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( maxTextureSize );
   }
 
@@ -398,6 +436,11 @@ void Adaptor::Start()
   {
     (*iter)->OnStart();
   }
+
+  if (mAddOnManager)
+  {
+    mAddOnManager->Start();
+  }
 }
 
 // Dali::Internal::Adaptor::Adaptor::Pause
@@ -412,6 +455,12 @@ void Adaptor::Pause()
       (*iter)->OnPause();
     }
 
+    // Extensions
+    if (mAddOnManager)
+    {
+      mAddOnManager->Pause();
+    }
+
     // Pause all windows event handlers when adaptor paused
     for( auto window : mWindows )
     {
@@ -446,6 +495,12 @@ void Adaptor::Resume()
       window->Resume();
     }
 
+    // Resume AddOnManager
+    if (mAddOnManager)
+    {
+      mAddOnManager->Resume();
+    }
+
     // Inform observers that we have resumed.
     for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
     {
@@ -477,6 +532,11 @@ void Adaptor::Stop()
       (*iter)->OnStop();
     }
 
+    if (mAddOnManager)
+    {
+      mAddOnManager->Stop();
+    }
+
     mThreadController->Stop();
 
     // Delete the TTS player
@@ -521,15 +581,15 @@ void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
   mWindows.front()->FeedTouchPoint( convertedPoint, timeStamp );
 }
 
-void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
+void Adaptor::FeedWheelEvent( Dali::WheelEvent& wheelEvent )
 {
-  Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
+  Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >( wheelEvent.GetType() ), wheelEvent.GetDirection(), wheelEvent.GetModifiers(), wheelEvent.GetPoint(), wheelEvent.GetDelta(), wheelEvent.GetTime() );
   mWindows.front()->FeedWheelEvent( event );
 }
 
-void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
+void Adaptor::FeedKeyEvent( Dali::KeyEvent& keyEvent )
 {
-  Integration::KeyEvent convertedEvent( keyEvent );
+  Integration::KeyEvent convertedEvent( keyEvent.GetKeyName(), keyEvent.GetLogicalKey(), keyEvent.GetKeyString(), keyEvent.GetKeyCode(), keyEvent.GetKeyModifier(), keyEvent.GetTime(), static_cast< Integration::KeyEvent::State >( keyEvent.GetState() ), keyEvent.GetCompose(), keyEvent.GetDeviceName(), keyEvent.GetDeviceClass(), keyEvent.GetDeviceSubclass() );
   mWindows.front()->FeedKeyEvent( convertedEvent );
 }
 
@@ -555,6 +615,16 @@ void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::Rende
   }
 }
 
+void Adaptor::DeleteSurface( Dali::RenderSurfaceInterface& surface )
+{
+  // Flush the event queue to give the update-render thread chance
+  // to start processing messages for new camera setup etc as soon as possible
+  ProcessCoreEvents();
+
+  // This method blocks until the render thread has finished rendering the current surface.
+  mThreadController->DeleteSurface( &surface );
+}
+
 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
 {
   return *mWindows.front()->GetSurface();
@@ -594,16 +664,25 @@ void Adaptor::RemoveIdle( CallbackBase* callback )
   mCallbackManager->RemoveIdleCallback( callback );
 }
 
+void Adaptor::ProcessIdle()
+{
+  bool idleProcessed = mCallbackManager->ProcessIdle();
+  mNotificationOnIdleInstalled = mNotificationOnIdleInstalled && !idleProcessed;
+}
+
 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
 {
   mThreadController->SetPreRenderCallback( callback );
 }
 
-bool Adaptor::AddWindow( Dali::Integration::SceneHolder childWindow, const std::string& childWindowName, const std::string& childWindowClassName, bool childWindowMode )
+bool Adaptor::AddWindow( Dali::Integration::SceneHolder childWindow )
 {
   Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( childWindow );
   windowImpl.SetAdaptor( Get() );
 
+  // ChildWindow is set to the layout direction of the default window.
+  windowImpl.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection );
+
   // Add the new Window to the container - the order is not important
   mWindows.push_back( &windowImpl );
 
@@ -694,7 +773,7 @@ Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
 GraphicsInterface& Adaptor::GetGraphicsInterface()
 {
   DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
-  return *mGraphics;
+  return *( mGraphics.get() );
 }
 
 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
@@ -785,7 +864,8 @@ Any Adaptor::GetGraphicsDisplay()
 
   if (mGraphics)
   {
-    auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
+    GraphicsInterface* graphics = mGraphics.get(); // This interface is temporary until Core has been updated to match
+    auto eglGraphics = static_cast<EglGraphics *>( graphics );
 
     EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
     display = eglImpl.GetDisplay();
@@ -884,6 +964,8 @@ void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
 
 void Adaptor::OnWindowShown()
 {
+  Dali::Accessibility::Bridge::GetCurrentBridge()->ApplicationShown();
+
   if( PAUSED_WHILE_HIDDEN == mState )
   {
     // Adaptor can now be resumed
@@ -901,6 +983,11 @@ void Adaptor::OnWindowShown()
 
     DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Update requested.\n" );
   }
+  else if( PAUSED_WHILE_INITIALIZING == mState )
+  {
+    // Change the state to READY again. It will be changed to RUNNING after the adaptor is started.
+    mState = READY;
+  }
   else
   {
     DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState );
@@ -909,6 +996,8 @@ void Adaptor::OnWindowShown()
 
 void Adaptor::OnWindowHidden()
 {
+  Dali::Accessibility::Bridge::GetCurrentBridge()->ApplicationHidden();
+
   if( RUNNING == mState || READY == mState )
   {
     bool allWindowsHidden = true;
@@ -1010,7 +1099,21 @@ void Adaptor::NotifyLanguageChanged()
 
 void Adaptor::RenderOnce()
 {
-  RequestUpdateOnce();
+  if( mThreadController )
+  {
+    UpdateMode updateMode;
+    if( mThreadMode == ThreadMode::NORMAL )
+    {
+      updateMode = UpdateMode::NORMAL;
+    }
+    else
+    {
+      updateMode = UpdateMode::FORCE_RENDER;
+
+      ProcessCoreEvents();
+    }
+    mThreadController->RequestUpdateOnce( updateMode );
+  }
 }
 
 const LogFactoryInterface& Adaptor::GetLogFactory()
@@ -1033,11 +1136,6 @@ bool Adaptor::IsMultipleWindowSupported() const
   return mConfigurationManager->IsMultipleWindowSupported();
 }
 
-bool Adaptor::IsRenderingWindows() const
-{
-  return ( mThreadController && mThreadController->IsRenderingWindows() );
-}
-
 void Adaptor::RequestUpdateOnce()
 {
   if( mThreadController )
@@ -1100,7 +1198,17 @@ Dali::SceneHolderList Adaptor::GetSceneHolders() const
   return sceneHolderList;
 }
 
-Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions)
+Dali::ObjectRegistry Adaptor::GetObjectRegistry() const
+{
+  Dali::ObjectRegistry registry;
+  if( mCore )
+  {
+    registry = mCore->GetObjectRegistry();
+  }
+  return registry;
+}
+
+Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode )
 : mResizedSignal(),
   mLanguageChangedSignal(),
   mWindowCreatedSignal(),
@@ -1126,8 +1234,10 @@ Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor,
   mSystemTracer(),
   mObjectProfiler( nullptr ),
   mSocketFactory(),
+  mThreadMode( threadMode ),
   mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
-  mUseRemoteSurface( false )
+  mUseRemoteSurface( false ),
+  mRootLayoutDirection( Dali::LayoutDirection::LEFT_TO_RIGHT )
 {
   DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
   mWindows.insert( mWindows.begin(), &Dali::GetImplementation( window ) );
@@ -1137,10 +1247,12 @@ Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor,
 
 void Adaptor::SetRootLayoutDirection( std::string locale )
 {
-  Dali::Stage stage = Dali::Stage::GetCurrent();
-
-  stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
-                                    static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
+  mRootLayoutDirection = static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) );
+  for ( auto& window : mWindows )
+  {
+    Dali::Actor root = window->GetRootLayer();
+    root.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection );
+  }
 }
 
 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
@@ -1153,6 +1265,12 @@ bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
     idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
   }
 
+  if( !idleAdded )
+  {
+    // Delete callback
+    delete callback;
+  }
+
   return idleAdded;
 }