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;
45 const bool DEFAULT_PARTIAL_UPDATE_REQUIRED_SETTING = true;
47 unsigned int GetIntegerEnvironmentVariable( const char* variable, unsigned int defaultValue )
49 const char* variableParameter = std::getenv(variable);
51 // if the parameter exists convert it to an integer, else return the default value
52 unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
56 bool GetIntegerEnvironmentVariable( const char* variable, int& intValue )
58 const char* variableParameter = std::getenv(variable);
60 if( !variableParameter )
64 // if the parameter exists convert it to an integer, else return the default value
65 intValue = std::atoi(variableParameter);
69 bool GetFloatEnvironmentVariable( const char* variable, float& floatValue )
71 const char* variableParameter = std::getenv(variable);
73 if( !variableParameter )
77 // if the parameter exists convert it to an integer, else return the default value
78 floatValue = std::atof(variableParameter);
82 const char * GetCharEnvironmentVariable( const char * variable )
84 return std::getenv( variable );
87 } // unnamed namespace
89 EnvironmentOptions::EnvironmentOptions()
90 : mLogFunction( NULL ),
95 mUpdateStatusFrequency( 0 ),
96 mObjectProfilerInterval( 0 ),
97 mPerformanceStatsLevel( 0 ),
98 mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY ),
99 mPerformanceTimeStampOutput( 0 ),
100 mPanGestureLoggingLevel( 0 ),
103 mRenderRefreshRate( 1u ),
104 mMaxTextureSize( 0 ),
105 mRenderToFboInterval( 0u ),
106 mPanGesturePredictionMode( -1 ),
107 mPanGesturePredictionAmount( -1 ), ///< only sets value in pan gesture if greater than 0
108 mPanGestureMaxPredictionAmount( -1 ),
109 mPanGestureMinPredictionAmount( -1 ),
110 mPanGesturePredictionAmountAdjustment( -1 ),
111 mPanGestureSmoothingMode( -1 ),
112 mPanGestureSmoothingAmount( -1.0f ),
113 mPanGestureUseActualTimes( -1 ),
114 mPanGestureInterpolationTimeRange( -1 ),
115 mPanGestureScalarOnlyPredictionEnabled( -1 ),
116 mPanGestureTwoPointPredictionEnabled( -1 ),
117 mPanGestureTwoPointInterpolatePastTime( -1 ),
118 mPanGestureTwoPointVelocityBias( -1.0f ),
119 mPanGestureTwoPointAccelerationBias( -1.0f ),
120 mPanGestureMultitapSmoothingRange( -1 ),
121 mPanMinimumDistance( -1 ),
122 mPanMinimumEvents( -1 ),
123 mPinchMinimumDistance( -1.0f ),
124 mPinchMinimumTouchEvents( -1 ),
125 mPinchMinimumTouchEventsAfterStart( -1 ),
126 mRotationMinimumTouchEvents( -1 ),
127 mRotationMinimumTouchEventsAfterStart( -1 ),
128 mLongPressMinimumHoldingTime( -1 ),
130 mMultiSamplingLevel( DEFAULT_MULTI_SAMPLING_LEVEL ),
131 mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
132 mGlesCallAccumulate( false ),
133 mDepthBufferRequired( DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING ),
134 mStencilBufferRequired( DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING ),
135 mPartialUpdateRequired( DEFAULT_PARTIAL_UPDATE_REQUIRED_SETTING )
137 ParseEnvironmentOptions();
140 EnvironmentOptions::~EnvironmentOptions()
144 void EnvironmentOptions::CreateTraceManager( PerformanceInterface* performanceInterface )
146 mTraceManager = TraceManagerFactory::CreateTraceFactory( performanceInterface );
149 void EnvironmentOptions::InstallTraceFunction() const
153 mTraceManager->Initialise();
157 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
159 mLogFunction = logFunction;
162 void EnvironmentOptions::InstallLogFunction() const
164 Dali::Integration::Log::InstallLogFunction( mLogFunction );
167 void EnvironmentOptions::UnInstallLogFunction() const
169 Dali::Integration::Log::UninstallLogFunction();
172 unsigned int EnvironmentOptions::GetNetworkControlMode() const
174 return mNetworkControl;
176 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
178 return mFpsFrequency;
181 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
183 return mUpdateStatusFrequency;
186 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
188 return mObjectProfilerInterval;
191 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
193 return mPerformanceStatsLevel;
195 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
197 return mPerformanceStatsFrequency;
199 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
201 return mPerformanceTimeStampOutput;
204 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
206 return mPanGestureLoggingLevel;
209 int EnvironmentOptions::GetPanGesturePredictionMode() const
211 return mPanGesturePredictionMode;
214 int EnvironmentOptions::GetPanGesturePredictionAmount() const
216 return mPanGesturePredictionAmount;
219 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
221 return mPanGestureMaxPredictionAmount;
224 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
226 return mPanGestureMinPredictionAmount;
229 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
231 return mPanGesturePredictionAmountAdjustment;
234 int EnvironmentOptions::GetPanGestureSmoothingMode() const
236 return mPanGestureSmoothingMode;
239 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
241 return mPanGestureSmoothingAmount;
244 int EnvironmentOptions::GetPanGestureUseActualTimes() const
246 return mPanGestureUseActualTimes;
249 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
251 return mPanGestureInterpolationTimeRange;
254 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
256 return mPanGestureScalarOnlyPredictionEnabled;
259 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
261 return mPanGestureTwoPointPredictionEnabled;
264 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
266 return mPanGestureTwoPointInterpolatePastTime;
269 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
271 return mPanGestureTwoPointVelocityBias;
274 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
276 return mPanGestureTwoPointAccelerationBias;
279 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
281 return mPanGestureMultitapSmoothingRange;
284 int EnvironmentOptions::GetMinimumPanDistance() const
286 return mPanMinimumDistance;
289 int EnvironmentOptions::GetMinimumPanEvents() const
291 return mPanMinimumEvents;
294 float EnvironmentOptions::GetMinimumPinchDistance() const
296 return mPinchMinimumDistance;
299 int EnvironmentOptions::GetMinimumPinchTouchEvents() const
301 return mPinchMinimumTouchEvents;
304 int EnvironmentOptions::GetMinimumPinchTouchEventsAfterStart() const
306 return mPinchMinimumTouchEventsAfterStart;
309 int EnvironmentOptions::GetMinimumRotationTouchEvents() const
311 return mRotationMinimumTouchEvents;
314 int EnvironmentOptions::GetMinimumRotationTouchEventsAfterStart() const
316 return mRotationMinimumTouchEventsAfterStart;
319 int EnvironmentOptions::GetLongPressMinimumHoldingTime() const
321 return mLongPressMinimumHoldingTime;
324 unsigned int EnvironmentOptions::GetWindowWidth() const
329 unsigned int EnvironmentOptions::GetWindowHeight() const
331 return mWindowHeight;
334 int EnvironmentOptions::GetGlesCallTime() const
336 return mGlesCallTime;
339 bool EnvironmentOptions::GetGlesCallAccumulate() const
341 return mGlesCallAccumulate;
344 const std::string& EnvironmentOptions::GetWindowName() const
349 const std::string& EnvironmentOptions::GetWindowClassName() const
351 return mWindowClassName;
354 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
356 return mThreadingMode;
359 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
361 return mRenderRefreshRate;
364 int EnvironmentOptions::GetMultiSamplingLevel() const
366 return mMultiSamplingLevel;
369 unsigned int EnvironmentOptions::GetMaxTextureSize() const
371 return mMaxTextureSize;
374 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
376 return mRenderToFboInterval;
379 bool EnvironmentOptions::PerformanceServerRequired() const
381 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
382 ( GetPerformanceTimeStampOutput() > 0 ) ||
383 ( GetNetworkControlMode() > 0) );
386 bool EnvironmentOptions::DepthBufferRequired() const
388 return mDepthBufferRequired;
391 bool EnvironmentOptions::StencilBufferRequired() const
393 return mStencilBufferRequired;
396 bool EnvironmentOptions::PartialUpdateRequired() const
398 return mPartialUpdateRequired;
401 void EnvironmentOptions::ParseEnvironmentOptions()
403 // get logging options
404 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
405 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
406 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
407 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
408 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
409 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
410 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
411 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
414 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
416 mPanGesturePredictionMode = predictionMode;
418 int predictionAmount(-1);
419 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
421 if( predictionAmount < 0 )
423 // do not support times in the past
424 predictionAmount = 0;
426 mPanGesturePredictionAmount = predictionAmount;
428 int minPredictionAmount(-1);
429 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
431 if( minPredictionAmount < 0 )
433 // do not support times in the past
434 minPredictionAmount = 0;
436 mPanGestureMinPredictionAmount = minPredictionAmount;
438 int maxPredictionAmount(-1);
439 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
441 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
443 // maximum amount should not be smaller than minimum amount
444 maxPredictionAmount = minPredictionAmount;
446 mPanGestureMaxPredictionAmount = maxPredictionAmount;
448 int predictionAmountAdjustment(-1);
449 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
451 if( predictionAmountAdjustment < 0 )
453 // negative amount doesn't make sense
454 predictionAmountAdjustment = 0;
456 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
459 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
461 mPanGestureSmoothingMode = smoothingMode;
463 float smoothingAmount = 1.0f;
464 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
466 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
467 mPanGestureSmoothingAmount = smoothingAmount;
470 int useActualTimes( -1 );
471 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_USE_ACTUAL_TIMES, useActualTimes ) )
473 mPanGestureUseActualTimes = useActualTimes == 0 ? 0 : 1;
476 int interpolationTimeRange( -1 );
477 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, interpolationTimeRange ) )
479 if( interpolationTimeRange < 0 )
481 interpolationTimeRange = 0;
483 mPanGestureInterpolationTimeRange = interpolationTimeRange;
486 int scalarOnlyPredictionEnabled( -1 );
487 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, scalarOnlyPredictionEnabled ) )
489 mPanGestureScalarOnlyPredictionEnabled = scalarOnlyPredictionEnabled == 0 ? 0 : 1;
492 int twoPointPredictionEnabled( -1 );
493 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, twoPointPredictionEnabled ) )
495 mPanGestureTwoPointPredictionEnabled = twoPointPredictionEnabled == 0 ? 0 : 1;
498 int twoPointPastInterpolateTime( -1 );
499 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, twoPointPastInterpolateTime ) )
501 if( twoPointPastInterpolateTime < 0 )
503 twoPointPastInterpolateTime = 0;
505 mPanGestureTwoPointInterpolatePastTime = twoPointPastInterpolateTime;
508 float twoPointVelocityBias = -1.0f;
509 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, twoPointVelocityBias ) )
511 twoPointVelocityBias = Clamp( twoPointVelocityBias, 0.0f, 1.0f );
512 mPanGestureTwoPointVelocityBias = twoPointVelocityBias;
515 float twoPointAccelerationBias = -1.0f;
516 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, twoPointAccelerationBias ) )
518 twoPointAccelerationBias = Clamp( twoPointAccelerationBias, 0.0f, 1.0f );
519 mPanGestureTwoPointAccelerationBias = twoPointAccelerationBias;
522 int multitapSmoothingRange( -1 );
523 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, multitapSmoothingRange ) )
525 if( multitapSmoothingRange < 0 )
527 multitapSmoothingRange = 0;
529 mPanGestureMultitapSmoothingRange = multitapSmoothingRange;
532 int minimumDistance(-1);
533 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
535 mPanMinimumDistance = minimumDistance;
538 int minimumEvents(-1);
539 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
541 mPanMinimumEvents = minimumEvents;
544 float pinchMinimumDistance = -1.0f;
545 if( GetFloatEnvironmentVariable( DALI_ENV_PINCH_MINIMUM_DISTANCE, pinchMinimumDistance ) )
547 mPinchMinimumDistance = pinchMinimumDistance;
550 int pinchMinimumTouchEvents = -1;
551 if( GetIntegerEnvironmentVariable( DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS, pinchMinimumTouchEvents ) )
553 mPinchMinimumTouchEvents = pinchMinimumTouchEvents;
556 int pinchMinimumTouchEventsAfterStart = -1;
557 if( GetIntegerEnvironmentVariable( DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS_AFTER_START, pinchMinimumTouchEventsAfterStart ) )
559 mPinchMinimumTouchEventsAfterStart = pinchMinimumTouchEventsAfterStart;
562 int rotationMinimumTouchEvents = -1;
563 if( GetIntegerEnvironmentVariable( DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS, rotationMinimumTouchEvents ) )
565 mRotationMinimumTouchEvents = rotationMinimumTouchEvents;
568 int rotationMinimumTouchEventsAfterStart = -1;
569 if( GetIntegerEnvironmentVariable( DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS_AFTER_START, rotationMinimumTouchEventsAfterStart ) )
571 mRotationMinimumTouchEventsAfterStart = rotationMinimumTouchEventsAfterStart;
574 int longPressMinimumHoldingTime = -1;
575 if( GetIntegerEnvironmentVariable( DALI_ENV_LONG_PRESS_MINIMUM_HOLDING_TIME, longPressMinimumHoldingTime ) )
577 mLongPressMinimumHoldingTime = longPressMinimumHoldingTime;
581 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
583 mGlesCallTime = glesCallTime;
586 int glesCallAccumulate( 0 );
587 if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
589 mGlesCallAccumulate = glesCallAccumulate != 0;
592 int windowWidth(0), windowHeight(0);
593 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
595 mWindowWidth = windowWidth;
596 mWindowHeight = windowHeight;
599 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
602 mWindowName = windowName;
605 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
606 if ( windowClassName )
608 mWindowClassName = windowClassName;
611 int threadingMode(0);
612 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
614 switch( threadingMode )
616 case ThreadingMode::COMBINED_UPDATE_RENDER:
618 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
624 int renderRefreshRate(0);
625 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
627 // Only change it if it's valid
628 if( renderRefreshRate > 1 )
630 mRenderRefreshRate = renderRefreshRate;
634 int multiSamplingLevel( 0 );
635 if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
637 mMultiSamplingLevel = multiSamplingLevel;
640 int maxTextureSize( 0 );
641 if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
643 if( maxTextureSize > 0 )
645 mMaxTextureSize = maxTextureSize;
649 mRenderToFboInterval = GetIntegerEnvironmentVariable( DALI_RENDER_TO_FBO, 0u );
652 int depthBufferRequired( -1 );
653 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_DEPTH_BUFFER, depthBufferRequired ) )
655 if( depthBufferRequired > 0 )
657 mDepthBufferRequired = false;
658 mStencilBufferRequired = false; // Disable stencil buffer as well
662 int stencilBufferRequired( -1 );
663 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_STENCIL_BUFFER, stencilBufferRequired ) )
665 if( stencilBufferRequired > 0 )
667 mStencilBufferRequired = false;
671 int partialUpdateRequired( -1 );
672 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_PARTIAL_UPDATE, partialUpdateRequired ) )
674 if( partialUpdateRequired > 0 )
676 mPartialUpdateRequired = false;