Render to Frame Buffer Object.
[platform/core/uifw/dali-adaptor.git] / adaptors / base / 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 "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 <base/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 = 4;
42
43 unsigned int GetIntegerEnvironmentVariable( const char* variable, unsigned int defaultValue )
44 {
45   const char* variableParameter = std::getenv(variable);
46
47   // if the parameter exists convert it to an integer, else return the default value
48   unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
49   return intValue;
50 }
51
52 bool GetIntegerEnvironmentVariable( const char* variable, int& intValue )
53 {
54   const char* variableParameter = std::getenv(variable);
55
56   if( !variableParameter )
57   {
58     return false;
59   }
60   // if the parameter exists convert it to an integer, else return the default value
61   intValue = std::atoi(variableParameter);
62   return true;
63 }
64
65 bool GetFloatEnvironmentVariable( const char* variable, float& floatValue )
66 {
67   const char* variableParameter = std::getenv(variable);
68
69   if( !variableParameter )
70   {
71     return false;
72   }
73   // if the parameter exists convert it to an integer, else return the default value
74   floatValue = std::atof(variableParameter);
75   return true;
76 }
77
78 const char * GetCharEnvironmentVariable( const char * variable )
79 {
80   return std::getenv( variable );
81 }
82
83 } // unnamed namespace
84
85 EnvironmentOptions::EnvironmentOptions()
86 : mWindowName(),
87   mWindowClassName(),
88   mNetworkControl(0),
89   mFpsFrequency(0),
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),
105   mGlesCallTime( 0 ),
106   mWindowWidth( 0u ),
107   mWindowHeight( 0u ),
108   mThreadingMode( ThreadingMode::COMBINED_UPDATE_RENDER ),
109   mRenderRefreshRate( 1u ),
110   mGlesCallAccumulate( false ),
111   mMultiSamplingLevel( DEFAULT_MULTI_SAMPLING_LEVEL ),
112   mMaxTextureSize( 0 ),
113   mIndicatorVisibleMode( -1 ),
114   mRenderToFboInterval( 0u ),
115   mLogFunction( NULL )
116 {
117   ParseEnvironmentOptions();
118 }
119
120 EnvironmentOptions::~EnvironmentOptions()
121 {
122 }
123
124 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
125 {
126   mLogFunction = logFunction;
127 }
128
129 void EnvironmentOptions::InstallLogFunction() const
130 {
131   Dali::Integration::Log::InstallLogFunction( mLogFunction );
132 }
133
134 void EnvironmentOptions::UnInstallLogFunction() const
135 {
136   Dali::Integration::Log::UninstallLogFunction();
137 }
138
139 unsigned int EnvironmentOptions::GetNetworkControlMode() const
140 {
141   return mNetworkControl;
142 }
143 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
144 {
145   return mFpsFrequency;
146 }
147
148 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
149 {
150   return mUpdateStatusFrequency;
151 }
152
153 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
154 {
155   return mObjectProfilerInterval;
156 }
157
158 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
159 {
160   return mPerformanceStatsLevel;
161 }
162 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
163 {
164   return mPerformanceStatsFrequency;
165 }
166 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
167 {
168   return mPerformanceTimeStampOutput;
169 }
170
171 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
172 {
173   return mPanGestureLoggingLevel;
174 }
175
176 int EnvironmentOptions::GetPanGesturePredictionMode() const
177 {
178   return mPanGesturePredictionMode;
179 }
180
181 int EnvironmentOptions::GetPanGesturePredictionAmount() const
182 {
183   return mPanGesturePredictionAmount;
184 }
185
186 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
187 {
188   return mPanGestureMaxPredictionAmount;
189 }
190
191 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
192 {
193   return mPanGestureMinPredictionAmount;
194 }
195
196 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
197 {
198   return mPanGesturePredictionAmountAdjustment;
199 }
200
201 int EnvironmentOptions::GetPanGestureSmoothingMode() const
202 {
203   return mPanGestureSmoothingMode;
204 }
205
206 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
207 {
208   return mPanGestureSmoothingAmount;
209 }
210
211 int EnvironmentOptions::GetMinimumPanDistance() const
212 {
213   return mPanMinimumDistance;
214 }
215
216 int EnvironmentOptions::GetMinimumPanEvents() const
217 {
218   return mPanMinimumEvents;
219 }
220
221 unsigned int EnvironmentOptions::GetWindowWidth() const
222 {
223   return mWindowWidth;
224 }
225
226 unsigned int EnvironmentOptions::GetWindowHeight() const
227 {
228   return mWindowHeight;
229 }
230
231 int EnvironmentOptions::GetGlesCallTime() const
232 {
233   return mGlesCallTime;
234 }
235
236 bool EnvironmentOptions::GetGlesCallAccumulate() const
237 {
238   return mGlesCallAccumulate;
239 }
240
241 const std::string& EnvironmentOptions::GetWindowName() const
242 {
243   return mWindowName;
244 }
245
246 const std::string& EnvironmentOptions::GetWindowClassName() const
247 {
248   return mWindowClassName;
249 }
250
251 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
252 {
253   return mThreadingMode;
254 }
255
256 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
257 {
258   return mRenderRefreshRate;
259 }
260
261 int EnvironmentOptions::GetMultiSamplingLevel() const
262 {
263   return mMultiSamplingLevel;
264 }
265
266 unsigned int EnvironmentOptions::GetMaxTextureSize() const
267 {
268   return mMaxTextureSize;
269 }
270
271 int EnvironmentOptions::GetIndicatorVisibleMode() const
272 {
273   return mIndicatorVisibleMode;
274 }
275
276 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
277 {
278   return mRenderToFboInterval;
279 }
280
281 bool EnvironmentOptions::PerformanceServerRequired() const
282 {
283   return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
284            ( GetPerformanceTimeStampOutput() > 0 ) ||
285            ( GetNetworkControlMode() > 0) );
286 }
287
288 void EnvironmentOptions::ParseEnvironmentOptions()
289 {
290   // get logging options
291   mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
292   mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
293   mObjectProfilerInterval = GetIntegerEnvironmentVariable( DALI_ENV_OBJECT_PROFILER_INTERVAL, 0 );
294   mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
295   mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
296   mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
297   mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
298   mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
299
300   int predictionMode;
301   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
302   {
303     mPanGesturePredictionMode = predictionMode;
304   }
305   int predictionAmount(-1);
306   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
307   {
308     if( predictionAmount < 0 )
309     {
310       // do not support times in the past
311       predictionAmount = 0;
312     }
313     mPanGesturePredictionAmount = predictionAmount;
314   }
315   int minPredictionAmount(-1);
316   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
317   {
318     if( minPredictionAmount < 0 )
319     {
320       // do not support times in the past
321       minPredictionAmount = 0;
322     }
323     mPanGestureMinPredictionAmount = minPredictionAmount;
324   }
325   int maxPredictionAmount(-1);
326   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
327   {
328     if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
329     {
330       // maximum amount should not be smaller than minimum amount
331       maxPredictionAmount = minPredictionAmount;
332     }
333     mPanGestureMaxPredictionAmount = maxPredictionAmount;
334   }
335   int predictionAmountAdjustment(-1);
336   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
337   {
338     if( predictionAmountAdjustment < 0 )
339     {
340       // negative amount doesn't make sense
341       predictionAmountAdjustment = 0;
342     }
343     mPanGesturePredictionAmountAdjustment = predictionAmountAdjustment;
344   }
345   int smoothingMode;
346   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
347   {
348     mPanGestureSmoothingMode = smoothingMode;
349   }
350   float smoothingAmount = 1.0f;
351   if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
352   {
353     smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
354     mPanGestureSmoothingAmount = smoothingAmount;
355   }
356
357   int minimumDistance(-1);
358   if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
359   {
360     mPanMinimumDistance = minimumDistance;
361   }
362
363   int minimumEvents(-1);
364   if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
365   {
366     mPanMinimumEvents = minimumEvents;
367   }
368
369   int glesCallTime(0);
370   if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
371   {
372     mGlesCallTime = glesCallTime;
373   }
374
375   int glesCallAccumulate( 0 );
376   if ( GetIntegerEnvironmentVariable( DALI_GLES_CALL_ACCUMULATE, glesCallAccumulate ) )
377   {
378     mGlesCallAccumulate = glesCallAccumulate != 0;
379   }
380
381   int windowWidth(0), windowHeight(0);
382   if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
383   {
384     mWindowWidth = windowWidth;
385     mWindowHeight = windowHeight;
386   }
387
388   const char * windowName = GetCharEnvironmentVariable( DALI_WINDOW_NAME );
389   if ( windowName )
390   {
391     mWindowName = windowName;
392   }
393
394   const char * windowClassName = GetCharEnvironmentVariable( DALI_WINDOW_CLASS_NAME );
395   if ( windowClassName )
396   {
397     mWindowClassName = windowClassName;
398   }
399
400   int threadingMode(0);
401   if ( GetIntegerEnvironmentVariable( DALI_THREADING_MODE, threadingMode ) )
402   {
403     switch( threadingMode )
404     {
405       case ThreadingMode::COMBINED_UPDATE_RENDER:
406       {
407         mThreadingMode = static_cast< ThreadingMode::Type >( threadingMode );
408         break;
409       }
410     }
411   }
412
413   int renderRefreshRate(0);
414   if ( GetIntegerEnvironmentVariable( DALI_REFRESH_RATE, renderRefreshRate ) )
415   {
416     // Only change it if it's valid
417     if( renderRefreshRate > 1 )
418     {
419       mRenderRefreshRate = renderRefreshRate;
420     }
421   }
422
423   int multiSamplingLevel( 0 );
424   if( GetIntegerEnvironmentVariable( DALI_ENV_MULTI_SAMPLING_LEVEL, multiSamplingLevel ) )
425   {
426     mMultiSamplingLevel = multiSamplingLevel;
427   }
428
429   int maxTextureSize( 0 );
430   if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
431   {
432     if( maxTextureSize > 0 )
433     {
434       mMaxTextureSize = maxTextureSize;
435     }
436   }
437
438   int indicatorVisibleMode( -1 );
439   if( GetIntegerEnvironmentVariable( DALI_ENV_INDICATOR_VISIBLE_MODE, indicatorVisibleMode ) )
440   {
441     if( indicatorVisibleMode > -1 )
442     {
443       mIndicatorVisibleMode = indicatorVisibleMode;
444     }
445   }
446
447   mRenderToFboInterval = GetIntegerEnvironmentVariable( DALI_RENDER_TO_FBO, 0u );
448 }
449
450 } // Adaptor
451
452 } // Internal
453
454 } // Dali