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