aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/skottie
diff options
context:
space:
mode:
Diffstat (limited to 'experimental/skottie')
-rw-r--r--experimental/skottie/Skottie.cpp18
-rw-r--r--experimental/skottie/SkottieProperties.cpp34
-rw-r--r--experimental/skottie/SkottieProperties.h17
3 files changed, 61 insertions, 8 deletions
diff --git a/experimental/skottie/Skottie.cpp b/experimental/skottie/Skottie.cpp
index a7b6b23817..5a04e5a719 100644
--- a/experimental/skottie/Skottie.cpp
+++ b/experimental/skottie/Skottie.cpp
@@ -427,19 +427,21 @@ std::vector<sk_sp<sksg::GeometryNode>> AttachTrimGeometryEffect(
std::vector<sk_sp<sksg::GeometryNode>> trimmed;
trimmed.reserve(inputs.size());
for (const auto& i : inputs) {
- const auto trim = sksg::TrimEffect::Make(i);
- trimmed.push_back(trim);
+ const auto trimEffect = sksg::TrimEffect::Make(i);
+ trimmed.push_back(trimEffect);
+
+ const auto trimComposite = sk_make_sp<CompositeTrimEffect>(std::move(trimEffect));
BindProperty<ScalarValue>(jtrim["s"], &ctx->fAnimators,
- [trim](const ScalarValue& s) {
- trim->setStart(s * 0.01f);
+ [trimComposite](const ScalarValue& s) {
+ trimComposite->setStart(s);
});
BindProperty<ScalarValue>(jtrim["e"], &ctx->fAnimators,
- [trim](const ScalarValue& e) {
- trim->setEnd(e * 0.01f);
+ [trimComposite](const ScalarValue& e) {
+ trimComposite->setEnd(e);
});
BindProperty<ScalarValue>(jtrim["o"], &ctx->fAnimators,
- [trim](const ScalarValue& o) {
- trim->setOffset(o / 360);
+ [trimComposite](const ScalarValue& o) {
+ trimComposite->setOffset(o);
});
}
diff --git a/experimental/skottie/SkottieProperties.cpp b/experimental/skottie/SkottieProperties.cpp
index 0816e15bca..a774217a8c 100644
--- a/experimental/skottie/SkottieProperties.cpp
+++ b/experimental/skottie/SkottieProperties.cpp
@@ -15,6 +15,7 @@
#include "SkSGPath.h"
#include "SkSGRect.h"
#include "SkSGTransform.h"
+#include "SkSGTrimEffect.h"
#include <cmath>
@@ -190,4 +191,37 @@ void CompositeRadialGradient::onApply() {
grad->setEndRadius(SkPoint::Distance(this->startPoint(), this->endPoint()));
}
+CompositeTrimEffect::CompositeTrimEffect(sk_sp<sksg::TrimEffect> trimEffect)
+ : fTrimEffect(std::move(trimEffect)) {
+ SkASSERT(fTrimEffect);
+}
+
+void CompositeTrimEffect::apply() {
+ // BM semantics: start/end are percentages, offset is "degrees" (?!).
+ const auto start = fStart / 100,
+ end = fEnd / 100,
+ offset = fOffset / 360;
+
+ auto startT = SkTMin(start, end) + offset,
+ stopT = SkTMax(start, end) + offset;
+ auto mode = SkTrimPathEffect::Mode::kNormal;
+
+ if (stopT - startT < 1) {
+ startT -= SkScalarFloorToScalar(startT);
+ stopT -= SkScalarFloorToScalar(stopT);
+
+ if (startT > stopT) {
+ SkTSwap(startT, stopT);
+ mode = SkTrimPathEffect::Mode::kInverted;
+ }
+ } else {
+ startT = 0;
+ stopT = 1;
+ }
+
+ fTrimEffect->setStart(startT);
+ fTrimEffect->setStop(stopT);
+ fTrimEffect->setMode(mode);
+}
+
} // namespace skottie
diff --git a/experimental/skottie/SkottieProperties.h b/experimental/skottie/SkottieProperties.h
index 8ca026eaeb..5e3fad0d9a 100644
--- a/experimental/skottie/SkottieProperties.h
+++ b/experimental/skottie/SkottieProperties.h
@@ -28,6 +28,7 @@ class Path;
class RadialGradient;
class RRect;
class RenderNode;;
+class TrimEffect;
}
namespace Json { class Value; }
@@ -161,6 +162,22 @@ private:
using INHERITED = CompositeGradient;
};
+class CompositeTrimEffect final : public SkRefCnt {
+public:
+ explicit CompositeTrimEffect(sk_sp<sksg::TrimEffect>);
+
+ COMPOSITE_PROPERTY(Start , SkScalar, 0)
+ COMPOSITE_PROPERTY(End , SkScalar, 100)
+ COMPOSITE_PROPERTY(Offset, SkScalar, 0)
+
+private:
+ void apply();
+
+ sk_sp<sksg::TrimEffect> fTrimEffect;
+
+ using INHERITED = SkRefCnt;
+};
+
#undef COMPOSITE_PROPERTY
} // namespace skottie