Revert "Remove EGL surface in the update thread"
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / adaptor-impl.cpp
index d42eff5..2ecb543 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -20,6 +20,8 @@
 #include <dali/internal/adaptor/common/adaptor-builder-impl.h>
 
 // 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/integration-api/events/wheel-event-integ.h>
 #include <dali/integration-api/processor-interface.h>
 
-#include <fstream>
-
 // INTERNAL INCLUDES
 #include <dali/public-api/dali-adaptor-common.h>
 #include <dali/internal/system/common/thread-controller.h>
 #include <dali/internal/system/common/performance-interface-factory.h>
 #include <dali/internal/adaptor/common/lifecycle-observer.h>
+#include <dali/internal/adaptor/common/thread-controller-interface.h>
 
 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
 #include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
@@ -58,6 +59,7 @@
 #include <dali/internal/clipboard/common/clipboard-impl.h>
 #include <dali/internal/system/common/object-profiler.h>
 #include <dali/internal/window-system/common/display-connection.h>
+#include <dali/internal/window-system/common/display-utils.h> // For Utils::MakeUnique
 #include <dali/internal/window-system/common/window-impl.h>
 #include <dali/internal/window-system/common/window-render-surface.h>
 
@@ -67,7 +69,8 @@
 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
 #include <dali/internal/imaging/common/image-loader.h>
 
-#include <dali/devel-api/adaptor-framework/file-stream.h>
+#include <dali/internal/system/common/configuration-manager.h>
+#include <dali/internal/system/common/environment-variables.h>
 
 using Dali::TextAbstraction::FontClient;
 
@@ -84,7 +87,9 @@ namespace Adaptor
 
 namespace
 {
+
 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
+
 } // unnamed namespace
 
 Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
@@ -142,14 +147,6 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
   GetDataStoragePath( path );
   mPlatformAbstraction->SetDataStoragePath( path );
 
-  ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
-  if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS )
-  {
-    dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
-  }
-
-  // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from files automatically.
-
   if( mEnvironmentOptions->PerformanceServerRequired() )
   {
     mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, *mEnvironmentOptions );
@@ -181,18 +178,15 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
                                   mGLES,
                                   eglSyncImpl,
                                   eglContextHelperImpl,
-                                  dataRetentionPolicy ,
                                   ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
                                   mGraphics->GetDepthBufferRequired(),
                                   mGraphics->GetStencilBufferRequired() );
 
   defaultWindow->SetAdaptor( Get() );
 
-  Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( defaultWindow ) );
-  if ( window )
-  {
-    mWindowCreatedSignal.Emit( window );
-  }
+  Dali::Integration::SceneHolder defaultSceneHolder( defaultWindow );
+
+  mWindowCreatedSignal.Emit( defaultSceneHolder );
 
   const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
   if( 0u < timeInterval )
@@ -200,7 +194,7 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
     mObjectProfiler = new ObjectProfiler( timeInterval );
   }
 
-  mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
+  mNotificationTrigger = TriggerEventFactory::CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
 
   mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow->GetSurface()->GetSurfaceType() );
 
@@ -283,46 +277,39 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
   {
     Integration::SetPinchGestureMinimumDistance( mEnvironmentOptions->GetMinimumPinchDistance() );
   }
-
-  // Set max texture size
-  if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
+  if( mEnvironmentOptions->GetMinimumPinchTouchEvents() >= 0 )
   {
-    Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
+    Integration::SetPinchGestureMinimumTouchEvents( mEnvironmentOptions->GetMinimumPinchTouchEvents() );
+  }
+  if( mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart() >= 0 )
+  {
+    Integration::SetPinchGestureMinimumTouchEventsAfterStart( mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart() );
+  }
+  if( mEnvironmentOptions->GetMinimumRotationTouchEvents() >= 0 )
+  {
+    Integration::SetRotationGestureMinimumTouchEvents( mEnvironmentOptions->GetMinimumRotationTouchEvents() );
+  }
+  if( mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart() >= 0 )
+  {
+    Integration::SetRotationGestureMinimumTouchEventsAfterStart( mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart() );
+  }
+  if( mEnvironmentOptions->GetLongPressMinimumHoldingTime() >= 0 )
+  {
+    Integration::SetLongPressMinimumHoldingTime( mEnvironmentOptions->GetLongPressMinimumHoldingTime() );
   }
 
   std::string systemCachePath = GetSystemCachePath();
-  if ( systemCachePath.c_str() != NULL )
+  if( ! systemCachePath.empty() )
   {
-    Dali::FileStream fileStream( systemCachePath + "gpu-environment.conf", Dali::FileStream::READ | Dali::FileStream::TEXT );
-    std::fstream& stream = dynamic_cast<std::fstream&>( fileStream.GetStream() );
-    if( stream.is_open() )
-    {
-      std::string line;
-      while( std::getline( stream, line ) )
-      {
-        line.erase( line.find_last_not_of( " \t\r\n" ) + 1 );
-        line.erase( 0, line.find_first_not_of( " \t\r\n" ) );
-        if( '#' == *( line.cbegin() ) || line == "" )
-        {
-          continue;
-        }
-
-        std::istringstream stream( line );
-        std::string environmentVariableName, environmentVariableValue;
-        std::getline(stream, environmentVariableName, ' ');
-        if( environmentVariableName == "DALI_ENV_MAX_TEXTURE_SIZE" && mEnvironmentOptions->GetMaxTextureSize() == 0 )
-        {
-          std::getline(stream, environmentVariableValue);
-          setenv( environmentVariableName.c_str() , environmentVariableValue.c_str(), 1 );
-          Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( std::atoi( environmentVariableValue.c_str() ) );
-        }
-      }
-    }
-    else
+    const int dir_err = mkdir( systemCachePath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH );
+    if ( 0 != dir_err && errno != EEXIST )
     {
-      DALI_LOG_ERROR( "Fail to open file : %s\n", ( systemCachePath + "gpu-environment.conf" ).c_str() );
+      DALI_LOG_ERROR( "Error creating system cache directory: %s!\n", systemCachePath.c_str() );
+      exit( 1 );
     }
   }
+
+  mConfigurationManager = Utils::MakeUnique<ConfigurationManager>( systemCachePath, eglGraphics, mThreadController );
 }
 
 Adaptor::~Adaptor()
@@ -392,29 +379,16 @@ void Adaptor::Start()
   // Initialize the thread controller
   mThreadController->Initialize();
 
-  if( !Dali::TizenPlatform::ImageLoader::MaxTextureSizeUpdated() )
+  // Set max texture size
+  if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
   {
-    auto eglGraphics = static_cast<EglGraphics *>( mGraphics );
-    GlImplementation& mGLES = eglGraphics->GetGlesInterface();
-    Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mGLES.GetMaxTextureSize() );
-
-    std::string systemCachePath = GetSystemCachePath();
-    if( systemCachePath.c_str() != NULL )
-    {
-      const int dir_err = system( std::string( "mkdir " + systemCachePath ).c_str() );
-      if (-1 == dir_err)
-      {
-          printf("Error creating directory!n");
-          exit(1);
-      }
-
-      Dali::FileStream fileStream( systemCachePath + "gpu-environment.conf", Dali::FileStream::WRITE | Dali::FileStream::TEXT );
-      std::fstream& configFile = dynamic_cast<std::fstream&>( fileStream.GetStream() );
-      if( configFile.is_open() )
-      {
-        configFile << "DALI_ENV_MAX_TEXTURE_SIZE " << mGLES.GetMaxTextureSize() << std::endl;
-      }
-    }
+    Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
+  }
+  else
+  {
+    unsigned int maxTextureSize = mConfigurationManager->GetMaxTextureSize();
+    setenv( DALI_ENV_MAX_TEXTURE_SIZE, std::to_string( maxTextureSize ).c_str(), 1 );
+    Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( maxTextureSize );
   }
 
   ProcessCoreEvents(); // Ensure any startup messages are processed.
@@ -583,16 +557,6 @@ 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();
@@ -632,6 +596,12 @@ 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 );
@@ -645,11 +615,11 @@ bool Adaptor::AddWindow( Dali::Integration::SceneHolder childWindow, const std::
   // Add the new Window to the container - the order is not important
   mWindows.push_back( &windowImpl );
 
-  Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( &windowImpl ) );
-  if ( window )
-  {
-    mWindowCreatedSignal.Emit( window );
-  }
+  Dali::RenderSurfaceInterface* surface = windowImpl.GetSurface();
+
+  mThreadController->AddSurface( surface );
+
+  mWindowCreatedSignal.Emit( childWindow );
 
   return true;
 }
@@ -745,11 +715,6 @@ TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
   return *mNotificationTrigger;
 }
 
-TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
-{
-  return mTriggerEventFactory;
-}
-
 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
 {
   return mSocketFactory;
@@ -786,6 +751,11 @@ Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
   return *mPlatformAbstraction;
 }
 
+void Adaptor::GetWindowContainerInterface( WindowContainer& windows )
+{
+  windows = mWindows;
+}
+
 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
 {
   if( mTtsPlayers[mode] )
@@ -799,6 +769,24 @@ Any Adaptor::GetNativeWindowHandle()
   return mWindows.front()->GetNativeHandle();
 }
 
+Any Adaptor::GetNativeWindowHandle( Dali::Actor actor )
+{
+  Any nativeWindowHandle;
+
+  Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
+
+  for( auto sceneHolder : mWindows )
+  {
+    if ( scene == sceneHolder->GetScene() )
+    {
+      nativeWindowHandle = sceneHolder->GetNativeHandle();
+      break;
+    }
+  }
+
+  return nativeWindowHandle;
+}
+
 Any Adaptor::GetGraphicsDisplay()
 {
   Any display;
@@ -877,11 +865,10 @@ void Adaptor::RequestUpdate( bool forceUpdate )
     case PAUSED:
     case PAUSED_WHILE_HIDDEN:
     {
-      // When Dali applications are partially visible behind the lock-screen,
-      // the indicator must be updated (therefore allow updates in the PAUSED state)
       if( forceUpdate )
       {
-        mThreadController->RequestUpdateOnce();
+        // Update (and resource upload) without rendering
+        mThreadController->RequestUpdateOnce( UpdateMode::SKIP_RENDER );
       }
       break;
     }
@@ -984,11 +971,12 @@ void Adaptor::SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, Surfa
 
 void Adaptor::SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
 {
+  // Nofify surface resizing before flushing event queue
+  mThreadController->ResizeSurface();
+
   // 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();
-
-  mThreadController->ResizeSurface();
 }
 
 void Adaptor::NotifySceneCreated()
@@ -1048,11 +1036,21 @@ void Adaptor::UnregisterProcessor( Integration::Processor& processor )
   GetCore().UnregisterProcessor(processor);
 }
 
+bool Adaptor::IsMultipleWindowSupported() const
+{
+  return mConfigurationManager->IsMultipleWindowSupported();
+}
+
+bool Adaptor::IsRenderingWindows() const
+{
+  return ( mThreadController && mThreadController->IsRenderingWindows() );
+}
+
 void Adaptor::RequestUpdateOnce()
 {
   if( mThreadController )
   {
-    mThreadController->RequestUpdateOnce();
+    mThreadController->RequestUpdateOnce( UpdateMode::NORMAL );
   }
 }
 
@@ -1098,6 +1096,18 @@ Dali::WindowContainer Adaptor::GetWindows() const
   return windows;
 }
 
+Dali::SceneHolderList Adaptor::GetSceneHolders() const
+{
+  Dali::SceneHolderList sceneHolderList;
+
+  for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
+  {
+    sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
+  }
+
+  return sceneHolderList;
+}
+
 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions)
 : mResizedSignal(),
   mLanguageChangedSignal(),
@@ -1109,6 +1119,7 @@ Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor,
   mGraphics( nullptr ),
   mDisplayConnection( nullptr ),
   mWindows(),
+  mConfigurationManager( nullptr ),
   mPlatformAbstraction( nullptr ),
   mCallbackManager( nullptr ),
   mNotificationOnIdleInstalled( false ),
@@ -1121,7 +1132,6 @@ Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor,
   mPerformanceInterface( nullptr ),
   mKernelTracer(),
   mSystemTracer(),
-  mTriggerEventFactory(),
   mObjectProfiler( nullptr ),
   mSocketFactory(),
   mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),