2 * Copyright (c) 2022 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 mMemoryPoolInterval(0),
210 mPerformanceStatsLevel(0),
211 mPerformanceStatsFrequency(DEFAULT_STATISTICS_LOG_FREQUENCY),
212 mPerformanceTimeStampOutput(0),
213 mPanGestureLoggingLevel(0),
216 mRenderRefreshRate(1u),
218 mRenderToFboInterval(0u),
219 mPanGesturePredictionMode(-1),
220 mPanGesturePredictionAmount(-1), ///< only sets value in pan gesture if greater than 0
221 mPanGestureMaxPredictionAmount(-1),
222 mPanGestureMinPredictionAmount(-1),
223 mPanGesturePredictionAmountAdjustment(-1),
224 mPanGestureSmoothingMode(-1),
225 mPanGestureSmoothingAmount(-1.0f),
226 mPanGestureUseActualTimes(-1),
227 mPanGestureInterpolationTimeRange(-1),
228 mPanGestureScalarOnlyPredictionEnabled(-1),
229 mPanGestureTwoPointPredictionEnabled(-1),
230 mPanGestureTwoPointInterpolatePastTime(-1),
231 mPanGestureTwoPointVelocityBias(-1.0f),
232 mPanGestureTwoPointAccelerationBias(-1.0f),
233 mPanGestureMultitapSmoothingRange(-1),
234 mPanMinimumDistance(-1),
235 mPanMinimumEvents(-1),
236 mPinchMinimumDistance(-1.0f),
237 mPinchMinimumTouchEvents(-1),
238 mPinchMinimumTouchEventsAfterStart(-1),
239 mRotationMinimumTouchEvents(-1),
240 mRotationMinimumTouchEventsAfterStart(-1),
241 mLongPressMinimumHoldingTime(-1),
242 mTapMaximumAllowedTime(-1),
244 mMultiSamplingLevel(DEFAULT_MULTI_SAMPLING_LEVEL),
245 mThreadingMode(ThreadingMode::COMBINED_UPDATE_RENDER),
246 mGlesCallAccumulate(false),
247 mDepthBufferRequired(DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING),
248 mStencilBufferRequired(DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING),
249 mPartialUpdateRequired(DEFAULT_PARTIAL_UPDATE_REQUIRED_SETTING)
251 ParseEnvironmentOptions();
254 EnvironmentOptions::~EnvironmentOptions()
258 void EnvironmentOptions::CreateTraceManager(PerformanceInterface* performanceInterface)
260 mTraceManager = TraceManagerFactory::CreateTraceFactory(performanceInterface);
263 void EnvironmentOptions::InstallTraceFunction() const
267 mTraceManager->Initialise();
271 void EnvironmentOptions::SetLogFunction(const Dali::Integration::Log::LogFunction& logFunction)
273 mLogFunction = logFunction;
276 void EnvironmentOptions::InstallLogFunction() const
278 Dali::Integration::Log::InstallLogFunction(mLogFunction);
281 void EnvironmentOptions::UnInstallLogFunction() const
283 Dali::Integration::Log::UninstallLogFunction();
286 unsigned int EnvironmentOptions::GetNetworkControlMode() const
288 return mNetworkControl;
290 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
292 return mFpsFrequency;
295 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
297 return mUpdateStatusFrequency;
300 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
302 return mObjectProfilerInterval;
304 unsigned int EnvironmentOptions::GetMemoryPoolInterval() const
306 return mMemoryPoolInterval;
308 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
310 return mPerformanceStatsLevel;
312 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
314 return mPerformanceStatsFrequency;
316 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
318 return mPerformanceTimeStampOutput;
321 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
323 return mPanGestureLoggingLevel;
326 int EnvironmentOptions::GetPanGesturePredictionMode() const
328 return mPanGesturePredictionMode;
331 int EnvironmentOptions::GetPanGesturePredictionAmount() const
333 return mPanGesturePredictionAmount;
336 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
338 return mPanGestureMaxPredictionAmount;
341 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
343 return mPanGestureMinPredictionAmount;
346 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
348 return mPanGesturePredictionAmountAdjustment;
351 int EnvironmentOptions::GetPanGestureSmoothingMode() const
353 return mPanGestureSmoothingMode;
356 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
358 return mPanGestureSmoothingAmount;
361 int EnvironmentOptions::GetPanGestureUseActualTimes() const
363 return mPanGestureUseActualTimes;
366 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
368 return mPanGestureInterpolationTimeRange;
371 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
373 return mPanGestureScalarOnlyPredictionEnabled;
376 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
378 return mPanGestureTwoPointPredictionEnabled;
381 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
383 return mPanGestureTwoPointInterpolatePastTime;
386 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
388 return mPanGestureTwoPointVelocityBias;
391 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
393 return mPanGestureTwoPointAccelerationBias;
396 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
398 return mPanGestureMultitapSmoothingRange;
401 int EnvironmentOptions::GetMinimumPanDistance() const
403 return mPanMinimumDistance;
406 int EnvironmentOptions::GetMinimumPanEvents() const
408 return mPanMinimumEvents;
411 float EnvironmentOptions::GetMinimumPinchDistance() const
413 return mPinchMinimumDistance;
416 int EnvironmentOptions::GetMinimumPinchTouchEvents() const
418 return mPinchMinimumTouchEvents;
421 int EnvironmentOptions::GetMinimumPinchTouchEventsAfterStart() const
423 return mPinchMinimumTouchEventsAfterStart;
426 int EnvironmentOptions::GetMinimumRotationTouchEvents() const
428 return mRotationMinimumTouchEvents;
431 int EnvironmentOptions::GetMinimumRotationTouchEventsAfterStart() const
433 return mRotationMinimumTouchEventsAfterStart;
436 int EnvironmentOptions::GetLongPressMinimumHoldingTime() const
438 return mLongPressMinimumHoldingTime;
441 int EnvironmentOptions::GetTapMaximumAllowedTime() const
443 return mTapMaximumAllowedTime;
446 unsigned int EnvironmentOptions::GetWindowWidth() const
451 unsigned int EnvironmentOptions::GetWindowHeight() const
453 return mWindowHeight;
456 int EnvironmentOptions::GetGlesCallTime() const
458 return mGlesCallTime;
461 bool EnvironmentOptions::GetGlesCallAccumulate() const
463 return mGlesCallAccumulate;
466 const std::string& EnvironmentOptions::GetWindowName() const
471 const std::string& EnvironmentOptions::GetWindowClassName() const
473 return mWindowClassName;
476 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
478 return mThreadingMode;
481 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
483 return mRenderRefreshRate;
486 int EnvironmentOptions::GetMultiSamplingLevel() const
488 return mMultiSamplingLevel;
491 unsigned int EnvironmentOptions::GetMaxTextureSize() const
493 return mMaxTextureSize;
496 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
498 return mRenderToFboInterval;
501 bool EnvironmentOptions::PerformanceServerRequired() const
503 return ((GetPerformanceStatsLoggingOptions() > 0) ||
504 (GetPerformanceTimeStampOutput() > 0) ||
505 (GetNetworkControlMode() > 0));
508 bool EnvironmentOptions::DepthBufferRequired() const
510 return mDepthBufferRequired;
513 bool EnvironmentOptions::StencilBufferRequired() const
515 return mStencilBufferRequired;
518 bool EnvironmentOptions::PartialUpdateRequired() const
520 return mPartialUpdateRequired;
523 void EnvironmentOptions::ParseEnvironmentOptions()
525 // get logging options
526 mFpsFrequency = GetEnvironmentVariable(DALI_ENV_FPS_TRACKING, 0);
527 mUpdateStatusFrequency = GetEnvironmentVariable(DALI_ENV_UPDATE_STATUS_INTERVAL, 0);
528 mObjectProfilerInterval = GetEnvironmentVariable(DALI_ENV_OBJECT_PROFILER_INTERVAL, 0);
529 mMemoryPoolInterval = GetEnvironmentVariable(DALI_ENV_MEMORY_POOL_INTERVAL, 0);
530 mPerformanceStatsLevel = GetEnvironmentVariable(DALI_ENV_LOG_PERFORMANCE_STATS, 0);
531 mPerformanceStatsFrequency = GetEnvironmentVariable(DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0);
532 mPerformanceTimeStampOutput = GetEnvironmentVariable(DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0);
533 mNetworkControl = GetEnvironmentVariable(DALI_ENV_NETWORK_CONTROL, 0);
534 mPanGestureLoggingLevel = GetEnvironmentVariable(DALI_ENV_LOG_PAN_GESTURE, 0);
536 SetFromEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, mPanGesturePredictionMode);
537 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_PREDICTION_AMOUNT, MinimumZero(mPanGesturePredictionAmount));
538 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, MinimumZero(mPanGestureMinPredictionAmount));
539 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT,
540 [&](int maxPredictionAmount) {
541 if(mPanGestureMinPredictionAmount > -1 && maxPredictionAmount < mPanGestureMinPredictionAmount)
543 // maximum amount should not be smaller than minimum amount
544 maxPredictionAmount = mPanGestureMinPredictionAmount;
546 mPanGestureMaxPredictionAmount = maxPredictionAmount;
548 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, MinimumZero(mPanGesturePredictionAmountAdjustment));
549 SetFromEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, mPanGestureSmoothingMode);
550 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_SMOOTHING_AMOUNT, ClampBetweenZeroAndOne(mPanGestureSmoothingAmount));
551 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_USE_ACTUAL_TIMES, EnableIfNonZero(mPanGestureUseActualTimes));
552 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, MinimumZero(mPanGestureInterpolationTimeRange));
553 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, EnableIfNonZero(mPanGestureScalarOnlyPredictionEnabled));
554 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, EnableIfNonZero(mPanGestureTwoPointPredictionEnabled));
555 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, MinimumZero(mPanGestureTwoPointInterpolatePastTime));
556 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, ClampBetweenZeroAndOne(mPanGestureTwoPointVelocityBias));
557 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, ClampBetweenZeroAndOne(mPanGestureTwoPointAccelerationBias));
558 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, MinimumZero(mPanGestureMultitapSmoothingRange));
559 SetFromEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, mPanMinimumDistance);
560 SetFromEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, mPanMinimumEvents);
562 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_DISTANCE, mPinchMinimumDistance);
563 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS, mPinchMinimumTouchEvents);
564 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS_AFTER_START, mPinchMinimumTouchEventsAfterStart);
566 SetFromEnvironmentVariable(DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS, mRotationMinimumTouchEvents);
567 SetFromEnvironmentVariable(DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS_AFTER_START, mRotationMinimumTouchEventsAfterStart);
569 SetFromEnvironmentVariable(DALI_ENV_LONG_PRESS_MINIMUM_HOLDING_TIME, mLongPressMinimumHoldingTime);
570 SetFromEnvironmentVariable(DALI_ENV_TAP_MAXIMUM_ALLOWED_TIME, mTapMaximumAllowedTime);
572 SetFromEnvironmentVariable(DALI_GLES_CALL_TIME, mGlesCallTime);
573 SetFromEnvironmentVariable<int>(DALI_GLES_CALL_ACCUMULATE, [&](int glesCallAccumulate) { mGlesCallAccumulate = glesCallAccumulate != 0; });
575 int windowWidth(0), windowHeight(0);
576 if(GetEnvironmentVariable(DALI_WINDOW_WIDTH, windowWidth) && GetEnvironmentVariable(DALI_WINDOW_HEIGHT, windowHeight))
578 mWindowWidth = windowWidth;
579 mWindowHeight = windowHeight;
581 SetFromEnvironmentVariable(DALI_WINDOW_NAME, mWindowName);
582 SetFromEnvironmentVariable(DALI_WINDOW_CLASS_NAME, mWindowClassName);
584 SetFromEnvironmentVariable<int>(DALI_THREADING_MODE,
585 [&](int threadingMode) {
586 switch(threadingMode)
588 case ThreadingMode::COMBINED_UPDATE_RENDER:
590 mThreadingMode = static_cast<ThreadingMode::Type>(threadingMode);
596 SetFromEnvironmentVariable<int>(DALI_REFRESH_RATE, GreaterThan(mRenderRefreshRate, 1));
598 SetFromEnvironmentVariable(DALI_ENV_MULTI_SAMPLING_LEVEL, mMultiSamplingLevel);
600 SetFromEnvironmentVariable<int>(DALI_ENV_MAX_TEXTURE_SIZE, GreaterThan(mMaxTextureSize, 0));
602 mRenderToFboInterval = GetEnvironmentVariable(DALI_RENDER_TO_FBO, 0u);
604 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_DEPTH_BUFFER,
605 [&](int depthBufferRequired) {
606 if(depthBufferRequired > 0)
608 mDepthBufferRequired = false;
609 mStencilBufferRequired = false; // Disable stencil buffer as well
612 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_STENCIL_BUFFER, DisableIfNonZero(mStencilBufferRequired));
614 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_PARTIAL_UPDATE, DisableIfNonZero(mPartialUpdateRequired));
617 } // namespace Adaptor
619 } // namespace Internal