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