[skottie] Cleanup: convert more effects to new animator pattern

TBR=
Change-Id: I9b538853766f31854bba4752cb0f7c20d61c148b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/265076
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2020-01-17 11:22:53 -05:00 committed by Skia Commit-Bot
parent f631cf3d16
commit e905233c8d
8 changed files with 261 additions and 309 deletions

View File

@ -7,7 +7,7 @@
#include "modules/skottie/src/effects/Effects.h"
#include "modules/skottie/src/SkottieAdapter.h"
#include "modules/skottie/src/Animator.h"
#include "modules/skottie/src/SkottieValue.h"
#include "modules/sksg/include/SkSGRenderEffect.h"
#include "src/utils/SkJSON.h"
@ -17,24 +17,43 @@ namespace internal {
namespace {
class DropShadowAdapter final : public SkNVRefCnt<DropShadowAdapter> {
class DropShadowAdapter final : public AnimatablePropertyContainer {
public:
explicit DropShadowAdapter(sk_sp<sksg::DropShadowImageFilter> dropShadow)
: fDropShadow(std::move(dropShadow)) {
SkASSERT(fDropShadow);
static sk_sp<DropShadowAdapter> Make(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer,
const AnimationBuilder* abuilder) {
return sk_sp<DropShadowAdapter>(new DropShadowAdapter(jprops, std::move(layer), abuilder));
}
ADAPTER_PROPERTY(Color , SkColor , SK_ColorBLACK)
ADAPTER_PROPERTY(Opacity , SkScalar, 255)
ADAPTER_PROPERTY(Direction , SkScalar, 0)
ADAPTER_PROPERTY(Distance , SkScalar, 0)
ADAPTER_PROPERTY(Softness , SkScalar, 0)
ADAPTER_PROPERTY(ShadowOnly, bool , false)
const sk_sp<sksg::RenderNode>& renderNode() const { return fImageFilterEffect; }
private:
void apply() {
DropShadowAdapter(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer,
const AnimationBuilder* abuilder)
: fDropShadow(sksg::DropShadowImageFilter::Make())
, fImageFilterEffect(sksg::ImageFilterEffect::Make(std::move(layer), fDropShadow)) {
enum : size_t {
kShadowColor_Index = 0,
kOpacity_Index = 1,
kDirection_Index = 2,
kDistance_Index = 3,
kSoftness_Index = 4,
kShadowOnly_Index = 5,
};
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kShadowColor_Index), &fColor );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kOpacity_Index), &fOpacity );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kDirection_Index), &fDirection);
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kDistance_Index), &fDistance );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kSoftness_Index), &fSoftness );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kShadowOnly_Index), &fShdwOnly );
}
void onSync() override {
// fColor -> RGB, fOpacity -> A
fDropShadow->setColor(SkColorSetA(fColor, SkTPin(SkScalarRoundToInt(fOpacity), 0, 255)));
const auto color = ValueTraits<VectorValue>::As<SkColor>(fColor);
fDropShadow->setColor(SkColorSetA(color, SkTPin(SkScalarRoundToInt(fOpacity), 0, 255)));
// The offset is specified in terms of a bearing angle + distance.
SkScalar rad = SkDegreesToRadians(90 - fDirection);
@ -46,55 +65,29 @@ private:
const auto sigma = fSoftness * kSoftnessToSigmaFactor;
fDropShadow->setSigma(SkVector::Make(sigma, sigma));
fDropShadow->setMode(fShadowOnly ? sksg::DropShadowImageFilter::Mode::kShadowOnly
: sksg::DropShadowImageFilter::Mode::kShadowAndForeground);
fDropShadow->setMode(SkToBool(fShdwOnly)
? sksg::DropShadowImageFilter::Mode::kShadowOnly
: sksg::DropShadowImageFilter::Mode::kShadowAndForeground);
}
const sk_sp<sksg::DropShadowImageFilter> fDropShadow;
const sk_sp<sksg::RenderNode> fImageFilterEffect;
VectorValue fColor = { 0, 0, 0, 1 };
ScalarValue fOpacity = 255.f,
fDirection = 0,
fDistance = 0,
fSoftness = 0,
fShdwOnly = 0;
};
} // anonymous ns
sk_sp<sksg::RenderNode> EffectBuilder::attachDropShadowEffect(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer) const {
enum : size_t {
kShadowColor_Index = 0,
kOpacity_Index = 1,
kDirection_Index = 2,
kDistance_Index = 3,
kSoftness_Index = 4,
kShadowOnly_Index = 5,
};
auto shadow_effect = sksg::DropShadowImageFilter::Make();
auto shadow_adapter = sk_make_sp<DropShadowAdapter>(shadow_effect);
fBuilder->bindProperty<VectorValue>(GetPropValue(jprops, kShadowColor_Index),
[shadow_adapter](const VectorValue& c) {
shadow_adapter->setColor(ValueTraits<VectorValue>::As<SkColor>(c));
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kOpacity_Index),
[shadow_adapter](const ScalarValue& o) {
shadow_adapter->setOpacity(o);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kDirection_Index),
[shadow_adapter](const ScalarValue& d) {
shadow_adapter->setDirection(d);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kDistance_Index),
[shadow_adapter](const ScalarValue& d) {
shadow_adapter->setDistance(d);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kSoftness_Index),
[shadow_adapter](const ScalarValue& s) {
shadow_adapter->setSoftness(s);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kShadowOnly_Index),
[shadow_adapter](const ScalarValue& s) {
shadow_adapter->setShadowOnly(SkToBool(s));
});
return sksg::ImageFilterEffect::Make(std::move(layer), std::move(shadow_effect));
return fBuilder->attachDiscardableAdapter<DropShadowAdapter>(jprops,
std::move(layer),
fBuilder);
}
} // namespace internal

View File

@ -132,9 +132,7 @@ MaskFilterEffectBase::MaskFilterEffectBase(sk_sp<sksg::RenderNode> child, const
, fMaskEffectNode(sksg::MaskFilterEffect::Make(std::move(child), fMaskNode))
, fLayerSize(ls) {}
MaskFilterEffectBase::~MaskFilterEffectBase() = default;
void MaskFilterEffectBase::apply() const {
void MaskFilterEffectBase::onSync() {
const auto minfo = this->onMakeMask();
fMaskEffectNode->setVisible(minfo.fVisible);

View File

@ -8,6 +8,7 @@
#ifndef SkottieEffects_DEFINED
#define SkottieEffects_DEFINED
#include "modules/skottie/src/Animator.h"
#include "modules/skottie/src/SkottiePriv.h"
class SkMaskFilter;
@ -74,19 +75,15 @@ private:
/**
* Base class for mask-filter-related effects.
*/
class MaskFilterEffectBase : public SkRefCnt {
class MaskFilterEffectBase : public AnimatablePropertyContainer {
public:
~MaskFilterEffectBase() override;
const sk_sp<sksg::MaskFilterEffect>& root() const { return fMaskEffectNode; }
const sk_sp<sksg::MaskFilterEffect>& renderNode() const { return fMaskEffectNode; }
protected:
MaskFilterEffectBase(sk_sp<sksg::RenderNode>, const SkSize&);
const SkSize& layerSize() const { return fLayerSize; }
void apply() const;
struct MaskInfo {
sk_sp<SkMaskFilter> fMask;
bool fVisible;
@ -94,6 +91,8 @@ protected:
virtual MaskInfo onMakeMask() const = 0;
private:
void onSync() final;
const sk_sp<sksg::MaskFilter> fMaskNode;
const sk_sp<sksg::MaskFilterEffect> fMaskEffectNode;
const SkSize fLayerSize;

View File

@ -7,7 +7,7 @@
#include "modules/skottie/src/effects/Effects.h"
#include "modules/skottie/src/SkottieAdapter.h"
#include "modules/skottie/src/Animator.h"
#include "modules/skottie/src/SkottieValue.h"
#include "modules/sksg/include/SkSGRenderEffect.h"
#include "src/utils/SkJSON.h"
@ -17,35 +17,36 @@ namespace internal {
namespace {
class GaussianBlurEffectAdapter final : public SkNVRefCnt<GaussianBlurEffectAdapter> {
class GaussianBlurEffectAdapter final : public AnimatablePropertyContainer {
public:
explicit GaussianBlurEffectAdapter(sk_sp<sksg::BlurImageFilter> blur)
: fBlur(std::move(blur)) {
SkASSERT(fBlur);
static sk_sp<GaussianBlurEffectAdapter> Make(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer,
const AnimationBuilder* abuilder) {
return sk_sp<GaussianBlurEffectAdapter>(new GaussianBlurEffectAdapter(jprops,
std::move(layer),
abuilder));
}
// AE/BM model properties. These are all animatable/interpolatable.
// Controls the blur sigma.
ADAPTER_PROPERTY(Blurriness, SkScalar, 0)
// Enum selecting the blur dimensionality:
//
// 1 -> horizontal & vertical
// 2 -> horizontal
// 3 -> vertical
//
ADAPTER_PROPERTY(Dimensions, SkScalar, 1)
// Enum selecting edge behavior:
//
// 0 -> clamp
// 1 -> repeat
//
ADAPTER_PROPERTY(RepeatEdge, SkScalar, 0)
const sk_sp<sksg::RenderNode>& renderNode() const { return fImageFilterEffect; }
private:
void apply() {
GaussianBlurEffectAdapter(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer,
const AnimationBuilder* abuilder)
: fBlur(sksg::BlurImageFilter::Make())
, fImageFilterEffect(sksg::ImageFilterEffect::Make(std::move(layer), fBlur)) {
enum : size_t {
kBlurriness_Index = 0,
kDimensions_Index = 1,
kRepeatEdge_Index = 2,
};
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kBlurriness_Index), &fBlurriness);
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kDimensions_Index), &fDimensions);
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kRepeatEdge_Index), &fRepeatEdge);
}
void onSync() override {
static constexpr SkVector kDimensionsMap[] = {
{ 1, 1 }, // 1 -> horizontal and vertical
{ 1, 0 }, // 2 -> horizontal
@ -73,6 +74,11 @@ private:
}
const sk_sp<sksg::BlurImageFilter> fBlur;
const sk_sp<sksg::RenderNode> fImageFilterEffect;
ScalarValue fBlurriness = 0, // Controls the blur sigma.
fDimensions = 1, // 1 -> horizontal & vertical, 2 -> horizontal, 3 -> vertical
fRepeatEdge = 0; // 0 -> clamp, 1 -> repeat
};
} // anonymous ns
@ -80,29 +86,9 @@ private:
sk_sp<sksg::RenderNode> EffectBuilder::attachGaussianBlurEffect(
const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer) const {
enum : size_t {
kBlurriness_Index = 0,
kDimensions_Index = 1,
kRepeatEdge_Index = 2,
};
auto blur_effect = sksg::BlurImageFilter::Make();
auto blur_addapter = sk_make_sp<GaussianBlurEffectAdapter>(blur_effect);
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kBlurriness_Index),
[blur_addapter](const ScalarValue& b) {
blur_addapter->setBlurriness(b);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kDimensions_Index),
[blur_addapter](const ScalarValue& d) {
blur_addapter->setDimensions(d);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kRepeatEdge_Index),
[blur_addapter](const ScalarValue& r) {
blur_addapter->setRepeatEdge(r);
});
return sksg::ImageFilterEffect::Make(std::move(layer), std::move(blur_effect));
return fBuilder->attachDiscardableAdapter<GaussianBlurEffectAdapter>(jprops,
std::move(layer),
fBuilder);
}
} // namespace internal

View File

@ -7,7 +7,7 @@
#include "modules/skottie/src/effects/Effects.h"
#include "modules/skottie/src/SkottieAdapter.h"
#include "modules/skottie/src/Animator.h"
#include "modules/skottie/src/SkottieValue.h"
#include "modules/sksg/include/SkSGGradient.h"
#include "modules/sksg/include/SkSGRenderEffect.h"
@ -18,31 +18,49 @@ namespace internal {
namespace {
class GradientRampEffectAdapter final : public SkNVRefCnt<GradientRampEffectAdapter> {
class GradientRampEffectAdapter final : public AnimatablePropertyContainer {
public:
explicit GradientRampEffectAdapter(sk_sp<sksg::RenderNode> child)
: fRoot(sksg::ShaderEffect::Make(std::move(child))) {}
static sk_sp<GradientRampEffectAdapter> Make(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer,
const AnimationBuilder* abuilder) {
return sk_sp<GradientRampEffectAdapter>(new GradientRampEffectAdapter(jprops,
std::move(layer),
abuilder));
}
ADAPTER_PROPERTY(StartPoint, SkPoint , SkPoint::Make(0, 0))
ADAPTER_PROPERTY(EndPoint , SkPoint , SkPoint::Make(0, 0))
ADAPTER_PROPERTY(StartColor, SkColor4f, SkColors::kBlack)
ADAPTER_PROPERTY(EndColor , SkColor4f, SkColors::kBlack)
ADAPTER_PROPERTY(Blend , SkScalar , 0)
ADAPTER_PROPERTY(Scatter , SkScalar , 0)
// Really an enum: 1 -> linear, 7 -> radial (?!)
ADAPTER_PROPERTY(Shape , SkScalar, 0)
const sk_sp<sksg::ShaderEffect>& root() const { return fRoot; }
sk_sp<sksg::RenderNode> renderNode() const { return fShaderEffect; }
private:
GradientRampEffectAdapter(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer,
const AnimationBuilder* abuilder)
: fShaderEffect(sksg::ShaderEffect::Make(std::move(layer))) {
enum : size_t {
kStartPoint_Index = 0,
kStartColor_Index = 1,
kEndPoint_Index = 2,
kEndColor_Index = 3,
kRampShape_Index = 4,
kRampScatter_Index = 5,
kBlendRatio_Index = 6,
};
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kStartPoint_Index), &fStartPoint);
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kStartColor_Index), &fStartColor);
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kEndPoint_Index), &fEndPoint );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kEndColor_Index), &fEndColor );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kRampShape_Index), &fShape );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kRampScatter_Index), &fScatter );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kBlendRatio_Index), &fBlend );
}
enum class InstanceType {
kNone,
kLinear,
kRadial,
};
void apply() {
void onSync() override {
// This adapter manages a SG fragment with the following structure:
//
// - ShaderEffect [fRoot]
@ -57,11 +75,12 @@ private:
? sk_sp<sksg::Gradient>(sksg::LinearGradient::Make())
: sk_sp<sksg::Gradient>(sksg::RadialGradient::Make());
fRoot->setShader(fGradient);
fShaderEffect->setShader(fGradient);
fInstanceType = new_type;
}
fGradient->setColorStops({ {0, fStartColor}, {1, fEndColor} });
fGradient->setColorStops({{0, ValueTraits<VectorValue>::As<SkColor4f>(fStartColor)},
{1, ValueTraits<VectorValue>::As<SkColor4f>( fEndColor)}});
};
static constexpr int kLinearShapeValue = 1;
@ -73,73 +92,45 @@ private:
update_gradient(instance_type);
// Sync instance-dependent gradient params.
const auto start_point = ValueTraits<VectorValue>::As<SkPoint>(fStartPoint),
end_point = ValueTraits<VectorValue>::As<SkPoint>( fEndPoint);
if (instance_type == InstanceType::kLinear) {
auto* lg = static_cast<sksg::LinearGradient*>(fGradient.get());
lg->setStartPoint(fStartPoint);
lg->setEndPoint(fEndPoint);
lg->setStartPoint(start_point);
lg->setEndPoint(end_point);
} else {
SkASSERT(instance_type == InstanceType::kRadial);
auto* rg = static_cast<sksg::RadialGradient*>(fGradient.get());
rg->setStartCenter(fStartPoint);
rg->setEndCenter(fStartPoint);
rg->setEndRadius(SkPoint::Distance(fStartPoint, fEndPoint));
rg->setStartCenter(start_point);
rg->setEndCenter(start_point);
rg->setEndRadius(SkPoint::Distance(start_point, end_point));
}
// TODO: blend, scatter
}
sk_sp<sksg::ShaderEffect> fRoot;
sk_sp<sksg::Gradient> fGradient;
const sk_sp<sksg::ShaderEffect> fShaderEffect;
sk_sp<sksg::Gradient> fGradient;
InstanceType fInstanceType = InstanceType::kNone;
VectorValue fStartPoint,
fStartColor,
fEndPoint,
fEndColor;
ScalarValue fBlend = 0,
fScatter = 0,
fShape = 0; // 1 -> linear, 7 -> radial (?!)
};
} // anonymous ns
sk_sp<sksg::RenderNode> EffectBuilder::attachGradientEffect(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer) const {
enum : size_t {
kStartPoint_Index = 0,
kStartColor_Index = 1,
kEndPoint_Index = 2,
kEndColor_Index = 3,
kRampShape_Index = 4,
kRampScatter_Index = 5,
kBlendRatio_Index = 6,
};
auto adapter = sk_make_sp<GradientRampEffectAdapter>(std::move(layer));
fBuilder->bindProperty<VectorValue>(GetPropValue(jprops, kStartPoint_Index),
[adapter](const VectorValue& p0) {
adapter->setStartPoint(ValueTraits<VectorValue>::As<SkPoint>(p0));
});
fBuilder->bindProperty<VectorValue>(GetPropValue(jprops, kEndPoint_Index),
[adapter](const VectorValue& p1) {
adapter->setEndPoint(ValueTraits<VectorValue>::As<SkPoint>(p1));
});
fBuilder->bindProperty<VectorValue>(GetPropValue(jprops, kStartColor_Index),
[adapter](const VectorValue& c0) {
adapter->setStartColor(ValueTraits<VectorValue>::As<SkColor4f>(c0));
});
fBuilder->bindProperty<VectorValue>(GetPropValue(jprops, kEndColor_Index),
[adapter](const VectorValue& c1) {
adapter->setEndColor(ValueTraits<VectorValue>::As<SkColor4f>(c1));
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kRampShape_Index),
[adapter](const ScalarValue& shape) {
adapter->setShape(shape);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kBlendRatio_Index),
[adapter](const ScalarValue& blend) {
adapter->setBlend(blend);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kRampScatter_Index),
[adapter](const ScalarValue& scatter) {
adapter->setScatter(scatter);
});
return adapter->root();
return fBuilder->attachDiscardableAdapter<GradientRampEffectAdapter>(jprops,
std::move(layer),
fBuilder);
}
} // namespace internal

View File

@ -8,7 +8,7 @@
#include "modules/skottie/src/effects/Effects.h"
#include "include/effects/SkTableColorFilter.h"
#include "modules/skottie/src/SkottieAdapter.h"
#include "modules/skottie/src/Animator.h"
#include "modules/skottie/src/SkottieValue.h"
#include "modules/sksg/include/SkSGColorFilter.h"
#include "src/utils/SkJSON.h"
@ -33,28 +33,48 @@ namespace internal {
namespace {
class LevelsEffectAdapter final : public SkNVRefCnt<LevelsEffectAdapter> {
class LevelsEffectAdapter final : public AnimatablePropertyContainer {
public:
explicit LevelsEffectAdapter(sk_sp<sksg::RenderNode> child)
: fEffect(sksg::ExternalColorFilter::Make(std::move(child))) {
SkASSERT(fEffect);
static sk_sp<LevelsEffectAdapter> Make(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer,
const AnimationBuilder* abuilder) {
return sk_sp<LevelsEffectAdapter>(new LevelsEffectAdapter(jprops,
std::move(layer),
abuilder));
}
// 1: RGB, 2: R, 3: G, 4: B, 5: A
ADAPTER_PROPERTY( Channel, SkScalar, 1)
ADAPTER_PROPERTY( InBlack, SkScalar, 0)
ADAPTER_PROPERTY( InWhite, SkScalar, 1)
ADAPTER_PROPERTY( OutBlack, SkScalar, 0)
ADAPTER_PROPERTY( OutWhite, SkScalar, 1)
ADAPTER_PROPERTY( Gamma, SkScalar, 1)
// 1: clip, 2,3: don't clip
ADAPTER_PROPERTY(ClipBlack, SkScalar, 1)
ADAPTER_PROPERTY(ClipWhite, SkScalar, 1)
const sk_sp<sksg::ExternalColorFilter>& root() const { return fEffect; }
sk_sp<sksg::RenderNode> renderNode() const { return fEffect; }
private:
void apply() {
LevelsEffectAdapter(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer,
const AnimationBuilder* abuilder)
: fEffect(sksg::ExternalColorFilter::Make(std::move(layer))) {
enum : size_t {
kChannel_Index = 0,
// ??? = 1,
kInputBlack_Index = 2,
kInputWhite_Index = 3,
kGamma_Index = 4,
kOutputBlack_Index = 5,
kOutputWhite_Index = 6,
kClipToOutBlack_Index = 7,
kClipToOutWhite_Index = 8,
};
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kChannel_Index), &fChannel );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kInputBlack_Index), &fInBlack );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kInputWhite_Index), &fInWhite );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kGamma_Index), &fGamma );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kOutputBlack_Index), &fOutBlack);
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kOutputWhite_Index), &fOutWhite);
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kClipToOutBlack_Index),
&fClipBlack);
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kClipToOutWhite_Index),
&fClipWhite);
}
void onSync() override {
enum LottieChannel {
kRGB_Channel = 1,
kR_Channel = 2,
@ -129,62 +149,25 @@ private:
));
}
sk_sp<sksg::ExternalColorFilter> fEffect;
const sk_sp<sksg::ExternalColorFilter> fEffect;
ScalarValue fChannel = 1, // 1: RGB, 2: R, 3: G, 4: B, 5: A
fInBlack = 0,
fInWhite = 1,
fOutBlack = 0,
fOutWhite = 1,
fGamma = 1,
fClipBlack = 1, // 1: clip, 2,3: don't clip
fClipWhite = 1; // ^
};
} // anonymous ns
sk_sp<sksg::RenderNode> EffectBuilder::attachLevelsEffect(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer) const {
enum : size_t {
kChannel_Index = 0,
// ??? = 1,
kInputBlack_Index = 2,
kInputWhite_Index = 3,
kGamma_Index = 4,
kOutputBlack_Index = 5,
kOutputWhite_Index = 6,
kClipToOutBlack_Index = 7,
kClipToOutWhite_Index = 8,
};
auto adapter = sk_make_sp<LevelsEffectAdapter>(std::move(layer));
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kChannel_Index),
[adapter](const ScalarValue& channel) {
adapter->setChannel(channel);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kInputBlack_Index),
[adapter](const ScalarValue& ib) {
adapter->setInBlack(ib);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kInputWhite_Index),
[adapter](const ScalarValue& iw) {
adapter->setInWhite(iw);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kOutputBlack_Index),
[adapter](const ScalarValue& ob) {
adapter->setOutBlack(ob);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kOutputWhite_Index),
[adapter](const ScalarValue& ow) {
adapter->setOutWhite(ow);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kGamma_Index),
[adapter](const ScalarValue& g) {
adapter->setGamma(g);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kClipToOutBlack_Index),
[adapter](const ScalarValue& cb) {
adapter->setClipBlack(cb);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kClipToOutWhite_Index),
[adapter](const ScalarValue& cw) {
adapter->setClipWhite(cw);
});
return adapter->root();
return fBuilder->attachDiscardableAdapter<LevelsEffectAdapter>(jprops,
std::move(layer),
fBuilder);
}
} // namespace internal

View File

@ -9,7 +9,6 @@
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkShaderMaskFilter.h"
#include "modules/skottie/src/SkottieAdapter.h"
#include "modules/skottie/src/SkottieValue.h"
#include "modules/sksg/include/SkSGRenderEffect.h"
#include "src/utils/SkJSON.h"
@ -24,14 +23,33 @@ namespace {
class LinearWipeAdapter final : public MaskFilterEffectBase {
public:
LinearWipeAdapter(sk_sp<sksg::RenderNode> layer, const SkSize& ls)
: INHERITED(std::move(layer), ls) {}
ADAPTER_PROPERTY(Completion, float, 0)
ADAPTER_PROPERTY(Angle , float, 0)
ADAPTER_PROPERTY(Feather , float, 0)
static sk_sp<LinearWipeAdapter> Make(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer,
const SkSize& layer_size,
const AnimationBuilder* abuilder) {
return sk_sp<LinearWipeAdapter>(new LinearWipeAdapter(jprops,
std::move(layer),
layer_size,
abuilder));
}
private:
LinearWipeAdapter(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer,
const SkSize& layer_size,
const AnimationBuilder* abuilder)
: INHERITED(std::move(layer), layer_size) {
enum : size_t {
kCompletion_Index = 0,
kAngle_Index = 1,
kFeather_Index = 2,
};
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kCompletion_Index), &fCompletion);
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kAngle_Index), &fAngle );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kFeather_Index), &fFeather );
}
MaskInfo onMakeMask() const override {
if (fCompletion >= 100) {
// The layer is fully disabled.
@ -89,6 +107,10 @@ private:
true };
}
float fCompletion = 0,
fAngle = 0,
fFeather = 0;
using INHERITED = MaskFilterEffectBase;
};
@ -96,28 +118,10 @@ private:
sk_sp<sksg::RenderNode> EffectBuilder::attachLinearWipeEffect(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer) const {
enum : size_t {
kCompletion_Index = 0,
kAngle_Index = 1,
kFeather_Index = 2,
};
auto adapter = sk_make_sp<LinearWipeAdapter>(std::move(layer), fLayerSize);
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kCompletion_Index),
[adapter](const ScalarValue& c) {
adapter->setCompletion(c);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kAngle_Index),
[adapter](const ScalarValue& a) {
adapter->setAngle(a);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kFeather_Index),
[adapter](const ScalarValue& f) {
adapter->setFeather(f);
});
return adapter->root();
return fBuilder->attachDiscardableAdapter<LinearWipeAdapter>(jprops,
std::move(layer),
fLayerSize,
fBuilder);
}
} // namespace internal

View File

@ -9,7 +9,6 @@
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkShaderMaskFilter.h"
#include "modules/skottie/src/SkottieAdapter.h"
#include "modules/skottie/src/SkottieValue.h"
#include "modules/sksg/include/SkSGRenderEffect.h"
#include "src/utils/SkJSON.h"
@ -23,15 +22,32 @@ namespace {
class VenetianBlindsAdapter final : public MaskFilterEffectBase {
public:
VenetianBlindsAdapter(sk_sp<sksg::RenderNode> layer, const SkSize& ls)
: INHERITED(std::move(layer), ls) {}
ADAPTER_PROPERTY(Completion, float, 0)
ADAPTER_PROPERTY(Direction , float, 0)
ADAPTER_PROPERTY(Width , float, 0)
ADAPTER_PROPERTY(Feather , float, 0)
static sk_sp<VenetianBlindsAdapter> Make(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer,
const SkSize& layer_size,
const AnimationBuilder* abuilder) {
return sk_sp<VenetianBlindsAdapter>(
new VenetianBlindsAdapter(jprops, std::move(layer), layer_size, abuilder));
}
private:
VenetianBlindsAdapter(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer, const SkSize& ls,
const AnimationBuilder* abuilder)
: INHERITED(std::move(layer), ls) {
enum : size_t {
kCompletion_Index = 0,
kDirection_Index = 1,
kWidth_Index = 2,
kFeather_Index = 3,
};
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kCompletion_Index), &fCompletion);
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kDirection_Index ), &fDirection );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kWidth_Index ), &fWidth );
this->bind(*abuilder, EffectBuilder::GetPropValue(jprops, kFeather_Index ), &fFeather );
}
MaskInfo onMakeMask() const override {
if (fCompletion >= 100) {
// The layer is fully disabled.
@ -130,6 +146,11 @@ private:
};
}
float fCompletion = 0,
fDirection = 0,
fWidth = 0,
fFeather = 0;
using INHERITED = MaskFilterEffectBase;
};
@ -137,33 +158,10 @@ private:
sk_sp<sksg::RenderNode> EffectBuilder::attachVenetianBlindsEffect(
const skjson::ArrayValue& jprops, sk_sp<sksg::RenderNode> layer) const {
enum : size_t {
kCompletion_Index = 0,
kDirection_Index = 1,
kWidth_Index = 2,
kFeather_Index = 3,
};
auto adapter = sk_make_sp<VenetianBlindsAdapter>(std::move(layer), fLayerSize);
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kCompletion_Index),
[adapter](const ScalarValue& c) {
adapter->setCompletion(c);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kDirection_Index),
[adapter](const ScalarValue& d) {
adapter->setDirection(d);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kWidth_Index),
[adapter](const ScalarValue& w) {
adapter->setWidth(w);
});
fBuilder->bindProperty<ScalarValue>(GetPropValue(jprops, kFeather_Index),
[adapter](const ScalarValue& f) {
adapter->setFeather(f);
});
return adapter->root();
return fBuilder->attachDiscardableAdapter<VenetianBlindsAdapter>(jprops,
std::move(layer),
fLayerSize,
fBuilder);
}
} // namespace internal