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()
88 mUpdateStatusFrequency(0),
89 mPerformanceStatsLevel(0),
90 mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY),
91 mPerformanceTimeStampOutput(0),
92 mPanGestureLoggingLevel(0),
93 mPanGesturePredictionMode(-1),
94 mPanGesturePredictionAmount(-1), ///< only sets value in pan gesture if greater than 0
95 mPanGestureMaxPredictionAmount(-1),
96 mPanGestureMinPredictionAmount(-1),
97 mPanGesturePredictionAmountAdjustment(-1),
98 mPanGestureSmoothingMode(-1),
99 mPanGestureSmoothingAmount(-1.0f),
100 mPanMinimumDistance(-1),
101 mPanMinimumEvents(-1),
106 ParseEnvironmentOptions();
109 EnvironmentOptions::~EnvironmentOptions()
113 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
115 mLogFunction = logFunction;
118 void EnvironmentOptions::InstallLogFunction() const
120 Dali::Integration::Log::InstallLogFunction( mLogFunction );
123 void EnvironmentOptions::UnInstallLogFunction() const
125 Dali::Integration::Log::UninstallLogFunction();
128 unsigned int EnvironmentOptions::GetNetworkControlMode() const
130 return mNetworkControl;
132 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
134 return mFpsFrequency;
137 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
139 return mUpdateStatusFrequency;
142 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
144 return mPerformanceStatsLevel;
146 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
148 return mPerformanceStatsFrequency;
150 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
152 return mPerformanceTimeStampOutput;
155 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
157 return mPanGestureLoggingLevel;
160 int EnvironmentOptions::GetPanGesturePredictionMode() const
162 return mPanGesturePredictionMode;
165 int EnvironmentOptions::GetPanGesturePredictionAmount() const
167 return mPanGesturePredictionAmount;
170 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
172 return mPanGestureMaxPredictionAmount;
175 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
177 return mPanGestureMinPredictionAmount;
180 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
182 return mPanGesturePredictionAmountAdjustment;
185 int EnvironmentOptions::GetPanGestureSmoothingMode() const
187 return mPanGestureSmoothingMode;
190 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
192 return mPanGestureSmoothingAmount;
195 int EnvironmentOptions::GetMinimumPanDistance() const
197 return mPanMinimumDistance;
200 int EnvironmentOptions::GetMinimumPanEvents() const
202 return mPanMinimumEvents;
205 unsigned int EnvironmentOptions::GetWindowWidth() const
210 unsigned int EnvironmentOptions::GetWindowHeight() const
212 return mWindowHeight;
215 void EnvironmentOptions::SetPanGesturePredictionMode( unsigned int mode )
217 mPanGesturePredictionMode = mode;
220 void EnvironmentOptions::SetPanGesturePredictionAmount( unsigned int amount )
222 mPanGesturePredictionAmount = amount;
225 void EnvironmentOptions::SetPanGestureMaximumPredictionAmount( unsigned int amount )
227 mPanGestureMaxPredictionAmount = amount;
230 void EnvironmentOptions::SetPanGestureMinimumPredictionAmount( unsigned int amount )
232 mPanGestureMinPredictionAmount = amount;
235 void EnvironmentOptions::SetPanGesturePredictionAmountAdjustment( unsigned int amount )
237 mPanGesturePredictionAmountAdjustment = amount;
240 void EnvironmentOptions::SetPanGestureSmoothingMode( unsigned int mode )
242 mPanGestureSmoothingMode = mode;
245 void EnvironmentOptions::SetPanGestureSmoothingAmount( float amount )
247 mPanGestureSmoothingAmount = amount;
250 void EnvironmentOptions::SetMinimumPanDistance( int distance )
252 mPanMinimumDistance = distance;
255 void EnvironmentOptions::SetMinimumPanEvents( int events )
257 mPanMinimumEvents = events;
260 void EnvironmentOptions::SetGlesCallTime( int time )
262 mGlesCallTime = time;
265 int EnvironmentOptions::GetGlesCallTime() const
267 return mGlesCallTime;
270 void EnvironmentOptions::SetWindowWidth( int width )
272 mWindowWidth = width;
275 void EnvironmentOptions::SetWindowHeight( int height )
277 mWindowHeight = height;
280 void EnvironmentOptions::SetWindowName( const char * name )
288 const std::string& EnvironmentOptions::GetWindowName() const
293 bool EnvironmentOptions::PerformanceServerRequired() const
295 return ( (GetPerformanceStatsLoggingOptions() > 0) ||
296 ( GetPerformanceTimeStampOutput() > 0 ) ||
297 ( GetNetworkControlMode() > 0) );
300 void EnvironmentOptions::ParseEnvironmentOptions()
302 // get logging options
303 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
304 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
305 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
306 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
307 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
308 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
309 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
312 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
314 SetPanGesturePredictionMode(predictionMode);
316 int predictionAmount(-1);
317 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
319 if( predictionAmount < 0 )
321 // do not support times in the past
322 predictionAmount = 0;
324 SetPanGesturePredictionAmount(predictionAmount);
326 int minPredictionAmount(-1);
327 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
329 if( minPredictionAmount < 0 )
331 // do not support times in the past
332 minPredictionAmount = 0;
334 SetPanGestureMinimumPredictionAmount(minPredictionAmount);
336 int maxPredictionAmount(-1);
337 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
339 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
341 // maximum amount should not be smaller than minimum amount
342 maxPredictionAmount = minPredictionAmount;
344 SetPanGestureMaximumPredictionAmount(maxPredictionAmount);
346 int predictionAmountAdjustment(-1);
347 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
349 if( predictionAmountAdjustment < 0 )
351 // negative amount doesn't make sense
352 predictionAmountAdjustment = 0;
354 SetPanGesturePredictionAmountAdjustment(predictionAmountAdjustment);
357 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
359 SetPanGestureSmoothingMode(smoothingMode);
361 float smoothingAmount = 1.0f;
362 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
364 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
365 SetPanGestureSmoothingAmount(smoothingAmount);
368 int minimumDistance(-1);
369 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
371 SetMinimumPanDistance( minimumDistance );
374 int minimumEvents(-1);
375 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
377 SetMinimumPanEvents( minimumEvents );
381 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
383 SetGlesCallTime( glesCallTime );
386 int windowWidth(0), windowHeight(0);
387 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
389 SetWindowWidth( windowWidth );
390 SetWindowHeight( windowHeight );
393 SetWindowName( GetCharEnvironmentVariable( DALI_WINDOW_NAME ) );