1 /*
2  * Copyright (c) 2024 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 #ifndef GRAPHICS_EFFECT_GE_VISUAL_EFFECT_IMPL_H
16 #define GRAPHICS_EFFECT_GE_VISUAL_EFFECT_IMPL_H
17 
18 #include <memory>
19 
20 #include "ge_shader_filter.h"
21 #include "ge_visual_effect.h"
22 
23 #include "effect/color_filter.h"
24 #include "effect/runtime_effect.h"
25 #include "effect/runtime_shader_builder.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 
31 class GEVisualEffectImpl {
32 public:
33     enum class FilterType {
34         NONE,
35         KAWASE_BLUR,
36         MESA_BLUR,
37         GREY, AIBAR,
38         LINEAR_GRADIENT_BLUR,
39         MAGNIFIER,
40         WATER_RIPPLE,
41         MAX
42     };
43 
44     GEVisualEffectImpl(const std::string& name);
45 
46     ~GEVisualEffectImpl();
47 
48     void SetParam(const std::string& tag, int32_t param);
49     void SetParam(const std::string& tag, int64_t param);
50     void SetParam(const std::string& tag, float param);
51     void SetParam(const std::string& tag, double param);
52     void SetParam(const std::string& tag, const char* const param);
53 
54     void SetParam(const std::string& tag, const std::shared_ptr<Drawing::Image> param);
55     void SetParam(const std::string& tag, const std::shared_ptr<Drawing::ColorFilter> param);
56     void SetParam(const std::string& tag, const Drawing::Matrix param);
57     void SetParam(const std::string& tag, const std::vector<std::pair<float, float>>);
58     void SetParam(const std::string& tag, bool param);
59     void SetParam(const std::string& tag, uint32_t param);
60 
SetFilterType(FilterType type)61     void SetFilterType(FilterType type)
62     {
63         filterType_ = type;
64     }
65 
GetFilterType()66     const FilterType& GetFilterType() const
67     {
68         return filterType_;
69     }
70 
MakeMESAParams()71     void MakeMESAParams()
72     {
73         mesaParams_ = std::make_shared<GEMESABlurShaderFilterParams>();
74     }
75 
GetMESAParams()76     const std::shared_ptr<GEMESABlurShaderFilterParams>& GetMESAParams() const
77     {
78         return mesaParams_;
79     }
80 
MakeKawaseParams()81     void MakeKawaseParams()
82     {
83         kawaseParams_ = std::make_shared<GEKawaseBlurShaderFilterParams>();
84     }
85 
GetKawaseParams()86     const std::shared_ptr<GEKawaseBlurShaderFilterParams>& GetKawaseParams() const
87     {
88         return kawaseParams_;
89     }
90 
MakeWaterRippleParams()91     void MakeWaterRippleParams()
92     {
93         waterRippleParams_ = std::make_shared<GEWaterRippleFilterParams>();
94     }
95 
GetWaterRippleParams()96     const std::shared_ptr<GEWaterRippleFilterParams>& GetWaterRippleParams() const
97     {
98         return waterRippleParams_;
99     }
100 
MakeAIBarParams()101     void MakeAIBarParams()
102     {
103         aiBarParams_ = std::make_shared<GEAIBarShaderFilterParams>();
104     }
105 
GetAIBarParams()106     const std::shared_ptr<GEAIBarShaderFilterParams>& GetAIBarParams() const
107     {
108         return aiBarParams_;
109     }
110 
MakeGreyParams()111     void MakeGreyParams()
112     {
113         greyParams_ = std::make_shared<GEGreyShaderFilterParams>();
114     }
115 
GetGreyParams()116     const std::shared_ptr<GEGreyShaderFilterParams>& GetGreyParams() const
117     {
118         return greyParams_;
119     }
120 
MakeLinearGradientBlurParams()121     void MakeLinearGradientBlurParams()
122     {
123         linearGradientBlurParams_ = std::make_shared<GELinearGradientBlurShaderFilterParams>();
124     }
125 
GetLinearGradientBlurParams()126     const std::shared_ptr<GELinearGradientBlurShaderFilterParams>& GetLinearGradientBlurParams() const
127     {
128         return linearGradientBlurParams_;
129     }
130 
MakeMagnifierParams()131     void MakeMagnifierParams()
132     {
133         magnifierParams_ = std::make_shared<GEMagnifierShaderFilterParams>();
134     }
135 
GetMagnifierParams()136     const std::shared_ptr<GEMagnifierShaderFilterParams>& GetMagnifierParams() const
137     {
138         return magnifierParams_;
139     }
140 
141 private:
142     static std::map<const std::string, std::function<void(GEVisualEffectImpl*)>> g_initialMap;
143 
144     void SetMESABlurParams(const std::string& tag, float param);
145     void SetAIBarParams(const std::string& tag, float param);
146     void SetGreyParams(const std::string& tag, float param);
147     void SetLinearGradientBlurParams(const std::string& tag, float param);
148     void SetMagnifierParamsFloat(const std::string& tag, float param);
149     void SetMagnifierParamsUint32(const std::string& tag, uint32_t param);
150     void SetWaterRippleParams(const std::string& tag, float param);
151 
152     FilterType filterType_ = GEVisualEffectImpl::FilterType::NONE;
153 
154     std::shared_ptr<GEKawaseBlurShaderFilterParams> kawaseParams_ = nullptr;
155     std::shared_ptr<GEMESABlurShaderFilterParams> mesaParams_ = nullptr;
156     std::shared_ptr<GEAIBarShaderFilterParams> aiBarParams_ = nullptr;
157     std::shared_ptr<GEGreyShaderFilterParams> greyParams_ = nullptr;
158     std::shared_ptr<GELinearGradientBlurShaderFilterParams> linearGradientBlurParams_ = nullptr;
159     std::shared_ptr<GEMagnifierShaderFilterParams> magnifierParams_ = nullptr;
160     std::shared_ptr<GEWaterRippleFilterParams> waterRippleParams_ = nullptr;
161 };
162 
163 } // namespace Drawing
164 } // namespace Rosen
165 } // namespace OHOS
166 
167 #endif // GRAPHICS_EFFECT_GE_VISUAL_EFFECT_IMPL_H
168