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 32f373ef728bde2409a7c6ee02bcd836f3989374..90a3a1563b81364842d98b24c3ff4906794f8306 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 1a3095106af98ece760f1df1519d58a8dbe7de82..45d350b2419c079868d31b4ec52e1a385d1b37a5 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 4935c939b527048ea90e87648ec98e916f430588..cbcc87acbb422b1291e2d151e958831f58799122 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 fd39a3a4eed808e3a8df1490f2dac2e543c49651..49e96017511e77d10a1d3b8d0a4923db667f8457 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 12702432b504488dc9d36b4c4110a595cd447916..8be71f8d4c592455322ea39ee3c67747f4649a44 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 b55883153f7edc47e1e745b7d59b792a9ea638f9..03e511e9acde852cb75a0f5e9584b08f36a78314 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.
@@ -136,6 +136,11 @@ public:
    */
   virtual void ResizeSurface();
 
+  /**
+   * @copydoc ThreadControllerInterface::WaitForGraphicsInitialization()
+   */
+  virtual void WaitForGraphicsInitialization();
+
   /**
    * @copydoc ThreadControllerInterface::SetRenderRefreshRate()
    */
@@ -289,6 +294,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 8c63c7d68b23edb831bf77b752828d5c0c37ca81..99317d61ffb0c211c6e3d64cd66ac0c085cfb71d 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.
@@ -103,6 +103,11 @@ public:
    */
   virtual void ResizeSurface() = 0;
 
+  /**
+   * Wait until the graphics is initialised.
+   */
+  virtual void WaitForGraphicsInitialization() = 0;
+
   /**
    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
    */
index 32343934185b0ba181c9f6167cf579a48596f187..c653ab609adee5a057f3b5e9b99467d1628bb596 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 cd6671dbe0e744372f04a48d92da9aec4a137400..fbe90dc957cd13e37033e813672f98a123276ff4 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 686c653fc0f36f50cea245e600cb6c07055a4936..e1f1c84e9a7b5c635845cb1671ccd893aa0c2358 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.
@@ -122,6 +122,11 @@ public:
    */
   void ResizeSurface();
 
+  /**
+   * Wait until the graphics is initialised.
+   */
+  void WaitForGraphicsInitialization();
+
   /**
    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
    */
index 4b57b1407caf50c28469e12ce211a7ad299df261..0ac2ec5911c9435e3ea517e403873e2a66cc9e4a 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