• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "platform/common/rs_system_properties.h"
17 
18 #include <cstdlib>
19 #include <parameter.h>
20 #include <parameters.h>
21 #include "param/sys_param.h"
22 #include "platform/common/rs_log.h"
23 #include "transaction/rs_render_service_client.h"
24 #include "scene_board_judgement.h"
25 #include "pipeline/rs_uni_render_judgement.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 constexpr int DEFAULT_CACHE_WIDTH = 1250;
30 constexpr int DEFAULT_CACHE_HEIGHT = 2710;
31 constexpr int DEFAULT_PARTIAL_RENDER_ENABLED_VALUE = 2;
32 constexpr int DEFAULT_UNI_PARTIAL_RENDER_ENABLED_VALUE = 4;
33 constexpr int DEFAULT_CORRECTION_MODE_VALUE = 999;
34 
35 #if (defined (ACE_ENABLE_GL) && defined (ACE_ENABLE_VK)) || (defined (RS_ENABLE_GL) && defined (RS_ENABLE_VK))
36 const GpuApiType RSSystemProperties::systemGpuApiType_ = Drawing::SystemProperties::GetGpuApiType();
37 #elif defined (ACE_ENABLE_GL) || defined (RS_ENABLE_GL)
38 const GpuApiType RSSystemProperties::systemGpuApiType_ = GpuApiType::OPENGL;
39 #else
40 const GpuApiType RSSystemProperties::systemGpuApiType_ = GpuApiType::VULKAN;
41 #endif
42 
ConvertToInt(const char * originValue,int defaultValue)43 int ConvertToInt(const char *originValue, int defaultValue)
44 {
45     return originValue == nullptr ? defaultValue : std::atoi(originValue);
46 }
ParseDfxSurfaceNamesString(const std::string & paramsStr,std::vector<std::string> & splitStrs,const std::string & seperator)47 static void ParseDfxSurfaceNamesString(const std::string& paramsStr,
48     std::vector<std::string>& splitStrs, const std::string& seperator)
49 {
50     std::string::size_type pos1 = 0;
51     std::string::size_type pos2 = paramsStr.find(seperator);
52     if (std::string::npos == pos2) {
53         splitStrs.push_back(paramsStr);
54         return;
55     }
56     while (std::string::npos != pos2) {
57         splitStrs.push_back(paramsStr.substr(pos1, pos2 - pos1));
58         pos1 = pos2 + seperator.size();
59         pos2 = paramsStr.find(seperator, pos1);
60     }
61     if (pos1 != paramsStr.length()) {
62         splitStrs.push_back(paramsStr.substr(pos1));
63     }
64 }
65 
IsSceneBoardEnabled()66 bool RSSystemProperties::IsSceneBoardEnabled()
67 {
68     return SceneBoardJudgement::IsSceneBoardEnabled();
69 }
70 
71 // used by clients
GetDumpFrameNum()72 int RSSystemProperties::GetDumpFrameNum()
73 {
74     static CachedHandle g_Handle = CachedParameterCreate("rosen.recording.frameNum", "0");
75     int changed = 0;
76     const char *num = CachedParameterGetChanged(g_Handle, &changed);
77     return ConvertToInt(num, 0);
78 }
79 
GetRecordingEnabled()80 int RSSystemProperties::GetRecordingEnabled()
81 {
82     static CachedHandle g_Handle = CachedParameterCreate("debug.graphic.recording.enabled", "0");
83     int changed = 0;
84     const char *num = CachedParameterGetChanged(g_Handle, &changed);
85     return ConvertToInt(num, 0);
86 }
87 
88 
SetRecordingDisenabled()89 void RSSystemProperties::SetRecordingDisenabled()
90 {
91     system::SetParameter("debug.graphic.recording.enabled", "0");
92     RS_LOGD("RSSystemProperties::SetRecordingDisenabled");
93 }
94 
GetRecordingFile()95 std::string RSSystemProperties::GetRecordingFile()
96 {
97     static CachedHandle g_Handle = CachedParameterCreate("rosen.dumpfile.path", "");
98     int changed = 0;
99     const char *file = CachedParameterGetChanged(g_Handle, &changed);
100     return file == nullptr ? "" : file;
101 }
102 
GetUniRenderEnabled()103 bool RSSystemProperties::GetUniRenderEnabled()
104 {
105     static bool inited = false;
106     if (inited) {
107         return isUniRenderEnabled_;
108     }
109 
110     isUniRenderEnabled_ = std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient())
111         ->GetUniRenderEnabled();
112     inited = true;
113     ROSEN_LOGD("RSSystemProperties::GetUniRenderEnabled:%{public}d", isUniRenderEnabled_);
114     return isUniRenderEnabled_;
115 }
116 
GetDrawOpTraceEnabled()117 bool RSSystemProperties::GetDrawOpTraceEnabled()
118 {
119     static bool code = system::GetParameter("persist.rosen.drawoptrace.enabled", "0") != "0";
120     return code;
121 }
122 
GetRenderNodeTraceEnabled()123 bool RSSystemProperties::GetRenderNodeTraceEnabled()
124 {
125     static bool isNeedTrace = system::GetParameter("persist.rosen.rendernodetrace.enabled", "0") != "0";
126     return isNeedTrace;
127 }
128 
GetRSScreenRoundCornerEnable()129 bool RSSystemProperties::GetRSScreenRoundCornerEnable()
130 {
131     static bool isNeedScreenRCD = system::GetParameter("persist.rosen.screenroundcornerrcd.enabled", "1") != "0";
132     return isNeedScreenRCD;
133 }
134 
GetDirtyRegionDebugType()135 DirtyRegionDebugType RSSystemProperties::GetDirtyRegionDebugType()
136 {
137     static CachedHandle g_Handle = CachedParameterCreate("rosen.dirtyregiondebug.enabled", "0");
138     int changed = 0;
139     const char *type = CachedParameterGetChanged(g_Handle, &changed);
140     return static_cast<DirtyRegionDebugType>(ConvertToInt(type, 0));
141 }
142 
GetPartialRenderEnabled()143 PartialRenderType RSSystemProperties::GetPartialRenderEnabled()
144 {
145     static CachedHandle g_Handle = CachedParameterCreate("rosen.partialrender.enabled", "0");
146     int changed = 0;
147     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
148     return static_cast<PartialRenderType>(ConvertToInt(enable, DEFAULT_PARTIAL_RENDER_ENABLED_VALUE));
149 }
150 
GetUniPartialRenderEnabled()151 PartialRenderType RSSystemProperties::GetUniPartialRenderEnabled()
152 {
153     int changed = 0;
154     static CachedHandle g_Handle = CachedParameterCreate("rosen.uni.partialrender.enabled", "4");
155     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
156     return static_cast<PartialRenderType>(ConvertToInt(enable, DEFAULT_UNI_PARTIAL_RENDER_ENABLED_VALUE));
157 }
158 
GetReleaseResourceEnabled()159 bool RSSystemProperties::GetReleaseResourceEnabled()
160 {
161     static CachedHandle g_Handle = CachedParameterCreate("persist.release.gpuresource.enabled", "1");
162     int changed = 0;
163     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
164     return ConvertToInt(enable, 1) != 0;
165 }
166 
GetOcclusionEnabled()167 bool RSSystemProperties::GetOcclusionEnabled()
168 {
169     static CachedHandle g_Handle = CachedParameterCreate("rosen.occlusion.enabled", "1");
170     int changed = 0;
171     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
172     return ConvertToInt(enable, 1) != 0;
173 }
174 
GetHardwareComposerEnabled()175 bool RSSystemProperties::GetHardwareComposerEnabled()
176 {
177     static bool hardwareComposerEnabled = system::GetParameter(
178         "persist.rosen.hardwarecomposer.enabled", "1") != "0";
179     return hardwareComposerEnabled;
180 }
181 
GetUseShadowBatchingEnabled()182 bool RSSystemProperties::GetUseShadowBatchingEnabled()
183 {
184     static bool useShadowBatching =
185         std::atoi((system::GetParameter("persist.useShadowBatching.enabled", "1")).c_str()) != 0;
186     return useShadowBatching;
187 }
188 
GetAFBCEnabled()189 bool RSSystemProperties::GetAFBCEnabled()
190 {
191     static CachedHandle g_Handle = CachedParameterCreate("rosen.afbc.enabled", "1");
192     static const bool isBra = (system::GetParameter("const.build.product", "0").compare("BRA") == 0);
193     int changed = 0;
194     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
195     return ConvertToInt(enable, 1) != 0 && !isBra;
196 }
197 
GetRSEventProperty(const std::string & paraName)198 std::string RSSystemProperties::GetRSEventProperty(const std::string &paraName)
199 {
200     return system::GetParameter(paraName, "0");
201 }
202 
GetDirectClientCompEnableStatus()203 bool RSSystemProperties::GetDirectClientCompEnableStatus()
204 {
205     // If the value of rosen.directClientComposition.enabled is not 0 then enable the direct CLIENT composition.
206     // Direct CLIENT composition will be processed only when the num of layer is larger than 11
207     static CachedHandle g_Handle = CachedParameterCreate("rosen.directClientComposition.enabled", "1");
208     int changed = 0;
209     const char *status = CachedParameterGetChanged(g_Handle, &changed);
210     return ConvertToInt(status, 1) != 0;
211 }
212 
GetHighContrastStatus()213 bool RSSystemProperties::GetHighContrastStatus()
214 {
215     // If the value of rosen.directClientComposition.enabled is not 0 then enable the direct CLIENT composition.
216     // Direct CLIENT composition will be processed only when the num of layer is larger than 11
217     static CachedHandle g_Handle = CachedParameterCreate("rosen.HighContrast.enabled", "0");
218     int changed = 0;
219     const char *status = CachedParameterGetChanged(g_Handle, &changed);
220     return ConvertToInt(status, 0) != 0;
221 }
222 
GetTargetDirtyRegionDfxEnabled(std::vector<std::string> & dfxTargetSurfaceNames_)223 bool RSSystemProperties::GetTargetDirtyRegionDfxEnabled(std::vector<std::string>& dfxTargetSurfaceNames_)
224 {
225     static CachedHandle g_Handle = CachedParameterCreate("rosen.dirtyregiondebug.surfacenames", "0");
226     int changed = 0;
227     const char *targetSurfacesStr = CachedParameterGetChanged(g_Handle, &changed);
228     if (strcmp(targetSurfacesStr, "0") == 0) {
229         dfxTargetSurfaceNames_.clear();
230         return false;
231     }
232     dfxTargetSurfaceNames_.clear();
233     ParseDfxSurfaceNamesString(targetSurfacesStr, dfxTargetSurfaceNames_, ",");
234     return true;
235 }
236 
GetOpaqueRegionDfxEnabled()237 bool RSSystemProperties::GetOpaqueRegionDfxEnabled()
238 {
239     static CachedHandle g_Handle = CachedParameterCreate("rosen.uni.opaqueregiondebug", "0");
240     int changed = 0;
241     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
242     return ConvertToInt(enable, 0) != 0;
243 }
244 
GetVisibleRegionDfxEnabled()245 bool RSSystemProperties::GetVisibleRegionDfxEnabled()
246 {
247     static CachedHandle g_Handle = CachedParameterCreate("rosen.uni.visibleregiondebug", "0");
248     int changed = 0;
249     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
250     return ConvertToInt(enable, 0) != 0;
251 }
252 
GetSurfaceRegionDfxType()253 SurfaceRegionDebugType RSSystemProperties::GetSurfaceRegionDfxType()
254 {
255     static CachedHandle g_Handle = CachedParameterCreate("rosen.uni.surfaceregiondebug", "0");
256     int changed = 0;
257     const char *type = CachedParameterGetChanged(g_Handle, &changed);
258     return static_cast<SurfaceRegionDebugType>(ConvertToInt(type, 0));
259 }
260 
GetCorrectionMode()261 uint32_t RSSystemProperties::GetCorrectionMode()
262 {
263     // If the value of rosen.directClientComposition.enabled is not 0 then enable the direct CLIENT composition.
264     // Direct CLIENT composition will be processed only when the num of layer is larger than 11
265     static CachedHandle g_Handle = CachedParameterCreate("rosen.CorrectionMode", "999");
266     int changed = 0;
267     const char *mode = CachedParameterGetChanged(g_Handle, &changed);
268     return ConvertToInt(mode, DEFAULT_CORRECTION_MODE_VALUE);
269 }
270 
GetDumpSurfaceType()271 DumpSurfaceType RSSystemProperties::GetDumpSurfaceType()
272 {
273     static CachedHandle g_Handle = CachedParameterCreate("rosen.dumpsurfacetype.enabled", "0");
274     int changed = 0;
275     const char *type = CachedParameterGetChanged(g_Handle, &changed);
276     return static_cast<DumpSurfaceType>(ConvertToInt(type, 0));
277 }
278 
GetDumpSurfaceId()279 long long int RSSystemProperties::GetDumpSurfaceId()
280 {
281     static CachedHandle g_Handle = CachedParameterCreate("rosen.dumpsurfaceid", "0");
282     int changed = 0;
283     const char *surfaceId = CachedParameterGetChanged(g_Handle, &changed);
284     return surfaceId == nullptr ? std::atoll("0") : std::atoll(surfaceId);
285 }
286 
GetDumpLayersEnabled()287 bool RSSystemProperties::GetDumpLayersEnabled()
288 {
289     static CachedHandle g_Handle = CachedParameterCreate("rosen.dumplayer.enabled", "0");
290     int changed = 0;
291     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
292     return ConvertToInt(enable, 0) != 0;
293 }
294 
SetDrawTextAsBitmap(bool flag)295 void RSSystemProperties::SetDrawTextAsBitmap(bool flag)
296 {
297     isDrawTextAsBitmap_ = flag;
298 }
GetDrawTextAsBitmap()299 bool RSSystemProperties::GetDrawTextAsBitmap()
300 {
301     return isDrawTextAsBitmap_;
302 }
303 
GetDumpRSTreeCount()304 int RSSystemProperties::GetDumpRSTreeCount()
305 {
306     static CachedHandle g_Handle = CachedParameterCreate("debug.graphic.dumpRSTreeCount", "0");
307 
308     int changed = 0;
309     const char *num = CachedParameterGetChanged(g_Handle, &changed);
310     return ConvertToInt(num, 0);
311 }
312 
SetDumpRSTreeCount(int count)313 void RSSystemProperties::SetDumpRSTreeCount(int count)
314 {
315     count = (count > 0) ? count : 0;
316     system::SetParameter("debug.graphic.dumpRSTreeCount", std::to_string(count));
317     RS_LOGD("RSSystemProperties::SetDumpRSTreeCount %{public}d", count);
318 }
319 
SetCacheEnabledForRotation(bool flag)320 void RSSystemProperties::SetCacheEnabledForRotation(bool flag)
321 {
322     cacheEnabledForRotation_ = flag;
323 }
324 
GetCacheEnabledForRotation()325 bool RSSystemProperties::GetCacheEnabledForRotation()
326 {
327     return cacheEnabledForRotation_;
328 }
329 
GetPrepareParallelRenderingEnabled()330 ParallelRenderingType RSSystemProperties::GetPrepareParallelRenderingEnabled()
331 {
332     static ParallelRenderingType systemPropertiePrepareType = static_cast<ParallelRenderingType>(
333         std::atoi((system::GetParameter("persist.rosen.prepareparallelrender.enabled", "1")).c_str()));
334     return systemPropertiePrepareType;
335 }
336 
GetParallelRenderingEnabled()337 ParallelRenderingType RSSystemProperties::GetParallelRenderingEnabled()
338 {
339     static ParallelRenderingType systemPropertieType = static_cast<ParallelRenderingType>(
340         std::atoi((system::GetParameter("persist.rosen.parallelrender.enabled", "0")).c_str()));
341     return systemPropertieType;
342 }
343 
GetHgmRefreshRatesEnabled()344 HgmRefreshRates RSSystemProperties::GetHgmRefreshRatesEnabled()
345 {
346     static CachedHandle g_Handle = CachedParameterCreate("rosen.sethgmrefreshrate.enabled", "0");
347     int changed = 0;
348     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
349     return static_cast<HgmRefreshRates>(ConvertToInt(enable, 0));
350 }
351 
SetHgmRefreshRateModesEnabled(std::string param)352 void RSSystemProperties::SetHgmRefreshRateModesEnabled(std::string param)
353 {
354     system::SetParameter("persist.rosen.sethgmrefreshratemode.enabled", param);
355     RS_LOGI("RSSystemProperties::SetHgmRefreshRateModesEnabled set to %{public}s", param.c_str());
356 }
357 
GetHgmRefreshRateModesEnabled()358 HgmRefreshRateModes RSSystemProperties::GetHgmRefreshRateModesEnabled()
359 {
360     static CachedHandle g_Handle = CachedParameterCreate("persist.rosen.sethgmrefreshratemode.enabled", "0");
361     int changed = 0;
362     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
363     return static_cast<HgmRefreshRateModes>(ConvertToInt(enable, 0));
364 }
365 
GetSkipForAlphaZeroEnabled()366 bool RSSystemProperties::GetSkipForAlphaZeroEnabled()
367 {
368     static CachedHandle g_Handle = CachedParameterCreate("persist.skipForAlphaZero.enabled", "1");
369     int changed = 0;
370     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
371     return ConvertToInt(enable, 1) != 0;
372 }
373 
GetSkipGeometryNotChangeEnabled()374 bool RSSystemProperties::GetSkipGeometryNotChangeEnabled()
375 {
376     static bool skipGeoNotChangeEnabled =
377         std::atoi((system::GetParameter("persist.skipGeometryNotChange.enabled", "1")).c_str()) != 0;
378     return skipGeoNotChangeEnabled;
379 }
380 
GetAnimationCacheEnabled()381 bool RSSystemProperties::GetAnimationCacheEnabled()
382 {
383     static bool animationCacheEnabled =
384         std::atoi((system::GetParameter("persist.animation.cache.enabled", "0")).c_str()) != 0;
385     return animationCacheEnabled;
386 }
387 
GetPropertyDrawableEnable()388 bool RSSystemProperties::GetPropertyDrawableEnable()
389 {
390     static bool propertyDrawableEnable =
391         std::atoi((system::GetParameter("persist.propertyDrawableGenerate.enabled", "1")).c_str()) != 0 &&
392         RSUniRenderJudgement::IsUniRender();
393     return propertyDrawableEnable;
394 }
395 
GetAnimationScale()396 float RSSystemProperties::GetAnimationScale()
397 {
398     static CachedHandle g_Handle = CachedParameterCreate("persist.sys.graphic.animationscale", "1.0");
399     int changed = 0;
400     const char *scale = CachedParameterGetChanged(g_Handle, &changed);
401     return scale == nullptr ? std::atof("1.0") : std::atof(scale);
402 }
403 
GetFilterCacheEnabled()404 bool RSSystemProperties::GetFilterCacheEnabled()
405 {
406     // Determine whether the filter cache should be enabled. The default value is 1, which means that it is enabled.
407     // If dirty-region is not properly implemented, the filter cache will act as a skip-frame strategy for filters.
408     static bool filterCacheEnabled =
409         std::atoi((system::GetParameter("persist.sys.graphic.filterCacheEnabled", "1")).c_str()) != 0;
410     return filterCacheEnabled;
411 }
412 
GetFilterCacheUpdateInterval()413 int RSSystemProperties::GetFilterCacheUpdateInterval()
414 {
415     // Configure whether to enable skip-frame for the filter cache. The default value is 1, which means that the cached
416     // image is updated with a delay of 1 frame.
417     static int filterCacheUpdateInterval =
418         std::atoi((system::GetParameter("persist.sys.graphic.filterCacheUpdateInterval", "1")).c_str());
419     return filterCacheUpdateInterval;
420 }
421 
GetFilterCacheSizeThreshold()422 int RSSystemProperties::GetFilterCacheSizeThreshold()
423 {
424     // Set the minimum size for enabling skip-frame in the filter cache. By default, this value is 400, which means that
425     // skip-frame is only enabled for regions where both the width and height are greater than 400.
426     static int filterCacheSizeThreshold =
427         std::atoi((system::GetParameter("persist.sys.graphic.filterCacheSizeThreshold", "400")).c_str());
428     return filterCacheSizeThreshold;
429 }
430 
GetFilterPartialRenderEnabled()431 bool RSSystemProperties::GetFilterPartialRenderEnabled()
432 {
433     // Determine whether the filter partial render should be enabled. The default value is 0,
434     // which means that it is unenabled.
435     static bool enabled =
436         std::atoi((system::GetParameter("persist.sys.graphic.filterPartialRenderEnabled", "1")).c_str()) != 0;
437     return enabled;
438 }
439 
GetColorPickerPartialEnabled()440 bool RSSystemProperties::GetColorPickerPartialEnabled()
441 {
442     // Determine whether the color picker partial render should be enabled. The default value is 0,
443     // which means that it is unenabled.
444     static bool enabled =
445         std::atoi((system::GetParameter("persist.sys.graphic.colorPickerPartialEnabled", "1")).c_str()) != 0;
446     return enabled;
447 }
448 
GetMaskLinearBlurEnabled()449 bool RSSystemProperties::GetMaskLinearBlurEnabled()
450 {
451     // Determine whether the mask LinearBlur render should be enabled. The default value is 0,
452     // which means that it is unenabled.
453     static bool enabled =
454         std::atoi((system::GetParameter("persist.sys.graphic.maskLinearBlurEnabled", "1")).c_str()) != 0;
455     return enabled;
456 }
457 
GetKawaseEnabled()458 bool RSSystemProperties::GetKawaseEnabled()
459 {
460     static bool kawaseBlurEnabled =
461         std::atoi((system::GetParameter("persist.sys.graphic.kawaseEnable", "1")).c_str()) != 0;
462     return kawaseBlurEnabled;
463 }
464 
GetKawaseRandomColorFactor()465 float RSSystemProperties::GetKawaseRandomColorFactor()
466 {
467     static float randomFactor =
468         std::atof((system::GetParameter("persist.sys.graphic.kawaseFactor", "1.75")).c_str());
469     return randomFactor;
470 }
471 
GetRandomColorEnabled()472 bool RSSystemProperties::GetRandomColorEnabled()
473 {
474     static bool randomColorEnabled =
475         std::atoi((system::GetParameter("persist.sys.graphic.randomColorEnable", "1")).c_str()) != 0;
476     return randomColorEnabled;
477 }
478 
GetKawaseOriginalEnabled()479 bool RSSystemProperties::GetKawaseOriginalEnabled()
480 {
481     static bool kawaseOriginalEnabled =
482         std::atoi((system::GetParameter("persist.sys.graphic.kawaseOriginalEnable", "0")).c_str()) != 0;
483     return kawaseOriginalEnabled;
484 }
485 
GetBlurEnabled()486 bool RSSystemProperties::GetBlurEnabled()
487 {
488     static bool blurEnabled =
489         std::atoi((system::GetParameter("persist.sys.graphic.blurEnabled", "1")).c_str()) != 0;
490     return blurEnabled;
491 }
492 
GetAiInvertCoef()493 const std::vector<float>& RSSystemProperties::GetAiInvertCoef()
494 {
495     // Configure AiInvertCoef: Low, High, Threshold, Opacity, Saturation, Filter Radius.
496     static std::vector<float> aiInvertCoef = {0.0, 1.0, 0.55, 0.4, 1.6, 45.0};
497     static bool initialized = false;
498     if (!initialized) {
499         initialized = true;
500         // Configure AiInvertCoef0: Low
501         aiInvertCoef[0] =
502             std::atof((system::GetParameter("persist.sys.graphic.aiInvertLow", "0")).c_str());
503         // Configure AiInvertCoef1: High.
504         aiInvertCoef[1] =
505             std::atof((system::GetParameter("persist.sys.graphic.aiInvertHigh", "1")).c_str());
506         // Configure AiInvertCoef2: Threshold.
507         aiInvertCoef[2] =
508             std::atof((system::GetParameter("persist.sys.graphic.aiInvertThreshold", "0.55")).c_str());
509         // Configure AiInvertCoef3: Opacity.
510         aiInvertCoef[3] =
511             std::atof((system::GetParameter("persist.sys.graphic.aiInvertOpacity", "0.4")).c_str());
512         // Configure AiInvertCoef4: Saturation.
513         aiInvertCoef[4] =
514             std::atof((system::GetParameter("persist.sys.graphic.aiInvertSaturation", "1.6")).c_str());
515         // Configure AiInvertCoef5: Filter Radius.
516         aiInvertCoef[5] =
517             std::atof((system::GetParameter("persist.sys.graphic.aiInvertFilterRadius", "45")).c_str());
518     }
519     return aiInvertCoef;
520 }
521 
GetProxyNodeDebugEnabled()522 bool RSSystemProperties::GetProxyNodeDebugEnabled()
523 {
524     static bool proxyNodeDebugEnabled = system::GetParameter("persist.sys.graphic.proxyNodeDebugEnabled", "0") != "0";
525     return proxyNodeDebugEnabled;
526 }
527 
GetUIFirstEnabled()528 bool RSSystemProperties::GetUIFirstEnabled()
529 {
530 #ifdef ROSEN_EMULATOR
531     return false;
532 #else
533     static CachedHandle g_Handle = CachedParameterCreate("rosen.ui.first.enabled", "1");
534     int changed = 0;
535     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
536     return ConvertToInt(enable, 1) != 0;
537 #endif
538 }
539 
GetDebugTraceEnabled()540 bool RSSystemProperties::GetDebugTraceEnabled()
541 {
542     static bool openDebugTrace =
543         std::atoi((system::GetParameter("persist.sys.graphic.openDebugTrace", "0")).c_str()) != 0;
544     return openDebugTrace;
545 }
546 
FindNodeInTargetList(std::string node)547 bool RSSystemProperties::FindNodeInTargetList(std::string node)
548 {
549     static std::string targetStr = system::GetParameter("persist.sys.graphic.traceTargetList", "");
550     static auto strSize = targetStr.size();
551     if (strSize == 0) {
552         return false;
553     }
554     static std::vector<std::string> targetVec;
555     static bool loaded = false;
556     if (!loaded) {
557         const std::string pattern = ";";
558         targetStr += pattern;
559         strSize = targetStr.size();
560         std::string::size_type pos;
561         for (std::string::size_type i = 0; i < strSize; i++) {
562             pos = targetStr.find(pattern, i);
563             if (pos >= strSize) {
564                 break;
565             }
566             auto str = targetStr.substr(i, pos - i);
567             if (str.size() > 0) {
568                 targetVec.emplace_back(str);
569             }
570             i = pos;
571         }
572         loaded = true;
573     }
574     bool res = std::find(targetVec.begin(), targetVec.end(), node) != targetVec.end();
575     return res;
576 }
577 
IsFoldScreenFlag()578 bool RSSystemProperties::IsFoldScreenFlag()
579 {
580     static bool isFoldScreenFlag = system::GetParameter("const.window.foldscreen.type", "") != "";
581     return isFoldScreenFlag;
582 }
583 
GetCacheCmdEnabled()584 bool RSSystemProperties::GetCacheCmdEnabled()
585 {
586     static CachedHandle g_Handle = CachedParameterCreate("rosen.cacheCmd.enabled", "1");
587     int changed = 0;
588     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
589     return ConvertToInt(enable, 1) != 0;
590 }
591 
GetASTCEnabled()592 bool RSSystemProperties::GetASTCEnabled()
593 {
594     static bool isASTCEnabled = std::atoi((system::GetParameter("persist.rosen.astc.enabled", "0")).c_str()) != 0;
595     return isASTCEnabled;
596 }
597 
598 // GetCachedBlurPartialRenderEnabled Option On: no need to expand blur dirtyregion if blur has background cache
GetCachedBlurPartialRenderEnabled()599 bool RSSystemProperties::GetCachedBlurPartialRenderEnabled()
600 {
601     static CachedHandle g_Handle = CachedParameterCreate("rosen.cachedblurpartialrender.enabled", "0");
602     int changed = 0;
603     const char *type = CachedParameterGetChanged(g_Handle, &changed);
604     return ConvertToInt(type, 1) != 0;
605 }
606 
GetParallelUploadTexture()607 bool RSSystemProperties::GetParallelUploadTexture()
608 {
609     static bool enable = std::atoi((system::GetParameter("rosen.parallelUpload,enabled", "1")).c_str()) != 0;
610     return enable;
611 }
612 
GetImageGpuResourceCacheEnable(int width,int height)613 bool RSSystemProperties::GetImageGpuResourceCacheEnable(int width, int height)
614 {
615     static bool cacheEnable =
616         std::atoi((system::GetParameter("persist.sys.graphic.gpuResourceCacheEnable", "1")).c_str()) != 0;
617     if (!cacheEnable) {
618         return false;
619     }
620 
621     // default cache full screen image gpu resource.
622     static int widthConfig =
623         std::atoi((system::GetParameter("persist.sys.graphic.gpuResourceCacheWidth", "0")).c_str());
624     static int heightConfig =
625         std::atoi((system::GetParameter("persist.sys.graphic.gpuResourceCacheHeight", "0")).c_str());
626     int cacheWidth = widthConfig == 0 ? DEFAULT_CACHE_WIDTH : widthConfig;
627     int cacheHeight = heightConfig == 0 ? DEFAULT_CACHE_HEIGHT : heightConfig;
628     if (width >= cacheWidth && height >= cacheHeight) {
629         return true;
630     }
631     return false;
632 }
633 
GetBoolSystemProperty(const char * name,bool defaultValue)634 bool RSSystemProperties::GetBoolSystemProperty(const char* name, bool defaultValue)
635 {
636     static CachedHandle g_Handle = CachedParameterCreate(name, defaultValue ? "1" : "0");
637     int changed = 0;
638     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
639     return ConvertToInt(enable, defaultValue ? 1 : 0) != 0;
640 }
641 
WatchSystemProperty(const char * name,OnSystemPropertyChanged func,void * context)642 int RSSystemProperties::WatchSystemProperty(const char* name, OnSystemPropertyChanged func, void* context)
643 {
644     return WatchParameter(name, func, context);
645 }
646 #if defined (ENABLE_DDGR_OPTIMIZE)
GetDDGRIntegrateEnable()647 bool RSSystemProperties::GetDDGRIntegrateEnable()
648 {
649     static bool isDataStEnable =
650         std::atoi((system::GetParameter("ddgr.data.st.enable", "1")).c_str()) != 0;
651     return isDataStEnable;
652 }
653 #endif
654 
GetSnapshotWithDMAEnabled()655 bool RSSystemProperties::GetSnapshotWithDMAEnabled()
656 {
657     static bool isSupportDma = system::GetParameter("const.product.devicetype", "pc") == "phone" ||
658         system::GetParameter("const.product.devicetype", "pc") == "tablet" ||
659         system::GetParameter("const.product.devicetype", "pc") == "pc" ||
660         system::GetParameter("const.product.devicetype", "pc") == "2in1";
661     return isSupportDma && system::GetBoolParameter("rosen.snapshotDma.enabled", true);
662 }
663 
IsPhoneType()664 bool RSSystemProperties::IsPhoneType()
665 {
666     static bool isPhone = system::GetParameter("const.product.devicetype", "pc") == "phone";
667     return isPhone;
668 }
669 
IsPcType()670 bool RSSystemProperties::IsPcType()
671 {
672     static bool isPc = (system::GetParameter("const.product.devicetype", "pc") == "pc") ||
673                        (system::GetParameter("const.product.devicetype", "pc") == "2in1");
674     return isPc;
675 }
676 
GetSyncTransactionEnabled()677 bool RSSystemProperties::GetSyncTransactionEnabled()
678 {
679     static bool syncTransactionEnabled =
680         std::atoi((system::GetParameter("persist.sys.graphic.syncTransaction.enabled", "1")).c_str()) != 0;
681     return syncTransactionEnabled;
682 }
683 
GetSyncTransactionWaitDelay()684 int RSSystemProperties::GetSyncTransactionWaitDelay()
685 {
686     static int syncTransactionWaitDelay =
687         std::atoi((system::GetParameter("persist.sys.graphic.syncTransactionWaitDelay", "1500")).c_str());
688     return syncTransactionWaitDelay;
689 }
690 
GetSingleFrameComposerEnabled()691 bool RSSystemProperties::GetSingleFrameComposerEnabled()
692 {
693     static bool singleFrameComposerEnabled =
694         (std::atoi((system::GetParameter("persist.sys.graphic.singleFrameComposer", "0")).c_str()) != 0);
695     return singleFrameComposerEnabled;
696 }
697 
GetSingleFrameComposerCanvasNodeEnabled()698 bool RSSystemProperties::GetSingleFrameComposerCanvasNodeEnabled()
699 {
700     static bool singleFrameComposerCanvasNodeEnabled =
701         (std::atoi((system::GetParameter("persist.sys.graphic.singleFrameComposerCanvasNode", "0")).c_str()) != 0);
702     return singleFrameComposerCanvasNodeEnabled;
703 }
704 
GetSubSurfaceEnabled()705 bool RSSystemProperties::GetSubSurfaceEnabled()
706 {
707     static bool subSurfaceEnabled =
708         std::atoi((system::GetParameter("persist.sys.graphic.subSurface", "0")).c_str());
709     return subSurfaceEnabled;
710 }
GetSecurityPermissionCheckEnabled()711 bool RSSystemProperties::GetSecurityPermissionCheckEnabled()
712 {
713     static bool openSecurityPermissionCheck =
714         std::atoi((system::GetParameter("persist.sys.graphic.openSecurityPermissionCheck", "0")).c_str()) != 0;
715     return openSecurityPermissionCheck;
716 }
717 
GetEffectMergeEnabled()718 bool RSSystemProperties::GetEffectMergeEnabled()
719 {
720     static CachedHandle g_Handle = CachedParameterCreate("rosen.graphic.effectMergeEnabled", "1");
721     int changed = 0;
722     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
723     return ConvertToInt(enable, 1) != 0;
724 }
725 
GetDumpUICaptureEnabled()726 bool RSSystemProperties::GetDumpUICaptureEnabled()
727 {
728     bool dumpUICaptureEnabled =
729         std::atoi((system::GetParameter("rosen.dumpUICaptureEnabled.enabled", "0")).c_str()) != 0;
730     return dumpUICaptureEnabled;
731 }
732 
GetDumpUIPixelmapEnabled()733 bool RSSystemProperties::GetDumpUIPixelmapEnabled()
734 {
735     bool dumpUIPixelmapEnabled =
736         std::atoi((system::GetParameter("rosen.dumpUIPixelmapEnabled.enabled", "0")).c_str()) != 0;
737     return dumpUIPixelmapEnabled;
738 }
739 } // namespace Rosen
740 } // namespace OHOS
741