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 <parameter.h>
19 #include <parameters.h>
20 #include "platform/common/rs_log.h"
21 #include "transaction/rs_render_service_client.h"
22
23 namespace OHOS {
24 namespace Rosen {
25
ParseDfxSurfaceNamesString(const std::string & paramsStr,std::vector<std::string> & splitStrs,const std::string & seperator)26 static void ParseDfxSurfaceNamesString(const std::string& paramsStr,
27 std::vector<std::string>& splitStrs, const std::string& seperator)
28 {
29 std::string::size_type pos1 = 0;
30 std::string::size_type pos2 = paramsStr.find(seperator);
31 if (std::string::npos == pos2) {
32 splitStrs.push_back(paramsStr);
33 return;
34 }
35 while (std::string::npos != pos2) {
36 splitStrs.push_back(paramsStr.substr(pos1, pos2 - pos1));
37 pos1 = pos2 + seperator.size();
38 pos2 = paramsStr.find(seperator, pos1);
39 }
40 if (pos1 != paramsStr.length()) {
41 splitStrs.push_back(paramsStr.substr(pos1));
42 }
43 }
44
45 // used by clients
GetUniRenderEnabled()46 bool RSSystemProperties::GetUniRenderEnabled()
47 {
48 static bool inited = false;
49 if (inited) {
50 return isUniRenderEnabled_;
51 }
52
53 isUniRenderEnabled_ = std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient())
54 ->GetUniRenderEnabled();
55 isUniRenderMode_ = isUniRenderEnabled_;
56 inited = true;
57 ROSEN_LOGI("RSSystemProperties::GetUniRenderEnabled:%d", isUniRenderEnabled_);
58 return isUniRenderEnabled_;
59 }
60
GetRenderNodeTraceEnabled()61 bool RSSystemProperties::GetRenderNodeTraceEnabled()
62 {
63 static bool isNeedTrace = system::GetParameter("persist.rosen.rendernodetrace.enabled", "0") != "0";
64 return isNeedTrace;
65 }
66
IsUniRenderMode()67 bool RSSystemProperties::IsUniRenderMode()
68 {
69 return isUniRenderMode_;
70 }
71
SetRenderMode(bool isUni)72 void RSSystemProperties::SetRenderMode(bool isUni)
73 {
74 isUniRenderMode_ = isUni;
75 }
76
GetDirtyRegionDebugType()77 DirtyRegionDebugType RSSystemProperties::GetDirtyRegionDebugType()
78 {
79 return static_cast<DirtyRegionDebugType>(
80 std::atoi((system::GetParameter("rosen.dirtyregiondebug.enabled", "0")).c_str()));
81 }
82
GetPartialRenderEnabled()83 PartialRenderType RSSystemProperties::GetPartialRenderEnabled()
84 {
85 return static_cast<PartialRenderType>(
86 std::atoi((system::GetParameter("rosen.partialrender.enabled", "1")).c_str()));
87 }
88
GetUniPartialRenderEnabled()89 PartialRenderType RSSystemProperties::GetUniPartialRenderEnabled()
90 {
91 return static_cast<PartialRenderType>(
92 std::atoi((system::GetParameter("rosen.uni.partialrender.enabled", "4")).c_str()));
93 }
94
GetContainerWindowConfig()95 ContainerWindowConfigType RSSystemProperties::GetContainerWindowConfig()
96 {
97 return static_cast<ContainerWindowConfigType>(
98 std::atoi((system::GetParameter("rosen.uni.containerwindowconfig", "2")).c_str()));
99 }
100
GetOcclusionEnabled()101 bool RSSystemProperties::GetOcclusionEnabled()
102 {
103 return std::atoi((system::GetParameter("rosen.occlusion.enabled", "1")).c_str()) != 0;
104 }
105
GetRSEventProperty(const std::string & paraName)106 std::string RSSystemProperties::GetRSEventProperty(const std::string ¶Name)
107 {
108 return system::GetParameter(paraName, "0");
109 }
110
GetDirectClientCompEnableStatus()111 bool RSSystemProperties::GetDirectClientCompEnableStatus()
112 {
113 // If the value of rosen.directClientComposition.enabled is not 0 then enable the direct CLIENT composition.
114 // Direct CLIENT composition will be processed only when the num of layer is larger than 11
115 return std::atoi((system::GetParameter("rosen.directClientComposition.enabled", "1")).c_str()) != 0;
116 }
117
GetHighContrastStatus()118 bool RSSystemProperties::GetHighContrastStatus()
119 {
120 // If the value of rosen.directClientComposition.enabled is not 0 then enable the direct CLIENT composition.
121 // Direct CLIENT composition will be processed only when the num of layer is larger than 11
122 return std::atoi((system::GetParameter("rosen.HighContrast.enabled", "0")).c_str()) != 0;
123 }
124
GetTargetDirtyRegionDfxEnabled(std::vector<std::string> & dfxTargetSurfaceNames_)125 bool RSSystemProperties::GetTargetDirtyRegionDfxEnabled(std::vector<std::string>& dfxTargetSurfaceNames_)
126 {
127 std::string targetSurfacesStr = system::GetParameter("rosen.dirtyregiondebug.surfacenames", "0");
128 if (targetSurfacesStr == "0") {
129 dfxTargetSurfaceNames_.clear();
130 return false;
131 }
132 dfxTargetSurfaceNames_.clear();
133 ParseDfxSurfaceNamesString(targetSurfacesStr, dfxTargetSurfaceNames_, ",");
134 return true;
135 }
136
GetCorrectionMode()137 uint32_t RSSystemProperties::GetCorrectionMode()
138 {
139 // If the value of rosen.directClientComposition.enabled is not 0 then enable the direct CLIENT composition.
140 // Direct CLIENT composition will be processed only when the num of layer is larger than 11
141 return std::atoi((system::GetParameter("rosen.CorrectionMode", "999")).c_str());
142 }
143
GetDumpSurfaceType()144 DumpSurfaceType RSSystemProperties::GetDumpSurfaceType()
145 {
146 return static_cast<DumpSurfaceType>(
147 std::atoi((system::GetParameter("rosen.dumpsurfacetype.enabled", "0")).c_str()));
148 }
149
GetDumpSurfaceId()150 uint64_t RSSystemProperties::GetDumpSurfaceId()
151 {
152 return std::atoi((system::GetParameter("rosen.dumpsurfaceid", "0")).c_str());
153 }
154
SetDrawTextAsBitmap(bool flag)155 void RSSystemProperties::SetDrawTextAsBitmap(bool flag)
156 {
157 isDrawTextAsBitmap_ = flag;
158 }
GetDrawTextAsBitmap()159 bool RSSystemProperties::GetDrawTextAsBitmap()
160 {
161 return isDrawTextAsBitmap_;
162 }
163
GetColdStartThreadEnabled()164 bool RSSystemProperties::GetColdStartThreadEnabled()
165 {
166 return std::atoi((system::GetParameter("rosen.coldstartthread.enabled", "0")).c_str()) != 0;
167 }
168
GetAnimationScale()169 float RSSystemProperties::GetAnimationScale()
170 {
171 return std::atof((system::GetParameter("persist.sys.graphic.animationscale", "1.0")).c_str());
172 }
173
GetBoolSystemProperty(const char * name,bool defaultValue)174 bool RSSystemProperties::GetBoolSystemProperty(const char* name, bool defaultValue)
175 {
176 return std::atoi((system::GetParameter(name, defaultValue ? "1" : "0")).c_str()) != 0;
177 }
178
WatchSystemProperty(const char * name,OnSystemPropertyChanged func,void * context)179 int RSSystemProperties::WatchSystemProperty(const char* name, OnSystemPropertyChanged func, void* context)
180 {
181 return WatchParameter(name, func, context);
182 }
183 } // namespace Rosen
184 } // namespace OHOS
185