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