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::COMBINED_UPDATE_RENDER ),
108 mRenderRefreshRate( 1 ),
111 ParseEnvironmentOptions();
114 EnvironmentOptions::~EnvironmentOptions()
118 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
120 mLogFunction = logFunction;
123 void EnvironmentOptions::InstallLogFunction() const
125 Dali::Integration::Log::InstallLogFunction( mLogFunction );
128 void EnvironmentOptions::UnInstallLogFunction() const
130 Dali::Integration::Log::UninstallLogFunction();
133 unsigned int EnvironmentOptions::GetNetworkControlMode() const
135 return mNetworkControl;
137 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
139 return mFpsFrequency;
142 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
144 return mUpdateStatusFrequency;
147 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
149 return mObjectProfilerInterval;
152 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
154 return mPerformanceStatsLevel;
156 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
158 return mPerformanceStatsFrequency;
160 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
162 return mPerformanceTimeStampOutput;
165 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
167 return mPanGestureLoggingLevel;
170 int EnvironmentOptions::GetPanGesturePredictionMode() const
172 return mPanGesturePredictionMode;
175 int EnvironmentOptions::GetPanGesturePredictionAmount() const
177 return mPanGesturePredictionAmount;
180 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
182 return mPanGestureMaxPredictionAmount;
185 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
187 return mPanGestureMinPredictionAmount;
190 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
192 return mPanGesturePredictionAmountAdjustment;
195 int EnvironmentOptions::GetPanGestureSmoothingMode() const
197 return mPanGestureSmoothingMode;
200 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
202 return mPanGestureSmoothingAmount;
205 int EnvironmentOptions::GetMinimumPanDistance() const
207 return mPanMinimumDistance;
210 int EnvironmentOptions::GetMinimumPanEvents() const
212 return mPanMinimumEvents;
215 unsigned int EnvironmentOptions::GetWindowWidth() const
220 unsigned int EnvironmentOptions::GetWindowHeight() const
222 return mWindowHeight;
225 int EnvironmentOptions::GetGlesCallTime() const
227 return mGlesCallTime;
230 const std::string& EnvironmentOptions::GetWindowName() const
235 const std::string& EnvironmentOptions::GetWindowClassName() const
237 return mWindowClassName;
240 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
242 return mThreadingMode;
245 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
247 return mRenderRefreshRate;
250 bool EnvironmentOptions::PerformanceServerRequired() const
252 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
253 ( GetPerformanceTimeStampOutput() > 0 ) ||
254 ( GetNetworkControlMode() > 0) );
257 void EnvironmentOptions::ParseEnvironmentOptions()
259 // get logging options
260 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
261 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
262 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
263 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
264 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
265 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
266 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
267 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
270 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
272 mPanGesturePredictionMode = predictionMode;
274 int predictionAmount(-1);
275 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
277 if( predictionAmount < 0 )
279 // do not support times in the past
280 predictionAmount = 0;
282 mPanGesturePredictionAmount = predictionAmount;
284 int minPredictionAmount(-1);
285 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
287 if( minPredictionAmount < 0 )
289 // do not support times in the past
290 minPredictionAmount = 0;
292 mPanGestureMinPredictionAmount = minPredictionAmount;
294 int maxPredictionAmount(-1);
295 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
297 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
299 // maximum amount should not be smaller than minimum amount
300 maxPredictionAmount = minPredictionAmount;
302 mPanGestureMaxPredictionAmount = maxPredictionAmount;
304 int predictionAmountAdjustment(-1);
305 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
307 if( predictionAmountAdjustment < 0 )
309 // negative amount doesn't make sense
310 predictionAmountAdjustment = 0;
312 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
315 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
317 mPanGestureSmoothingMode = smoothingMode;
319 float smoothingAmount = 1.0f;
320 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
322 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
323 mPanGestureSmoothingAmount = smoothingAmount;
326 int minimumDistance(-1);
327 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
329 mPanMinimumDistance = minimumDistance;
332 int minimumEvents(-1);
333 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
335 mPanMinimumEvents = minimumEvents;
339 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
341 mGlesCallTime = glesCallTime;
344 int windowWidth(0), windowHeight(0);
345 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
347 mWindowWidth = windowWidth;
348 mWindowHeight = windowHeight;
351 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
354 mWindowName = windowName;
357 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
358 if ( windowClassName )
360 mWindowClassName = windowClassName;
363 int threadingMode(0);
364 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
366 switch( threadingMode )
368 case ThreadingMode::SEPARATE_UPDATE_RENDER:
369 case ThreadingMode::COMBINED_UPDATE_RENDER:
370 case ThreadingMode::SINGLE_THREADED:
372 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
378 int renderRefreshRate(0);
379 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
381 // Only change it if it's valid
382 if( renderRefreshRate > 1 )
384 mRenderRefreshRate = renderRefreshRate;