• 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_CLIENT_CORE_RENDER_RS_MATERIAL_FILTER_H
16 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_MATERIAL_FILTER_H
17 
18 #ifdef NEW_SKIA
19 #include "include/effects/SkRuntimeEffect.h"
20 #endif
21 
22 #include "common/rs_color.h"
23 #include "render/rs_hps_blur.h"
24 #include "render/rs_skia_filter.h"
25 #include "render/rs_kawase_blur.h"
26 
27 #include "effect/color_filter.h"
28 #include "draw/color.h"
29 #include "effect/color_matrix.h"
30 #include "effect/image_filter.h"
31 
32 namespace OHOS {
33 namespace Rosen {
34 enum MATERIAL_BLUR_STYLE : int {
35     // card blur style
36     STYLE_CARD_THIN_LIGHT  = 1,
37     STYLE_CARD_LIGHT       = 2,
38     STYLE_CARD_THICK_LIGHT = 3,
39     STYLE_CARD_THIN_DARK   = 4,
40     STYLE_CARD_DARK        = 5,
41     STYLE_CARD_THICK_DARK  = 6,
42 
43     // background blur style
44     STYLE_BACKGROUND_SMALL_LIGHT  = 101,
45     STYLE_BACKGROUND_MEDIUM_LIGHT = 102,
46     STYLE_BACKGROUND_LARGE_LIGHT  = 103,
47     STYLE_BACKGROUND_XLARGE_LIGHT = 104,
48     STYLE_BACKGROUND_SMALL_DARK   = 105,
49     STYLE_BACKGROUND_MEDIUM_DARK  = 106,
50     STYLE_BACKGROUND_LARGE_DARK   = 107,
51     STYLE_BACKGROUND_XLARGE_DARK  = 108
52 };
53 // material blur style params
54 struct MaterialParam {
55     float radius;
56     float saturation;
57     float brightness;
58     RSColor maskColor;
59 };
60 class RSB_EXPORT RSMaterialFilter : public RSDrawingFilterOriginal {
61 public:
62     RSMaterialFilter(int style, float dipScale, BLUR_COLOR_MODE mode, float ratio);
63     RSMaterialFilter(MaterialParam materialParam, BLUR_COLOR_MODE mode);
64     RSMaterialFilter(const RSMaterialFilter&) = delete;
65     RSMaterialFilter operator=(const RSMaterialFilter&) = delete;
66     ~RSMaterialFilter() override;
67     std::shared_ptr<RSFilter> TransformFilter(float fraction) const;
68     bool IsValid() const override;
69     void PreProcess(std::shared_ptr<Drawing::Image> image) override;
70     void PostProcess(Drawing::Canvas& canvas) override;
71     std::shared_ptr<RSDrawingFilterOriginal> Compose(
72         const std::shared_ptr<RSDrawingFilterOriginal>& other) const override;
73     std::string GetDescription() override;
74     std::string GetDetailedDescription() override;
75 
76     std::shared_ptr<RSFilter> Add(const std::shared_ptr<RSFilter>& rhs) override;
77     std::shared_ptr<RSFilter> Sub(const std::shared_ptr<RSFilter>& rhs) override;
78     std::shared_ptr<RSFilter> Multiply(float rhs) override;
79     std::shared_ptr<RSFilter> Negate() override;
80     void DrawImageRect(Drawing::Canvas& canvas, const std::shared_ptr<Drawing::Image>& image,
81         const Drawing::Rect& src, const Drawing::Rect& dst) const override;
82     float GetRadius() const;
83     float GetSaturation() const;
84     float GetBrightness() const;
85     RSColor GetMaskColor() const;
86     BLUR_COLOR_MODE GetColorMode() const;
87     bool CanSkipFrame() const override;
88 
89     bool IsNearEqual(
90         const std::shared_ptr<RSFilter>& other, float threshold = std::numeric_limits<float>::epsilon()) const override;
91     bool IsNearZero(float threshold = std::numeric_limits<float>::epsilon()) const override;
92     void SetGreyCoef(const std::optional<Vector2f>& greyCoef) override;
93 
94     bool IsEqual(const std::shared_ptr<RSFilter>& other) const override;
95     bool IsEqualZero() const override;
96 
97 private:
98     BLUR_COLOR_MODE colorMode_;
99     float radius_ {};
100     float saturation_ = 1.f;
101     float brightness_ = 1.f;
102     RSColor maskColor_ = RSColor();
103     std::optional<Vector2f> greyCoef_;
104 
105     std::shared_ptr<Drawing::ColorFilter> GetColorFilter(float sat, float brightness);
106     std::shared_ptr<Drawing::ImageFilter> CreateMaterialStyle(MATERIAL_BLUR_STYLE style, float dipScale, float ratio);
107     std::shared_ptr<Drawing::ImageFilter> CreateMaterialFilter(float radius, float sat, float brightness);
108     static float RadiusVp2Sigma(float radiusVp, float dipScale);
109 
110     std::shared_ptr<Drawing::ColorFilter> colorFilter_;
111     friend class RSMarshallingHelper;
112 };
113 } // namespace Rosen
114 } // namespace OHOS
115 
116 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BLUR_FILTER_H
117