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