[skottie] Cleanup: convert remaining effects to new adapter pattern
Also add a couple of tests for missing coverage. TBR= Change-Id: I420c71d73657c5d003fda94a4c43dde20a1a6b87 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/267556 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
parent
3e98c0e1d1
commit
cc982ecbca
@ -146,19 +146,6 @@ sk_sp<sksg::Path> AnimationBuilder::attachPath(const skjson::Value& jpath) const
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
sk_sp<sksg::Color> AnimationBuilder::attachColor(const skjson::ObjectValue& jcolor,
|
||||
const char prop_name[]) const {
|
||||
auto color_node = sksg::Color::Make(SK_ColorBLACK);
|
||||
|
||||
this->bindProperty<VectorValue>(jcolor[prop_name],
|
||||
[color_node](const VectorValue& c) {
|
||||
color_node->setColor(ValueTraits<VectorValue>::As<SkColor>(c));
|
||||
});
|
||||
this->dispatchColorProperty(color_node);
|
||||
|
||||
return color_node;
|
||||
}
|
||||
|
||||
AnimationBuilder::AnimationBuilder(sk_sp<ResourceProvider> rp, sk_sp<SkFontMgr> fontmgr,
|
||||
sk_sp<PropertyObserver> pobserver, sk_sp<Logger> logger,
|
||||
sk_sp<MarkerObserver> mobserver,
|
||||
|
@ -78,7 +78,6 @@ public:
|
||||
|
||||
void log(Logger::Level, const skjson::Value*, const char fmt[], ...) const;
|
||||
|
||||
sk_sp<sksg::Color> attachColor(const skjson::ObjectValue&, const char prop_name[]) const;
|
||||
sk_sp<sksg::Transform> attachMatrix2D(const skjson::ObjectValue&, sk_sp<sksg::Transform>) const;
|
||||
sk_sp<sksg::Transform> attachMatrix3D(const skjson::ObjectValue&, sk_sp<sksg::Transform>) const;
|
||||
|
||||
|
@ -71,6 +71,28 @@ private:
|
||||
const SkSize fLayerSize;
|
||||
};
|
||||
|
||||
// Syntactic sugar/helper.
|
||||
class EffectBinder {
|
||||
public:
|
||||
EffectBinder(const skjson::ArrayValue& jprops,
|
||||
const AnimationBuilder& abuilder,
|
||||
AnimatablePropertyContainer* acontainer)
|
||||
: fProps(jprops)
|
||||
, fBuilder(abuilder)
|
||||
, fContainer(acontainer) {}
|
||||
|
||||
template <typename T>
|
||||
const EffectBinder& bind(size_t prop_index, T& value) const {
|
||||
fContainer->bind(fBuilder, EffectBuilder::GetPropValue(fProps, prop_index), value);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
const skjson::ArrayValue& fProps;
|
||||
const AnimationBuilder& fBuilder;
|
||||
AnimatablePropertyContainer* fContainer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Base class for mask-filter-related effects.
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "modules/skottie/src/effects/Effects.h"
|
||||
|
||||
#include "modules/skottie/src/Adapter.h"
|
||||
#include "modules/skottie/src/SkottieValue.h"
|
||||
#include "modules/sksg/include/SkSGColorFilter.h"
|
||||
#include "modules/sksg/include/SkSGPaint.h"
|
||||
@ -15,44 +16,62 @@
|
||||
namespace skottie {
|
||||
namespace internal {
|
||||
|
||||
namespace {
|
||||
|
||||
class FillAdapter final : public AnimatablePropertyContainer {
|
||||
public:
|
||||
static sk_sp<FillAdapter> Make(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer,
|
||||
const AnimationBuilder& abuilder) {
|
||||
return sk_sp<FillAdapter>(new FillAdapter(jprops, std::move(layer), abuilder));
|
||||
}
|
||||
|
||||
const auto& node() const { return fFilterNode; }
|
||||
|
||||
private:
|
||||
FillAdapter(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer,
|
||||
const AnimationBuilder& abuilder)
|
||||
: fColorNode(sksg::Color::Make(SK_ColorBLACK))
|
||||
, fFilterNode(sksg::ModeColorFilter::Make(std::move(layer),
|
||||
fColorNode,
|
||||
SkBlendMode::kSrcIn)) {
|
||||
enum : size_t {
|
||||
// kFillMask_Index = 0,
|
||||
// kAllMasks_Index = 1,
|
||||
kColor_Index = 2,
|
||||
// kInvert_Index = 3,
|
||||
// kHFeather_Index = 4,
|
||||
// kVFeather_Index = 5,
|
||||
kOpacity_Index = 6,
|
||||
};
|
||||
|
||||
EffectBinder(jprops, abuilder, this)
|
||||
.bind( kColor_Index, fColor )
|
||||
.bind(kOpacity_Index, fOpacity);
|
||||
|
||||
abuilder.dispatchColorProperty(fColorNode);
|
||||
}
|
||||
|
||||
void onSync() override {
|
||||
const auto c = ValueTraits<VectorValue>::As<SkColor>(fColor);
|
||||
const auto a =
|
||||
sk_float_round2int_no_saturate(SkColorGetA(c) * SkTPin(fOpacity, 0.0f, 1.0f));
|
||||
fColorNode->setColor(SkColorSetA(c, a));
|
||||
}
|
||||
|
||||
const sk_sp<sksg::Color> fColorNode;
|
||||
const sk_sp<sksg::ModeColorFilter> fFilterNode;
|
||||
|
||||
VectorValue fColor;
|
||||
ScalarValue fOpacity = 1;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
sk_sp<sksg::RenderNode> EffectBuilder::attachFillEffect(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer) const {
|
||||
enum : size_t {
|
||||
kFillMask_Index = 0,
|
||||
kAllMasks_Index = 1,
|
||||
kColor_Index = 2,
|
||||
kInvert_Index = 3,
|
||||
kHFeather_Index = 4,
|
||||
kVFeather_Index = 5,
|
||||
kOpacity_Index = 6,
|
||||
|
||||
kMax_Index = kOpacity_Index,
|
||||
};
|
||||
|
||||
if (jprops.size() <= kMax_Index) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const skjson::ObjectValue* color_prop = jprops[ kColor_Index];
|
||||
const skjson::ObjectValue* opacity_prop = jprops[kOpacity_Index];
|
||||
if (!color_prop || !opacity_prop) {
|
||||
return nullptr;
|
||||
}
|
||||
sk_sp<sksg::Color> color_node = fBuilder->attachColor(*color_prop, "v");
|
||||
if (!color_node) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
fBuilder->bindProperty<ScalarValue>((*opacity_prop)["v"],
|
||||
[color_node](const ScalarValue& o) {
|
||||
const auto c = color_node->getColor();
|
||||
const auto a = sk_float_round2int_no_saturate(SkTPin(o, 0.0f, 1.0f) * 255);
|
||||
color_node->setColor(SkColorSetA(c, a));
|
||||
});
|
||||
|
||||
return sksg::ModeColorFilter::Make(std::move(layer),
|
||||
std::move(color_node),
|
||||
SkBlendMode::kSrcIn);
|
||||
return fBuilder->attachDiscardableAdapter<FillAdapter>(jprops, std::move(layer), *fBuilder);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "include/core/SkPictureRecorder.h"
|
||||
#include "include/core/SkShader.h"
|
||||
#include "include/effects/SkGradientShader.h"
|
||||
#include "modules/skottie/src/Adapter.h"
|
||||
#include "modules/skottie/src/SkottieValue.h"
|
||||
#include "modules/sksg/include/SkSGRenderNode.h"
|
||||
#include "src/utils/SkJSON.h"
|
||||
@ -166,57 +167,70 @@ private:
|
||||
using INHERITED = sksg::CustomRenderNode;
|
||||
};
|
||||
|
||||
class MotionTileAdapter final : public DiscardableAdapterBase<MotionTileAdapter, TileRenderNode> {
|
||||
public:
|
||||
MotionTileAdapter(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer,
|
||||
const AnimationBuilder& abuilder,
|
||||
const SkSize& layer_size)
|
||||
: INHERITED(sk_make_sp<TileRenderNode>(layer_size, std::move(layer))) {
|
||||
|
||||
enum : size_t {
|
||||
kTileCenter_Index = 0,
|
||||
kTileWidth_Index = 1,
|
||||
kTileHeight_Index = 2,
|
||||
kOutputWidth_Index = 3,
|
||||
kOutputHeight_Index = 4,
|
||||
kMirrorEdges_Index = 5,
|
||||
kPhase_Index = 6,
|
||||
kHorizontalPhaseShift_Index = 7,
|
||||
};
|
||||
|
||||
EffectBinder(jprops, abuilder, this)
|
||||
.bind( kTileCenter_Index, fTileCenter )
|
||||
.bind( kTileWidth_Index, fTileW )
|
||||
.bind( kTileHeight_Index, fTileH )
|
||||
.bind( kOutputWidth_Index, fOutputW )
|
||||
.bind( kOutputHeight_Index, fOutputH )
|
||||
.bind( kMirrorEdges_Index, fMirrorEdges )
|
||||
.bind( kPhase_Index, fPhase )
|
||||
.bind(kHorizontalPhaseShift_Index, fHorizontalPhase);
|
||||
}
|
||||
|
||||
private:
|
||||
void onSync() override {
|
||||
const auto& tiler = this->node();
|
||||
|
||||
tiler->setTileCenter(ValueTraits<VectorValue>::As<SkPoint>(fTileCenter));
|
||||
tiler->setTileWidth (fTileW);
|
||||
tiler->setTileHeight(fTileH);
|
||||
tiler->setOutputWidth (fOutputW);
|
||||
tiler->setOutputHeight(fOutputH);
|
||||
tiler->setPhase(fPhase);
|
||||
tiler->setMirrorEdges(SkToBool(fMirrorEdges));
|
||||
tiler->setHorizontalPhase(SkToBool(fHorizontalPhase));
|
||||
}
|
||||
|
||||
VectorValue fTileCenter;
|
||||
ScalarValue fTileW = 1,
|
||||
fTileH = 1,
|
||||
fOutputW = 1,
|
||||
fOutputH = 1,
|
||||
fMirrorEdges = 0,
|
||||
fPhase = 0,
|
||||
fHorizontalPhase = 0;
|
||||
|
||||
using INHERITED = DiscardableAdapterBase<MotionTileAdapter, TileRenderNode>;
|
||||
};
|
||||
|
||||
} // anonymous ns
|
||||
|
||||
sk_sp<sksg::RenderNode> EffectBuilder::attachMotionTileEffect(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer) const {
|
||||
enum : size_t {
|
||||
kTileCenter_Index = 0,
|
||||
kTileWidth_Index = 1,
|
||||
kTileHeight_Index = 2,
|
||||
kOutputWidth_Index = 3,
|
||||
kOutputHeight_Index = 4,
|
||||
kMirrorEdges_Index = 5,
|
||||
kPhase_Index = 6,
|
||||
kHorizontalPhaseShift_Index = 7,
|
||||
};
|
||||
|
||||
auto tiler = sk_make_sp<TileRenderNode>(fLayerSize, std::move(layer));
|
||||
|
||||
fBuilder->bindProperty<VectorValue>(GetPropValue(jprops, kTileCenter_Index),
|
||||
[tiler](const VectorValue& tc) {
|
||||
tiler->setTileCenter(ValueTraits<VectorValue>::As<SkPoint>(tc));
|
||||
});
|
||||
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kTileWidth_Index),
|
||||
[tiler](const ScalarValue& tw) {
|
||||
tiler->setTileWidth(tw);
|
||||
});
|
||||
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kTileHeight_Index),
|
||||
[tiler](const ScalarValue& th) {
|
||||
tiler->setTileHeight(th);
|
||||
});
|
||||
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kOutputWidth_Index),
|
||||
[tiler](const ScalarValue& ow) {
|
||||
tiler->setOutputWidth(ow);
|
||||
});
|
||||
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kOutputHeight_Index),
|
||||
[tiler](const ScalarValue& oh) {
|
||||
tiler->setOutputHeight(oh);
|
||||
});
|
||||
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kMirrorEdges_Index),
|
||||
[tiler](const ScalarValue& me) {
|
||||
tiler->setMirrorEdges(SkScalarRoundToInt(me));
|
||||
});
|
||||
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kPhase_Index),
|
||||
[tiler](const ScalarValue& ph) {
|
||||
tiler->setPhase(ph);
|
||||
});
|
||||
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kHorizontalPhaseShift_Index),
|
||||
[tiler](const ScalarValue& hp) {
|
||||
tiler->setHorizontalPhase(SkScalarRoundToInt(hp));
|
||||
});
|
||||
|
||||
return tiler;
|
||||
return fBuilder->attachDiscardableAdapter<MotionTileAdapter>(jprops,
|
||||
std::move(layer),
|
||||
*fBuilder,
|
||||
fLayerSize);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/effects/SkGradientShader.h"
|
||||
#include "include/effects/SkShaderMaskFilter.h"
|
||||
#include "modules/skottie/src/Adapter.h"
|
||||
#include "modules/skottie/src/SkottieValue.h"
|
||||
#include "modules/sksg/include/SkSGRenderNode.h"
|
||||
#include "src/utils/SkJSON.h"
|
||||
@ -131,42 +132,56 @@ private:
|
||||
using INHERITED = sksg::CustomRenderNode;
|
||||
};
|
||||
|
||||
class RadialWipeAdapter final : public DiscardableAdapterBase<RadialWipeAdapter, RWipeRenderNode> {
|
||||
public:
|
||||
RadialWipeAdapter(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer,
|
||||
const AnimationBuilder& abuilder)
|
||||
: INHERITED(sk_make_sp<RWipeRenderNode>(std::move(layer))) {
|
||||
|
||||
enum : size_t {
|
||||
kCompletion_Index = 0,
|
||||
kStartAngle_Index = 1,
|
||||
kWipeCenter_Index = 2,
|
||||
kWipe_Index = 3,
|
||||
kFeather_Index = 4,
|
||||
};
|
||||
|
||||
EffectBinder(jprops, abuilder, this)
|
||||
.bind(kCompletion_Index, fCompletion)
|
||||
.bind(kStartAngle_Index, fStartAngle)
|
||||
.bind(kWipeCenter_Index, fWipeCenter)
|
||||
.bind( kWipe_Index, fWipe )
|
||||
.bind( kFeather_Index, fFeather );
|
||||
}
|
||||
|
||||
private:
|
||||
void onSync() override {
|
||||
const auto& wiper = this->node();
|
||||
|
||||
wiper->setCompletion(fCompletion);
|
||||
wiper->setStartAngle(fStartAngle);
|
||||
wiper->setWipeCenter(ValueTraits<VectorValue>::As<SkPoint>(fWipeCenter));
|
||||
wiper->setWipe(fWipe);
|
||||
wiper->setFeather(fFeather);
|
||||
}
|
||||
|
||||
VectorValue fWipeCenter;
|
||||
ScalarValue fCompletion = 0,
|
||||
fStartAngle = 0,
|
||||
fWipe = 0,
|
||||
fFeather = 0;
|
||||
|
||||
using INHERITED = DiscardableAdapterBase<RadialWipeAdapter, RWipeRenderNode>;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
sk_sp<sksg::RenderNode> EffectBuilder::attachRadialWipeEffect(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer) const {
|
||||
enum : size_t {
|
||||
kCompletion_Index = 0,
|
||||
kStartAngle_Index = 1,
|
||||
kWipeCenter_Index = 2,
|
||||
kWipe_Index = 3,
|
||||
kFeather_Index = 4,
|
||||
};
|
||||
|
||||
auto wiper = sk_make_sp<RWipeRenderNode>(std::move(layer));
|
||||
|
||||
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kCompletion_Index),
|
||||
[wiper](const ScalarValue& c) {
|
||||
wiper->setCompletion(c);
|
||||
});
|
||||
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kStartAngle_Index),
|
||||
[wiper](const ScalarValue& sa) {
|
||||
wiper->setStartAngle(sa);
|
||||
});
|
||||
fBuilder->bindProperty<VectorValue>(GetPropValue(jprops, kWipeCenter_Index),
|
||||
[wiper](const VectorValue& c) {
|
||||
wiper->setWipeCenter(ValueTraits<VectorValue>::As<SkPoint>(c));
|
||||
});
|
||||
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kWipe_Index),
|
||||
[wiper](const ScalarValue& w) {
|
||||
wiper->setWipe(w);
|
||||
});
|
||||
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kFeather_Index),
|
||||
[wiper](const ScalarValue& f) {
|
||||
wiper->setFeather(f);
|
||||
});
|
||||
|
||||
return wiper;
|
||||
return fBuilder->attachDiscardableAdapter<RadialWipeAdapter>(jprops,
|
||||
std::move(layer),
|
||||
*fBuilder);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
@ -15,43 +15,62 @@
|
||||
namespace skottie {
|
||||
namespace internal {
|
||||
|
||||
namespace {
|
||||
|
||||
class TintAdapter final : public AnimatablePropertyContainer {
|
||||
public:
|
||||
static sk_sp<TintAdapter> Make(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer,
|
||||
const AnimationBuilder& abuilder) {
|
||||
return sk_sp<TintAdapter>(new TintAdapter(jprops, std::move(layer), abuilder));
|
||||
}
|
||||
|
||||
const auto& node() const { return fFilterNode; }
|
||||
|
||||
private:
|
||||
TintAdapter(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer,
|
||||
const AnimationBuilder& abuilder)
|
||||
: fColorNode0(sksg::Color::Make(SK_ColorBLACK))
|
||||
, fColorNode1(sksg::Color::Make(SK_ColorBLACK))
|
||||
, fFilterNode(sksg::GradientColorFilter::Make(std::move(layer), fColorNode0, fColorNode1)) {
|
||||
|
||||
enum : size_t {
|
||||
kMapBlackTo_Index = 0,
|
||||
kMapWhiteTo_Index = 1,
|
||||
kAmount_Index = 2,
|
||||
// kOpacity_Index = 3, // currently unused (not exported)
|
||||
|
||||
kMax_Index = kAmount_Index,
|
||||
};
|
||||
|
||||
EffectBinder(jprops, abuilder, this)
|
||||
.bind(kMapBlackTo_Index, fMapBlackTo)
|
||||
.bind(kMapWhiteTo_Index, fMapWhiteTo)
|
||||
.bind( kAmount_Index, fAmount );
|
||||
}
|
||||
|
||||
void onSync() override {
|
||||
fColorNode0->setColor(ValueTraits<VectorValue>::As<SkColor>(fMapBlackTo));
|
||||
fColorNode1->setColor(ValueTraits<VectorValue>::As<SkColor>(fMapWhiteTo));
|
||||
|
||||
fFilterNode->setWeight(fAmount / 100); // 100-based
|
||||
}
|
||||
|
||||
const sk_sp<sksg::Color> fColorNode0,
|
||||
fColorNode1;
|
||||
const sk_sp<sksg::GradientColorFilter> fFilterNode;
|
||||
|
||||
VectorValue fMapBlackTo,
|
||||
fMapWhiteTo;
|
||||
ScalarValue fAmount = 0;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
sk_sp<sksg::RenderNode> EffectBuilder::attachTintEffect(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer) const {
|
||||
enum : size_t {
|
||||
kMapBlackTo_Index = 0,
|
||||
kMapWhiteTo_Index = 1,
|
||||
kAmount_Index = 2,
|
||||
// kOpacity_Index = 3, // currently unused (not exported)
|
||||
|
||||
kMax_Index = kAmount_Index,
|
||||
};
|
||||
|
||||
if (jprops.size() <= kMax_Index) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const skjson::ObjectValue* color0_prop = jprops[kMapBlackTo_Index];
|
||||
const skjson::ObjectValue* color1_prop = jprops[kMapWhiteTo_Index];
|
||||
const skjson::ObjectValue* amount_prop = jprops[ kAmount_Index];
|
||||
|
||||
if (!color0_prop || !color1_prop || !amount_prop) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto tint_node =
|
||||
sksg::GradientColorFilter::Make(std::move(layer),
|
||||
fBuilder->attachColor(*color0_prop, "v"),
|
||||
fBuilder->attachColor(*color1_prop, "v"));
|
||||
if (!tint_node) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
fBuilder->bindProperty<ScalarValue>((*amount_prop)["v"],
|
||||
[tint_node](const ScalarValue& w) {
|
||||
tint_node->setWeight(w / 100); // 100-based
|
||||
});
|
||||
|
||||
return tint_node;
|
||||
return fBuilder->attachDiscardableAdapter<TintAdapter>(jprops, std::move(layer), *fBuilder);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "modules/skottie/src/effects/Effects.h"
|
||||
|
||||
#include "modules/skottie/src/Adapter.h"
|
||||
#include "modules/skottie/src/SkottieValue.h"
|
||||
#include "modules/sksg/include/SkSGColorFilter.h"
|
||||
#include "modules/sksg/include/SkSGPaint.h"
|
||||
@ -15,45 +16,66 @@
|
||||
namespace skottie {
|
||||
namespace internal {
|
||||
|
||||
namespace {
|
||||
|
||||
class TritoneAdapter final : public AnimatablePropertyContainer {
|
||||
public:
|
||||
static sk_sp<TritoneAdapter> Make(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer,
|
||||
const AnimationBuilder& abuilder) {
|
||||
return sk_sp<TritoneAdapter>(new TritoneAdapter(jprops, std::move(layer), abuilder));
|
||||
}
|
||||
|
||||
const auto& node() const { return fCF; }
|
||||
|
||||
private:
|
||||
TritoneAdapter(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer,
|
||||
const AnimationBuilder& abuilder)
|
||||
: fLoColorNode(sksg::Color::Make(SK_ColorBLACK))
|
||||
, fMiColorNode(sksg::Color::Make(SK_ColorBLACK))
|
||||
, fHiColorNode(sksg::Color::Make(SK_ColorBLACK))
|
||||
, fCF(sksg::GradientColorFilter::Make(std::move(layer),
|
||||
{ fLoColorNode, fMiColorNode, fHiColorNode })) {
|
||||
enum : size_t {
|
||||
kHiColor_Index = 0,
|
||||
kMiColor_Index = 1,
|
||||
kLoColor_Index = 2,
|
||||
kBlendAmount_Index = 3,
|
||||
};
|
||||
|
||||
EffectBinder(jprops, abuilder, this)
|
||||
.bind( kHiColor_Index, fHiColor)
|
||||
.bind( kMiColor_Index, fMiColor)
|
||||
.bind( kLoColor_Index, fLoColor)
|
||||
.bind(kBlendAmount_Index, fWeight );
|
||||
}
|
||||
|
||||
void onSync() override {
|
||||
fLoColorNode->setColor(ValueTraits<VectorValue>::As<SkColor>(fLoColor));
|
||||
fMiColorNode->setColor(ValueTraits<VectorValue>::As<SkColor>(fMiColor));
|
||||
fHiColorNode->setColor(ValueTraits<VectorValue>::As<SkColor>(fHiColor));
|
||||
|
||||
// 100-based, inverted
|
||||
fCF->setWeight((100 - fWeight) / 100);
|
||||
}
|
||||
|
||||
const sk_sp<sksg::Color> fLoColorNode,
|
||||
fMiColorNode,
|
||||
fHiColorNode;
|
||||
const sk_sp<sksg::GradientColorFilter> fCF;
|
||||
|
||||
VectorValue fLoColor,
|
||||
fMiColor,
|
||||
fHiColor;
|
||||
ScalarValue fWeight = 0;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
sk_sp<sksg::RenderNode> EffectBuilder::attachTritoneEffect(const skjson::ArrayValue& jprops,
|
||||
sk_sp<sksg::RenderNode> layer) const {
|
||||
enum : size_t {
|
||||
kHiColor_Index = 0,
|
||||
kMiColor_Index = 1,
|
||||
kLoColor_Index = 2,
|
||||
kBlendAmount_Index = 3,
|
||||
|
||||
kMax_Index = kBlendAmount_Index,
|
||||
};
|
||||
|
||||
if (jprops.size() <= kMax_Index) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const skjson::ObjectValue* hicolor_prop = jprops[ kHiColor_Index];
|
||||
const skjson::ObjectValue* micolor_prop = jprops[ kMiColor_Index];
|
||||
const skjson::ObjectValue* locolor_prop = jprops[ kLoColor_Index];
|
||||
const skjson::ObjectValue* blend_prop = jprops[kBlendAmount_Index];
|
||||
|
||||
if (!hicolor_prop || !micolor_prop || !locolor_prop || !blend_prop) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto tritone_node =
|
||||
sksg::GradientColorFilter::Make(std::move(layer), {
|
||||
fBuilder->attachColor(*locolor_prop, "v"),
|
||||
fBuilder->attachColor(*micolor_prop, "v"),
|
||||
fBuilder->attachColor(*hicolor_prop, "v") });
|
||||
if (!tritone_node) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
fBuilder->bindProperty<ScalarValue>((*blend_prop)["v"],
|
||||
[tritone_node](const ScalarValue& w) {
|
||||
tritone_node->setWeight((100 - w) / 100); // 100-based, inverted (!?).
|
||||
});
|
||||
|
||||
return tritone_node;
|
||||
return fBuilder->attachDiscardableAdapter<TritoneAdapter>(jprops, std::move(layer), *fBuilder);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
1
resources/skottie/skottie-fill-effect.json
Normal file
1
resources/skottie/skottie-fill-effect.json
Normal file
@ -0,0 +1 @@
|
||||
{"v":"5.5.10","fr":60,"ip":0,"op":601,"w":500,"h":500,"nm":"fill","ddd":0,"assets":[{"id":"comp_0","layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 1","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[250,250,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[200,200],"ix":2},"p":{"a":0,"k":[100,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"fl","c":{"a":0,"k":[0,1,0.250980407,1],"ix":4},"o":{"a":0,"k":75,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":600,"s":[360]}],"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 3","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ty":"sr","sy":1,"d":1,"pt":{"a":0,"k":5,"ix":3},"p":{"a":0,"k":[0,0],"ix":4},"r":{"a":0,"k":0,"ix":5},"ir":{"a":0,"k":50,"ix":6},"is":{"a":0,"k":0,"ix":8},"or":{"a":0,"k":162,"ix":7},"os":{"a":0,"k":0,"ix":9},"ix":1,"nm":"Polystar Path 1","mn":"ADBE Vector Shape - Star","hd":false},{"ty":"fl","c":{"a":0,"k":[1,0.250980407,0,1],"ix":4},"o":{"a":0,"k":75,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":600,"s":[720]}],"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":2,"cix":2,"bm":0,"ix":2,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[175,175],"ix":2},"p":{"a":0,"k":[-90,0],"ix":3},"r":{"a":0,"k":0,"ix":4},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"fl","c":{"a":0,"k":[0.250980407,0,1,1],"ix":4},"o":{"a":0,"k":75,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":600,"s":[-360]}],"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 2","np":2,"cix":2,"bm":0,"ix":3,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":601,"st":0,"bm":0}]}],"layers":[{"ddd":0,"ind":1,"ty":0,"nm":"precomp","refId":"comp_0","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[250,250,0],"ix":2},"a":{"a":0,"k":[250,250,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"ef":[{"ty":21,"nm":"Fill","np":9,"mn":"ADBE Fill","ix":1,"en":1,"ef":[{"ty":10,"nm":"Fill Mask","mn":"ADBE Fill-0001","ix":1,"v":{"a":0,"k":0,"ix":1}},{"ty":7,"nm":"All Masks","mn":"ADBE Fill-0007","ix":2,"v":{"a":0,"k":0,"ix":2}},{"ty":2,"nm":"Color","mn":"ADBE Fill-0002","ix":3,"v":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[1,0,0,1]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":210,"s":[0,1,0,1]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":406,"s":[0,0,1,1]},{"t":600,"s":[1,0,0,1]}],"ix":3}},{"ty":7,"nm":"Invert","mn":"ADBE Fill-0006","ix":4,"v":{"a":0,"k":0,"ix":4}},{"ty":0,"nm":"Horizontal Feather","mn":"ADBE Fill-0003","ix":5,"v":{"a":0,"k":0,"ix":5}},{"ty":0,"nm":"Vertical Feather","mn":"ADBE Fill-0004","ix":6,"v":{"a":0,"k":0,"ix":6}},{"ty":0,"nm":"Opacity","mn":"ADBE Fill-0005","ix":7,"v":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[1]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":300,"s":[0.5]},{"t":600,"s":[1]}],"ix":7}}]}],"w":500,"h":500,"ip":0,"op":601,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":1,"nm":"White Solid 4","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[250,250,0],"ix":2},"a":{"a":0,"k":[250,250,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"sw":500,"sh":500,"sc":"#ffffff","ip":0,"op":601,"st":0,"bm":0}],"markers":[]}
|
1
resources/skottie/skottie-tritone-effect.json
Normal file
1
resources/skottie/skottie-tritone-effect.json
Normal file
@ -0,0 +1 @@
|
||||
{"v":"5.5.10","fr":60,"ip":0,"op":601,"w":500,"h":500,"nm":"tritone","ddd":0,"assets":[{"id":"comp_0","layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 1","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[250,250,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[200,200],"ix":2},"p":{"a":0,"k":[100,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"fl","c":{"a":0,"k":[0,1,0.250980407,1],"ix":4},"o":{"a":0,"k":75,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":600,"s":[360]}],"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 3","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ty":"sr","sy":1,"d":1,"pt":{"a":0,"k":5,"ix":3},"p":{"a":0,"k":[0,0],"ix":4},"r":{"a":0,"k":0,"ix":5},"ir":{"a":0,"k":50,"ix":6},"is":{"a":0,"k":0,"ix":8},"or":{"a":0,"k":162,"ix":7},"os":{"a":0,"k":0,"ix":9},"ix":1,"nm":"Polystar Path 1","mn":"ADBE Vector Shape - Star","hd":false},{"ty":"fl","c":{"a":0,"k":[1,0.250980407,0,1],"ix":4},"o":{"a":0,"k":75,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":600,"s":[720]}],"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":2,"cix":2,"bm":0,"ix":2,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[175,175],"ix":2},"p":{"a":0,"k":[-90,0],"ix":3},"r":{"a":0,"k":0,"ix":4},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"fl","c":{"a":0,"k":[0.250980407,0,1,1],"ix":4},"o":{"a":0,"k":75,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":600,"s":[-360]}],"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 2","np":2,"cix":2,"bm":0,"ix":3,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":601,"st":0,"bm":0}]}],"layers":[{"ddd":0,"ind":1,"ty":0,"nm":"precomp","refId":"comp_0","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[250,250,0],"ix":2},"a":{"a":0,"k":[250,250,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"ef":[{"ty":23,"nm":"Tritone","np":6,"mn":"ADBE Tritone","ix":1,"en":1,"ef":[{"ty":2,"nm":"Highlights","mn":"ADBE Tritone-0001","ix":1,"v":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[1,0.988710165024,0,1]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":300,"s":[0.50727635622,0,1,1]},{"t":600,"s":[1,1,1,0]}],"ix":1}},{"ty":2,"nm":"Midtones","mn":"ADBE Tritone-0002","ix":2,"v":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[1,0,0,1]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":300,"s":[0,0,0,1]},{"t":600,"s":[1,0,0,1]}],"ix":2}},{"ty":2,"nm":"Shadows","mn":"ADBE Tritone-0003","ix":3,"v":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0,1,0,1]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":300,"s":[0,0,0.535355389118,1]},{"t":600,"s":[0,1,0,1]}],"ix":3}},{"ty":0,"nm":"Blend With Original","mn":"ADBE Tritone-0004","ix":4,"v":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":150,"s":[5]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":300,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":450,"s":[0.5]},{"t":600,"s":[0]}],"ix":4}}]}],"w":500,"h":500,"ip":0,"op":601,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":1,"nm":"White Solid 3","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[250,250,0],"ix":2},"a":{"a":0,"k":[250,250,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"sw":500,"sh":500,"sc":"#ffffff","ip":0,"op":601,"st":0,"bm":0}],"markers":[]}
|
Loading…
Reference in New Issue
Block a user