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()71 bool RSSystemParameters::GetShowRefreshRateEnabled()
72 {
73     static CachedHandle g_Handle = CachedParameterCreate("rosen.showRefreshRate.enabled", "0");
74     int changed = 0;
75     const char *enabled = CachedParameterGetChanged(g_Handle, &changed);
76     return ConvertToInt(enabled, 0) != 0;
77 }
78 
GetQuickSkipPrepareType()79 QuickSkipPrepareType RSSystemParameters::GetQuickSkipPrepareType()
80 {
81     static CachedHandle g_Handle = CachedParameterCreate("rosen.quickskipprepare.enabled", "2");
82     int changed = 0;
83     const char *type = CachedParameterGetChanged(g_Handle, &changed);
84     return static_cast<QuickSkipPrepareType>(ConvertToInt(type, DEFAULT_QUICK_SKIP_PREPARE_TYPE_VALUE));
85 }
86 
GetRsParallelType()87 RsParallelType RSSystemParameters::GetRsParallelType()
88 {
89     static CachedHandle g_Handle = CachedParameterCreate("persist.sys.graphic.parallel.type", "0");
90     int changed = 0;
91     const char *type = CachedParameterGetChanged(g_Handle, &changed);
92     return static_cast<RsParallelType>(ConvertToInt(type, 0));
93 }
94 
GetRsSurfaceCaptureType()95 RsSurfaceCaptureType RSSystemParameters::GetRsSurfaceCaptureType()
96 {
97     if (GetRsParallelType() == RsParallelType::RS_PARALLEL_TYPE_SINGLE_THREAD) {
98         return RsSurfaceCaptureType::RS_SURFACE_CAPTURE_TYPE_MAIN_THREAD;
99     }
100     static CachedHandle g_Handle =
101         CachedParameterCreate("persist.sys.graphic.surface_capture.type", "0");
102     int changed = 0;
103     const char *type = CachedParameterGetChanged(g_Handle, &changed);
104     return static_cast<RsSurfaceCaptureType>(ConvertToInt(type, 0));
105 }
106 
GetVSyncControlEnabled()107 bool RSSystemParameters::GetVSyncControlEnabled()
108 {
109     static bool vsyncControlEnabled =
110         std::atoi((system::GetParameter("persist.sys.graphic.vsyncControlEnabled", "1")).c_str()) != 0;
111     return vsyncControlEnabled;
112 }
113 
GetSystemAnimatedScenesEnabled()114 bool RSSystemParameters::GetSystemAnimatedScenesEnabled()
115 {
116     static bool systemAnimatedScenesEnabled =
117         std::atoi((system::GetParameter("persist.sys.graphic.systemAnimatedScenesEnabled", "1")).c_str()) != 0;
118     return systemAnimatedScenesEnabled;
119 }
120 
GetFilterCacheOcculusionEnabled()121 bool RSSystemParameters::GetFilterCacheOcculusionEnabled()
122 {
123     static bool filterCacheOcclusionEnabled =
124         std::atoi((system::GetParameter("persist.sys.graphic.filterCacheOcclusionEnabled", "1")).c_str()) != 0;
125     return filterCacheOcclusionEnabled;
126 }
127 
GetSkipCanvasNodeOutofScreenEnabled()128 bool RSSystemParameters::GetSkipCanvasNodeOutofScreenEnabled()
129 {
130     static CachedHandle g_Handle = CachedParameterCreate("rosen.skipCanvasNodeOutofScreen.enabled", "0");
131     int changed = 0;
132     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
133     return ConvertToInt(enable, 1) != 0;
134 }
135 
GetDrawingEffectRegionEnabledDfx()136 bool RSSystemParameters::GetDrawingEffectRegionEnabledDfx()
137 {
138     static CachedHandle g_Handle = CachedParameterCreate("rosen.graphic.drawingEffectRegionEnabledDfx", "0");
139     int changed = 0;
140     const char *enableDfx = CachedParameterGetChanged(g_Handle, &changed);
141     return ConvertToInt(enableDfx, 0) != 0;
142 }
143 
GetRenderStop()144 bool RSSystemParameters::GetRenderStop()
145 {
146     static CachedHandle g_Handle = CachedParameterCreate("rosen.render.stop", "0");
147     int changed = 0;
148     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
149     return ConvertToInt(enable, 0) != 0;
150 }
151 
GetOcclusionCallBackToWMSDebugType()152 bool RSSystemParameters::GetOcclusionCallBackToWMSDebugType()
153 {
154     static CachedHandle g_Handle = CachedParameterCreate("rosen.occlusion.callbacktowms.debug.enabled", "0");
155     int changed = 0;
156     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
157     return ConvertToInt(enable, 0) != 0;
158 }
159 
GetPrevalidateHwcNodeEnabled()160 bool RSSystemParameters::GetPrevalidateHwcNodeEnabled()
161 {
162     static bool prevalidateHwcNodeEnabled =
163         std::atoi((system::GetParameter("persist.sys.graphic.prevalidateHwcNode.Enabled", "1")).c_str()) != 0;
164     return prevalidateHwcNodeEnabled;
165 }
166 
GetSolidLayerHwcEnabled()167 bool RSSystemParameters::GetSolidLayerHwcEnabled()
168 {
169     static bool solidLayerHwcEnabled =
170         std::atoi((system::GetParameter("persist.sys.graphic.solidLayer.Enabled", "1")).c_str()) != 0;
171     return solidLayerHwcEnabled;
172 }
173 
GetControlBufferConsumeEnabled()174 bool RSSystemParameters::GetControlBufferConsumeEnabled()
175 {
176     static bool controlBufferConsume =
177         std::atoi((system::GetParameter("persist.sys.graphic.controlBufferConsume.Enabled", "1")).c_str()) != 0;
178     return controlBufferConsume;
179 }
180 
GetHideNotchStatus()181 bool RSSystemParameters::GetHideNotchStatus()
182 {
183     static CachedHandle g_Handle = CachedParameterCreate("persist.sys.graphic.hideNotch.status", "0");
184     int changed = 0;
185     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
186     if (!enable) {
187         return false;
188     }
189     return (strcmp(enable, "2") == 0);
190 }
191 
GetUIFirstDmaBufferEnabled()192 bool RSSystemParameters::GetUIFirstDmaBufferEnabled()
193 {
194     static bool enable =
195         std::atoi((system::GetParameter("persist.sys.graphic.ui.first.dma.enabled", "1")).c_str()) != 0;
196     return enable;
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 
GetWiredScreenOndrawEnabled()205 bool RSSystemParameters::GetWiredScreenOndrawEnabled()
206 {
207     static CachedHandle g_Handle = CachedParameterCreate("rosen.wiredScreenOndraw.enabled", "1");
208     int changed = 0;
209     const char *enable = CachedParameterGetChanged(g_Handle, &changed);
210     return ConvertToInt(enable, 0) != 0;
211 }
212 
GetArsrPreEnabled()213 bool RSSystemParameters::GetArsrPreEnabled()
214 {
215     static bool flag = system::GetBoolParameter("const.display.enable_arsr_pre", true);
216         return flag;
217 }
218 
GetMultimediaEnableCameraRotationCompensation()219 bool RSSystemParameters::GetMultimediaEnableCameraRotationCompensation()
220 {
221     static bool flag = system::GetBoolParameter("const.multimedia.enable_camera_rotation_compensation", 0);
222     return flag;
223 }
224 } // namespace Rosen
225 } // namespace OHOS
226