• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 RENDER_SERVICE_BASE_RENDER_RENDER_RS_GRADIENT_BLUR_PARA_H
16 #define RENDER_SERVICE_BASE_RENDER_RENDER_RS_GRADIENT_BLUR_PARA_H
17 
18 #include <array>
19 #include "common/rs_macros.h"
20 #include "platform/common/rs_system_properties.h"
21 #include "render/rs_filter.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 
26 enum class GradientDirection {
27     LEFT = 0,
28     TOP,
29     RIGHT,
30     BOTTOM,
31     LEFT_TOP,
32     LEFT_BOTTOM,
33     RIGHT_TOP,
34     RIGHT_BOTTOM,
35     NONE,
36     START_TO_END,
37     END_TO_START,
38 };
39 
40 class RSB_EXPORT RSLinearGradientBlurPara {
41 public:
42     float blurRadius_;
43     // Each pair in fractionStops_ represents <blur degree, position scale>
44     std::vector<std::pair<float, float>> fractionStops_;
45     GradientDirection direction_;
46     std::shared_ptr<RSFilter> LinearGradientBlurFilter_;
47     bool isRadiusGradient_ = false;
RSLinearGradientBlurPara(const float blurRadius,const std::vector<std::pair<float,float>> fractionStops,const GradientDirection direction)48     explicit RSLinearGradientBlurPara(const float blurRadius,
49                     const std::vector<std::pair<float, float>>fractionStops, const GradientDirection direction)
50     {
51         blurRadius_ = blurRadius;
52         fractionStops_ = fractionStops;
53         direction_ = direction;
54         isRadiusGradient_ = false;
55         if (RSSystemProperties::GetMaskLinearBlurEnabled()) {
56             LinearGradientBlurFilter_ = RSFilter::CreateBlurFilter(blurRadius_ / 2, blurRadius_ / 2);
57         }
58     }
59     ~RSLinearGradientBlurPara() = default;
60 
Dump(std::string & out)61     void Dump(std::string& out) const
62     {
63         out += "[blurRadius:" + std::to_string(blurRadius_);
64         out += " direction:" + std::to_string(static_cast<int>(direction_)) + " fractionStops[";
65         for (auto& val : fractionStops_) {
66             out += "[blurDegree:" + std::to_string(val.first) + " positionScale:" + std::to_string(val.second) + "] ";
67         }
68         if (fractionStops_.size() > 0) {
69             out.pop_back();
70         }
71         out += "]]";
72     }
73 };
74 } // namespace Rosen
75 } // namespace OHOS
76 
77 #endif // RENDER_SERVICE_BASE_RENDER_RENDER_RS_GRADIENT_BLUR_PARA_H