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";
47 bool RetrieveKeyFromConfigFile( std::iostream& stream, const std::string& key, std::string& value )
49 bool keyFound = false;
52 while( std::getline( stream, line ) )
54 line.erase( line.find_last_not_of( " \t\r\n" ) + 1 );
55 line.erase( 0, line.find_first_not_of( " \t\r\n" ) );
56 if( '#' == *( line.cbegin() ) || line == "" )
61 std::istringstream stream( line );
63 std::getline(stream, name, ' ');
66 std::getline(stream, value);
76 } // unnamed namespace
78 ConfigurationManager::ConfigurationManager( std::string systemCachePath, EglGraphics* eglGraphics, ThreadController* threadController )
79 : mSystemCacheFilePath( systemCachePath + SYSTEM_CACHE_FILE ),
80 mEglGraphics( eglGraphics ),
81 mThreadController( threadController ),
82 mMaxTextureSize( 0u ),
83 mIsMultipleWindowSupported( true ),
84 mMaxTextureSizeCached( false ) ,
85 mIsMultipleWindowSupportedCached( false )
89 ConfigurationManager::~ConfigurationManager()
93 void ConfigurationManager::RetrieveKeysFromConfigFile( const std::string& configFilePath )
95 Dali::FileStream configFile( configFilePath, Dali::FileStream::READ | Dali::FileStream::TEXT );
96 std::iostream& stream = configFile.GetStream();
97 if( stream.rdbuf()->in_avail() )
100 if( !mMaxTextureSizeCached &&
101 RetrieveKeyFromConfigFile( stream, DALI_ENV_MAX_TEXTURE_SIZE, value ) )
103 mMaxTextureSize = std::atoi( value.c_str() );
104 mMaxTextureSizeCached = true;
107 if( !mIsMultipleWindowSupportedCached &&
108 RetrieveKeyFromConfigFile( stream, DALI_ENV_MULTIPLE_WINDOW_SUPPORT, value ) )
110 mIsMultipleWindowSupported = std::atoi( value.c_str() );
111 mIsMultipleWindowSupportedCached = true;
116 unsigned int ConfigurationManager::GetMaxTextureSize()
118 if( !mMaxTextureSizeCached )
120 RetrieveKeysFromConfigFile( mSystemCacheFilePath );
122 if( !mMaxTextureSizeCached )
124 GlImplementation& mGLES = mEglGraphics->GetGlesInterface();
125 mMaxTextureSize = mGLES.GetMaxTextureSize();
126 mMaxTextureSizeCached = true;
128 Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
129 std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
130 if( stream.is_open() )
132 stream << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
136 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
141 return mMaxTextureSize;
144 bool ConfigurationManager::IsMultipleWindowSupported()
146 if ( !mIsMultipleWindowSupportedCached )
148 RetrieveKeysFromConfigFile( mSystemCacheFilePath );
150 if ( !mIsMultipleWindowSupportedCached )
152 EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
153 if ( !eglImpl.IsGlesInitialized() )
155 // Wait until GLES is initialised, but this will happen once.
156 // This method blocks until the render thread has initialised the graphics.
157 mThreadController->WaitForGraphicsInitialization();
160 // Query from GLES and save the cache
161 mIsMultipleWindowSupported = eglImpl.IsSurfacelessContextSupported();
162 mIsMultipleWindowSupportedCached = true;
164 Dali::FileStream configFile( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT );
165 std::fstream& stream = dynamic_cast<std::fstream&>( configFile.GetStream() );
166 if ( stream.is_open() )
168 stream << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
172 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
177 return mIsMultipleWindowSupported;