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