blob: d1f19e4221679430f00e3cea209d8d7ecea6b116 [file] [log] [blame]
Chris Dalton70a0d2c2021-01-26 12:01:21 -07001/*
2 * Copyright 2021 Google LLC.
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 GrPathStencilFillOp_DEFINED
9#define GrPathStencilFillOp_DEFINED
10
11#include "src/gpu/ops/GrDrawOp.h"
12#include "src/gpu/tessellate/GrPathShader.h"
13#include "src/gpu/tessellate/GrTessellationPathRenderer.h"
14
15class GrPathTessellator;
16
17// Draws paths using a standard Redbook "stencil then fill" method. Curves get linearized by either
18// GPU tessellation shaders or indirect draws. This Op doesn't apply analytic AA, so it requires a
19// render target that supports either MSAA or mixed samples if AA is desired.
20class GrPathStencilFillOp : public GrDrawOp {
21private:
22 DEFINE_OP_CLASS_ID
23
24 GrPathStencilFillOp(const SkMatrix& viewMatrix, const SkPath& path, GrPaint&& paint,
25 GrAAType aaType, GrTessellationPathRenderer::OpFlags opFlags)
26 : GrDrawOp(ClassID())
27 , fOpFlags(opFlags)
28 , fViewMatrix(viewMatrix)
29 , fPath(path)
30 , fAAType(aaType)
31 , fColor(paint.getColor4f())
32 , fProcessors(std::move(paint)) {
33 SkRect devBounds;
34 fViewMatrix.mapRect(&devBounds, path.getBounds());
35 this->setBounds(devBounds, HasAABloat(GrAAType::kCoverage == fAAType), IsHairline::kNo);
36 }
37
38 const char* name() const override { return "GrPathStencilFillOp"; }
39 void visitProxies(const VisitProxyFunc& fn) const override;
40 FixedFunctionFlags fixedFunctionFlags() const override;
41 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
42 bool hasMixedSampledCoverage, GrClampType) override;
43
44 // Chooses the rendering method we will use and creates the corresponding tessellator and
45 // stencil/fill programs.
46 void prePreparePrograms(const GrPathShader::ProgramArgs&, GrAppliedClip&& clip);
47
48 void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*,
49 const GrXferProcessor::DstProxyView&, GrXferBarrierFlags,
50 GrLoadOp colorLoadOp) override;
51 void onPrepare(GrOpFlushState*) override;
52 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
53
54 const GrTessellationPathRenderer::OpFlags fOpFlags;
55 const SkMatrix fViewMatrix;
56 const SkPath fPath;
57 const GrAAType fAAType;
58 SkPMColor4f fColor;
59 GrProcessorSet fProcessors;
60
61 // Decided during prePreparePrograms.
62 GrPathTessellator* fTessellator = nullptr;
63 const GrProgramInfo* fStencilFanProgram = nullptr;
64 const GrProgramInfo* fStencilPathProgram = nullptr;
65 const GrProgramInfo* fFillBBoxProgram = nullptr;
66
67 // Filled during onPrepare.
68 sk_sp<const GrBuffer> fFanBuffer;
69 int fFanBaseVertex = 0;
70 int fFanVertexCount = 0;
71
72 friend class GrOp; // For ctor.
73};
74
75#endif