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