• 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 <sstream>
17 #include "opinc_param_parse.h"
18 
19 namespace OHOS::Rosen {
20 
ParseFeatureParam(FeatureParamMapType & featureMap,xmlNode & node)21 int32_t OPIncParamParse::ParseFeatureParam(FeatureParamMapType &featureMap, xmlNode &node)
22 {
23     xmlNode *currNode = &node;
24     if (currNode->xmlChildrenNode == nullptr) {
25         RS_LOGD("OPIncParamParse stop parsing, no children nodes");
26         return PARSE_GET_CHILD_FAIL;
27     }
28 
29     currNode = currNode->xmlChildrenNode;
30     for (; currNode; currNode = currNode->next) {
31         if (currNode->type != XML_ELEMENT_NODE) {
32             continue;
33         }
34 
35         if (ParseOPIncInternal(featureMap, *currNode) != PARSE_EXEC_SUCCESS) {
36             RS_LOGD("OPIncParamParse stop parsing, parse internal fail");
37             return PARSE_INTERNAL_FAIL;
38         }
39     }
40     return PARSE_EXEC_SUCCESS;
41 }
42 
ParseOPIncInternal(FeatureParamMapType & featureMap,xmlNode & node)43 int32_t OPIncParamParse::ParseOPIncInternal(FeatureParamMapType &featureMap, xmlNode &node)
44 {
45     xmlNode *currNode = &node;
46 
47     auto iter = featureMap.find(FEATURE_CONFIGS[OPInc]);
48     if (iter == featureMap.end()) {
49         RS_LOGD("OPIncParamParse stop parsing, no initializing param map");
50         return PARSE_INTERNAL_FAIL;
51     }
52     opincParam_ = std::static_pointer_cast<OPIncParam>(iter->second);
53 
54     // Start Parse Feature Params
55     int xmlParamType = GetXmlNodeAsInt(*currNode);
56     auto name = ExtractPropertyValue("name", *currNode);
57     auto val = ExtractPropertyValue("value", *currNode);
58     if (xmlParamType == PARSE_XML_FEATURE_MULTIPARAM) {
59         bool isEnabled = ParseFeatureSwitch(val);
60         if (name == "OPIncEnabled") {
61             opincParam_->SetOPIncEnable(isEnabled);
62             RS_LOGI("OPIncParamParse parse OPIncEnabled %{public}d", opincParam_->IsOPIncEnable());
63         }
64     } else if (xmlParamType == PARSE_XML_FEATURE_SINGLEPARAM) {
65         if (name == "CacheWidthThresholdPercentValue" && IsNumber(val)) {
66             int num;
67             std::istringstream iss(val);
68             if (iss >> num) {
69                 opincParam_->SetCacheWidthThresholdPercentValue(num);
70                 RS_LOGI("OPIncParamParse parse CacheWidthThresholdPercentValue %{public}d",
71                     opincParam_->GetCacheWidthThresholdPercentValue());
72             }
73         }
74     }
75 
76     return PARSE_EXEC_SUCCESS;
77 }
78 } // namespace OHOS::Rosen