Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1002)

Unified Diff: experimental/curve_dash_measure/SkDashMeasure.cpp

Issue 2236483004: Add SkDashMeasure.h (name up for bikeshedding) which takes a dashinfo (Closed) Base URL: https://skia.googlesource.com/skia.git@initializer_constructor
Patch Set: Actually remove src/core/SkDashMeasure.h Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/curve_dash_measure/SkDashMeasure.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/curve_dash_measure/SkDashMeasure.cpp
diff --git a/experimental/curve_dash_measure/SkDashMeasure.cpp b/experimental/curve_dash_measure/SkDashMeasure.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7271cd8a3808df4e2ab70273c56c7274fc2be411
--- /dev/null
+++ b/experimental/curve_dash_measure/SkDashMeasure.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkCurveMeasure.h"
+#include "SkDashMeasure.h"
+#include "SkPathMeasurePriv.h"
+
+void getDashedPath(const SkPath& path,
+ const struct SkPathEffect::DashInfo& dashInfo,
+ SkPath* dst) {
+ const SkScalar* intervals = dashInfo.fIntervals;
+
+ int32_t interval_index = 0;
+ SkScalar interval_accum = intervals[interval_index];
+
+ SkPath::Iter iter(path, false);
+ SkPath::Verb current;
+ SkPoint pts[4];
+
+ while ((current = iter.next(pts)) != SkPath::kDone_Verb) {
+ SkSegType segtype;
+ SkPoint end;
+ switch (current) {
+ case SkPath::kMove_Verb:
+ dst->moveTo(pts[0]);
+ continue;
+ case SkPath::kLine_Verb:
+ segtype = kLine_SegType;
+ end = pts[1];
+ break;
+ case SkPath::kQuad_Verb:
+ segtype = kQuad_SegType;
+ end = pts[2];
+ break;
+ case SkPath::kConic_Verb:
+ segtype = kConic_SegType;
+ end = pts[2];
+ break;
+ case SkPath::kCubic_Verb:
+ segtype = kCubic_SegType;
+ end = pts[3];
+ break;
+ case SkPath::kClose_Verb:
+ // should not appear in the iter since we're not using RawIter
+ SkASSERT(false);
+ break;
+ default: // unreachable
+ SkASSERT(false);
+ break;
+ }
+
+ // TODO(hstern): Do heuristic check to see whether we should do
+ // pathmeasure or curvemeasure. probably do it before the outer loop
+ // by giving CurveMeasure a reset() and reusing the object inside.
+ SkCurveMeasure meas(pts, segtype);
+
+ SkScalar prevT = 0;
+
+ SkScalar current_length = meas.getLength();
+ while (interval_accum < current_length) {
+ SkScalar time;
+ SkPoint pos;
+ meas.getPosTanTime(interval_accum, &pos, nullptr, &time);
+ if (dashIsOn(interval_index)) {
+ SkPathMeasure_segTo(pts, segtype, prevT, time, dst);
+ } else {
+ dst->moveTo(pos);
+ }
+ prevT = time;
+
+ interval_accum += intervals[interval_index];
+ interval_index = (interval_index+1) % dashInfo.fCount;
+ }
+ if (dashIsOn(interval_index)) {
+ SkPathMeasure_segTo(pts, segtype, prevT, 1, dst);
+ } else {
+ dst->moveTo(end);
+ }
+
+ interval_accum = interval_accum - current_length;
+ }
+}
« no previous file with comments | « experimental/curve_dash_measure/SkDashMeasure.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698