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