Fix the crash when it assumes the platform does not support multiple windows as GL... 67/223167/8
authorRichard Huang <r.huang@samsung.com>
Thu, 23 Jan 2020 14:18:25 +0000 (14:18 +0000)
committerRichard Huang <r.huang@samsung.com>
Thu, 30 Jan 2020 14:39:42 +0000 (14:39 +0000)
Change-Id: Iaaced2a7154079485f89ab1cff9750d3ed4f6ea6

13 files changed:
dali/devel-api/adaptor-framework/file-stream.h
dali/internal/adaptor-framework/generic/file-stream-impl-generic.cpp
dali/internal/adaptor/common/adaptor-impl.cpp
dali/internal/adaptor/common/adaptor-impl.h
dali/internal/adaptor/common/combined-update-render-controller.cpp
dali/internal/adaptor/common/combined-update-render-controller.h
dali/internal/adaptor/common/thread-controller-interface.h
dali/internal/graphics/gles/egl-implementation.cpp
dali/internal/system/common/configuration-manager.cpp [new file with mode: 0644]
dali/internal/system/common/configuration-manager.h [new file with mode: 0644]
dali/internal/system/common/thread-controller.cpp
dali/internal/system/common/thread-controller.h
dali/internal/system/file.list

index 32f373e..90a3a15 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_FILE_STREAM_H
 
 /*
- * 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.
@@ -42,10 +42,11 @@ public:
    */
   enum FileMode  ///< FileType format
   {
-    BINARY = 0x1,      ///< File stream will be opened as a binary
-    TEXT   = 0x2,      ///< File stream will be opened as text
-    READ   = 0x4,      ///< File stream will be opened for reading
-    WRITE  = 0x8,      ///< File stream will be opende for writing
+    BINARY = 1 << 0,      ///< File stream will be opened as a binary
+    TEXT   = 1 << 1,      ///< File stream will be opened as text
+    READ   = 1 << 2,      ///< File stream will be opened for reading
+    WRITE  = 1 << 3,      ///< File stream will be opened for writing
+    APPEND = 1 << 4,      ///< File stream will be opened for appending
   };
 
   /**
index 1a30951..45d350b 100644 (file)
@@ -106,14 +106,20 @@ std::iostream& FileStream::Impl::GetStream()
     return mBufferStream;
   }
 
-  std::ios_base::openmode openMode;
-  if( mMode & Dali::FileStream::WRITE )
+  int openMode = 0;
+
+  if( mMode & Dali::FileStream::APPEND )
   {
-    openMode = ( std::ios::out | std::ios::ate );
+    openMode |= ( std::ios::out | std::ios::app );
   }
-  else
+  else if( mMode & Dali::FileStream::WRITE )
+  {
+    openMode |= ( std::ios::out | std::ios::ate );
+  }
+
+  if( mMode & Dali::FileStream::READ )
   {
-    openMode = std::ios::in;
+    openMode |= std::ios::in;
   }
 
   if( mMode & Dali::FileStream::BINARY )
@@ -123,10 +129,10 @@ std::iostream& FileStream::Impl::GetStream()
 
   if( !mFileName.empty() )
   {
-    mFileStream.open( mFileName, openMode );
+    mFileStream.open( mFileName, static_cast<std::ios_base::openmode>( openMode ) );
     if( !mFileStream.is_open() )
     {
-      DALI_LOG_WARNING( "stream open failed for: \"%s\", in mode: \"%d\".\n", mFileName, static_cast<int>( openMode ) );
+      DALI_LOG_WARNING( "stream open failed for: \"%s\", in mode: \"%d\".\n", mFileName.c_str(), openMode );
     }
     return mFileStream;
   }
@@ -136,7 +142,7 @@ std::iostream& FileStream::Impl::GetStream()
     if( !mBufferStream.rdbuf()->in_avail() )
     {
       DALI_LOG_WARNING( "File open failed for memory buffer at location: \"%p\", of size: \"%u\", in mode: \"%d\".\n",
-          static_cast<void*>( mBuffer ), static_cast<unsigned>( mDataSize ), static_cast<int>( openMode ) );
+          static_cast<void*>( mBuffer ), static_cast<unsigned>( mDataSize ), openMode );
     }
   }
 
@@ -159,7 +165,11 @@ FILE* FileStream::Impl::GetFile()
   char openMode[16] = { 0 };
   int i = 0;
 
-  if( mMode & Dali::FileStream::WRITE )
+  if( mMode & Dali::FileStream::APPEND )
+  {
+    openMode[i++] = 'a';
+  }
+  else if( mMode & Dali::FileStream::WRITE )
   {
     openMode[i++] = 'w';
   }
index 4935c93..cbcc87a 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.
@@ -34,8 +34,6 @@
 #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>
@@ -59,6 +57,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>
 
@@ -68,7 +67,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;
 
@@ -85,7 +85,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 )
@@ -287,45 +289,18 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
     Integration::SetLongPressMinimumHoldingTime( mEnvironmentOptions->GetLongPressMinimumHoldingTime() );
   }
 
-  // Set max texture size
-  if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
-  {
-    Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
-  }
-
   std::string systemCachePath = GetSystemCachePath();
-  if ( ! systemCachePath.empty() )
+  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() )
+    const int dir_err = system( std::string( "mkdir " + systemCachePath ).c_str() );
+    if (-1 == dir_err)
     {
-      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
-    {
-      DALI_LOG_ERROR( "Fail to open file : %s\n", ( systemCachePath + "gpu-environment.conf" ).c_str() );
+        printf( "Error creating system cache directory: %s!\n", systemCachePath.c_str() );
+        exit(1);
     }
   }
+
+  mConfigurationManager = Utils::MakeUnique<ConfigurationManager>( systemCachePath, eglGraphics, mThreadController );
 }
 
 Adaptor::~Adaptor()
@@ -395,29 +370,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.empty() )
-    {
-      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.
@@ -1066,10 +1028,7 @@ void Adaptor::UnregisterProcessor( Integration::Processor& processor )
 
 bool Adaptor::IsMultipleWindowSupported() const
 {
-  auto eglGraphics = static_cast<EglGraphics *>( mGraphics );
-  EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
-  bool ret = eglImpl.IsSurfacelessContextSupported();
-  return ret;
+  return mConfigurationManager->IsMultipleWindowSupported();
 }
 
 void Adaptor::RequestUpdateOnce()
@@ -1145,6 +1104,7 @@ Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor,
   mGraphics( nullptr ),
   mDisplayConnection( nullptr ),
   mWindows(),
+  mConfigurationManager( nullptr ),
   mPlatformAbstraction( nullptr ),
   mCallbackManager( nullptr ),
   mNotificationOnIdleInstalled( false ),
index fd39a3a..49e9601 100755 (executable)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_ADAPTOR_IMPL_H
 
 /*
- * 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.
@@ -75,6 +75,7 @@ class PerformanceInterface;
 class LifeCycleObserver;
 class ObjectProfiler;
 class SceneHolder;
+class ConfigurationManager;
 
 /**
  * Implementation of the Adaptor class.
@@ -662,6 +663,8 @@ private: // Data
   Dali::DisplayConnection*              mDisplayConnection;           ///< Display connection
   WindowContainer                       mWindows;                     ///< A container of all the Windows that are currently created
 
+  std::unique_ptr<ConfigurationManager> mConfigurationManager;        ///< Configuration manager
+
   TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction;      ///< Platform abstraction
 
   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
@@ -679,7 +682,7 @@ private: // Data
   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
   SocketFactory                         mSocketFactory;               ///< Socket factory
   const bool                            mEnvironmentOptionsOwned:1;   ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
-  bool                                  mUseRemoteSurface;            ///< whether the remoteSurface is used or not
+  bool                                  mUseRemoteSurface:1;          ///< whether the remoteSurface is used or not
 
 public:
   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
index 1270243..8be71f8 100644 (file)
@@ -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.
@@ -91,6 +91,7 @@ CombinedUpdateRenderController::CombinedUpdateRenderController( AdaptorInternalS
 : mFpsTracker( environmentOptions ),
   mUpdateStatusLogger( environmentOptions ),
   mEventThreadSemaphore(),
+  mGraphicsInitializeSemaphore(),
   mUpdateRenderThreadWaitCondition(),
   mAdaptorInterfaces( adaptorInterfaces ),
   mPerformanceInterface( adaptorInterfaces.GetPerformanceInterface() ),
@@ -134,7 +135,9 @@ CombinedUpdateRenderController::CombinedUpdateRenderController( AdaptorInternalS
   TriggerEventFactoryInterface& triggerFactory = mAdaptorInterfaces.GetTriggerEventFactoryInterface();
   mSleepTrigger = triggerFactory.CreateTriggerEvent( MakeCallback( this, &CombinedUpdateRenderController::ProcessSleepRequest ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER );
 
-  sem_init( &mEventThreadSemaphore, 0, 0 ); // Initialize to 0 so that it just waits if sem_post has not been called
+  // Initialize to 0 so that it just waits if sem_post has not been called
+  sem_init( &mEventThreadSemaphore, 0, 0 );
+  sem_init( &mGraphicsInitializeSemaphore, 0, 0 );
 }
 
 CombinedUpdateRenderController::~CombinedUpdateRenderController()
@@ -343,6 +346,21 @@ void CombinedUpdateRenderController::DeleteSurface( Dali::RenderSurfaceInterface
   }
 }
 
+void CombinedUpdateRenderController::WaitForGraphicsInitialization()
+{
+  LOG_EVENT_TRACE;
+
+  if( mUpdateRenderThread )
+  {
+    LOG_EVENT( "Waiting for graphics initialisation, event-thread blocked" );
+
+    // Wait until the graphics has been initialised
+    sem_wait( &mGraphicsInitializeSemaphore );
+
+    LOG_EVENT( "graphics initialised, event-thread continuing" );
+  }
+}
+
 void CombinedUpdateRenderController::ResizeSurface()
 {
   LOG_EVENT_TRACE;
@@ -457,6 +475,9 @@ void CombinedUpdateRenderController::UpdateRenderThread()
   Dali::DisplayConnection& displayConnection = mAdaptorInterfaces.GetDisplayConnectionInterface();
   displayConnection.Initialize();
 
+  // EGL has been initialised at this point
+  NotifyGraphicsInitialised();
+
   RenderSurfaceInterface* currentSurface = nullptr;
 
   GraphicsInterface& graphics = mAdaptorInterfaces.GetGraphicsInterface();
@@ -849,6 +870,11 @@ void CombinedUpdateRenderController::NotifyThreadInitialised()
   sem_post( &mEventThreadSemaphore );
 }
 
+void CombinedUpdateRenderController::NotifyGraphicsInitialised()
+{
+  sem_post( &mGraphicsInitializeSemaphore );
+}
+
 void CombinedUpdateRenderController::AddPerformanceMarker( PerformanceInterface::MarkerType type )
 {
   if( mPerformanceInterface )
index b558831..03e511e 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_COMBINED_UPDATE_RENDER_CONTROLLER_H
 
 /*
- * 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.
@@ -137,6 +137,11 @@ public:
   virtual void ResizeSurface();
 
   /**
+   * @copydoc ThreadControllerInterface::WaitForGraphicsInitialization()
+   */
+  virtual void WaitForGraphicsInitialization();
+
+  /**
    * @copydoc ThreadControllerInterface::SetRenderRefreshRate()
    */
   virtual void SetRenderRefreshRate( unsigned int numberOfFramesPerRender );
@@ -290,6 +295,11 @@ private:
   void NotifyThreadInitialised();
 
   /**
+   * Called by the update-render thread when graphics has been initialised.
+   */
+  void NotifyGraphicsInitialised();
+
+  /**
    * Helper to add a performance marker to the performance server (if it's active)
    * @param[in]  type  performance marker type
    */
@@ -328,6 +338,7 @@ private:
   UpdateStatusLogger                mUpdateStatusLogger;               ///< Object that logs the update-status as required.
 
   sem_t                             mEventThreadSemaphore;             ///< Used by the event thread to ensure all threads have been initialised, and when replacing the surface.
+  sem_t                             mGraphicsInitializeSemaphore;      ///< Used by the render thread to ensure the graphics has been initialised.
 
   ConditionalWait                   mUpdateRenderThreadWaitCondition;  ///< The wait condition for the update-render-thread.
 
index 8c63c7d..99317d6 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_THREAD_CONTROLLER_INTERFACE_H
 
 /*
- * 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.
@@ -104,6 +104,11 @@ public:
   virtual void ResizeSurface() = 0;
 
   /**
+   * Wait until the graphics is initialised.
+   */
+  virtual void WaitForGraphicsInitialization() = 0;
+
+  /**
    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
    */
   virtual void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender ) = 0;
index 3234393..c653ab6 100755 (executable)
@@ -115,7 +115,6 @@ bool EglImplementation::InitializeGles( EGLNativeDisplayType display, bool isOwn
     }
     eglBindAPI(EGL_OPENGL_ES_API);
 
-    mGlesInitialized = true;
     mIsOwnSurface = isOwnSurface;
   }
 
@@ -138,6 +137,8 @@ bool EglImplementation::InitializeGles( EGLNativeDisplayType display, bool isOwn
     }
   }
 
+  mGlesInitialized = true;
+
   // We want to display this information all the time, so use the LogMessage directly
   Integration::Log::LogMessage(Integration::Log::DebugInfo, "EGL Information\n"
       "            Vendor:        %s\n"
diff --git a/dali/internal/system/common/configuration-manager.cpp b/dali/internal/system/common/configuration-manager.cpp
new file mode 100644 (file)
index 0000000..975749e
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali/internal/system/common/configuration-manager.h>
+
+// EXTERNAL INCLUDES
+#include <fstream>
+#include <dali/integration-api/debug.h>
+
+// INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/file-stream.h>
+#include <dali/internal/graphics/gles/egl-graphics.h>
+#include <dali/internal/system/common/environment-options.h>
+#include <dali/internal/system/common/environment-variables.h>
+#include <dali/internal/system/common/thread-controller.h>
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Adaptor
+{
+
+namespace
+{
+
+const std::string SYSTEM_CACHE_FILE = "gpu-environment.conf";
+const std::string DALI_ENV_MULTIPLE_WINDOW_SUPPORT = "DALI_ENV_MULTIPLE_WINDOW_SUPPORT";
+
+bool RetrieveKeyFromFile( std::fstream& stream, std::string key, std::string& value )
+{
+  bool keyFound = false;
+
+  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 name;
+    std::getline(stream, name, ' ');
+    if( name == key )
+    {
+      std::getline(stream, value);
+      keyFound = true;
+      break;
+    }
+  }
+
+  return keyFound;
+}
+
+
+} // unnamed namespace
+
+ConfigurationManager::ConfigurationManager( std::string systemCachePath, EglGraphics* eglGraphics, ThreadController* threadController )
+: mSystemCacheFilePath( systemCachePath + SYSTEM_CACHE_FILE ),
+  mFileStream( new Dali::FileStream( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT ) ),
+  mEglGraphics( eglGraphics ),
+  mThreadController( threadController ),
+  mMaxTextureSize( 0u ),
+  mIsMultipleWindowSupported( true ),
+  mMaxTextureSizeCached( false ) ,
+  mIsMultipleWindowSupportedCached( false )
+{
+}
+
+ConfigurationManager::~ConfigurationManager()
+{
+}
+
+unsigned int ConfigurationManager::GetMaxTextureSize()
+{
+  if ( !mMaxTextureSizeCached )
+  {
+    std::fstream& configFile = dynamic_cast<std::fstream&>( mFileStream->GetStream() );
+    if( configFile.is_open() )
+    {
+      std::string environmentVariableValue;
+      if( RetrieveKeyFromFile( configFile, DALI_ENV_MAX_TEXTURE_SIZE, environmentVariableValue ) )
+      {
+        mMaxTextureSize = std::atoi( environmentVariableValue.c_str() );
+      }
+      else
+      {
+        GlImplementation& mGLES = mEglGraphics->GetGlesInterface();
+        mMaxTextureSize = mGLES.GetMaxTextureSize();
+
+        configFile.clear();
+        configFile << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
+      }
+
+      mMaxTextureSizeCached = true;
+
+      if ( mIsMultipleWindowSupportedCached )
+      {
+        configFile.close();
+      }
+    }
+    else
+    {
+      DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
+    }
+  }
+
+  return mMaxTextureSize;
+}
+
+bool ConfigurationManager::IsMultipleWindowSupported()
+{
+  if ( !mIsMultipleWindowSupportedCached )
+  {
+    std::fstream& configFile = dynamic_cast<std::fstream&>( mFileStream->GetStream() );
+    if( configFile.is_open() )
+    {
+      std::string environmentVariableValue;
+      if( RetrieveKeyFromFile( configFile, DALI_ENV_MULTIPLE_WINDOW_SUPPORT, environmentVariableValue ) )
+      {
+        mIsMultipleWindowSupported = std::atoi( environmentVariableValue.c_str() );
+      }
+      else
+      {
+        EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
+        if ( !eglImpl.IsGlesInitialized() )
+        {
+          // Wait until GLES is initialised, but this will happen once.
+          // This method blocks until the render thread has initialised the graphics.
+          mThreadController->WaitForGraphicsInitialization();
+        }
+
+        // Query from GLES and save the cache
+        mIsMultipleWindowSupported = eglImpl.IsSurfacelessContextSupported();
+
+        configFile.clear();
+        configFile << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
+      }
+
+      mIsMultipleWindowSupportedCached = true;
+
+      if ( mMaxTextureSizeCached )
+      {
+        configFile.close();
+      }
+    }
+    else
+    {
+      DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
+    }
+  }
+
+  return mIsMultipleWindowSupported;
+}
+
+} // Adaptor
+
+} // Internal
+
+} // Dali
diff --git a/dali/internal/system/common/configuration-manager.h b/dali/internal/system/common/configuration-manager.h
new file mode 100644 (file)
index 0000000..105a5b4
--- /dev/null
@@ -0,0 +1,96 @@
+#ifndef DALI_INTERNAL_ENVIRONMENT_CONFIGURATION_MANAGER_H
+#define DALI_INTERNAL_ENVIRONMENT_CONFIGURATION_MANAGER_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <memory>
+#include <string>
+
+namespace Dali
+{
+
+class FileStream;
+
+namespace Internal
+{
+namespace Adaptor
+{
+
+class EglGraphics;
+class ThreadController;
+
+/**
+ * This class retrieves and caches the system configuration.
+ *
+ */
+class ConfigurationManager
+{
+public:
+
+  /**
+   * @brief Constructor
+   */
+  ConfigurationManager( std::string systemCachePath, EglGraphics* eglGraphics, ThreadController* threadController );
+
+  /**
+   * @brief Virtual Destructor for interface cleanup
+   */
+  virtual ~ConfigurationManager();
+
+  /**
+   * @brief Get the maximum texture size.
+   * @return The maximum texture size
+   */
+  unsigned int GetMaxTextureSize();
+
+  /**
+   * @brief Check whether multiple window is supported
+   * @return Whether multiple window is supported
+   */
+  bool IsMultipleWindowSupported();
+
+  // Deleted copy constructor.
+  ConfigurationManager( const ConfigurationManager& ) = delete;
+
+  // Deleted move constructor.
+  ConfigurationManager( const ConfigurationManager&& ) = delete;
+
+  // Deleted assignment operator.
+  ConfigurationManager& operator=( const ConfigurationManager& ) = delete;
+
+  // Deleted move assignment operator.
+  ConfigurationManager& operator=( const ConfigurationManager&& ) = delete;
+
+private: // Data
+
+  std::string mSystemCacheFilePath;              ///< The path of system cache file
+  std::unique_ptr<FileStream> mFileStream;       ///< The file stream to access the system cache
+  EglGraphics* mEglGraphics;                     ///< EGL graphics
+  ThreadController* mThreadController;           ///< The thread controller
+  unsigned int mMaxTextureSize;                  ///< The largest texture that the GL can handle
+  bool mIsMultipleWindowSupported:1;             ///< Whether multiple window is supported by the GLES
+  bool mMaxTextureSizeCached:1;                  ///< Whether we have checked the maximum texture size
+  bool mIsMultipleWindowSupportedCached:1;       ///< Whether we have checked the support of multiple window
+};
+
+} // Adaptor
+} // Internal
+} // Dali
+
+#endif // DALI_INTERNAL_ENVIRONMENT_CONFIGURATION_MANAGER_H
index cd6671d..fbe90dc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 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.
@@ -100,6 +100,11 @@ void ThreadController::ResizeSurface()
   mThreadControllerInterface->ResizeSurface();
 }
 
+void ThreadController::WaitForGraphicsInitialization()
+{
+  mThreadControllerInterface->WaitForGraphicsInitialization();
+}
+
 void ThreadController::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender )
 {
   mThreadControllerInterface->SetRenderRefreshRate( numberOfVSyncsPerRender );
index 686c653..e1f1c84 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_THREAD_CONTROLLER_H
 
 /*
- * 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.
@@ -123,6 +123,11 @@ public:
   void ResizeSurface();
 
   /**
+   * Wait until the graphics is initialised.
+   */
+  void WaitForGraphicsInitialization();
+
+  /**
    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
    */
   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
index 4b57b14..0ac2ec5 100644 (file)
@@ -4,6 +4,7 @@ SET( adaptor_system_common_src_files
     ${adaptor_system_dir}/common/abort-handler.cpp
     ${adaptor_system_dir}/common/color-controller-impl.cpp
     ${adaptor_system_dir}/common/command-line-options.cpp
+    ${adaptor_system_dir}/common/configuration-manager.cpp
     ${adaptor_system_dir}/common/environment-options.cpp
     ${adaptor_system_dir}/common/fps-tracker.cpp
     ${adaptor_system_dir}/common/frame-time-stamp.cpp