• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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_KAWASE_BLUR_H
16 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_KAWASE_BLUR_H
17 
18 #include "include/core/SkCanvas.h"
19 #include "include/core/SkData.h"
20 #include "include/core/SkPaint.h"
21 #include "include/core/SkSize.h"
22 #include "include/core/SkString.h"
23 #include "include/core/SkSurface.h"
24 #ifdef NEW_SKIA
25 #include "include/effects/SkRuntimeEffect.h"
26 #endif
27 #include "tools/Resources.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 #ifndef USE_ROSEN_DRAWING
32 struct KawaseParameter {
33     SkRect src;
34     SkRect dst;
35     int radius;
36     sk_sp<SkColorFilter> colorFilter;
37     float alpha;
38 
39     KawaseParameter(const SkRect& s, const SkRect& d, int r, sk_sp<SkColorFilter> color = nullptr, float a = 0.f)
srcKawaseParameter40         : src(s), dst(d), radius(r), colorFilter(color), alpha(a) {}
41 };
42 class KawaseBlurFilter {
43 public:
44     explicit KawaseBlurFilter();
45     ~KawaseBlurFilter();
46     bool ApplyKawaseBlur(SkCanvas& canvas, const sk_sp<SkImage>& image, const KawaseParameter& param);
47 
48 private:
49     static SkMatrix GetShaderTransform(const SkCanvas* canvas, const SkRect& blurRect, float scale = 1.0f);
50     bool ApplyBlur(SkCanvas& canvas, const sk_sp<SkImage>& image, const sk_sp<SkImage>& blurImage,
51         const KawaseParameter& param) const;
52     void ComputeRadiusAndScale(int radius);
53     void AdjustRadiusAndScale();
54     std::string GetDescription() const;
55 
56     static constexpr float baseBlurScale = 0.5f; // base downSample radio
57     static constexpr uint32_t kMaxPasses = 4; // Maximum number of render passes
58     static constexpr uint32_t kMaxPassesLargeRadius = 7;
59     static constexpr float kDilatedConvolution = 2.0f;
60     static constexpr float kDilatedConvolutionLargeRadius = 4.6f;
61     // To avoid downscaling artifacts, interpolate the blurred fbo with the full composited image, up to this radius
62     static constexpr float kMaxCrossFadeRadius = 10.0f;
63     static constexpr bool supportLargeRadius = true;
64 
65 #ifdef NEW_SKIA
66     sk_sp<SkRuntimeEffect> blurEffect_;
67     sk_sp<SkRuntimeEffect> mixEffect_;
68 #endif
69     float blurRadius_ = 0.f;
70     float blurScale_ = 0.25f;
71 };
72 #endif
73 } // namespace Rosen
74 } // namespace OHOS
75 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_KAWASE_BLUR_H
76