2 * Copyright (c) 2015 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 "environment-options.h"
23 #include <dali/integration-api/render-controller.h>
24 #include <dali/public-api/math/math-utils.h>
27 #include <base/environment-variables.h>
40 const unsigned int DEFAULT_STATISTICS_LOG_FREQUENCY = 2;
42 unsigned int GetIntegerEnvironmentVariable( const char* variable, unsigned int defaultValue )
44 const char* variableParameter = std::getenv(variable);
46 // if the parameter exists convert it to an integer, else return the default value
47 unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
51 bool GetIntegerEnvironmentVariable( const char* variable, int& intValue )
53 const char* variableParameter = std::getenv(variable);
55 if( !variableParameter )
59 // if the parameter exists convert it to an integer, else return the default value
60 intValue = std::atoi(variableParameter);
64 bool GetFloatEnvironmentVariable( const char* variable, float& floatValue )
66 const char* variableParameter = std::getenv(variable);
68 if( !variableParameter )
72 // if the parameter exists convert it to an integer, else return the default value
73 floatValue = std::atof(variableParameter);
77 const char * GetCharEnvironmentVariable( const char * variable )
79 return std::getenv( variable );
82 } // unnamed namespace
84 EnvironmentOptions::EnvironmentOptions()
89 mUpdateStatusFrequency( 0 ),
90 mObjectProfilerInterval( 0 ),
91 mPerformanceStatsLevel( 0 ),
92 mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY ),
93 mPerformanceTimeStampOutput( 0 ),
94 mPanGestureLoggingLevel( 0 ),
95 mPanGesturePredictionMode( -1 ),
96 mPanGesturePredictionAmount( -1 ), ///< only sets value in pan gesture if greater than 0
97 mPanGestureMaxPredictionAmount( -1 ),
98 mPanGestureMinPredictionAmount( -1 ),
99 mPanGesturePredictionAmountAdjustment( -1 ),
100 mPanGestureSmoothingMode( -1 ),
101 mPanGestureSmoothingAmount( -1.0f ),
102 mPanGestureUseActualTimes( -1 ),
103 mPanGestureInterpolationTimeRange( -1 ),
104 mPanGestureScalarOnlyPredictionEnabled( -1 ),
105 mPanGestureTwoPointPredictionEnabled( -1 ),
106 mPanGestureTwoPointInterpolatePastTime( -1 ),
107 mPanGestureTwoPointVelocityBias( -1.0f ),
108 mPanGestureTwoPointAccelerationBias( -1.0f ),
109 mPanGestureMultitapSmoothingRange( -1 ),
110 mPanMinimumDistance( -1 ),
111 mPanMinimumEvents( -1 ),
115 mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
116 mRenderRefreshRate( 1 ),
117 mGlesCallAccumulate( false ),
120 ParseEnvironmentOptions();
123 EnvironmentOptions::~EnvironmentOptions()
127 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
129 mLogFunction = logFunction;
132 void EnvironmentOptions::InstallLogFunction() const
134 Dali::Integration::Log::InstallLogFunction( mLogFunction );
137 void EnvironmentOptions::UnInstallLogFunction() const
139 Dali::Integration::Log::UninstallLogFunction();
142 unsigned int EnvironmentOptions::GetNetworkControlMode() const
144 return mNetworkControl;
146 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
148 return mFpsFrequency;
151 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
153 return mUpdateStatusFrequency;
156 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
158 return mObjectProfilerInterval;
161 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
163 return mPerformanceStatsLevel;
165 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
167 return mPerformanceStatsFrequency;
169 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
171 return mPerformanceTimeStampOutput;
174 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
176 return mPanGestureLoggingLevel;
179 int EnvironmentOptions::GetPanGesturePredictionMode() const
181 return mPanGesturePredictionMode;
184 int EnvironmentOptions::GetPanGesturePredictionAmount() const
186 return mPanGesturePredictionAmount;
189 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
191 return mPanGestureMaxPredictionAmount;
194 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
196 return mPanGestureMinPredictionAmount;
199 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
201 return mPanGesturePredictionAmountAdjustment;
204 int EnvironmentOptions::GetPanGestureSmoothingMode() const
206 return mPanGestureSmoothingMode;
209 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
211 return mPanGestureSmoothingAmount;
214 int EnvironmentOptions::GetPanGestureUseActualTimes() const
216 return mPanGestureUseActualTimes;
219 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
221 return mPanGestureInterpolationTimeRange;
224 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
226 return mPanGestureScalarOnlyPredictionEnabled;
229 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
231 return mPanGestureTwoPointPredictionEnabled;
234 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
236 return mPanGestureTwoPointInterpolatePastTime;
239 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
241 return mPanGestureTwoPointVelocityBias;
244 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
246 return mPanGestureTwoPointAccelerationBias;
249 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
251 return mPanGestureMultitapSmoothingRange;
254 int EnvironmentOptions::GetMinimumPanDistance() const
256 return mPanMinimumDistance;
259 int EnvironmentOptions::GetMinimumPanEvents() const
261 return mPanMinimumEvents;
264 unsigned int EnvironmentOptions::GetWindowWidth() const
269 unsigned int EnvironmentOptions::GetWindowHeight() const
271 return mWindowHeight;
274 int EnvironmentOptions::GetGlesCallTime() const
276 return mGlesCallTime;
279 bool EnvironmentOptions::GetGlesCallAccumulate() const
281 return mGlesCallAccumulate;
284 const std::string& EnvironmentOptions::GetWindowName() const
289 const std::string& EnvironmentOptions::GetWindowClassName() const
291 return mWindowClassName;
294 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
296 return mThreadingMode;
299 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
301 return mRenderRefreshRate;
304 bool EnvironmentOptions::PerformanceServerRequired() const
306 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
307 ( GetPerformanceTimeStampOutput() > 0 ) ||
308 ( GetNetworkControlMode() > 0) );
311 void EnvironmentOptions::ParseEnvironmentOptions()
313 // get logging options
314 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
315 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
316 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
317 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
318 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
319 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
320 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
321 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
324 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
326 mPanGesturePredictionMode = predictionMode;
328 int predictionAmount(-1);
329 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
331 if( predictionAmount < 0 )
333 // do not support times in the past
334 predictionAmount = 0;
336 mPanGesturePredictionAmount = predictionAmount;
338 int minPredictionAmount(-1);
339 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
341 if( minPredictionAmount < 0 )
343 // do not support times in the past
344 minPredictionAmount = 0;
346 mPanGestureMinPredictionAmount = minPredictionAmount;
348 int maxPredictionAmount(-1);
349 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
351 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
353 // maximum amount should not be smaller than minimum amount
354 maxPredictionAmount = minPredictionAmount;
356 mPanGestureMaxPredictionAmount = maxPredictionAmount;
358 int predictionAmountAdjustment(-1);
359 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
361 if( predictionAmountAdjustment < 0 )
363 // negative amount doesn't make sense
364 predictionAmountAdjustment = 0;
366 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
369 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
371 mPanGestureSmoothingMode = smoothingMode;
373 float smoothingAmount = 1.0f;
374 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
376 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
377 mPanGestureSmoothingAmount = smoothingAmount;
380 int useActualTimes( -1 );
381 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_USE_ACTUAL_TIMES, useActualTimes ) )
383 mPanGestureUseActualTimes = useActualTimes == 0 ? 0 : 1;
386 int interpolationTimeRange( -1 );
387 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, interpolationTimeRange ) )
389 if( interpolationTimeRange < 0 )
391 interpolationTimeRange = 0;
393 mPanGestureInterpolationTimeRange = interpolationTimeRange;
396 int scalarOnlyPredictionEnabled( -1 );
397 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, scalarOnlyPredictionEnabled ) )
399 mPanGestureScalarOnlyPredictionEnabled = scalarOnlyPredictionEnabled == 0 ? 0 : 1;
402 int twoPointPredictionEnabled( -1 );
403 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, twoPointPredictionEnabled ) )
405 mPanGestureTwoPointPredictionEnabled = twoPointPredictionEnabled == 0 ? 0 : 1;
408 int twoPointPastInterpolateTime( -1 );
409 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, twoPointPastInterpolateTime ) )
411 if( twoPointPastInterpolateTime < 0 )
413 twoPointPastInterpolateTime = 0;
415 mPanGestureTwoPointInterpolatePastTime = twoPointPastInterpolateTime;
418 float twoPointVelocityBias = -1.0f;
419 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, twoPointVelocityBias ) )
421 twoPointVelocityBias = Clamp( twoPointVelocityBias, 0.0f, 1.0f );
422 mPanGestureTwoPointVelocityBias = twoPointVelocityBias;
425 float twoPointAccelerationBias = -1.0f;
426 if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, twoPointAccelerationBias ) )
428 twoPointAccelerationBias = Clamp( twoPointAccelerationBias, 0.0f, 1.0f );
429 mPanGestureTwoPointAccelerationBias = twoPointAccelerationBias;
432 int multitapSmoothingRange( -1 );
433 if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, multitapSmoothingRange ) )
435 if( multitapSmoothingRange < 0 )
437 multitapSmoothingRange = 0;
439 mPanGestureMultitapSmoothingRange = multitapSmoothingRange;
442 int minimumDistance(-1);
443 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
445 mPanMinimumDistance = minimumDistance;
448 int minimumEvents(-1);
449 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
451 mPanMinimumEvents = minimumEvents;
455 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
457 mGlesCallTime = glesCallTime;
460 int glesCallAccumulate( 0 );
461 if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
463 mGlesCallAccumulate = glesCallAccumulate != 0;
466 int windowWidth(0), windowHeight(0);
467 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
469 mWindowWidth = windowWidth;
470 mWindowHeight = windowHeight;
473 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
476 mWindowName = windowName;
479 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
480 if ( windowClassName )
482 mWindowClassName = windowClassName;
485 int threadingMode(0);
486 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
488 switch( threadingMode )
490 case ThreadingMode::SEPARATE_UPDATE_RENDER:
491 case ThreadingMode::COMBINED_UPDATE_RENDER:
492 case ThreadingMode::SINGLE_THREADED:
494 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
500 int renderRefreshRate(0);
501 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
503 // Only change it if it's valid
504 if( renderRefreshRate > 1 )
506 mRenderRefreshRate = renderRefreshRate;