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_CLIENT_CORE_RENDER_RS_BLUR_FILTER_H
16 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BLUR_FILTER_H
17 
18 #include <optional>
19 
20 #include "include/core/SkColorFilter.h"
21 #ifdef NEW_SKIA
22 #include "include/effects/SkRuntimeEffect.h"
23 #endif
24 
25 #include "property/rs_properties_painter.h"
26 #include "common/rs_macros.h"
27 #include "render/rs_skia_filter.h"
28 #include "render/rs_kawase_blur.h"
29 
30 namespace OHOS {
31 namespace Rosen {
32 class RSB_EXPORT RSBlurFilter : public RSDrawingFilterOriginal {
33 public:
34     RSBlurFilter(float blurRadiusX, float blurRadiusY);
35     RSBlurFilter(const RSBlurFilter&) = delete;
36     RSBlurFilter operator=(const RSBlurFilter&) = delete;
37     ~RSBlurFilter() override;
38     float GetBlurRadiusX();
39     float GetBlurRadiusY();
40     bool IsValid() const override;
41     std::shared_ptr<RSDrawingFilterOriginal> Compose(
42         const std::shared_ptr<RSDrawingFilterOriginal>& other) const override;
43     std::string GetDescription() override;
44     std::string GetDetailedDescription() override;
45 
46     std::shared_ptr<RSFilter> Add(const std::shared_ptr<RSFilter>& rhs) override;
47     std::shared_ptr<RSFilter> Sub(const std::shared_ptr<RSFilter>& rhs) override;
48     std::shared_ptr<RSFilter> Multiply(float rhs) override;
49     std::shared_ptr<RSFilter> Negate() override;
50     void DrawImageRect(Drawing::Canvas& canvas, const std::shared_ptr<Drawing::Image>& image,
51         const Drawing::Rect& src, const Drawing::Rect& dst) const override;
52     void SetGreyCoef(const std::optional<Vector2f>& greyCoef) override;
53 
54     bool CanSkipFrame() const override;
55 
56     bool IsNearEqual(
57         const std::shared_ptr<RSFilter>& other, float threshold = std::numeric_limits<float>::epsilon()) const override;
58     bool IsNearZero(float threshold = std::numeric_limits<float>::epsilon()) const override;
59 
60     bool IsEqual(const std::shared_ptr<RSFilter>& other) const override;
61     bool IsEqualZero() const override;
62 
63 private:
64     float blurRadiusX_;
65     float blurRadiusY_;
66     std::optional<Vector2f> greyCoef_;
67 };
68 } // namespace Rosen
69 } // namespace OHOS
70 
71 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BLUR_FILTER_H