diff options
author | joshualitt <joshualitt@chromium.org> | 2014-12-10 14:23:40 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-10 14:23:40 -0800 |
commit | bd528cdb51c4a64c2daead66f152b4034cebf752 (patch) | |
tree | 1591b9853e3f971dd9990ac8afdfbdf3c880fc47 /gm/hairlines.cpp | |
parent | b2fe5407df616e00e41d380393673136d8f9f1e7 (diff) |
fix for chrome bug with sub pixel hairlines
BUG=skia:
Review URL: https://codereview.chromium.org/796573002
Diffstat (limited to 'gm/hairlines.cpp')
-rw-r--r-- | gm/hairlines.cpp | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/gm/hairlines.cpp b/gm/hairlines.cpp index e017d8b22d..df67412dfe 100644 --- a/gm/hairlines.cpp +++ b/gm/hairlines.cpp @@ -22,7 +22,7 @@ protected: return SkString("hairlines"); } - virtual SkISize onISize() { return SkISize::Make(800, 600); } + virtual SkISize onISize() { return SkISize::Make(1250, 1250); } virtual void onOnceBeforeDraw() SK_OVERRIDE { { @@ -166,6 +166,7 @@ protected: virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { static const SkAlpha kAlphaValue[] = { 0xFF, 0x40 }; + static const SkScalar kWidths[] = { 0, 0.5f, 1.5f }; enum { kMargin = 5, @@ -180,32 +181,34 @@ protected: for (int p = 0; p < fPaths.count(); ++p) { for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) { for (int aa = 0; aa < 2; ++aa) { - const SkRect& bounds = fPaths[p].getBounds(); + for (size_t w = 0; w < SK_ARRAY_COUNT(kWidths); w++) { + const SkRect& bounds = fPaths[p].getBounds(); + + if (x + bounds.width() > wrapX) { + canvas->restore(); + canvas->translate(0, maxH + SkIntToScalar(kMargin)); + canvas->save(); + maxH = 0; + x = SkIntToScalar(kMargin); + } + + SkPaint paint; + paint.setARGB(kAlphaValue[a], 0, 0, 0); + paint.setAntiAlias(SkToBool(aa)); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(kWidths[w]); - if (x + bounds.width() > wrapX) { - canvas->restore(); - canvas->translate(0, maxH + SkIntToScalar(kMargin)); canvas->save(); - maxH = 0; - x = SkIntToScalar(kMargin); - } - - SkPaint paint; - paint.setARGB(kAlphaValue[a], 0, 0, 0); - paint.setAntiAlias(SkToBool(aa)); - paint.setStyle(SkPaint::kStroke_Style); - paint.setStrokeWidth(0); - - canvas->save(); - canvas->translate(-bounds.fLeft, -bounds.fTop); - canvas->drawPath(fPaths[p], paint); - canvas->restore(); + canvas->translate(-bounds.fLeft, -bounds.fTop); + canvas->drawPath(fPaths[p], paint); + canvas->restore(); - maxH = SkMaxScalar(maxH, bounds.height()); + maxH = SkMaxScalar(maxH, bounds.height()); - SkScalar dx = bounds.width() + SkIntToScalar(kMargin); - x += dx; - canvas->translate(dx, 0); + SkScalar dx = bounds.width() + SkIntToScalar(kMargin); + x += dx; + canvas->translate(dx, 0); + } } } } |