Merge "Fix svace issue for image-operator" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / configuration-manager.cpp
index e587db8..ff77416 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 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.
@@ -37,38 +37,11 @@ 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";
-const std::string DALI_BLEND_EQUATION_ADVANCED_SUPPORT = "DALI_BLEND_EQUATION_ADVANCED_SUPPORT";
-const std::string DALI_GLSL_VERSION                    = "DALI_GLSL_VERSION";
-
-bool RetrieveKeyFromConfigFile(std::iostream& stream, const 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;
-}
+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
 
@@ -80,9 +53,11 @@ ConfigurationManager::ConfigurationManager(std::string systemCachePath, Graphics
   mShaderLanguageVersion(0u),
   mIsMultipleWindowSupported(true),
   mIsAdvancedBlendEquationSupported(true),
+  mIsMultisampledRenderToTextureSupported(true),
   mMaxTextureSizeCached(false),
   mIsMultipleWindowSupportedCached(false),
   mIsAdvancedBlendEquationSupportedCached(false),
+  mIsMultisampledRenderToTextureSupportedCached(false),
   mShaderLanguageVersionCached(false)
 {
 }
@@ -97,33 +72,50 @@ void ConfigurationManager::RetrieveKeysFromConfigFile(const std::string& configF
   std::iostream&   stream = configFile.GetStream();
   if(stream.rdbuf()->in_avail())
   {
-    std::string value;
-    if(!mMaxTextureSizeCached &&
-       RetrieveKeyFromConfigFile(stream, DALI_ENV_MAX_TEXTURE_SIZE, value))
-    {
-      mMaxTextureSize       = std::atoi(value.c_str());
-      mMaxTextureSizeCached = true;
-    }
-
-    if(!mShaderLanguageVersionCached &&
-       RetrieveKeyFromConfigFile(stream, DALI_GLSL_VERSION, value))
-    {
-      mShaderLanguageVersion       = std::atoi(value.c_str());
-      mShaderLanguageVersionCached = true;
-    }
-
-    if(!mIsMultipleWindowSupportedCached &&
-       RetrieveKeyFromConfigFile(stream, DALI_ENV_MULTIPLE_WINDOW_SUPPORT, value))
+    std::string line;
+    while(std::getline(stream, line))
     {
-      mIsMultipleWindowSupported       = std::atoi(value.c_str());
-      mIsMultipleWindowSupportedCached = true;
-    }
+      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;
+      }
 
-    if(!mIsAdvancedBlendEquationSupportedCached &&
-       RetrieveKeyFromConfigFile(stream, DALI_BLEND_EQUATION_ADVANCED_SUPPORT, value))
-    {
-      mIsAdvancedBlendEquationSupported       = std::atoi(value.c_str());
-      mIsAdvancedBlendEquationSupportedCached = true;
+      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;
+      }
+      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;
+      }
     }
   }
 }
@@ -136,6 +128,13 @@ uint32_t ConfigurationManager::GetMaxTextureSize()
 
     if(!mMaxTextureSizeCached)
     {
+      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;
 
@@ -171,8 +170,7 @@ uint32_t ConfigurationManager::GetShadingLanguageVersion()
       }
 
       // Query from graphics and save the cache
-      mShaderLanguageVersion = mGraphics->GetShaderLanguageVersion();
-      DALI_LOG_ERROR("mShaderLanguageVersion : %d\n", mShaderLanguageVersion);
+      mShaderLanguageVersion       = mGraphics->GetShaderLanguageVersion();
       mShaderLanguageVersionCached = true;
 
       Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
@@ -261,6 +259,41 @@ bool ConfigurationManager::IsAdvancedBlendEquationSupported()
   return mIsAdvancedBlendEquationSupported;
 }
 
+bool ConfigurationManager::IsMultisampledRenderToTextureSupported()
+{
+  if(!mIsMultisampledRenderToTextureSupportedCached)
+  {
+    RetrieveKeysFromConfigFile(mSystemCacheFilePath);
+
+    if(!mIsMultisampledRenderToTextureSupportedCached)
+    {
+      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();
+      }
+
+      // 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())
+      {
+        stream << DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT << " " << mIsMultisampledRenderToTextureSupported << std::endl;
+      }
+      else
+      {
+        DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
+      }
+    }
+  }
+
+  return mIsMultisampledRenderToTextureSupported;
+}
+
 } // namespace Adaptor
 
 } // namespace Internal