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 } // 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 mMaxTextureSize = mGraphics->GetMaxTextureSize();
123 mMaxTextureSizeCached = true;
125 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
126 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
129 stream << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
133 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
138 return mMaxTextureSize;
141 uint32_t ConfigurationManager::GetShadingLanguageVersion()
143 if(!mShaderLanguageVersionCached)
145 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
147 if(!mShaderLanguageVersionCached)
149 if(!mGraphics->IsInitialized())
151 // Wait until Graphics Subsystem is initialised, but this will happen once.
152 // This method blocks until the render thread has initialised the graphics.
153 mThreadController->WaitForGraphicsInitialization();
156 // Query from graphics and save the cache
157 mShaderLanguageVersion = mGraphics->GetShaderLanguageVersion();
158 mShaderLanguageVersionCached = true;
160 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
161 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
164 stream << DALI_GLSL_VERSION << " " << mShaderLanguageVersion << std::endl;
168 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
173 return mShaderLanguageVersion;
176 bool ConfigurationManager::IsMultipleWindowSupported()
178 if(!mIsMultipleWindowSupportedCached)
180 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
182 if(!mIsMultipleWindowSupportedCached)
184 if(!mGraphics->IsInitialized())
186 // Wait until Graphics Subsystem is initialised, but this will happen once.
187 // This method blocks until the render thread has initialised the graphics.
188 mThreadController->WaitForGraphicsInitialization();
191 // Query from Graphics Subsystem and save the cache
192 mIsMultipleWindowSupported = mGraphics->IsResourceContextSupported();
193 mIsMultipleWindowSupportedCached = true;
195 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
196 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
199 stream << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
203 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
208 return mIsMultipleWindowSupported;
211 bool ConfigurationManager::IsAdvancedBlendEquationSupported()
213 if(!mIsAdvancedBlendEquationSupportedCached)
215 RetrieveKeysFromConfigFile(mSystemCacheFilePath);
217 if(!mIsAdvancedBlendEquationSupportedCached)
219 if(!mGraphics->IsInitialized())
221 // Wait until graphics subsystem is initialised, but this will happen once per factory reset.
222 // This method blocks until the render thread has initialised the graphics.
223 mThreadController->WaitForGraphicsInitialization();
226 // Query from Graphics Subsystem and save the cache
227 mIsAdvancedBlendEquationSupported = mGraphics->IsAdvancedBlendEquationSupported();
228 mIsAdvancedBlendEquationSupportedCached = true;
230 Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);
231 std::fstream& stream = dynamic_cast<std::fstream&>(configFile.GetStream());
234 stream << DALI_BLEND_EQUATION_ADVANCED_SUPPORT << " " << mIsAdvancedBlendEquationSupported << std::endl;
238 DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str());
243 return mIsAdvancedBlendEquationSupported;
246 } // namespace Adaptor
248 } // namespace Internal