| 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 |
|
| 8 |
#include "include/core/SkColor.h" |
| 9 |
#include "include/core/SkRefCnt.h" |
| 10 |
#include "modules/skottie/src/SkottiePriv.h" |
| 11 |
#include "modules/skottie/src/SkottieValue.h" |
| 12 |
#include "modules/skottie/src/animator/Animator.h" |
| 13 |
#include "modules/skottie/src/effects/Effects.h" |
| 14 |
#include "modules/sksg/include/SkSGColorFilter.h" |
| 15 |
#include "modules/sksg/include/SkSGPaint.h" |
| 16 |
#include "modules/sksg/include/SkSGRenderNode.h" |
| 17 |
|
| 18 |
#include <cstddef> |
| 19 |
#include <utility> |
| 20 |
|
| 21 |
namespace skjson { |
| 22 |
class ArrayValue; |
| 23 |
} |
| 24 |
|
| 25 |
namespace skottie { |
| 26 |
namespace internal { |
| 27 |
|
| 28 |
namespace { |
| 29 |
|
| 30 |
class TritoneAdapter final : public AnimatablePropertyContainer { |
| 31 |
public: |
| 32 |
static sk_sp<TritoneAdapter> Make(const skjson::ArrayValue& jprops, |
| 33 |
sk_sp<sksg::RenderNode> layer, |
| 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 |
|
| 40 |
private: |
| 41 |
TritoneAdapter(const skjson::ArrayValue& jprops, |
| 42 |
sk_sp<sksg::RenderNode> layer, |
| 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; |
| 75 |
const sk_sp<sksg::GradientColorFilter> fCF; |
| 76 |
|
| 77 |
ColorValue fLoColor, |
| 78 |
fMiColor, |
| 79 |
fHiColor; |
| 80 |
ScalarValue fWeight = 0; |
| 81 |
}; |
| 82 |
|
| 83 |
} // namespace |
| 84 |
|
| 85 |
sk_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 |