1 /*
2 * Copyright (c) 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 "rs_system_parameters.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
24 namespace OHOS {
25 namespace Rosen {
26 constexpr int DEFAULT_QUICK_SKIP_PREPARE_TYPE_VALUE = 3;
ConvertToInt(const char * originValue,int defaultValue)27 int ConvertToInt(const char *originValue, int defaultValue)
28 {
29 return originValue == nullptr ? defaultValue : std::atoi(originValue);
30 }
31
GetCalcCostEnabled()32 bool RSSystemParameters::GetCalcCostEnabled()
33 {
34 static CachedHandle g_Handle = CachedParameterCreate("rosen.calcCost.enabled", "0");
35 int changed = 0;
36 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
37 return ConvertToInt(enable, 0) != 0;
38 }
39
GetDumpRSTreeCount()40 int RSSystemParameters::GetDumpRSTreeCount()
41 {
42 static CachedHandle g_Handle = CachedParameterCreate("debug.graphic.dumpRSTreeCount", "0");
43 int changed = 0;
44 const char *num = CachedParameterGetChanged(g_Handle, &changed);
45 return ConvertToInt(num, 0);
46 }
47
SetDumpRSTreeCount(int count)48 void RSSystemParameters::SetDumpRSTreeCount(int count)
49 {
50 count = (count > 0) ? count : 0;
51 system::SetParameter("debug.graphic.dumpRSTreeCount", std::to_string(count));
52 RS_LOGD("RSSystemParameters::SetDumpRSTreeCount %{public}d", count);
53 }
54
GetDrawingCacheEnabled()55 bool RSSystemParameters::GetDrawingCacheEnabled()
56 {
57 static CachedHandle g_Handle = CachedParameterCreate("rosen.drawingCache.enabled", "1");
58 int changed = 0;
59 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
60 return ConvertToInt(enable, 1) != 0;
61 }
62
GetDrawingCacheEnabledDfx()63 bool RSSystemParameters::GetDrawingCacheEnabledDfx()
64 {
65 static CachedHandle g_Handle = CachedParameterCreate("rosen.drawingCache.enabledDfx", "0");
66 int changed = 0;
67 const char *enabledDfx = CachedParameterGetChanged(g_Handle, &changed);
68 return ConvertToInt(enabledDfx, 0) != 0;
69 }
70
GetShowRefreshRateEnabled(int * changed)71 bool RSSystemParameters::GetShowRefreshRateEnabled(int *changed)
72 {
73 static CachedHandle g_Handle = CachedParameterCreate("rosen.showRefreshRate.enabled", "0");
74 const char *enabled = CachedParameterGetChanged(g_Handle, changed);
75 return ConvertToInt(enabled, 0) != 0;
76 }
77
GetQuickSkipPrepareType()78 QuickSkipPrepareType RSSystemParameters::GetQuickSkipPrepareType()
79 {
80 static CachedHandle g_Handle = CachedParameterCreate("rosen.quickskipprepare.enabled", "2");
81 int changed = 0;
82 const char *type = CachedParameterGetChanged(g_Handle, &changed);
83 return static_cast<QuickSkipPrepareType>(ConvertToInt(type, DEFAULT_QUICK_SKIP_PREPARE_TYPE_VALUE));
84 }
85
GetRsParallelType()86 RsParallelType RSSystemParameters::GetRsParallelType()
87 {
88 static CachedHandle g_Handle = CachedParameterCreate("persist.sys.graphic.parallel.type", "0");
89 int changed = 0;
90 const char *type = CachedParameterGetChanged(g_Handle, &changed);
91 return static_cast<RsParallelType>(ConvertToInt(type, 0));
92 }
93
GetRsSurfaceCaptureType()94 RsSurfaceCaptureType RSSystemParameters::GetRsSurfaceCaptureType()
95 {
96 if (GetRsParallelType() == RsParallelType::RS_PARALLEL_TYPE_SINGLE_THREAD) {
97 return RsSurfaceCaptureType::RS_SURFACE_CAPTURE_TYPE_MAIN_THREAD;
98 }
99 static CachedHandle g_Handle =
100 CachedParameterCreate("persist.sys.graphic.surface_capture.type", "0");
101 int changed = 0;
102 const char *type = CachedParameterGetChanged(g_Handle, &changed);
103 return static_cast<RsSurfaceCaptureType>(ConvertToInt(type, 0));
104 }
105
GetVRateControlEnabled()106 bool RSSystemParameters::GetVRateControlEnabled()
107 {
108 static CachedHandle g_Handle = CachedParameterCreate("rosen.vRateControl.enabled", "1");
109 int changed = 0;
110 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
111 return ConvertToInt(enable, 1) != 0;
112 }
113
GetVSyncControlEnabled()114 bool RSSystemParameters::GetVSyncControlEnabled()
115 {
116 static bool vsyncControlEnabled =
117 std::atoi((system::GetParameter("persist.sys.graphic.vsyncControlEnabled", "1")).c_str()) != 0;
118 return vsyncControlEnabled;
119 }
120
GetSystemAnimatedScenesEnabled()121 bool RSSystemParameters::GetSystemAnimatedScenesEnabled()
122 {
123 static bool systemAnimatedScenesEnabled =
124 std::atoi((system::GetParameter("persist.sys.graphic.systemAnimatedScenesEnabled", "1")).c_str()) != 0;
125 return systemAnimatedScenesEnabled;
126 }
127
GetFilterCacheOcculusionEnabled()128 bool RSSystemParameters::GetFilterCacheOcculusionEnabled()
129 {
130 static bool filterCacheOcclusionEnabled =
131 std::atoi((system::GetParameter("persist.sys.graphic.filterCacheOcclusionEnabled", "1")).c_str()) != 0;
132 return filterCacheOcclusionEnabled;
133 }
134
GetSkipCanvasNodeOutofScreenEnabled()135 bool RSSystemParameters::GetSkipCanvasNodeOutofScreenEnabled()
136 {
137 static CachedHandle g_Handle = CachedParameterCreate("rosen.skipCanvasNodeOutofScreen.enabled", "0");
138 int changed = 0;
139 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
140 return ConvertToInt(enable, 1) != 0;
141 }
142
GetDrawingEffectRegionEnabledDfx()143 bool RSSystemParameters::GetDrawingEffectRegionEnabledDfx()
144 {
145 static CachedHandle g_Handle = CachedParameterCreate("rosen.graphic.drawingEffectRegionEnabledDfx", "0");
146 int changed = 0;
147 const char *enableDfx = CachedParameterGetChanged(g_Handle, &changed);
148 return ConvertToInt(enableDfx, 0) != 0;
149 }
150
GetRenderStop()151 bool RSSystemParameters::GetRenderStop()
152 {
153 static CachedHandle g_Handle = CachedParameterCreate("rosen.render.stop", "0");
154 int changed = 0;
155 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
156 return ConvertToInt(enable, 0) != 0;
157 }
158
GetOcclusionCallBackToWMSDebugType()159 bool RSSystemParameters::GetOcclusionCallBackToWMSDebugType()
160 {
161 static CachedHandle g_Handle = CachedParameterCreate("rosen.occlusion.callbacktowms.debug.enabled", "0");
162 int changed = 0;
163 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
164 return ConvertToInt(enable, 0) != 0;
165 }
166
GetPrevalidateHwcNodeEnabled()167 bool RSSystemParameters::GetPrevalidateHwcNodeEnabled()
168 {
169 static bool prevalidateHwcNodeEnabled =
170 std::atoi((system::GetParameter("persist.sys.graphic.prevalidateHwcNode.Enabled", "1")).c_str()) != 0;
171 return prevalidateHwcNodeEnabled;
172 }
173
GetSolidLayerHwcEnabled()174 bool RSSystemParameters::GetSolidLayerHwcEnabled()
175 {
176 static bool solidLayerHwcEnabled =
177 std::atoi((system::GetParameter("persist.sys.graphic.solidLayer.Enabled", "1")).c_str()) != 0;
178 return solidLayerHwcEnabled;
179 }
180
GetControlBufferConsumeEnabled()181 bool RSSystemParameters::GetControlBufferConsumeEnabled()
182 {
183 static bool controlBufferConsume =
184 std::atoi((system::GetParameter("persist.sys.graphic.controlBufferConsume.Enabled", "1")).c_str()) != 0;
185 return controlBufferConsume;
186 }
187
GetHideNotchStatus()188 bool RSSystemParameters::GetHideNotchStatus()
189 {
190 static CachedHandle g_Handle = CachedParameterCreate("persist.sys.graphic.hideNotch.status", "0");
191 int changed = 0;
192 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
193 if (!enable) {
194 return false;
195 }
196 return (strcmp(enable, "2") == 0);
197 }
198
GetTcacheEnabled()199 bool RSSystemParameters::GetTcacheEnabled()
200 {
201 static bool flag = system::GetBoolParameter("persist.sys.graphic.tcache.enable", true);
202 return flag;
203 }
204
GetDumpCanvasDrawingNodeEnabled()205 bool RSSystemParameters::GetDumpCanvasDrawingNodeEnabled()
206 {
207 static CachedHandle g_Handle = CachedParameterCreate("debug.graphic.canvasDrawingEnabled", "0");
208 int changed = 0;
209 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
210 return ConvertToInt(enable, 0) != 0;
211 }
212
IsNeedScRGBForP3(const GraphicColorGamut & currentGamut)213 bool RSSystemParameters::IsNeedScRGBForP3(const GraphicColorGamut& currentGamut)
214 {
215 static bool isSupportScRGBForP3_ = system::GetBoolParameter("persist.sys.graphic.scrgb.enabled", false);
216 return isSupportScRGBForP3_ && (currentGamut != GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB);
217 }
218
GetWiredScreenOndrawEnabled()219 bool RSSystemParameters::GetWiredScreenOndrawEnabled()
220 {
221 static CachedHandle g_Handle = CachedParameterCreate("rosen.wiredScreenOndraw.enabled", "1");
222 int changed = 0;
223 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
224 return ConvertToInt(enable, 0) != 0;
225 }
226
GetDebugMirrorOndrawEnabled()227 bool RSSystemParameters::GetDebugMirrorOndrawEnabled()
228 {
229 static CachedHandle g_Handle = CachedParameterCreate("rosen.debugMirrorOndraw.enabled", "0");
230 int changed = 0;
231 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
232 return ConvertToInt(enable, 1) != 0;
233 }
234
GetArsrPreEnabled()235 bool RSSystemParameters::GetArsrPreEnabled()
236 {
237 static bool flag = system::GetBoolParameter("const.display.enable_arsr_pre", true);
238 return flag;
239 }
240
GetMultimediaEnableCameraRotationCompensation()241 bool RSSystemParameters::GetMultimediaEnableCameraRotationCompensation()
242 {
243 static bool flag = system::GetBoolParameter("const.multimedia.enable_camera_rotation_compensation", 0);
244 return flag;
245 }
246
GetCanvasDrawingNodeRegionEnabled()247 bool RSSystemParameters::GetCanvasDrawingNodeRegionEnabled()
248 {
249 static CachedHandle g_Handle = CachedParameterCreate("rosen.canvas_drawing_node.region.enabled", "0");
250 int changed = 0;
251 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
252 return ConvertToInt(enable, 0) != 0;
253 }
254
GetWindowScreenScanType()255 int32_t RSSystemParameters::GetWindowScreenScanType()
256 {
257 static int32_t screenScanType = system::GetIntParameter<int32_t>("const.window.screen.scan_type", 0);
258 return screenScanType;
259 }
260
GetPurgeableResourceLimit()261 int32_t RSSystemParameters::GetPurgeableResourceLimit()
262 {
263 static int32_t purgeableResourceLimit =
264 system::GetIntParameter<int32_t>("persist.sys.graphic.purgeableResourceLimit", 40000); // purge limit: 40000
265 return purgeableResourceLimit;
266 }
267
GetAnimationOcclusionEnabled()268 bool RSSystemParameters::GetAnimationOcclusionEnabled()
269 {
270 static CachedHandle g_Handle = CachedParameterCreate("rosen.ani.occlusion.enabled", "1");
271 int changed = 0;
272 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
273 return ConvertToInt(enable, 0) != 0;
274 }
275
GetUIFirstPurgeEnabled()276 bool RSSystemParameters::GetUIFirstPurgeEnabled()
277 {
278 static CachedHandle g_Handle = CachedParameterCreate("rosen.uifirst.purge.enable", "1");
279 int changed = 0;
280 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
281 return ConvertToInt(enable, 0) != 0;
282 }
283
GetUIFirstOcclusionEnabled()284 bool RSSystemParameters::GetUIFirstOcclusionEnabled()
285 {
286 static CachedHandle g_Handle = CachedParameterCreate("rosen.uni.uifirst.occlusion.enable", "1");
287 int changed = 0;
288 const char *enable = CachedParameterGetChanged(g_Handle, &changed);
289 return ConvertToInt(enable, 0);
290 }
291 } // namespace Rosen
292 } // namespace OHOS
293