OLD | NEW |
---|---|
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 Loading... | |
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) { | |
robertphillips
2015/09/21 17:12:44
Just use devRect.centerX() ?
joshualitt
2015/09/21 19:51:25
Acknowledged.
| |
62 SkScalar midPoint = devRect.width() / 2.0f + devRect.fLeft; | |
63 devInside.fLeft = devInside.fRight = midPoint; | |
64 | |
robertphillips
2015/09/21 17:12:44
Just use devRect.centerY() ?
joshualitt
2015/09/21 19:51:25
Acknowledged.
| |
65 midPoint = devRect.height() / 2.0f + devRect.fTop; | |
66 devInside.fTop = devInside.fBottom = midPoint; | |
67 } | |
68 | |
61 SkRect devOutsideAssist(devRect); | 69 SkRect devOutsideAssist(devRect); |
62 | 70 |
63 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist) | 71 // 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 | 72 // 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. | 73 // edge, while vertex number of inner edge is 4, the same as miter-stroke. |
66 if (!miterStroke) { | 74 if (!miterStroke) { |
67 devOutside.inset(0, ry); | 75 devOutside.inset(0, ry); |
68 devOutsideAssist.outset(0, ry); | 76 devOutsideAssist.outset(0, ry); |
69 } | 77 } |
70 | 78 |
71 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside Assist, devInside, | 79 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside Assist, devInside, |
72 miterStroke); | 80 miterStroke, degenerate); |
73 } | 81 } |
74 | 82 |
75 GrDrawBatch* CreateAAFillNestedRects(GrColor color, | 83 GrDrawBatch* CreateAAFillNestedRects(GrColor color, |
76 const SkMatrix& viewMatrix, | 84 const SkMatrix& viewMatrix, |
77 const SkRect rects[2]) { | 85 const SkRect rects[2]) { |
78 SkASSERT(viewMatrix.rectStaysRect()); | 86 SkASSERT(viewMatrix.rectStaysRect()); |
79 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); | 87 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); |
80 | 88 |
81 SkRect devOutside, devInside; | 89 SkRect devOutside, devInside; |
82 viewMatrix.mapRect(&devOutside, rects[0]); | 90 viewMatrix.mapRect(&devOutside, rects[0]); |
83 viewMatrix.mapRect(&devInside, rects[1]); | 91 viewMatrix.mapRect(&devInside, rects[1]); |
84 | 92 |
robertphillips
2015/09/21 17:12:44
Don't we want to get rid of this and pass 'true' t
joshualitt
2015/09/21 19:51:25
Acknowledged.
| |
85 if (devInside.isEmpty()) { | 93 if (devInside.isEmpty()) { |
86 return CreateAAFill(color, viewMatrix, devOutside, devOutside); | 94 return CreateAAFill(color, viewMatrix, devOutside, devOutside); |
87 } | 95 } |
88 | 96 |
89 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside , devInside, true); | 97 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside , devInside, true, |
98 false); | |
90 } | 99 } |
91 | 100 |
92 }; | 101 }; |
OLD | NEW |