[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:
parent
f631cf3d16
commit
e905233c8d
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "modules/skottie/src/effects/Effects.h"
|
#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/skottie/src/SkottieValue.h"
|
||||||
#include "modules/sksg/include/SkSGRenderEffect.h"
|
#include "modules/sksg/include/SkSGRenderEffect.h"
|
||||||
#include "src/utils/SkJSON.h"
|
#include "src/utils/SkJSON.h"
|
||||||
@ -17,24 +17,43 @@ namespace internal {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class DropShadowAdapter final : public SkNVRefCnt<DropShadowAdapter> {
|
class DropShadowAdapter final : public AnimatablePropertyContainer {
|
||||||
public:
|
public:
|
||||||
explicit DropShadowAdapter(sk_sp<sksg::DropShadowImageFilter> dropShadow)
|
static sk_sp<DropShadowAdapter> Make(const skjson::ArrayValue& jprops,
|
||||||
: fDropShadow(std::move(dropShadow)) {
|
sk_sp<sksg::RenderNode> layer,
|
||||||
SkASSERT(fDropShadow);
|
const AnimationBuilder* abuilder) {
|
||||||
|
return sk_sp<DropShadowAdapter>(new DropShadowAdapter(jprops, std::move(layer), abuilder));
|
||||||
}
|
}
|
||||||
|
|
||||||
ADAPTER_PROPERTY(Color , SkColor , SK_ColorBLACK)
|
const sk_sp<sksg::RenderNode>& renderNode() const { return fImageFilterEffect; }
|
||||||
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)
|
|
||||||
|
|
||||||
private:
|
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
|
// 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.
|
// The offset is specified in terms of a bearing angle + distance.
|
||||||
SkScalar rad = SkDegreesToRadians(90 - fDirection);
|
SkScalar rad = SkDegreesToRadians(90 - fDirection);
|
||||||
@ -46,55 +65,29 @@ private:
|
|||||||
const auto sigma = fSoftness * kSoftnessToSigmaFactor;
|
const auto sigma = fSoftness * kSoftnessToSigmaFactor;
|
||||||
fDropShadow->setSigma(SkVector::Make(sigma, sigma));
|
fDropShadow->setSigma(SkVector::Make(sigma, sigma));
|
||||||
|
|
||||||
fDropShadow->setMode(fShadowOnly ? sksg::DropShadowImageFilter::Mode::kShadowOnly
|
fDropShadow->setMode(SkToBool(fShdwOnly)
|
||||||
: sksg::DropShadowImageFilter::Mode::kShadowAndForeground);
|
? sksg::DropShadowImageFilter::Mode::kShadowOnly
|
||||||
|
: sksg::DropShadowImageFilter::Mode::kShadowAndForeground);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sk_sp<sksg::DropShadowImageFilter> fDropShadow;
|
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
|
} // anonymous ns
|
||||||
|
|
||||||
sk_sp<sksg::RenderNode> EffectBuilder::attachDropShadowEffect(const skjson::ArrayValue& jprops,
|
sk_sp<sksg::RenderNode> EffectBuilder::attachDropShadowEffect(const skjson::ArrayValue& jprops,
|
||||||
sk_sp<sksg::RenderNode> layer) const {
|
sk_sp<sksg::RenderNode> layer) const {
|
||||||
enum : size_t {
|
return fBuilder->attachDiscardableAdapter<DropShadowAdapter>(jprops,
|
||||||
kShadowColor_Index = 0,
|
std::move(layer),
|
||||||
kOpacity_Index = 1,
|
fBuilder);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -132,9 +132,7 @@ MaskFilterEffectBase::MaskFilterEffectBase(sk_sp<sksg::RenderNode> child, const
|
|||||||
, fMaskEffectNode(sksg::MaskFilterEffect::Make(std::move(child), fMaskNode))
|
, fMaskEffectNode(sksg::MaskFilterEffect::Make(std::move(child), fMaskNode))
|
||||||
, fLayerSize(ls) {}
|
, fLayerSize(ls) {}
|
||||||
|
|
||||||
MaskFilterEffectBase::~MaskFilterEffectBase() = default;
|
void MaskFilterEffectBase::onSync() {
|
||||||
|
|
||||||
void MaskFilterEffectBase::apply() const {
|
|
||||||
const auto minfo = this->onMakeMask();
|
const auto minfo = this->onMakeMask();
|
||||||
|
|
||||||
fMaskEffectNode->setVisible(minfo.fVisible);
|
fMaskEffectNode->setVisible(minfo.fVisible);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#ifndef SkottieEffects_DEFINED
|
#ifndef SkottieEffects_DEFINED
|
||||||
#define SkottieEffects_DEFINED
|
#define SkottieEffects_DEFINED
|
||||||
|
|
||||||
|
#include "modules/skottie/src/Animator.h"
|
||||||
#include "modules/skottie/src/SkottiePriv.h"
|
#include "modules/skottie/src/SkottiePriv.h"
|
||||||
|
|
||||||
class SkMaskFilter;
|
class SkMaskFilter;
|
||||||
@ -74,19 +75,15 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Base class for mask-filter-related effects.
|
* Base class for mask-filter-related effects.
|
||||||
*/
|
*/
|
||||||
class MaskFilterEffectBase : public SkRefCnt {
|
class MaskFilterEffectBase : public AnimatablePropertyContainer {
|
||||||
public:
|
public:
|
||||||
~MaskFilterEffectBase() override;
|
const sk_sp<sksg::MaskFilterEffect>& renderNode() const { return fMaskEffectNode; }
|
||||||
|
|
||||||
const sk_sp<sksg::MaskFilterEffect>& root() const { return fMaskEffectNode; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MaskFilterEffectBase(sk_sp<sksg::RenderNode>, const SkSize&);
|
MaskFilterEffectBase(sk_sp<sksg::RenderNode>, const SkSize&);
|
||||||
|
|
||||||
const SkSize& layerSize() const { return fLayerSize; }
|
const SkSize& layerSize() const { return fLayerSize; }
|
||||||
|
|
||||||
void apply() const;
|
|
||||||
|
|
||||||
struct MaskInfo {
|
struct MaskInfo {
|
||||||
sk_sp<SkMaskFilter> fMask;
|
sk_sp<SkMaskFilter> fMask;
|
||||||
bool fVisible;
|
bool fVisible;
|
||||||
@ -94,6 +91,8 @@ protected:
|
|||||||
virtual MaskInfo onMakeMask() const = 0;
|
virtual MaskInfo onMakeMask() const = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void onSync() final;
|
||||||
|
|
||||||
const sk_sp<sksg::MaskFilter> fMaskNode;
|
const sk_sp<sksg::MaskFilter> fMaskNode;
|
||||||
const sk_sp<sksg::MaskFilterEffect> fMaskEffectNode;
|
const sk_sp<sksg::MaskFilterEffect> fMaskEffectNode;
|
||||||
const SkSize fLayerSize;
|
const SkSize fLayerSize;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "modules/skottie/src/effects/Effects.h"
|
#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/skottie/src/SkottieValue.h"
|
||||||
#include "modules/sksg/include/SkSGRenderEffect.h"
|
#include "modules/sksg/include/SkSGRenderEffect.h"
|
||||||
#include "src/utils/SkJSON.h"
|
#include "src/utils/SkJSON.h"
|
||||||
@ -17,35 +17,36 @@ namespace internal {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class GaussianBlurEffectAdapter final : public SkNVRefCnt<GaussianBlurEffectAdapter> {
|
class GaussianBlurEffectAdapter final : public AnimatablePropertyContainer {
|
||||||
public:
|
public:
|
||||||
explicit GaussianBlurEffectAdapter(sk_sp<sksg::BlurImageFilter> blur)
|
static sk_sp<GaussianBlurEffectAdapter> Make(const skjson::ArrayValue& jprops,
|
||||||
: fBlur(std::move(blur)) {
|
sk_sp<sksg::RenderNode> layer,
|
||||||
SkASSERT(fBlur);
|
const AnimationBuilder* abuilder) {
|
||||||
|
return sk_sp<GaussianBlurEffectAdapter>(new GaussianBlurEffectAdapter(jprops,
|
||||||
|
std::move(layer),
|
||||||
|
abuilder));
|
||||||
}
|
}
|
||||||
|
|
||||||
// AE/BM model properties. These are all animatable/interpolatable.
|
const sk_sp<sksg::RenderNode>& renderNode() const { return fImageFilterEffect; }
|
||||||
|
|
||||||
// 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)
|
|
||||||
|
|
||||||
private:
|
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[] = {
|
static constexpr SkVector kDimensionsMap[] = {
|
||||||
{ 1, 1 }, // 1 -> horizontal and vertical
|
{ 1, 1 }, // 1 -> horizontal and vertical
|
||||||
{ 1, 0 }, // 2 -> horizontal
|
{ 1, 0 }, // 2 -> horizontal
|
||||||
@ -73,6 +74,11 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sk_sp<sksg::BlurImageFilter> fBlur;
|
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
|
} // anonymous ns
|
||||||
@ -80,29 +86,9 @@ private:
|
|||||||
sk_sp<sksg::RenderNode> EffectBuilder::attachGaussianBlurEffect(
|
sk_sp<sksg::RenderNode> EffectBuilder::attachGaussianBlurEffect(
|
||||||
const skjson::ArrayValue& jprops,
|
const skjson::ArrayValue& jprops,
|
||||||
sk_sp<sksg::RenderNode> layer) const {
|
sk_sp<sksg::RenderNode> layer) const {
|
||||||
enum : size_t {
|
return fBuilder->attachDiscardableAdapter<GaussianBlurEffectAdapter>(jprops,
|
||||||
kBlurriness_Index = 0,
|
std::move(layer),
|
||||||
kDimensions_Index = 1,
|
fBuilder);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "modules/skottie/src/effects/Effects.h"
|
#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/skottie/src/SkottieValue.h"
|
||||||
#include "modules/sksg/include/SkSGGradient.h"
|
#include "modules/sksg/include/SkSGGradient.h"
|
||||||
#include "modules/sksg/include/SkSGRenderEffect.h"
|
#include "modules/sksg/include/SkSGRenderEffect.h"
|
||||||
@ -18,31 +18,49 @@ namespace internal {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class GradientRampEffectAdapter final : public SkNVRefCnt<GradientRampEffectAdapter> {
|
class GradientRampEffectAdapter final : public AnimatablePropertyContainer {
|
||||||
public:
|
public:
|
||||||
explicit GradientRampEffectAdapter(sk_sp<sksg::RenderNode> child)
|
static sk_sp<GradientRampEffectAdapter> Make(const skjson::ArrayValue& jprops,
|
||||||
: fRoot(sksg::ShaderEffect::Make(std::move(child))) {}
|
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))
|
sk_sp<sksg::RenderNode> renderNode() const { return fShaderEffect; }
|
||||||
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; }
|
|
||||||
|
|
||||||
private:
|
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 {
|
enum class InstanceType {
|
||||||
kNone,
|
kNone,
|
||||||
kLinear,
|
kLinear,
|
||||||
kRadial,
|
kRadial,
|
||||||
};
|
};
|
||||||
|
|
||||||
void apply() {
|
void onSync() override {
|
||||||
// This adapter manages a SG fragment with the following structure:
|
// This adapter manages a SG fragment with the following structure:
|
||||||
//
|
//
|
||||||
// - ShaderEffect [fRoot]
|
// - ShaderEffect [fRoot]
|
||||||
@ -57,11 +75,12 @@ private:
|
|||||||
? sk_sp<sksg::Gradient>(sksg::LinearGradient::Make())
|
? sk_sp<sksg::Gradient>(sksg::LinearGradient::Make())
|
||||||
: sk_sp<sksg::Gradient>(sksg::RadialGradient::Make());
|
: sk_sp<sksg::Gradient>(sksg::RadialGradient::Make());
|
||||||
|
|
||||||
fRoot->setShader(fGradient);
|
fShaderEffect->setShader(fGradient);
|
||||||
fInstanceType = new_type;
|
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;
|
static constexpr int kLinearShapeValue = 1;
|
||||||
@ -73,73 +92,45 @@ private:
|
|||||||
update_gradient(instance_type);
|
update_gradient(instance_type);
|
||||||
|
|
||||||
// Sync instance-dependent gradient params.
|
// 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) {
|
if (instance_type == InstanceType::kLinear) {
|
||||||
auto* lg = static_cast<sksg::LinearGradient*>(fGradient.get());
|
auto* lg = static_cast<sksg::LinearGradient*>(fGradient.get());
|
||||||
lg->setStartPoint(fStartPoint);
|
lg->setStartPoint(start_point);
|
||||||
lg->setEndPoint(fEndPoint);
|
lg->setEndPoint(end_point);
|
||||||
} else {
|
} else {
|
||||||
SkASSERT(instance_type == InstanceType::kRadial);
|
SkASSERT(instance_type == InstanceType::kRadial);
|
||||||
|
|
||||||
auto* rg = static_cast<sksg::RadialGradient*>(fGradient.get());
|
auto* rg = static_cast<sksg::RadialGradient*>(fGradient.get());
|
||||||
rg->setStartCenter(fStartPoint);
|
rg->setStartCenter(start_point);
|
||||||
rg->setEndCenter(fStartPoint);
|
rg->setEndCenter(start_point);
|
||||||
rg->setEndRadius(SkPoint::Distance(fStartPoint, fEndPoint));
|
rg->setEndRadius(SkPoint::Distance(start_point, end_point));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: blend, scatter
|
// TODO: blend, scatter
|
||||||
}
|
}
|
||||||
|
|
||||||
sk_sp<sksg::ShaderEffect> fRoot;
|
const sk_sp<sksg::ShaderEffect> fShaderEffect;
|
||||||
sk_sp<sksg::Gradient> fGradient;
|
sk_sp<sksg::Gradient> fGradient;
|
||||||
|
|
||||||
InstanceType fInstanceType = InstanceType::kNone;
|
InstanceType fInstanceType = InstanceType::kNone;
|
||||||
|
|
||||||
|
VectorValue fStartPoint,
|
||||||
|
fStartColor,
|
||||||
|
fEndPoint,
|
||||||
|
fEndColor;
|
||||||
|
ScalarValue fBlend = 0,
|
||||||
|
fScatter = 0,
|
||||||
|
fShape = 0; // 1 -> linear, 7 -> radial (?!)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // anonymous ns
|
} // anonymous ns
|
||||||
|
|
||||||
sk_sp<sksg::RenderNode> EffectBuilder::attachGradientEffect(const skjson::ArrayValue& jprops,
|
sk_sp<sksg::RenderNode> EffectBuilder::attachGradientEffect(const skjson::ArrayValue& jprops,
|
||||||
sk_sp<sksg::RenderNode> layer) const {
|
sk_sp<sksg::RenderNode> layer) const {
|
||||||
enum : size_t {
|
return fBuilder->attachDiscardableAdapter<GradientRampEffectAdapter>(jprops,
|
||||||
kStartPoint_Index = 0,
|
std::move(layer),
|
||||||
kStartColor_Index = 1,
|
fBuilder);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "modules/skottie/src/effects/Effects.h"
|
#include "modules/skottie/src/effects/Effects.h"
|
||||||
|
|
||||||
#include "include/effects/SkTableColorFilter.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/skottie/src/SkottieValue.h"
|
||||||
#include "modules/sksg/include/SkSGColorFilter.h"
|
#include "modules/sksg/include/SkSGColorFilter.h"
|
||||||
#include "src/utils/SkJSON.h"
|
#include "src/utils/SkJSON.h"
|
||||||
@ -33,28 +33,48 @@ namespace internal {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class LevelsEffectAdapter final : public SkNVRefCnt<LevelsEffectAdapter> {
|
class LevelsEffectAdapter final : public AnimatablePropertyContainer {
|
||||||
public:
|
public:
|
||||||
explicit LevelsEffectAdapter(sk_sp<sksg::RenderNode> child)
|
static sk_sp<LevelsEffectAdapter> Make(const skjson::ArrayValue& jprops,
|
||||||
: fEffect(sksg::ExternalColorFilter::Make(std::move(child))) {
|
sk_sp<sksg::RenderNode> layer,
|
||||||
SkASSERT(fEffect);
|
const AnimationBuilder* abuilder) {
|
||||||
|
return sk_sp<LevelsEffectAdapter>(new LevelsEffectAdapter(jprops,
|
||||||
|
std::move(layer),
|
||||||
|
abuilder));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1: RGB, 2: R, 3: G, 4: B, 5: A
|
sk_sp<sksg::RenderNode> renderNode() const { return fEffect; }
|
||||||
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; }
|
|
||||||
|
|
||||||
private:
|
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 {
|
enum LottieChannel {
|
||||||
kRGB_Channel = 1,
|
kRGB_Channel = 1,
|
||||||
kR_Channel = 2,
|
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
|
} // anonymous ns
|
||||||
|
|
||||||
sk_sp<sksg::RenderNode> EffectBuilder::attachLevelsEffect(const skjson::ArrayValue& jprops,
|
sk_sp<sksg::RenderNode> EffectBuilder::attachLevelsEffect(const skjson::ArrayValue& jprops,
|
||||||
sk_sp<sksg::RenderNode> layer) const {
|
sk_sp<sksg::RenderNode> layer) const {
|
||||||
enum : size_t {
|
return fBuilder->attachDiscardableAdapter<LevelsEffectAdapter>(jprops,
|
||||||
kChannel_Index = 0,
|
std::move(layer),
|
||||||
// ??? = 1,
|
fBuilder);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
#include "include/effects/SkGradientShader.h"
|
#include "include/effects/SkGradientShader.h"
|
||||||
#include "include/effects/SkShaderMaskFilter.h"
|
#include "include/effects/SkShaderMaskFilter.h"
|
||||||
#include "modules/skottie/src/SkottieAdapter.h"
|
|
||||||
#include "modules/skottie/src/SkottieValue.h"
|
#include "modules/skottie/src/SkottieValue.h"
|
||||||
#include "modules/sksg/include/SkSGRenderEffect.h"
|
#include "modules/sksg/include/SkSGRenderEffect.h"
|
||||||
#include "src/utils/SkJSON.h"
|
#include "src/utils/SkJSON.h"
|
||||||
@ -24,14 +23,33 @@ namespace {
|
|||||||
|
|
||||||
class LinearWipeAdapter final : public MaskFilterEffectBase {
|
class LinearWipeAdapter final : public MaskFilterEffectBase {
|
||||||
public:
|
public:
|
||||||
LinearWipeAdapter(sk_sp<sksg::RenderNode> layer, const SkSize& ls)
|
static sk_sp<LinearWipeAdapter> Make(const skjson::ArrayValue& jprops,
|
||||||
: INHERITED(std::move(layer), ls) {}
|
sk_sp<sksg::RenderNode> layer,
|
||||||
|
const SkSize& layer_size,
|
||||||
ADAPTER_PROPERTY(Completion, float, 0)
|
const AnimationBuilder* abuilder) {
|
||||||
ADAPTER_PROPERTY(Angle , float, 0)
|
return sk_sp<LinearWipeAdapter>(new LinearWipeAdapter(jprops,
|
||||||
ADAPTER_PROPERTY(Feather , float, 0)
|
std::move(layer),
|
||||||
|
layer_size,
|
||||||
|
abuilder));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
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 {
|
MaskInfo onMakeMask() const override {
|
||||||
if (fCompletion >= 100) {
|
if (fCompletion >= 100) {
|
||||||
// The layer is fully disabled.
|
// The layer is fully disabled.
|
||||||
@ -89,6 +107,10 @@ private:
|
|||||||
true };
|
true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float fCompletion = 0,
|
||||||
|
fAngle = 0,
|
||||||
|
fFeather = 0;
|
||||||
|
|
||||||
using INHERITED = MaskFilterEffectBase;
|
using INHERITED = MaskFilterEffectBase;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -96,28 +118,10 @@ private:
|
|||||||
|
|
||||||
sk_sp<sksg::RenderNode> EffectBuilder::attachLinearWipeEffect(const skjson::ArrayValue& jprops,
|
sk_sp<sksg::RenderNode> EffectBuilder::attachLinearWipeEffect(const skjson::ArrayValue& jprops,
|
||||||
sk_sp<sksg::RenderNode> layer) const {
|
sk_sp<sksg::RenderNode> layer) const {
|
||||||
enum : size_t {
|
return fBuilder->attachDiscardableAdapter<LinearWipeAdapter>(jprops,
|
||||||
kCompletion_Index = 0,
|
std::move(layer),
|
||||||
kAngle_Index = 1,
|
fLayerSize,
|
||||||
kFeather_Index = 2,
|
fBuilder);
|
||||||
};
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
#include "include/effects/SkGradientShader.h"
|
#include "include/effects/SkGradientShader.h"
|
||||||
#include "include/effects/SkShaderMaskFilter.h"
|
#include "include/effects/SkShaderMaskFilter.h"
|
||||||
#include "modules/skottie/src/SkottieAdapter.h"
|
|
||||||
#include "modules/skottie/src/SkottieValue.h"
|
#include "modules/skottie/src/SkottieValue.h"
|
||||||
#include "modules/sksg/include/SkSGRenderEffect.h"
|
#include "modules/sksg/include/SkSGRenderEffect.h"
|
||||||
#include "src/utils/SkJSON.h"
|
#include "src/utils/SkJSON.h"
|
||||||
@ -23,15 +22,32 @@ namespace {
|
|||||||
|
|
||||||
class VenetianBlindsAdapter final : public MaskFilterEffectBase {
|
class VenetianBlindsAdapter final : public MaskFilterEffectBase {
|
||||||
public:
|
public:
|
||||||
VenetianBlindsAdapter(sk_sp<sksg::RenderNode> layer, const SkSize& ls)
|
static sk_sp<VenetianBlindsAdapter> Make(const skjson::ArrayValue& jprops,
|
||||||
: INHERITED(std::move(layer), ls) {}
|
sk_sp<sksg::RenderNode> layer,
|
||||||
|
const SkSize& layer_size,
|
||||||
ADAPTER_PROPERTY(Completion, float, 0)
|
const AnimationBuilder* abuilder) {
|
||||||
ADAPTER_PROPERTY(Direction , float, 0)
|
return sk_sp<VenetianBlindsAdapter>(
|
||||||
ADAPTER_PROPERTY(Width , float, 0)
|
new VenetianBlindsAdapter(jprops, std::move(layer), layer_size, abuilder));
|
||||||
ADAPTER_PROPERTY(Feather , float, 0)
|
}
|
||||||
|
|
||||||
private:
|
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 {
|
MaskInfo onMakeMask() const override {
|
||||||
if (fCompletion >= 100) {
|
if (fCompletion >= 100) {
|
||||||
// The layer is fully disabled.
|
// The layer is fully disabled.
|
||||||
@ -130,6 +146,11 @@ private:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float fCompletion = 0,
|
||||||
|
fDirection = 0,
|
||||||
|
fWidth = 0,
|
||||||
|
fFeather = 0;
|
||||||
|
|
||||||
using INHERITED = MaskFilterEffectBase;
|
using INHERITED = MaskFilterEffectBase;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -137,33 +158,10 @@ private:
|
|||||||
|
|
||||||
sk_sp<sksg::RenderNode> EffectBuilder::attachVenetianBlindsEffect(
|
sk_sp<sksg::RenderNode> EffectBuilder::attachVenetianBlindsEffect(
|
||||||
const skjson::ArrayValue& jprops, sk_sp<sksg::RenderNode> layer) const {
|
const skjson::ArrayValue& jprops, sk_sp<sksg::RenderNode> layer) const {
|
||||||
enum : size_t {
|
return fBuilder->attachDiscardableAdapter<VenetianBlindsAdapter>(jprops,
|
||||||
kCompletion_Index = 0,
|
std::move(layer),
|
||||||
kDirection_Index = 1,
|
fLayerSize,
|
||||||
kWidth_Index = 2,
|
fBuilder);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
Loading…
Reference in New Issue
Block a user