diff options
author | ethannicholas <ethannicholas@google.com> | 2015-08-19 12:09:12 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-19 12:09:12 -0700 |
commit | fea7763140ba74b78f2c30028452e250140b6f21 (patch) | |
tree | 281b8afc1cb82b3828e0815cbf06736bf8c9e0d1 | |
parent | e5e6c6069fb808626df0280cebc9399a950cdff7 (diff) |
Fix transformed stroke width in GrAALinearizingConvexPathRenderer.
BUG=520476
Review URL: https://codereview.chromium.org/1302503003
-rw-r--r-- | gm/scaledstrokes.cpp | 84 | ||||
-rw-r--r-- | src/gpu/GrAAConvexTessellator.cpp | 11 | ||||
-rw-r--r-- | src/gpu/GrAALinearizingConvexPathRenderer.cpp | 7 |
3 files changed, 97 insertions, 5 deletions
diff --git a/gm/scaledstrokes.cpp b/gm/scaledstrokes.cpp new file mode 100644 index 0000000000..59c3efb1cc --- /dev/null +++ b/gm/scaledstrokes.cpp @@ -0,0 +1,84 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gm.h" +#include "SkCanvas.h" +#include "SkRRect.h" +#include "SkPath.h" + +class ScaledStrokesGM : public skiagm::GM { +public: + ScaledStrokesGM() {} + +protected: + + SkString onShortName() override { + return SkString("scaledstrokes"); + } + + SkISize onISize() override { + return SkISize::Make(640, 320); + } + + static void draw_path(SkScalar size, SkCanvas* canvas, SkPaint paint) { + SkScalar c = 0.551915024494f * size; + SkPath path; + path.moveTo(0.0f, size); + path.cubicTo(c, size, size, c, size, 0.0f); + path.cubicTo(size, -c, c, -size, 0.0f, -size); + path.cubicTo(-c, -size, -size, -c, -size, 0.0f); + path.cubicTo(-size, c, -c, size, 0.0f, size); + canvas->drawPath(path, paint); + } + + void onDraw(SkCanvas* canvas) override { + SkPaint paint; + SkPath path; + paint.setStyle(SkPaint::Style::kStroke_Style); + canvas->translate(5.0f, 5.0f); + const SkScalar size = 60.0f; + for (int i = 0; i < 2; i++) { + paint.setAntiAlias(i == 1); + canvas->save(); + for (int j = 0; j < 4; j++) { + SkScalar scale = 4.0f - j; + paint.setStrokeWidth(4.0f / scale); + canvas->save(); + canvas->translate(size / 2.0f, size / 2.0f); + canvas->scale(scale, scale); + draw_path(size / 2.0f / scale, canvas, paint); + canvas->restore(); + + canvas->save(); + canvas->translate(size / 2.0f, 80.0f + size / 2.0f); + canvas->scale(scale, scale); + canvas->drawCircle(0.0f, 0.0f, size / 2.0f / scale, paint); + canvas->restore(); + + canvas->save(); + canvas->translate(0.0f, 160.0f); + canvas->scale(scale, scale); + canvas->drawRect(SkRect::MakeXYWH(0.0f, 0.0f, size / scale, size / scale), paint); + canvas->restore(); + + canvas->save(); + canvas->translate(0.0f, 240.0f); + canvas->scale(scale, scale); + canvas->drawLine(0.0f, 0.0f, size / scale, size / scale, paint); + canvas->restore(); + + canvas->translate(80.0f, 0.0f); + } + } + + } + +private: + typedef GM INHERITED; +}; + +DEF_GM( return new ScaledStrokesGM; ) diff --git a/src/gpu/GrAAConvexTessellator.cpp b/src/gpu/GrAAConvexTessellator.cpp index e38ba3c3ae..db10086741 100644 --- a/src/gpu/GrAAConvexTessellator.cpp +++ b/src/gpu/GrAAConvexTessellator.cpp @@ -201,10 +201,14 @@ bool GrAAConvexTessellator::tessellate(const SkMatrix& m, const SkPath& path) { } SkScalar coverage = 1.0f; + SkScalar scaleFactor = 0.0f; if (fStrokeWidth >= 0.0f) { + SkASSERT(m.isSimilarity()); + scaleFactor = m.getMaxScale(); // x and y scale are the same + SkScalar effectiveStrokeWidth = scaleFactor * fStrokeWidth; Ring outerStrokeRing; - this->createOuterRing(fInitialRing, fStrokeWidth / 2 - kAntialiasingRadius, coverage, - &outerStrokeRing); + this->createOuterRing(fInitialRing, effectiveStrokeWidth / 2 - kAntialiasingRadius, + coverage, &outerStrokeRing); outerStrokeRing.init(*this); Ring outerAARing; this->createOuterRing(outerStrokeRing, kAntialiasingRadius * 2, 0.0f, &outerAARing); @@ -216,8 +220,9 @@ bool GrAAConvexTessellator::tessellate(const SkMatrix& m, const SkPath& path) { // the bisectors are only needed for the computation of the outer ring fBisectors.rewind(); if (fStrokeWidth >= 0.0f && fInitialRing.numPts() > 2) { + SkScalar effectiveStrokeWidth = scaleFactor * fStrokeWidth; Ring* insetStrokeRing; - SkScalar strokeDepth = fStrokeWidth / 2 - kAntialiasingRadius; + SkScalar strokeDepth = effectiveStrokeWidth / 2 - kAntialiasingRadius; if (this->createInsetRings(fInitialRing, 0.0f, coverage, strokeDepth, coverage, &insetStrokeRing)) { Ring* insetAARing; diff --git a/src/gpu/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/GrAALinearizingConvexPathRenderer.cpp index fc72a8f60f..899c6b1ef1 100644 --- a/src/gpu/GrAALinearizingConvexPathRenderer.cpp +++ b/src/gpu/GrAALinearizingConvexPathRenderer.cpp @@ -50,8 +50,11 @@ bool GrAALinearizingConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& arg return false; } if (args.fStroke->getStyle() == SkStrokeRec::kStroke_Style) { - return args.fViewMatrix->isSimilarity() && args.fStroke->getWidth() >= 1.0f && - args.fStroke->getWidth() <= kMaxStrokeWidth && !args.fStroke->isDashed() && + if (!args.fViewMatrix->isSimilarity()) { + return false; + } + SkScalar strokeWidth = args.fViewMatrix->getMaxScale() * args.fStroke->getWidth(); + return strokeWidth >= 1.0f && strokeWidth <= kMaxStrokeWidth && !args.fStroke->isDashed() && SkPathPriv::LastVerbIsClose(*args.fPath) && args.fStroke->getJoin() != SkPaint::Join::kRound_Join; } |