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" 15#include "GrMeshDrawOp.h" 16#include "GrNonAAFillRectOp.h" 17#include "GrNonAAStrokeRectOp.h" 18#include "GrPaint.h" 19#include "SkMatrix.h" 20#include "SkRefCnt.h" 21 22struct SkRect; 23class SkStrokeRec; 24 25/** 26 * A factory for returning GrDrawOps which can draw rectangles. 27 */ 28namespace GrRectOpFactory { 29 30inline std::unique_ptr<GrMeshDrawOp> MakeNonAAFill(GrColor color, 31 const SkMatrix& viewMatrix, 32 const SkRect& rect, 33 const SkRect* localRect, 34 const SkMatrix* localMatrix) { 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 43inline std::unique_ptr<GrMeshDrawOp> MakeAAFill(const GrPaint& paint, 44 const SkMatrix& viewMatrix, 45 const SkRect& rect, 46 const SkRect& croppedRect, 47 const SkRect& devRect) { 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 55inline std::unique_ptr<GrMeshDrawOp> MakeAAFill(GrColor color, 56 const SkMatrix& viewMatrix, 57 const SkMatrix& localMatrix, 58 const SkRect& rect, 59 const SkRect& devRect) { 60 return GrAAFillRectOp::Make(color, viewMatrix, localMatrix, rect, devRect); 61} 62 63inline std::unique_ptr<GrMeshDrawOp> MakeNonAAStroke(GrColor color, 64 const SkMatrix& viewMatrix, 65 const SkRect& rect, 66 const SkStrokeRec& strokeRec, 67 bool snapToPixelCenters) { 68 return GrNonAAStrokeRectOp::Make(color, viewMatrix, rect, strokeRec, snapToPixelCenters); 69} 70 71inline std::unique_ptr<GrMeshDrawOp> MakeAAStroke(GrColor color, 72 const SkMatrix& viewMatrix, 73 const SkRect& rect, 74 const SkStrokeRec& stroke) { 75 return GrAAStrokeRectOp::Make(color, viewMatrix, rect, stroke); 76} 77 78// First rect is outer; second rect is inner 79std::unique_ptr<GrMeshDrawOp> MakeAAFillNestedRects(GrColor, const SkMatrix& viewMatrix, 80 const SkRect rects[2]); 81}; 82 83#endif 84