blob: 19bce7fd2c9723b7be12ca6f17c21fc18cd5ef9b [file] [log] [blame]
Brian Salomon6a639042016-12-14 11:08:17 -05001/*
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 Salomon649a3412017-03-09 13:50:43 -050015#include "GrMeshDrawOp.h"
Brian Salomon6a639042016-12-14 11:08:17 -050016#include "GrNonAAFillRectOp.h"
17#include "GrNonAAStrokeRectOp.h"
18#include "GrPaint.h"
19#include "SkMatrix.h"
20#include "SkRefCnt.h"
Brian Salomon6a639042016-12-14 11:08:17 -050021
22struct SkRect;
23class SkStrokeRec;
24
25/**
Brian Salomon53e4c3c2016-12-21 11:38:53 -050026 * A factory for returning GrDrawOps which can draw rectangles.
Brian Salomon6a639042016-12-14 11:08:17 -050027 */
28namespace GrRectOpFactory {
29
Brian Salomon649a3412017-03-09 13:50:43 -050030inline std::unique_ptr<GrMeshDrawOp> MakeNonAAFill(GrColor color,
31 const SkMatrix& viewMatrix,
32 const SkRect& rect,
33 const SkRect* localRect,
34 const SkMatrix* localMatrix) {
Brian Salomon6a639042016-12-14 11:08:17 -050035 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 Salomon649a3412017-03-09 13:50:43 -050043inline 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 Salomon6a639042016-12-14 11:08:17 -050048 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 Salomon649a3412017-03-09 13:50:43 -050055inline std::unique_ptr<GrMeshDrawOp> MakeAAFill(GrColor color,
56 const SkMatrix& viewMatrix,
57 const SkMatrix& localMatrix,
58 const SkRect& rect,
59 const SkRect& devRect) {
Brian Salomon6a639042016-12-14 11:08:17 -050060 return GrAAFillRectOp::Make(color, viewMatrix, localMatrix, rect, devRect);
61}
62
Brian Salomon649a3412017-03-09 13:50:43 -050063inline std::unique_ptr<GrMeshDrawOp> MakeNonAAStroke(GrColor color,
64 const SkMatrix& viewMatrix,
65 const SkRect& rect,
66 const SkStrokeRec& strokeRec,
67 bool snapToPixelCenters) {
Brian Salomon6a639042016-12-14 11:08:17 -050068 return GrNonAAStrokeRectOp::Make(color, viewMatrix, rect, strokeRec, snapToPixelCenters);
69}
70
Brian Salomon649a3412017-03-09 13:50:43 -050071inline std::unique_ptr<GrMeshDrawOp> MakeAAStroke(GrColor color,
72 const SkMatrix& viewMatrix,
73 const SkRect& rect,
74 const SkStrokeRec& stroke) {
Brian Salomon6a639042016-12-14 11:08:17 -050075 return GrAAStrokeRectOp::Make(color, viewMatrix, rect, stroke);
76}
77
78// First rect is outer; second rect is inner
Brian Salomon649a3412017-03-09 13:50:43 -050079std::unique_ptr<GrMeshDrawOp> MakeAAFillNestedRects(GrColor, const SkMatrix& viewMatrix,
80 const SkRect rects[2]);
Brian Salomon6a639042016-12-14 11:08:17 -050081};
82
83#endif