2 * Copyright (c) 2023 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 char* SYSTEM_CACHE_FILE = "gpu-environment.conf";
41 const char* DALI_ENV_MULTIPLE_WINDOW_SUPPORT = "DALI_ENV_MULTIPLE_WINDOW_SUPPORT";
42 const char* DALI_BLEND_EQUATION_ADVANCED_SUPPORT = "DALI_BLEND_EQUATION_ADVANCED_SUPPORT";
43 const char* DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT = "DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT";
44 const char* DALI_GLSL_VERSION = "DALI_GLSL_VERSION";
46 } // unnamed namespace
48 ConfigurationManager::ConfigurationManager(std::string systemCachePath, GraphicsInterface* graphics, ThreadController* threadController)
49 : mSystemCacheFilePath(systemCachePath + SYSTEM_CACHE_FILE),
51 mThreadController(threadController),
53 mMaxCombinedTextureUnits(0u),
54 mShaderLanguageVersion(0u),
55 mIsMultipleWindowSupported(true),
56 mIsAdvancedBlendEquationSupported(true),
57 mIsMultisampledRenderToTextureSupported(true),
58 mMaxTextureSizeCached(false),
59 mIsMultipleWindowSupportedCached(false),
60 mIsAdvancedBlendEquationSupportedCached(false),
61 mIsMultisampledRenderToTextureSupportedCached(false),
62 mShaderLanguageVersionCached(false),
63 mMaxCombinedTextureUnitsCached(false)
67 ConfigurationManager::~ConfigurationManager()
71 void ConfigurationManager::RetrieveKeysFromConfigFile(const std::string& configFilePath)
73 Dali::FileStream configFile(configFilePath, Dali::FileStream::READ | Dali::FileStream::TEXT);
74 std::iostream& stream = configFile.GetStream();
75 if(stream.rdbuf()->in_avail())
78 while(std::getline(stream, line))
80 line.erase(line.find_last_not_of(" \t\r\n") + 1);
81 line.erase(0, line.find_first_not_of(" \t\r\n"));
82 if('#' == *(line.cbegin()) || line == "")
87 std::istringstream subStream(line);
90 std::getline(subStream, name, ' ');
91 if(!mMaxTextureSizeCached && name == DALI_ENV_MAX_TEXTURE_SIZE)
93 std::getline(subStream, value);
94 mMaxTextureSize = std::atoi(value.c_str());
95 mMaxTextureSizeCached = true;
97 if(!mMaxCombinedTextureUnitsCached && name == DALI_ENV_MAX_COMBINED_TEXTURE_UNITS)
99 std::getline(subStream, value);
100 mMaxCombinedTextureUnits = std::atoi(value.c_str());
101 mMaxCombinedTextureUnitsCached = true;
103 else if(!mIsAdvancedBlendEquationSupportedCached && name == DALI_BLEND_EQUATION_ADVANCED_SUPPORT)
105 std::getline(subStream, value);
106 mIsAdvancedBlendEquationSupported = std::atoi(value.c_str());
107 mIsAdvancedBlendEquationSupportedCached = true;
109 else if(!mIsMultisampledRenderToTextureSupportedCached && name == DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT)
111 std::getline(subStream, value);
112 mIsMultisampledRenderToTextureSupported = std::atoi(value.c_str());
113 mIsMultisampledRenderToTextureSupportedCached = true;
115 else if(!mShaderLanguageVersionCached && name == DALI_GLSL_VERSION)
117 std::getline(subStream, value);
118 mShaderLanguageVersion = std::atoi(value.c_str());
119 mShaderLanguageVersionCached = true;
121 else if(!mIsMultipleWindowSupportedCached && name == DALI_ENV_MULTIPLE_WINDOW_SUPPORT)
123 std::getline(subStream, value);
124 mIsMultipleWindowSupported = std::atoi(value.c_str());
125 mIsMultipleWindowSupportedCached = true;
131 uint32_t ConfigurationManager::GetMaxTextureSize()
133 if(!mMaxTextureSizeCached)
135 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
137 if(!mMaxTextureSizeCached)
139 if(!mGraphics->IsInitialized())
141 // Wait until Graphics Subsystem is initialised, but this will happen once.
142 // This method blocks until the render thread has initialised the graphics.
143 mThreadController->WaitForGraphicsInitialization();
146 mMaxTextureSize = mGraphics->GetMaxTextureSize();
147 mMaxTextureSizeCached = true;
149 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
150 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
153 stream << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
157 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
162 return mMaxTextureSize;
165 uint32_t ConfigurationManager::GetMaxCombinedTextureUnits()
167 if(!mMaxCombinedTextureUnitsCached)
169 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
171 if(!mMaxCombinedTextureUnitsCached)
173 if(!mGraphics->IsInitialized())
175 // Wait until Graphics Subsystem is initialised, but this will happen once.
176 // This method blocks until the render thread has initialised the graphics.
177 mThreadController->WaitForGraphicsInitialization();
180 mMaxCombinedTextureUnits = mGraphics->GetMaxCombinedTextureUnits();
181 mMaxCombinedTextureUnitsCached = true;
182 DALI_LOG_RENDER_INFO("MaxCombinedTextureUnits = %d\n", mMaxCombinedTextureUnits);
184 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
185 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
188 stream << DALI_ENV_MAX_COMBINED_TEXTURE_UNITS << " " << mMaxCombinedTextureUnits << std::endl;
192 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
197 return mMaxCombinedTextureUnits;
200 uint32_t ConfigurationManager::GetShadingLanguageVersion()
202 if(!mShaderLanguageVersionCached)
204 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
206 if(!mShaderLanguageVersionCached)
208 if(!mGraphics->IsInitialized())
210 // Wait until Graphics Subsystem is initialised, but this will happen once.
211 // This method blocks until the render thread has initialised the graphics.
212 mThreadController->WaitForGraphicsInitialization();
215 // Query from graphics and save the cache
216 mShaderLanguageVersion = mGraphics->GetShaderLanguageVersion();
217 mShaderLanguageVersionCached = true;
219 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
220 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
223 stream << DALI_GLSL_VERSION << " " << mShaderLanguageVersion << std::endl;
227 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
232 return mShaderLanguageVersion;
235 bool ConfigurationManager::IsMultipleWindowSupported()
237 if(!mIsMultipleWindowSupportedCached)
239 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
241 if(!mIsMultipleWindowSupportedCached)
243 if(!mGraphics->IsInitialized())
245 // Wait until Graphics Subsystem is initialised, but this will happen once.
246 // This method blocks until the render thread has initialised the graphics.
247 mThreadController->WaitForGraphicsInitialization();
250 // Query from Graphics Subsystem and save the cache
251 mIsMultipleWindowSupported = mGraphics->IsResourceContextSupported();
252 mIsMultipleWindowSupportedCached = true;
254 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
255 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
258 stream << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
262 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
267 return mIsMultipleWindowSupported;
270 bool ConfigurationManager::IsAdvancedBlendEquationSupported()
272 if(!mIsAdvancedBlendEquationSupportedCached)
274 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
276 if(!mIsAdvancedBlendEquationSupportedCached)
278 if(!mGraphics->IsInitialized())
280 // Wait until graphics subsystem is initialised, but this will happen once per factory reset.
281 // This method blocks until the render thread has initialised the graphics.
282 mThreadController->WaitForGraphicsInitialization();
285 // Query from Graphics Subsystem and save the cache
286 mIsAdvancedBlendEquationSupported = mGraphics->IsAdvancedBlendEquationSupported();
287 mIsAdvancedBlendEquationSupportedCached = true;
289 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
290 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
293 stream << DALI_BLEND_EQUATION_ADVANCED_SUPPORT << " " << mIsAdvancedBlendEquationSupported << std::endl;
297 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
302 return mIsAdvancedBlendEquationSupported;
305 bool ConfigurationManager::IsMultisampledRenderToTextureSupported()
307 if(!mIsMultisampledRenderToTextureSupportedCached)
309 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
311 if(!mIsMultisampledRenderToTextureSupportedCached)
313 if(!mGraphics->IsInitialized())
315 // Wait until graphics subsystem is initialised, but this will happen once per factory reset.
316 // This method blocks until the render thread has initialised the graphics.
317 mThreadController->WaitForGraphicsInitialization();
320 // Query from Graphics Subsystem and save the cache
321 mIsMultisampledRenderToTextureSupported = mGraphics->IsMultisampledRenderToTextureSupported();
322 mIsMultisampledRenderToTextureSupportedCached = true;
324 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
325 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
328 stream << DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT << " " << mIsMultisampledRenderToTextureSupported << std::endl;
332 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
337 return mIsMultisampledRenderToTextureSupported;
340 } // namespace Adaptor
342 } // namespace Internal