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" |
11 #include "GrStrokeRectBatch.h" | |
12 | 11 |
13 #include "SkStrokeRec.h" | 12 #include "SkStrokeRec.h" |
14 | 13 |
15 static GrDrawBatch* create_stroke_aa_batch(GrColor color, | |
16 const SkMatrix& viewMatrix, | |
17 const SkRect& devOutside, | |
18 const SkRect& devOutsideAssist, | |
19 const SkRect& devInside, | |
20 bool miterStroke) { | |
21 GrAAStrokeRectBatch::Geometry geometry; | |
22 geometry.fColor = color; | |
23 geometry.fDevOutside = devOutside; | |
24 geometry.fDevOutsideAssist = devOutsideAssist; | |
25 geometry.fDevInside = devInside; | |
26 geometry.fMiterStroke = miterStroke; | |
27 | |
28 return GrAAStrokeRectBatch::Create(geometry, viewMatrix); | |
29 } | |
30 | |
31 namespace GrRectBatchFactory { | 14 namespace GrRectBatchFactory { |
32 | 15 |
33 GrDrawBatch* CreateNonAAStroke(GrColor color, | |
34 const SkMatrix& viewMatrix, | |
35 const SkRect& rect, | |
36 SkScalar strokeWidth, | |
37 bool snapToPixelCenters) { | |
38 GrStrokeRectBatch::Geometry geometry; | |
39 geometry.fColor = color; | |
40 geometry.fViewMatrix = viewMatrix; | |
41 geometry.fRect = rect; | |
42 geometry.fStrokeWidth = strokeWidth; | |
43 return GrStrokeRectBatch::Create(geometry, snapToPixelCenters); | |
44 } | |
45 | |
46 GrDrawBatch* CreateAAStroke(GrColor color, | 16 GrDrawBatch* CreateAAStroke(GrColor color, |
47 const SkMatrix& viewMatrix, | 17 const SkMatrix& viewMatrix, |
48 const SkRect& rect, | 18 const SkRect& rect, |
49 const SkRect& devRect, | 19 const SkRect& devRect, |
50 const SkStrokeRec& stroke) { | 20 const SkStrokeRec& stroke) { |
51 SkVector devStrokeSize; | 21 SkVector devStrokeSize; |
52 SkScalar width = stroke.getWidth(); | 22 SkScalar width = stroke.getWidth(); |
53 if (width > 0) { | 23 if (width > 0) { |
54 devStrokeSize.set(width, width); | 24 devStrokeSize.set(width, width); |
55 viewMatrix.mapVectors(&devStrokeSize, 1); | 25 viewMatrix.mapVectors(&devStrokeSize, 1); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 SkRect devOutsideAssist(devRect); | 61 SkRect devOutsideAssist(devRect); |
92 | 62 |
93 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist) | 63 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist) |
94 // to draw the outer of the rect. Because there are 8 vertices on the outer | 64 // to draw the outer of the rect. Because there are 8 vertices on the outer |
95 // edge, while vertex number of inner edge is 4, the same as miter-stroke. | 65 // edge, while vertex number of inner edge is 4, the same as miter-stroke. |
96 if (!miterStroke) { | 66 if (!miterStroke) { |
97 devOutside.inset(0, ry); | 67 devOutside.inset(0, ry); |
98 devOutsideAssist.outset(0, ry); | 68 devOutsideAssist.outset(0, ry); |
99 } | 69 } |
100 | 70 |
101 return create_stroke_aa_batch(color, viewMatrix, devOutside, devOutsideAssis
t, devInside, | 71 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside
Assist, devInside, |
102 miterStroke); | 72 miterStroke); |
103 } | 73 } |
104 | 74 |
105 GrDrawBatch* CreateAAFillNestedRects(GrColor color, | 75 GrDrawBatch* CreateAAFillNestedRects(GrColor color, |
106 const SkMatrix& viewMatrix, | 76 const SkMatrix& viewMatrix, |
107 const SkRect rects[2]) { | 77 const SkRect rects[2]) { |
108 SkASSERT(viewMatrix.rectStaysRect()); | 78 SkASSERT(viewMatrix.rectStaysRect()); |
109 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); | 79 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); |
110 | 80 |
111 SkRect devOutside, devInside; | 81 SkRect devOutside, devInside; |
112 viewMatrix.mapRect(&devOutside, rects[0]); | 82 viewMatrix.mapRect(&devOutside, rects[0]); |
113 viewMatrix.mapRect(&devInside, rects[1]); | 83 viewMatrix.mapRect(&devInside, rects[1]); |
114 | 84 |
115 if (devInside.isEmpty()) { | 85 if (devInside.isEmpty()) { |
116 return CreateAAFill(color, viewMatrix, devOutside, devOutside); | 86 return CreateAAFill(color, viewMatrix, devOutside, devOutside); |
117 } | 87 } |
118 | 88 |
119 return create_stroke_aa_batch(color, viewMatrix, devOutside, devOutside, dev
Inside, true); | 89 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside
, devInside, true); |
120 } | 90 } |
121 | 91 |
122 }; | 92 }; |
OLD | NEW |