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);
78 EnvironmentOptions::EnvironmentOptions()
81 mUpdateStatusFrequency(0),
82 mPerformanceStatsLevel(0),
83 mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY),
84 mPerformanceTimeStampOutput(0),
85 mPanGestureLoggingLevel(0),
86 mPanGesturePredictionMode(-1),
87 mPanGesturePredictionAmount(-1), ///< only sets value in pan gesture if greater than 0
88 mPanGestureMaxPredictionAmount(-1),
89 mPanGestureMinPredictionAmount(-1),
90 mPanGesturePredictionAmountAdjustment(-1),
91 mPanGestureSmoothingMode(-1),
92 mPanGestureSmoothingAmount(-1.0f),
93 mPanMinimumDistance(-1),
94 mPanMinimumEvents(-1),
99 ParseEnvironmentOptions();
102 EnvironmentOptions::~EnvironmentOptions()
106 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
108 mLogFunction = logFunction;
111 void EnvironmentOptions::InstallLogFunction() const
113 Dali::Integration::Log::InstallLogFunction( mLogFunction );
116 void EnvironmentOptions::UnInstallLogFunction() const
118 Dali::Integration::Log::UninstallLogFunction();
121 unsigned int EnvironmentOptions::GetNetworkControlMode() const
123 return mNetworkControl;
125 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
127 return mFpsFrequency;
130 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
132 return mUpdateStatusFrequency;
135 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
137 return mPerformanceStatsLevel;
139 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
141 return mPerformanceStatsFrequency;
143 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
145 return mPerformanceTimeStampOutput;
148 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
150 return mPanGestureLoggingLevel;
153 int EnvironmentOptions::GetPanGesturePredictionMode() const
155 return mPanGesturePredictionMode;
158 int EnvironmentOptions::GetPanGesturePredictionAmount() const
160 return mPanGesturePredictionAmount;
163 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
165 return mPanGestureMaxPredictionAmount;
168 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
170 return mPanGestureMinPredictionAmount;
173 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
175 return mPanGesturePredictionAmountAdjustment;
178 int EnvironmentOptions::GetPanGestureSmoothingMode() const
180 return mPanGestureSmoothingMode;
183 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
185 return mPanGestureSmoothingAmount;
188 int EnvironmentOptions::GetMinimumPanDistance() const
190 return mPanMinimumDistance;
193 int EnvironmentOptions::GetMinimumPanEvents() const
195 return mPanMinimumEvents;
198 unsigned int EnvironmentOptions::GetWindowWidth() const
203 unsigned int EnvironmentOptions::GetWindowHeight() const
205 return mWindowHeight;
208 void EnvironmentOptions::SetPanGesturePredictionMode( unsigned int mode )
210 mPanGesturePredictionMode = mode;
213 void EnvironmentOptions::SetPanGesturePredictionAmount( unsigned int amount )
215 mPanGesturePredictionAmount = amount;
218 void EnvironmentOptions::SetPanGestureMaximumPredictionAmount( unsigned int amount )
220 mPanGestureMaxPredictionAmount = amount;
223 void EnvironmentOptions::SetPanGestureMinimumPredictionAmount( unsigned int amount )
225 mPanGestureMinPredictionAmount = amount;
228 void EnvironmentOptions::SetPanGesturePredictionAmountAdjustment( unsigned int amount )
230 mPanGesturePredictionAmountAdjustment = amount;
233 void EnvironmentOptions::SetPanGestureSmoothingMode( unsigned int mode )
235 mPanGestureSmoothingMode = mode;
238 void EnvironmentOptions::SetPanGestureSmoothingAmount( float amount )
240 mPanGestureSmoothingAmount = amount;
243 void EnvironmentOptions::SetMinimumPanDistance( int distance )
245 mPanMinimumDistance = distance;
248 void EnvironmentOptions::SetMinimumPanEvents( int events )
250 mPanMinimumEvents = events;
253 void EnvironmentOptions::SetGlesCallTime( int time )
255 mGlesCallTime = time;
258 int EnvironmentOptions::GetGlesCallTime() const
260 return mGlesCallTime;
263 void EnvironmentOptions::SetWindowWidth( int width )
265 mWindowWidth = width;
268 void EnvironmentOptions::SetWindowHeight( int height )
270 mWindowHeight = height;
273 bool EnvironmentOptions::PerformanceServerRequired() const
275 return ( (GetPerformanceStatsLoggingOptions() > 0) ||
276 ( GetPerformanceTimeStampOutput() > 0 ) ||
277 ( GetNetworkControlMode() > 0) );
280 void EnvironmentOptions::ParseEnvironmentOptions()
282 // get logging options
283 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
284 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
285 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
286 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
287 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
288 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
289 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
292 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
294 SetPanGesturePredictionMode(predictionMode);
296 int predictionAmount(-1);
297 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
299 if( predictionAmount < 0 )
301 // do not support times in the past
302 predictionAmount = 0;
304 SetPanGesturePredictionAmount(predictionAmount);
306 int minPredictionAmount(-1);
307 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
309 if( minPredictionAmount < 0 )
311 // do not support times in the past
312 minPredictionAmount = 0;
314 SetPanGestureMinimumPredictionAmount(minPredictionAmount);
316 int maxPredictionAmount(-1);
317 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
319 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
321 // maximum amount should not be smaller than minimum amount
322 maxPredictionAmount = minPredictionAmount;
324 SetPanGestureMaximumPredictionAmount(maxPredictionAmount);
326 int predictionAmountAdjustment(-1);
327 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
329 if( predictionAmountAdjustment < 0 )
331 // negative amount doesn't make sense
332 predictionAmountAdjustment = 0;
334 SetPanGesturePredictionAmountAdjustment(predictionAmountAdjustment);
337 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
339 SetPanGestureSmoothingMode(smoothingMode);
341 float smoothingAmount = 1.0f;
342 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
344 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
345 SetPanGestureSmoothingAmount(smoothingAmount);
348 int minimumDistance(-1);
349 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
351 SetMinimumPanDistance( minimumDistance );
354 int minimumEvents(-1);
355 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
357 SetMinimumPanEvents( minimumEvents );
361 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
363 SetGlesCallTime( glesCallTime );
366 int windowWidth(0), windowHeight(0);
367 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
369 SetWindowWidth( windowWidth );
370 SetWindowHeight( windowHeight );