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 mPerformanceStatsLevel(0),
91 mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY),
92 mPerformanceTimeStampOutput(0),
93 mPanGestureLoggingLevel(0),
94 mPanGesturePredictionMode(-1),
95 mPanGesturePredictionAmount(-1), ///< only sets value in pan gesture if greater than 0
96 mPanGestureMaxPredictionAmount(-1),
97 mPanGestureMinPredictionAmount(-1),
98 mPanGesturePredictionAmountAdjustment(-1),
99 mPanGestureSmoothingMode(-1),
100 mPanGestureSmoothingAmount(-1.0f),
101 mPanMinimumDistance(-1),
102 mPanMinimumEvents(-1),
107 ParseEnvironmentOptions();
110 EnvironmentOptions::~EnvironmentOptions()
114 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
116 mLogFunction = logFunction;
119 void EnvironmentOptions::InstallLogFunction() const
121 Dali::Integration::Log::InstallLogFunction( mLogFunction );
124 void EnvironmentOptions::UnInstallLogFunction() const
126 Dali::Integration::Log::UninstallLogFunction();
129 unsigned int EnvironmentOptions::GetNetworkControlMode() const
131 return mNetworkControl;
133 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
135 return mFpsFrequency;
138 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
140 return mUpdateStatusFrequency;
143 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
145 return mPerformanceStatsLevel;
147 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
149 return mPerformanceStatsFrequency;
151 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
153 return mPerformanceTimeStampOutput;
156 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
158 return mPanGestureLoggingLevel;
161 int EnvironmentOptions::GetPanGesturePredictionMode() const
163 return mPanGesturePredictionMode;
166 int EnvironmentOptions::GetPanGesturePredictionAmount() const
168 return mPanGesturePredictionAmount;
171 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
173 return mPanGestureMaxPredictionAmount;
176 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
178 return mPanGestureMinPredictionAmount;
181 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
183 return mPanGesturePredictionAmountAdjustment;
186 int EnvironmentOptions::GetPanGestureSmoothingMode() const
188 return mPanGestureSmoothingMode;
191 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
193 return mPanGestureSmoothingAmount;
196 int EnvironmentOptions::GetMinimumPanDistance() const
198 return mPanMinimumDistance;
201 int EnvironmentOptions::GetMinimumPanEvents() const
203 return mPanMinimumEvents;
206 unsigned int EnvironmentOptions::GetWindowWidth() const
211 unsigned int EnvironmentOptions::GetWindowHeight() const
213 return mWindowHeight;
216 int EnvironmentOptions::GetGlesCallTime() const
218 return mGlesCallTime;
221 const std::string& EnvironmentOptions::GetWindowName() const
226 const std::string& EnvironmentOptions::GetWindowClassName() const
228 return mWindowClassName;
231 bool EnvironmentOptions::PerformanceServerRequired() const
233 return ( (GetPerformanceStatsLoggingOptions() > 0) ||
234 ( GetPerformanceTimeStampOutput() > 0 ) ||
235 ( GetNetworkControlMode() > 0) );
238 void EnvironmentOptions::ParseEnvironmentOptions()
240 // get logging options
241 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
242 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
243 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
244 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
245 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
246 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
247 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
250 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
252 mPanGesturePredictionMode = predictionMode;
254 int predictionAmount(-1);
255 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
257 if( predictionAmount < 0 )
259 // do not support times in the past
260 predictionAmount = 0;
262 mPanGesturePredictionAmount = predictionAmount;
264 int minPredictionAmount(-1);
265 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
267 if( minPredictionAmount < 0 )
269 // do not support times in the past
270 minPredictionAmount = 0;
272 mPanGestureMinPredictionAmount = minPredictionAmount;
274 int maxPredictionAmount(-1);
275 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
277 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
279 // maximum amount should not be smaller than minimum amount
280 maxPredictionAmount = minPredictionAmount;
282 mPanGestureMaxPredictionAmount = maxPredictionAmount;
284 int predictionAmountAdjustment(-1);
285 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
287 if( predictionAmountAdjustment < 0 )
289 // negative amount doesn't make sense
290 predictionAmountAdjustment = 0;
292 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
295 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
297 mPanGestureSmoothingMode = smoothingMode;
299 float smoothingAmount = 1.0f;
300 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
302 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
303 mPanGestureSmoothingAmount = smoothingAmount;
306 int minimumDistance(-1);
307 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
309 mPanMinimumDistance = minimumDistance;
312 int minimumEvents(-1);
313 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
315 mPanMinimumEvents = minimumEvents;
319 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
321 mGlesCallTime = glesCallTime;
324 int windowWidth(0), windowHeight(0);
325 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
327 mWindowWidth = windowWidth;
328 mWindowHeight = windowHeight;
331 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
334 mWindowName = windowName;
337 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
338 if ( windowClassName )
340 mWindowClassName = windowClassName;