2 * Copyright (c) 2017 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 "environment-options.h"
23 #include <dali/integration-api/render-controller.h>
24 #include <dali/public-api/math/math-utils.h>
27 #include <base/environment-variables.h>
40 const unsigned int DEFAULT_STATISTICS_LOG_FREQUENCY = 2;
41 const int DEFAULT_MULTI_SAMPLING_LEVEL = -1;
43 unsigned int GetIntegerEnvironmentVariable( const char* variable, unsigned int defaultValue )
45 const char* variableParameter = std::getenv(variable);
47 // if the parameter exists convert it to an integer, else return the default value
48 unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
52 bool GetIntegerEnvironmentVariable( const char* variable, int& intValue )
54 const char* variableParameter = std::getenv(variable);
56 if( !variableParameter )
60 // if the parameter exists convert it to an integer, else return the default value
61 intValue = std::atoi(variableParameter);
65 bool GetFloatEnvironmentVariable( const char* variable, float& floatValue )
67 const char* variableParameter = std::getenv(variable);
69 if( !variableParameter )
73 // if the parameter exists convert it to an integer, else return the default value
74 floatValue = std::atof(variableParameter);
78 const char * GetCharEnvironmentVariable( const char * variable )
80 return std::getenv( variable );
83 } // unnamed namespace
85 EnvironmentOptions::EnvironmentOptions()
90 mUpdateStatusFrequency(0),
91 mObjectProfilerInterval( 0 ),
92 mPerformanceStatsLevel(0),
93 mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY ),
94 mPerformanceTimeStampOutput(0),
95 mPanGestureLoggingLevel(0),
96 mPanGesturePredictionMode(-1),
97 mPanGesturePredictionAmount(-1), ///< only sets value in pan gesture if greater than 0
98 mPanGestureMaxPredictionAmount(-1),
99 mPanGestureMinPredictionAmount(-1),
100 mPanGesturePredictionAmountAdjustment(-1),
101 mPanGestureSmoothingMode(-1),
102 mPanGestureSmoothingAmount(-1.0f),
103 mPanMinimumDistance(-1),
104 mPanMinimumEvents(-1),
108 mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
109 mRenderRefreshRate( 1u ),
110 mGlesCallAccumulate( false ),
111 mMultiSamplingLevel( DEFAULT_MULTI_SAMPLING_LEVEL ),
112 mMaxTextureSize( 0 ),
113 mIndicatorVisibleMode( -1 ),
114 mRenderToFboInterval( 0u ),
117 ParseEnvironmentOptions();
120 EnvironmentOptions::~EnvironmentOptions()
124 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
126 mLogFunction = logFunction;
129 void EnvironmentOptions::InstallLogFunction() const
131 Dali::Integration::Log::InstallLogFunction( mLogFunction );
134 void EnvironmentOptions::UnInstallLogFunction() const
136 Dali::Integration::Log::UninstallLogFunction();
139 unsigned int EnvironmentOptions::GetNetworkControlMode() const
141 return mNetworkControl;
143 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
145 return mFpsFrequency;
148 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
150 return mUpdateStatusFrequency;
153 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
155 return mObjectProfilerInterval;
158 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
160 return mPerformanceStatsLevel;
162 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
164 return mPerformanceStatsFrequency;
166 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
168 return mPerformanceTimeStampOutput;
171 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
173 return mPanGestureLoggingLevel;
176 int EnvironmentOptions::GetPanGesturePredictionMode() const
178 return mPanGesturePredictionMode;
181 int EnvironmentOptions::GetPanGesturePredictionAmount() const
183 return mPanGesturePredictionAmount;
186 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
188 return mPanGestureMaxPredictionAmount;
191 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
193 return mPanGestureMinPredictionAmount;
196 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
198 return mPanGesturePredictionAmountAdjustment;
201 int EnvironmentOptions::GetPanGestureSmoothingMode() const
203 return mPanGestureSmoothingMode;
206 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
208 return mPanGestureSmoothingAmount;
211 int EnvironmentOptions::GetMinimumPanDistance() const
213 return mPanMinimumDistance;
216 int EnvironmentOptions::GetMinimumPanEvents() const
218 return mPanMinimumEvents;
221 unsigned int EnvironmentOptions::GetWindowWidth() const
226 unsigned int EnvironmentOptions::GetWindowHeight() const
228 return mWindowHeight;
231 int EnvironmentOptions::GetGlesCallTime() const
233 return mGlesCallTime;
236 bool EnvironmentOptions::GetGlesCallAccumulate() const
238 return mGlesCallAccumulate;
241 const std::string& EnvironmentOptions::GetWindowName() const
246 const std::string& EnvironmentOptions::GetWindowClassName() const
248 return mWindowClassName;
251 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
253 return mThreadingMode;
256 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
258 return mRenderRefreshRate;
261 int EnvironmentOptions::GetMultiSamplingLevel() const
263 return mMultiSamplingLevel;
266 unsigned int EnvironmentOptions::GetMaxTextureSize() const
268 return mMaxTextureSize;
271 int EnvironmentOptions::GetIndicatorVisibleMode() const
273 return mIndicatorVisibleMode;
276 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
278 return mRenderToFboInterval;
281 bool EnvironmentOptions::PerformanceServerRequired() const
283 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
284 ( GetPerformanceTimeStampOutput() > 0 ) ||
285 ( GetNetworkControlMode() > 0) );
288 void EnvironmentOptions::ParseEnvironmentOptions()
290 // get logging options
291 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
292 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
293 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
294 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
295 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
296 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
297 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
298 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
301 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
303 mPanGesturePredictionMode = predictionMode;
305 int predictionAmount(-1);
306 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
308 if( predictionAmount < 0 )
310 // do not support times in the past
311 predictionAmount = 0;
313 mPanGesturePredictionAmount = predictionAmount;
315 int minPredictionAmount(-1);
316 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
318 if( minPredictionAmount < 0 )
320 // do not support times in the past
321 minPredictionAmount = 0;
323 mPanGestureMinPredictionAmount = minPredictionAmount;
325 int maxPredictionAmount(-1);
326 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
328 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
330 // maximum amount should not be smaller than minimum amount
331 maxPredictionAmount = minPredictionAmount;
333 mPanGestureMaxPredictionAmount = maxPredictionAmount;
335 int predictionAmountAdjustment(-1);
336 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
338 if( predictionAmountAdjustment < 0 )
340 // negative amount doesn't make sense
341 predictionAmountAdjustment = 0;
343 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
346 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
348 mPanGestureSmoothingMode = smoothingMode;
350 float smoothingAmount = 1.0f;
351 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
353 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
354 mPanGestureSmoothingAmount = smoothingAmount;
357 int minimumDistance(-1);
358 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
360 mPanMinimumDistance = minimumDistance;
363 int minimumEvents(-1);
364 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
366 mPanMinimumEvents = minimumEvents;
370 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
372 mGlesCallTime = glesCallTime;
375 int glesCallAccumulate( 0 );
376 if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
378 mGlesCallAccumulate = glesCallAccumulate != 0;
381 int windowWidth(0), windowHeight(0);
382 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
384 mWindowWidth = windowWidth;
385 mWindowHeight = windowHeight;
388 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
391 mWindowName = windowName;
394 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
395 if ( windowClassName )
397 mWindowClassName = windowClassName;
400 int threadingMode(0);
401 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
403 switch( threadingMode )
405 case ThreadingMode::COMBINED_UPDATE_RENDER:
407 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
413 int renderRefreshRate(0);
414 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
416 // Only change it if it's valid
417 if( renderRefreshRate > 1 )
419 mRenderRefreshRate = renderRefreshRate;
423 int multiSamplingLevel( 0 );
424 if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
426 mMultiSamplingLevel = multiSamplingLevel;
429 int maxTextureSize( 0 );
430 if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
432 if( maxTextureSize > 0 )
434 mMaxTextureSize = maxTextureSize;
438 int indicatorVisibleMode( -1 );
439 if( GetIntegerEnvironmentVariable( DALI_ENV_INDICATOR_VISIBLE_MODE, indicatorVisibleMode ) )
441 if( indicatorVisibleMode > -1 )
443 mIndicatorVisibleMode = indicatorVisibleMode;
447 mRenderToFboInterval = GetIntegerEnvironmentVariable( DALI_RENDER_TO_FBO, 0u );