2 * Copyright (c) 2018 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/trace/common/trace-factory.h>
28 #include <dali/internal/system/common/environment-variables.h>
41 const unsigned int DEFAULT_STATISTICS_LOG_FREQUENCY = 2;
42 const int DEFAULT_MULTI_SAMPLING_LEVEL = -1;
43 const bool DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING = true;
44 const bool DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING = true;
46 unsigned int GetIntegerEnvironmentVariable( const char* variable, unsigned int defaultValue )
48 const char* variableParameter = std::getenv(variable);
50 // if the parameter exists convert it to an integer, else return the default value
51 unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
55 bool GetIntegerEnvironmentVariable( const char* variable, int& intValue )
57 const char* variableParameter = std::getenv(variable);
59 if( !variableParameter )
63 // if the parameter exists convert it to an integer, else return the default value
64 intValue = std::atoi(variableParameter);
68 bool GetFloatEnvironmentVariable( const char* variable, float& floatValue )
70 const char* variableParameter = std::getenv(variable);
72 if( !variableParameter )
76 // if the parameter exists convert it to an integer, else return the default value
77 floatValue = std::atof(variableParameter);
81 const char * GetCharEnvironmentVariable( const char * variable )
83 return std::getenv( variable );
86 } // unnamed namespace
88 EnvironmentOptions::EnvironmentOptions()
89 : mLogFunction( NULL ),
94 mUpdateStatusFrequency( 0 ),
95 mObjectProfilerInterval( 0 ),
96 mPerformanceStatsLevel( 0 ),
97 mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY ),
98 mPerformanceTimeStampOutput( 0 ),
99 mPanGestureLoggingLevel( 0 ),
102 mRenderRefreshRate( 1u ),
103 mMaxTextureSize( 0 ),
104 mRenderToFboInterval( 0u ),
105 mPanGesturePredictionMode( -1 ),
106 mPanGesturePredictionAmount( -1 ), ///< only sets value in pan gesture if greater than 0
107 mPanGestureMaxPredictionAmount( -1 ),
108 mPanGestureMinPredictionAmount( -1 ),
109 mPanGesturePredictionAmountAdjustment( -1 ),
110 mPanGestureSmoothingMode( -1 ),
111 mPanGestureSmoothingAmount( -1.0f ),
112 mPanGestureUseActualTimes( -1 ),
113 mPanGestureInterpolationTimeRange( -1 ),
114 mPanGestureScalarOnlyPredictionEnabled( -1 ),
115 mPanGestureTwoPointPredictionEnabled( -1 ),
116 mPanGestureTwoPointInterpolatePastTime( -1 ),
117 mPanGestureTwoPointVelocityBias( -1.0f ),
118 mPanGestureTwoPointAccelerationBias( -1.0f ),
119 mPanGestureMultitapSmoothingRange( -1 ),
120 mPanMinimumDistance( -1 ),
121 mPanMinimumEvents( -1 ),
123 mMultiSamplingLevel( DEFAULT_MULTI_SAMPLING_LEVEL ),
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::CreateTraceManager( PerformanceInterface* performanceInterface )
138 mTraceManager = TraceManagerFactory::CreateTraceFactory( performanceInterface );
141 void EnvironmentOptions::InstallTraceFunction() const
145 mTraceManager->Initialise();
149 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
151 mLogFunction = logFunction;
154 void EnvironmentOptions::InstallLogFunction() const
156 Dali::Integration::Log::InstallLogFunction( mLogFunction );
159 void EnvironmentOptions::UnInstallLogFunction() const
161 Dali::Integration::Log::UninstallLogFunction();
164 unsigned int EnvironmentOptions::GetNetworkControlMode() const
166 return mNetworkControl;
168 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
170 return mFpsFrequency;
173 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
175 return mUpdateStatusFrequency;
178 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
180 return mObjectProfilerInterval;
183 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
185 return mPerformanceStatsLevel;
187 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
189 return mPerformanceStatsFrequency;
191 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
193 return mPerformanceTimeStampOutput;
196 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
198 return mPanGestureLoggingLevel;
201 int EnvironmentOptions::GetPanGesturePredictionMode() const
203 return mPanGesturePredictionMode;
206 int EnvironmentOptions::GetPanGesturePredictionAmount() const
208 return mPanGesturePredictionAmount;
211 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
213 return mPanGestureMaxPredictionAmount;
216 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
218 return mPanGestureMinPredictionAmount;
221 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
223 return mPanGesturePredictionAmountAdjustment;
226 int EnvironmentOptions::GetPanGestureSmoothingMode() const
228 return mPanGestureSmoothingMode;
231 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
233 return mPanGestureSmoothingAmount;
236 int EnvironmentOptions::GetPanGestureUseActualTimes() const
238 return mPanGestureUseActualTimes;
241 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
243 return mPanGestureInterpolationTimeRange;
246 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
248 return mPanGestureScalarOnlyPredictionEnabled;
251 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
253 return mPanGestureTwoPointPredictionEnabled;
256 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
258 return mPanGestureTwoPointInterpolatePastTime;
261 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
263 return mPanGestureTwoPointVelocityBias;
266 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
268 return mPanGestureTwoPointAccelerationBias;
271 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
273 return mPanGestureMultitapSmoothingRange;
276 int EnvironmentOptions::GetMinimumPanDistance() const
278 return mPanMinimumDistance;
281 int EnvironmentOptions::GetMinimumPanEvents() const
283 return mPanMinimumEvents;
286 unsigned int EnvironmentOptions::GetWindowWidth() const
291 unsigned int EnvironmentOptions::GetWindowHeight() const
293 return mWindowHeight;
296 int EnvironmentOptions::GetGlesCallTime() const
298 return mGlesCallTime;
301 bool EnvironmentOptions::GetGlesCallAccumulate() const
303 return mGlesCallAccumulate;
306 const std::string& EnvironmentOptions::GetWindowName() const
311 const std::string& EnvironmentOptions::GetWindowClassName() const
313 return mWindowClassName;
316 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
318 return mThreadingMode;
321 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
323 return mRenderRefreshRate;
326 int EnvironmentOptions::GetMultiSamplingLevel() const
328 return mMultiSamplingLevel;
331 unsigned int EnvironmentOptions::GetMaxTextureSize() const
333 return mMaxTextureSize;
336 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
338 return mRenderToFboInterval;
341 bool EnvironmentOptions::PerformanceServerRequired() const
343 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
344 ( GetPerformanceTimeStampOutput() > 0 ) ||
345 ( GetNetworkControlMode() > 0) );
348 bool EnvironmentOptions::DepthBufferRequired() const
350 return mDepthBufferRequired;
353 bool EnvironmentOptions::StencilBufferRequired() const
355 return mStencilBufferRequired;
358 void EnvironmentOptions::ParseEnvironmentOptions()
360 // get logging options
361 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
362 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
363 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
364 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
365 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
366 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
367 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
368 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
371 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
373 mPanGesturePredictionMode = predictionMode;
375 int predictionAmount(-1);
376 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
378 if( predictionAmount < 0 )
380 // do not support times in the past
381 predictionAmount = 0;
383 mPanGesturePredictionAmount = predictionAmount;
385 int minPredictionAmount(-1);
386 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
388 if( minPredictionAmount < 0 )
390 // do not support times in the past
391 minPredictionAmount = 0;
393 mPanGestureMinPredictionAmount = minPredictionAmount;
395 int maxPredictionAmount(-1);
396 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
398 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
400 // maximum amount should not be smaller than minimum amount
401 maxPredictionAmount = minPredictionAmount;
403 mPanGestureMaxPredictionAmount = maxPredictionAmount;
405 int predictionAmountAdjustment(-1);
406 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
408 if( predictionAmountAdjustment < 0 )
410 // negative amount doesn't make sense
411 predictionAmountAdjustment = 0;
413 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
416 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
418 mPanGestureSmoothingMode = smoothingMode;
420 float smoothingAmount = 1.0f;
421 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
423 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
424 mPanGestureSmoothingAmount = smoothingAmount;
427 int useActualTimes( -1 );
428 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_USE_ACTUAL_TIMES, useActualTimes ) )
430 mPanGestureUseActualTimes = useActualTimes == 0 ? 0 : 1;
433 int interpolationTimeRange( -1 );
434 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, interpolationTimeRange ) )
436 if( interpolationTimeRange < 0 )
438 interpolationTimeRange = 0;
440 mPanGestureInterpolationTimeRange = interpolationTimeRange;
443 int scalarOnlyPredictionEnabled( -1 );
444 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, scalarOnlyPredictionEnabled ) )
446 mPanGestureScalarOnlyPredictionEnabled = scalarOnlyPredictionEnabled == 0 ? 0 : 1;
449 int twoPointPredictionEnabled( -1 );
450 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, twoPointPredictionEnabled ) )
452 mPanGestureTwoPointPredictionEnabled = twoPointPredictionEnabled == 0 ? 0 : 1;
455 int twoPointPastInterpolateTime( -1 );
456 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, twoPointPastInterpolateTime ) )
458 if( twoPointPastInterpolateTime < 0 )
460 twoPointPastInterpolateTime = 0;
462 mPanGestureTwoPointInterpolatePastTime = twoPointPastInterpolateTime;
465 float twoPointVelocityBias = -1.0f;
466 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, twoPointVelocityBias ) )
468 twoPointVelocityBias = Clamp( twoPointVelocityBias, 0.0f, 1.0f );
469 mPanGestureTwoPointVelocityBias = twoPointVelocityBias;
472 float twoPointAccelerationBias = -1.0f;
473 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, twoPointAccelerationBias ) )
475 twoPointAccelerationBias = Clamp( twoPointAccelerationBias, 0.0f, 1.0f );
476 mPanGestureTwoPointAccelerationBias = twoPointAccelerationBias;
479 int multitapSmoothingRange( -1 );
480 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, multitapSmoothingRange ) )
482 if( multitapSmoothingRange < 0 )
484 multitapSmoothingRange = 0;
486 mPanGestureMultitapSmoothingRange = multitapSmoothingRange;
489 int minimumDistance(-1);
490 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
492 mPanMinimumDistance = minimumDistance;
495 int minimumEvents(-1);
496 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
498 mPanMinimumEvents = minimumEvents;
502 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
504 mGlesCallTime = glesCallTime;
507 int glesCallAccumulate( 0 );
508 if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
510 mGlesCallAccumulate = glesCallAccumulate != 0;
513 int windowWidth(0), windowHeight(0);
514 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
516 mWindowWidth = windowWidth;
517 mWindowHeight = windowHeight;
520 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
523 mWindowName = windowName;
526 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
527 if ( windowClassName )
529 mWindowClassName = windowClassName;
532 int threadingMode(0);
533 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
535 switch( threadingMode )
537 case ThreadingMode::COMBINED_UPDATE_RENDER:
539 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
545 int renderRefreshRate(0);
546 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
548 // Only change it if it's valid
549 if( renderRefreshRate > 1 )
551 mRenderRefreshRate = renderRefreshRate;
555 int multiSamplingLevel( 0 );
556 if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
558 mMultiSamplingLevel = multiSamplingLevel;
561 int maxTextureSize( 0 );
562 if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
564 if( maxTextureSize > 0 )
566 mMaxTextureSize = maxTextureSize;
570 mRenderToFboInterval = GetIntegerEnvironmentVariable( DALI_RENDER_TO_FBO, 0u );
573 int depthBufferRequired( -1 );
574 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_DEPTH_BUFFER, depthBufferRequired ) )
576 if( depthBufferRequired > 0 )
578 mDepthBufferRequired = false;
579 mStencilBufferRequired = false; // Disable stencil buffer as well
583 int stencilBufferRequired( -1 );
584 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_STENCIL_BUFFER, stencilBufferRequired ) )
586 if( stencilBufferRequired > 0 )
588 mStencilBufferRequired = false;