/src/skia/modules/skottie/src/effects/DirectionalBlur.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2021 Google Inc. |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license that can be |
5 | | * found in the LICENSE file. |
6 | | */ |
7 | | |
8 | | #include "include/core/SkImageFilter.h" |
9 | | #include "include/core/SkMatrix.h" |
10 | | #include "include/core/SkRefCnt.h" |
11 | | #include "include/core/SkSamplingOptions.h" |
12 | | #include "include/effects/SkImageFilters.h" |
13 | | #include "modules/skottie/src/Adapter.h" |
14 | | #include "modules/skottie/src/SkottiePriv.h" |
15 | | #include "modules/skottie/src/SkottieValue.h" |
16 | | #include "modules/skottie/src/effects/Effects.h" |
17 | | #include "modules/sksg/include/SkSGRenderEffect.h" |
18 | | #include "modules/sksg/include/SkSGRenderNode.h" |
19 | | |
20 | | #include <cstddef> |
21 | | #include <utility> |
22 | | |
23 | | namespace skjson { |
24 | | class ArrayValue; |
25 | | } |
26 | | |
27 | | namespace skottie::internal { |
28 | | |
29 | | namespace { |
30 | | |
31 | | class DirectionalBlurAdapter final : public DiscardableAdapterBase<DirectionalBlurAdapter, |
32 | | sksg::ExternalImageFilter> { |
33 | | public: |
34 | | DirectionalBlurAdapter(const skjson::ArrayValue& jprops, |
35 | | const AnimationBuilder& abuilder) |
36 | | : INHERITED(sksg::ExternalImageFilter::Make()) |
37 | 0 | { |
38 | 0 | enum : size_t { |
39 | 0 | kDirection_Index = 0, |
40 | 0 | kBlurLength_Index = 1, |
41 | 0 | }; |
42 | | |
43 | |
|
44 | 0 | EffectBinder(jprops, abuilder, this) |
45 | 0 | .bind( kDirection_Index, fDirection) |
46 | 0 | .bind( kBlurLength_Index, fBlurLength); |
47 | 0 | } |
48 | | private: |
49 | 0 | void onSync() override { |
50 | 0 | const auto rot = fDirection - 90; |
51 | 0 | auto filter = |
52 | 0 | SkImageFilters::MatrixTransform(SkMatrix::RotateDeg(rot), |
53 | 0 | SkSamplingOptions(SkFilterMode::kLinear), |
54 | 0 | SkImageFilters::Blur(fBlurLength * kBlurSizeToSigma, 0, |
55 | 0 | SkImageFilters::MatrixTransform(SkMatrix::RotateDeg(-rot), |
56 | 0 | SkSamplingOptions(SkFilterMode::kLinear), nullptr))); |
57 | 0 | this->node()->setImageFilter(std::move(filter)); |
58 | 0 | } |
59 | | |
60 | | ScalarValue fDirection = 0; |
61 | | ScalarValue fBlurLength = 0; |
62 | | |
63 | | using INHERITED = DiscardableAdapterBase<DirectionalBlurAdapter, sksg::ExternalImageFilter>; |
64 | | }; |
65 | | |
66 | | } // namespace |
67 | | |
68 | | sk_sp<sksg::RenderNode> EffectBuilder::attachDirectionalBlurEffect(const skjson::ArrayValue& jprops, |
69 | 0 | sk_sp<sksg::RenderNode> layer) const { |
70 | 0 | auto imageFilterNode = fBuilder->attachDiscardableAdapter<DirectionalBlurAdapter>(jprops, |
71 | 0 | *fBuilder); |
72 | 0 | return sksg::ImageFilterEffect::Make(std::move(layer), std::move(imageFilterNode)); |
73 | 0 | } |
74 | | |
75 | | } // namespace skottie::internal |