Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / configuration-manager.cpp
index 63b62dc..9f42c21 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
 #include <dali/internal/system/common/configuration-manager.h>
 
 // EXTERNAL INCLUDES
-#include <fstream>
 #include <dali/integration-api/debug.h>
+#include <fstream>
 
 // INTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/file-stream.h>
-#include <dali/internal/graphics/gles/egl-graphics.h>
+#include <dali/internal/graphics/common/graphics-interface.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 char* SYSTEM_CACHE_FILE                           = "gpu-environment.conf";
+const char* DALI_ENV_MULTIPLE_WINDOW_SUPPORT            = "DALI_ENV_MULTIPLE_WINDOW_SUPPORT";
+const char* DALI_BLEND_EQUATION_ADVANCED_SUPPORT        = "DALI_BLEND_EQUATION_ADVANCED_SUPPORT";
+const char* DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT = "DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT";
+const char* DALI_GLSL_VERSION                           = "DALI_GLSL_VERSION";
+
+} // unnamed namespace
 
-const std::string SYSTEM_CACHE_FILE = "gpu-environment.conf";
-const std::string DALI_ENV_MULTIPLE_WINDOW_SUPPORT = "DALI_ENV_MULTIPLE_WINDOW_SUPPORT";
+ConfigurationManager::ConfigurationManager(std::string systemCachePath, GraphicsInterface* graphics, ThreadController* threadController)
+: mSystemCacheFilePath(systemCachePath + SYSTEM_CACHE_FILE),
+  mGraphics(graphics),
+  mThreadController(threadController),
+  mMaxTextureSize(0u),
+  mMaxCombinedTextureUnits(0u),
+  mShaderLanguageVersion(0u),
+  mIsMultipleWindowSupported(true),
+  mIsAdvancedBlendEquationSupported(true),
+  mIsMultisampledRenderToTextureSupported(true),
+  mMaxTextureSizeCached(false),
+  mIsMultipleWindowSupportedCached(false),
+  mIsAdvancedBlendEquationSupportedCached(false),
+  mIsMultisampledRenderToTextureSupportedCached(false),
+  mShaderLanguageVersionCached(false),
+  mMaxCombinedTextureUnitsCached(false)
+{
+}
 
-bool RetrieveKeyFromConfigFile( std::iostream& stream, const std::string& key, std::string& value )
+ConfigurationManager::~ConfigurationManager()
 {
-  bool keyFound = false;
+}
 
-  std::string line;
-  while( std::getline( stream, line ) )
+void ConfigurationManager::RetrieveKeysFromConfigFile(const std::string& configFilePath)
+{
+  Dali::FileStream configFile(configFilePath, Dali::FileStream::READ | Dali::FileStream::TEXT);
+  std::iostream&   stream = configFile.GetStream();
+  if(stream.rdbuf()->in_avail())
   {
-    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 == "" )
+    std::string line;
+    while(std::getline(stream, line))
     {
-      continue;
+      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 subStream(line);
+      std::string        name;
+      std::string        value;
+      std::getline(subStream, name, ' ');
+      if(!mMaxTextureSizeCached && name == DALI_ENV_MAX_TEXTURE_SIZE)
+      {
+        std::getline(subStream, value);
+        mMaxTextureSize       = std::atoi(value.c_str());
+        mMaxTextureSizeCached = true;
+      }
+      if(!mMaxCombinedTextureUnitsCached && name == DALI_ENV_MAX_COMBINED_TEXTURE_UNITS)
+      {
+        std::getline(subStream, value);
+        mMaxCombinedTextureUnits       = std::atoi(value.c_str());
+        mMaxCombinedTextureUnitsCached = true;
+      }
+      else if(!mIsAdvancedBlendEquationSupportedCached && name == DALI_BLEND_EQUATION_ADVANCED_SUPPORT)
+      {
+        std::getline(subStream, value);
+        mIsAdvancedBlendEquationSupported       = std::atoi(value.c_str());
+        mIsAdvancedBlendEquationSupportedCached = true;
+      }
+      else if(!mIsMultisampledRenderToTextureSupportedCached && name == DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT)
+      {
+        std::getline(subStream, value);
+        mIsMultisampledRenderToTextureSupported       = std::atoi(value.c_str());
+        mIsMultisampledRenderToTextureSupportedCached = true;
+      }
+      else if(!mShaderLanguageVersionCached && name == DALI_GLSL_VERSION)
+      {
+        std::getline(subStream, value);
+        mShaderLanguageVersion       = std::atoi(value.c_str());
+        mShaderLanguageVersionCached = true;
+      }
+      else if(!mIsMultipleWindowSupportedCached && name == DALI_ENV_MULTIPLE_WINDOW_SUPPORT)
+      {
+        std::getline(subStream, value);
+        mIsMultipleWindowSupported       = std::atoi(value.c_str());
+        mIsMultipleWindowSupportedCached = true;
+      }
     }
+  }
+}
+
+uint32_t ConfigurationManager::GetMaxTextureSize()
+{
+  if(!mMaxTextureSizeCached)
+  {
+    RetrieveKeysFromConfigFile(mSystemCacheFilePath);
 
-    std::istringstream stream( line );
-    std::string name;
-    std::getline(stream, name, ' ');
-    if( name == key )
+    if(!mMaxTextureSizeCached)
     {
-      std::getline(stream, value);
-      keyFound = true;
-      break;
+      if(!mGraphics->IsInitialized())
+      {
+        // Wait until Graphics Subsystem is initialised, but this will happen once.
+        // This method blocks until the render thread has initialised the graphics.
+        mThreadController->WaitForGraphicsInitialization();
+      }
+
+      mMaxTextureSize       = mGraphics->GetMaxTextureSize();
+      mMaxTextureSizeCached = true;
+
+      Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
+      std::fstream&    stream = dynamic_cast<std::fstream&>(configFile.GetStream());
+      if(stream.is_open())
+      {
+        stream << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
+      }
+      else
+      {
+        DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
+      }
     }
   }
 
-  return keyFound;
+  return mMaxTextureSize;
 }
 
+uint32_t ConfigurationManager::GetMaxCombinedTextureUnits()
+{
+  if(!mMaxCombinedTextureUnitsCached)
+  {
+    RetrieveKeysFromConfigFile(mSystemCacheFilePath);
 
-} // unnamed namespace
+    if(!mMaxCombinedTextureUnitsCached)
+    {
+      if(!mGraphics->IsInitialized())
+      {
+        // Wait until Graphics Subsystem is initialised, but this will happen once.
+        // This method blocks until the render thread has initialised the graphics.
+        mThreadController->WaitForGraphicsInitialization();
+      }
 
-ConfigurationManager::ConfigurationManager( std::string systemCachePath, EglGraphics* eglGraphics, ThreadController* threadController )
-: mSystemCacheFilePath( systemCachePath + SYSTEM_CACHE_FILE ),
-  mEglGraphics( eglGraphics ),
-  mThreadController( threadController ),
-  mMaxTextureSize( 0u ),
-  mIsMultipleWindowSupported( true ),
-  mMaxTextureSizeCached( false ) ,
-  mIsMultipleWindowSupportedCached( false )
-{
-}
+      mMaxCombinedTextureUnits       = mGraphics->GetMaxCombinedTextureUnits();
+      mMaxCombinedTextureUnitsCached = true;
+      DALI_LOG_RENDER_INFO("MaxCombinedTextureUnits = %d\n", mMaxCombinedTextureUnits);
 
-ConfigurationManager::~ConfigurationManager()
-{
+      Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
+      std::fstream&    stream = dynamic_cast<std::fstream&>(configFile.GetStream());
+      if(stream.is_open())
+      {
+        stream << DALI_ENV_MAX_COMBINED_TEXTURE_UNITS << " " << mMaxCombinedTextureUnits << std::endl;
+      }
+      else
+      {
+        DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
+      }
+    }
+  }
+
+  return mMaxCombinedTextureUnits;
 }
 
-void ConfigurationManager::RetrieveKeysFromConfigFile( const std::string& configFilePath )
+uint32_t ConfigurationManager::GetShadingLanguageVersion()
 {
-  Dali::FileStream configFile( configFilePath, Dali::FileStream::READ | Dali::FileStream::TEXT );
-  std::iostream& stream = configFile.GetStream();
-  if( stream.rdbuf()->in_avail() )
+  if(!mShaderLanguageVersionCached)
   {
-    std::string value;
-    if( !mMaxTextureSizeCached &&
-        RetrieveKeyFromConfigFile( stream, DALI_ENV_MAX_TEXTURE_SIZE, value ) )
+    RetrieveKeysFromConfigFile(mSystemCacheFilePath);
+
+    if(!mShaderLanguageVersionCached)
     {
-      mMaxTextureSize = std::atoi( value.c_str() );
-      mMaxTextureSizeCached = true;
+      if(!mGraphics->IsInitialized())
+      {
+        // Wait until Graphics Subsystem is initialised, but this will happen once.
+        // This method blocks until the render thread has initialised the graphics.
+        mThreadController->WaitForGraphicsInitialization();
+      }
+
+      // Query from graphics and save the cache
+      mShaderLanguageVersion       = mGraphics->GetShaderLanguageVersion();
+      mShaderLanguageVersionCached = true;
+
+      Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
+      std::fstream&    stream = dynamic_cast<std::fstream&>(configFile.GetStream());
+      if(stream.is_open())
+      {
+        stream << DALI_GLSL_VERSION << " " << mShaderLanguageVersion << std::endl;
+      }
+      else
+      {
+        DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
+      }
     }
+  }
+
+  return mShaderLanguageVersion;
+}
+
+bool ConfigurationManager::IsMultipleWindowSupported()
+{
+  if(!mIsMultipleWindowSupportedCached)
+  {
+    RetrieveKeysFromConfigFile(mSystemCacheFilePath);
 
-    if( !mIsMultipleWindowSupportedCached &&
-        RetrieveKeyFromConfigFile( stream, DALI_ENV_MULTIPLE_WINDOW_SUPPORT, value ) )
+    if(!mIsMultipleWindowSupportedCached)
     {
-      mIsMultipleWindowSupported = std::atoi( value.c_str() );
+      if(!mGraphics->IsInitialized())
+      {
+        // Wait until Graphics Subsystem is initialised, but this will happen once.
+        // This method blocks until the render thread has initialised the graphics.
+        mThreadController->WaitForGraphicsInitialization();
+      }
+
+      // Query from Graphics Subsystem and save the cache
+      mIsMultipleWindowSupported       = mGraphics->IsResourceContextSupported();
       mIsMultipleWindowSupportedCached = true;
+
+      Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
+      std::fstream&    stream = dynamic_cast<std::fstream&>(configFile.GetStream());
+      if(stream.is_open())
+      {
+        stream << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
+      }
+      else
+      {
+        DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
+      }
     }
   }
+
+  return mIsMultipleWindowSupported;
 }
 
-unsigned int ConfigurationManager::GetMaxTextureSize()
+bool ConfigurationManager::IsAdvancedBlendEquationSupported()
 {
-  if( !mMaxTextureSizeCached )
+  if(!mIsAdvancedBlendEquationSupportedCached)
   {
-    RetrieveKeysFromConfigFile( mSystemCacheFilePath );
+    RetrieveKeysFromConfigFile(mSystemCacheFilePath);
 
-    if( !mMaxTextureSizeCached )
+    if(!mIsAdvancedBlendEquationSupportedCached)
     {
-      GlImplementation& mGLES = mEglGraphics->GetGlesInterface();
-      mMaxTextureSize = mGLES.GetMaxTextureSize();
-      mMaxTextureSizeCached = true;
+      if(!mGraphics->IsInitialized())
+      {
+        // Wait until graphics subsystem is initialised, but this will happen once per factory reset.
+        // This method blocks until the render thread has initialised the graphics.
+        mThreadController->WaitForGraphicsInitialization();
+      }
 
-      Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
-      std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
-      if( stream.is_open() )
+      // Query from Graphics Subsystem and save the cache
+      mIsAdvancedBlendEquationSupported       = mGraphics->IsAdvancedBlendEquationSupported();
+      mIsAdvancedBlendEquationSupportedCached = true;
+
+      Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
+      std::fstream&    stream = dynamic_cast<std::fstream&>(configFile.GetStream());
+      if(stream.is_open())
       {
-        stream << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
+        stream << DALI_BLEND_EQUATION_ADVANCED_SUPPORT << " " << mIsAdvancedBlendEquationSupported << std::endl;
       }
       else
       {
-        DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
+        DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
       }
     }
   }
 
-  return mMaxTextureSize;
+  return mIsAdvancedBlendEquationSupported;
 }
 
-bool ConfigurationManager::IsMultipleWindowSupported()
+bool ConfigurationManager::IsMultisampledRenderToTextureSupported()
 {
-  if ( !mIsMultipleWindowSupportedCached )
+  if(!mIsMultisampledRenderToTextureSupportedCached)
   {
-    RetrieveKeysFromConfigFile( mSystemCacheFilePath );
+    RetrieveKeysFromConfigFile(mSystemCacheFilePath);
 
-    if ( !mIsMultipleWindowSupportedCached )
+    if(!mIsMultisampledRenderToTextureSupportedCached)
     {
-      EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
-      if ( !eglImpl.IsGlesInitialized() )
+      if(!mGraphics->IsInitialized())
       {
-        // Wait until GLES is initialised, but this will happen once.
+        // Wait until graphics subsystem is initialised, but this will happen once per factory reset.
         // This method blocks until the render thread has initialised the graphics.
         mThreadController->WaitForGraphicsInitialization();
       }
 
-      // Query from GLES and save the cache
-      mIsMultipleWindowSupported = eglImpl.IsSurfacelessContextSupported();
-      mIsMultipleWindowSupportedCached = true;
+      // Query from Graphics Subsystem and save the cache
+      mIsMultisampledRenderToTextureSupported       = mGraphics->IsMultisampledRenderToTextureSupported();
+      mIsMultisampledRenderToTextureSupportedCached = true;
 
-      Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
-      std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
-      if ( stream.is_open() )
+      Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
+      std::fstream&    stream = dynamic_cast<std::fstream&>(configFile.GetStream());
+      if(stream.is_open())
       {
-        stream << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
+        stream << DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT << " " << mIsMultisampledRenderToTextureSupported << std::endl;
       }
       else
       {
-        DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
+        DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
       }
     }
   }
 
-  return mIsMultipleWindowSupported;
+  return mIsMultisampledRenderToTextureSupported;
 }
 
-} // Adaptor
+} // namespace Adaptor
 
-} // Internal
+} // namespace Internal
 
-} // Dali
+} // namespace Dali