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

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

Issue 1893433002: In SkDraw::drawRect, use SkPath for huge rects. Base URL: https://skia.googlesource.com/skia@fixed-assert
Patch Set: Created 4 years, 8 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 | « src/core/SkAAClip.cpp ('k') | src/core/SkRasterClip.h » ('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 #define __STDC_LIMIT_MACROS 7 #define __STDC_LIMIT_MACROS
8 8
9 #include "SkDraw.h" 9 #include "SkDraw.h"
10 #include "SkBlitter.h" 10 #include "SkBlitter.h"
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 } 789 }
790 790
791 static const SkPoint* rect_points(const SkRect& r) { 791 static const SkPoint* rect_points(const SkRect& r) {
792 return SkTCast<const SkPoint*>(&r); 792 return SkTCast<const SkPoint*>(&r);
793 } 793 }
794 794
795 static SkPoint* rect_points(SkRect& r) { 795 static SkPoint* rect_points(SkRect& r) {
796 return SkTCast<SkPoint*>(&r); 796 return SkTCast<SkPoint*>(&r);
797 } 797 }
798 798
799 namespace {
800
801 void drawRectAsPath(const SkDraw& origDraw, const SkMatrix* matrix, const SkRect & prePaintRect, const SkPaint& paint) {
802 SkDraw draw(origDraw);
803 draw.fMatrix = matrix;
804 SkPath tmp;
805 tmp.addRect(prePaintRect);
806 tmp.setFillType(SkPath::kWinding_FillType);
807 draw.drawPath(tmp, paint, nullptr, true);
808 }
809
810 } // namespace
811
799 void SkDraw::drawRect(const SkRect& prePaintRect, const SkPaint& paint, 812 void SkDraw::drawRect(const SkRect& prePaintRect, const SkPaint& paint,
800 const SkMatrix* paintMatrix, const SkRect* postPaintRect) const { 813 const SkMatrix* paintMatrix, const SkRect* postPaintRect) const {
801 SkDEBUGCODE(this->validate();) 814 SkDEBUGCODE(this->validate();)
802 815
803 // nothing to draw 816 // nothing to draw
804 if (fRC->isEmpty()) { 817 if (fRC->isEmpty()) {
805 return; 818 return;
806 } 819 }
807 820
808 const SkMatrix* matrix; 821 const SkMatrix* matrix;
809 SkMatrix combinedMatrixStorage; 822 SkMatrix combinedMatrixStorage;
810 if (paintMatrix) { 823 if (paintMatrix) {
811 SkASSERT(postPaintRect); 824 SkASSERT(postPaintRect);
812 combinedMatrixStorage.setConcat(*fMatrix, *paintMatrix); 825 combinedMatrixStorage.setConcat(*fMatrix, *paintMatrix);
813 matrix = &combinedMatrixStorage; 826 matrix = &combinedMatrixStorage;
814 } else { 827 } else {
815 SkASSERT(!postPaintRect); 828 SkASSERT(!postPaintRect);
816 matrix = fMatrix; 829 matrix = fMatrix;
817 } 830 }
818 831
819 SkPoint strokeSize; 832 SkPoint strokeSize;
820 RectType rtype = ComputeRectType(paint, *fMatrix, &strokeSize); 833 RectType rtype = ComputeRectType(paint, *fMatrix, &strokeSize);
821 834
822 if (kPath_RectType == rtype) { 835 if (kPath_RectType == rtype) {
823 SkDraw draw(*this); 836 drawRectAsPath(*this, matrix, prePaintRect, paint);
824 if (paintMatrix) {
825 draw.fMatrix = matrix;
826 }
827 SkPath tmp;
828 tmp.addRect(prePaintRect);
829 tmp.setFillType(SkPath::kWinding_FillType);
830 draw.drawPath(tmp, paint, nullptr, true);
831 return; 837 return;
832 } 838 }
833 839
834 SkRect devRect; 840 SkRect devRect;
835 const SkRect& paintRect = paintMatrix ? *postPaintRect : prePaintRect; 841 const SkRect& paintRect = paintMatrix ? *postPaintRect : prePaintRect;
836 // skip the paintMatrix when transforming the rect by the CTM 842 // skip the paintMatrix when transforming the rect by the CTM
837 fMatrix->mapPoints(rect_points(devRect), rect_points(paintRect), 2); 843 fMatrix->mapPoints(rect_points(devRect), rect_points(paintRect), 2);
838 devRect.sort(); 844 devRect.sort();
839 845
840 // look for the quick exit, before we build a blitter 846 // look for the quick exit, before we build a blitter
841 SkRect bbox = devRect; 847 SkRect bbox = devRect;
842 if (paint.getStyle() != SkPaint::kFill_Style) { 848 if (paint.getStyle() != SkPaint::kFill_Style) {
843 // extra space for hairlines 849 // extra space for hairlines
844 if (paint.getStrokeWidth() == 0) { 850 if (paint.getStrokeWidth() == 0) {
845 bbox.outset(1, 1); 851 bbox.outset(1, 1);
846 } else { 852 } else {
847 // For kStroke_RectType, strokeSize is already computed. 853 // For kStroke_RectType, strokeSize is already computed.
848 const SkPoint& ssize = (kStroke_RectType == rtype) 854 const SkPoint& ssize = (kStroke_RectType == rtype)
849 ? strokeSize 855 ? strokeSize
850 : compute_stroke_size(paint, *fMatrix); 856 : compute_stroke_size(paint, *fMatrix);
851 bbox.outset(SkScalarHalf(ssize.x()), SkScalarHalf(ssize.y())); 857 bbox.outset(SkScalarHalf(ssize.x()), SkScalarHalf(ssize.y()));
852 } 858 }
853 } 859 }
854 860
861 // If bbox is larger than the largest SkIRect, use drawRectAsPath.
862 if (!bbox.canRound()) {
863 drawRectAsPath(*this, matrix, prePaintRect, paint);
864 return;
865 }
866
855 SkIRect ir = bbox.roundOut(); 867 SkIRect ir = bbox.roundOut();
856 if (fRC->quickReject(ir)) { 868 if (fRC->quickReject(ir)) {
857 return; 869 return;
858 } 870 }
859 871
860 SkDeviceLooper looper(fDst, *fRC, ir, paint.isAntiAlias()); 872 SkDeviceLooper looper(fDst, *fRC, ir, paint.isAntiAlias());
861 while (looper.next()) { 873 while (looper.next()) {
862 SkRect localDevRect; 874 SkRect localDevRect;
863 looper.mapRect(&localDevRect, devRect); 875 looper.mapRect(&localDevRect, devRect);
864 SkMatrix localMatrix; 876 SkMatrix localMatrix;
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2068 mask->fImage = SkMask::AllocImage(size); 2080 mask->fImage = SkMask::AllocImage(size);
2069 memset(mask->fImage, 0, mask->computeImageSize()); 2081 memset(mask->fImage, 0, mask->computeImageSize());
2070 } 2082 }
2071 2083
2072 if (SkMask::kJustComputeBounds_CreateMode != mode) { 2084 if (SkMask::kJustComputeBounds_CreateMode != mode) {
2073 draw_into_mask(*mask, devPath, style); 2085 draw_into_mask(*mask, devPath, style);
2074 } 2086 }
2075 2087
2076 return true; 2088 return true;
2077 } 2089 }
OLDNEW
« no previous file with comments | « src/core/SkAAClip.cpp ('k') | src/core/SkRasterClip.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698