Fix transformed stroke width in GrAALinearizingConvexPathRenderer.
BUG=520476 Review URL: https://codereview.chromium.org/1302503003
This commit is contained in:
parent
e5e6c6069f
commit
fea7763140
84
gm/scaledstrokes.cpp
Normal file
84
gm/scaledstrokes.cpp
Normal file
@ -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; )
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user