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 <dali/internal/system/common/environment-options.h>
23 #include <dali/integration-api/render-controller.h>
24 #include <dali/public-api/math/math-utils.h>
27 #include <dali/internal/system/common/environment-variables.h>
40 const unsigned int DEFAULT_STATISTICS_LOG_FREQUENCY = 2;
41 const int DEFAULT_MULTI_SAMPLING_LEVEL = -1;
42 const bool DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING = true;
43 const bool DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING = true;
45 unsigned int GetIntegerEnvironmentVariable( const char* variable, unsigned int defaultValue )
47 const char* variableParameter = std::getenv(variable);
49 // if the parameter exists convert it to an integer, else return the default value
50 unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
54 bool GetIntegerEnvironmentVariable( const char* variable, int& intValue )
56 const char* variableParameter = std::getenv(variable);
58 if( !variableParameter )
62 // if the parameter exists convert it to an integer, else return the default value
63 intValue = std::atoi(variableParameter);
67 bool GetFloatEnvironmentVariable( const char* variable, float& floatValue )
69 const char* variableParameter = std::getenv(variable);
71 if( !variableParameter )
75 // if the parameter exists convert it to an integer, else return the default value
76 floatValue = std::atof(variableParameter);
80 const char * GetCharEnvironmentVariable( const char * variable )
82 return std::getenv( variable );
85 } // unnamed namespace
87 EnvironmentOptions::EnvironmentOptions()
88 : mLogFunction( NULL ),
93 mUpdateStatusFrequency( 0 ),
94 mObjectProfilerInterval( 0 ),
95 mPerformanceStatsLevel( 0 ),
96 mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY ),
97 mPerformanceTimeStampOutput( 0 ),
98 mPanGestureLoggingLevel( 0 ),
101 mRenderRefreshRate( 1u ),
102 mMaxTextureSize( 0 ),
103 mRenderToFboInterval( 0u ),
104 mPanGesturePredictionMode( -1 ),
105 mPanGesturePredictionAmount( -1 ), ///< only sets value in pan gesture if greater than 0
106 mPanGestureMaxPredictionAmount( -1 ),
107 mPanGestureMinPredictionAmount( -1 ),
108 mPanGesturePredictionAmountAdjustment( -1 ),
109 mPanGestureSmoothingMode( -1 ),
110 mPanGestureSmoothingAmount( -1.0f ),
111 mPanGestureUseActualTimes( -1 ),
112 mPanGestureInterpolationTimeRange( -1 ),
113 mPanGestureScalarOnlyPredictionEnabled( -1 ),
114 mPanGestureTwoPointPredictionEnabled( -1 ),
115 mPanGestureTwoPointInterpolatePastTime( -1 ),
116 mPanGestureTwoPointVelocityBias( -1.0f ),
117 mPanGestureTwoPointAccelerationBias( -1.0f ),
118 mPanGestureMultitapSmoothingRange( -1 ),
119 mPanMinimumDistance( -1 ),
120 mPanMinimumEvents( -1 ),
122 mMultiSamplingLevel( DEFAULT_MULTI_SAMPLING_LEVEL ),
123 mIndicatorVisibleMode( -1 ),
124 mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
125 mGlesCallAccumulate( false ),
126 mDepthBufferRequired( DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING ),
127 mStencilBufferRequired( DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING )
129 ParseEnvironmentOptions();
132 EnvironmentOptions::~EnvironmentOptions()
136 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
138 mLogFunction = logFunction;
141 void EnvironmentOptions::InstallLogFunction() const
143 Dali::Integration::Log::InstallLogFunction( mLogFunction );
146 void EnvironmentOptions::UnInstallLogFunction() const
148 Dali::Integration::Log::UninstallLogFunction();
151 unsigned int EnvironmentOptions::GetNetworkControlMode() const
153 return mNetworkControl;
155 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
157 return mFpsFrequency;
160 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
162 return mUpdateStatusFrequency;
165 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
167 return mObjectProfilerInterval;
170 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
172 return mPerformanceStatsLevel;
174 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
176 return mPerformanceStatsFrequency;
178 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
180 return mPerformanceTimeStampOutput;
183 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
185 return mPanGestureLoggingLevel;
188 int EnvironmentOptions::GetPanGesturePredictionMode() const
190 return mPanGesturePredictionMode;
193 int EnvironmentOptions::GetPanGesturePredictionAmount() const
195 return mPanGesturePredictionAmount;
198 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
200 return mPanGestureMaxPredictionAmount;
203 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
205 return mPanGestureMinPredictionAmount;
208 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
210 return mPanGesturePredictionAmountAdjustment;
213 int EnvironmentOptions::GetPanGestureSmoothingMode() const
215 return mPanGestureSmoothingMode;
218 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
220 return mPanGestureSmoothingAmount;
223 int EnvironmentOptions::GetPanGestureUseActualTimes() const
225 return mPanGestureUseActualTimes;
228 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
230 return mPanGestureInterpolationTimeRange;
233 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
235 return mPanGestureScalarOnlyPredictionEnabled;
238 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
240 return mPanGestureTwoPointPredictionEnabled;
243 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
245 return mPanGestureTwoPointInterpolatePastTime;
248 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
250 return mPanGestureTwoPointVelocityBias;
253 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
255 return mPanGestureTwoPointAccelerationBias;
258 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
260 return mPanGestureMultitapSmoothingRange;
263 int EnvironmentOptions::GetMinimumPanDistance() const
265 return mPanMinimumDistance;
268 int EnvironmentOptions::GetMinimumPanEvents() const
270 return mPanMinimumEvents;
273 unsigned int EnvironmentOptions::GetWindowWidth() const
278 unsigned int EnvironmentOptions::GetWindowHeight() const
280 return mWindowHeight;
283 int EnvironmentOptions::GetGlesCallTime() const
285 return mGlesCallTime;
288 bool EnvironmentOptions::GetGlesCallAccumulate() const
290 return mGlesCallAccumulate;
293 const std::string& EnvironmentOptions::GetWindowName() const
298 const std::string& EnvironmentOptions::GetWindowClassName() const
300 return mWindowClassName;
303 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
305 return mThreadingMode;
308 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
310 return mRenderRefreshRate;
313 int EnvironmentOptions::GetMultiSamplingLevel() const
315 return mMultiSamplingLevel;
318 unsigned int EnvironmentOptions::GetMaxTextureSize() const
320 return mMaxTextureSize;
323 int EnvironmentOptions::GetIndicatorVisibleMode() const
325 return mIndicatorVisibleMode;
328 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
330 return mRenderToFboInterval;
333 bool EnvironmentOptions::PerformanceServerRequired() const
335 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
336 ( GetPerformanceTimeStampOutput() > 0 ) ||
337 ( GetNetworkControlMode() > 0) );
340 bool EnvironmentOptions::DepthBufferRequired() const
342 return mDepthBufferRequired;
345 bool EnvironmentOptions::StencilBufferRequired() const
347 return mStencilBufferRequired;
350 void EnvironmentOptions::ParseEnvironmentOptions()
352 // get logging options
353 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
354 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
355 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
356 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
357 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
358 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
359 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
360 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
363 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
365 mPanGesturePredictionMode = predictionMode;
367 int predictionAmount(-1);
368 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
370 if( predictionAmount < 0 )
372 // do not support times in the past
373 predictionAmount = 0;
375 mPanGesturePredictionAmount = predictionAmount;
377 int minPredictionAmount(-1);
378 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
380 if( minPredictionAmount < 0 )
382 // do not support times in the past
383 minPredictionAmount = 0;
385 mPanGestureMinPredictionAmount = minPredictionAmount;
387 int maxPredictionAmount(-1);
388 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
390 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
392 // maximum amount should not be smaller than minimum amount
393 maxPredictionAmount = minPredictionAmount;
395 mPanGestureMaxPredictionAmount = maxPredictionAmount;
397 int predictionAmountAdjustment(-1);
398 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
400 if( predictionAmountAdjustment < 0 )
402 // negative amount doesn't make sense
403 predictionAmountAdjustment = 0;
405 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
408 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
410 mPanGestureSmoothingMode = smoothingMode;
412 float smoothingAmount = 1.0f;
413 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
415 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
416 mPanGestureSmoothingAmount = smoothingAmount;
419 int useActualTimes( -1 );
420 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_USE_ACTUAL_TIMES, useActualTimes ) )
422 mPanGestureUseActualTimes = useActualTimes == 0 ? 0 : 1;
425 int interpolationTimeRange( -1 );
426 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, interpolationTimeRange ) )
428 if( interpolationTimeRange < 0 )
430 interpolationTimeRange = 0;
432 mPanGestureInterpolationTimeRange = interpolationTimeRange;
435 int scalarOnlyPredictionEnabled( -1 );
436 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, scalarOnlyPredictionEnabled ) )
438 mPanGestureScalarOnlyPredictionEnabled = scalarOnlyPredictionEnabled == 0 ? 0 : 1;
441 int twoPointPredictionEnabled( -1 );
442 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, twoPointPredictionEnabled ) )
444 mPanGestureTwoPointPredictionEnabled = twoPointPredictionEnabled == 0 ? 0 : 1;
447 int twoPointPastInterpolateTime( -1 );
448 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, twoPointPastInterpolateTime ) )
450 if( twoPointPastInterpolateTime < 0 )
452 twoPointPastInterpolateTime = 0;
454 mPanGestureTwoPointInterpolatePastTime = twoPointPastInterpolateTime;
457 float twoPointVelocityBias = -1.0f;
458 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, twoPointVelocityBias ) )
460 twoPointVelocityBias = Clamp( twoPointVelocityBias, 0.0f, 1.0f );
461 mPanGestureTwoPointVelocityBias = twoPointVelocityBias;
464 float twoPointAccelerationBias = -1.0f;
465 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, twoPointAccelerationBias ) )
467 twoPointAccelerationBias = Clamp( twoPointAccelerationBias, 0.0f, 1.0f );
468 mPanGestureTwoPointAccelerationBias = twoPointAccelerationBias;
471 int multitapSmoothingRange( -1 );
472 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, multitapSmoothingRange ) )
474 if( multitapSmoothingRange < 0 )
476 multitapSmoothingRange = 0;
478 mPanGestureMultitapSmoothingRange = multitapSmoothingRange;
481 int minimumDistance(-1);
482 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
484 mPanMinimumDistance = minimumDistance;
487 int minimumEvents(-1);
488 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
490 mPanMinimumEvents = minimumEvents;
494 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
496 mGlesCallTime = glesCallTime;
499 int glesCallAccumulate( 0 );
500 if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
502 mGlesCallAccumulate = glesCallAccumulate != 0;
505 int windowWidth(0), windowHeight(0);
506 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
508 mWindowWidth = windowWidth;
509 mWindowHeight = windowHeight;
512 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
515 mWindowName = windowName;
518 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
519 if ( windowClassName )
521 mWindowClassName = windowClassName;
524 int threadingMode(0);
525 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
527 switch( threadingMode )
529 case ThreadingMode::COMBINED_UPDATE_RENDER:
531 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
537 int renderRefreshRate(0);
538 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
540 // Only change it if it's valid
541 if( renderRefreshRate > 1 )
543 mRenderRefreshRate = renderRefreshRate;
547 int multiSamplingLevel( 0 );
548 if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
550 mMultiSamplingLevel = multiSamplingLevel;
553 int maxTextureSize( 0 );
554 if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
556 if( maxTextureSize > 0 )
558 mMaxTextureSize = maxTextureSize;
562 int indicatorVisibleMode( -1 );
563 if( GetIntegerEnvironmentVariable( DALI_ENV_INDICATOR_VISIBLE_MODE, indicatorVisibleMode ) )
565 if( indicatorVisibleMode > -1 )
567 mIndicatorVisibleMode = indicatorVisibleMode;
571 mRenderToFboInterval = GetIntegerEnvironmentVariable( DALI_RENDER_TO_FBO, 0u );
574 int depthBufferRequired( -1 );
575 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_DEPTH_BUFFER, depthBufferRequired ) )
577 if( depthBufferRequired > 0 )
579 mDepthBufferRequired = false;
580 mStencilBufferRequired = false; // Disable stencil buffer as well
584 int stencilBufferRequired( -1 );
585 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_STENCIL_BUFFER, stencilBufferRequired ) )
587 if( stencilBufferRequired > 0 )
589 mStencilBufferRequired = false;