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