diff options
author | george <george@mozilla.com> | 2014-09-09 11:33:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-09 11:33:57 -0700 |
commit | b3eba478d5bed5fb2b5f0f224738c8c292cebf36 (patch) | |
tree | 0d1a4fee05c8292abd4544240afba10bb91e968a | |
parent | 32673b99a4fb5d798206eb7665b730ed0b4597a0 (diff) |
Outset the stroke width when computing the bounds for drawing a stroked rect, or 1 if it's a hairline
Adds a testcase for stroke rect bug
R=reed@google.com, reed1
BUG=skia:
Author: george@mozilla.com
Review URL: https://codereview.chromium.org/552743004
-rw-r--r-- | gm/clip_strokerect.cpp | 73 | ||||
-rw-r--r-- | gyp/gmslides.gypi | 1 | ||||
-rw-r--r-- | src/core/SkDraw.cpp | 7 |
3 files changed, 80 insertions, 1 deletions
diff --git a/gm/clip_strokerect.cpp b/gm/clip_strokerect.cpp new file mode 100644 index 0000000000..707229214a --- /dev/null +++ b/gm/clip_strokerect.cpp @@ -0,0 +1,73 @@ +/* + * Copyright 2011 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 "SkPath.h" + +class ClipStrokeRectGM : public skiagm::GM { +public: + ClipStrokeRectGM() { + + } + +protected: + virtual SkString onShortName() SK_OVERRIDE { + return SkString("clip_strokerect"); + } + + virtual SkISize onISize() SK_OVERRIDE { + return SkISize::Make(200, 400); + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + SkPaint p; + p.setColor(SK_ColorRED); + p.setAntiAlias(true); + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(22); + + SkRect r = SkRect::MakeXYWH(20, 20, 100, 100); + // setting the height of this to 19 causes failure + SkRect rect = SkRect::MakeXYWH(20, 0, 100, 20); + + canvas->save(); + canvas->clipRect(rect, SkRegion::kReplace_Op, true); + canvas->drawRect(r, p); + canvas->restore(); + + p.setColor(SK_ColorBLUE); + p.setStrokeWidth(2); + canvas->drawRect(rect, p); + + p.setColor(SK_ColorRED); + p.setAntiAlias(true); + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(22); + + SkRect r2 = SkRect::MakeXYWH(20, 140, 100, 100); + // setting the height of this to 19 causes failure + SkRect rect2 = SkRect::MakeXYWH(20, 120, 100, 19); + + canvas->save(); + canvas->clipRect(rect2, SkRegion::kReplace_Op, true); + canvas->drawRect(r2, p); + canvas->restore(); + + p.setColor(SK_ColorBLUE); + p.setStrokeWidth(2); + canvas->drawRect(rect2, p); + } + + virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } + +private: + typedef skiagm::GM INHERITED; +}; + +DEF_GM( return SkNEW(ClipStrokeRectGM); ) + diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index 9ac1dfd50f..c8f9c2f65c 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -40,6 +40,7 @@ '../gm/blurroundrect.cpp', '../gm/circles.cpp', '../gm/circularclips.cpp', + '../gm/clip_strokerect.cpp', '../gm/clippedbitmapshaders.cpp', '../gm/coloremoji.cpp', '../gm/colorfilterimagefilter.cpp', diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index 3532efd7e5..4b878ba2b1 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -817,7 +817,12 @@ void SkDraw::drawRect(const SkRect& rect, const SkPaint& paint) const { devRect.roundOut(&ir); if (paint.getStyle() != SkPaint::kFill_Style) { // extra space for hairlines - ir.inset(-1, -1); + if (paint.getStrokeWidth() == 0) { + ir.outset(1, 1); + } else { + SkScalar radius = SkScalarHalf(paint.getStrokeWidth()); + ir.outset(radius, radius); + } } if (fRC->quickReject(ir)) { return; |