2 * Copyright (c) 2020 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>
24 #include <dali/integration-api/render-controller.h>
25 #include <dali/public-api/math/math-utils.h>
28 #include <dali/internal/trace/common/trace-factory.h>
29 #include <dali/internal/system/common/environment-variables.h>
42 const unsigned int DEFAULT_STATISTICS_LOG_FREQUENCY = 2;
43 const int DEFAULT_MULTI_SAMPLING_LEVEL = -1;
44 const bool DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING = true;
45 const bool DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING = true;
46 const bool DEFAULT_PARTIAL_UPDATE_REQUIRED_SETTING = true;
48 unsigned int GetEnvironmentVariable( const char* variable, unsigned int defaultValue )
50 const char* variableParameter = std::getenv(variable);
52 // if the parameter exists convert it to an integer, else return the default value
53 unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
57 bool GetEnvironmentVariable( const char* variable, int& intValue )
59 const char* variableParameter = std::getenv(variable);
61 if( !variableParameter )
65 // if the parameter exists convert it to an integer, else return the default value
66 intValue = std::atoi(variableParameter);
70 bool GetEnvironmentVariable( const char* variable, float& floatValue )
72 const char* variableParameter = std::getenv(variable);
74 if( !variableParameter )
78 // if the parameter exists convert it to an integer, else return the default value
79 floatValue = std::atof(variableParameter);
83 void SetFromEnvironmentVariable(const char* variable, std::string& stringValue)
85 const char * charValue = std::getenv( variable );
88 stringValue = charValue;
92 template<typename Type>
93 void SetFromEnvironmentVariable(const char* variable, Type& memberVariable)
95 Type envVarValue = -1;
96 if(GetEnvironmentVariable(variable, envVarValue))
98 memberVariable = envVarValue;
102 template<typename Type>
103 void SetFromEnvironmentVariable(const char* variable, std::function<void(Type)> function)
105 Type envVarValue = -1;
106 if(GetEnvironmentVariable(variable, envVarValue))
108 function(envVarValue);
112 /// Provides a functor which ensures a non-negative number is set for the given member variable
115 MinimumZero(int& memberValue)
116 : mMemberValue(memberValue)
120 void operator()(int value)
122 // Negative Amounts do not make sense
123 mMemberValue = std::max(0, value);
129 /// Provides a functor which clamps the environment variable between 0.0f and 1.0f
130 struct ClampBetweenZeroAndOne
132 ClampBetweenZeroAndOne(float& memberValue)
133 : mMemberValue(memberValue)
137 void operator()(float value)
139 value = Clamp(value, 0.0f, 1.0f);
140 mMemberValue = value;
146 /// Provides a functor which only sets the member variable if the environment variable value is greater than the specified constant
149 GreaterThan(unsigned int& memberValue, int greaterThanValue)
150 : mMemberValue(memberValue),
151 mGreaterThanValue(greaterThanValue)
155 void operator()(int value)
157 if(value > mGreaterThanValue)
159 mMemberValue = value;
163 unsigned int& mMemberValue;
164 const int mGreaterThanValue;
167 /// Provides a functor which sets the member to 1 if if the environment variable value is not zero
168 struct EnableIfNonZero
170 EnableIfNonZero(int& memberValue) : mMemberValue(memberValue) {}
172 void operator()(int value)
174 mMemberValue = ( value == 0 ) ? 0 : 1;
180 /// Provides a functor which sets the member to false if the environment variable value is not zero
181 struct DisableIfNonZero
183 DisableIfNonZero(bool& memberValue) : mMemberValue(memberValue) {}
185 void operator()(int value)
189 mMemberValue = false;
197 } // unnamed namespace
199 EnvironmentOptions::EnvironmentOptions()
200 : mLogFunction( NULL ),
203 mNetworkControl( 0 ),
205 mUpdateStatusFrequency( 0 ),
206 mObjectProfilerInterval( 0 ),
207 mPerformanceStatsLevel( 0 ),
208 mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY ),
209 mPerformanceTimeStampOutput( 0 ),
210 mPanGestureLoggingLevel( 0 ),
213 mRenderRefreshRate( 1u ),
214 mMaxTextureSize( 0 ),
215 mRenderToFboInterval( 0u ),
216 mPanGesturePredictionMode( -1 ),
217 mPanGesturePredictionAmount( -1 ), ///< only sets value in pan gesture if greater than 0
218 mPanGestureMaxPredictionAmount( -1 ),
219 mPanGestureMinPredictionAmount( -1 ),
220 mPanGesturePredictionAmountAdjustment( -1 ),
221 mPanGestureSmoothingMode( -1 ),
222 mPanGestureSmoothingAmount( -1.0f ),
223 mPanGestureUseActualTimes( -1 ),
224 mPanGestureInterpolationTimeRange( -1 ),
225 mPanGestureScalarOnlyPredictionEnabled( -1 ),
226 mPanGestureTwoPointPredictionEnabled( -1 ),
227 mPanGestureTwoPointInterpolatePastTime( -1 ),
228 mPanGestureTwoPointVelocityBias( -1.0f ),
229 mPanGestureTwoPointAccelerationBias( -1.0f ),
230 mPanGestureMultitapSmoothingRange( -1 ),
231 mPanMinimumDistance( -1 ),
232 mPanMinimumEvents( -1 ),
233 mPinchMinimumDistance( -1.0f ),
234 mPinchMinimumTouchEvents( -1 ),
235 mPinchMinimumTouchEventsAfterStart( -1 ),
236 mRotationMinimumTouchEvents( -1 ),
237 mRotationMinimumTouchEventsAfterStart( -1 ),
238 mLongPressMinimumHoldingTime( -1 ),
240 mMultiSamplingLevel( DEFAULT_MULTI_SAMPLING_LEVEL ),
241 mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
242 mGlesCallAccumulate( false ),
243 mDepthBufferRequired( DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING ),
244 mStencilBufferRequired( DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING ),
245 mPartialUpdateRequired( DEFAULT_PARTIAL_UPDATE_REQUIRED_SETTING )
247 ParseEnvironmentOptions();
250 EnvironmentOptions::~EnvironmentOptions()
254 void EnvironmentOptions::CreateTraceManager( PerformanceInterface* performanceInterface )
256 mTraceManager = TraceManagerFactory::CreateTraceFactory( performanceInterface );
259 void EnvironmentOptions::InstallTraceFunction() const
263 mTraceManager->Initialise();
267 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
269 mLogFunction = logFunction;
272 void EnvironmentOptions::InstallLogFunction() const
274 Dali::Integration::Log::InstallLogFunction( mLogFunction );
277 void EnvironmentOptions::UnInstallLogFunction() const
279 Dali::Integration::Log::UninstallLogFunction();
282 unsigned int EnvironmentOptions::GetNetworkControlMode() const
284 return mNetworkControl;
286 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
288 return mFpsFrequency;
291 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
293 return mUpdateStatusFrequency;
296 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
298 return mObjectProfilerInterval;
301 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
303 return mPerformanceStatsLevel;
305 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
307 return mPerformanceStatsFrequency;
309 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
311 return mPerformanceTimeStampOutput;
314 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
316 return mPanGestureLoggingLevel;
319 int EnvironmentOptions::GetPanGesturePredictionMode() const
321 return mPanGesturePredictionMode;
324 int EnvironmentOptions::GetPanGesturePredictionAmount() const
326 return mPanGesturePredictionAmount;
329 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
331 return mPanGestureMaxPredictionAmount;
334 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
336 return mPanGestureMinPredictionAmount;
339 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
341 return mPanGesturePredictionAmountAdjustment;
344 int EnvironmentOptions::GetPanGestureSmoothingMode() const
346 return mPanGestureSmoothingMode;
349 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
351 return mPanGestureSmoothingAmount;
354 int EnvironmentOptions::GetPanGestureUseActualTimes() const
356 return mPanGestureUseActualTimes;
359 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
361 return mPanGestureInterpolationTimeRange;
364 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
366 return mPanGestureScalarOnlyPredictionEnabled;
369 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
371 return mPanGestureTwoPointPredictionEnabled;
374 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
376 return mPanGestureTwoPointInterpolatePastTime;
379 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
381 return mPanGestureTwoPointVelocityBias;
384 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
386 return mPanGestureTwoPointAccelerationBias;
389 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
391 return mPanGestureMultitapSmoothingRange;
394 int EnvironmentOptions::GetMinimumPanDistance() const
396 return mPanMinimumDistance;
399 int EnvironmentOptions::GetMinimumPanEvents() const
401 return mPanMinimumEvents;
404 float EnvironmentOptions::GetMinimumPinchDistance() const
406 return mPinchMinimumDistance;
409 int EnvironmentOptions::GetMinimumPinchTouchEvents() const
411 return mPinchMinimumTouchEvents;
414 int EnvironmentOptions::GetMinimumPinchTouchEventsAfterStart() const
416 return mPinchMinimumTouchEventsAfterStart;
419 int EnvironmentOptions::GetMinimumRotationTouchEvents() const
421 return mRotationMinimumTouchEvents;
424 int EnvironmentOptions::GetMinimumRotationTouchEventsAfterStart() const
426 return mRotationMinimumTouchEventsAfterStart;
429 int EnvironmentOptions::GetLongPressMinimumHoldingTime() const
431 return mLongPressMinimumHoldingTime;
434 unsigned int EnvironmentOptions::GetWindowWidth() const
439 unsigned int EnvironmentOptions::GetWindowHeight() const
441 return mWindowHeight;
444 int EnvironmentOptions::GetGlesCallTime() const
446 return mGlesCallTime;
449 bool EnvironmentOptions::GetGlesCallAccumulate() const
451 return mGlesCallAccumulate;
454 const std::string& EnvironmentOptions::GetWindowName() const
459 const std::string& EnvironmentOptions::GetWindowClassName() const
461 return mWindowClassName;
464 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
466 return mThreadingMode;
469 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
471 return mRenderRefreshRate;
474 int EnvironmentOptions::GetMultiSamplingLevel() const
476 return mMultiSamplingLevel;
479 unsigned int EnvironmentOptions::GetMaxTextureSize() const
481 return mMaxTextureSize;
484 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
486 return mRenderToFboInterval;
489 bool EnvironmentOptions::PerformanceServerRequired() const
491 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
492 ( GetPerformanceTimeStampOutput() > 0 ) ||
493 ( GetNetworkControlMode() > 0) );
496 bool EnvironmentOptions::DepthBufferRequired() const
498 return mDepthBufferRequired;
501 bool EnvironmentOptions::StencilBufferRequired() const
503 return mStencilBufferRequired;
506 bool EnvironmentOptions::PartialUpdateRequired() const
508 return mPartialUpdateRequired;
511 void EnvironmentOptions::ParseEnvironmentOptions()
513 // get logging options
514 mFpsFrequency = GetEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
515 mUpdateStatusFrequency = GetEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
516 mObjectProfilerInterval = GetEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
517 mPerformanceStatsLevel = GetEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
518 mPerformanceStatsFrequency = GetEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
519 mPerformanceTimeStampOutput = GetEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
520 mNetworkControl = GetEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
521 mPanGestureLoggingLevel = GetEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
523 SetFromEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, mPanGesturePredictionMode);
524 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_PREDICTION_AMOUNT, MinimumZero(mPanGesturePredictionAmount));
525 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, MinimumZero(mPanGestureMinPredictionAmount));
526 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT,
527 [&](int maxPredictionAmount)
529 if( mPanGestureMinPredictionAmount > -1 && maxPredictionAmount < mPanGestureMinPredictionAmount )
531 // maximum amount should not be smaller than minimum amount
532 maxPredictionAmount = mPanGestureMinPredictionAmount;
534 mPanGestureMaxPredictionAmount = maxPredictionAmount;
536 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, MinimumZero(mPanGesturePredictionAmountAdjustment));
537 SetFromEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, mPanGestureSmoothingMode);
538 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_SMOOTHING_AMOUNT, ClampBetweenZeroAndOne(mPanGestureSmoothingAmount));
539 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_USE_ACTUAL_TIMES, EnableIfNonZero(mPanGestureUseActualTimes));
540 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, MinimumZero(mPanGestureInterpolationTimeRange));
541 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, EnableIfNonZero(mPanGestureScalarOnlyPredictionEnabled));
542 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, EnableIfNonZero(mPanGestureTwoPointPredictionEnabled));
543 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, MinimumZero(mPanGestureTwoPointInterpolatePastTime));
544 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, ClampBetweenZeroAndOne(mPanGestureTwoPointVelocityBias));
545 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, ClampBetweenZeroAndOne(mPanGestureTwoPointAccelerationBias));
546 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, MinimumZero(mPanGestureMultitapSmoothingRange));
547 SetFromEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, mPanMinimumDistance);
548 SetFromEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, mPanMinimumEvents);
550 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_DISTANCE, mPinchMinimumDistance);
551 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS, mPinchMinimumTouchEvents);
552 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS_AFTER_START, mPinchMinimumTouchEventsAfterStart);
554 SetFromEnvironmentVariable(DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS, mRotationMinimumTouchEvents);
555 SetFromEnvironmentVariable(DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS_AFTER_START, mRotationMinimumTouchEventsAfterStart);
557 SetFromEnvironmentVariable(DALI_ENV_LONG_PRESS_MINIMUM_HOLDING_TIME, mLongPressMinimumHoldingTime);
559 SetFromEnvironmentVariable(DALI_GLES_CALL_TIME, mGlesCallTime);
560 SetFromEnvironmentVariable<int>(DALI_GLES_CALL_ACCUMULATE, [&](int glesCallAccumulate) { mGlesCallAccumulate = glesCallAccumulate != 0; });
562 int windowWidth(0), windowHeight(0);
563 if ( GetEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
565 mWindowWidth = windowWidth;
566 mWindowHeight = windowHeight;
568 SetFromEnvironmentVariable(DALI_WINDOW_NAME, mWindowName );
569 SetFromEnvironmentVariable(DALI_WINDOW_CLASS_NAME, mWindowClassName);
571 SetFromEnvironmentVariable<int>(DALI_THREADING_MODE,
572 [&](int threadingMode)
574 switch( threadingMode )
576 case ThreadingMode::COMBINED_UPDATE_RENDER:
578 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
584 SetFromEnvironmentVariable<int>(DALI_REFRESH_RATE, GreaterThan(mRenderRefreshRate, 1));
586 SetFromEnvironmentVariable(DALI_ENV_MULTI_SAMPLING_LEVEL, mMultiSamplingLevel);
588 SetFromEnvironmentVariable<int>(DALI_ENV_MAX_TEXTURE_SIZE, GreaterThan(mMaxTextureSize, 0));
590 mRenderToFboInterval = GetEnvironmentVariable( DALI_RENDER_TO_FBO, 0u );
592 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_DEPTH_BUFFER,
593 [&](int depthBufferRequired)
595 if( depthBufferRequired > 0 )
597 mDepthBufferRequired = false;
598 mStencilBufferRequired = false; // Disable stencil buffer as well
601 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_STENCIL_BUFFER, DisableIfNonZero(mStencilBufferRequired));
603 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_PARTIAL_UPDATE, DisableIfNonZero(mPartialUpdateRequired));