Flutter Engine
The Flutter Engine
GaussianBlurEffect.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 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
18
19#include <array>
20#include <cstddef>
21#include <utility>
22
23namespace skjson {
24class ArrayValue;
25}
26
27namespace skottie {
28namespace internal {
29
30namespace {
31
32class GaussianBlurEffectAdapter final : public AnimatablePropertyContainer {
33public:
36 const AnimationBuilder* abuilder) {
37 return sk_sp<GaussianBlurEffectAdapter>(new GaussianBlurEffectAdapter(jprops,
38 std::move(layer),
39 abuilder));
40 }
41
42 const sk_sp<sksg::RenderNode>& node() const { return fImageFilterEffect; }
43
44private:
45 GaussianBlurEffectAdapter(const skjson::ArrayValue& jprops,
47 const AnimationBuilder* abuilder)
48 : fBlur(sksg::BlurImageFilter::Make())
49 , fImageFilterEffect(sksg::ImageFilterEffect::Make(std::move(layer), fBlur)) {
50 enum : size_t {
51 kBlurriness_Index = 0,
52 kDimensions_Index = 1,
53 kRepeatEdge_Index = 2,
54 };
55
56 EffectBinder(jprops, *abuilder, this)
57 .bind(kBlurriness_Index, fBlurriness)
58 .bind(kDimensions_Index, fDimensions)
59 .bind(kRepeatEdge_Index, fRepeatEdge);
60 }
61
62 void onSync() override {
63 static constexpr SkVector kDimensionsMap[] = {
64 { 1, 1 }, // 1 -> horizontal and vertical
65 { 1, 0 }, // 2 -> horizontal
66 { 0, 1 }, // 3 -> vertical
67 };
68
69 const auto dim_index = SkTPin<size_t>(static_cast<size_t>(fDimensions),
70 1, std::size(kDimensionsMap)) - 1;
71
72 const auto sigma = fBlurriness * kBlurSizeToSigma;
73
74 fBlur->setSigma({ sigma * kDimensionsMap[dim_index].x(),
75 sigma * kDimensionsMap[dim_index].y() });
76
77 // 0 -> repeat edge pixels: off
78 // 1 -> repeat edge pixels: on
79 const auto repeat_edge = static_cast<bool>(fRepeatEdge);
80
81 // Repeat edge pixels implies two things:
82 // - the blur uses kClamp tiling
83 // - the output is cropped to content size
84 fBlur->setTileMode(repeat_edge
87 static_cast<sksg::ImageFilterEffect*>(fImageFilterEffect.get())->setCropping(repeat_edge
90 }
91
93 const sk_sp<sksg::RenderNode> fImageFilterEffect;
94
95 ScalarValue fBlurriness = 0, // Controls the blur sigma.
96 fDimensions = 1, // 1 -> horizontal & vertical, 2 -> horizontal, 3 -> vertical
97 fRepeatEdge = 0; // 0 -> clamp, 1 -> repeat
98};
99
100} // namespace
101
102sk_sp<sksg::RenderNode> EffectBuilder::attachGaussianBlurEffect(
103 const skjson::ArrayValue& jprops,
104 sk_sp<sksg::RenderNode> layer) const {
105 return fBuilder->attachDiscardableAdapter<GaussianBlurEffectAdapter>(jprops,
106 std::move(layer),
107 fBuilder);
108}
109
110} // namespace internal
111} // namespace skottie
T * get() const
Definition: SkRefCnt.h:303
void attachDiscardableAdapter(sk_sp< T > adapter) const
Definition: SkottiePriv.h:139
double y
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
static constexpr float kBlurSizeToSigma
Definition: SkottiePriv.h:47
SkScalar ScalarValue
Definition: SkottieValue.h:22
Definition: Skottie.h:32
Definition: ref_ptr.h:256
constexpr float x() const
Definition: SkPoint_impl.h:181