aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2015-10-26 08:17:04 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-10-26 08:17:04 -0700
commit950305ec77702639fe6ad1923f7b8d828ccef634 (patch)
tree94bd31af42271a4ac9e25da07f8383cc6a16e1f0
parent05ded891272772d43acc16345b2f90a4560df090 (diff)
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
-rw-r--r--gm/strokes.cpp37
-rw-r--r--src/core/SkStroke.cpp11
2 files changed, 43 insertions, 5 deletions
diff --git a/gm/strokes.cpp b/gm/strokes.cpp
index e74d35f800..bd393829e0 100644
--- a/gm/strokes.cpp
+++ b/gm/strokes.cpp
@@ -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; )
diff --git a/src/core/SkStroke.cpp b/src/core/SkStroke.cpp
index 522a000712..e04d14aea5 100644
--- a/src/core/SkStroke.cpp
+++ b/src/core/SkStroke.cpp
@@ -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;
}