aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2018-03-07 17:02:47 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-07 22:32:20 +0000
commit4123223ccc85e4f712495403dd1a2869110fd8c4 (patch)
treeccb587567bd48f2a1b77885e92f8a0c44649fff2 /src/effects
parent23d23892cad305117fb8e46bcf8e15c3174c47f4 (diff)
add TrimPathEffect
Bug: skia: Change-Id: I453fb81ded4435b33567e9c8a6f3abe9535d687f Reviewed-on: https://skia-review.googlesource.com/112820 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/SkDashImpl.h2
-rw-r--r--src/effects/SkTrimPE.h32
-rw-r--r--src/effects/SkTrimPathEffect.cpp63
3 files changed, 96 insertions, 1 deletions
diff --git a/src/effects/SkDashImpl.h b/src/effects/SkDashImpl.h
index cf74529934..c4e81478c7 100644
--- a/src/effects/SkDashImpl.h
+++ b/src/effects/SkDashImpl.h
@@ -10,7 +10,7 @@
#include "SkPathEffect.h"
-class SK_API SkDashImpl : public SkPathEffect {
+class SkDashImpl : public SkPathEffect {
public:
SkDashImpl(const SkScalar intervals[], int count, SkScalar phase);
diff --git a/src/effects/SkTrimPE.h b/src/effects/SkTrimPE.h
new file mode 100644
index 0000000000..2cd39c4793
--- /dev/null
+++ b/src/effects/SkTrimPE.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkTrimImpl_DEFINED
+#define SkTrimImpl_DEFINED
+
+#include "SkPathEffect.h"
+
+class SkTrimPE : public SkPathEffect {
+public:
+ SkTrimPE(SkScalar startT, SkScalar stopT);
+
+ bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
+
+ SK_TO_STRING_OVERRIDE()
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTrimPE)
+
+protected:
+ void flatten(SkWriteBuffer&) const override;
+
+private:
+ const SkScalar fStartT;
+ const SkScalar fStopT;
+
+ typedef SkPathEffect INHERITED;
+};
+
+#endif
diff --git a/src/effects/SkTrimPathEffect.cpp b/src/effects/SkTrimPathEffect.cpp
new file mode 100644
index 0000000000..beaa36e17d
--- /dev/null
+++ b/src/effects/SkTrimPathEffect.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkPathMeasure.h"
+#include "SkTrimPathEffect.h"
+#include "SkTrimPE.h"
+#include "SkReadBuffer.h"
+#include "SkWriteBuffer.h"
+
+SkTrimPE::SkTrimPE(SkScalar startT, SkScalar stopT) : fStartT(startT), fStopT(stopT) {
+ SkASSERT(startT >= 0 && startT <= 1);
+ SkASSERT(stopT >= 0 && stopT <= 1);
+ SkASSERT(startT != stopT);
+}
+
+bool SkTrimPE::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
+ const SkRect* cullRect) const {
+ SkPathMeasure meas(src, false);
+ SkScalar length = meas.getLength();
+
+ if (fStartT < fStopT) {
+ meas.getSegment(fStartT * length, fStopT * length, dst, true);
+ } else {
+ meas.getSegment(0, fStopT * length, dst, true);
+ meas.getSegment(fStartT * length, length, dst, true);
+ }
+ return true;
+}
+
+void SkTrimPE::flatten(SkWriteBuffer& buffer) const {
+ buffer.writeScalar(fStartT);
+ buffer.writeScalar(fStopT);
+}
+
+sk_sp<SkFlattenable> SkTrimPE::CreateProc(SkReadBuffer& buffer) {
+ SkScalar start = buffer.readScalar();
+ SkScalar stop = buffer.readScalar();
+ return SkTrimPathEffect::Make(start, stop);
+}
+
+#ifndef SK_IGNORE_TO_STRING
+void SkTrimPE::toString(SkString* str) const {
+ str->appendf("SkTrimPathEffect: (%g %g)", fStartT, fStopT);
+}
+#endif
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+sk_sp<SkPathEffect> SkTrimPathEffect::Make(SkScalar startT, SkScalar stopT) {
+ if (!SkScalarsAreFinite(startT, stopT)) {
+ return nullptr;
+ }
+ startT = SkTPin(startT, 0.f, 1.f);
+ stopT = SkTPin(stopT, 0.f, 1.f);
+ if (startT == stopT) {
+ return nullptr;
+ }
+ return sk_sp<SkPathEffect>(new SkTrimPE(startT, stopT));
+}