Flutter Engine
The Flutter Engine
TritoneEffect.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 TritoneAdapter final : public AnimatablePropertyContainer {
31public:
34 const AnimationBuilder& abuilder) {
35 return sk_sp<TritoneAdapter>(new TritoneAdapter(jprops, std::move(layer), abuilder));
36 }
37
38 const auto& node() const { return fCF; }
39
40private:
41 TritoneAdapter(const skjson::ArrayValue& jprops,
43 const AnimationBuilder& abuilder)
44 : fLoColorNode(sksg::Color::Make(SK_ColorBLACK))
45 , fMiColorNode(sksg::Color::Make(SK_ColorBLACK))
46 , fHiColorNode(sksg::Color::Make(SK_ColorBLACK))
47 , fCF(sksg::GradientColorFilter::Make(std::move(layer),
48 { fLoColorNode, fMiColorNode, fHiColorNode })) {
49 enum : size_t {
50 kHiColor_Index = 0,
51 kMiColor_Index = 1,
52 kLoColor_Index = 2,
53 kBlendAmount_Index = 3,
54 };
55
56 EffectBinder(jprops, abuilder, this)
57 .bind( kHiColor_Index, fHiColor)
58 .bind( kMiColor_Index, fMiColor)
59 .bind( kLoColor_Index, fLoColor)
60 .bind(kBlendAmount_Index, fWeight );
61 }
62
63 void onSync() override {
64 fLoColorNode->setColor(fLoColor);
65 fMiColorNode->setColor(fMiColor);
66 fHiColorNode->setColor(fHiColor);
67
68 // 100-based, inverted
69 fCF->setWeight((100 - fWeight) / 100);
70 }
71
72 const sk_sp<sksg::Color> fLoColorNode,
73 fMiColorNode,
74 fHiColorNode;
76
77 ColorValue fLoColor,
78 fMiColor,
79 fHiColor;
80 ScalarValue fWeight = 0;
81};
82
83} // namespace
84
85sk_sp<sksg::RenderNode> EffectBuilder::attachTritoneEffect(const skjson::ArrayValue& jprops,
86 sk_sp<sksg::RenderNode> layer) const {
87 return fBuilder->attachDiscardableAdapter<TritoneAdapter>(jprops, std::move(layer), *fBuilder);
88}
89
90} // namespace internal
91} // 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