2 * Copyright (c) 2020 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>
23 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/file-stream.h>
27 #include <dali/internal/graphics/gles/egl-graphics.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>
44 const std::string SYSTEM_CACHE_FILE = "gpu-environment.conf";
45 const std::string DALI_ENV_MULTIPLE_WINDOW_SUPPORT = "DALI_ENV_MULTIPLE_WINDOW_SUPPORT";
46 const std::string DALI_BLEND_EQUATION_ADVANCED_SUPPORT = "DALI_BLEND_EQUATION_ADVANCED_SUPPORT";
47 const std::string DALI_GLSL_VERSION = "DALI_GLSL_VERSION";
49 bool RetrieveKeyFromConfigFile( std::iostream& stream, const std::string& key, std::string& value )
51 bool keyFound = false;
54 while( std::getline( stream, line ) )
56 line.erase( line.find_last_not_of( " \t\r\n" ) + 1 );
57 line.erase( 0, line.find_first_not_of( " \t\r\n" ) );
58 if( '#' == *( line.cbegin() ) || line == "" )
63 std::istringstream stream( line );
65 std::getline(stream, name, ' ');
68 std::getline(stream, value);
78 } // unnamed namespace
80 ConfigurationManager::ConfigurationManager( std::string systemCachePath, EglGraphics* eglGraphics, ThreadController* threadController )
81 : mSystemCacheFilePath( systemCachePath + SYSTEM_CACHE_FILE ),
82 mEglGraphics( eglGraphics ),
83 mThreadController( threadController ),
84 mMaxTextureSize( 0u ),
86 mIsMultipleWindowSupported( true ),
87 mIsAdvancedBlendEquationSupported( true ),
88 mMaxTextureSizeCached( false ),
89 mIsMultipleWindowSupportedCached( false ),
90 mIsAdvancedBlendEquationSupportedCached( false ),
91 mGlslVersionCached( false )
95 ConfigurationManager::~ConfigurationManager()
99 void ConfigurationManager::RetrieveKeysFromConfigFile( const std::string& configFilePath )
101 Dali::FileStream configFile( configFilePath, Dali::FileStream::READ | Dali::FileStream::TEXT );
102 std::iostream& stream = configFile.GetStream();
103 if( stream.rdbuf()->in_avail() )
106 if( !mMaxTextureSizeCached &&
107 RetrieveKeyFromConfigFile( stream, DALI_ENV_MAX_TEXTURE_SIZE, value ) )
109 mMaxTextureSize = std::atoi( value.c_str() );
110 mMaxTextureSizeCached = true;
113 if( !mGlslVersionCached &&
114 RetrieveKeyFromConfigFile( stream, DALI_GLSL_VERSION, value ) )
116 mGlslVersion = std::atoi( value.c_str() );
117 mGlslVersionCached = true;
120 if( !mIsMultipleWindowSupportedCached &&
121 RetrieveKeyFromConfigFile( stream, DALI_ENV_MULTIPLE_WINDOW_SUPPORT, value ) )
123 mIsMultipleWindowSupported = std::atoi( value.c_str() );
124 mIsMultipleWindowSupportedCached = true;
127 if( !mIsAdvancedBlendEquationSupportedCached &&
128 RetrieveKeyFromConfigFile( stream, DALI_BLEND_EQUATION_ADVANCED_SUPPORT, value ) )
130 mIsAdvancedBlendEquationSupported = std::atoi( value.c_str() );
131 mIsAdvancedBlendEquationSupportedCached = true;
136 uint32_t ConfigurationManager::GetMaxTextureSize()
138 if( !mMaxTextureSizeCached )
140 RetrieveKeysFromConfigFile( mSystemCacheFilePath );
142 if( !mMaxTextureSizeCached )
144 GlImplementation& mGLES = mEglGraphics->GetGlesInterface();
145 mMaxTextureSize = mGLES.GetMaxTextureSize();
146 mMaxTextureSizeCached = true;
148 Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
149 std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
150 if( stream.is_open() )
152 stream << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
156 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
161 return mMaxTextureSize;
164 uint32_t ConfigurationManager::GetShadingLanguageVersion()
166 if ( !mGlslVersionCached )
168 RetrieveKeysFromConfigFile( mSystemCacheFilePath );
170 if ( !mGlslVersionCached )
172 EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
173 if ( !eglImpl.IsGlesInitialized() )
175 // Wait until GLES is initialised, but this will happen once.
176 // This method blocks until the render thread has initialised the graphics.
177 mThreadController->WaitForGraphicsInitialization();
180 // Query from GLES and save the cache
181 mGlslVersion = mEglGraphics->GetGlesInterface().GetShadingLanguageVersion();
182 DALI_LOG_ERROR("mGlslVersion : %d\n", mGlslVersion);
183 mGlslVersionCached = true;
185 Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
186 std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
187 if ( stream.is_open() )
189 stream << DALI_GLSL_VERSION << " " << mGlslVersion << std::endl;
193 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
201 bool ConfigurationManager::IsMultipleWindowSupported()
203 if ( !mIsMultipleWindowSupportedCached )
205 RetrieveKeysFromConfigFile( mSystemCacheFilePath );
207 if ( !mIsMultipleWindowSupportedCached )
209 EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
210 if ( !eglImpl.IsGlesInitialized() )
212 // Wait until GLES is initialised, but this will happen once.
213 // This method blocks until the render thread has initialised the graphics.
214 mThreadController->WaitForGraphicsInitialization();
217 // Query from GLES and save the cache
218 mIsMultipleWindowSupported = eglImpl.IsSurfacelessContextSupported();
219 mIsMultipleWindowSupportedCached = true;
221 Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
222 std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
223 if ( stream.is_open() )
225 stream << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
229 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
234 return mIsMultipleWindowSupported;
237 bool ConfigurationManager::IsAdvancedBlendEquationSupported()
239 if ( !mIsAdvancedBlendEquationSupportedCached )
241 RetrieveKeysFromConfigFile( mSystemCacheFilePath );
243 if ( !mIsAdvancedBlendEquationSupportedCached )
245 EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
246 if ( !eglImpl.IsGlesInitialized() )
248 // Wait until GLES is initialised, but this will happen once.
249 // This method blocks until the render thread has initialised the graphics.
250 mThreadController->WaitForGraphicsInitialization();
253 // Query from GLES and save the cache
254 mIsAdvancedBlendEquationSupported = mEglGraphics->GetGlesInterface().IsAdvancedBlendEquationSupported();
255 mIsAdvancedBlendEquationSupportedCached = true;
257 Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
258 std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
259 if ( stream.is_open() )
261 stream << DALI_BLEND_EQUATION_ADVANCED_SUPPORT << " " << mIsAdvancedBlendEquationSupported << std::endl;
265 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
270 return mIsAdvancedBlendEquationSupported;