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 ),
124 mMultiSamplingLevel( DEFAULT_MULTI_SAMPLING_LEVEL ),
125 mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
126 mGlesCallAccumulate( false ),
127 mDepthBufferRequired( DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING ),
128 mStencilBufferRequired( DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING ),
129 mPartialUpdateAvailable( false )
131 ParseEnvironmentOptions();
134 EnvironmentOptions::~EnvironmentOptions()
138 void EnvironmentOptions::CreateTraceManager( PerformanceInterface* performanceInterface )
140 mTraceManager = TraceManagerFactory::CreateTraceFactory( performanceInterface );
143 void EnvironmentOptions::InstallTraceFunction() const
147 mTraceManager->Initialise();
151 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
153 mLogFunction = logFunction;
156 void EnvironmentOptions::InstallLogFunction() const
158 Dali::Integration::Log::InstallLogFunction( mLogFunction );
161 void EnvironmentOptions::UnInstallLogFunction() const
163 Dali::Integration::Log::UninstallLogFunction();
166 unsigned int EnvironmentOptions::GetNetworkControlMode() const
168 return mNetworkControl;
170 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
172 return mFpsFrequency;
175 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
177 return mUpdateStatusFrequency;
180 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
182 return mObjectProfilerInterval;
185 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
187 return mPerformanceStatsLevel;
189 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
191 return mPerformanceStatsFrequency;
193 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
195 return mPerformanceTimeStampOutput;
198 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
200 return mPanGestureLoggingLevel;
203 int EnvironmentOptions::GetPanGesturePredictionMode() const
205 return mPanGesturePredictionMode;
208 int EnvironmentOptions::GetPanGesturePredictionAmount() const
210 return mPanGesturePredictionAmount;
213 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
215 return mPanGestureMaxPredictionAmount;
218 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
220 return mPanGestureMinPredictionAmount;
223 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
225 return mPanGesturePredictionAmountAdjustment;
228 int EnvironmentOptions::GetPanGestureSmoothingMode() const
230 return mPanGestureSmoothingMode;
233 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
235 return mPanGestureSmoothingAmount;
238 int EnvironmentOptions::GetPanGestureUseActualTimes() const
240 return mPanGestureUseActualTimes;
243 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
245 return mPanGestureInterpolationTimeRange;
248 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
250 return mPanGestureScalarOnlyPredictionEnabled;
253 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
255 return mPanGestureTwoPointPredictionEnabled;
258 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
260 return mPanGestureTwoPointInterpolatePastTime;
263 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
265 return mPanGestureTwoPointVelocityBias;
268 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
270 return mPanGestureTwoPointAccelerationBias;
273 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
275 return mPanGestureMultitapSmoothingRange;
278 int EnvironmentOptions::GetMinimumPanDistance() const
280 return mPanMinimumDistance;
283 int EnvironmentOptions::GetMinimumPanEvents() const
285 return mPanMinimumEvents;
288 float EnvironmentOptions::GetMinimumPinchDistance() const
290 return mPinchMinimumDistance;
293 unsigned int EnvironmentOptions::GetWindowWidth() const
298 unsigned int EnvironmentOptions::GetWindowHeight() const
300 return mWindowHeight;
303 int EnvironmentOptions::GetGlesCallTime() const
305 return mGlesCallTime;
308 bool EnvironmentOptions::GetGlesCallAccumulate() const
310 return mGlesCallAccumulate;
313 const std::string& EnvironmentOptions::GetWindowName() const
318 const std::string& EnvironmentOptions::GetWindowClassName() const
320 return mWindowClassName;
323 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
325 return mThreadingMode;
328 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
330 return mRenderRefreshRate;
333 int EnvironmentOptions::GetMultiSamplingLevel() const
335 return mMultiSamplingLevel;
338 unsigned int EnvironmentOptions::GetMaxTextureSize() const
340 return mMaxTextureSize;
343 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
345 return mRenderToFboInterval;
348 bool EnvironmentOptions::PerformanceServerRequired() const
350 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
351 ( GetPerformanceTimeStampOutput() > 0 ) ||
352 ( GetNetworkControlMode() > 0) );
355 bool EnvironmentOptions::DepthBufferRequired() const
357 return mDepthBufferRequired;
360 bool EnvironmentOptions::StencilBufferRequired() const
362 return mStencilBufferRequired;
365 bool EnvironmentOptions::PartialUpdateAvailable() const
367 return mPartialUpdateAvailable;
370 void EnvironmentOptions::ParseEnvironmentOptions()
372 // get logging options
373 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
374 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
375 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
376 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
377 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
378 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
379 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
380 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
383 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
385 mPanGesturePredictionMode = predictionMode;
387 int predictionAmount(-1);
388 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
390 if( predictionAmount < 0 )
392 // do not support times in the past
393 predictionAmount = 0;
395 mPanGesturePredictionAmount = predictionAmount;
397 int minPredictionAmount(-1);
398 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
400 if( minPredictionAmount < 0 )
402 // do not support times in the past
403 minPredictionAmount = 0;
405 mPanGestureMinPredictionAmount = minPredictionAmount;
407 int maxPredictionAmount(-1);
408 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
410 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
412 // maximum amount should not be smaller than minimum amount
413 maxPredictionAmount = minPredictionAmount;
415 mPanGestureMaxPredictionAmount = maxPredictionAmount;
417 int predictionAmountAdjustment(-1);
418 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
420 if( predictionAmountAdjustment < 0 )
422 // negative amount doesn't make sense
423 predictionAmountAdjustment = 0;
425 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
428 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
430 mPanGestureSmoothingMode = smoothingMode;
432 float smoothingAmount = 1.0f;
433 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
435 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
436 mPanGestureSmoothingAmount = smoothingAmount;
439 int useActualTimes( -1 );
440 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_USE_ACTUAL_TIMES, useActualTimes ) )
442 mPanGestureUseActualTimes = useActualTimes == 0 ? 0 : 1;
445 int interpolationTimeRange( -1 );
446 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, interpolationTimeRange ) )
448 if( interpolationTimeRange < 0 )
450 interpolationTimeRange = 0;
452 mPanGestureInterpolationTimeRange = interpolationTimeRange;
455 int scalarOnlyPredictionEnabled( -1 );
456 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, scalarOnlyPredictionEnabled ) )
458 mPanGestureScalarOnlyPredictionEnabled = scalarOnlyPredictionEnabled == 0 ? 0 : 1;
461 int twoPointPredictionEnabled( -1 );
462 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, twoPointPredictionEnabled ) )
464 mPanGestureTwoPointPredictionEnabled = twoPointPredictionEnabled == 0 ? 0 : 1;
467 int twoPointPastInterpolateTime( -1 );
468 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, twoPointPastInterpolateTime ) )
470 if( twoPointPastInterpolateTime < 0 )
472 twoPointPastInterpolateTime = 0;
474 mPanGestureTwoPointInterpolatePastTime = twoPointPastInterpolateTime;
477 float twoPointVelocityBias = -1.0f;
478 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, twoPointVelocityBias ) )
480 twoPointVelocityBias = Clamp( twoPointVelocityBias, 0.0f, 1.0f );
481 mPanGestureTwoPointVelocityBias = twoPointVelocityBias;
484 float twoPointAccelerationBias = -1.0f;
485 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, twoPointAccelerationBias ) )
487 twoPointAccelerationBias = Clamp( twoPointAccelerationBias, 0.0f, 1.0f );
488 mPanGestureTwoPointAccelerationBias = twoPointAccelerationBias;
491 int multitapSmoothingRange( -1 );
492 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, multitapSmoothingRange ) )
494 if( multitapSmoothingRange < 0 )
496 multitapSmoothingRange = 0;
498 mPanGestureMultitapSmoothingRange = multitapSmoothingRange;
501 int minimumDistance(-1);
502 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
504 mPanMinimumDistance = minimumDistance;
507 int minimumEvents(-1);
508 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
510 mPanMinimumEvents = minimumEvents;
513 float pinchMinimumDistance = -1.0f;
514 if( GetFloatEnvironmentVariable( DALI_ENV_PINCH_MINIMUM_DISTANCE, pinchMinimumDistance ) )
516 mPinchMinimumDistance = pinchMinimumDistance;
520 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
522 mGlesCallTime = glesCallTime;
525 int glesCallAccumulate( 0 );
526 if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
528 mGlesCallAccumulate = glesCallAccumulate != 0;
531 int windowWidth(0), windowHeight(0);
532 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
534 mWindowWidth = windowWidth;
535 mWindowHeight = windowHeight;
538 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
541 mWindowName = windowName;
544 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
545 if ( windowClassName )
547 mWindowClassName = windowClassName;
550 int threadingMode(0);
551 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
553 switch( threadingMode )
555 case ThreadingMode::COMBINED_UPDATE_RENDER:
557 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
563 int renderRefreshRate(0);
564 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
566 // Only change it if it's valid
567 if( renderRefreshRate > 1 )
569 mRenderRefreshRate = renderRefreshRate;
573 int multiSamplingLevel( 0 );
574 if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
576 mMultiSamplingLevel = multiSamplingLevel;
579 int maxTextureSize( 0 );
580 if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
582 if( maxTextureSize > 0 )
584 mMaxTextureSize = maxTextureSize;
588 mRenderToFboInterval = GetIntegerEnvironmentVariable( DALI_RENDER_TO_FBO, 0u );
591 int depthBufferRequired( -1 );
592 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_DEPTH_BUFFER, depthBufferRequired ) )
594 if( depthBufferRequired > 0 )
596 mDepthBufferRequired = false;
597 mStencilBufferRequired = false; // Disable stencil buffer as well
601 int stencilBufferRequired( -1 );
602 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_STENCIL_BUFFER, stencilBufferRequired ) )
604 if( stencilBufferRequired > 0 )
606 mStencilBufferRequired = false;
610 int partialUpdateRequired( -1 );
611 if( GetIntegerEnvironmentVariable( DALI_ENV_PARTIAL_UPDATE_AVAILABLE, partialUpdateRequired ) )
613 if( partialUpdateRequired > 0 )
615 mPartialUpdateAvailable = true;