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 "hfbc_param_parse.h"
17
18 #include "hgm_core.h"
19
20 namespace OHOS::Rosen {
21
ParseFeatureParam(FeatureParamMapType & featureMap,xmlNode & node)22 int32_t HFBCParamParse::ParseFeatureParam(FeatureParamMapType &featureMap, xmlNode &node)
23 {
24 RS_LOGI("HFBCParamParse start");
25 xmlNode *currNode = &node;
26 if (currNode->xmlChildrenNode == nullptr) {
27 RS_LOGE("HFBCParamParse stop parsing, no children nodes");
28 return PARSE_GET_CHILD_FAIL;
29 }
30
31 currNode = currNode->xmlChildrenNode;
32 for (; currNode; currNode = currNode->next) {
33 if (currNode->type != XML_ELEMENT_NODE) {
34 continue;
35 }
36
37 if (ParseHfbcInternal(*currNode) != PARSE_EXEC_SUCCESS) {
38 RS_LOGE("HFBCParamParse stop parsing, parse internal fail");
39 return PARSE_INTERNAL_FAIL;
40 }
41 }
42
43 return PARSE_EXEC_SUCCESS;
44 }
45
ParseHfbcInternal(xmlNode & node)46 int32_t HFBCParamParse::ParseHfbcInternal(xmlNode &node)
47 {
48 xmlNode *currNode = &node;
49
50 // Start Parse Feature Params
51 int xmlParamType = GetXmlNodeAsInt(*currNode);
52 auto name = ExtractPropertyValue("name", *currNode);
53 auto val = ExtractPropertyValue("value", *currNode);
54 if (xmlParamType == PARSE_XML_FEATURE_MULTIPARAM) {
55 if (ParseFeatureMultiParamForApp(*currNode, name) != PARSE_EXEC_SUCCESS) {
56 RS_LOGE("HFBCParamParse parse MultiParam fail");
57 }
58 if (name == "HfbcDisable") {
59 HgmTaskHandleThread::Instance().PostTask([val] () {
60 HgmHfbcConfig& hfbcConfig = HgmCore::Instance().GetHfbcConfig();
61 RS_LOGI("HFBCParamParse postTask about hfbcConfig");
62 hfbcConfig.SetHfbcConfigMap(HFBCParam::GetHfbcConfigMap());
63 // val 0: enable list mode, other: disable list mode
64 hfbcConfig.SetHfbcControlMode(val != "0");
65 });
66 }
67 }
68 return PARSE_EXEC_SUCCESS;
69 }
70
ParseFeatureMultiParamForApp(xmlNode & node,std::string & name)71 int32_t HFBCParamParse::ParseFeatureMultiParamForApp(xmlNode &node, std::string &name)
72 {
73 xmlNode *currNode = &node;
74 if (currNode->xmlChildrenNode == nullptr) {
75 RS_LOGE("HFBCParamParse stop parsing, no children nodes");
76 return PARSE_GET_CHILD_FAIL;
77 }
78 currNode = currNode->xmlChildrenNode;
79 for (; currNode; currNode = currNode->next) {
80 if (currNode->type != XML_ELEMENT_NODE) {
81 continue;
82 }
83 auto property = ExtractPropertyValue("name", *currNode);
84 auto val = ExtractPropertyValue("value", *currNode);
85 if (!IsNumber(val)) {
86 return PARSE_ERROR;
87 }
88 RS_LOGI("HFBCParamParse %{public}s: property:%{public}s, value:%{public}s",
89 __func__, property.c_str(), val.c_str());
90 if (name == "HfbcDisable") {
91 HFBCParam::SetHfbcConfigForApp(property, val);
92 } else {
93 RS_LOGE("HFBCParamParse ParseFeatureMultiParam cannot find name:%s", name.c_str());
94 return PARSE_NO_PARAM;
95 }
96 }
97 return PARSE_EXEC_SUCCESS;
98 }
99 } // namespace OHOS::Rosen