From f97aa74fea0133378e64700e30a7c2962212fcb5 Mon Sep 17 00:00:00 2001 From: caryclark Date: Fri, 18 Dec 2015 07:03:13 -0800 Subject: [PATCH] fix large dashed paths Paths with lots of points exceed the 32767 point index. Make the index larger, add a test, and allow the t value to use the extra bits. R=reed@google.com,fmalita@chromium.org BUG=skia:3501 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1534223002 Review URL: https://codereview.chromium.org/1534223002 --- gm/dashing.cpp | 26 ++++++++++++++++++++++++++ include/core/SkPathMeasure.h | 6 +++++- src/core/SkPathMeasure.cpp | 9 +++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/gm/dashing.cpp b/gm/dashing.cpp index 300eb776f5..aed4c0019f 100644 --- a/gm/dashing.cpp +++ b/gm/dashing.cpp @@ -476,6 +476,32 @@ private: bool fDoAA; }; +DEF_SIMPLE_GM(longpathdash, canvas, 512, 512) { + SkPath lines; + for (int x = 32; x < 256; x += 16) { + for (SkScalar a = 0; a < 3.141592f * 2; a += 0.03141592f) { + SkPoint pts[2] = { + { 256 + (float) sin(a) * x, + 256 + (float) cos(a) * x }, + { 256 + (float) sin(a + 3.141592 / 3) * (x + 64), + 256 + (float) cos(a + 3.141592 / 3) * (x + 64) } + }; + lines.moveTo(pts[0]); + for (SkScalar i = 0; i < 1; i += 0.05f) { + lines.lineTo(pts[0].fX * (1 - i) + pts[1].fX * i, + pts[0].fY * (1 - i) + pts[1].fY * i); + } + } + } + SkPaint p; + p.setAntiAlias(true); + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(1); + const SkScalar intervals[] = { 1, 1 }; + p.setPathEffect(SkDashPathEffect::Create(intervals, SK_ARRAY_COUNT(intervals), 0))->unref(); + canvas->drawPath(lines, p); +} + ////////////////////////////////////////////////////////////////////////////// DEF_GM(return new DashingGM;) diff --git a/include/core/SkPathMeasure.h b/include/core/SkPathMeasure.h index f6e606f0c0..7528736ba8 100644 --- a/include/core/SkPathMeasure.h +++ b/include/core/SkPathMeasure.h @@ -89,8 +89,12 @@ private: struct Segment { SkScalar fDistance; // total distance up to this point - unsigned fPtIndex : 15; // index into the fPts array + unsigned fPtIndex; // index into the fPts array +#ifdef SK_SUPPORT_LEGACY_PATH_MEASURE_TVALUE unsigned fTValue : 15; +#else + unsigned fTValue : 30; +#endif unsigned fType : 2; SkScalar getScalarT() const; diff --git a/src/core/SkPathMeasure.cpp b/src/core/SkPathMeasure.cpp index caff6df399..d959f45f4f 100644 --- a/src/core/SkPathMeasure.cpp +++ b/src/core/SkPathMeasure.cpp @@ -20,11 +20,20 @@ enum { kConic_SegType, }; +#ifdef SK_SUPPORT_LEGACY_PATH_MEASURE_TVALUE #define kMaxTValue 32767 +#else +#define kMaxTValue 0x3FFFFFFF +#endif static inline SkScalar tValue2Scalar(int t) { SkASSERT((unsigned)t <= kMaxTValue); +#ifdef SK_SUPPORT_LEGACY_PATH_MEASURE_TVALUE return t * 3.05185e-5f; // t / 32767 +#else + const SkScalar kMaxTReciprocal = 1.0f / kMaxTValue; + return t * kMaxTReciprocal; +#endif } SkScalar SkPathMeasure::Segment::getScalarT() const { -- 2.34.1