23bec81feb13fcd3df172d7ced15d80b04b33295
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / environment-options.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/system/common/environment-options.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstdlib>
23 #include <dali/integration-api/render-controller.h>
24 #include <dali/public-api/math/math-utils.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/internal/trace/common/trace-factory.h>
28 #include <dali/internal/system/common/environment-variables.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace Adaptor
37 {
38
39 namespace
40 {
41 const unsigned int DEFAULT_STATISTICS_LOG_FREQUENCY = 2;
42 const int DEFAULT_MULTI_SAMPLING_LEVEL = -1;
43 const bool DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING = true;
44 const bool DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING = true;
45
46 unsigned int GetIntegerEnvironmentVariable( const char* variable, unsigned int defaultValue )
47 {
48   const char* variableParameter = std::getenv(variable);
49
50   // if the parameter exists convert it to an integer, else return the default value
51   unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
52   return intValue;
53 }
54
55 bool GetIntegerEnvironmentVariable( const char* variable, int& intValue )
56 {
57   const char* variableParameter = std::getenv(variable);
58
59   if( !variableParameter )
60   {
61     return false;
62   }
63   // if the parameter exists convert it to an integer, else return the default value
64   intValue = std::atoi(variableParameter);
65   return true;
66 }
67
68 bool GetFloatEnvironmentVariable( const char* variable, float& floatValue )
69 {
70   const char* variableParameter = std::getenv(variable);
71
72   if( !variableParameter )
73   {
74     return false;
75   }
76   // if the parameter exists convert it to an integer, else return the default value
77   floatValue = std::atof(variableParameter);
78   return true;
79 }
80
81 const char * GetCharEnvironmentVariable( const char * variable )
82 {
83   return std::getenv( variable );
84 }
85
86 } // unnamed namespace
87
88 EnvironmentOptions::EnvironmentOptions()
89 : mLogFunction( NULL ),
90   mWindowName(),
91   mWindowClassName(),
92   mNetworkControl( 0 ),
93   mFpsFrequency( 0 ),
94   mUpdateStatusFrequency( 0 ),
95   mObjectProfilerInterval( 0 ),
96   mPerformanceStatsLevel( 0 ),
97   mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY ),
98   mPerformanceTimeStampOutput( 0 ),
99   mPanGestureLoggingLevel( 0 ),
100   mWindowWidth( 0u ),
101   mWindowHeight( 0u ),
102   mRenderRefreshRate( 1u ),
103   mMaxTextureSize( 0 ),
104   mRenderToFboInterval( 0u ),
105   mPanGesturePredictionMode( -1 ),
106   mPanGesturePredictionAmount( -1 ), ///< only sets value in pan gesture if greater than 0
107   mPanGestureMaxPredictionAmount( -1 ),
108   mPanGestureMinPredictionAmount( -1 ),
109   mPanGesturePredictionAmountAdjustment( -1 ),
110   mPanGestureSmoothingMode( -1 ),
111   mPanGestureSmoothingAmount( -1.0f ),
112   mPanGestureUseActualTimes( -1 ),
113   mPanGestureInterpolationTimeRange( -1 ),
114   mPanGestureScalarOnlyPredictionEnabled( -1 ),
115   mPanGestureTwoPointPredictionEnabled( -1 ),
116   mPanGestureTwoPointInterpolatePastTime( -1 ),
117   mPanGestureTwoPointVelocityBias( -1.0f ),
118   mPanGestureTwoPointAccelerationBias( -1.0f ),
119   mPanGestureMultitapSmoothingRange( -1 ),
120   mPanMinimumDistance( -1 ),
121   mPanMinimumEvents( -1 ),
122   mPinchMinimumDistance( -1.0f ),
123   mGlesCallTime( 0 ),
124   mMultiSamplingLevel( DEFAULT_MULTI_SAMPLING_LEVEL ),
125   mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
126   mGlesCallAccumulate( false ),
127   mDepthBufferRequired( DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING ),
128   mStencilBufferRequired( DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING )
129 {
130   ParseEnvironmentOptions();
131 }
132
133 EnvironmentOptions::~EnvironmentOptions()
134 {
135 }
136
137 void EnvironmentOptions::CreateTraceManager( PerformanceInterface* performanceInterface )
138 {
139   mTraceManager = TraceManagerFactory::CreateTraceFactory( performanceInterface );
140 }
141
142 void EnvironmentOptions::InstallTraceFunction() const
143 {
144   if( mTraceManager )
145   {
146     mTraceManager->Initialise();
147   }
148 }
149
150 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
151 {
152   mLogFunction = logFunction;
153 }
154
155 void EnvironmentOptions::InstallLogFunction() const
156 {
157   Dali::Integration::Log::InstallLogFunction( mLogFunction );
158 }
159
160 void EnvironmentOptions::UnInstallLogFunction() const
161 {
162   Dali::Integration::Log::UninstallLogFunction();
163 }
164
165 unsigned int EnvironmentOptions::GetNetworkControlMode() const
166 {
167   return mNetworkControl;
168 }
169 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
170 {
171   return mFpsFrequency;
172 }
173
174 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
175 {
176   return mUpdateStatusFrequency;
177 }
178
179 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
180 {
181   return mObjectProfilerInterval;
182 }
183
184 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
185 {
186   return mPerformanceStatsLevel;
187 }
188 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
189 {
190   return mPerformanceStatsFrequency;
191 }
192 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
193 {
194   return mPerformanceTimeStampOutput;
195 }
196
197 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
198 {
199   return mPanGestureLoggingLevel;
200 }
201
202 int EnvironmentOptions::GetPanGesturePredictionMode() const
203 {
204   return mPanGesturePredictionMode;
205 }
206
207 int EnvironmentOptions::GetPanGesturePredictionAmount() const
208 {
209   return mPanGesturePredictionAmount;
210 }
211
212 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
213 {
214   return mPanGestureMaxPredictionAmount;
215 }
216
217 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
218 {
219   return mPanGestureMinPredictionAmount;
220 }
221
222 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
223 {
224   return mPanGesturePredictionAmountAdjustment;
225 }
226
227 int EnvironmentOptions::GetPanGestureSmoothingMode() const
228 {
229   return mPanGestureSmoothingMode;
230 }
231
232 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
233 {
234   return mPanGestureSmoothingAmount;
235 }
236
237 int EnvironmentOptions::GetPanGestureUseActualTimes() const
238 {
239   return mPanGestureUseActualTimes;
240 }
241
242 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
243 {
244   return mPanGestureInterpolationTimeRange;
245 }
246
247 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
248 {
249   return mPanGestureScalarOnlyPredictionEnabled;
250 }
251
252 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
253 {
254   return mPanGestureTwoPointPredictionEnabled;
255 }
256
257 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
258 {
259   return mPanGestureTwoPointInterpolatePastTime;
260 }
261
262 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
263 {
264   return mPanGestureTwoPointVelocityBias;
265 }
266
267 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
268 {
269   return mPanGestureTwoPointAccelerationBias;
270 }
271
272 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
273 {
274   return mPanGestureMultitapSmoothingRange;
275 }
276
277 int EnvironmentOptions::GetMinimumPanDistance() const
278 {
279   return mPanMinimumDistance;
280 }
281
282 int EnvironmentOptions::GetMinimumPanEvents() const
283 {
284   return mPanMinimumEvents;
285 }
286
287 float EnvironmentOptions::GetMinimumPinchDistance() const
288 {
289   return mPinchMinimumDistance;
290 }
291
292 unsigned int EnvironmentOptions::GetWindowWidth() const
293 {
294   return mWindowWidth;
295 }
296
297 unsigned int EnvironmentOptions::GetWindowHeight() const
298 {
299   return mWindowHeight;
300 }
301
302 int EnvironmentOptions::GetGlesCallTime() const
303 {
304   return mGlesCallTime;
305 }
306
307 bool EnvironmentOptions::GetGlesCallAccumulate() const
308 {
309   return mGlesCallAccumulate;
310 }
311
312 const std::string& EnvironmentOptions::GetWindowName() const
313 {
314   return mWindowName;
315 }
316
317 const std::string& EnvironmentOptions::GetWindowClassName() const
318 {
319   return mWindowClassName;
320 }
321
322 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
323 {
324   return mThreadingMode;
325 }
326
327 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
328 {
329   return mRenderRefreshRate;
330 }
331
332 int EnvironmentOptions::GetMultiSamplingLevel() const
333 {
334   return mMultiSamplingLevel;
335 }
336
337 unsigned int EnvironmentOptions::GetMaxTextureSize() const
338 {
339   return mMaxTextureSize;
340 }
341
342 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
343 {
344   return mRenderToFboInterval;
345 }
346
347 bool EnvironmentOptions::PerformanceServerRequired() const
348 {
349   return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
350            ( GetPerformanceTimeStampOutput() > 0 ) ||
351            ( GetNetworkControlMode() > 0) );
352 }
353
354 bool EnvironmentOptions::DepthBufferRequired() const
355 {
356   return mDepthBufferRequired;
357 }
358
359 bool EnvironmentOptions::StencilBufferRequired() const
360 {
361   return mStencilBufferRequired;
362 }
363
364 void EnvironmentOptions::ParseEnvironmentOptions()
365 {
366   // get logging options
367   mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
368   mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
369   mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
370   mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
371   mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
372   mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
373   mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
374   mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
375
376   int predictionMode;
377   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
378   {
379     mPanGesturePredictionMode = predictionMode;
380   }
381   int predictionAmount(-1);
382   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
383   {
384     if( predictionAmount < 0 )
385     {
386       // do not support times in the past
387       predictionAmount = 0;
388     }
389     mPanGesturePredictionAmount = predictionAmount;
390   }
391   int minPredictionAmount(-1);
392   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
393   {
394     if( minPredictionAmount < 0 )
395     {
396       // do not support times in the past
397       minPredictionAmount = 0;
398     }
399     mPanGestureMinPredictionAmount = minPredictionAmount;
400   }
401   int maxPredictionAmount(-1);
402   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
403   {
404     if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
405     {
406       // maximum amount should not be smaller than minimum amount
407       maxPredictionAmount = minPredictionAmount;
408     }
409     mPanGestureMaxPredictionAmount = maxPredictionAmount;
410   }
411   int predictionAmountAdjustment(-1);
412   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
413   {
414     if( predictionAmountAdjustment < 0 )
415     {
416       // negative amount doesn't make sense
417       predictionAmountAdjustment = 0;
418     }
419     mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
420   }
421   int smoothingMode;
422   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
423   {
424     mPanGestureSmoothingMode = smoothingMode;
425   }
426   float smoothingAmount = 1.0f;
427   if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
428   {
429     smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
430     mPanGestureSmoothingAmount = smoothingAmount;
431   }
432
433   int useActualTimes( -1 );
434   if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_USE_ACTUAL_TIMES, useActualTimes ) )
435   {
436     mPanGestureUseActualTimes = useActualTimes == 0 ? 0 : 1;
437   }
438
439   int interpolationTimeRange( -1 );
440   if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, interpolationTimeRange ) )
441   {
442     if( interpolationTimeRange < 0 )
443     {
444       interpolationTimeRange = 0;
445     }
446     mPanGestureInterpolationTimeRange = interpolationTimeRange;
447   }
448
449   int scalarOnlyPredictionEnabled( -1 );
450   if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, scalarOnlyPredictionEnabled ) )
451   {
452     mPanGestureScalarOnlyPredictionEnabled = scalarOnlyPredictionEnabled == 0 ? 0 : 1;
453   }
454
455   int twoPointPredictionEnabled( -1 );
456   if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, twoPointPredictionEnabled ) )
457   {
458     mPanGestureTwoPointPredictionEnabled = twoPointPredictionEnabled == 0 ? 0 : 1;
459   }
460
461   int twoPointPastInterpolateTime( -1 );
462   if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, twoPointPastInterpolateTime ) )
463   {
464     if( twoPointPastInterpolateTime < 0 )
465     {
466       twoPointPastInterpolateTime = 0;
467     }
468     mPanGestureTwoPointInterpolatePastTime = twoPointPastInterpolateTime;
469   }
470
471   float twoPointVelocityBias = -1.0f;
472   if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, twoPointVelocityBias ) )
473   {
474     twoPointVelocityBias = Clamp( twoPointVelocityBias, 0.0f, 1.0f );
475     mPanGestureTwoPointVelocityBias = twoPointVelocityBias;
476   }
477
478   float twoPointAccelerationBias = -1.0f;
479   if( GetFloatEnvironmentVariable( DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, twoPointAccelerationBias ) )
480   {
481     twoPointAccelerationBias = Clamp( twoPointAccelerationBias, 0.0f, 1.0f );
482     mPanGestureTwoPointAccelerationBias = twoPointAccelerationBias;
483   }
484
485   int multitapSmoothingRange( -1 );
486   if( GetIntegerEnvironmentVariable( DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, multitapSmoothingRange ) )
487   {
488     if( multitapSmoothingRange < 0 )
489     {
490       multitapSmoothingRange = 0;
491     }
492     mPanGestureMultitapSmoothingRange = multitapSmoothingRange;
493   }
494
495   int minimumDistance(-1);
496   if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
497   {
498     mPanMinimumDistance = minimumDistance;
499   }
500
501   int minimumEvents(-1);
502   if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
503   {
504     mPanMinimumEvents = minimumEvents;
505   }
506
507   float pinchMinimumDistance = -1.0f;
508   if( GetFloatEnvironmentVariable( DALI_ENV_PINCH_MINIMUM_DISTANCE, pinchMinimumDistance ) )
509   {
510     mPinchMinimumDistance = pinchMinimumDistance;
511   }
512
513   int glesCallTime(0);
514   if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
515   {
516     mGlesCallTime = glesCallTime;
517   }
518
519   int glesCallAccumulate( 0 );
520   if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
521   {
522     mGlesCallAccumulate = glesCallAccumulate != 0;
523   }
524
525   int windowWidth(0), windowHeight(0);
526   if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
527   {
528     mWindowWidth = windowWidth;
529     mWindowHeight = windowHeight;
530   }
531
532   const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
533   if ( windowName )
534   {
535     mWindowName = windowName;
536   }
537
538   const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
539   if ( windowClassName )
540   {
541     mWindowClassName = windowClassName;
542   }
543
544   int threadingMode(0);
545   if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
546   {
547     switch( threadingMode )
548     {
549       case ThreadingMode::COMBINED_UPDATE_RENDER:
550       {
551         mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
552         break;
553       }
554     }
555   }
556
557   int renderRefreshRate(0);
558   if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
559   {
560     // Only change it if it's valid
561     if( renderRefreshRate > 1 )
562     {
563       mRenderRefreshRate = renderRefreshRate;
564     }
565   }
566
567   int multiSamplingLevel( 0 );
568   if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
569   {
570     mMultiSamplingLevel = multiSamplingLevel;
571   }
572
573   int maxTextureSize( 0 );
574   if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
575   {
576     if( maxTextureSize > 0 )
577     {
578       mMaxTextureSize = maxTextureSize;
579     }
580   }
581
582   mRenderToFboInterval = GetIntegerEnvironmentVariable( DALI_RENDER_TO_FBO, 0u );
583
584
585   int depthBufferRequired( -1 );
586   if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_DEPTH_BUFFER, depthBufferRequired ) )
587   {
588     if( depthBufferRequired > 0 )
589     {
590       mDepthBufferRequired = false;
591       mStencilBufferRequired = false; // Disable stencil buffer as well
592     }
593   }
594
595   int stencilBufferRequired( -1 );
596   if( GetIntegerEnvironmentVariable( DALI_ENV_DISABLE_STENCIL_BUFFER, stencilBufferRequired ) )
597   {
598     if( stencilBufferRequired > 0 )
599     {
600       mStencilBufferRequired = false;
601     }
602   }
603 }
604
605 } // Adaptor
606
607 } // Internal
608
609 } // Dali