aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2015-01-15 06:01:23 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-15 06:01:23 -0800
commit1a178ca6dd2ff7f62c684f7d0ee94e54fc31c91b (patch)
tree296cb27db22dd48f8595a73efdd849a8a10a05b0 /src/core
parent6e87913ab991f0aa41e51647314b5cfbda581273 (diff)
Use device-space stroke width for SkDraw::drawRect() quick-reject
The stroke width needs to be CTM-adjusted when applied to device space rects. BUG=skia:3313 R=reed@google.com Review URL: https://codereview.chromium.org/801353008
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkDraw.cpp39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index 60075322b6..f69137f6b8 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -735,6 +735,16 @@ void SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count,
}
}
+static inline SkPoint compute_stroke_size(const SkPaint& paint, const SkMatrix& matrix) {
+ SkASSERT(matrix.rectStaysRect());
+ SkASSERT(SkPaint::kFill_Style != paint.getStyle());
+
+ SkVector size;
+ SkPoint pt = { paint.getStrokeWidth(), paint.getStrokeWidth() };
+ matrix.mapVectors(&size, &pt, 1);
+ return SkPoint::Make(SkScalarAbs(size.fX), SkScalarAbs(size.fY));
+}
+
static bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix,
SkPoint* strokeSize) {
if (SkPaint::kMiter_Join != paint.getStrokeJoin() ||
@@ -742,11 +752,7 @@ static bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix,
return false;
}
- SkASSERT(matrix.rectStaysRect());
- SkPoint pt = { paint.getStrokeWidth(), paint.getStrokeWidth() };
- matrix.mapVectors(strokeSize, &pt, 1);
- strokeSize->fX = SkScalarAbs(strokeSize->fX);
- strokeSize->fY = SkScalarAbs(strokeSize->fY);
+ *strokeSize = compute_stroke_size(paint, matrix);
return true;
}
@@ -822,26 +828,27 @@ void SkDraw::drawRect(const SkRect& prePaintRect, const SkPaint& paint,
}
SkRect devRect;
- if (paintMatrix) {
- // skip the paintMatrix when transforming the rect by the CTM
- fMatrix->mapPoints(rect_points(devRect), rect_points(*postPaintRect), 2);
- } else {
- fMatrix->mapPoints(rect_points(devRect), rect_points(prePaintRect), 2);
- }
- // transform rect into devRect
+ const SkRect& paintRect = paintMatrix ? *postPaintRect : prePaintRect;
+ // skip the paintMatrix when transforming the rect by the CTM
+ fMatrix->mapPoints(rect_points(devRect), rect_points(paintRect), 2);
devRect.sort();
// look for the quick exit, before we build a blitter
- SkIRect ir = devRect.roundOut();
+ SkRect bbox = devRect;
if (paint.getStyle() != SkPaint::kFill_Style) {
// extra space for hairlines
if (paint.getStrokeWidth() == 0) {
- ir.outset(1, 1);
+ bbox.outset(1, 1);
} else {
- SkScalar radius = SkScalarHalf(paint.getStrokeWidth());
- ir.outset(radius, radius);
+ // For kStroke_RectType, strokeSize is already computed.
+ const SkPoint& ssize = (kStroke_RectType == rtype)
+ ? strokeSize
+ : compute_stroke_size(paint, *fMatrix);
+ bbox.outset(SkScalarHalf(ssize.x()), SkScalarHalf(ssize.y()));
}
}
+
+ SkIRect ir = bbox.roundOut();
if (fRC->quickReject(ir)) {
return;
}