Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
FillEffect.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
19
20#include <cstddef>
21#include <utility>
22
23namespace skjson {
24class ArrayValue;
25}
26
27namespace skottie {
28namespace internal {
29
30namespace {
31
32class FillAdapter final : public AnimatablePropertyContainer {
33public:
34 static sk_sp<FillAdapter> Make(const skjson::ArrayValue& jprops,
36 const AnimationBuilder& abuilder) {
37 return sk_sp<FillAdapter>(new FillAdapter(jprops, std::move(layer), abuilder));
38 }
39
40 const auto& node() const { return fFilterNode; }
41
42private:
43 FillAdapter(const skjson::ArrayValue& jprops,
45 const AnimationBuilder& abuilder)
46 : fColorNode(sksg::Color::Make(SK_ColorBLACK))
47 , fFilterNode(sksg::ModeColorFilter::Make(std::move(layer),
48 fColorNode,
50 enum : size_t {
51 // kFillMask_Index = 0,
52 // kAllMasks_Index = 1,
53 kColor_Index = 2,
54 // kInvert_Index = 3,
55 // kHFeather_Index = 4,
56 // kVFeather_Index = 5,
57 kOpacity_Index = 6,
58 };
59
60 EffectBinder(jprops, abuilder, this)
61 .bind( kColor_Index, fColor )
62 .bind(kOpacity_Index, fOpacity);
63 abuilder.dispatchColorProperty(fColorNode);
64 }
65
66 void onSync() override {
67 auto c = static_cast<SkColor4f>(fColor);
68 c.fA = SkTPin(fOpacity, 0.0f, 1.0f);
69
70 fColorNode->setColor(c.toSkColor());
71 }
72
73 const sk_sp<sksg::Color> fColorNode;
74 const sk_sp<sksg::ModeColorFilter> fFilterNode;
75
76 ColorValue fColor;
77 ScalarValue fOpacity = 1;
78};
79
80} // namespace
81
82sk_sp<sksg::RenderNode> EffectBuilder::attachFillEffect(const skjson::ArrayValue& jprops,
83 sk_sp<sksg::RenderNode> layer) const {
84 return fBuilder->attachDiscardableAdapter<FillAdapter>(jprops, std::move(layer), *fBuilder);
85}
86
87} // namespace internal
88} // namespace skottie
SkBlendMode
Definition SkBlendMode.h:38
@ kSrcIn
r = s * da
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
static std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap *src, const SkYUVAPixmaps *srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options)
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition SkTPin.h:19
void attachDiscardableAdapter(sk_sp< T > adapter) const
SkScalar ScalarValue
Definition Skottie.h:32
Definition ref_ptr.h:256