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