diff options
author | Florin Malita <fmalita@chromium.org> | 2018-03-22 12:20:02 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-22 16:43:05 +0000 |
commit | 69526b023cc9cdced1ae1df74002b11cd6709b12 (patch) | |
tree | ad11cdb6ffc446c48f39a41f88c3db680f4712f9 /experimental/skottie/SkottieProperties.cpp | |
parent | 1a605cd396620d30a8f2b11bf57439fce5927a00 (diff) |
[sksg] Simplify TrimEffect
Move the Lottie-specific bits to Skottie and keep TrimEffect as a thin
SkTrimPathEffect wrapper.
TBR=
Change-Id: Iecc6624d01ba61eb96a2056ef8e9e24e731f8979
Reviewed-on: https://skia-review.googlesource.com/115923
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental/skottie/SkottieProperties.cpp')
-rw-r--r-- | experimental/skottie/SkottieProperties.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
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 |