[Tizen] remove setenv() that can cause Seg fault
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / adaptor-impl.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 2ecb543..b43c376
@@ -22,9 +22,9 @@
 // EXTERNAL INCLUDES
 #include <errno.h>
 #include <sys/stat.h>
-#include <dali/public-api/common/stage.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/devel-api/actors/actor-devel.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/core.h>
@@ -161,10 +161,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();
@@ -180,7 +181,8 @@ 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() );
 
@@ -191,14 +193,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() )
@@ -387,7 +389,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 );
   }
 
@@ -557,6 +558,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();
@@ -702,7 +713,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()
@@ -793,7 +804,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();
@@ -1018,7 +1030,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()
@@ -1041,11 +1067,6 @@ bool Adaptor::IsMultipleWindowSupported() const
   return mConfigurationManager->IsMultipleWindowSupported();
 }
 
-bool Adaptor::IsRenderingWindows() const
-{
-  return ( mThreadController && mThreadController->IsRenderingWindows() );
-}
-
 void Adaptor::RequestUpdateOnce()
 {
   if( mThreadController )
@@ -1108,6 +1129,16 @@ Dali::SceneHolderList Adaptor::GetSceneHolders() const
   return sceneHolderList;
 }
 
+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)
 : mResizedSignal(),
   mLanguageChangedSignal(),
@@ -1134,6 +1165,7 @@ Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor,
   mSystemTracer(),
   mObjectProfiler( nullptr ),
   mSocketFactory(),
+  mThreadMode( ThreadMode::NORMAL ),
   mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
   mUseRemoteSurface( false )
 {
@@ -1145,10 +1177,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 ) ) ) );
+  for ( auto& window : mWindows )
+  {
+    Dali::Actor root = window->GetRootLayer();
+    root.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
+                      static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
+  }
 }
 
 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )