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