2 * Copyright (c) 2017 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 ),
109 mGlesCallAccumulate( false ),
110 mMultiSamplingLevel( 0 ),
111 mMaxTextureSize( 0 ),
112 mIndicatorVisibleMode( -1 ),
115 ParseEnvironmentOptions();
118 EnvironmentOptions::~EnvironmentOptions()
122 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
124 mLogFunction = logFunction;
127 void EnvironmentOptions::InstallLogFunction() const
129 Dali::Integration::Log::InstallLogFunction( mLogFunction );
132 void EnvironmentOptions::UnInstallLogFunction() const
134 Dali::Integration::Log::UninstallLogFunction();
137 unsigned int EnvironmentOptions::GetNetworkControlMode() const
139 return mNetworkControl;
141 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
143 return mFpsFrequency;
146 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
148 return mUpdateStatusFrequency;
151 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
153 return mObjectProfilerInterval;
156 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
158 return mPerformanceStatsLevel;
160 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
162 return mPerformanceStatsFrequency;
164 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
166 return mPerformanceTimeStampOutput;
169 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
171 return mPanGestureLoggingLevel;
174 int EnvironmentOptions::GetPanGesturePredictionMode() const
176 return mPanGesturePredictionMode;
179 int EnvironmentOptions::GetPanGesturePredictionAmount() const
181 return mPanGesturePredictionAmount;
184 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
186 return mPanGestureMaxPredictionAmount;
189 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
191 return mPanGestureMinPredictionAmount;
194 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
196 return mPanGesturePredictionAmountAdjustment;
199 int EnvironmentOptions::GetPanGestureSmoothingMode() const
201 return mPanGestureSmoothingMode;
204 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
206 return mPanGestureSmoothingAmount;
209 int EnvironmentOptions::GetMinimumPanDistance() const
211 return mPanMinimumDistance;
214 int EnvironmentOptions::GetMinimumPanEvents() const
216 return mPanMinimumEvents;
219 unsigned int EnvironmentOptions::GetWindowWidth() const
224 unsigned int EnvironmentOptions::GetWindowHeight() const
226 return mWindowHeight;
229 int EnvironmentOptions::GetGlesCallTime() const
231 return mGlesCallTime;
234 bool EnvironmentOptions::GetGlesCallAccumulate() const
236 return mGlesCallAccumulate;
239 const std::string& EnvironmentOptions::GetWindowName() const
244 const std::string& EnvironmentOptions::GetWindowClassName() const
246 return mWindowClassName;
249 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
251 return mThreadingMode;
254 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
256 return mRenderRefreshRate;
259 unsigned int EnvironmentOptions::GetMultiSamplingLevel() const
261 return mMultiSamplingLevel;
264 unsigned int EnvironmentOptions::GetMaxTextureSize() const
266 return mMaxTextureSize;
269 int EnvironmentOptions::GetIndicatorVisibleMode() const
271 return mIndicatorVisibleMode;
274 bool EnvironmentOptions::PerformanceServerRequired() const
276 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
277 ( GetPerformanceTimeStampOutput() > 0 ) ||
278 ( GetNetworkControlMode() > 0) );
281 void EnvironmentOptions::ParseEnvironmentOptions()
283 // get logging options
284 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
285 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
286 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
287 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
288 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
289 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
290 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
291 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
294 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
296 mPanGesturePredictionMode = predictionMode;
298 int predictionAmount(-1);
299 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
301 if( predictionAmount < 0 )
303 // do not support times in the past
304 predictionAmount = 0;
306 mPanGesturePredictionAmount = predictionAmount;
308 int minPredictionAmount(-1);
309 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
311 if( minPredictionAmount < 0 )
313 // do not support times in the past
314 minPredictionAmount = 0;
316 mPanGestureMinPredictionAmount = minPredictionAmount;
318 int maxPredictionAmount(-1);
319 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
321 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
323 // maximum amount should not be smaller than minimum amount
324 maxPredictionAmount = minPredictionAmount;
326 mPanGestureMaxPredictionAmount = maxPredictionAmount;
328 int predictionAmountAdjustment(-1);
329 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
331 if( predictionAmountAdjustment < 0 )
333 // negative amount doesn't make sense
334 predictionAmountAdjustment = 0;
336 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
339 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
341 mPanGestureSmoothingMode = smoothingMode;
343 float smoothingAmount = 1.0f;
344 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
346 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
347 mPanGestureSmoothingAmount = smoothingAmount;
350 int minimumDistance(-1);
351 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
353 mPanMinimumDistance = minimumDistance;
356 int minimumEvents(-1);
357 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
359 mPanMinimumEvents = minimumEvents;
363 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
365 mGlesCallTime = glesCallTime;
368 int glesCallAccumulate( 0 );
369 if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
371 mGlesCallAccumulate = glesCallAccumulate != 0;
374 int windowWidth(0), windowHeight(0);
375 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
377 mWindowWidth = windowWidth;
378 mWindowHeight = windowHeight;
381 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
384 mWindowName = windowName;
387 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
388 if ( windowClassName )
390 mWindowClassName = windowClassName;
393 int threadingMode(0);
394 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
396 switch( threadingMode )
398 case ThreadingMode::COMBINED_UPDATE_RENDER:
400 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
406 int renderRefreshRate(0);
407 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
409 // Only change it if it's valid
410 if( renderRefreshRate > 1 )
412 mRenderRefreshRate = renderRefreshRate;
416 int multiSamplingLevel( 0 );
417 if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
419 if( multiSamplingLevel > 0 )
421 mMultiSamplingLevel = multiSamplingLevel;
425 int maxTextureSize( 0 );
426 if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
428 if( maxTextureSize > 0 )
430 mMaxTextureSize = maxTextureSize;
434 int indicatorVisibleMode( -1 );
435 if( GetIntegerEnvironmentVariable( DALI_ENV_INDICATOR_VISIBLE_MODE, indicatorVisibleMode ) )
437 if( indicatorVisibleMode > -1 )
439 mIndicatorVisibleMode = indicatorVisibleMode;