2 * Copyright (c) 2019 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 ),
122 mPinchMinimumDistance( -1.0f ),
123 mPinchMinimumTouchEvents( -1 ),
124 mPinchMinimumTouchEventsAfterStart( -1 ),
125 mRotationMinimumTouchEvents( -1 ),
126 mRotationMinimumTouchEventsAfterStart( -1 ),
127 mLongPressMinimumHoldingTime( -1 ),
129 mMultiSamplingLevel( DEFAULT_MULTI_SAMPLING_LEVEL ),
130 mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
131 mGlesCallAccumulate( false ),
132 mDepthBufferRequired( DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING ),
133 mStencilBufferRequired( DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING )
135 ParseEnvironmentOptions();
138 EnvironmentOptions::~EnvironmentOptions()
142 void EnvironmentOptions::CreateTraceManager( PerformanceInterface* performanceInterface )
144 mTraceManager = TraceManagerFactory::CreateTraceFactory( performanceInterface );
147 void EnvironmentOptions::InstallTraceFunction() const
151 mTraceManager->Initialise();
155 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
157 mLogFunction = logFunction;
160 void EnvironmentOptions::InstallLogFunction() const
162 Dali::Integration::Log::InstallLogFunction( mLogFunction );
165 void EnvironmentOptions::UnInstallLogFunction() const
167 Dali::Integration::Log::UninstallLogFunction();
170 unsigned int EnvironmentOptions::GetNetworkControlMode() const
172 return mNetworkControl;
174 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
176 return mFpsFrequency;
179 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
181 return mUpdateStatusFrequency;
184 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
186 return mObjectProfilerInterval;
189 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
191 return mPerformanceStatsLevel;
193 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
195 return mPerformanceStatsFrequency;
197 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
199 return mPerformanceTimeStampOutput;
202 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
204 return mPanGestureLoggingLevel;
207 int EnvironmentOptions::GetPanGesturePredictionMode() const
209 return mPanGesturePredictionMode;
212 int EnvironmentOptions::GetPanGesturePredictionAmount() const
214 return mPanGesturePredictionAmount;
217 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
219 return mPanGestureMaxPredictionAmount;
222 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
224 return mPanGestureMinPredictionAmount;
227 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
229 return mPanGesturePredictionAmountAdjustment;
232 int EnvironmentOptions::GetPanGestureSmoothingMode() const
234 return mPanGestureSmoothingMode;
237 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
239 return mPanGestureSmoothingAmount;
242 int EnvironmentOptions::GetPanGestureUseActualTimes() const
244 return mPanGestureUseActualTimes;
247 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
249 return mPanGestureInterpolationTimeRange;
252 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
254 return mPanGestureScalarOnlyPredictionEnabled;
257 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
259 return mPanGestureTwoPointPredictionEnabled;
262 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
264 return mPanGestureTwoPointInterpolatePastTime;
267 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
269 return mPanGestureTwoPointVelocityBias;
272 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
274 return mPanGestureTwoPointAccelerationBias;
277 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
279 return mPanGestureMultitapSmoothingRange;
282 int EnvironmentOptions::GetMinimumPanDistance() const
284 return mPanMinimumDistance;
287 int EnvironmentOptions::GetMinimumPanEvents() const
289 return mPanMinimumEvents;
292 float EnvironmentOptions::GetMinimumPinchDistance() const
294 return mPinchMinimumDistance;
297 int EnvironmentOptions::GetMinimumPinchTouchEvents() const
299 return mPinchMinimumTouchEvents;
302 int EnvironmentOptions::GetMinimumPinchTouchEventsAfterStart() const
304 return mPinchMinimumTouchEventsAfterStart;
307 int EnvironmentOptions::GetMinimumRotationTouchEvents() const
309 return mRotationMinimumTouchEvents;
312 int EnvironmentOptions::GetMinimumRotationTouchEventsAfterStart() const
314 return mRotationMinimumTouchEventsAfterStart;
317 int EnvironmentOptions::GetLongPressMinimumHoldingTime() const
319 return mLongPressMinimumHoldingTime;
322 unsigned int EnvironmentOptions::GetWindowWidth() const
327 unsigned int EnvironmentOptions::GetWindowHeight() const
329 return mWindowHeight;
332 int EnvironmentOptions::GetGlesCallTime() const
334 return mGlesCallTime;
337 bool EnvironmentOptions::GetGlesCallAccumulate() const
339 return mGlesCallAccumulate;
342 const std::string& EnvironmentOptions::GetWindowName() const
347 const std::string& EnvironmentOptions::GetWindowClassName() const
349 return mWindowClassName;
352 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
354 return mThreadingMode;
357 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
359 return mRenderRefreshRate;
362 int EnvironmentOptions::GetMultiSamplingLevel() const
364 return mMultiSamplingLevel;
367 unsigned int EnvironmentOptions::GetMaxTextureSize() const
369 return mMaxTextureSize;
372 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
374 return mRenderToFboInterval;
377 bool EnvironmentOptions::PerformanceServerRequired() const
379 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
380 ( GetPerformanceTimeStampOutput() > 0 ) ||
381 ( GetNetworkControlMode() > 0) );
384 bool EnvironmentOptions::DepthBufferRequired() const
386 return mDepthBufferRequired;
389 bool EnvironmentOptions::StencilBufferRequired() const
391 return mStencilBufferRequired;
394 void EnvironmentOptions::ParseEnvironmentOptions()
396 // get logging options
397 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
398 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
399 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
400 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
401 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
402 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
403 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
404 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
407 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
409 mPanGesturePredictionMode = predictionMode;
411 int predictionAmount(-1);
412 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
414 if( predictionAmount < 0 )
416 // do not support times in the past
417 predictionAmount = 0;
419 mPanGesturePredictionAmount = predictionAmount;
421 int minPredictionAmount(-1);
422 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
424 if( minPredictionAmount < 0 )
426 // do not support times in the past
427 minPredictionAmount = 0;
429 mPanGestureMinPredictionAmount = minPredictionAmount;
431 int maxPredictionAmount(-1);
432 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
434 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
436 // maximum amount should not be smaller than minimum amount
437 maxPredictionAmount = minPredictionAmount;
439 mPanGestureMaxPredictionAmount = maxPredictionAmount;
441 int predictionAmountAdjustment(-1);
442 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
444 if( predictionAmountAdjustment < 0 )
446 // negative amount doesn't make sense
447 predictionAmountAdjustment = 0;
449 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
452 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
454 mPanGestureSmoothingMode = smoothingMode;
456 float smoothingAmount = 1.0f;
457 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
459 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
460 mPanGestureSmoothingAmount = smoothingAmount;
463 int useActualTimes( -1 );
464 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_USE_ACTUAL_TIMES, useActualTimes ) )
466 mPanGestureUseActualTimes = useActualTimes == 0 ? 0 : 1;
469 int interpolationTimeRange( -1 );
470 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, interpolationTimeRange ) )
472 if( interpolationTimeRange < 0 )
474 interpolationTimeRange = 0;
476 mPanGestureInterpolationTimeRange = interpolationTimeRange;
479 int scalarOnlyPredictionEnabled( -1 );
480 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, scalarOnlyPredictionEnabled ) )
482 mPanGestureScalarOnlyPredictionEnabled = scalarOnlyPredictionEnabled == 0 ? 0 : 1;
485 int twoPointPredictionEnabled( -1 );
486 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, twoPointPredictionEnabled ) )
488 mPanGestureTwoPointPredictionEnabled = twoPointPredictionEnabled == 0 ? 0 : 1;
491 int twoPointPastInterpolateTime( -1 );
492 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, twoPointPastInterpolateTime ) )
494 if( twoPointPastInterpolateTime < 0 )
496 twoPointPastInterpolateTime = 0;
498 mPanGestureTwoPointInterpolatePastTime = twoPointPastInterpolateTime;
501 float twoPointVelocityBias = -1.0f;
502 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, twoPointVelocityBias ) )
504 twoPointVelocityBias = Clamp( twoPointVelocityBias, 0.0f, 1.0f );
505 mPanGestureTwoPointVelocityBias = twoPointVelocityBias;
508 float twoPointAccelerationBias = -1.0f;
509 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, twoPointAccelerationBias ) )
511 twoPointAccelerationBias = Clamp( twoPointAccelerationBias, 0.0f, 1.0f );
512 mPanGestureTwoPointAccelerationBias = twoPointAccelerationBias;
515 int multitapSmoothingRange( -1 );
516 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, multitapSmoothingRange ) )
518 if( multitapSmoothingRange < 0 )
520 multitapSmoothingRange = 0;
522 mPanGestureMultitapSmoothingRange = multitapSmoothingRange;
525 int minimumDistance(-1);
526 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
528 mPanMinimumDistance = minimumDistance;
531 int minimumEvents(-1);
532 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
534 mPanMinimumEvents = minimumEvents;
537 float pinchMinimumDistance = -1.0f;
538 if( GetFloatEnvironmentVariable( DALI_ENV_PINCH_MINIMUM_DISTANCE, pinchMinimumDistance ) )
540 mPinchMinimumDistance = pinchMinimumDistance;
543 int pinchMinimumTouchEvents = -1;
544 if( GetIntegerEnvironmentVariable( DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS, pinchMinimumTouchEvents ) )
546 mPinchMinimumTouchEvents = pinchMinimumTouchEvents;
549 int pinchMinimumTouchEventsAfterStart = -1;
550 if( GetIntegerEnvironmentVariable( DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS_AFTER_START, pinchMinimumTouchEventsAfterStart ) )
552 mPinchMinimumTouchEventsAfterStart = pinchMinimumTouchEventsAfterStart;
555 int rotationMinimumTouchEvents = -1;
556 if( GetIntegerEnvironmentVariable( DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS, rotationMinimumTouchEvents ) )
558 mRotationMinimumTouchEvents = rotationMinimumTouchEvents;
561 int rotationMinimumTouchEventsAfterStart = -1;
562 if( GetIntegerEnvironmentVariable( DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS_AFTER_START, rotationMinimumTouchEventsAfterStart ) )
564 mRotationMinimumTouchEventsAfterStart = rotationMinimumTouchEventsAfterStart;
567 int longPressMinimumHoldingTime = -1;
568 if( GetIntegerEnvironmentVariable( DALI_ENV_LONG_PRESS_MINIMUM_HOLDING_TIME, longPressMinimumHoldingTime ) )
570 mLongPressMinimumHoldingTime = longPressMinimumHoldingTime;
574 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
576 mGlesCallTime = glesCallTime;
579 int glesCallAccumulate( 0 );
580 if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
582 mGlesCallAccumulate = glesCallAccumulate != 0;
585 int windowWidth(0), windowHeight(0);
586 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
588 mWindowWidth = windowWidth;
589 mWindowHeight = windowHeight;
592 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
595 mWindowName = windowName;
598 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
599 if ( windowClassName )
601 mWindowClassName = windowClassName;
604 int threadingMode(0);
605 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
607 switch( threadingMode )
609 case ThreadingMode::COMBINED_UPDATE_RENDER:
611 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
617 int renderRefreshRate(0);
618 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
620 // Only change it if it's valid
621 if( renderRefreshRate > 1 )
623 mRenderRefreshRate = renderRefreshRate;
627 int multiSamplingLevel( 0 );
628 if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
630 mMultiSamplingLevel = multiSamplingLevel;
633 int maxTextureSize( 0 );
634 if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
636 if( maxTextureSize > 0 )
638 mMaxTextureSize = maxTextureSize;
642 mRenderToFboInterval = GetIntegerEnvironmentVariable( DALI_RENDER_TO_FBO, 0u );
645 int depthBufferRequired( -1 );
646 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_DEPTH_BUFFER, depthBufferRequired ) )
648 if( depthBufferRequired > 0 )
650 mDepthBufferRequired = false;
651 mStencilBufferRequired = false; // Disable stencil buffer as well
655 int stencilBufferRequired( -1 );
656 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_STENCIL_BUFFER, stencilBufferRequired ) )
658 if( stencilBufferRequired > 0 )
660 mStencilBufferRequired = false;