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 "hwc_param_parse.h"
17
18 #include "common/rs_common_hook.h"
19
20 #undef LOG_TAG
21 #define LOG_TAG "HWCParamParse"
22
23 namespace OHOS::Rosen {
24
ParseFeatureParam(FeatureParamMapType & featureMap,xmlNode & node)25 int32_t HWCParamParse::ParseFeatureParam(FeatureParamMapType& featureMap, xmlNode& node)
26 {
27 RS_LOGI("start");
28 xmlNode *currNode = &node;
29 if (currNode->xmlChildrenNode == nullptr) {
30 RS_LOGD("stop parsing, no children nodes");
31 return PARSE_GET_CHILD_FAIL;
32 }
33
34 currNode = currNode->xmlChildrenNode;
35 for (; currNode; currNode = currNode->next) {
36 if (currNode->type != XML_ELEMENT_NODE) {
37 continue;
38 }
39
40 if (ParseHwcInternal(featureMap, *currNode) != PARSE_EXEC_SUCCESS) {
41 RS_LOGD("stop parsing, parse internal fail");
42 return PARSE_INTERNAL_FAIL;
43 }
44 }
45 return PARSE_EXEC_SUCCESS;
46 }
47
ParseHwcInternal(FeatureParamMapType & featureMap,xmlNode & node)48 int32_t HWCParamParse::ParseHwcInternal(FeatureParamMapType& featureMap, xmlNode& node)
49 {
50 xmlNode *currNode = &node;
51
52 auto iter = featureMap.find(FEATURE_CONFIGS[HWC]);
53 if (iter != featureMap.end()) {
54 hwcParam_ = std::static_pointer_cast<HWCParam>(iter->second);
55 } else {
56 RS_LOGD("stop parsing, no initializing param map");
57 return PARSE_NO_PARAM;
58 }
59
60 // Start Parse Feature Params
61 int xmlParamType = GetXmlNodeAsInt(*currNode);
62 auto name = ExtractPropertyValue("name", *currNode);
63 auto val = ExtractPropertyValue("value", *currNode);
64 if (xmlParamType == PARSE_XML_FEATURE_SWITCH) {
65 bool isEnabled = ParseFeatureSwitch(val);
66 if (name == "DisableHwcOnExpandScreen") {
67 HWCParam::SetDisableHwcOnExpandScreen(isEnabled);
68 RS_LOGI("parse DisableHwcOnExpandScreen %{public}d", HWCParam::IsDisableHwcOnExpandScreen());
69 } else if (name == "SolidLayerEnabled") {
70 HWCParam::SetSolidLayerEnable(isEnabled);
71 RS_LOGI("parse SolidLayerEnabled %{public}d", HWCParam::IsSolidLayerEnable());
72 }
73 } else if (xmlParamType == PARSE_XML_FEATURE_MULTIPARAM) {
74 if (ParseFeatureMultiParamForApp(*currNode, name) != PARSE_EXEC_SUCCESS) {
75 RS_LOGD("parse MultiParam fail");
76 }
77 } else if (xmlParamType == PARSE_XML_FEATURE_SINGLEPARAM) {
78 if (name == "TvPlayerBundleName") {
79 RsCommonHook::Instance().SetTvPlayerBundleName(val);
80 RS_LOGI("parse TvPlayerBundleName ok");
81 }
82 }
83
84 return PARSE_EXEC_SUCCESS;
85 }
86
ParseFeatureMultiParamForApp(xmlNode & node,std::string & name)87 int32_t HWCParamParse::ParseFeatureMultiParamForApp(xmlNode& node, std::string& name)
88 {
89 xmlNode *currNode = &node;
90 if (currNode->xmlChildrenNode == nullptr) {
91 RS_LOGD("stop parsing, no children nodes");
92 return PARSE_GET_CHILD_FAIL;
93 }
94 currNode = currNode->xmlChildrenNode;
95 for (; currNode; currNode = currNode->next) {
96 if (currNode->type != XML_ELEMENT_NODE) {
97 continue;
98 }
99 auto appName = ExtractPropertyValue("name", *currNode);
100 auto val = ExtractPropertyValue("value", *currNode);
101 if (!IsNumber(val)) {
102 return PARSE_ERROR;
103 }
104 if (name == "SourceTuningForYuv420") {
105 hwcParam_->SetSourceTuningForApp(appName, val);
106 } else if (name == "RsSolidColorLayerConfig") {
107 hwcParam_->SetSolidColorLayerForApp(appName, val);
108 } else if (name == "FilterUnderHwcConfig") {
109 RsCommonHook::Instance().SetFilterUnderHwcConfigByApp(appName, val);
110 RS_LOGD("parse FilterUnderHwcConfig ok");
111 } else {
112 RS_LOGD("ParseFeatureMultiParam cannot find name");
113 return PARSE_NO_PARAM;
114 }
115 }
116 hwcParam_->MoveDataToHgmCore();
117 return PARSE_EXEC_SUCCESS;
118 }
119 } // namespace OHOS::Rosen