Flutter Engine
The Flutter Engine
TintEffect.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
17
18#include <cstddef>
19#include <utility>
20
21namespace skjson {
22class ArrayValue;
23}
24
25namespace skottie {
26namespace internal {
27
28namespace {
29
30class TintAdapter final : public AnimatablePropertyContainer {
31public:
32 static sk_sp<TintAdapter> Make(const skjson::ArrayValue& jprops,
34 const AnimationBuilder& abuilder) {
35 return sk_sp<TintAdapter>(new TintAdapter(jprops, std::move(layer), abuilder));
36 }
37
38 const auto& node() const { return fFilterNode; }
39
40private:
41 TintAdapter(const skjson::ArrayValue& jprops,
43 const AnimationBuilder& abuilder)
44 : fColorNode0(sksg::Color::Make(SK_ColorBLACK))
45 , fColorNode1(sksg::Color::Make(SK_ColorBLACK))
46 , fFilterNode(sksg::GradientColorFilter::Make(std::move(layer), fColorNode0, fColorNode1)) {
47
48 enum : size_t {
49 kMapBlackTo_Index = 0,
50 kMapWhiteTo_Index = 1,
51 kAmount_Index = 2,
52 // kOpacity_Index = 3, // currently unused (not exported)
53
54 kMax_Index = kAmount_Index,
55 };
56
57 EffectBinder(jprops, abuilder, this)
58 .bind(kMapBlackTo_Index, fMapBlackTo)
59 .bind(kMapWhiteTo_Index, fMapWhiteTo)
60 .bind( kAmount_Index, fAmount );
61 }
62
63 void onSync() override {
64 fColorNode0->setColor(fMapBlackTo);
65 fColorNode1->setColor(fMapWhiteTo);
66
67 fFilterNode->setWeight(fAmount / 100); // 100-based
68 }
69
70 const sk_sp<sksg::Color> fColorNode0,
71 fColorNode1;
72 const sk_sp<sksg::GradientColorFilter> fFilterNode;
73
74 ColorValue fMapBlackTo,
75 fMapWhiteTo;
76 ScalarValue fAmount = 0;
77};
78
79} // namespace
80
81sk_sp<sksg::RenderNode> EffectBuilder::attachTintEffect(const skjson::ArrayValue& jprops,
82 sk_sp<sksg::RenderNode> layer) const {
83 return fBuilder->attachDiscardableAdapter<TintAdapter>(jprops, std::move(layer), *fBuilder);
84}
85
86} // namespace internal
87} // namespace skottie
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void attachDiscardableAdapter(sk_sp< T > adapter) const
Definition: SkottiePriv.h:139
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
SK_API sk_sp< SkShader > Color(SkColor)
SkScalar ScalarValue
Definition: SkottieValue.h:22
Definition: Skottie.h:32
Definition: ref_ptr.h:256