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),
242 mMultiSamplingLevel(DEFAULT_MULTI_SAMPLING_LEVEL),
243 mThreadingMode(ThreadingMode::COMBINED_UPDATE_RENDER),
244 mGlesCallAccumulate(false),
245 mDepthBufferRequired(DEFAULT_DEPTH_BUFFER_REQUIRED_SETTING),
246 mStencilBufferRequired(DEFAULT_STENCIL_BUFFER_REQUIRED_SETTING),
247 mPartialUpdateRequired(DEFAULT_PARTIAL_UPDATE_REQUIRED_SETTING)
249 ParseEnvironmentOptions();
252 EnvironmentOptions::~EnvironmentOptions()
256 void EnvironmentOptions::CreateTraceManager(PerformanceInterface* performanceInterface)
258 mTraceManager = TraceManagerFactory::CreateTraceFactory(performanceInterface);
261 void EnvironmentOptions::InstallTraceFunction() const
265 mTraceManager->Initialise();
269 void EnvironmentOptions::SetLogFunction(const Dali::Integration::Log::LogFunction& logFunction)
271 mLogFunction = logFunction;
274 void EnvironmentOptions::InstallLogFunction() const
276 Dali::Integration::Log::InstallLogFunction(mLogFunction);
279 void EnvironmentOptions::UnInstallLogFunction() const
281 Dali::Integration::Log::UninstallLogFunction();
284 unsigned int EnvironmentOptions::GetNetworkControlMode() const
286 return mNetworkControl;
288 unsigned int EnvironmentOptions::GetFrameRateLoggingFrequency() const
290 return mFpsFrequency;
293 unsigned int EnvironmentOptions::GetUpdateStatusLoggingFrequency() const
295 return mUpdateStatusFrequency;
298 unsigned int EnvironmentOptions::GetObjectProfilerInterval() const
300 return mObjectProfilerInterval;
303 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingOptions() const
305 return mPerformanceStatsLevel;
307 unsigned int EnvironmentOptions::GetPerformanceStatsLoggingFrequency() const
309 return mPerformanceStatsFrequency;
311 unsigned int EnvironmentOptions::GetPerformanceTimeStampOutput() const
313 return mPerformanceTimeStampOutput;
316 unsigned int EnvironmentOptions::GetPanGestureLoggingLevel() const
318 return mPanGestureLoggingLevel;
321 int EnvironmentOptions::GetPanGesturePredictionMode() const
323 return mPanGesturePredictionMode;
326 int EnvironmentOptions::GetPanGesturePredictionAmount() const
328 return mPanGesturePredictionAmount;
331 int EnvironmentOptions::GetPanGestureMaximumPredictionAmount() const
333 return mPanGestureMaxPredictionAmount;
336 int EnvironmentOptions::GetPanGestureMinimumPredictionAmount() const
338 return mPanGestureMinPredictionAmount;
341 int EnvironmentOptions::GetPanGesturePredictionAmountAdjustment() const
343 return mPanGesturePredictionAmountAdjustment;
346 int EnvironmentOptions::GetPanGestureSmoothingMode() const
348 return mPanGestureSmoothingMode;
351 float EnvironmentOptions::GetPanGestureSmoothingAmount() const
353 return mPanGestureSmoothingAmount;
356 int EnvironmentOptions::GetPanGestureUseActualTimes() const
358 return mPanGestureUseActualTimes;
361 int EnvironmentOptions::GetPanGestureInterpolationTimeRange() const
363 return mPanGestureInterpolationTimeRange;
366 int EnvironmentOptions::GetPanGestureScalarOnlyPredictionEnabled() const
368 return mPanGestureScalarOnlyPredictionEnabled;
371 int EnvironmentOptions::GetPanGestureTwoPointPredictionEnabled() const
373 return mPanGestureTwoPointPredictionEnabled;
376 int EnvironmentOptions::GetPanGestureTwoPointInterpolatePastTime() const
378 return mPanGestureTwoPointInterpolatePastTime;
381 float EnvironmentOptions::GetPanGestureTwoPointVelocityBias() const
383 return mPanGestureTwoPointVelocityBias;
386 float EnvironmentOptions::GetPanGestureTwoPointAccelerationBias() const
388 return mPanGestureTwoPointAccelerationBias;
391 int EnvironmentOptions::GetPanGestureMultitapSmoothingRange() const
393 return mPanGestureMultitapSmoothingRange;
396 int EnvironmentOptions::GetMinimumPanDistance() const
398 return mPanMinimumDistance;
401 int EnvironmentOptions::GetMinimumPanEvents() const
403 return mPanMinimumEvents;
406 float EnvironmentOptions::GetMinimumPinchDistance() const
408 return mPinchMinimumDistance;
411 int EnvironmentOptions::GetMinimumPinchTouchEvents() const
413 return mPinchMinimumTouchEvents;
416 int EnvironmentOptions::GetMinimumPinchTouchEventsAfterStart() const
418 return mPinchMinimumTouchEventsAfterStart;
421 int EnvironmentOptions::GetMinimumRotationTouchEvents() const
423 return mRotationMinimumTouchEvents;
426 int EnvironmentOptions::GetMinimumRotationTouchEventsAfterStart() const
428 return mRotationMinimumTouchEventsAfterStart;
431 int EnvironmentOptions::GetLongPressMinimumHoldingTime() const
433 return mLongPressMinimumHoldingTime;
436 unsigned int EnvironmentOptions::GetWindowWidth() const
441 unsigned int EnvironmentOptions::GetWindowHeight() const
443 return mWindowHeight;
446 int EnvironmentOptions::GetGlesCallTime() const
448 return mGlesCallTime;
451 bool EnvironmentOptions::GetGlesCallAccumulate() const
453 return mGlesCallAccumulate;
456 const std::string& EnvironmentOptions::GetWindowName() const
461 const std::string& EnvironmentOptions::GetWindowClassName() const
463 return mWindowClassName;
466 ThreadingMode::Type EnvironmentOptions::GetThreadingMode() const
468 return mThreadingMode;
471 unsigned int EnvironmentOptions::GetRenderRefreshRate() const
473 return mRenderRefreshRate;
476 int EnvironmentOptions::GetMultiSamplingLevel() const
478 return mMultiSamplingLevel;
481 unsigned int EnvironmentOptions::GetMaxTextureSize() const
483 return mMaxTextureSize;
486 unsigned int EnvironmentOptions::GetRenderToFboInterval() const
488 return mRenderToFboInterval;
491 bool EnvironmentOptions::PerformanceServerRequired() const
493 return ((GetPerformanceStatsLoggingOptions() > 0) ||
494 (GetPerformanceTimeStampOutput() > 0) ||
495 (GetNetworkControlMode() > 0));
498 bool EnvironmentOptions::DepthBufferRequired() const
500 return mDepthBufferRequired;
503 bool EnvironmentOptions::StencilBufferRequired() const
505 return mStencilBufferRequired;
508 bool EnvironmentOptions::PartialUpdateRequired() const
510 return mPartialUpdateRequired;
513 void EnvironmentOptions::ParseEnvironmentOptions()
515 // get logging options
516 mFpsFrequency = GetEnvironmentVariable(DALI_ENV_FPS_TRACKING, 0);
517 mUpdateStatusFrequency = GetEnvironmentVariable(DALI_ENV_UPDATE_STATUS_INTERVAL, 0);
518 mObjectProfilerInterval = GetEnvironmentVariable(DALI_ENV_OBJECT_PROFILER_INTERVAL, 0);
519 mPerformanceStatsLevel = GetEnvironmentVariable(DALI_ENV_LOG_PERFORMANCE_STATS, 0);
520 mPerformanceStatsFrequency = GetEnvironmentVariable(DALI_ENV_LOG_PERFORMANCE_STATS_FREQUENCY, 0);
521 mPerformanceTimeStampOutput = GetEnvironmentVariable(DALI_ENV_PERFORMANCE_TIMESTAMP_OUTPUT, 0);
522 mNetworkControl = GetEnvironmentVariable(DALI_ENV_NETWORK_CONTROL, 0);
523 mPanGestureLoggingLevel = GetEnvironmentVariable(DALI_ENV_LOG_PAN_GESTURE, 0);
525 SetFromEnvironmentVariable(DALI_ENV_PAN_PREDICTION_MODE, mPanGesturePredictionMode);
526 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_PREDICTION_AMOUNT, MinimumZero(mPanGesturePredictionAmount));
527 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MIN_PREDICTION_AMOUNT, MinimumZero(mPanGestureMinPredictionAmount));
528 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MAX_PREDICTION_AMOUNT,
529 [&](int maxPredictionAmount) {
530 if(mPanGestureMinPredictionAmount > -1 && maxPredictionAmount < mPanGestureMinPredictionAmount)
532 // maximum amount should not be smaller than minimum amount
533 maxPredictionAmount = mPanGestureMinPredictionAmount;
535 mPanGestureMaxPredictionAmount = maxPredictionAmount;
537 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_PREDICTION_AMOUNT_ADJUSTMENT, MinimumZero(mPanGesturePredictionAmountAdjustment));
538 SetFromEnvironmentVariable(DALI_ENV_PAN_SMOOTHING_MODE, mPanGestureSmoothingMode);
539 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_SMOOTHING_AMOUNT, ClampBetweenZeroAndOne(mPanGestureSmoothingAmount));
540 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_USE_ACTUAL_TIMES, EnableIfNonZero(mPanGestureUseActualTimes));
541 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_INTERPOLATION_TIME_RANGE, MinimumZero(mPanGestureInterpolationTimeRange));
542 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_SCALAR_ONLY_PREDICTION_ENABLED, EnableIfNonZero(mPanGestureScalarOnlyPredictionEnabled));
543 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_TWO_POINT_PREDICTION_ENABLED, EnableIfNonZero(mPanGestureTwoPointPredictionEnabled));
544 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_TWO_POINT_PAST_INTERPOLATE_TIME, MinimumZero(mPanGestureTwoPointInterpolatePastTime));
545 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_TWO_POINT_VELOCITY_BIAS, ClampBetweenZeroAndOne(mPanGestureTwoPointVelocityBias));
546 SetFromEnvironmentVariable<float>(DALI_ENV_PAN_TWO_POINT_ACCELERATION_BIAS, ClampBetweenZeroAndOne(mPanGestureTwoPointAccelerationBias));
547 SetFromEnvironmentVariable<int>(DALI_ENV_PAN_MULTITAP_SMOOTHING_RANGE, MinimumZero(mPanGestureMultitapSmoothingRange));
548 SetFromEnvironmentVariable(DALI_ENV_PAN_MINIMUM_DISTANCE, mPanMinimumDistance);
549 SetFromEnvironmentVariable(DALI_ENV_PAN_MINIMUM_EVENTS, mPanMinimumEvents);
551 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_DISTANCE, mPinchMinimumDistance);
552 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS, mPinchMinimumTouchEvents);
553 SetFromEnvironmentVariable(DALI_ENV_PINCH_MINIMUM_TOUCH_EVENTS_AFTER_START, mPinchMinimumTouchEventsAfterStart);
555 SetFromEnvironmentVariable(DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS, mRotationMinimumTouchEvents);
556 SetFromEnvironmentVariable(DALI_ENV_ROTATION_MINIMUM_TOUCH_EVENTS_AFTER_START, mRotationMinimumTouchEventsAfterStart);
558 SetFromEnvironmentVariable(DALI_ENV_LONG_PRESS_MINIMUM_HOLDING_TIME, mLongPressMinimumHoldingTime);
560 SetFromEnvironmentVariable(DALI_GLES_CALL_TIME, mGlesCallTime);
561 SetFromEnvironmentVariable<int>(DALI_GLES_CALL_ACCUMULATE, [&](int glesCallAccumulate) { mGlesCallAccumulate = glesCallAccumulate != 0; });
563 int windowWidth(0), windowHeight(0);
564 if(GetEnvironmentVariable(DALI_WINDOW_WIDTH, windowWidth) && GetEnvironmentVariable(DALI_WINDOW_HEIGHT, windowHeight))
566 mWindowWidth = windowWidth;
567 mWindowHeight = windowHeight;
569 SetFromEnvironmentVariable(DALI_WINDOW_NAME, mWindowName);
570 SetFromEnvironmentVariable(DALI_WINDOW_CLASS_NAME, mWindowClassName);
572 SetFromEnvironmentVariable<int>(DALI_THREADING_MODE,
573 [&](int threadingMode) {
574 switch(threadingMode)
576 case ThreadingMode::COMBINED_UPDATE_RENDER:
578 mThreadingMode = static_cast<ThreadingMode::Type>(threadingMode);
584 SetFromEnvironmentVariable<int>(DALI_REFRESH_RATE, GreaterThan(mRenderRefreshRate, 1));
586 SetFromEnvironmentVariable(DALI_ENV_MULTI_SAMPLING_LEVEL, mMultiSamplingLevel);
588 SetFromEnvironmentVariable<int>(DALI_ENV_MAX_TEXTURE_SIZE, GreaterThan(mMaxTextureSize, 0));
590 mRenderToFboInterval = GetEnvironmentVariable(DALI_RENDER_TO_FBO, 0u);
592 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_DEPTH_BUFFER,
593 [&](int depthBufferRequired) {
594 if(depthBufferRequired > 0)
596 mDepthBufferRequired = false;
597 mStencilBufferRequired = false; // Disable stencil buffer as well
600 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_STENCIL_BUFFER, DisableIfNonZero(mStencilBufferRequired));
602 SetFromEnvironmentVariable<int>(DALI_ENV_DISABLE_PARTIAL_UPDATE, DisableIfNonZero(mPartialUpdateRequired));
605 } // namespace Adaptor
607 } // namespace Internal