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_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT = "DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT";
44 const std::string 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 mShaderLanguageVersion(0u),
54 mIsMultipleWindowSupported(true),
55 mIsAdvancedBlendEquationSupported(true),
56 mIsMultisampledRenderToTextureSupported(true),
57 mMaxTextureSizeCached(false),
58 mIsMultipleWindowSupportedCached(false),
59 mIsAdvancedBlendEquationSupportedCached(false),
60 mIsMultisampledRenderToTextureSupportedCached(false),
61 mShaderLanguageVersionCached(false)
65 ConfigurationManager::~ConfigurationManager()
69 void ConfigurationManager::RetrieveKeysFromConfigFile(const std::string& configFilePath)
71 Dali::FileStream configFile(configFilePath, Dali::FileStream::READ | Dali::FileStream::TEXT);
72 std::iostream& stream = configFile.GetStream();
73 if(stream.rdbuf()->in_avail())
76 while(std::getline(stream, line))
78 line.erase(line.find_last_not_of(" \t\r\n") + 1);
79 line.erase(0, line.find_first_not_of(" \t\r\n"));
80 if('#' == *(line.cbegin()) || line == "")
85 std::istringstream subStream(line);
88 std::getline(subStream, name, ' ');
89 if(!mMaxTextureSizeCached && name == DALI_ENV_MAX_TEXTURE_SIZE)
91 std::getline(subStream, value);
92 mMaxTextureSize = std::atoi(value.c_str());
93 mMaxTextureSizeCached = true;
95 else if(!mIsAdvancedBlendEquationSupportedCached && name == DALI_BLEND_EQUATION_ADVANCED_SUPPORT)
97 std::getline(subStream, value);
98 mIsAdvancedBlendEquationSupported = std::atoi(value.c_str());
99 mIsAdvancedBlendEquationSupportedCached = true;
101 else if(!mIsMultisampledRenderToTextureSupportedCached && name == DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT)
103 std::getline(subStream, value);
104 mIsMultisampledRenderToTextureSupported = std::atoi(value.c_str());
105 mIsMultisampledRenderToTextureSupportedCached = true;
107 else if(!mShaderLanguageVersionCached && name == DALI_GLSL_VERSION)
109 std::getline(subStream, value);
110 mShaderLanguageVersion = std::atoi(value.c_str());
111 mShaderLanguageVersionCached = true;
113 else if(!mIsMultipleWindowSupportedCached && name == DALI_ENV_MULTIPLE_WINDOW_SUPPORT)
115 std::getline(subStream, value);
116 mIsMultipleWindowSupported = std::atoi(value.c_str());
117 mIsMultipleWindowSupportedCached = true;
123 uint32_t ConfigurationManager::GetMaxTextureSize()
125 if(!mMaxTextureSizeCached)
127 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
129 if(!mMaxTextureSizeCached)
131 if(!mGraphics->IsInitialized())
133 // Wait until Graphics Subsystem is initialised, but this will happen once.
134 // This method blocks until the render thread has initialised the graphics.
135 mThreadController->WaitForGraphicsInitialization();
138 mMaxTextureSize = mGraphics->GetMaxTextureSize();
139 mMaxTextureSizeCached = true;
141 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
142 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
145 stream << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
149 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
154 return mMaxTextureSize;
157 uint32_t ConfigurationManager::GetShadingLanguageVersion()
159 if(!mShaderLanguageVersionCached)
161 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
163 if(!mShaderLanguageVersionCached)
165 if(!mGraphics->IsInitialized())
167 // Wait until Graphics Subsystem is initialised, but this will happen once.
168 // This method blocks until the render thread has initialised the graphics.
169 mThreadController->WaitForGraphicsInitialization();
172 // Query from graphics and save the cache
173 mShaderLanguageVersion = mGraphics->GetShaderLanguageVersion();
174 mShaderLanguageVersionCached = true;
176 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
177 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
180 stream << DALI_GLSL_VERSION << " " << mShaderLanguageVersion << std::endl;
184 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
189 return mShaderLanguageVersion;
192 bool ConfigurationManager::IsMultipleWindowSupported()
194 if(!mIsMultipleWindowSupportedCached)
196 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
198 if(!mIsMultipleWindowSupportedCached)
200 if(!mGraphics->IsInitialized())
202 // Wait until Graphics Subsystem is initialised, but this will happen once.
203 // This method blocks until the render thread has initialised the graphics.
204 mThreadController->WaitForGraphicsInitialization();
207 // Query from Graphics Subsystem and save the cache
208 mIsMultipleWindowSupported = mGraphics->IsResourceContextSupported();
209 mIsMultipleWindowSupportedCached = true;
211 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
212 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
215 stream << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
219 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
224 return mIsMultipleWindowSupported;
227 bool ConfigurationManager::IsAdvancedBlendEquationSupported()
229 if(!mIsAdvancedBlendEquationSupportedCached)
231 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
233 if(!mIsAdvancedBlendEquationSupportedCached)
235 if(!mGraphics->IsInitialized())
237 // Wait until graphics subsystem is initialised, but this will happen once per factory reset.
238 // This method blocks until the render thread has initialised the graphics.
239 mThreadController->WaitForGraphicsInitialization();
242 // Query from Graphics Subsystem and save the cache
243 mIsAdvancedBlendEquationSupported = mGraphics->IsAdvancedBlendEquationSupported();
244 mIsAdvancedBlendEquationSupportedCached = true;
246 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
247 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
250 stream << DALI_BLEND_EQUATION_ADVANCED_SUPPORT << " " << mIsAdvancedBlendEquationSupported << std::endl;
254 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
259 return mIsAdvancedBlendEquationSupported;
262 bool ConfigurationManager::IsMultisampledRenderToTextureSupported()
264 if(!mIsMultisampledRenderToTextureSupportedCached)
266 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
268 if(!mIsMultisampledRenderToTextureSupportedCached)
270 if(!mGraphics->IsInitialized())
272 // Wait until graphics subsystem is initialised, but this will happen once per factory reset.
273 // This method blocks until the render thread has initialised the graphics.
274 mThreadController->WaitForGraphicsInitialization();
277 // Query from Graphics Subsystem and save the cache
278 mIsMultisampledRenderToTextureSupported = mGraphics->IsMultisampledRenderToTextureSupported();
279 mIsMultisampledRenderToTextureSupportedCached = true;
281 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
282 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
285 stream << DALI_MULTISAMPLED_RENDER_TO_TEXTURE_SUPPORT << " " << mIsMultisampledRenderToTextureSupported << std::endl;
289 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
294 return mIsMultisampledRenderToTextureSupported;
297 } // namespace Adaptor
299 } // namespace Internal