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;
41 const int DEFAULT_MULTI_SAMPLING_LEVEL = -1;
43 unsigned int GetIntegerEnvironmentVariable( const char* variable, unsigned int defaultValue )
45 const char* variableParameter = std::getenv(variable);
47 // if the parameter exists convert it to an integer, else return the default value
48 unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
52 bool GetIntegerEnvironmentVariable( const char* variable, int& intValue )
54 const char* variableParameter = std::getenv(variable);
56 if( !variableParameter )
60 // if the parameter exists convert it to an integer, else return the default value
61 intValue = std::atoi(variableParameter);
65 bool GetFloatEnvironmentVariable( const char* variable, float& floatValue )
67 const char* variableParameter = std::getenv(variable);
69 if( !variableParameter )
73 // if the parameter exists convert it to an integer, else return the default value
74 floatValue = std::atof(variableParameter);
78 const char * GetCharEnvironmentVariable( const char * variable )
80 return std::getenv( variable );
83 } // unnamed namespace
85 EnvironmentOptions::EnvironmentOptions()
90 mUpdateStatusFrequency(0),
91 mObjectProfilerInterval( 0 ),
92 mPerformanceStatsLevel(0),
93 mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY ),
94 mPerformanceTimeStampOutput(0),
95 mPanGestureLoggingLevel(0),
96 mPanGesturePredictionMode(-1),
97 mPanGesturePredictionAmount(-1), ///< only sets value in pan gesture if greater than 0
98 mPanGestureMaxPredictionAmount(-1),
99 mPanGestureMinPredictionAmount(-1),
100 mPanGesturePredictionAmountAdjustment(-1),
101 mPanGestureSmoothingMode(-1),
102 mPanGestureSmoothingAmount(-1.0f),
103 mPanMinimumDistance(-1),
104 mPanMinimumEvents(-1),
108 mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
109 mRenderRefreshRate( 1 ),
110 mGlesCallAccumulate( false ),
111 mMultiSamplingLevel( DEFAULT_MULTI_SAMPLING_LEVEL ),
112 mMaxTextureSize( 0 ),
113 mIndicatorVisibleMode( -1 ),
116 ParseEnvironmentOptions();
119 EnvironmentOptions::~EnvironmentOptions()
123 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
125 mLogFunction = logFunction;
128 void EnvironmentOptions::InstallLogFunction() const
130 Dali::Integration::Log::InstallLogFunction( mLogFunction );
133 void EnvironmentOptions::UnInstallLogFunction() const
135 Dali::Integration::Log::UninstallLogFunction();
138 unsigned int EnvironmentOptions::GetNetworkControlMode() const
140 return mNetworkControl;
142 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
144 return mFpsFrequency;
147 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
149 return mUpdateStatusFrequency;
152 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
154 return mObjectProfilerInterval;
157 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
159 return mPerformanceStatsLevel;
161 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
163 return mPerformanceStatsFrequency;
165 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
167 return mPerformanceTimeStampOutput;
170 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
172 return mPanGestureLoggingLevel;
175 int EnvironmentOptions::GetPanGesturePredictionMode() const
177 return mPanGesturePredictionMode;
180 int EnvironmentOptions::GetPanGesturePredictionAmount() const
182 return mPanGesturePredictionAmount;
185 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
187 return mPanGestureMaxPredictionAmount;
190 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
192 return mPanGestureMinPredictionAmount;
195 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
197 return mPanGesturePredictionAmountAdjustment;
200 int EnvironmentOptions::GetPanGestureSmoothingMode() const
202 return mPanGestureSmoothingMode;
205 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
207 return mPanGestureSmoothingAmount;
210 int EnvironmentOptions::GetMinimumPanDistance() const
212 return mPanMinimumDistance;
215 int EnvironmentOptions::GetMinimumPanEvents() const
217 return mPanMinimumEvents;
220 unsigned int EnvironmentOptions::GetWindowWidth() const
225 unsigned int EnvironmentOptions::GetWindowHeight() const
227 return mWindowHeight;
230 int EnvironmentOptions::GetGlesCallTime() const
232 return mGlesCallTime;
235 bool EnvironmentOptions::GetGlesCallAccumulate() const
237 return mGlesCallAccumulate;
240 const std::string& EnvironmentOptions::GetWindowName() const
245 const std::string& EnvironmentOptions::GetWindowClassName() const
247 return mWindowClassName;
250 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
252 return mThreadingMode;
255 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
257 return mRenderRefreshRate;
260 int EnvironmentOptions::GetMultiSamplingLevel() const
262 return mMultiSamplingLevel;
265 unsigned int EnvironmentOptions::GetMaxTextureSize() const
267 return mMaxTextureSize;
270 int EnvironmentOptions::GetIndicatorVisibleMode() const
272 return mIndicatorVisibleMode;
275 bool EnvironmentOptions::PerformanceServerRequired() const
277 return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
278 ( GetPerformanceTimeStampOutput() > 0 ) ||
279 ( GetNetworkControlMode() > 0) );
282 void EnvironmentOptions::ParseEnvironmentOptions()
284 // get logging options
285 mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
286 mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
287 mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
288 mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
289 mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
290 mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
291 mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
292 mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
295 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
297 mPanGesturePredictionMode = predictionMode;
299 int predictionAmount(-1);
300 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
302 if( predictionAmount < 0 )
304 // do not support times in the past
305 predictionAmount = 0;
307 mPanGesturePredictionAmount = predictionAmount;
309 int minPredictionAmount(-1);
310 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
312 if( minPredictionAmount < 0 )
314 // do not support times in the past
315 minPredictionAmount = 0;
317 mPanGestureMinPredictionAmount = minPredictionAmount;
319 int maxPredictionAmount(-1);
320 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
322 if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
324 // maximum amount should not be smaller than minimum amount
325 maxPredictionAmount = minPredictionAmount;
327 mPanGestureMaxPredictionAmount = maxPredictionAmount;
329 int predictionAmountAdjustment(-1);
330 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
332 if( predictionAmountAdjustment < 0 )
334 // negative amount doesn't make sense
335 predictionAmountAdjustment = 0;
337 mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
340 if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
342 mPanGestureSmoothingMode = smoothingMode;
344 float smoothingAmount = 1.0f;
345 if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
347 smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
348 mPanGestureSmoothingAmount = smoothingAmount;
351 int minimumDistance(-1);
352 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
354 mPanMinimumDistance = minimumDistance;
357 int minimumEvents(-1);
358 if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
360 mPanMinimumEvents = minimumEvents;
364 if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
366 mGlesCallTime = glesCallTime;
369 int glesCallAccumulate( 0 );
370 if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
372 mGlesCallAccumulate = glesCallAccumulate != 0;
375 int windowWidth(0), windowHeight(0);
376 if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
378 mWindowWidth = windowWidth;
379 mWindowHeight = windowHeight;
382 const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
385 mWindowName = windowName;
388 const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
389 if ( windowClassName )
391 mWindowClassName = windowClassName;
394 int threadingMode(0);
395 if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
397 switch( threadingMode )
399 case ThreadingMode::COMBINED_UPDATE_RENDER:
401 mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
407 int renderRefreshRate(0);
408 if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
410 // Only change it if it's valid
411 if( renderRefreshRate > 1 )
413 mRenderRefreshRate = renderRefreshRate;
417 int multiSamplingLevel( 0 );
418 if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
420 mMultiSamplingLevel = multiSamplingLevel;
423 int maxTextureSize( 0 );
424 if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
426 if( maxTextureSize > 0 )
428 mMaxTextureSize = maxTextureSize;
432 int indicatorVisibleMode( -1 );
433 if( GetIntegerEnvironmentVariable( DALI_ENV_INDICATOR_VISIBLE_MODE, indicatorVisibleMode ) )
435 if( indicatorVisibleMode > -1 )
437 mIndicatorVisibleMode = indicatorVisibleMode;