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