diff options
author | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-01-15 12:53:31 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-01-15 12:53:31 +0000 |
commit | 5c4d5582c9d47ea47c7699fe69b9f95d0117dbd5 (patch) | |
tree | 3b8a2af2897a6896b328d58f7e892a2ec69d0e0b | |
parent | fb830981f2ec157674953650de6ddbf8723051a0 (diff) |
dashing asPoints could draw excessively long first dash
https://codereview.appspot.com/7098054/
Will require rebaselining of dashing gm.
git-svn-id: http://skia.googlecode.com/svn/trunk@7177 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | debugger/SkDrawCommand.cpp | 1 | ||||
-rw-r--r-- | gm/dashing.cpp | 6 | ||||
-rw-r--r-- | src/effects/SkDashPathEffect.cpp | 33 |
3 files changed, 24 insertions, 16 deletions
diff --git a/debugger/SkDrawCommand.cpp b/debugger/SkDrawCommand.cpp index 4b39fac587..5f33eb1f39 100644 --- a/debugger/SkDrawCommand.cpp +++ b/debugger/SkDrawCommand.cpp @@ -316,6 +316,7 @@ DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count, this->fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar(count), "Points: ")); this->fInfo.push(SkObjectParser::PointModeToString(mode)); + this->fInfo.push(SkObjectParser::PaintToString(paint)); } void DrawPoints::execute(SkCanvas* canvas) { diff --git a/gm/dashing.cpp b/gm/dashing.cpp index 914824d885..37ea285024 100644 --- a/gm/dashing.cpp +++ b/gm/dashing.cpp @@ -248,6 +248,12 @@ protected: this->drawDashedLines(canvas, 99.5f, SK_ScalarHalf, SK_Scalar1, 1, false); canvas->restore(); + // 255on/255off 1x1 squares with phase of 0 - rects fast path + canvas->save(); + canvas->translate(446, 0); + this->drawDashedLines(canvas, 100, 0, SkIntToScalar(255), 1, false); + canvas->restore(); + // 1on/1off 3x3 squares with phase of 0 - points fast path canvas->save(); canvas->translate(2, 110); diff --git a/src/effects/SkDashPathEffect.cpp b/src/effects/SkDashPathEffect.cpp index 58d746b3b9..ef10ca5e8c 100644 --- a/src/effects/SkDashPathEffect.cpp +++ b/src/effects/SkDashPathEffect.cpp @@ -320,6 +320,7 @@ bool SkDashPathEffect::asPoints(PointData* results, if (NULL != results) { results->fFlags = 0; + SkScalar clampedInitialDashLength = SkMinScalar(length, fInitialDashLength); if (SkPaint::kRound_Cap == rec.getCap()) { results->fFlags |= PointData::kCircles_PointFlag; @@ -328,22 +329,22 @@ bool SkDashPathEffect::asPoints(PointData* results, results->fNumPoints = 0; SkScalar len2 = length; bool partialFirst = false; - if (fInitialDashLength > 0 || 0 == fInitialDashIndex) { - SkASSERT(len2 >= fInitialDashLength); + if (clampedInitialDashLength > 0 || 0 == fInitialDashIndex) { + SkASSERT(len2 >= clampedInitialDashLength); if (0 == fInitialDashIndex) { - if (fInitialDashLength > 0) { + if (clampedInitialDashLength > 0) { partialFirst = true; - if (fInitialDashLength >= fIntervals[0]) { + if (clampedInitialDashLength >= fIntervals[0]) { ++results->fNumPoints; // partial first dash } - len2 -= fInitialDashLength; + len2 -= clampedInitialDashLength; } len2 -= fIntervals[1]; // also skip first space if (len2 < 0) { len2 = 0; } } else { - len2 -= fInitialDashLength; // skip initial partial empty + len2 -= clampedInitialDashLength; // skip initial partial empty } } int numMidPoints = SkScalarFloorToInt(SkScalarDiv(len2, fIntervalLength)); @@ -364,24 +365,24 @@ bool SkDashPathEffect::asPoints(PointData* results, SkScalar distance = 0; int curPt = 0; - if (fInitialDashLength > 0 || 0 == fInitialDashIndex) { - SkASSERT(fInitialDashLength <= length); + if (clampedInitialDashLength > 0 || 0 == fInitialDashIndex) { + SkASSERT(clampedInitialDashLength <= length); if (0 == fInitialDashIndex) { - if (fInitialDashLength > 0) { + if (clampedInitialDashLength > 0) { // partial first block SkASSERT(SkPaint::kRound_Cap != rec.getCap()); // can't handle partial circles - SkScalar x = pts[0].fX + SkScalarMul(tangent.fX, SkScalarHalf(fInitialDashLength)); - SkScalar y = pts[0].fY + SkScalarMul(tangent.fY, SkScalarHalf(fInitialDashLength)); + SkScalar x = pts[0].fX + SkScalarMul(tangent.fX, SkScalarHalf(clampedInitialDashLength)); + SkScalar y = pts[0].fY + SkScalarMul(tangent.fY, SkScalarHalf(clampedInitialDashLength)); SkScalar halfWidth, halfHeight; if (isXAxis) { - halfWidth = SkScalarHalf(fInitialDashLength); + halfWidth = SkScalarHalf(clampedInitialDashLength); halfHeight = SkScalarHalf(rec.getWidth()); } else { halfWidth = SkScalarHalf(rec.getWidth()); - halfHeight = SkScalarHalf(fInitialDashLength); + halfHeight = SkScalarHalf(clampedInitialDashLength); } - if (fInitialDashLength < fIntervals[0]) { + if (clampedInitialDashLength < fIntervals[0]) { // This one will not be like the others results->fFirst.addRect(x - halfWidth, y - halfHeight, x + halfWidth, y + halfHeight); @@ -391,12 +392,12 @@ bool SkDashPathEffect::asPoints(PointData* results, ++curPt; } - distance += fInitialDashLength; + distance += clampedInitialDashLength; } distance += fIntervals[1]; // skip over the next blank block too } else { - distance += fInitialDashLength; + distance += clampedInitialDashLength; } } |