aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-03-13 17:52:41 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-13 23:25:08 +0000
commit43398a8a4a18d11196be8a2f4ffc65b53ad92144 (patch)
tree0974f1c8a58ae1f63e79751802bb77a8f8fcd0e3 /experimental
parent6fccc50a4a6f6f094abdb7fd5a0f927e2240bde6 (diff)
[sksg] Use SkTrimPathEffect for path trimming
Refactor TrimEffect using SkTrimPathEffect instead of SkDashPathEffect. TBR= Change-Id: I1415b30b58db28cb74b70fb176307634ab0774e8 Reviewed-on: https://skia-review.googlesource.com/114264 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental')
-rw-r--r--experimental/sksg/geometry/SkSGTrimEffect.cpp52
1 files changed, 23 insertions, 29 deletions
diff --git a/experimental/sksg/geometry/SkSGTrimEffect.cpp b/experimental/sksg/geometry/SkSGTrimEffect.cpp
index 195b09ece0..fea8249161 100644
--- a/experimental/sksg/geometry/SkSGTrimEffect.cpp
+++ b/experimental/sksg/geometry/SkSGTrimEffect.cpp
@@ -8,9 +8,8 @@
#include "SkSGTrimEffect.h"
#include "SkCanvas.h"
-#include "SkDashPathEffect.h"
-#include "SkPathMeasure.h"
#include "SkStrokeRec.h"
+#include "SkTrimPathEffect.h"
namespace sksg {
@@ -41,34 +40,29 @@ SkRect TrimEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm)
SkASSERT(this->hasInval());
const auto childbounds = fChild->revalidate(ic, ctm);
+ const auto path = fChild->asPath();
- const auto path = fChild->asPath();
- SkScalar pathLen = 0;
- SkPathMeasure measure(path, false);
- do {
- pathLen += measure.getLength();
- } while (measure.nextContour());
-
- const auto start = pathLen * fStart,
- end = pathLen * fEnd,
- offset = pathLen * fOffset,
- len = end - start;
-
- fTrimmedPath.reset();
-
- if (len > 0) {
- // If the trim is positioned exactly at the beginning of the path, we don't expect any
- // visible wrap-around. But due to limited precision / accumulated error, the dash effect
- // may sometimes start one extra dash at the very end (a flickering dot during animation).
- // To avoid this, we bump the dash len by |epsilon|.
- const SkScalar dashes[] = { len, pathLen + SK_ScalarNearlyZero - len };
- auto dashEffect = SkDashPathEffect::Make(dashes,
- SK_ARRAY_COUNT(dashes),
- -start - offset);
- if (dashEffect) {
- SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle);
- SkAssertResult(dashEffect->filterPath(&fTrimmedPath, path, &rec, &childbounds));
- }
+ // TODO: relocate these funky semantics to a Skottie composite helper,
+ // and refactor TrimEffect as a thin SkTrimpPathEffect wrapper.
+ auto start = SkTMin(fStart, fEnd) + fOffset,
+ stop = SkTMax(fStart, fEnd) + fOffset;
+
+ sk_sp<SkPathEffect> trim;
+ if (stop - start < 1) {
+ start -= SkScalarFloorToScalar(start);
+ stop -= SkScalarFloorToScalar(stop);
+
+ trim = start <= stop
+ ? SkTrimPathEffect::Make(start, stop, SkTrimPathEffect::Mode::kNormal)
+ : SkTrimPathEffect::Make(stop, start, SkTrimPathEffect::Mode::kInverted);
+ }
+
+ if (trim) {
+ fTrimmedPath.reset();
+ SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle);
+ SkAssertResult(trim->filterPath(&fTrimmedPath, path, &rec, &childbounds));
+ } else {
+ fTrimmedPath = path;
}
return fTrimmedPath.computeTightBounds();