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 ),
85 mIsMultipleWindowSupported( true ),
86 mIsAdvancedBlendEquationSupported( true ),
87 mMaxTextureSizeCached( false ),
88 mIsMultipleWindowSupportedCached( false ),
89 mIsAdvancedBlendEquationSupportedCached( false ),
90 mGlslVersionCached( false )
94 ConfigurationManager::~ConfigurationManager()
98 void ConfigurationManager::RetrieveKeysFromConfigFile( const std::string& configFilePath )
100 Dali::FileStream configFile( configFilePath, Dali::FileStream::READ | Dali::FileStream::TEXT );
101 std::iostream& stream = configFile.GetStream();
102 if( stream.rdbuf()->in_avail() )
105 if( !mMaxTextureSizeCached &&
106 RetrieveKeyFromConfigFile( stream, DALI_ENV_MAX_TEXTURE_SIZE, value ) )
108 mMaxTextureSize = std::atoi( value.c_str() );
109 mMaxTextureSizeCached = true;
112 if( !mGlslVersionCached &&
113 RetrieveKeyFromConfigFile( stream, DALI_GLSL_VERSION, value ) )
115 mGlslVersion = std::atoi( value.c_str() );
116 mGlslVersionCached = true;
119 if( !mIsMultipleWindowSupportedCached &&
120 RetrieveKeyFromConfigFile( stream, DALI_ENV_MULTIPLE_WINDOW_SUPPORT, value ) )
122 mIsMultipleWindowSupported = std::atoi( value.c_str() );
123 mIsMultipleWindowSupportedCached = true;
126 if( !mIsAdvancedBlendEquationSupportedCached &&
127 RetrieveKeyFromConfigFile( stream, DALI_BLEND_EQUATION_ADVANCED_SUPPORT, value ) )
129 mIsAdvancedBlendEquationSupported = std::atoi( value.c_str() );
130 mIsAdvancedBlendEquationSupportedCached = true;
135 uint32_t ConfigurationManager::GetMaxTextureSize()
137 if( !mMaxTextureSizeCached )
139 RetrieveKeysFromConfigFile( mSystemCacheFilePath );
141 if( !mMaxTextureSizeCached )
143 GlImplementation& mGLES = mEglGraphics->GetGlesInterface();
144 mMaxTextureSize = mGLES.GetMaxTextureSize();
145 mMaxTextureSizeCached = true;
147 Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
148 std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
149 if( stream.is_open() )
151 stream << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
155 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
160 return mMaxTextureSize;
163 uint32_t ConfigurationManager::GetShadingLanguageVersion()
165 if ( !mGlslVersionCached )
167 RetrieveKeysFromConfigFile( mSystemCacheFilePath );
169 if ( !mGlslVersionCached )
171 EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
172 if ( !eglImpl.IsGlesInitialized() )
174 // Wait until GLES is initialised, but this will happen once.
175 // This method blocks until the render thread has initialised the graphics.
176 mThreadController->WaitForGraphicsInitialization();
179 // Query from GLES and save the cache
180 mGlslVersion = mEglGraphics->GetGlesInterface().GetShadingLanguageVersion();
181 DALI_LOG_ERROR("mGlslVersion : %d\n", mGlslVersion);
182 mGlslVersionCached = true;
184 Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
185 std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
186 if ( stream.is_open() )
188 stream << DALI_GLSL_VERSION << " " << mGlslVersion << std::endl;
192 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
200 bool ConfigurationManager::IsMultipleWindowSupported()
202 if ( !mIsMultipleWindowSupportedCached )
204 RetrieveKeysFromConfigFile( mSystemCacheFilePath );
206 if ( !mIsMultipleWindowSupportedCached )
208 EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
209 if ( !eglImpl.IsGlesInitialized() )
211 // Wait until GLES is initialised, but this will happen once.
212 // This method blocks until the render thread has initialised the graphics.
213 mThreadController->WaitForGraphicsInitialization();
216 // Query from GLES and save the cache
217 mIsMultipleWindowSupported = eglImpl.IsSurfacelessContextSupported();
218 mIsMultipleWindowSupportedCached = true;
220 Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
221 std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
222 if ( stream.is_open() )
224 stream << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
228 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
233 return mIsMultipleWindowSupported;
236 bool ConfigurationManager::IsAdvancedBlendEquationSupported()
238 if ( !mIsAdvancedBlendEquationSupportedCached )
240 RetrieveKeysFromConfigFile( mSystemCacheFilePath );
242 if ( !mIsAdvancedBlendEquationSupportedCached )
244 EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
245 if ( !eglImpl.IsGlesInitialized() )
247 // Wait until GLES is initialised, but this will happen once.
248 // This method blocks until the render thread has initialised the graphics.
249 mThreadController->WaitForGraphicsInitialization();
252 // Query from GLES and save the cache
253 mIsAdvancedBlendEquationSupported = mEglGraphics->GetGlesInterface().IsAdvancedBlendEquationSupported();
254 mIsAdvancedBlendEquationSupportedCached = true;
256 Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
257 std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
258 if ( stream.is_open() )
260 stream << DALI_BLEND_EQUATION_ADVANCED_SUPPORT << " " << mIsAdvancedBlendEquationSupported << std::endl;
264 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
269 return mIsAdvancedBlendEquationSupported;