2 * Copyright (c) 2024 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/devel-api/adaptor-framework/environment-variable.h>
29 #include <dali/internal/system/common/environment-variables.h>
30 #include <dali/internal/trace/common/trace-factory.h>
40 const unsigned int DEFAULT_STATISTICS_LOG_FREQUENCY = 2;
41 const int DEFAULT_MULTI_SAMPLING_LEVEL = -1;
42 const bool DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING = true;
43 const bool DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING = true;
44 const bool DEFAULT_PARTIAL_UPDATE_REQUIRED_SETTING = true;
45 const bool DEFAULT_VSYNC_RENDER_REQUIRED_SETTING = true;
47 unsigned int GetEnvironmentVariable(const char* variable, unsigned int defaultValue)
49 const char* variableParameter = Dali::EnvironmentVariable::GetEnvironmentVariable(variable);
51 // if the parameter exists convert it to an integer, else return the default value
52 unsigned int intValue = variableParameter ? std::atoi(variableParameter) : defaultValue;
56 bool GetEnvironmentVariable(const char* variable, int& intValue)
58 const char* variableParameter = Dali::EnvironmentVariable::GetEnvironmentVariable(variable);
60 if(!variableParameter)
64 // if the parameter exists convert it to an integer, else return the default value
65 intValue = std::atoi(variableParameter);
69 bool GetEnvironmentVariable(const char* variable, float& floatValue)
71 const char* variableParameter = Dali::EnvironmentVariable::GetEnvironmentVariable(variable);
73 if(!variableParameter)
77 // if the parameter exists convert it to an integer, else return the default value
78 floatValue = std::atof(variableParameter);
82 void SetFromEnvironmentVariable(const char* variable, std::string& stringValue)
84 const char* charValue = Dali::EnvironmentVariable::GetEnvironmentVariable(variable);
87 stringValue = charValue;
91 template<typename Type>
92 void SetFromEnvironmentVariable(const char* variable, Type& memberVariable)
94 Type envVarValue = -1;
95 if(GetEnvironmentVariable(variable, envVarValue))
97 memberVariable = envVarValue;
101 template<typename Type>
102 void SetFromEnvironmentVariable(const char* variable, std::function<void(Type)> function)
104 Type envVarValue = -1;
105 if(GetEnvironmentVariable(variable, envVarValue))
107 function(envVarValue);
111 /// Provides a functor which ensures a non-negative number is set for the given member variable
114 MinimumZero(int& memberValue)
115 : mMemberValue(memberValue)
119 void operator()(int value)
121 // Negative Amounts do not make sense
122 mMemberValue = std::max(0, value);
128 /// Provides a functor which clamps the environment variable between 0.0f and 1.0f
129 struct ClampBetweenZeroAndOne
131 ClampBetweenZeroAndOne(float& memberValue)
132 : mMemberValue(memberValue)
136 void operator()(float value)
138 value = Clamp(value, 0.0f, 1.0f);
139 mMemberValue = value;
145 /// Provides a functor which only sets the member variable if the environment variable value is greater than the specified constant
148 GreaterThan(unsigned int& memberValue, int greaterThanValue)
149 : mMemberValue(memberValue),
150 mGreaterThanValue(greaterThanValue)
154 void operator()(int value)
156 if(value > mGreaterThanValue)
158 mMemberValue = value;
162 unsigned int& mMemberValue;
163 const int mGreaterThanValue;
166 /// Provides a functor which sets the member to 1 if if the environment variable value is not zero
167 struct EnableIfNonZero
169 EnableIfNonZero(int& memberValue)
170 : mMemberValue(memberValue)
174 void operator()(int value)
176 mMemberValue = (value == 0) ? 0 : 1;
182 /// Provides a functor which sets the member to false if the environment variable value is not zero
183 struct DisableIfNonZero
185 DisableIfNonZero(bool& memberValue)
186 : mMemberValue(memberValue)
190 void operator()(int value)
194 mMemberValue = false;
201 } // unnamed namespace
203 EnvironmentOptions::EnvironmentOptions()
204 : mLogFunction(NULL),
209 mUpdateStatusFrequency(0),
210 mObjectProfilerInterval(0),
211 mMemoryPoolInterval(0),
212 mPerformanceStatsLevel(0),
213 mPerformanceStatsFrequency(DEFAULT_STATISTICS_LOG_FREQUENCY),
214 mPerformanceTimeStampOutput(0),
215 mPanGestureLoggingLevel(0),
218 mRenderRefreshRate(1u),
220 mRenderToFboInterval(0u),
221 mPanGesturePredictionMode(-1),
222 mPanGesturePredictionAmount(-1), ///< only sets value in pan gesture if greater than 0
223 mPanGestureMaxPredictionAmount(-1),
224 mPanGestureMinPredictionAmount(-1),
225 mPanGesturePredictionAmountAdjustment(-1),
226 mPanGestureSmoothingMode(-1),
227 mPanGestureSmoothingAmount(-1.0f),
228 mPanGestureUseActualTimes(-1),
229 mPanGestureInterpolationTimeRange(-1),
230 mPanGestureScalarOnlyPredictionEnabled(-1),
231 mPanGestureTwoPointPredictionEnabled(-1),
232 mPanGestureTwoPointInterpolatePastTime(-1),
233 mPanGestureTwoPointVelocityBias(-1.0f),
234 mPanGestureTwoPointAccelerationBias(-1.0f),
235 mPanGestureMultitapSmoothingRange(-1),
236 mPanMinimumDistance(-1),
237 mPanMinimumEvents(-1),
238 mPinchMinimumDistance(-1.0f),
239 mPinchMinimumTouchEvents(-1),
240 mPinchMinimumTouchEventsAfterStart(-1),
241 mRotationMinimumTouchEvents(-1),
242 mRotationMinimumTouchEventsAfterStart(-1),
243 mLongPressMinimumHoldingTime(-1),
244 mTapMaximumAllowedTime(-1),
246 mMultiSamplingLevel(DEFAULT_MULTI_SAMPLING_LEVEL),
247 mThreadingMode(ThreadingMode::COMBINED_UPDATE_RENDER),
248 mGlesCallAccumulate(false),
249 mDepthBufferRequired(DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING),
250 mStencilBufferRequired(DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING),
251 mPartialUpdateRequired(DEFAULT_PARTIAL_UPDATE_REQUIRED_SETTING),
252 mVsyncRenderRequired(DEFAULT_VSYNC_RENDER_REQUIRED_SETTING)
254 ParseEnvironmentOptions();
257 EnvironmentOptions::~EnvironmentOptions()
261 void EnvironmentOptions::CreateTraceManager(PerformanceInterface* performanceInterface)
263 mTraceManager = TraceManagerFactory::CreateTraceFactory(performanceInterface);
266 void EnvironmentOptions::InstallTraceFunction() const
270 mTraceManager->Initialise();
274 void EnvironmentOptions::SetLogFunction(const Dali::Integration::Log::LogFunction& logFunction)
276 mLogFunction = logFunction;
279 void EnvironmentOptions::InstallLogFunction() const
281 Dali::Integration::Log::InstallLogFunction(mLogFunction);
284 void EnvironmentOptions::UnInstallLogFunction() const
286 Dali::Integration::Log::UninstallLogFunction();
289 unsigned int EnvironmentOptions::GetNetworkControlMode() const
291 return mNetworkControl;
293 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
295 return mFpsFrequency;
298 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
300 return mUpdateStatusFrequency;
303 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
305 return mObjectProfilerInterval;
307 unsigned int EnvironmentOptions::GetMemoryPoolInterval() const
309 return mMemoryPoolInterval;
311 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
313 return mPerformanceStatsLevel;
315 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
317 return mPerformanceStatsFrequency;
319 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
321 return mPerformanceTimeStampOutput;
324 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
326 return mPanGestureLoggingLevel;
329 int EnvironmentOptions::GetPanGesturePredictionMode() const
331 return mPanGesturePredictionMode;
334 int EnvironmentOptions::GetPanGesturePredictionAmount() const
336 return mPanGesturePredictionAmount;
339 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
341 return mPanGestureMaxPredictionAmount;
344 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
346 return mPanGestureMinPredictionAmount;
349 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
351 return mPanGesturePredictionAmountAdjustment;
354 int EnvironmentOptions::GetPanGestureSmoothingMode() const
356 return mPanGestureSmoothingMode;
359 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
361 return mPanGestureSmoothingAmount;
364 int EnvironmentOptions::GetPanGestureUseActualTimes() const
366 return mPanGestureUseActualTimes;
369 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
371 return mPanGestureInterpolationTimeRange;
374 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
376 return mPanGestureScalarOnlyPredictionEnabled;
379 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
381 return mPanGestureTwoPointPredictionEnabled;
384 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
386 return mPanGestureTwoPointInterpolatePastTime;
389 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
391 return mPanGestureTwoPointVelocityBias;
394 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
396 return mPanGestureTwoPointAccelerationBias;
399 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
401 return mPanGestureMultitapSmoothingRange;
404 int EnvironmentOptions::GetMinimumPanDistance() const
406 return mPanMinimumDistance;
409 int EnvironmentOptions::GetMinimumPanEvents() const
411 return mPanMinimumEvents;
414 float EnvironmentOptions::GetMinimumPinchDistance() const
416 return mPinchMinimumDistance;
419 int EnvironmentOptions::GetMinimumPinchTouchEvents() const
421 return mPinchMinimumTouchEvents;
424 int EnvironmentOptions::GetMinimumPinchTouchEventsAfterStart() const
426 return mPinchMinimumTouchEventsAfterStart;
429 int EnvironmentOptions::GetMinimumRotationTouchEvents() const
431 return mRotationMinimumTouchEvents;
434 int EnvironmentOptions::GetMinimumRotationTouchEventsAfterStart() const
436 return mRotationMinimumTouchEventsAfterStart;
439 int EnvironmentOptions::GetLongPressMinimumHoldingTime() const
441 return mLongPressMinimumHoldingTime;
444 int EnvironmentOptions::GetTapMaximumAllowedTime() const
446 return mTapMaximumAllowedTime;
449 unsigned int EnvironmentOptions::GetWindowWidth() const
454 unsigned int EnvironmentOptions::GetWindowHeight() const
456 return mWindowHeight;
459 int EnvironmentOptions::GetGlesCallTime() const
461 return mGlesCallTime;
464 bool EnvironmentOptions::GetGlesCallAccumulate() const
466 return mGlesCallAccumulate;
469 const std::string& EnvironmentOptions::GetWindowName() const
474 const std::string& EnvironmentOptions::GetWindowClassName() const
476 return mWindowClassName;
479 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
481 return mThreadingMode;
484 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
486 return mRenderRefreshRate;
489 int EnvironmentOptions::GetMultiSamplingLevel() const
491 return mMultiSamplingLevel;
494 unsigned int EnvironmentOptions::GetMaxTextureSize() const
496 return mMaxTextureSize;
499 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
501 return mRenderToFboInterval;
504 bool EnvironmentOptions::PerformanceServerRequired() const
506 return ((GetPerformanceStatsLoggingOptions() > 0) ||
507 (GetPerformanceTimeStampOutput() > 0) ||
508 (GetNetworkControlMode() > 0));
511 bool EnvironmentOptions::DepthBufferRequired() const
513 return mDepthBufferRequired;
516 bool EnvironmentOptions::StencilBufferRequired() const
518 return mStencilBufferRequired;
521 bool EnvironmentOptions::PartialUpdateRequired() const
523 return mPartialUpdateRequired;
526 bool EnvironmentOptions::VsyncRenderRequired() const
528 return mVsyncRenderRequired;
531 void EnvironmentOptions::ParseEnvironmentOptions()
533 // get logging options
534 mFpsFrequency = GetEnvironmentVariable(DALI_ENV_FPS_TRACKING, 0);
535 mUpdateStatusFrequency = GetEnvironmentVariable(DALI_ENV_UPDATE_STATUS_INTERVAL, 0);
536 mObjectProfilerInterval = GetEnvironmentVariable(DALI_ENV_OBJECT_PROFILER_INTERVAL, 0);
537 mMemoryPoolInterval = GetEnvironmentVariable(DALI_ENV_MEMORY_POOL_INTERVAL, 0);
538 mPerformanceStatsLevel = GetEnvironmentVariable(DALI_ENV_LOG_PERFORMANCE_STATS, 0);
539 mPerformanceStatsFrequency = GetEnvironmentVariable(DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0);
540 mPerformanceTimeStampOutput = GetEnvironmentVariable(DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0);
541 mNetworkControl = GetEnvironmentVariable(DALI_ENV_NETWORK_CONTROL, 0);
542 mPanGestureLoggingLevel = GetEnvironmentVariable(DALI_ENV_LOG_PAN_GESTURE, 0);
544 SetFromEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, mPanGesturePredictionMode);
545 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_PREDICTION_AMOUNT, MinimumZero(mPanGesturePredictionAmount));
546 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, MinimumZero(mPanGestureMinPredictionAmount));
547 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT,
548 [&](int maxPredictionAmount) {
549 if(mPanGestureMinPredictionAmount > -1 && maxPredictionAmount < mPanGestureMinPredictionAmount)
551 // maximum amount should not be smaller than minimum amount
552 maxPredictionAmount = mPanGestureMinPredictionAmount;
554 mPanGestureMaxPredictionAmount = maxPredictionAmount;
556 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, MinimumZero(mPanGesturePredictionAmountAdjustment));
557 SetFromEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, mPanGestureSmoothingMode);
558 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_SMOOTHING_AMOUNT, ClampBetweenZeroAndOne(mPanGestureSmoothingAmount));
559 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_USE_ACTUAL_TIMES, EnableIfNonZero(mPanGestureUseActualTimes));
560 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, MinimumZero(mPanGestureInterpolationTimeRange));
561 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, EnableIfNonZero(mPanGestureScalarOnlyPredictionEnabled));
562 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, EnableIfNonZero(mPanGestureTwoPointPredictionEnabled));
563 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, MinimumZero(mPanGestureTwoPointInterpolatePastTime));
564 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, ClampBetweenZeroAndOne(mPanGestureTwoPointVelocityBias));
565 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, ClampBetweenZeroAndOne(mPanGestureTwoPointAccelerationBias));
566 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, MinimumZero(mPanGestureMultitapSmoothingRange));
567 SetFromEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, mPanMinimumDistance);
568 SetFromEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, mPanMinimumEvents);
570 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_DISTANCE, mPinchMinimumDistance);
571 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS, mPinchMinimumTouchEvents);
572 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS_AFTER_START, mPinchMinimumTouchEventsAfterStart);
574 SetFromEnvironmentVariable(DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS, mRotationMinimumTouchEvents);
575 SetFromEnvironmentVariable(DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS_AFTER_START, mRotationMinimumTouchEventsAfterStart);
577 SetFromEnvironmentVariable(DALI_ENV_LONG_PRESS_MINIMUM_HOLDING_TIME, mLongPressMinimumHoldingTime);
578 SetFromEnvironmentVariable(DALI_ENV_TAP_MAXIMUM_ALLOWED_TIME, mTapMaximumAllowedTime);
580 SetFromEnvironmentVariable(DALI_GLES_CALL_TIME, mGlesCallTime);
581 SetFromEnvironmentVariable<int>(DALI_GLES_CALL_ACCUMULATE, [&](int glesCallAccumulate) { mGlesCallAccumulate = glesCallAccumulate != 0; });
583 int windowWidth(0), windowHeight(0);
584 if(GetEnvironmentVariable(DALI_WINDOW_WIDTH, windowWidth) && GetEnvironmentVariable(DALI_WINDOW_HEIGHT, windowHeight))
586 mWindowWidth = windowWidth;
587 mWindowHeight = windowHeight;
589 SetFromEnvironmentVariable(DALI_WINDOW_NAME, mWindowName);
590 SetFromEnvironmentVariable(DALI_WINDOW_CLASS_NAME, mWindowClassName);
592 SetFromEnvironmentVariable<int>(DALI_THREADING_MODE,
593 [&](int threadingMode) {
594 switch(threadingMode)
596 case ThreadingMode::COMBINED_UPDATE_RENDER:
598 mThreadingMode = static_cast<ThreadingMode::Type>(threadingMode);
604 SetFromEnvironmentVariable<int>(DALI_REFRESH_RATE, GreaterThan(mRenderRefreshRate, 1));
606 SetFromEnvironmentVariable(DALI_ENV_MULTI_SAMPLING_LEVEL, mMultiSamplingLevel);
608 SetFromEnvironmentVariable<int>(DALI_ENV_MAX_TEXTURE_SIZE, GreaterThan(mMaxTextureSize, 0));
610 mRenderToFboInterval = GetEnvironmentVariable(DALI_RENDER_TO_FBO, 0u);
612 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_DEPTH_BUFFER,
613 [&](int depthBufferRequired) {
614 if(depthBufferRequired > 0)
616 mDepthBufferRequired = false;
617 mStencilBufferRequired = false; // Disable stencil buffer as well
620 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_STENCIL_BUFFER, DisableIfNonZero(mStencilBufferRequired));
622 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_PARTIAL_UPDATE, DisableIfNonZero(mPartialUpdateRequired));
624 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_VSYNC_RENDER, DisableIfNonZero(mVsyncRenderRequired));
627 } // namespace Adaptor
629 } // namespace Internal