1/*
2 * Copyright 2018 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 GrFillRectOp_DEFINED
9#define GrFillRectOp_DEFINED
10
11#include "include/private/GrTypesPriv.h"
12#include "src/gpu/GrRenderTargetContext.h"
13#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
14
15class GrDrawOp;
16class GrPaint;
17class GrQuad;
18class GrRecordingContext;
19struct GrUserStencilSettings;
20class SkMatrix;
21struct SkRect;
22
23/**
24 * A set of factory functions for drawing filled rectangles either coverage-antialiased, or
25 * non-antialiased. The non-antialiased ops can be used with MSAA. As with other GrDrawOp factories,
26 * the GrPaint is only consumed by these methods if a valid op is returned. If null is returned then
27 * the paint is unmodified and may still be used.
28 */
29class GrFillRectOp {
30public:
31 using InputFlags = GrSimpleMeshDrawOpHelper::InputFlags;
32
33 static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
34 GrPaint&& paint,
35 GrAAType aaType,
36 DrawQuad* quad,
37 const GrUserStencilSettings* stencil = nullptr,
38 InputFlags = InputFlags::kNone);
39
40 // Utility function to create a non-AA rect transformed by view. This is used commonly enough
41 // in testing and GMs that manage ops without going through GrRTC that it's worth the
42 // convenience.
43 static std::unique_ptr<GrDrawOp> MakeNonAARect(GrRecordingContext* context,
44 GrPaint&& paint,
45 const SkMatrix& view,
46 const SkRect& rect,
47 const GrUserStencilSettings* stencil = nullptr);
48
49 // Bulk API for drawing quads with a single op
50 // TODO(michaelludwig) - remove if the bulk API is not useful for SkiaRenderer
51 static void AddFillRectOps(GrRenderTargetContext*,
52 const GrClip* clip,
53 GrRecordingContext*,
54 GrPaint&&,
55 GrAAType,
56 const SkMatrix& viewMatrix,
57 const GrRenderTargetContext::QuadSetEntry quads[],
58 int quadCount,
59 const GrUserStencilSettings* = nullptr);
60
61#if GR_TEST_UTILS
62 static uint32_t ClassID();
63#endif
64
65private:
66 // Create a GrFillRectOp that uses as many quads as possible from 'quads' w/o exceeding
67 // any index buffer size limits.
68 static std::unique_ptr<GrDrawOp> MakeOp(GrRecordingContext*,
69 GrPaint&&,
70 GrAAType,
71 const SkMatrix& viewMatrix,
72 const GrRenderTargetContext::QuadSetEntry quads[],
73 int quadCount,
74 const GrUserStencilSettings*,
75 int* numConsumed);
76};
77
78#endif // GrFillRectOp_DEFINED
79