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(featureMap, *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(FeatureParamMapType & featureMap,xmlNode & node)46 int32_t DirtyRegionParamParse::ParseDirtyRegionInternal(FeatureParamMapType &featureMap, xmlNode &node)
47 {
48 auto iter = featureMap.find(FEATURE_CONFIGS[DIRTYREGION]);
49 if (iter != featureMap.end()) {
50 dirtyRegionParam_ = std::static_pointer_cast<DirtyRegionParam>(iter->second);
51 } else {
52 RS_LOGE("DirtyRegionParamParse stop parsing, no initializing param map");
53 return PARSE_NO_PARAM;
54 }
55
56 // Start Parse Feature Params
57 int xmlParamType = GetXmlNodeAsInt(node);
58 auto name = ExtractPropertyValue("name", node);
59 auto val = ExtractPropertyValue("value", node);
60 if (xmlParamType == PARSE_XML_FEATURE_SWITCH) {
61 bool isEnabled = ParseFeatureSwitch(val);
62 if (name == "DirtyRegionEnabled") {
63 dirtyRegionParam_->SetDirtyRegionEnable(isEnabled);
64 } else if (name == "ExpandScreenDirtyRegionEnabled") {
65 dirtyRegionParam_->SetExpandScreenDirtyRegionEnable(isEnabled);
66 } else if (name == "ExpandScreenDirtyRegionEnabled") {
67 dirtyRegionParam_->SetExpandScreenDirtyRegionEnable(isEnabled);
68 } else if (name == "MirrorScreenDirtyRegionEnabled") {
69 dirtyRegionParam_->SetMirrorScreenDirtyRegionEnable(isEnabled);
70 } else if (name == "AdvancedDirtyRegionEnabled") {
71 dirtyRegionParam_->SetAdvancedDirtyRegionEnable(isEnabled);
72 } else if (name == "TileBasedAlignEnabled") {
73 dirtyRegionParam_->SetTileBasedAlignEnable(isEnabled);
74 } else {
75 return PARSE_ERROR;
76 }
77 RS_LOGI("DirtyRegionParamParse Set %{public}s with value: %{public}d", name.c_str(), isEnabled);
78 } else if (xmlParamType == PARSE_XML_FEATURE_SINGLEPARAM) {
79 if (name == "TileBasedAlignBits" && IsNumber(val)) {
80 int num;
81 std::istringstream iss(val);
82 if (iss >> num) {
83 dirtyRegionParam_->SetTileBasedAlignBits(num);
84 RS_LOGI("DirtyRegionParamParse parse SetTileBasedAlignBits %{public}d", num);
85 } else {
86 dirtyRegionParam_->SetTileBasedAlignEnable(false);
87 return PARSE_ERROR;
88 }
89 } else {
90 dirtyRegionParam_->SetTileBasedAlignEnable(false);
91 return PARSE_ERROR;
92 }
93 } else {
94 return PARSE_ERROR;
95 }
96 return PARSE_EXEC_SUCCESS;
97 }
98 } // namespace OHOS::Rosen