2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/system/common/configuration-manager.h>
22 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/file-stream.h>
27 #include <dali/internal/graphics/common/graphics-interface.h>
28 #include <dali/internal/system/common/environment-options.h>
29 #include <dali/internal/system/common/environment-variables.h>
30 #include <dali/internal/system/common/thread-controller.h>
40 const std::string SYSTEM_CACHE_FILE = "gpu-environment.conf";
41 const std::string DALI_ENV_MULTIPLE_WINDOW_SUPPORT = "DALI_ENV_MULTIPLE_WINDOW_SUPPORT";
42 const std::string DALI_BLEND_EQUATION_ADVANCED_SUPPORT = "DALI_BLEND_EQUATION_ADVANCED_SUPPORT";
43 const std::string DALI_GLSL_VERSION = "DALI_GLSL_VERSION";
45 } // unnamed namespace
47 ConfigurationManager::ConfigurationManager(std::string systemCachePath, GraphicsInterface* graphics, ThreadController* threadController)
48 : mSystemCacheFilePath(systemCachePath + SYSTEM_CACHE_FILE),
50 mThreadController(threadController),
52 mShaderLanguageVersion(0u),
53 mIsMultipleWindowSupported(true),
54 mIsAdvancedBlendEquationSupported(true),
55 mMaxTextureSizeCached(false),
56 mIsMultipleWindowSupportedCached(false),
57 mIsAdvancedBlendEquationSupportedCached(false),
58 mShaderLanguageVersionCached(false)
62 ConfigurationManager::~ConfigurationManager()
66 void ConfigurationManager::RetrieveKeysFromConfigFile(const std::string& configFilePath)
68 Dali::FileStream configFile(configFilePath, Dali::FileStream::READ | Dali::FileStream::TEXT);
69 std::iostream& stream = configFile.GetStream();
70 if(stream.rdbuf()->in_avail())
73 while(std::getline(stream, line))
75 line.erase(line.find_last_not_of(" \t\r\n") + 1);
76 line.erase(0, line.find_first_not_of(" \t\r\n"));
77 if('#' == *(line.cbegin()) || line == "")
82 std::istringstream subStream(line);
85 std::getline(subStream, name, ' ');
86 if(!mMaxTextureSizeCached && name == DALI_ENV_MAX_TEXTURE_SIZE)
88 std::getline(subStream, value);
89 mMaxTextureSize = std::atoi(value.c_str());
90 mMaxTextureSizeCached = true;
92 else if(!mIsAdvancedBlendEquationSupportedCached && name == DALI_BLEND_EQUATION_ADVANCED_SUPPORT)
94 std::getline(subStream, value);
95 mIsAdvancedBlendEquationSupported = std::atoi(value.c_str());
96 mIsAdvancedBlendEquationSupportedCached = true;
98 else if(!mShaderLanguageVersionCached && name == DALI_GLSL_VERSION)
100 std::getline(subStream, value);
101 mShaderLanguageVersion = std::atoi(value.c_str());
102 mShaderLanguageVersionCached = true;
104 else if(!mIsMultipleWindowSupportedCached && name == DALI_ENV_MULTIPLE_WINDOW_SUPPORT)
106 std::getline(subStream, value);
107 mIsMultipleWindowSupported = std::atoi(value.c_str());
108 mIsMultipleWindowSupportedCached = true;
114 uint32_t ConfigurationManager::GetMaxTextureSize()
116 if(!mMaxTextureSizeCached)
118 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
120 if(!mMaxTextureSizeCached)
122 if(!mGraphics->IsInitialized())
124 // Wait until Graphics Subsystem is initialised, but this will happen once.
125 // This method blocks until the render thread has initialised the graphics.
126 mThreadController->WaitForGraphicsInitialization();
129 mMaxTextureSize = mGraphics->GetMaxTextureSize();
130 mMaxTextureSizeCached = true;
132 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
133 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
136 stream << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
140 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
145 return mMaxTextureSize;
148 uint32_t ConfigurationManager::GetShadingLanguageVersion()
150 if(!mShaderLanguageVersionCached)
152 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
154 if(!mShaderLanguageVersionCached)
156 if(!mGraphics->IsInitialized())
158 // Wait until Graphics Subsystem is initialised, but this will happen once.
159 // This method blocks until the render thread has initialised the graphics.
160 mThreadController->WaitForGraphicsInitialization();
163 // Query from graphics and save the cache
164 mShaderLanguageVersion = mGraphics->GetShaderLanguageVersion();
165 mShaderLanguageVersionCached = true;
167 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
168 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
171 stream << DALI_GLSL_VERSION << " " << mShaderLanguageVersion << std::endl;
175 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
180 return mShaderLanguageVersion;
183 bool ConfigurationManager::IsMultipleWindowSupported()
185 if(!mIsMultipleWindowSupportedCached)
187 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
189 if(!mIsMultipleWindowSupportedCached)
191 if(!mGraphics->IsInitialized())
193 // Wait until Graphics Subsystem is initialised, but this will happen once.
194 // This method blocks until the render thread has initialised the graphics.
195 mThreadController->WaitForGraphicsInitialization();
198 // Query from Graphics Subsystem and save the cache
199 mIsMultipleWindowSupported = mGraphics->IsResourceContextSupported();
200 mIsMultipleWindowSupportedCached = true;
202 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
203 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
206 stream << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
210 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
215 return mIsMultipleWindowSupported;
218 bool ConfigurationManager::IsAdvancedBlendEquationSupported()
220 if(!mIsAdvancedBlendEquationSupportedCached)
222 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
224 if(!mIsAdvancedBlendEquationSupportedCached)
226 if(!mGraphics->IsInitialized())
228 // Wait until graphics subsystem is initialised, but this will happen once per factory reset.
229 // This method blocks until the render thread has initialised the graphics.
230 mThreadController->WaitForGraphicsInitialization();
233 // Query from Graphics Subsystem and save the cache
234 mIsAdvancedBlendEquationSupported = mGraphics->IsAdvancedBlendEquationSupported();
235 mIsAdvancedBlendEquationSupportedCached = true;
237 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
238 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
241 stream << DALI_BLEND_EQUATION_ADVANCED_SUPPORT << " " << mIsAdvancedBlendEquationSupported << std::endl;
245 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
250 return mIsAdvancedBlendEquationSupported;
253 } // namespace Adaptor
255 } // namespace Internal