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 mIndicatorVisibleMode( -1 ),
125 mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
126 mGlesCallAccumulate( false ),
127 mDepthBufferRequired( DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING ),
128 mStencilBufferRequired( DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING )
130 ParseEnvironmentOptions();
133 EnvironmentOptions::~EnvironmentOptions()
137 void EnvironmentOptions::CreateTraceManager( PerformanceInterface* performanceInterface )
139 mTraceManager = TraceManagerFactory::CreateTraceFactory( performanceInterface );
142 void EnvironmentOptions::InstallTraceFunction() const
146 mTraceManager->Initialise();
150 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
152 mLogFunction = logFunction;
155 void EnvironmentOptions::InstallLogFunction() const
157 Dali::Integration::Log::InstallLogFunction( mLogFunction );
160 void EnvironmentOptions::UnInstallLogFunction() const
162 Dali::Integration::Log::UninstallLogFunction();
165 unsigned int EnvironmentOptions::GetNetworkControlMode() const
167 return mNetworkControl;
169 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
171 return mFpsFrequency;
174 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
176 return mUpdateStatusFrequency;
179 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
181 return mObjectProfilerInterval;
184 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
186 return mPerformanceStatsLevel;
188 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
190 return mPerformanceStatsFrequency;
192 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
194 return mPerformanceTimeStampOutput;
197 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
199 return mPanGestureLoggingLevel;
202 int EnvironmentOptions::GetPanGesturePredictionMode() const
204 return mPanGesturePredictionMode;
207 int EnvironmentOptions::GetPanGesturePredictionAmount() const
209 return mPanGesturePredictionAmount;
212 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
214 return mPanGestureMaxPredictionAmount;
217 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
219 return mPanGestureMinPredictionAmount;
222 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
224 return mPanGesturePredictionAmountAdjustment;
227 int EnvironmentOptions::GetPanGestureSmoothingMode() const
229 return mPanGestureSmoothingMode;
232 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
234 return mPanGestureSmoothingAmount;
237 int EnvironmentOptions::GetPanGestureUseActualTimes() const
239 return mPanGestureUseActualTimes;
242 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
244 return mPanGestureInterpolationTimeRange;
247 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
249 return mPanGestureScalarOnlyPredictionEnabled;
252 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
254 return mPanGestureTwoPointPredictionEnabled;
257 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
259 return mPanGestureTwoPointInterpolatePastTime;
262 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
264 return mPanGestureTwoPointVelocityBias;
267 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
269 return mPanGestureTwoPointAccelerationBias;
272 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
274 return mPanGestureMultitapSmoothingRange;
277 int EnvironmentOptions::GetMinimumPanDistance() const
279 return mPanMinimumDistance;
282 int EnvironmentOptions::GetMinimumPanEvents() const
284 return mPanMinimumEvents;
287 unsigned int EnvironmentOptions::GetWindowWidth() const
292 unsigned int EnvironmentOptions::GetWindowHeight() const
294 return mWindowHeight;
297 int EnvironmentOptions::GetGlesCallTime() const
299 return mGlesCallTime;
302 bool EnvironmentOptions::GetGlesCallAccumulate() const
304 return mGlesCallAccumulate;
307 const std::string& EnvironmentOptions::GetWindowName() const
312 const std::string& EnvironmentOptions::GetWindowClassName() const
314 return mWindowClassName;
317 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
319 return mThreadingMode;
322 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
324 return mRenderRefreshRate;
327 int EnvironmentOptions::GetMultiSamplingLevel() const
329 return mMultiSamplingLevel;
332 unsigned int EnvironmentOptions::GetMaxTextureSize() const
334 return mMaxTextureSize;
337 int EnvironmentOptions::GetIndicatorVisibleMode() const
339 return mIndicatorVisibleMode;
342 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
344 return mRenderToFboInterval;
347 bool EnvironmentOptions::PerformanceServerRequired() const
349 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
350 ( GetPerformanceTimeStampOutput() > 0 ) ||
351 ( GetNetworkControlMode() > 0) );
354 bool EnvironmentOptions::DepthBufferRequired() const
356 return mDepthBufferRequired;
359 bool EnvironmentOptions::StencilBufferRequired() const
361 return mStencilBufferRequired;
364 void EnvironmentOptions::ParseEnvironmentOptions()
366 // get logging options
367 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
368 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
369 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
370 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
371 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
372 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
373 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
374 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
377 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
379 mPanGesturePredictionMode = predictionMode;
381 int predictionAmount(-1);
382 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
384 if( predictionAmount < 0 )
386 // do not support times in the past
387 predictionAmount = 0;
389 mPanGesturePredictionAmount = predictionAmount;
391 int minPredictionAmount(-1);
392 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
394 if( minPredictionAmount < 0 )
396 // do not support times in the past
397 minPredictionAmount = 0;
399 mPanGestureMinPredictionAmount = minPredictionAmount;
401 int maxPredictionAmount(-1);
402 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
404 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
406 // maximum amount should not be smaller than minimum amount
407 maxPredictionAmount = minPredictionAmount;
409 mPanGestureMaxPredictionAmount = maxPredictionAmount;
411 int predictionAmountAdjustment(-1);
412 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
414 if( predictionAmountAdjustment < 0 )
416 // negative amount doesn't make sense
417 predictionAmountAdjustment = 0;
419 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
422 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
424 mPanGestureSmoothingMode = smoothingMode;
426 float smoothingAmount = 1.0f;
427 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
429 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
430 mPanGestureSmoothingAmount = smoothingAmount;
433 int useActualTimes( -1 );
434 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_USE_ACTUAL_TIMES, useActualTimes ) )
436 mPanGestureUseActualTimes = useActualTimes == 0 ? 0 : 1;
439 int interpolationTimeRange( -1 );
440 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, interpolationTimeRange ) )
442 if( interpolationTimeRange < 0 )
444 interpolationTimeRange = 0;
446 mPanGestureInterpolationTimeRange = interpolationTimeRange;
449 int scalarOnlyPredictionEnabled( -1 );
450 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, scalarOnlyPredictionEnabled ) )
452 mPanGestureScalarOnlyPredictionEnabled = scalarOnlyPredictionEnabled == 0 ? 0 : 1;
455 int twoPointPredictionEnabled( -1 );
456 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, twoPointPredictionEnabled ) )
458 mPanGestureTwoPointPredictionEnabled = twoPointPredictionEnabled == 0 ? 0 : 1;
461 int twoPointPastInterpolateTime( -1 );
462 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, twoPointPastInterpolateTime ) )
464 if( twoPointPastInterpolateTime < 0 )
466 twoPointPastInterpolateTime = 0;
468 mPanGestureTwoPointInterpolatePastTime = twoPointPastInterpolateTime;
471 float twoPointVelocityBias = -1.0f;
472 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, twoPointVelocityBias ) )
474 twoPointVelocityBias = Clamp( twoPointVelocityBias, 0.0f, 1.0f );
475 mPanGestureTwoPointVelocityBias = twoPointVelocityBias;
478 float twoPointAccelerationBias = -1.0f;
479 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, twoPointAccelerationBias ) )
481 twoPointAccelerationBias = Clamp( twoPointAccelerationBias, 0.0f, 1.0f );
482 mPanGestureTwoPointAccelerationBias = twoPointAccelerationBias;
485 int multitapSmoothingRange( -1 );
486 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, multitapSmoothingRange ) )
488 if( multitapSmoothingRange < 0 )
490 multitapSmoothingRange = 0;
492 mPanGestureMultitapSmoothingRange = multitapSmoothingRange;
495 int minimumDistance(-1);
496 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
498 mPanMinimumDistance = minimumDistance;
501 int minimumEvents(-1);
502 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
504 mPanMinimumEvents = minimumEvents;
508 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
510 mGlesCallTime = glesCallTime;
513 int glesCallAccumulate( 0 );
514 if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
516 mGlesCallAccumulate = glesCallAccumulate != 0;
519 int windowWidth(0), windowHeight(0);
520 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
522 mWindowWidth = windowWidth;
523 mWindowHeight = windowHeight;
526 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
529 mWindowName = windowName;
532 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
533 if ( windowClassName )
535 mWindowClassName = windowClassName;
538 int threadingMode(0);
539 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
541 switch( threadingMode )
543 case ThreadingMode::COMBINED_UPDATE_RENDER:
545 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
551 int renderRefreshRate(0);
552 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
554 // Only change it if it's valid
555 if( renderRefreshRate > 1 )
557 mRenderRefreshRate = renderRefreshRate;
561 int multiSamplingLevel( 0 );
562 if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
564 mMultiSamplingLevel = multiSamplingLevel;
567 int maxTextureSize( 0 );
568 if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
570 if( maxTextureSize > 0 )
572 mMaxTextureSize = maxTextureSize;
576 int indicatorVisibleMode( -1 );
577 if( GetIntegerEnvironmentVariable( DALI_ENV_INDICATOR_VISIBLE_MODE, indicatorVisibleMode ) )
579 if( indicatorVisibleMode > -1 )
581 mIndicatorVisibleMode = indicatorVisibleMode;
585 mRenderToFboInterval = GetIntegerEnvironmentVariable( DALI_RENDER_TO_FBO, 0u );
588 int depthBufferRequired( -1 );
589 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_DEPTH_BUFFER, depthBufferRequired ) )
591 if( depthBufferRequired > 0 )
593 mDepthBufferRequired = false;
594 mStencilBufferRequired = false; // Disable stencil buffer as well
598 int stencilBufferRequired( -1 );
599 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_STENCIL_BUFFER, stencilBufferRequired ) )
601 if( stencilBufferRequired > 0 )
603 mStencilBufferRequired = false;