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

Side by Side Diff: src/gpu/batches/GrRectBatchFactory.cpp

Issue 1359453002: Fix for degenerate stroke rect (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
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 "GrRectBatchFactory.h" 8 #include "GrRectBatchFactory.h"
9 9
10 #include "GrAAStrokeRectBatch.h" 10 #include "GrAAStrokeRectBatch.h"
(...skipping 15 matching lines...) Expand all
26 devStrokeSize.setAbs(devStrokeSize); 26 devStrokeSize.setAbs(devStrokeSize);
27 } else { 27 } else {
28 devStrokeSize.set(SK_Scalar1, SK_Scalar1); 28 devStrokeSize.set(SK_Scalar1, SK_Scalar1);
29 } 29 }
30 30
31 const SkScalar dx = devStrokeSize.fX; 31 const SkScalar dx = devStrokeSize.fX;
32 const SkScalar dy = devStrokeSize.fY; 32 const SkScalar dy = devStrokeSize.fY;
33 const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf); 33 const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf);
34 const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf); 34 const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf);
35 35
36 SkScalar spare;
37 {
38 SkScalar w = devRect.width() - dx;
39 SkScalar h = devRect.height() - dy;
40 spare = SkTMin(w, h);
41 }
42
43 SkRect devOutside(devRect); 36 SkRect devOutside(devRect);
44 devOutside.outset(rx, ry); 37 devOutside.outset(rx, ry);
45 38
46 bool miterStroke = true; 39 bool miterStroke = true;
47 // For hairlines, make bevel and round joins appear the same as mitered ones . 40 // For hairlines, make bevel and round joins appear the same as mitered ones .
48 // small miter limit means right angles show bevel... 41 // small miter limit means right angles show bevel...
49 if ((width > 0) && (stroke.getJoin() != SkPaint::kMiter_Join || 42 if ((width > 0) && (stroke.getJoin() != SkPaint::kMiter_Join ||
50 stroke.getMiter() < SK_ScalarSqrt2)) { 43 stroke.getMiter() < SK_ScalarSqrt2)) {
51 miterStroke = false; 44 miterStroke = false;
52 } 45 }
53 46
54 if (spare <= 0 && miterStroke) {
55 return CreateAAFill(color, viewMatrix, devOutside, devOutside);
56 }
57
58 SkRect devInside(devRect); 47 SkRect devInside(devRect);
59 devInside.inset(rx, ry); 48 devInside.inset(rx, ry);
60 49
50 // If we have a degenerate stroking rect(ie the stroke is larger than inner rect) then we
51 // make a degenerate inside rect to avoid double hitting. We will also jam all of the points
52 // together when we render these rects.
53 SkScalar spare;
54 {
55 SkScalar w = devRect.width() - dx;
56 SkScalar h = devRect.height() - dy;
57 spare = SkTMin(w, h);
58 }
59
60 bool degenerate = spare <= 0;
61 if (degenerate) {
62 devInside.fLeft = devInside.fRight = devRect.centerX();
63 devInside.fTop = devInside.fBottom = devRect.centerY();
64 }
65
61 SkRect devOutsideAssist(devRect); 66 SkRect devOutsideAssist(devRect);
62 67
63 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist) 68 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist)
64 // to draw the outer of the rect. Because there are 8 vertices on the outer 69 // to draw the outer of the rect. Because there are 8 vertices on the outer
65 // edge, while vertex number of inner edge is 4, the same as miter-stroke. 70 // edge, while vertex number of inner edge is 4, the same as miter-stroke.
66 if (!miterStroke) { 71 if (!miterStroke) {
67 devOutside.inset(0, ry); 72 devOutside.inset(0, ry);
68 devOutsideAssist.outset(0, ry); 73 devOutsideAssist.outset(0, ry);
69 } 74 }
70 75
71 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside Assist, devInside, 76 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside Assist, devInside,
72 miterStroke); 77 miterStroke, degenerate);
73 } 78 }
74 79
75 GrDrawBatch* CreateAAFillNestedRects(GrColor color, 80 GrDrawBatch* CreateAAFillNestedRects(GrColor color,
76 const SkMatrix& viewMatrix, 81 const SkMatrix& viewMatrix,
77 const SkRect rects[2]) { 82 const SkRect rects[2]) {
78 SkASSERT(viewMatrix.rectStaysRect()); 83 SkASSERT(viewMatrix.rectStaysRect());
79 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); 84 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty());
80 85
81 SkRect devOutside, devInside; 86 SkRect devOutside, devInside;
82 viewMatrix.mapRect(&devOutside, rects[0]); 87 viewMatrix.mapRect(&devOutside, rects[0]);
83 viewMatrix.mapRect(&devInside, rects[1]); 88 viewMatrix.mapRect(&devInside, rects[1]);
84 89
robertphillips 2015/09/21 19:57:39 false -> devInside.isEmpty() ?
85 if (devInside.isEmpty()) { 90 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside , devInside, true,
86 return CreateAAFill(color, viewMatrix, devOutside, devOutside); 91 false);
87 }
88
89 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside , devInside, true);
90 } 92 }
91 93
92 }; 94 };
OLDNEW
« src/gpu/batches/GrAAStrokeRectBatch.cpp ('K') | « src/gpu/batches/GrAAStrokeRectBatch.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698