fix for teeny strokes

Pass the scale before evaluating degenerate line segments.

This does not change other GMs.

R=reed@google.com
BUG=478337

Review URL: https://codereview.chromium.org/1418133007
This commit is contained in:
caryclark 2015-10-26 08:17:04 -07:00 committed by Commit bot
parent 05ded89127
commit 950305ec77
2 changed files with 43 additions and 5 deletions

View File

@ -158,6 +158,42 @@ private:
typedef skiagm::GM INHERITED;
};
class TeenyStrokesGM : public skiagm::GM {
SkString onShortName() override {
return SkString("teenyStrokes");
}
SkISize onISize() override {
return SkISize::Make(W, H*2);
}
static void line(SkScalar scale, SkCanvas* canvas, SkColor color) {
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
p.setColor(color);
canvas->translate(50, 0);
canvas->save();
p.setStrokeWidth(scale * 5);
canvas->scale(1 / scale, 1 / scale);
canvas->drawLine(20 * scale, 20 * scale, 20 * scale, 100 * scale, p);
canvas->drawLine(20 * scale, 20 * scale, 100 * scale, 100 * scale, p);
canvas->restore();
}
void onDraw(SkCanvas* canvas) override {
line(0.00005f, canvas, SK_ColorBLACK);
line(0.000045f, canvas, SK_ColorRED);
line(0.0000035f, canvas, SK_ColorGREEN);
line(0.000003f, canvas, SK_ColorBLUE);
line(0.000002f, canvas, SK_ColorBLACK);
}
private:
typedef skiagm::GM INHERITED;
};
class Strokes2GM : public skiagm::GM {
SkPath fPath;
protected:
@ -418,3 +454,4 @@ static skiagm::GMRegistry R3(F3);
static skiagm::GMRegistry R4(F4);
DEF_GM( return new ZeroLenStrokesGM; )
DEF_GM( return new TeenyStrokesGM; )

View File

@ -51,10 +51,11 @@ static inline bool degenerate_vector(const SkVector& v) {
return !SkPoint::CanNormalize(v.fX, v.fY);
}
static bool set_normal_unitnormal(const SkPoint& before, const SkPoint& after,
static bool set_normal_unitnormal(const SkPoint& before, const SkPoint& after, SkScalar scale,
SkScalar radius,
SkVector* normal, SkVector* unitNormal) {
if (!unitNormal->setNormalize(after.fX - before.fX, after.fY - before.fY)) {
if (!unitNormal->setNormalize((after.fX - before.fX) * scale,
(after.fY - before.fY) * scale)) {
return false;
}
unitNormal->rotateCCW();
@ -244,7 +245,7 @@ bool SkPathStroker::preJoinTo(const SkPoint& currPt, SkVector* normal,
SkScalar prevX = fPrevPt.fX;
SkScalar prevY = fPrevPt.fY;
if (!set_normal_unitnormal(fPrevPt, currPt, fRadius, normal, unitNormal)) {
if (!set_normal_unitnormal(fPrevPt, currPt, fResScale, fRadius, normal, unitNormal)) {
if (SkStrokerPriv::CapFactory(SkPaint::kButt_Cap) == fCapper) {
return false;
}
@ -367,7 +368,7 @@ void SkPathStroker::line_to(const SkPoint& currPt, const SkVector& normal) {
void SkPathStroker::lineTo(const SkPoint& currPt) {
if (SkStrokerPriv::CapFactory(SkPaint::kButt_Cap) == fCapper
&& SkPath::IsLineDegenerate(fPrevPt, currPt, false)) {
&& fPrevPt.equalsWithinTolerance(currPt, SK_ScalarNearlyZero * fInvResScale)) {
return;
}
SkVector normal, unitNormal;
@ -381,7 +382,7 @@ void SkPathStroker::lineTo(const SkPoint& currPt) {
void SkPathStroker::setQuadEndNormal(const SkPoint quad[3], const SkVector& normalAB,
const SkVector& unitNormalAB, SkVector* normalBC, SkVector* unitNormalBC) {
if (!set_normal_unitnormal(quad[1], quad[2], fRadius, normalBC, unitNormalBC)) {
if (!set_normal_unitnormal(quad[1], quad[2], fResScale, fRadius, normalBC, unitNormalBC)) {
*normalBC = normalAB;
*unitNormalBC = unitNormalAB;
}