1 /*
2 * Copyright (c) 2025 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 "dirtyregion_param_parse.h"
17
18 #include <sstream>
19
20 namespace OHOS::Rosen {
21
ParseFeatureParam(FeatureParamMapType & featureMap,xmlNode & node)22 int32_t DirtyRegionParamParse::ParseFeatureParam(FeatureParamMapType &featureMap, xmlNode &node)
23 {
24 RS_LOGI("DirtyRegionParamParse start");
25 xmlNode *curNode = &node;
26 if (curNode->xmlChildrenNode == nullptr) {
27 RS_LOGE("DirtyRegionParamParse stop parsing, no children nodes");
28 return PARSE_GET_CHILD_FAIL;
29 }
30
31 curNode = curNode->xmlChildrenNode;
32 for (; curNode; curNode = curNode->next) {
33 if (curNode->type != XML_ELEMENT_NODE) {
34 continue;
35 }
36
37 if (ParseDirtyRegionInternal(*curNode) != PARSE_EXEC_SUCCESS) {
38 RS_LOGE("DirtyRegionParamParse stop parsing, parse internal fail");
39 return PARSE_INTERNAL_FAIL;
40 }
41 }
42
43 return PARSE_EXEC_SUCCESS;
44 }
45
ParseDirtyRegionInternal(xmlNode & node)46 int32_t DirtyRegionParamParse::ParseDirtyRegionInternal(xmlNode &node)
47 {
48 // Start Parse Feature Params
49 int xmlParamType = GetXmlNodeAsInt(node);
50 auto name = ExtractPropertyValue("name", node);
51 auto val = ExtractPropertyValue("value", node);
52 if (xmlParamType == PARSE_XML_FEATURE_SWITCH) {
53 bool isEnabled = ParseFeatureSwitch(val);
54 if (name == "DirtyRegionEnabled") {
55 DirtyRegionParam::SetDirtyRegionEnable(isEnabled);
56 } else if (name == "ExpandScreenDirtyRegionEnabled") {
57 DirtyRegionParam::SetExpandScreenDirtyRegionEnable(isEnabled);
58 } else if (name == "ExpandScreenDirtyRegionEnabled") {
59 DirtyRegionParam::SetExpandScreenDirtyRegionEnable(isEnabled);
60 } else if (name == "MirrorScreenDirtyRegionEnabled") {
61 DirtyRegionParam::SetMirrorScreenDirtyRegionEnable(isEnabled);
62 } else if (name == "AdvancedDirtyRegionEnabled") {
63 DirtyRegionParam::SetAdvancedDirtyRegionEnable(isEnabled);
64 } else if (name == "ComposeDirtyRegionEnableInPartialDisplay") {
65 DirtyRegionParam::SetComposeDirtyRegionEnableInPartialDisplay(isEnabled);
66 } else if (name == "TileBasedAlignEnabled") {
67 DirtyRegionParam::SetTileBasedAlignEnable(isEnabled);
68 } else {
69 return PARSE_ERROR;
70 }
71 RS_LOGI("DirtyRegionParamParse Set %{public}s with value: %{public}d", name.c_str(), isEnabled);
72 } else if (xmlParamType == PARSE_XML_FEATURE_SINGLEPARAM) {
73 if (name == "TileBasedAlignBits" && IsNumber(val)) {
74 int num;
75 std::istringstream iss(val);
76 if (iss >> num) {
77 DirtyRegionParam::SetTileBasedAlignBits(num);
78 RS_LOGI("DirtyRegionParamParse parse SetTileBasedAlignBits %{public}d", num);
79 } else {
80 DirtyRegionParam::SetTileBasedAlignEnable(false);
81 return PARSE_ERROR;
82 }
83 } else {
84 DirtyRegionParam::SetTileBasedAlignEnable(false);
85 return PARSE_ERROR;
86 }
87 } else {
88 return PARSE_ERROR;
89 }
90 return PARSE_EXEC_SUCCESS;
91 }
92 } // namespace OHOS::Rosen