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 mLongPressMinimumHoldingTime( -1 ),
125 mMultiSamplingLevel( DEFAULT_MULTI_SAMPLING_LEVEL ),
126 mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
127 mGlesCallAccumulate( false ),
128 mDepthBufferRequired( DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING ),
129 mStencilBufferRequired( DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING ),
130 mPartialUpdateAvailable( false )
132 ParseEnvironmentOptions();
135 EnvironmentOptions::~EnvironmentOptions()
139 void EnvironmentOptions::CreateTraceManager( PerformanceInterface* performanceInterface )
141 mTraceManager = TraceManagerFactory::CreateTraceFactory( performanceInterface );
144 void EnvironmentOptions::InstallTraceFunction() const
148 mTraceManager->Initialise();
152 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
154 mLogFunction = logFunction;
157 void EnvironmentOptions::InstallLogFunction() const
159 Dali::Integration::Log::InstallLogFunction( mLogFunction );
162 void EnvironmentOptions::UnInstallLogFunction() const
164 Dali::Integration::Log::UninstallLogFunction();
167 unsigned int EnvironmentOptions::GetNetworkControlMode() const
169 return mNetworkControl;
171 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
173 return mFpsFrequency;
176 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
178 return mUpdateStatusFrequency;
181 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
183 return mObjectProfilerInterval;
186 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
188 return mPerformanceStatsLevel;
190 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
192 return mPerformanceStatsFrequency;
194 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
196 return mPerformanceTimeStampOutput;
199 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
201 return mPanGestureLoggingLevel;
204 int EnvironmentOptions::GetPanGesturePredictionMode() const
206 return mPanGesturePredictionMode;
209 int EnvironmentOptions::GetPanGesturePredictionAmount() const
211 return mPanGesturePredictionAmount;
214 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
216 return mPanGestureMaxPredictionAmount;
219 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
221 return mPanGestureMinPredictionAmount;
224 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
226 return mPanGesturePredictionAmountAdjustment;
229 int EnvironmentOptions::GetPanGestureSmoothingMode() const
231 return mPanGestureSmoothingMode;
234 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
236 return mPanGestureSmoothingAmount;
239 int EnvironmentOptions::GetPanGestureUseActualTimes() const
241 return mPanGestureUseActualTimes;
244 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
246 return mPanGestureInterpolationTimeRange;
249 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
251 return mPanGestureScalarOnlyPredictionEnabled;
254 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
256 return mPanGestureTwoPointPredictionEnabled;
259 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
261 return mPanGestureTwoPointInterpolatePastTime;
264 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
266 return mPanGestureTwoPointVelocityBias;
269 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
271 return mPanGestureTwoPointAccelerationBias;
274 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
276 return mPanGestureMultitapSmoothingRange;
279 int EnvironmentOptions::GetMinimumPanDistance() const
281 return mPanMinimumDistance;
284 int EnvironmentOptions::GetMinimumPanEvents() const
286 return mPanMinimumEvents;
289 float EnvironmentOptions::GetMinimumPinchDistance() const
291 return mPinchMinimumDistance;
294 int EnvironmentOptions::GetLongPressMinimumHoldingTime() const
296 return mLongPressMinimumHoldingTime;
299 unsigned int EnvironmentOptions::GetWindowWidth() const
304 unsigned int EnvironmentOptions::GetWindowHeight() const
306 return mWindowHeight;
309 int EnvironmentOptions::GetGlesCallTime() const
311 return mGlesCallTime;
314 bool EnvironmentOptions::GetGlesCallAccumulate() const
316 return mGlesCallAccumulate;
319 const std::string& EnvironmentOptions::GetWindowName() const
324 const std::string& EnvironmentOptions::GetWindowClassName() const
326 return mWindowClassName;
329 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
331 return mThreadingMode;
334 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
336 return mRenderRefreshRate;
339 int EnvironmentOptions::GetMultiSamplingLevel() const
341 return mMultiSamplingLevel;
344 unsigned int EnvironmentOptions::GetMaxTextureSize() const
346 return mMaxTextureSize;
349 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
351 return mRenderToFboInterval;
354 bool EnvironmentOptions::PerformanceServerRequired() const
356 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
357 ( GetPerformanceTimeStampOutput() > 0 ) ||
358 ( GetNetworkControlMode() > 0) );
361 bool EnvironmentOptions::DepthBufferRequired() const
363 return mDepthBufferRequired;
366 bool EnvironmentOptions::StencilBufferRequired() const
368 return mStencilBufferRequired;
371 bool EnvironmentOptions::PartialUpdateAvailable() const
373 return mPartialUpdateAvailable;
376 void EnvironmentOptions::ParseEnvironmentOptions()
378 // get logging options
379 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
380 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
381 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
382 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
383 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
384 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
385 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
386 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
389 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
391 mPanGesturePredictionMode = predictionMode;
393 int predictionAmount(-1);
394 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
396 if( predictionAmount < 0 )
398 // do not support times in the past
399 predictionAmount = 0;
401 mPanGesturePredictionAmount = predictionAmount;
403 int minPredictionAmount(-1);
404 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
406 if( minPredictionAmount < 0 )
408 // do not support times in the past
409 minPredictionAmount = 0;
411 mPanGestureMinPredictionAmount = minPredictionAmount;
413 int maxPredictionAmount(-1);
414 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
416 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
418 // maximum amount should not be smaller than minimum amount
419 maxPredictionAmount = minPredictionAmount;
421 mPanGestureMaxPredictionAmount = maxPredictionAmount;
423 int predictionAmountAdjustment(-1);
424 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
426 if( predictionAmountAdjustment < 0 )
428 // negative amount doesn't make sense
429 predictionAmountAdjustment = 0;
431 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
434 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
436 mPanGestureSmoothingMode = smoothingMode;
438 float smoothingAmount = 1.0f;
439 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
441 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
442 mPanGestureSmoothingAmount = smoothingAmount;
445 int useActualTimes( -1 );
446 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_USE_ACTUAL_TIMES, useActualTimes ) )
448 mPanGestureUseActualTimes = useActualTimes == 0 ? 0 : 1;
451 int interpolationTimeRange( -1 );
452 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, interpolationTimeRange ) )
454 if( interpolationTimeRange < 0 )
456 interpolationTimeRange = 0;
458 mPanGestureInterpolationTimeRange = interpolationTimeRange;
461 int scalarOnlyPredictionEnabled( -1 );
462 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, scalarOnlyPredictionEnabled ) )
464 mPanGestureScalarOnlyPredictionEnabled = scalarOnlyPredictionEnabled == 0 ? 0 : 1;
467 int twoPointPredictionEnabled( -1 );
468 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, twoPointPredictionEnabled ) )
470 mPanGestureTwoPointPredictionEnabled = twoPointPredictionEnabled == 0 ? 0 : 1;
473 int twoPointPastInterpolateTime( -1 );
474 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, twoPointPastInterpolateTime ) )
476 if( twoPointPastInterpolateTime < 0 )
478 twoPointPastInterpolateTime = 0;
480 mPanGestureTwoPointInterpolatePastTime = twoPointPastInterpolateTime;
483 float twoPointVelocityBias = -1.0f;
484 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, twoPointVelocityBias ) )
486 twoPointVelocityBias = Clamp( twoPointVelocityBias, 0.0f, 1.0f );
487 mPanGestureTwoPointVelocityBias = twoPointVelocityBias;
490 float twoPointAccelerationBias = -1.0f;
491 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, twoPointAccelerationBias ) )
493 twoPointAccelerationBias = Clamp( twoPointAccelerationBias, 0.0f, 1.0f );
494 mPanGestureTwoPointAccelerationBias = twoPointAccelerationBias;
497 int multitapSmoothingRange( -1 );
498 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, multitapSmoothingRange ) )
500 if( multitapSmoothingRange < 0 )
502 multitapSmoothingRange = 0;
504 mPanGestureMultitapSmoothingRange = multitapSmoothingRange;
507 int minimumDistance(-1);
508 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
510 mPanMinimumDistance = minimumDistance;
513 int minimumEvents(-1);
514 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
516 mPanMinimumEvents = minimumEvents;
519 float pinchMinimumDistance = -1.0f;
520 if( GetFloatEnvironmentVariable( DALI_ENV_PINCH_MINIMUM_DISTANCE, pinchMinimumDistance ) )
522 mPinchMinimumDistance = pinchMinimumDistance;
525 int longPressMinimumHoldingTime = -1;
526 if( GetIntegerEnvironmentVariable( DALI_ENV_LONG_PRESS_MINIMUM_HOLDING_TIME, longPressMinimumHoldingTime ) )
528 mLongPressMinimumHoldingTime = longPressMinimumHoldingTime;
532 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
534 mGlesCallTime = glesCallTime;
537 int glesCallAccumulate( 0 );
538 if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
540 mGlesCallAccumulate = glesCallAccumulate != 0;
543 int windowWidth(0), windowHeight(0);
544 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
546 mWindowWidth = windowWidth;
547 mWindowHeight = windowHeight;
550 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
553 mWindowName = windowName;
556 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
557 if ( windowClassName )
559 mWindowClassName = windowClassName;
562 int threadingMode(0);
563 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
565 switch( threadingMode )
567 case ThreadingMode::COMBINED_UPDATE_RENDER:
569 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
575 int renderRefreshRate(0);
576 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
578 // Only change it if it's valid
579 if( renderRefreshRate > 1 )
581 mRenderRefreshRate = renderRefreshRate;
585 int multiSamplingLevel( 0 );
586 if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
588 mMultiSamplingLevel = multiSamplingLevel;
591 int maxTextureSize( 0 );
592 if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
594 if( maxTextureSize > 0 )
596 mMaxTextureSize = maxTextureSize;
600 mRenderToFboInterval = GetIntegerEnvironmentVariable( DALI_RENDER_TO_FBO, 0u );
603 int depthBufferRequired( -1 );
604 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_DEPTH_BUFFER, depthBufferRequired ) )
606 if( depthBufferRequired > 0 )
608 mDepthBufferRequired = false;
609 mStencilBufferRequired = false; // Disable stencil buffer as well
613 int stencilBufferRequired( -1 );
614 if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_STENCIL_BUFFER, stencilBufferRequired ) )
616 if( stencilBufferRequired > 0 )
618 mStencilBufferRequired = false;
622 int partialUpdateRequired( -1 );
623 if( GetIntegerEnvironmentVariable( DALI_ENV_PARTIAL_UPDATE_AVAILABLE, partialUpdateRequired ) )
625 if( partialUpdateRequired > 0 )
627 mPartialUpdateAvailable = true;