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