| 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" | 11 #include "GrStrokeRectBatch.h" |
| 12 | 12 |
| 13 #include "SkStrokeRec.h" | 13 #include "SkStrokeRec.h" |
| 14 | 14 |
| 15 static GrBatch* create_stroke_aa_batch(GrColor color, | 15 static GrDrawBatch* create_stroke_aa_batch(GrColor color, |
| 16 const SkMatrix& viewMatrix, | 16 const SkMatrix& viewMatrix, |
| 17 const SkRect& devOutside, | 17 const SkRect& devOutside, |
| 18 const SkRect& devOutsideAssist, | 18 const SkRect& devOutsideAssist, |
| 19 const SkRect& devInside, | 19 const SkRect& devInside, |
| 20 bool miterStroke) { | 20 bool miterStroke) { |
| 21 GrAAStrokeRectBatch::Geometry geometry; | 21 GrAAStrokeRectBatch::Geometry geometry; |
| 22 geometry.fColor = color; | 22 geometry.fColor = color; |
| 23 geometry.fDevOutside = devOutside; | 23 geometry.fDevOutside = devOutside; |
| 24 geometry.fDevOutsideAssist = devOutsideAssist; | 24 geometry.fDevOutsideAssist = devOutsideAssist; |
| 25 geometry.fDevInside = devInside; | 25 geometry.fDevInside = devInside; |
| 26 geometry.fMiterStroke = miterStroke; | 26 geometry.fMiterStroke = miterStroke; |
| 27 | 27 |
| 28 return GrAAStrokeRectBatch::Create(geometry, viewMatrix); | 28 return GrAAStrokeRectBatch::Create(geometry, viewMatrix); |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace GrRectBatchFactory { | 31 namespace GrRectBatchFactory { |
| 32 | 32 |
| 33 | 33 GrDrawBatch* CreateStrokeBW(GrColor color, |
| 34 GrBatch* CreateStrokeBW(GrColor color, | 34 const SkMatrix& viewMatrix, |
| 35 const SkMatrix& viewMatrix, | 35 const SkRect& rect, |
| 36 const SkRect& rect, | 36 SkScalar strokeWidth, |
| 37 SkScalar strokeWidth, | 37 bool snapToPixelCenters) { |
| 38 bool snapToPixelCenters) { | |
| 39 GrStrokeRectBatch::Geometry geometry; | 38 GrStrokeRectBatch::Geometry geometry; |
| 40 geometry.fColor = color; | 39 geometry.fColor = color; |
| 41 geometry.fViewMatrix = viewMatrix; | 40 geometry.fViewMatrix = viewMatrix; |
| 42 geometry.fRect = rect; | 41 geometry.fRect = rect; |
| 43 geometry.fStrokeWidth = strokeWidth; | 42 geometry.fStrokeWidth = strokeWidth; |
| 44 return GrStrokeRectBatch::Create(geometry, snapToPixelCenters); | 43 return GrStrokeRectBatch::Create(geometry, snapToPixelCenters); |
| 45 } | 44 } |
| 46 | 45 |
| 47 GrBatch* CreateStrokeAA(GrColor color, | 46 GrDrawBatch* CreateStrokeAA(GrColor color, |
| 48 const SkMatrix& viewMatrix, | 47 const SkMatrix& viewMatrix, |
| 49 const SkRect& rect, | 48 const SkRect& rect, |
| 50 const SkRect& devRect, | 49 const SkRect& devRect, |
| 51 const SkStrokeRec& stroke) { | 50 const SkStrokeRec& stroke) { |
| 52 SkVector devStrokeSize; | 51 SkVector devStrokeSize; |
| 53 SkScalar width = stroke.getWidth(); | 52 SkScalar width = stroke.getWidth(); |
| 54 if (width > 0) { | 53 if (width > 0) { |
| 55 devStrokeSize.set(width, width); | 54 devStrokeSize.set(width, width); |
| 56 viewMatrix.mapVectors(&devStrokeSize, 1); | 55 viewMatrix.mapVectors(&devStrokeSize, 1); |
| 57 devStrokeSize.setAbs(devStrokeSize); | 56 devStrokeSize.setAbs(devStrokeSize); |
| 58 } else { | 57 } else { |
| 59 devStrokeSize.set(SK_Scalar1, SK_Scalar1); | 58 devStrokeSize.set(SK_Scalar1, SK_Scalar1); |
| 60 } | 59 } |
| 61 | 60 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // edge, while vertex number of inner edge is 4, the same as miter-stroke. | 95 // edge, while vertex number of inner edge is 4, the same as miter-stroke. |
| 97 if (!miterStroke) { | 96 if (!miterStroke) { |
| 98 devOutside.inset(0, ry); | 97 devOutside.inset(0, ry); |
| 99 devOutsideAssist.outset(0, ry); | 98 devOutsideAssist.outset(0, ry); |
| 100 } | 99 } |
| 101 | 100 |
| 102 return create_stroke_aa_batch(color, viewMatrix, devOutside, devOutsideAssis
t, devInside, | 101 return create_stroke_aa_batch(color, viewMatrix, devOutside, devOutsideAssis
t, devInside, |
| 103 miterStroke); | 102 miterStroke); |
| 104 } | 103 } |
| 105 | 104 |
| 106 GrBatch* CreateFillNestedRectsAA(GrColor color, | 105 GrDrawBatch* CreateFillNestedRectsAA(GrColor color, |
| 107 const SkMatrix& viewMatrix, | 106 const SkMatrix& viewMatrix, |
| 108 const SkRect rects[2]) { | 107 const SkRect rects[2]) { |
| 109 SkASSERT(viewMatrix.rectStaysRect()); | 108 SkASSERT(viewMatrix.rectStaysRect()); |
| 110 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); | 109 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); |
| 111 | 110 |
| 112 SkRect devOutside, devInside; | 111 SkRect devOutside, devInside; |
| 113 viewMatrix.mapRect(&devOutside, rects[0]); | 112 viewMatrix.mapRect(&devOutside, rects[0]); |
| 114 viewMatrix.mapRect(&devInside, rects[1]); | 113 viewMatrix.mapRect(&devInside, rects[1]); |
| 115 | 114 |
| 116 if (devInside.isEmpty()) { | 115 if (devInside.isEmpty()) { |
| 117 return CreateFillAA(color, viewMatrix, devOutside, devOutside); | 116 return CreateFillAA(color, viewMatrix, devOutside, devOutside); |
| 118 } | 117 } |
| 119 | 118 |
| 120 return create_stroke_aa_batch(color, viewMatrix, devOutside, devOutside, dev
Inside, true); | 119 return create_stroke_aa_batch(color, viewMatrix, devOutside, devOutside, dev
Inside, true); |
| 121 } | 120 } |
| 122 | 121 |
| 123 }; | 122 }; |
| OLD | NEW |