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 "platform/common/rs_log.h"
22 #include "transaction/rs_render_service_client.h"
23 #include "scene_board_judgement.h"
24
25 namespace OHOS {
26 namespace Rosen {
27
28 constexpr int DEFAULT_CACHE_WIDTH = 1344;
29 constexpr int DEFAULT_CACHE_HEIGHT = 2772;
30
ParseDfxSurfaceNamesString(const std::string & paramsStr,std::vector<std::string> & splitStrs,const std::string & seperator)31 static void ParseDfxSurfaceNamesString(const std::string& paramsStr,
32 std::vector<std::string>& splitStrs, const std::string& seperator)
33 {
34 std::string::size_type pos1 = 0;
35 std::string::size_type pos2 = paramsStr.find(seperator);
36 if (std::string::npos == pos2) {
37 splitStrs.push_back(paramsStr);
38 return;
39 }
40 while (std::string::npos != pos2) {
41 splitStrs.push_back(paramsStr.substr(pos1, pos2 - pos1));
42 pos1 = pos2 + seperator.size();
43 pos2 = paramsStr.find(seperator, pos1);
44 }
45 if (pos1 != paramsStr.length()) {
46 splitStrs.push_back(paramsStr.substr(pos1));
47 }
48 }
49
IsSceneBoardEnabled()50 bool RSSystemProperties::IsSceneBoardEnabled()
51 {
52 return SceneBoardJudgement::IsSceneBoardEnabled();
53 }
54
55 // used by clients
GetDumpFrameNum()56 int RSSystemProperties::GetDumpFrameNum()
57 {
58 return std::atoi((system::GetParameter("debug.graphic.recording.frameNum", "0")).c_str());
59 }
60
GetRecordingEnabled()61 bool RSSystemProperties::GetRecordingEnabled()
62 {
63 return (system::GetParameter("debug.graphic.recording.enabled", "0") != "0");
64 }
65
SetRecordingDisenabled()66 void RSSystemProperties::SetRecordingDisenabled()
67 {
68 system::SetParameter("debug.graphic.recording.enabled", "0");
69 RS_LOGD("RSSystemProperties::SetRecordingDisenabled");
70 }
71
GetRecordingFile()72 std::string RSSystemProperties::GetRecordingFile()
73 {
74 return system::GetParameter("debug.graphic.dumpfile.path", "");
75 }
76
GetUniRenderEnabled()77 bool RSSystemProperties::GetUniRenderEnabled()
78 {
79 static bool inited = false;
80 if (inited) {
81 return isUniRenderEnabled_;
82 }
83
84 isUniRenderEnabled_ = std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient())
85 ->GetUniRenderEnabled();
86 inited = true;
87 ROSEN_LOGI("RSSystemProperties::GetUniRenderEnabled:%d", isUniRenderEnabled_);
88 return isUniRenderEnabled_;
89 }
90
GetDrawOpTraceEnabled()91 bool RSSystemProperties::GetDrawOpTraceEnabled()
92 {
93 static bool code = system::GetParameter("persist.rosen.drawoptrace.enabled", "0") != "0";
94 return code;
95 }
96
GetRenderNodeTraceEnabled()97 bool RSSystemProperties::GetRenderNodeTraceEnabled()
98 {
99 static bool isNeedTrace = system::GetParameter("persist.rosen.rendernodetrace.enabled", "0") != "0";
100 return isNeedTrace;
101 }
102
GetDirtyRegionDebugType()103 DirtyRegionDebugType RSSystemProperties::GetDirtyRegionDebugType()
104 {
105 return static_cast<DirtyRegionDebugType>(
106 std::atoi((system::GetParameter("rosen.dirtyregiondebug.enabled", "0")).c_str()));
107 }
108
GetPartialRenderEnabled()109 PartialRenderType RSSystemProperties::GetPartialRenderEnabled()
110 {
111 return static_cast<PartialRenderType>(
112 std::atoi((system::GetParameter("rosen.partialrender.enabled", "2")).c_str()));
113 }
114
GetUniPartialRenderEnabled()115 PartialRenderType RSSystemProperties::GetUniPartialRenderEnabled()
116 {
117 #if defined(RS_ENABLE_PARALLEL_RENDER) && defined(RS_ENABLE_VK)
118 return static_cast<PartialRenderType>(
119 std::atoi((system::GetParameter("rosen.uni.partialrender.enabled", "0")).c_str()));
120 #else
121 return static_cast<PartialRenderType>(
122 std::atoi((system::GetParameter("rosen.uni.partialrender.enabled", "4")).c_str()));
123 #endif
124 }
125
GetReleaseGpuResourceEnabled()126 ReleaseGpuResourceType RSSystemProperties::GetReleaseGpuResourceEnabled()
127 {
128 return static_cast<ReleaseGpuResourceType>(
129 std::atoi((system::GetParameter("persist.release.gpuresource.enabled", "2")).c_str()));
130 }
131
GetOcclusionEnabled()132 bool RSSystemProperties::GetOcclusionEnabled()
133 {
134 return std::atoi((system::GetParameter("rosen.occlusion.enabled", "1")).c_str()) != 0;
135 }
136
GetHardwareComposerEnabled()137 bool RSSystemProperties::GetHardwareComposerEnabled()
138 {
139 return system::GetParameter("rosen.hardwarecomposer.enabled", "1") != "0";
140 }
141
GetAFBCEnabled()142 bool RSSystemProperties::GetAFBCEnabled()
143 {
144 return system::GetParameter("rosen.afbc.enabled", "1") != "0";
145 }
146
GetRSEventProperty(const std::string & paraName)147 std::string RSSystemProperties::GetRSEventProperty(const std::string ¶Name)
148 {
149 return system::GetParameter(paraName, "0");
150 }
151
GetDirectClientCompEnableStatus()152 bool RSSystemProperties::GetDirectClientCompEnableStatus()
153 {
154 // If the value of rosen.directClientComposition.enabled is not 0 then enable the direct CLIENT composition.
155 // Direct CLIENT composition will be processed only when the num of layer is larger than 11
156 return std::atoi((system::GetParameter("rosen.directClientComposition.enabled", "1")).c_str()) != 0;
157 }
158
GetHighContrastStatus()159 bool RSSystemProperties::GetHighContrastStatus()
160 {
161 // If the value of rosen.directClientComposition.enabled is not 0 then enable the direct CLIENT composition.
162 // Direct CLIENT composition will be processed only when the num of layer is larger than 11
163 return std::atoi((system::GetParameter("rosen.HighContrast.enabled", "0")).c_str()) != 0;
164 }
165
GetTargetDirtyRegionDfxEnabled(std::vector<std::string> & dfxTargetSurfaceNames_)166 bool RSSystemProperties::GetTargetDirtyRegionDfxEnabled(std::vector<std::string>& dfxTargetSurfaceNames_)
167 {
168 std::string targetSurfacesStr = system::GetParameter("rosen.dirtyregiondebug.surfacenames", "0");
169 if (targetSurfacesStr == "0") {
170 dfxTargetSurfaceNames_.clear();
171 return false;
172 }
173 dfxTargetSurfaceNames_.clear();
174 ParseDfxSurfaceNamesString(targetSurfacesStr, dfxTargetSurfaceNames_, ",");
175 return true;
176 }
177
GetOpaqueRegionDfxEnabled()178 bool RSSystemProperties::GetOpaqueRegionDfxEnabled()
179 {
180 return std::atoi((system::GetParameter("rosen.uni.opaqueregiondebug", "0")).c_str()) != 0;
181 }
182
GetCorrectionMode()183 uint32_t RSSystemProperties::GetCorrectionMode()
184 {
185 // If the value of rosen.directClientComposition.enabled is not 0 then enable the direct CLIENT composition.
186 // Direct CLIENT composition will be processed only when the num of layer is larger than 11
187 return std::atoi((system::GetParameter("rosen.CorrectionMode", "999")).c_str());
188 }
189
GetDumpSurfaceType()190 DumpSurfaceType RSSystemProperties::GetDumpSurfaceType()
191 {
192 return static_cast<DumpSurfaceType>(
193 std::atoi((system::GetParameter("rosen.dumpsurfacetype.enabled", "0")).c_str()));
194 }
195
GetDumpSurfaceId()196 long long int RSSystemProperties::GetDumpSurfaceId()
197 {
198 return std::atoll((system::GetParameter("rosen.dumpsurfaceid", "0")).c_str());
199 }
200
GetDumpLayersEnabled()201 bool RSSystemProperties::GetDumpLayersEnabled()
202 {
203 return std::atoi((system::GetParameter("rosen.dumplayer.enabled", "0")).c_str()) != 0;
204 }
205
SetDrawTextAsBitmap(bool flag)206 void RSSystemProperties::SetDrawTextAsBitmap(bool flag)
207 {
208 isDrawTextAsBitmap_ = flag;
209 }
GetDrawTextAsBitmap()210 bool RSSystemProperties::GetDrawTextAsBitmap()
211 {
212 return isDrawTextAsBitmap_;
213 }
214
GetPrepareParallelRenderingEnabled()215 ParallelRenderingType RSSystemProperties::GetPrepareParallelRenderingEnabled()
216 {
217 return static_cast<ParallelRenderingType>(
218 std::atoi((system::GetParameter("rosen.prepareparallelrender.enabled", "1")).c_str()));
219 }
220
GetParallelRenderingEnabled()221 ParallelRenderingType RSSystemProperties::GetParallelRenderingEnabled()
222 {
223 return static_cast<ParallelRenderingType>(
224 std::atoi((system::GetParameter("rosen.parallelrender.enabled", "0")).c_str()));
225 }
226
GetHgmRefreshRatesEnabled()227 HgmRefreshRates RSSystemProperties::GetHgmRefreshRatesEnabled()
228 {
229 return static_cast<HgmRefreshRates>(
230 std::atoi((system::GetParameter("rosen.sethgmrefreshrate.enabled", "0")).c_str()));
231 }
232
SetHgmRefreshRateModesEnabled(std::string param)233 void RSSystemProperties::SetHgmRefreshRateModesEnabled(std::string param)
234 {
235 system::SetParameter("persist.rosen.sethgmrefreshratemode.enabled", param);
236 RS_LOGD("RSSystemProperties::SetHgmRefreshRateModesEnabled set to %{public}s", param.c_str());
237 }
238
GetHgmRefreshRateModesEnabled()239 HgmRefreshRateModes RSSystemProperties::GetHgmRefreshRateModesEnabled()
240 {
241 return static_cast<HgmRefreshRateModes>(
242 std::atoi((system::GetParameter("persist.rosen.sethgmrefreshratemode.enabled", "0")).c_str()));
243 }
244
GetColdStartThreadEnabled()245 bool RSSystemProperties::GetColdStartThreadEnabled()
246 {
247 return std::atoi((system::GetParameter("rosen.coldstartthread.enabled", "0")).c_str()) != 0;
248 }
249
GetSkipForAlphaZeroEnabled()250 bool RSSystemProperties::GetSkipForAlphaZeroEnabled()
251 {
252 return std::atoi((system::GetParameter("persist.skipForAlphaZero.enabled", "1")).c_str()) != 0;
253 }
254
GetSkipGeometryNotChangeEnabled()255 bool RSSystemProperties::GetSkipGeometryNotChangeEnabled()
256 {
257 static bool skipGeoNotChangeEnabled =
258 std::atoi((system::GetParameter("persist.skipGeometryNotChange.enabled", "1")).c_str()) != 0;
259 return skipGeoNotChangeEnabled;
260 }
261
GetAnimationScale()262 float RSSystemProperties::GetAnimationScale()
263 {
264 return std::atof((system::GetParameter("persist.sys.graphic.animationscale", "1.0")).c_str());
265 }
266
GetFilterCacheEnabled()267 bool RSSystemProperties::GetFilterCacheEnabled()
268 {
269 // Determine whether the filter cache should be enabled. The default value is 1, which means that it is enabled.
270 // If dirty-region is not properly implemented, the filter cache will act as a skip-frame strategy for filters.
271 static bool filterCacheEnabled =
272 std::atoi((system::GetParameter("persist.sys.graphic.filterCacheEnabled", "1")).c_str()) != 0;
273 return filterCacheEnabled;
274 }
275
GetFilterCacheUpdateInterval()276 int RSSystemProperties::GetFilterCacheUpdateInterval()
277 {
278 // Configure whether to enable skip-frame for the filter cache. The default value is 1, which means that the cached
279 // image is updated with a delay of 1 frame.
280 static int filterCacheUpdateInterval =
281 std::atoi((system::GetParameter("persist.sys.graphic.filterCacheUpdateInterval", "1")).c_str());
282 return filterCacheUpdateInterval;
283 }
284
GetFilterCacheSizeThreshold()285 int RSSystemProperties::GetFilterCacheSizeThreshold()
286 {
287 // Set the minimum size for enabling skip-frame in the filter cache. By default, this value is 400, which means that
288 // skip-frame is only enabled for regions where both the width and height are greater than 400.
289 static int filterCacheSizeThreshold =
290 std::atoi((system::GetParameter("persist.sys.graphic.filterCacheSizeThreshold", "400")).c_str());
291 return filterCacheSizeThreshold;
292 }
293
GetKawaseEnabled()294 bool RSSystemProperties::GetKawaseEnabled()
295 {
296 static bool kawaseBlurEnabled =
297 std::atoi((system::GetParameter("persist.sys.graphic.kawaseEnable", "1")).c_str()) != 0;
298 return kawaseBlurEnabled;
299 }
300
GetBlurEnabled()301 bool RSSystemProperties::GetBlurEnabled()
302 {
303 static bool blurEnabled =
304 std::atoi((system::GetParameter("persist.sys.graphic.blurEnabled", "1")).c_str()) != 0;
305 return blurEnabled;
306 }
307
GetProxyNodeDebugEnabled()308 bool RSSystemProperties::GetProxyNodeDebugEnabled()
309 {
310 static bool proxyNodeDebugEnabled = system::GetParameter("persist.sys.graphic.proxyNodeDebugEnabled", "0") != "0";
311 return proxyNodeDebugEnabled;
312 }
313
GetUIFirstEnabled()314 bool RSSystemProperties::GetUIFirstEnabled()
315 {
316 return (std::atoi((system::GetParameter("rosen.ui.first.enabled", "1")).c_str()) != 0);
317 }
318
GetDebugTraceEnabled()319 bool RSSystemProperties::GetDebugTraceEnabled()
320 {
321 static bool openDebugTrace =
322 std::atoi((system::GetParameter("persist.sys.graphic.openDebugTrace", "0")).c_str()) != 0;
323 return openDebugTrace;
324 }
325
GetCacheCmdEnabled()326 bool RSSystemProperties::GetCacheCmdEnabled()
327 {
328 return std::atoi((system::GetParameter("rosen.cacheCmd.enabled", "1")).c_str()) != 0;
329 }
330
GetASTCEnabled()331 bool RSSystemProperties::GetASTCEnabled()
332 {
333 static bool isASTCEnabled = std::atoi((system::GetParameter("persist.rosen.astc.enabled", "0")).c_str()) != 0;
334 return isASTCEnabled;
335 }
336
GetImageGpuResourceCacheEnable(int width,int height)337 bool RSSystemProperties::GetImageGpuResourceCacheEnable(int width, int height)
338 {
339 static bool cacheEnable =
340 std::atoi((system::GetParameter("persist.sys.graphic.gpuResourceCacheEnable", "1")).c_str()) != 0;
341 if (!cacheEnable) {
342 return false;
343 }
344
345 // default cache full screen image gpu resource.
346 static int widthConfig =
347 std::atoi((system::GetParameter("persist.sys.graphic.gpuResourceCacheWidth", "0")).c_str());
348 static int heightConfig =
349 std::atoi((system::GetParameter("persist.sys.graphic.gpuResourceCacheHeight", "0")).c_str());
350 int cacheWidth = widthConfig == 0 ? DEFAULT_CACHE_WIDTH : widthConfig;
351 int cacheHeight = heightConfig == 0 ? DEFAULT_CACHE_HEIGHT : heightConfig;
352 if (width >= cacheWidth && height >= cacheHeight) {
353 return true;
354 }
355 return false;
356 }
357
GetBoolSystemProperty(const char * name,bool defaultValue)358 bool RSSystemProperties::GetBoolSystemProperty(const char* name, bool defaultValue)
359 {
360 return std::atoi((system::GetParameter(name, defaultValue ? "1" : "0")).c_str()) != 0;
361 }
362
WatchSystemProperty(const char * name,OnSystemPropertyChanged func,void * context)363 int RSSystemProperties::WatchSystemProperty(const char* name, OnSystemPropertyChanged func, void* context)
364 {
365 return WatchParameter(name, func, context);
366 }
367 #if defined (ENABLE_DDGR_OPTIMIZE)
GetDDGRIntegrateEnable()368 bool RSSystemProperties::GetDDGRIntegrateEnable()
369 {
370 static bool isDataStEnable =
371 std::atoi((system::GetParameter("ddgr.data.st.enable", "1")).c_str()) != 0;
372 return isDataStEnable;
373 }
374 #endif
375 } // namespace Rosen
376 } // namespace OHOS
377