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 RetrieveKeyFromFile( std::fstream& stream, 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 mFileStream( new Dali::FileStream( mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT ) ),
81 mEglGraphics( eglGraphics ),
82 mThreadController( threadController ),
83 mMaxTextureSize( 0u ),
84 mIsMultipleWindowSupported( true ),
85 mMaxTextureSizeCached( false ) ,
86 mIsMultipleWindowSupportedCached( false )
90 ConfigurationManager::~ConfigurationManager()
94 unsigned int ConfigurationManager::GetMaxTextureSize()
96 if ( !mMaxTextureSizeCached )
98 std::fstream& configFile = dynamic_cast<std::fstream&>( mFileStream->GetStream() );
99 if( configFile.is_open() )
101 std::string environmentVariableValue;
102 if( RetrieveKeyFromFile( configFile, DALI_ENV_MAX_TEXTURE_SIZE, environmentVariableValue ) )
104 mMaxTextureSize = std::atoi( environmentVariableValue.c_str() );
108 GlImplementation& mGLES = mEglGraphics->GetGlesInterface();
109 mMaxTextureSize = mGLES.GetMaxTextureSize();
112 configFile << DALI_ENV_MAX_TEXTURE_SIZE << " " << mMaxTextureSize << std::endl;
115 mMaxTextureSizeCached = true;
117 if ( mIsMultipleWindowSupportedCached )
124 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
128 return mMaxTextureSize;
131 bool ConfigurationManager::IsMultipleWindowSupported()
133 if ( !mIsMultipleWindowSupportedCached )
135 std::fstream& configFile = dynamic_cast<std::fstream&>( mFileStream->GetStream() );
136 if( configFile.is_open() )
138 std::string environmentVariableValue;
139 if( RetrieveKeyFromFile( configFile, DALI_ENV_MULTIPLE_WINDOW_SUPPORT, environmentVariableValue ) )
141 mIsMultipleWindowSupported = std::atoi( environmentVariableValue.c_str() );
145 EglImplementation& eglImpl = mEglGraphics->GetEglImplementation();
146 if ( !eglImpl.IsGlesInitialized() )
148 // Wait until GLES is initialised, but this will happen once.
149 // This method blocks until the render thread has initialised the graphics.
150 mThreadController->WaitForGraphicsInitialization();
153 // Query from GLES and save the cache
154 mIsMultipleWindowSupported = eglImpl.IsSurfacelessContextSupported();
157 configFile << DALI_ENV_MULTIPLE_WINDOW_SUPPORT << " " << mIsMultipleWindowSupported << std::endl;
160 mIsMultipleWindowSupportedCached = true;
162 if ( mMaxTextureSizeCached )
169 DALI_LOG_ERROR( "Fail to open file : %s\n", mSystemCacheFilePath.c_str() );
173 return mIsMultipleWindowSupported;