• 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 "filter_param_parse.h"
17 #define XML_KEY_NAME "name"
18 #define XML_KEY_VALUE "value"
19 #define XML_PARAM_FILTER_CACHE_ENABLED "FilterCacheEnabled"
20 #define XML_PARAM_EFFECT_MERGE_ENABLED "EffectMergeEnabled"
21 #define XML_PARAM_BLUR_ADAPTIVE_ADJUST "BlurAdaptiveAdjust"
22 
23 namespace OHOS::Rosen {
24 
ParseFeatureParam(FeatureParamMapType & featureMap,xmlNode & node)25 int32_t FilterParamParse::ParseFeatureParam(FeatureParamMapType &featureMap, xmlNode &node)
26 {
27     RS_LOGI("FilterParamParse start");
28     xmlNode *currNode = &node;
29     if (currNode->xmlChildrenNode == nullptr) {
30         RS_LOGD("FilterParamParse 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 (ParseFilterCacheInternal(featureMap, *currNode) != PARSE_EXEC_SUCCESS) {
41             RS_LOGD("FilterParamParse stop parsing, parse internal fail");
42             return PARSE_INTERNAL_FAIL;
43         }
44     }
45 
46     return PARSE_EXEC_SUCCESS;
47 }
48 
ParseFilterCacheInternal(FeatureParamMapType & featureMap,xmlNode & node)49 int32_t FilterParamParse::ParseFilterCacheInternal(FeatureParamMapType &featureMap, xmlNode &node)
50 {
51     xmlNode *currNode = &node;
52 
53     auto iter = featureMap.find(FEATURE_CONFIGS[FILTER]);
54     if (iter == featureMap.end()) {
55         RS_LOGD("FilterCacheParamParse stop parsing, no initializing param map");
56         return PARSE_NO_PARAM;
57     }
58     filterParam_ = std::static_pointer_cast<FilterParam>(iter->second);
59 
60     // Start Parse Feature Params
61     int xmlParamType = GetXmlNodeAsInt(*currNode);
62     auto name = ExtractPropertyValue(XML_KEY_NAME, *currNode);
63     auto val = ExtractPropertyValue(XML_KEY_VALUE, *currNode);
64     if (xmlParamType == PARSE_XML_FEATURE_SWITCH) {
65         bool isEnabled = ParseFeatureSwitch(val);
66         if (name == XML_PARAM_FILTER_CACHE_ENABLED) {
67             filterParam_->SetFilterCacheEnable(isEnabled);
68             RS_LOGI("FilterParamParse parse FilterCacheEnabled %{public}d", filterParam_->IsFilterCacheEnable());
69         } else if (name == XML_PARAM_EFFECT_MERGE_ENABLED) {
70             filterParam_->SetEffectMergeEnable(isEnabled);
71             RS_LOGI("FilterParamParse parse EffectMergeEnabled %{public}d", filterParam_->IsEffectMergeEnable());
72         } else if (name == XML_PARAM_BLUR_ADAPTIVE_ADJUST) {
73             filterParam_->SetBlurAdaptiveAdjust(isEnabled);
74             RS_LOGI("FilterParamParse parse BlurAdaptiveAdjust %{public}d", filterParam_->IsBlurAdaptiveAdjust());
75         } else {
76             RS_LOGD("FilterParamParse unknown feature name");
77         }
78     }
79 
80     return PARSE_EXEC_SUCCESS;
81 }
82 } // namespace OHOS::Rosen