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

Unified Diff: src/core/SkDashMeasure.h

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: remove accidentally-included test gm 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkDashMeasure.h
diff --git a/src/core/SkDashMeasure.h b/src/core/SkDashMeasure.h
new file mode 100644
index 0000000000000000000000000000000000000000..23751fc8dae23694fac598565d51be8de53fc0e4
--- /dev/null
+++ b/src/core/SkDashMeasure.h
@@ -0,0 +1,92 @@
+/*
+ * 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 "SkGeometry.h"
+#include "SkPath.h"
+#include "SkPathEffect.h"
+#include "SkPathMeasurePriv.h"
+
+static inline void getDashedPath(const SkPath& path,
+ const struct SkPathEffect::DashInfo& dashInfo,
+ SkPath* dst) {
+ const SkScalar* intervals = dashInfo.fIntervals;
+
+ SkScalar interval_accum = 0.0f;
caryclark 2016/08/11 12:35:12 remove this
Harry Stern 2016/08/11 15:21:09 Done.
+ int32_t interval_index = 0;
+
+ interval_accum = intervals[interval_index];
caryclark 2016/08/11 12:35:12 SkScalar internal_accum ...
Harry Stern 2016/08/11 15:21:09 Done.
+
+ 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):
caryclark 2016/08/11 12:35:12 no need for parens
Harry Stern 2016/08/11 15:21:09 Done.
+ 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[3];
caryclark 2016/08/11 12:35:12 pts[2]
Harry Stern 2016/08/11 15:21:09 Done.
+ 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.0f;
caryclark 2016/08/11 12:35:12 0 is fine here
Harry Stern 2016/08/11 15:21:09 Done.
+
+ SkScalar current_length = meas.getLength();
+ while (interval_accum < current_length) {
+ SkScalar time;
+ SkPoint pos;
+ meas.getPosTanTime(interval_accum, &pos, nullptr, &time);
+ if (!(interval_index%2)) {
caryclark 2016/08/11 12:35:12 spaces on both sides of %
Harry Stern 2016/08/11 15:21:09 Done. I'm actually going to put this in a tiny hel
+ SkPathMeasure_segTo(pts, segtype, prevT, time, dst);
+ }
+ else {
+ dst->moveTo(pos);
caryclark 2016/08/11 12:35:12 put else on same line as close brace
Harry Stern 2016/08/11 15:21:09 Done, but I have written my elses on separate line
+ }
+ prevT = time;
+
+ interval_accum += intervals[interval_index];
+ interval_index = (interval_index+1)%dashInfo.fCount;
caryclark 2016/08/11 12:35:12 spaces on both sides of %
Harry Stern 2016/08/11 15:21:09 Done.
+ }
+ if (!(interval_index%2)) {
caryclark 2016/08/11 12:35:12 spaces on either side of %
Harry Stern 2016/08/11 15:21:09 Done.
+ SkPathMeasure_segTo(pts, segtype, prevT, 1.0f, dst);
caryclark 2016/08/11 12:35:12 1 is fine here
Harry Stern 2016/08/11 15:21:09 Done.
+ }
+ else {
caryclark 2016/08/11 12:35:12 put else on same line as close brace
Harry Stern 2016/08/11 15:21:09 Done.
+ dst->moveTo(end);
+ }
+
+ interval_accum = interval_accum - current_length;
+ }
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698