• 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_GRADIENT_BLUR_PARA_H
16 #define GRAPHICS_EFFECT_GE_GRADIENT_BLUR_PARA_H
17 
18 #include <array>
19 
20 #include "ge_kawase_blur_shader_filter.h"
21 #include "ge_shader_filter.h"
22 #include "ge_visual_effect.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 
27 enum class GEGradientDirection {
28     LEFT = 0,
29     TOP,
30     RIGHT,
31     BOTTOM,
32     LEFT_TOP,
33     LEFT_BOTTOM,
34     RIGHT_TOP,
35     RIGHT_BOTTOM,
36     NONE,
37     START_TO_END,
38     END_TO_START
39 };
40 
41 class GELinearGradientBlurPara {
42 public:
43     static constexpr float ORIGINAL_BASE = 1000.0f; // 1000.0f represents original radius_base
44 
GELinearGradientBlurPara(const float blurRadius,const std::vector<std::pair<float,float>> fractionStops,const GEGradientDirection direction,const bool maskLinearBlurEnabled)45     explicit GELinearGradientBlurPara(const float blurRadius, const std::vector<std::pair<float, float>> fractionStops,
46         const GEGradientDirection direction, const bool maskLinearBlurEnabled)
47         : blurRadius_(blurRadius), fractionStops_(fractionStops), direction_(direction)
48     {
49         if (blurRadius > ORIGINAL_BASE) {
50             useMaskAlgorithm_ = false;
51         } else {
52             useMaskAlgorithm_ = true;
53         }
54 
55         if (maskLinearBlurEnabled && useMaskAlgorithm_) {
56             auto kawaseParams = std::make_shared<Drawing::GEKawaseBlurShaderFilterParams>();
57             kawaseParams->radius = blurRadius_ / 2; // 2: experience factor
58             linearGradientBlurFilter_ = std::make_shared<GEKawaseBlurShaderFilter>(*kawaseParams);
59         }
60     }
61 
62     ~GELinearGradientBlurPara() = default;
63 
64     float blurRadius_;
65     // Each pair in fractionStops_ represents <blur degree, position scale>
66     std::vector<std::pair<float, float>> fractionStops_;
67     GEGradientDirection direction_;
68     std::shared_ptr<GEShaderFilter> linearGradientBlurFilter_;
69     bool useMaskAlgorithm_;
70 };
71 
72 } // namespace Rosen
73 } // namespace OHOS
74 
75 #endif // GRAPHICS_EFFECT_GE_GRADIENT_BLUR_PARA_H
76