Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: src/core/SkDraw.cpp

Issue 801353008: Use device-space stroke width for SkDraw::drawRect() quick-reject (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/tests.gypi ('k') | tests/RectTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDraw.h" 8 #include "SkDraw.h"
9 #include "SkBlitter.h" 9 #include "SkBlitter.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 this->drawPath(path, p, NULL, true); 728 this->drawPath(path, p, NULL, true);
729 } 729 }
730 path.rewind(); 730 path.rewind();
731 } 731 }
732 break; 732 break;
733 } 733 }
734 } 734 }
735 } 735 }
736 } 736 }
737 737
738 static inline SkPoint compute_stroke_size(const SkPaint& paint, const SkMatrix& matrix) {
739 SkASSERT(matrix.rectStaysRect());
740 SkASSERT(SkPaint::kFill_Style != paint.getStyle());
741
742 SkVector size;
743 SkPoint pt = { paint.getStrokeWidth(), paint.getStrokeWidth() };
744 matrix.mapVectors(&size, &pt, 1);
745 return SkPoint::Make(SkScalarAbs(size.fX), SkScalarAbs(size.fY));
746 }
747
738 static bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix, 748 static bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix,
739 SkPoint* strokeSize) { 749 SkPoint* strokeSize) {
740 if (SkPaint::kMiter_Join != paint.getStrokeJoin() || 750 if (SkPaint::kMiter_Join != paint.getStrokeJoin() ||
741 paint.getStrokeMiter() < SK_ScalarSqrt2) { 751 paint.getStrokeMiter() < SK_ScalarSqrt2) {
742 return false; 752 return false;
743 } 753 }
744 754
745 SkASSERT(matrix.rectStaysRect()); 755 *strokeSize = compute_stroke_size(paint, matrix);
746 SkPoint pt = { paint.getStrokeWidth(), paint.getStrokeWidth() };
747 matrix.mapVectors(strokeSize, &pt, 1);
748 strokeSize->fX = SkScalarAbs(strokeSize->fX);
749 strokeSize->fY = SkScalarAbs(strokeSize->fY);
750 return true; 756 return true;
751 } 757 }
752 758
753 SkDraw::RectType SkDraw::ComputeRectType(const SkPaint& paint, 759 SkDraw::RectType SkDraw::ComputeRectType(const SkPaint& paint,
754 const SkMatrix& matrix, 760 const SkMatrix& matrix,
755 SkPoint* strokeSize) { 761 SkPoint* strokeSize) {
756 RectType rtype; 762 RectType rtype;
757 const SkScalar width = paint.getStrokeWidth(); 763 const SkScalar width = paint.getStrokeWidth();
758 const bool zeroWidth = (0 == width); 764 const bool zeroWidth = (0 == width);
759 SkPaint::Style style = paint.getStyle(); 765 SkPaint::Style style = paint.getStyle();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 draw.fMatrix = matrix; 821 draw.fMatrix = matrix;
816 } 822 }
817 SkPath tmp; 823 SkPath tmp;
818 tmp.addRect(prePaintRect); 824 tmp.addRect(prePaintRect);
819 tmp.setFillType(SkPath::kWinding_FillType); 825 tmp.setFillType(SkPath::kWinding_FillType);
820 draw.drawPath(tmp, paint, NULL, true); 826 draw.drawPath(tmp, paint, NULL, true);
821 return; 827 return;
822 } 828 }
823 829
824 SkRect devRect; 830 SkRect devRect;
825 if (paintMatrix) { 831 const SkRect& paintRect = paintMatrix ? *postPaintRect : prePaintRect;
826 // skip the paintMatrix when transforming the rect by the CTM 832 // skip the paintMatrix when transforming the rect by the CTM
827 fMatrix->mapPoints(rect_points(devRect), rect_points(*postPaintRect), 2) ; 833 fMatrix->mapPoints(rect_points(devRect), rect_points(paintRect), 2);
828 } else {
829 fMatrix->mapPoints(rect_points(devRect), rect_points(prePaintRect), 2);
830 }
831 // transform rect into devRect
832 devRect.sort(); 834 devRect.sort();
833 835
834 // look for the quick exit, before we build a blitter 836 // look for the quick exit, before we build a blitter
835 SkIRect ir = devRect.roundOut(); 837 SkRect bbox = devRect;
836 if (paint.getStyle() != SkPaint::kFill_Style) { 838 if (paint.getStyle() != SkPaint::kFill_Style) {
837 // extra space for hairlines 839 // extra space for hairlines
838 if (paint.getStrokeWidth() == 0) { 840 if (paint.getStrokeWidth() == 0) {
839 ir.outset(1, 1); 841 bbox.outset(1, 1);
840 } else { 842 } else {
841 SkScalar radius = SkScalarHalf(paint.getStrokeWidth()); 843 // For kStroke_RectType, strokeSize is already computed.
842 ir.outset(radius, radius); 844 const SkPoint& ssize = (kStroke_RectType == rtype)
845 ? strokeSize
846 : compute_stroke_size(paint, *fMatrix);
847 bbox.outset(SkScalarHalf(ssize.x()), SkScalarHalf(ssize.y()));
843 } 848 }
844 } 849 }
850
851 SkIRect ir = bbox.roundOut();
845 if (fRC->quickReject(ir)) { 852 if (fRC->quickReject(ir)) {
846 return; 853 return;
847 } 854 }
848 855
849 SkDeviceLooper looper(*fBitmap, *fRC, ir, paint.isAntiAlias()); 856 SkDeviceLooper looper(*fBitmap, *fRC, ir, paint.isAntiAlias());
850 while (looper.next()) { 857 while (looper.next()) {
851 SkRect localDevRect; 858 SkRect localDevRect;
852 looper.mapRect(&localDevRect, devRect); 859 looper.mapRect(&localDevRect, devRect);
853 SkMatrix localMatrix; 860 SkMatrix localMatrix;
854 looper.mapMatrix(&localMatrix, *matrix); 861 looper.mapMatrix(&localMatrix, *matrix);
(...skipping 1536 matching lines...) Expand 10 before | Expand all | Expand 10 after
2391 mask->fImage = SkMask::AllocImage(size); 2398 mask->fImage = SkMask::AllocImage(size);
2392 memset(mask->fImage, 0, mask->computeImageSize()); 2399 memset(mask->fImage, 0, mask->computeImageSize());
2393 } 2400 }
2394 2401
2395 if (SkMask::kJustComputeBounds_CreateMode != mode) { 2402 if (SkMask::kJustComputeBounds_CreateMode != mode) {
2396 draw_into_mask(*mask, devPath, style); 2403 draw_into_mask(*mask, devPath, style);
2397 } 2404 }
2398 2405
2399 return true; 2406 return true;
2400 } 2407 }
OLDNEW
« no previous file with comments | « gyp/tests.gypi ('k') | tests/RectTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698