From aaa70658c277928f1f98f715e4d397c3a0a2368e Mon Sep 17 00:00:00 2001 From: Jorge Betancourt Date: Wed, 20 Oct 2021 14:55:24 -0400 Subject: [PATCH] expose directional blur to skottie Change-Id: I759e4fff7a6d9cd1aae6ece060d570d05c1af94a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/461236 Commit-Queue: Jorge Betancourt Reviewed-by: Florin Malita --- modules/skottie/skottie.gni | 1 + .../skottie/src/effects/DirectionalBlur.cpp | 64 +++++++++++++++++++ modules/skottie/src/effects/Effects.cpp | 2 + modules/skottie/src/effects/Effects.h | 2 + .../skottie/skottie-directional-blur.json | 1 + 5 files changed, 70 insertions(+) create mode 100644 modules/skottie/src/effects/DirectionalBlur.cpp create mode 100644 resources/skottie/skottie-directional-blur.json diff --git a/modules/skottie/skottie.gni b/modules/skottie/skottie.gni index e5499457f2..2fa3599772 100644 --- a/modules/skottie/skottie.gni +++ b/modules/skottie/skottie.gni @@ -44,6 +44,7 @@ skia_skottie_sources = [ "$_src/effects/BrightnessContrastEffect.cpp", "$_src/effects/CCToner.cpp", "$_src/effects/CornerPinEffect.cpp", + "$_src/effects/DirectionalBlur.cpp", "$_src/effects/DisplacementMapEffect.cpp", "$_src/effects/DropShadowEffect.cpp", "$_src/effects/Effects.cpp", diff --git a/modules/skottie/src/effects/DirectionalBlur.cpp b/modules/skottie/src/effects/DirectionalBlur.cpp new file mode 100644 index 0000000000..6cfc5b9261 --- /dev/null +++ b/modules/skottie/src/effects/DirectionalBlur.cpp @@ -0,0 +1,64 @@ +/* + * Copyright 2021 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "modules/skottie/src/effects/Effects.h" + +#include "modules/skottie/src/Adapter.h" +#include "modules/skottie/src/SkottieValue.h" +#include "modules/sksg/include/SkSGPaint.h" +#include "modules/sksg/include/SkSGRenderEffect.h" +#include "src/utils/SkJSON.h" + +namespace skottie::internal { + +namespace { + +class DirectionalBlurAdapter final : public DiscardableAdapterBase { + public: + DirectionalBlurAdapter(const skjson::ArrayValue& jprops, + const AnimationBuilder& abuilder) + : INHERITED(sksg::ExternalImageFilter::Make()) + { + enum : size_t { + kDirection_Index = 0, + kBlurLength_Index = 1, + }; + + + EffectBinder(jprops, abuilder, this) + .bind( kDirection_Index, fDirection) + .bind( kBlurLength_Index, fBlurLength); + } + private: + void onSync() override { + const auto rot = fDirection - 90; + auto filter = + SkImageFilters::MatrixTransform(SkMatrix::RotateDeg(rot), + SkSamplingOptions(SkFilterMode::kLinear), + SkImageFilters::Blur(fBlurLength * kBlurSizeToSigma, 0, + SkImageFilters::MatrixTransform(SkMatrix::RotateDeg(-rot), + SkSamplingOptions(SkFilterMode::kLinear), nullptr))); + this->node()->setImageFilter(std::move(filter)); + } + + ScalarValue fDirection = 0; + ScalarValue fBlurLength = 0; + + using INHERITED = DiscardableAdapterBase; +}; + +} // namespace + +sk_sp EffectBuilder::attachDirectionalBlurEffect(const skjson::ArrayValue& jprops, + sk_sp layer) const { + auto imageFilterNode = fBuilder->attachDiscardableAdapter(jprops, + *fBuilder); + return sksg::ImageFilterEffect::Make(std::move(layer), std::move(imageFilterNode)); +} + +} // namespace skottie::internal diff --git a/modules/skottie/src/effects/Effects.cpp b/modules/skottie/src/effects/Effects.cpp index 2fece5fc7d..bde3d0d4ff 100644 --- a/modules/skottie/src/effects/Effects.cpp +++ b/modules/skottie/src/effects/Effects.cpp @@ -31,6 +31,7 @@ EffectBuilder::EffectBuilderT EffectBuilder::findBuilder(const skjson::ObjectVal const char* fName; EffectBuilderT fBuilder; } gBuilderInfo[] = { + // alphabetized for binary search lookup { "ADBE Black&White" , &EffectBuilder::attachBlackAndWhiteEffect }, { "ADBE Brightness & Contrast 2", &EffectBuilder::attachBrightnessContrastEffect }, { "ADBE Corner Pin" , &EffectBuilder::attachCornerPinEffect }, @@ -44,6 +45,7 @@ EffectBuilder::EffectBuilderT EffectBuilder::findBuilder(const skjson::ObjectVal { "ADBE HUE SATURATION" , &EffectBuilder::attachHueSaturationEffect }, { "ADBE Invert" , &EffectBuilder::attachInvertEffect }, { "ADBE Linear Wipe" , &EffectBuilder::attachLinearWipeEffect }, + { "ADBE Motion Blur" , &EffectBuilder::attachDirectionalBlurEffect }, { "ADBE Pro Levels2" , &EffectBuilder::attachProLevelsEffect }, { "ADBE Radial Wipe" , &EffectBuilder::attachRadialWipeEffect }, { "ADBE Ramp" , &EffectBuilder::attachGradientEffect }, diff --git a/modules/skottie/src/effects/Effects.h b/modules/skottie/src/effects/Effects.h index a6268a831d..7159b45ced 100644 --- a/modules/skottie/src/effects/Effects.h +++ b/modules/skottie/src/effects/Effects.h @@ -49,6 +49,8 @@ private: sk_sp) const; sk_sp attachCCTonerEffect (const skjson::ArrayValue&, sk_sp) const; + sk_sp attachDirectionalBlurEffect (const skjson::ArrayValue&, + sk_sp) const; sk_sp attachDisplacementMapEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachDropShadowEffect (const skjson::ArrayValue&, diff --git a/resources/skottie/skottie-directional-blur.json b/resources/skottie/skottie-directional-blur.json new file mode 100644 index 0000000000..f4a515c029 --- /dev/null +++ b/resources/skottie/skottie-directional-blur.json @@ -0,0 +1 @@ +{"assets":[],"ddd":0,"fr":60,"h":500,"ip":0,"layers":[{"ao":0,"bm":0,"ddd":0,"ef":[{"ef":[{"ix":1,"mn":"ADBE Motion Blur-0001","nm":"Direction","ty":0,"v":{"a":1,"ix":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"s":[0],"t":0},{"s":[360],"t":299}]}},{"ix":2,"mn":"ADBE Motion Blur-0002","nm":"Blur Length","ty":0,"v":{"a":1,"ix":2,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"s":[9.963],"t":0},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"s":[30],"t":38},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"s":[9.963],"t":75},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"s":[30],"t":114},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"s":[9.963],"t":150},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"s":[30],"t":189},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"s":[9.963],"t":225},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"s":[30],"t":264},{"s":[9.963],"t":299}]}}],"en":1,"ix":1,"mn":"ADBE Motion Blur","nm":"Directional Blur","np":4,"ty":5}],"ind":1,"ip":0,"ks":{"a":{"a":0,"ix":1,"k":[0,0,0],"l":2},"o":{"a":0,"ix":11,"k":100},"p":{"a":0,"ix":2,"k":[250,250,0],"l":2},"r":{"a":0,"ix":10,"k":0},"s":{"a":0,"ix":6,"k":[100,100,100],"l":2}},"nm":"Shape Layer 1","op":300,"shapes":[{"bm":0,"cix":2,"hd":false,"it":[{"d":1,"hd":false,"mn":"ADBE Vector Shape - Ellipse","nm":"Ellipse Path 1","p":{"a":0,"ix":3,"k":[0,0]},"s":{"a":0,"ix":2,"k":[350,350]},"ty":"el"},{"d":1,"hd":false,"mn":"ADBE Vector Shape - Rect","nm":"Rectangle Path 2","p":{"a":0,"ix":3,"k":[0,0]},"r":{"a":0,"ix":4,"k":0},"s":{"a":0,"ix":2,"k":[0,344]},"ty":"rc"},{"d":1,"hd":false,"mn":"ADBE Vector Shape - Rect","nm":"Rectangle Path 1","p":{"a":0,"ix":3,"k":[0,0]},"r":{"a":0,"ix":4,"k":0},"s":{"a":0,"ix":2,"k":[344,0]},"ty":"rc"},{"bm":0,"c":{"a":0,"ix":3,"k":[0,0.309803932905,0,1]},"hd":false,"lc":1,"lj":1,"ml":4,"mn":"ADBE Vector Graphic - Stroke","nm":"Stroke 1","o":{"a":0,"ix":4,"k":100},"ty":"st","w":{"a":0,"ix":5,"k":50}},{"a":{"a":0,"ix":1,"k":[0,0]},"nm":"Transform","o":{"a":0,"ix":7,"k":100},"p":{"a":0,"ix":2,"k":[0,0]},"r":{"a":0,"ix":6,"k":0},"s":{"a":0,"ix":3,"k":[100,100]},"sa":{"a":0,"ix":5,"k":0},"sk":{"a":0,"ix":4,"k":0},"ty":"tr"}],"ix":1,"mn":"ADBE Vector Group","nm":"Group 1","np":4,"ty":"gr"}],"sr":1,"st":0,"ty":4},{"ao":0,"bm":0,"ddd":0,"ind":2,"ip":0,"ks":{"a":{"a":0,"ix":1,"k":[250,250,0],"l":2},"o":{"a":0,"ix":11,"k":100},"p":{"a":0,"ix":2,"k":[250,250,0],"l":2},"r":{"a":0,"ix":10,"k":0},"s":{"a":0,"ix":6,"k":[100,100,100],"l":2}},"nm":"White Solid 3","op":300,"sc":"#ffffff","sh":500,"sr":1,"st":0,"sw":500,"ty":1}],"markers":[],"nm":"Directional Blur","op":300,"v":"5.7.14","w":500} \ No newline at end of file