2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/system/common/environment-options.h>
22 #include <dali/integration-api/render-controller.h>
23 #include <dali/public-api/math/math-utils.h>
28 #include <dali/internal/system/common/environment-variables.h>
29 #include <dali/internal/trace/common/trace-factory.h>
39 const unsigned int DEFAULT_STATISTICS_LOG_FREQUENCY = 2;
40 const int DEFAULT_MULTI_SAMPLING_LEVEL = -1;
41 const bool DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING = true;
42 const bool DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING = true;
43 const bool DEFAULT_PARTIAL_UPDATE_REQUIRED_SETTING = true;
45 unsigned int GetEnvironmentVariable(const char* variable, unsigned int defaultValue)
47 const char* variableParameter = std::getenv(variable);
49 // if the parameter exists convert it to an integer, else return the default value
50 unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
54 bool GetEnvironmentVariable(const char* variable, int& intValue)
56 const char* variableParameter = std::getenv(variable);
58 if(!variableParameter)
62 // if the parameter exists convert it to an integer, else return the default value
63 intValue = std::atoi(variableParameter);
67 bool GetEnvironmentVariable(const char* variable, float& floatValue)
69 const char* variableParameter = std::getenv(variable);
71 if(!variableParameter)
75 // if the parameter exists convert it to an integer, else return the default value
76 floatValue = std::atof(variableParameter);
80 void SetFromEnvironmentVariable(const char* variable, std::string& stringValue)
82 const char* charValue = std::getenv(variable);
85 stringValue = charValue;
89 template<typename Type>
90 void SetFromEnvironmentVariable(const char* variable, Type& memberVariable)
92 Type envVarValue = -1;
93 if(GetEnvironmentVariable(variable, envVarValue))
95 memberVariable = envVarValue;
99 template<typename Type>
100 void SetFromEnvironmentVariable(const char* variable, std::function<void(Type)> function)
102 Type envVarValue = -1;
103 if(GetEnvironmentVariable(variable, envVarValue))
105 function(envVarValue);
109 /// Provides a functor which ensures a non-negative number is set for the given member variable
112 MinimumZero(int& memberValue)
113 : mMemberValue(memberValue)
117 void operator()(int value)
119 // Negative Amounts do not make sense
120 mMemberValue = std::max(0, value);
126 /// Provides a functor which clamps the environment variable between 0.0f and 1.0f
127 struct ClampBetweenZeroAndOne
129 ClampBetweenZeroAndOne(float& memberValue)
130 : mMemberValue(memberValue)
134 void operator()(float value)
136 value = Clamp(value, 0.0f, 1.0f);
137 mMemberValue = value;
143 /// Provides a functor which only sets the member variable if the environment variable value is greater than the specified constant
146 GreaterThan(unsigned int& memberValue, int greaterThanValue)
147 : mMemberValue(memberValue),
148 mGreaterThanValue(greaterThanValue)
152 void operator()(int value)
154 if(value > mGreaterThanValue)
156 mMemberValue = value;
160 unsigned int& mMemberValue;
161 const int mGreaterThanValue;
164 /// Provides a functor which sets the member to 1 if if the environment variable value is not zero
165 struct EnableIfNonZero
167 EnableIfNonZero(int& memberValue)
168 : mMemberValue(memberValue)
172 void operator()(int value)
174 mMemberValue = (value == 0) ? 0 : 1;
180 /// Provides a functor which sets the member to false if the environment variable value is not zero
181 struct DisableIfNonZero
183 DisableIfNonZero(bool& memberValue)
184 : mMemberValue(memberValue)
188 void operator()(int value)
192 mMemberValue = false;
199 } // unnamed namespace
201 EnvironmentOptions::EnvironmentOptions()
202 : mLogFunction(NULL),
207 mUpdateStatusFrequency(0),
208 mObjectProfilerInterval(0),
209 mPerformanceStatsLevel(0),
210 mPerformanceStatsFrequency(DEFAULT_STATISTICS_LOG_FREQUENCY),
211 mPerformanceTimeStampOutput(0),
212 mPanGestureLoggingLevel(0),
215 mRenderRefreshRate(1u),
217 mRenderToFboInterval(0u),
218 mPanGesturePredictionMode(-1),
219 mPanGesturePredictionAmount(-1), ///< only sets value in pan gesture if greater than 0
220 mPanGestureMaxPredictionAmount(-1),
221 mPanGestureMinPredictionAmount(-1),
222 mPanGesturePredictionAmountAdjustment(-1),
223 mPanGestureSmoothingMode(-1),
224 mPanGestureSmoothingAmount(-1.0f),
225 mPanGestureUseActualTimes(-1),
226 mPanGestureInterpolationTimeRange(-1),
227 mPanGestureScalarOnlyPredictionEnabled(-1),
228 mPanGestureTwoPointPredictionEnabled(-1),
229 mPanGestureTwoPointInterpolatePastTime(-1),
230 mPanGestureTwoPointVelocityBias(-1.0f),
231 mPanGestureTwoPointAccelerationBias(-1.0f),
232 mPanGestureMultitapSmoothingRange(-1),
233 mPanMinimumDistance(-1),
234 mPanMinimumEvents(-1),
235 mPinchMinimumDistance(-1.0f),
236 mPinchMinimumTouchEvents(-1),
237 mPinchMinimumTouchEventsAfterStart(-1),
238 mRotationMinimumTouchEvents(-1),
239 mRotationMinimumTouchEventsAfterStart(-1),
240 mLongPressMinimumHoldingTime(-1),
241 mTapMaximumAllowedTime(-1),
243 mMultiSamplingLevel(DEFAULT_MULTI_SAMPLING_LEVEL),
244 mThreadingMode(ThreadingMode::COMBINED_UPDATE_RENDER),
245 mGlesCallAccumulate(false),
246 mDepthBufferRequired(DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING),
247 mStencilBufferRequired(DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING),
248 mPartialUpdateRequired(DEFAULT_PARTIAL_UPDATE_REQUIRED_SETTING)
250 ParseEnvironmentOptions();
253 EnvironmentOptions::~EnvironmentOptions()
257 void EnvironmentOptions::CreateTraceManager(PerformanceInterface* performanceInterface)
259 mTraceManager = TraceManagerFactory::CreateTraceFactory(performanceInterface);
262 void EnvironmentOptions::InstallTraceFunction() const
266 mTraceManager->Initialise();
270 void EnvironmentOptions::SetLogFunction(const Dali::Integration::Log::LogFunction& logFunction)
272 mLogFunction = logFunction;
275 void EnvironmentOptions::InstallLogFunction() const
277 Dali::Integration::Log::InstallLogFunction(mLogFunction);
280 void EnvironmentOptions::UnInstallLogFunction() const
282 Dali::Integration::Log::UninstallLogFunction();
285 unsigned int EnvironmentOptions::GetNetworkControlMode() const
287 return mNetworkControl;
289 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
291 return mFpsFrequency;
294 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
296 return mUpdateStatusFrequency;
299 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
301 return mObjectProfilerInterval;
304 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
306 return mPerformanceStatsLevel;
308 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
310 return mPerformanceStatsFrequency;
312 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
314 return mPerformanceTimeStampOutput;
317 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
319 return mPanGestureLoggingLevel;
322 int EnvironmentOptions::GetPanGesturePredictionMode() const
324 return mPanGesturePredictionMode;
327 int EnvironmentOptions::GetPanGesturePredictionAmount() const
329 return mPanGesturePredictionAmount;
332 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
334 return mPanGestureMaxPredictionAmount;
337 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
339 return mPanGestureMinPredictionAmount;
342 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
344 return mPanGesturePredictionAmountAdjustment;
347 int EnvironmentOptions::GetPanGestureSmoothingMode() const
349 return mPanGestureSmoothingMode;
352 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
354 return mPanGestureSmoothingAmount;
357 int EnvironmentOptions::GetPanGestureUseActualTimes() const
359 return mPanGestureUseActualTimes;
362 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
364 return mPanGestureInterpolationTimeRange;
367 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
369 return mPanGestureScalarOnlyPredictionEnabled;
372 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
374 return mPanGestureTwoPointPredictionEnabled;
377 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
379 return mPanGestureTwoPointInterpolatePastTime;
382 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
384 return mPanGestureTwoPointVelocityBias;
387 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
389 return mPanGestureTwoPointAccelerationBias;
392 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
394 return mPanGestureMultitapSmoothingRange;
397 int EnvironmentOptions::GetMinimumPanDistance() const
399 return mPanMinimumDistance;
402 int EnvironmentOptions::GetMinimumPanEvents() const
404 return mPanMinimumEvents;
407 float EnvironmentOptions::GetMinimumPinchDistance() const
409 return mPinchMinimumDistance;
412 int EnvironmentOptions::GetMinimumPinchTouchEvents() const
414 return mPinchMinimumTouchEvents;
417 int EnvironmentOptions::GetMinimumPinchTouchEventsAfterStart() const
419 return mPinchMinimumTouchEventsAfterStart;
422 int EnvironmentOptions::GetMinimumRotationTouchEvents() const
424 return mRotationMinimumTouchEvents;
427 int EnvironmentOptions::GetMinimumRotationTouchEventsAfterStart() const
429 return mRotationMinimumTouchEventsAfterStart;
432 int EnvironmentOptions::GetLongPressMinimumHoldingTime() const
434 return mLongPressMinimumHoldingTime;
437 int EnvironmentOptions::GetTapMaximumAllowedTime() const
439 return mTapMaximumAllowedTime;
442 unsigned int EnvironmentOptions::GetWindowWidth() const
447 unsigned int EnvironmentOptions::GetWindowHeight() const
449 return mWindowHeight;
452 int EnvironmentOptions::GetGlesCallTime() const
454 return mGlesCallTime;
457 bool EnvironmentOptions::GetGlesCallAccumulate() const
459 return mGlesCallAccumulate;
462 const std::string& EnvironmentOptions::GetWindowName() const
467 const std::string& EnvironmentOptions::GetWindowClassName() const
469 return mWindowClassName;
472 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
474 return mThreadingMode;
477 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
479 return mRenderRefreshRate;
482 int EnvironmentOptions::GetMultiSamplingLevel() const
484 return mMultiSamplingLevel;
487 unsigned int EnvironmentOptions::GetMaxTextureSize() const
489 return mMaxTextureSize;
492 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
494 return mRenderToFboInterval;
497 bool EnvironmentOptions::PerformanceServerRequired() const
499 return ((GetPerformanceStatsLoggingOptions() > 0) ||
500 (GetPerformanceTimeStampOutput() > 0) ||
501 (GetNetworkControlMode() > 0));
504 bool EnvironmentOptions::DepthBufferRequired() const
506 return mDepthBufferRequired;
509 bool EnvironmentOptions::StencilBufferRequired() const
511 return mStencilBufferRequired;
514 bool EnvironmentOptions::PartialUpdateRequired() const
516 return mPartialUpdateRequired;
519 void EnvironmentOptions::ParseEnvironmentOptions()
521 // get logging options
522 mFpsFrequency = GetEnvironmentVariable(DALI_ENV_FPS_TRACKING, 0);
523 mUpdateStatusFrequency = GetEnvironmentVariable(DALI_ENV_UPDATE_STATUS_INTERVAL, 0);
524 mObjectProfilerInterval = GetEnvironmentVariable(DALI_ENV_OBJECT_PROFILER_INTERVAL, 0);
525 mPerformanceStatsLevel = GetEnvironmentVariable(DALI_ENV_LOG_PERFORMANCE_STATS, 0);
526 mPerformanceStatsFrequency = GetEnvironmentVariable(DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0);
527 mPerformanceTimeStampOutput = GetEnvironmentVariable(DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0);
528 mNetworkControl = GetEnvironmentVariable(DALI_ENV_NETWORK_CONTROL, 0);
529 mPanGestureLoggingLevel = GetEnvironmentVariable(DALI_ENV_LOG_PAN_GESTURE, 0);
531 SetFromEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, mPanGesturePredictionMode);
532 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_PREDICTION_AMOUNT, MinimumZero(mPanGesturePredictionAmount));
533 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, MinimumZero(mPanGestureMinPredictionAmount));
534 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT,
535 [&](int maxPredictionAmount) {
536 if(mPanGestureMinPredictionAmount > -1 && maxPredictionAmount < mPanGestureMinPredictionAmount)
538 // maximum amount should not be smaller than minimum amount
539 maxPredictionAmount = mPanGestureMinPredictionAmount;
541 mPanGestureMaxPredictionAmount = maxPredictionAmount;
543 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, MinimumZero(mPanGesturePredictionAmountAdjustment));
544 SetFromEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, mPanGestureSmoothingMode);
545 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_SMOOTHING_AMOUNT, ClampBetweenZeroAndOne(mPanGestureSmoothingAmount));
546 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_USE_ACTUAL_TIMES, EnableIfNonZero(mPanGestureUseActualTimes));
547 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, MinimumZero(mPanGestureInterpolationTimeRange));
548 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, EnableIfNonZero(mPanGestureScalarOnlyPredictionEnabled));
549 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, EnableIfNonZero(mPanGestureTwoPointPredictionEnabled));
550 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, MinimumZero(mPanGestureTwoPointInterpolatePastTime));
551 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, ClampBetweenZeroAndOne(mPanGestureTwoPointVelocityBias));
552 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, ClampBetweenZeroAndOne(mPanGestureTwoPointAccelerationBias));
553 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, MinimumZero(mPanGestureMultitapSmoothingRange));
554 SetFromEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, mPanMinimumDistance);
555 SetFromEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, mPanMinimumEvents);
557 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_DISTANCE, mPinchMinimumDistance);
558 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS, mPinchMinimumTouchEvents);
559 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS_AFTER_START, mPinchMinimumTouchEventsAfterStart);
561 SetFromEnvironmentVariable(DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS, mRotationMinimumTouchEvents);
562 SetFromEnvironmentVariable(DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS_AFTER_START, mRotationMinimumTouchEventsAfterStart);
564 SetFromEnvironmentVariable(DALI_ENV_LONG_PRESS_MINIMUM_HOLDING_TIME, mLongPressMinimumHoldingTime);
565 SetFromEnvironmentVariable(DALI_ENV_TAP_MAXIMUM_ALLOWED_TIME, mTapMaximumAllowedTime);
567 SetFromEnvironmentVariable(DALI_GLES_CALL_TIME, mGlesCallTime);
568 SetFromEnvironmentVariable<int>(DALI_GLES_CALL_ACCUMULATE, [&](int glesCallAccumulate) { mGlesCallAccumulate = glesCallAccumulate != 0; });
570 int windowWidth(0), windowHeight(0);
571 if(GetEnvironmentVariable(DALI_WINDOW_WIDTH, windowWidth) && GetEnvironmentVariable(DALI_WINDOW_HEIGHT, windowHeight))
573 mWindowWidth = windowWidth;
574 mWindowHeight = windowHeight;
576 SetFromEnvironmentVariable(DALI_WINDOW_NAME, mWindowName);
577 SetFromEnvironmentVariable(DALI_WINDOW_CLASS_NAME, mWindowClassName);
579 SetFromEnvironmentVariable<int>(DALI_THREADING_MODE,
580 [&](int threadingMode) {
581 switch(threadingMode)
583 case ThreadingMode::COMBINED_UPDATE_RENDER:
585 mThreadingMode = static_cast<ThreadingMode::Type>(threadingMode);
591 SetFromEnvironmentVariable<int>(DALI_REFRESH_RATE, GreaterThan(mRenderRefreshRate, 1));
593 SetFromEnvironmentVariable(DALI_ENV_MULTI_SAMPLING_LEVEL, mMultiSamplingLevel);
595 SetFromEnvironmentVariable<int>(DALI_ENV_MAX_TEXTURE_SIZE, GreaterThan(mMaxTextureSize, 0));
597 mRenderToFboInterval = GetEnvironmentVariable(DALI_RENDER_TO_FBO, 0u);
599 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_DEPTH_BUFFER,
600 [&](int depthBufferRequired) {
601 if(depthBufferRequired > 0)
603 mDepthBufferRequired = false;
604 mStencilBufferRequired = false; // Disable stencil buffer as well
607 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_STENCIL_BUFFER, DisableIfNonZero(mStencilBufferRequired));
609 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_PARTIAL_UPDATE, DisableIfNonZero(mPartialUpdateRequired));
612 } // namespace Adaptor
614 } // namespace Internal