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