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),
107 mThreadingMode( ThreadingMode::SEPARATE_UPDATE_RENDER ),
110 ParseEnvironmentOptions();
113 EnvironmentOptions::~EnvironmentOptions()
117 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
119 mLogFunction = logFunction;
122 void EnvironmentOptions::InstallLogFunction() const
124 Dali::Integration::Log::InstallLogFunction( mLogFunction );
127 void EnvironmentOptions::UnInstallLogFunction() const
129 Dali::Integration::Log::UninstallLogFunction();
132 unsigned int EnvironmentOptions::GetNetworkControlMode() const
134 return mNetworkControl;
136 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
138 return mFpsFrequency;
141 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
143 return mUpdateStatusFrequency;
146 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
148 return mObjectProfilerInterval;
151 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
153 return mPerformanceStatsLevel;
155 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
157 return mPerformanceStatsFrequency;
159 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
161 return mPerformanceTimeStampOutput;
164 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
166 return mPanGestureLoggingLevel;
169 int EnvironmentOptions::GetPanGesturePredictionMode() const
171 return mPanGesturePredictionMode;
174 int EnvironmentOptions::GetPanGesturePredictionAmount() const
176 return mPanGesturePredictionAmount;
179 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
181 return mPanGestureMaxPredictionAmount;
184 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
186 return mPanGestureMinPredictionAmount;
189 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
191 return mPanGesturePredictionAmountAdjustment;
194 int EnvironmentOptions::GetPanGestureSmoothingMode() const
196 return mPanGestureSmoothingMode;
199 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
201 return mPanGestureSmoothingAmount;
204 int EnvironmentOptions::GetMinimumPanDistance() const
206 return mPanMinimumDistance;
209 int EnvironmentOptions::GetMinimumPanEvents() const
211 return mPanMinimumEvents;
214 unsigned int EnvironmentOptions::GetWindowWidth() const
219 unsigned int EnvironmentOptions::GetWindowHeight() const
221 return mWindowHeight;
224 int EnvironmentOptions::GetGlesCallTime() const
226 return mGlesCallTime;
229 const std::string& EnvironmentOptions::GetWindowName() const
234 const std::string& EnvironmentOptions::GetWindowClassName() const
236 return mWindowClassName;
239 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
241 return mThreadingMode;
244 bool EnvironmentOptions::PerformanceServerRequired() const
246 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
247 ( GetPerformanceTimeStampOutput() > 0 ) ||
248 ( GetNetworkControlMode() > 0) );
251 void EnvironmentOptions::ParseEnvironmentOptions()
253 // get logging options
254 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
255 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
256 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
257 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
258 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
259 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
260 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
261 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
264 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
266 mPanGesturePredictionMode = predictionMode;
268 int predictionAmount(-1);
269 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
271 if( predictionAmount < 0 )
273 // do not support times in the past
274 predictionAmount = 0;
276 mPanGesturePredictionAmount = predictionAmount;
278 int minPredictionAmount(-1);
279 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
281 if( minPredictionAmount < 0 )
283 // do not support times in the past
284 minPredictionAmount = 0;
286 mPanGestureMinPredictionAmount = minPredictionAmount;
288 int maxPredictionAmount(-1);
289 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
291 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
293 // maximum amount should not be smaller than minimum amount
294 maxPredictionAmount = minPredictionAmount;
296 mPanGestureMaxPredictionAmount = maxPredictionAmount;
298 int predictionAmountAdjustment(-1);
299 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
301 if( predictionAmountAdjustment < 0 )
303 // negative amount doesn't make sense
304 predictionAmountAdjustment = 0;
306 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
309 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
311 mPanGestureSmoothingMode = smoothingMode;
313 float smoothingAmount = 1.0f;
314 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
316 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
317 mPanGestureSmoothingAmount = smoothingAmount;
320 int minimumDistance(-1);
321 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
323 mPanMinimumDistance = minimumDistance;
326 int minimumEvents(-1);
327 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
329 mPanMinimumEvents = minimumEvents;
333 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
335 mGlesCallTime = glesCallTime;
338 int windowWidth(0), windowHeight(0);
339 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
341 mWindowWidth = windowWidth;
342 mWindowHeight = windowHeight;
345 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
348 mWindowName = windowName;
351 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
352 if ( windowClassName )
354 mWindowClassName = windowClassName;
357 int threadingMode(0);
358 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
360 switch( threadingMode )
362 case ThreadingMode::SEPARATE_UPDATE_RENDER:
363 case ThreadingMode::COMBINED_UPDATE_RENDER:
364 case ThreadingMode::SINGLE_THREADED:
366 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );