Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 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 GrRectOpFactory_DEFINED |
| 9 | #define GrRectOpFactory_DEFINED |
| 10 | |
| 11 | #include "GrAAFillRectOp.h" |
| 12 | #include "GrAAStrokeRectOp.h" |
| 13 | #include "GrAnalyticRectOp.h" |
| 14 | #include "GrColor.h" |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 15 | #include "GrMeshDrawOp.h" |
Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 16 | #include "GrNonAAFillRectOp.h" |
| 17 | #include "GrNonAAStrokeRectOp.h" |
| 18 | #include "GrPaint.h" |
| 19 | #include "SkMatrix.h" |
| 20 | #include "SkRefCnt.h" |
Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 21 | |
| 22 | struct SkRect; |
| 23 | class SkStrokeRec; |
| 24 | |
| 25 | /** |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 26 | * A factory for returning GrDrawOps which can draw rectangles. |
Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 27 | */ |
| 28 | namespace GrRectOpFactory { |
| 29 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 30 | inline std::unique_ptr<GrMeshDrawOp> MakeNonAAFill(GrColor color, |
| 31 | const SkMatrix& viewMatrix, |
| 32 | const SkRect& rect, |
| 33 | const SkRect* localRect, |
| 34 | const SkMatrix* localMatrix) { |
Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 35 | if (viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPerspective())) { |
| 36 | return GrNonAAFillRectOp::MakeWithPerspective(color, viewMatrix, rect, localRect, |
| 37 | localMatrix); |
| 38 | } else { |
| 39 | return GrNonAAFillRectOp::Make(color, viewMatrix, rect, localRect, localMatrix); |
| 40 | } |
| 41 | } |
| 42 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 43 | inline std::unique_ptr<GrMeshDrawOp> MakeAAFill(const GrPaint& paint, |
| 44 | const SkMatrix& viewMatrix, |
| 45 | const SkRect& rect, |
| 46 | const SkRect& croppedRect, |
| 47 | const SkRect& devRect) { |
Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 48 | if (!paint.usesDistanceVectorField()) { |
| 49 | return GrAAFillRectOp::Make(paint.getColor(), viewMatrix, croppedRect, devRect); |
| 50 | } else { |
| 51 | return GrAnalyticRectOp::Make(paint.getColor(), viewMatrix, rect, croppedRect, devRect); |
| 52 | } |
| 53 | } |
| 54 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 55 | inline std::unique_ptr<GrMeshDrawOp> MakeAAFill(GrColor color, |
| 56 | const SkMatrix& viewMatrix, |
| 57 | const SkMatrix& localMatrix, |
| 58 | const SkRect& rect, |
| 59 | const SkRect& devRect) { |
Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 60 | return GrAAFillRectOp::Make(color, viewMatrix, localMatrix, rect, devRect); |
| 61 | } |
| 62 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 63 | inline std::unique_ptr<GrMeshDrawOp> MakeNonAAStroke(GrColor color, |
| 64 | const SkMatrix& viewMatrix, |
| 65 | const SkRect& rect, |
| 66 | const SkStrokeRec& strokeRec, |
| 67 | bool snapToPixelCenters) { |
Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 68 | return GrNonAAStrokeRectOp::Make(color, viewMatrix, rect, strokeRec, snapToPixelCenters); |
| 69 | } |
| 70 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 71 | inline std::unique_ptr<GrMeshDrawOp> MakeAAStroke(GrColor color, |
| 72 | const SkMatrix& viewMatrix, |
| 73 | const SkRect& rect, |
| 74 | const SkStrokeRec& stroke) { |
Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 75 | return GrAAStrokeRectOp::Make(color, viewMatrix, rect, stroke); |
| 76 | } |
| 77 | |
| 78 | // First rect is outer; second rect is inner |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 79 | std::unique_ptr<GrMeshDrawOp> MakeAAFillNestedRects(GrColor, const SkMatrix& viewMatrix, |
| 80 | const SkRect rects[2]); |
Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | #endif |