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 mPanMinimumDistance(-1),
103 mPanMinimumEvents(-1),
108 ParseEnvironmentOptions();
111 EnvironmentOptions::~EnvironmentOptions()
115 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
117 mLogFunction = logFunction;
120 void EnvironmentOptions::InstallLogFunction() const
122 Dali::Integration::Log::InstallLogFunction( mLogFunction );
125 void EnvironmentOptions::UnInstallLogFunction() const
127 Dali::Integration::Log::UninstallLogFunction();
130 unsigned int EnvironmentOptions::GetNetworkControlMode() const
132 return mNetworkControl;
134 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
136 return mFpsFrequency;
139 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
141 return mUpdateStatusFrequency;
144 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
146 return mObjectProfilerInterval;
149 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
151 return mPerformanceStatsLevel;
153 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
155 return mPerformanceStatsFrequency;
157 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
159 return mPerformanceTimeStampOutput;
162 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
164 return mPanGestureLoggingLevel;
167 int EnvironmentOptions::GetPanGesturePredictionMode() const
169 return mPanGesturePredictionMode;
172 int EnvironmentOptions::GetPanGesturePredictionAmount() const
174 return mPanGesturePredictionAmount;
177 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
179 return mPanGestureMaxPredictionAmount;
182 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
184 return mPanGestureMinPredictionAmount;
187 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
189 return mPanGesturePredictionAmountAdjustment;
192 int EnvironmentOptions::GetPanGestureSmoothingMode() const
194 return mPanGestureSmoothingMode;
197 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
199 return mPanGestureSmoothingAmount;
202 int EnvironmentOptions::GetMinimumPanDistance() const
204 return mPanMinimumDistance;
207 int EnvironmentOptions::GetMinimumPanEvents() const
209 return mPanMinimumEvents;
212 unsigned int EnvironmentOptions::GetWindowWidth() const
217 unsigned int EnvironmentOptions::GetWindowHeight() const
219 return mWindowHeight;
222 int EnvironmentOptions::GetGlesCallTime() const
224 return mGlesCallTime;
227 const std::string& EnvironmentOptions::GetWindowName() const
232 const std::string& EnvironmentOptions::GetWindowClassName() const
234 return mWindowClassName;
237 bool EnvironmentOptions::PerformanceServerRequired() const
239 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
240 ( GetPerformanceTimeStampOutput() > 0 ) ||
241 ( GetNetworkControlMode() > 0) );
244 void EnvironmentOptions::ParseEnvironmentOptions()
246 // get logging options
247 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
248 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
249 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
250 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
251 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
252 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
253 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
254 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
257 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
259 mPanGesturePredictionMode = predictionMode;
261 int predictionAmount(-1);
262 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
264 if( predictionAmount < 0 )
266 // do not support times in the past
267 predictionAmount = 0;
269 mPanGesturePredictionAmount = predictionAmount;
271 int minPredictionAmount(-1);
272 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
274 if( minPredictionAmount < 0 )
276 // do not support times in the past
277 minPredictionAmount = 0;
279 mPanGestureMinPredictionAmount = minPredictionAmount;
281 int maxPredictionAmount(-1);
282 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
284 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
286 // maximum amount should not be smaller than minimum amount
287 maxPredictionAmount = minPredictionAmount;
289 mPanGestureMaxPredictionAmount = maxPredictionAmount;
291 int predictionAmountAdjustment(-1);
292 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
294 if( predictionAmountAdjustment < 0 )
296 // negative amount doesn't make sense
297 predictionAmountAdjustment = 0;
299 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
302 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
304 mPanGestureSmoothingMode = smoothingMode;
306 float smoothingAmount = 1.0f;
307 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
309 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
310 mPanGestureSmoothingAmount = smoothingAmount;
313 int minimumDistance(-1);
314 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
316 mPanMinimumDistance = minimumDistance;
319 int minimumEvents(-1);
320 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
322 mPanMinimumEvents = minimumEvents;
326 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
328 mGlesCallTime = glesCallTime;
331 int windowWidth(0), windowHeight(0);
332 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
334 mWindowWidth = windowWidth;
335 mWindowHeight = windowHeight;
338 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
341 mWindowName = windowName;
344 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
345 if ( windowClassName )
347 mWindowClassName = windowClassName;