Merge "Change Application to use NotifySceneCreated from Adaptor" 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   mNetworkControl(0),
87   mFpsFrequency(0),
88   mUpdateStatusFrequency(0),
89   mPerformanceStatsLevel(0),
90   mPerformanceStatsFrequency( DEFAULT_STATISTICS_LOG_FREQUENCY),
91   mPerformanceTimeStampOutput(0),
92   mPanGestureLoggingLevel(0),
93   mPanGesturePredictionMode(-1),
94   mPanGesturePredictionAmount(-1), ///< only sets value in pan gesture if greater than 0
95   mPanGestureMaxPredictionAmount(-1),
96   mPanGestureMinPredictionAmount(-1),
97   mPanGesturePredictionAmountAdjustment(-1),
98   mPanGestureSmoothingMode(-1),
99   mPanGestureSmoothingAmount(-1.0f),
100   mPanMinimumDistance(-1),
101   mPanMinimumEvents(-1),
102   mGlesCallTime(0),
103   mWindowWidth( 0 ),
104   mWindowHeight( 0 )
105 {
106   ParseEnvironmentOptions();
107 }
108
109 EnvironmentOptions::~EnvironmentOptions()
110 {
111 }
112
113 void EnvironmentOptions::SetLogFunction( const Dali::Integration::Log::LogFunction& logFunction )
114 {
115   mLogFunction = logFunction;
116 }
117
118 void EnvironmentOptions::InstallLogFunction() const
119 {
120   Dali::Integration::Log::InstallLogFunction( mLogFunction );
121 }
122
123 void EnvironmentOptions::UnInstallLogFunction() const
124 {
125   Dali::Integration::Log::UninstallLogFunction();
126 }
127
128 unsigned int EnvironmentOptions::GetNetworkControlMode() const
129 {
130   return mNetworkControl;
131 }
132 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
133 {
134   return mFpsFrequency;
135 }
136
137 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
138 {
139   return mUpdateStatusFrequency;
140 }
141
142 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
143 {
144   return mPerformanceStatsLevel;
145 }
146 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
147 {
148   return mPerformanceStatsFrequency;
149 }
150 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
151 {
152   return mPerformanceTimeStampOutput;
153 }
154
155 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
156 {
157   return mPanGestureLoggingLevel;
158 }
159
160 int EnvironmentOptions::GetPanGesturePredictionMode() const
161 {
162   return mPanGesturePredictionMode;
163 }
164
165 int EnvironmentOptions::GetPanGesturePredictionAmount() const
166 {
167   return mPanGesturePredictionAmount;
168 }
169
170 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
171 {
172   return mPanGestureMaxPredictionAmount;
173 }
174
175 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
176 {
177   return mPanGestureMinPredictionAmount;
178 }
179
180 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
181 {
182   return mPanGesturePredictionAmountAdjustment;
183 }
184
185 int EnvironmentOptions::GetPanGestureSmoothingMode() const
186 {
187   return mPanGestureSmoothingMode;
188 }
189
190 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
191 {
192   return mPanGestureSmoothingAmount;
193 }
194
195 int EnvironmentOptions::GetMinimumPanDistance() const
196 {
197   return mPanMinimumDistance;
198 }
199
200 int EnvironmentOptions::GetMinimumPanEvents() const
201 {
202   return mPanMinimumEvents;
203 }
204
205 unsigned int EnvironmentOptions::GetWindowWidth() const
206 {
207   return mWindowWidth;
208 }
209
210 unsigned int EnvironmentOptions::GetWindowHeight() const
211 {
212   return mWindowHeight;
213 }
214
215 void EnvironmentOptions::SetPanGesturePredictionMode( unsigned int mode )
216 {
217   mPanGesturePredictionMode = mode;
218 }
219
220 void EnvironmentOptions::SetPanGesturePredictionAmount( unsigned int amount )
221 {
222   mPanGesturePredictionAmount = amount;
223 }
224
225 void EnvironmentOptions::SetPanGestureMaximumPredictionAmount( unsigned int amount )
226 {
227   mPanGestureMaxPredictionAmount = amount;
228 }
229
230 void EnvironmentOptions::SetPanGestureMinimumPredictionAmount( unsigned int amount )
231 {
232   mPanGestureMinPredictionAmount = amount;
233 }
234
235 void EnvironmentOptions::SetPanGesturePredictionAmountAdjustment( unsigned int amount )
236 {
237   mPanGesturePredictionAmountAdjustment = amount;
238 }
239
240 void EnvironmentOptions::SetPanGestureSmoothingMode( unsigned int mode )
241 {
242   mPanGestureSmoothingMode = mode;
243 }
244
245 void EnvironmentOptions::SetPanGestureSmoothingAmount( float amount )
246 {
247   mPanGestureSmoothingAmount = amount;
248 }
249
250 void EnvironmentOptions::SetMinimumPanDistance( int distance )
251 {
252   mPanMinimumDistance = distance;
253 }
254
255 void EnvironmentOptions::SetMinimumPanEvents( int events )
256 {
257   mPanMinimumEvents = events;
258 }
259
260 void EnvironmentOptions::SetGlesCallTime( int time )
261 {
262   mGlesCallTime = time;
263 }
264
265 int EnvironmentOptions::GetGlesCallTime() const
266 {
267   return mGlesCallTime;
268 }
269
270 void EnvironmentOptions::SetWindowWidth( int width )
271 {
272   mWindowWidth = width;
273 }
274
275 void EnvironmentOptions::SetWindowHeight( int height )
276 {
277   mWindowHeight = height;
278 }
279
280 void EnvironmentOptions::SetWindowName( const char * name )
281 {
282   if ( name )
283   {
284     mWindowName = name;
285   }
286 }
287
288 const std::string& EnvironmentOptions::GetWindowName() const
289 {
290   return mWindowName;
291 }
292
293 bool EnvironmentOptions::PerformanceServerRequired() const
294 {
295   return ( (GetPerformanceStatsLoggingOptions() > 0) ||
296            ( GetPerformanceTimeStampOutput() > 0 ) ||
297            ( GetNetworkControlMode() > 0) );
298 }
299
300 void EnvironmentOptions::ParseEnvironmentOptions()
301 {
302   // get logging options
303   mFpsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_FPS_TRACKING, 0 );
304   mUpdateStatusFrequency = GetIntegerEnvironmentVariable( DALI_ENV_UPDATE_STATUS_INTERVAL, 0 );
305   mPerformanceStatsLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS, 0 );
306   mPerformanceStatsFrequency = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0 );
307   mPerformanceTimeStampOutput = GetIntegerEnvironmentVariable( DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0 );
308   mNetworkControl = GetIntegerEnvironmentVariable( DALI_ENV_NETWORK_CONTROL, 0 );
309   mPanGestureLoggingLevel = GetIntegerEnvironmentVariable( DALI_ENV_LOG_PAN_GESTURE, 0 );
310
311   int predictionMode;
312   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, predictionMode) )
313   {
314     SetPanGesturePredictionMode(predictionMode);
315   }
316   int predictionAmount(-1);
317   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT, predictionAmount) )
318   {
319     if( predictionAmount < 0 )
320     {
321       // do not support times in the past
322       predictionAmount = 0;
323     }
324     SetPanGesturePredictionAmount(predictionAmount);
325   }
326   int minPredictionAmount(-1);
327   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, minPredictionAmount) )
328   {
329     if( minPredictionAmount < 0 )
330     {
331       // do not support times in the past
332       minPredictionAmount = 0;
333     }
334     SetPanGestureMinimumPredictionAmount(minPredictionAmount);
335   }
336   int maxPredictionAmount(-1);
337   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT, maxPredictionAmount) )
338   {
339     if( minPredictionAmount > -1 && maxPredictionAmount < minPredictionAmount )
340     {
341       // maximum amount should not be smaller than minimum amount
342       maxPredictionAmount = minPredictionAmount;
343     }
344     SetPanGestureMaximumPredictionAmount(maxPredictionAmount);
345   }
346   int predictionAmountAdjustment(-1);
347   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, predictionAmountAdjustment) )
348   {
349     if( predictionAmountAdjustment < 0 )
350     {
351       // negative amount doesn't make sense
352       predictionAmountAdjustment = 0;
353     }
354     SetPanGesturePredictionAmountAdjustment(predictionAmountAdjustment);
355   }
356   int smoothingMode;
357   if( GetIntegerEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, smoothingMode) )
358   {
359     SetPanGestureSmoothingMode(smoothingMode);
360   }
361   float smoothingAmount = 1.0f;
362   if( GetFloatEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_AMOUNT, smoothingAmount) )
363   {
364     smoothingAmount = Clamp(smoothingAmount, 0.0f, 1.0f);
365     SetPanGestureSmoothingAmount(smoothingAmount);
366   }
367
368   int minimumDistance(-1);
369   if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, minimumDistance ))
370   {
371     SetMinimumPanDistance( minimumDistance );
372   }
373
374   int minimumEvents(-1);
375   if ( GetIntegerEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, minimumEvents ))
376   {
377     SetMinimumPanEvents( minimumEvents );
378   }
379
380   int glesCallTime(0);
381   if ( GetIntegerEnvironmentVariable(DALI_GLES_CALL_TIME, glesCallTime ))
382   {
383     SetGlesCallTime( glesCallTime );
384   }
385
386   int windowWidth(0), windowHeight(0);
387   if ( GetIntegerEnvironmentVariable( DALI_WINDOW_WIDTH, windowWidth ) && GetIntegerEnvironmentVariable( DALI_WINDOW_HEIGHT, windowHeight ) )
388   {
389     SetWindowWidth( windowWidth );
390     SetWindowHeight( windowHeight );
391   }
392
393   SetWindowName( GetCharEnvironmentVariable( DALI_WINDOW_NAME ) );
394 }
395
396 } // Adaptor
397
398 } // Internal
399
400 } // Dali