1 /* 2 * Copyright 2015 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrRectBatchFactory_DEFINED 9 #define GrRectBatchFactory_DEFINED 10 11 #include "GrAAFillRectBatch.h" 12 #include "GrAAStrokeRectBatch.h" 13 #include "GrColor.h" 14 #include "GrNonAAFillRectBatch.h" 15 #include "GrNonAAStrokeRectBatch.h" 16 #include "SkMatrix.h" 17 18 class GrBatch; 19 struct SkRect; 20 class SkStrokeRec; 21 22 /* 23 * A factory for returning batches which can draw rectangles. 24 */ 25 namespace GrRectBatchFactory { 26 27 inline GrDrawBatch* CreateNonAAFill(GrColor color, 28 const SkMatrix& viewMatrix, 29 const SkRect& rect, 30 const SkRect* localRect, 31 const SkMatrix* localMatrix) { 32 if (viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPerspective())) { 33 return GrNonAAFillRectBatch::CreateWithPerspective(color, viewMatrix, rect, localRect, 34 localMatrix); 35 } else { 36 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, localRect, localMatrix); 37 } 38 } 39 40 inline GrDrawBatch* CreateAAFill(GrColor color, 41 const SkMatrix& viewMatrix, 42 const SkRect& rect, 43 const SkRect& devRect) { 44 return GrAAFillRectBatch::Create(color, viewMatrix, rect, devRect); 45 } 46 47 inline GrDrawBatch* CreateAAFill(GrColor color, 48 const SkMatrix& viewMatrix, 49 const SkMatrix& localMatrix, 50 const SkRect& rect, 51 const SkRect& devRect) { 52 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRect); 53 } 54 55 inline GrDrawBatch* CreateNonAAStroke(GrColor color, 56 const SkMatrix& viewMatrix, 57 const SkRect& rect, 58 SkScalar strokeWidth, 59 bool snapToPixelCenters) { 60 return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeWidth, snapToPixelCenters); 61 } 62 63 inline GrDrawBatch* CreateAAStroke(GrColor color, 64 const SkMatrix& viewMatrix, 65 const SkRect& rect, 66 const SkStrokeRec& stroke) { 67 return GrAAStrokeRectBatch::Create(color, viewMatrix, rect, stroke); 68 } 69 70 // First rect is outer; second rect is inner 71 GrDrawBatch* CreateAAFillNestedRects(GrColor, 72 const SkMatrix& viewMatrix, 73 const SkRect rects[2]); 74 75 }; 76 77 #endif 78