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 #ifndef GRAPHIC_FEATURE_PARAM_MANAGER_H
17 #define GRAPHIC_FEATURE_PARAM_MANAGER_H
18
19 #include <list>
20 #include <mutex>
21 #include <unordered_map>
22
23 #include "refbase.h"
24 #include "xml_parser_base.h"
25
26 #include "accessibility_param_parse.h"
27 #include "accessibility_param.h"
28 #include "capture_base_param_parse.h"
29 #include "capture_base_param.h"
30 #include "dirtyregion_param.h"
31 #include "dirtyregion_param_parse.h"
32 #include "drm_param_parse.h"
33 #include "drm_param.h"
34 #include "color_gamut_param_parse.h"
35 #include "color_gamut_param.h"
36 #include "hard_cursor_param.h"
37 #include "hard_cursor_param_parse.h"
38 #include "hfbc_param_parse.h"
39 #include "hfbc_param.h"
40 #include "hwc_param_parse.h"
41 #include "hwc_param.h"
42 #include "mem_param_parse.h"
43 #include "mem_param.h"
44 #include "multiscreen_param_parse.h"
45 #include "multiscreen_param.h"
46 #include "occlusion_culling_param.h"
47 #include "occlusion_culling_param_parse.h"
48 #include "opinc_param_parse.h"
49 #include "opinc_param.h"
50 #include "prevalidate_param_parse.h"
51 #include "prevalidate_param.h"
52 #include "rotateoffscreen_param_parse.h"
53 #include "rotateoffscreen_param.h"
54 #include "speciallayer_param.h"
55 #include "speciallayer_param_parse.h"
56 #include "subtree_parallel_param.h"
57 #include "subtree_parallel_param_parse.h"
58 #include "uifirst_param_parse.h"
59 #include "uifirst_param.h"
60 #include "vrate_param_parse.h"
61 #include "vrate_param.h"
62 #include "filter_param_parse.h"
63 #include "filter_param.h"
64 #include "dvsync_param_parse.h"
65 #include "dvsync_param.h"
66 #include "socperf_param_parse.h"
67 #include "socperf_param.h"
68 #include "surface_capture_param_parse.h"
69 #include "surface_capture_param.h"
70 #include "ui_capture_param_parse.h"
71 #include "ui_capture_param.h"
72
73 namespace OHOS::Rosen {
74 struct ModuleConfig {
75 std::string name;
76 std::function<std::unique_ptr<XMLParserBase>()> xmlParser;
77 std::function<std::unique_ptr<FeatureParam>()> featureParam;
78 };
79 // add new module here
80 const std::vector<ModuleConfig> FEATURE_MODULES = {
81 {FEATURE_CONFIGS[DIRTYREGION], [] { return std::make_unique<DirtyRegionParamParse>(); },
82 [] { return std::make_unique<DirtyRegionParam>(); }},
83 {FEATURE_CONFIGS[COLOR_GAMUT], [] {return std::make_unique<ColorGamutParamParse>(); },
84 [] {return std::make_unique<ColorGamutParam>(); }},
85 {FEATURE_CONFIGS[DRM], [] { return std::make_unique<DRMParamParse>(); },
86 [] { return std::make_unique<DRMParam>(); }},
87 {FEATURE_CONFIGS[HWC], [] {return std::make_unique<HWCParamParse>(); }, [] {return std::make_unique<HWCParam>(); }},
88 {FEATURE_CONFIGS[HFBC], [] {return std::make_unique<HFBCParamParse>(); },
89 [] {return std::make_unique<HFBCParam>(); }},
90 {FEATURE_CONFIGS[MEM], [] { return std::make_unique<MEMParamParse>(); },
91 [] { return std::make_unique<MEMParam>(); }},
92 {FEATURE_CONFIGS[SPECIALLAYER], [] { return std::make_unique<SpecialLayerParamParse>(); },
93 [] { return std::make_unique<SpecialLayerParam>(); }},
94 {FEATURE_CONFIGS[OCCLUSION_CULLING], [] { return std::make_unique<OcclusionCullingParamParse>(); },
95 [] {return std::make_unique<OcclusionCullingParam>(); }},
96 {FEATURE_CONFIGS[OPInc], [] {return std::make_unique<OPIncParamParse>(); },
97 [] {return std::make_unique<OPIncParam>(); }},
98 {FEATURE_CONFIGS[MULTISCREEN], [] { return std::make_unique<MultiScreenParamParse>(); },
99 [] {return std::make_unique<MultiScreenParam>(); }},
100 {FEATURE_CONFIGS[PREVALIDATE], [] { return std::make_unique<PrevalidateParamParse>(); },
101 [] { return std::make_unique<PrevalidateParam>(); }},
102 {FEATURE_CONFIGS[UIFirst], [] {return std::make_unique<UIFirstParamParse>(); },
103 [] {return std::make_unique<UIFirstParam>(); }},
104 {FEATURE_CONFIGS[FILTER], [] { return std::make_unique<FilterParamParse>(); },
105 [] { return std::make_unique<FilterParam>(); }},
106 {FEATURE_CONFIGS[DVSYNC], [] { return std::make_unique<DVSyncParamParse>(); },
107 [] { return std::make_unique<DVSyncParam>(); }},
108 {FEATURE_CONFIGS[HARDCURSOR], [] { return std::make_unique<HardCursorParamParse>(); },
109 [] { return std::make_unique<HardCursorParam>(); }},
110 {FEATURE_CONFIGS[SOC_PERF], [] { return std::make_unique<SOCPerfParamParse>(); },
111 [] { return std::make_unique<SOCPerfParam>(); }},
112 {FEATURE_CONFIGS[CAPTURE_BASE], [] {return std::make_unique<CaptureBaseParamParse>(); },
113 [] {return std::make_unique<CaptureBaseParam>(); }},
114 {FEATURE_CONFIGS[SURFACE_CAPTURE], [] {return std::make_unique<SurfaceCaptureParamParse>(); },
115 [] {return std::make_unique<SurfaceCaptureParam>(); }},
116 {FEATURE_CONFIGS[UI_CAPTURE], [] {return std::make_unique<UICaptureParamParse>(); },
117 [] {return std::make_unique<UICaptureParam>(); }},
118 {FEATURE_CONFIGS[ACCESSIBILITY], [] { return std::make_unique<AccessibilityParamParse>(); },
119 [] { return std::make_unique<AccessibilityParam>(); }},
120 {FEATURE_CONFIGS[VRATE], [] { return std::make_unique<VRateParamParse>(); },
121 [] { return std::make_unique<VRateParam>(); }},
122 {FEATURE_CONFIGS[ROTATEOFFSCREEN], [] { return std::make_unique<RotateOffScreenParamParse>(); },
123 [] { return std::make_unique<RotateOffScreenParam>(); }},
124 {FEATURE_CONFIGS[SUBTREEPARALLEL], [] { return std::make_unique<SubtreeParallelParamParse>(); },
125 [] { return std::make_unique<SubtreeParallelParam>(); }},
126 };
127
128 class GraphicFeatureParamManager : public RefBase {
129 public:
130 static GraphicFeatureParamManager& GetInstance();
131
132 void Init();
133 void FeatureParamParseEntry();
134 std::shared_ptr<FeatureParam> GetFeatureParam(std::string featureName);
135
136 // [featureName, parseFunc]
137 std::unordered_map<std::string, std::shared_ptr<XMLParserBase>> featureParseMap_;
138 // [featureName, featureParam]
139 std::unordered_map<std::string, std::shared_ptr<FeatureParam>> featureParamMap_;
140
141 private:
142 GraphicFeatureParamManager();
143 ~GraphicFeatureParamManager() noexcept override;
144
145 std::string graphicConfigPath_ = "etc/graphic/graphic_config.xml";
146
147 std::unique_ptr<XMLParserBase> featureParser_ = nullptr;
148 };
149
150 template<class Ret, class Cls, class... FuncArgs, class... Args>
GetFeatureParamValue(const std::string & featureName,Ret (Cls::* func)(FuncArgs &&...)const,Args &&...args)151 std::optional<Ret> GetFeatureParamValue(const std::string& featureName,
152 Ret (Cls::*func)(FuncArgs&&...) const, Args&&... args)
153 {
154 static_assert(std::is_base_of_v<FeatureParam, Cls>, "Invalid Param Type");
155 auto pParam = GraphicFeatureParamManager::GetInstance().GetFeatureParam(featureName);
156 if (pParam == nullptr || func == nullptr) {
157 return std::nullopt;
158 }
159 auto pCls = std::static_pointer_cast<Cls>(pParam);
160 return ((pCls.get())->*func)(std::forward<Args>(args)...);
161 }
162 } // namespace OHOS::Rosen
163 #endif // GRAPHIC_FEATURE_PARAM_MANAGER_H