2 * Copyright (c) 2021 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 bool RetrieveKeyFromConfigFile(std::iostream& stream, const std::string& key, std::string& value)
47 bool keyFound = false;
50 while(std::getline(stream, line))
52 line.erase(line.find_last_not_of(" \t\r\n") + 1);
53 line.erase(0, line.find_first_not_of(" \t\r\n"));
54 if('#' == *(line.cbegin()) || line == "")
59 std::istringstream stream(line);
61 std::getline(stream, name, ' ');
64 std::getline(stream, value);
73 } // unnamed namespace
75 ConfigurationManager::ConfigurationManager(std::string systemCachePath, GraphicsInterface* graphics, ThreadController* threadController)
76 : mSystemCacheFilePath(systemCachePath + SYSTEM_CACHE_FILE),
78 mThreadController(threadController),
80 mShaderLanguageVersion(0u),
81 mIsMultipleWindowSupported(true),
82 mIsAdvancedBlendEquationSupported(true),
83 mMaxTextureSizeCached(false),
84 mIsMultipleWindowSupportedCached(false),
85 mIsAdvancedBlendEquationSupportedCached(false),
86 mShaderLanguageVersionCached(false)
90 ConfigurationManager::~ConfigurationManager()
94 void ConfigurationManager::RetrieveKeysFromConfigFile(const std::string& configFilePath)
96 Dali::FileStream configFile(configFilePath, Dali::FileStream::READ | Dali::FileStream::TEXT);
97 std::iostream& stream = configFile.GetStream();
98 if(stream.rdbuf()->in_avail())
101 if(!mMaxTextureSizeCached &&
102 RetrieveKeyFromConfigFile(stream, DALI_ENV_MAX_TEXTURE_SIZE, value))
104 mMaxTextureSize = std::atoi(value.c_str());
105 mMaxTextureSizeCached = true;
108 if(!mShaderLanguageVersionCached &&
109 RetrieveKeyFromConfigFile(stream, DALI_GLSL_VERSION, value))
111 mShaderLanguageVersion = std::atoi(value.c_str());
112 mShaderLanguageVersionCached = true;
115 if(!mIsMultipleWindowSupportedCached &&
116 RetrieveKeyFromConfigFile(stream, DALI_ENV_MULTIPLE_WINDOW_SUPPORT, value))
118 mIsMultipleWindowSupported = std::atoi(value.c_str());
119 mIsMultipleWindowSupportedCached = true;
122 if(!mIsAdvancedBlendEquationSupportedCached &&
123 RetrieveKeyFromConfigFile(stream, DALI_BLEND_EQUATION_ADVANCED_SUPPORT, value))
125 mIsAdvancedBlendEquationSupported = std::atoi(value.c_str());
126 mIsAdvancedBlendEquationSupportedCached = true;
131 uint32_t ConfigurationManager::GetMaxTextureSize()
133 if(!mMaxTextureSizeCached)
135 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
137 if(!mMaxTextureSizeCached)
139 mMaxTextureSize = mGraphics->GetMaxTextureSize();
140 mMaxTextureSizeCached = true;
142 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
143 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
146 stream << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
150 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
155 return mMaxTextureSize;
158 uint32_t ConfigurationManager::GetShadingLanguageVersion()
160 if(!mShaderLanguageVersionCached)
162 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
164 if(!mShaderLanguageVersionCached)
166 if(!mGraphics->IsInitialized())
168 // Wait until Graphics Subsystem is initialised, but this will happen once.
169 // This method blocks until the render thread has initialised the graphics.
170 mThreadController->WaitForGraphicsInitialization();
173 // Query from graphics and save the cache
174 mShaderLanguageVersion = mGraphics->GetShaderLanguageVersion();
175 DALI_LOG_ERROR("mShaderLanguageVersion : %d\n", mShaderLanguageVersion);
176 mShaderLanguageVersionCached = true;
178 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
179 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
182 stream << DALI_GLSL_VERSION << " " << mShaderLanguageVersion << std::endl;
186 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
191 return mShaderLanguageVersion;
194 bool ConfigurationManager::IsMultipleWindowSupported()
196 if(!mIsMultipleWindowSupportedCached)
198 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
200 if(!mIsMultipleWindowSupportedCached)
202 if(!mGraphics->IsInitialized())
204 // Wait until Graphics Subsystem is initialised, but this will happen once.
205 // This method blocks until the render thread has initialised the graphics.
206 mThreadController->WaitForGraphicsInitialization();
209 // Query from Graphics Subsystem and save the cache
210 mIsMultipleWindowSupported = mGraphics->IsResourceContextSupported();
211 mIsMultipleWindowSupportedCached = true;
213 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
214 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
217 stream << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
221 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
226 return mIsMultipleWindowSupported;
229 bool ConfigurationManager::IsAdvancedBlendEquationSupported()
231 if(!mIsAdvancedBlendEquationSupportedCached)
233 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
235 if(!mIsAdvancedBlendEquationSupportedCached)
237 if(!mGraphics->IsInitialized())
239 // Wait until graphics subsystem is initialised, but this will happen once per factory reset.
240 // This method blocks until the render thread has initialised the graphics.
241 mThreadController->WaitForGraphicsInitialization();
244 // Query from Graphics Subsystem and save the cache
245 mIsAdvancedBlendEquationSupported = mGraphics->IsAdvancedBlendEquationSupported();
246 mIsAdvancedBlendEquationSupportedCached = true;
248 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
249 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
252 stream << DALI_BLEND_EQUATION_ADVANCED_SUPPORT << " " << mIsAdvancedBlendEquationSupported << std::endl;
256 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
261 return mIsAdvancedBlendEquationSupported;
264 } // namespace Adaptor
266 } // namespace Internal