blob: 2780ef456800cdb2fb6903c6a8ba185e46cb2982 [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
Chris Dalton031d76b2021-06-08 16:32:00 -06008#ifndef GrPathStencilCoverOp_DEFINED
9#define GrPathStencilCoverOp_DEFINED
Chris Dalton70a0d2c2021-01-26 12:01:21 -070010
11#include "src/gpu/ops/GrDrawOp.h"
Chris Dalton8a1bbaa2021-07-28 14:43:07 -060012#include "src/gpu/tessellate/GrPathTessellator.h"
Robert Phillips832f3fb2021-08-18 13:05:15 -040013#include "src/gpu/tessellate/GrTessTypes.h"
Chris Dalton3b412782021-06-01 13:40:03 -060014#include "src/gpu/tessellate/shaders/GrTessellationShader.h"
Chris Dalton70a0d2c2021-01-26 12:01:21 -070015
Chris Dalton031d76b2021-06-08 16:32:00 -060016// Draws paths using a standard Redbook "stencil then cover" method. Curves get linearized by either
Chris Dalton57ab06c2021-04-22 12:57:28 -060017// GPU tessellation shaders or indirect draws. This Op doesn't apply analytic AA, so it requires
18// MSAA if AA is desired.
Chris Dalton031d76b2021-06-08 16:32:00 -060019class GrPathStencilCoverOp : public GrDrawOp {
Chris Dalton70a0d2c2021-01-26 12:01:21 -070020private:
21 DEFINE_OP_CLASS_ID
22
Chris Dalton8a1bbaa2021-07-28 14:43:07 -060023 using PathDrawList = GrPathTessellator::PathDrawList;
24
Chris Daltonbaae2dd2021-06-25 14:52:49 -060025 // If the path is inverse filled, drawBounds must be the entire backing store dimensions of the
26 // render target.
Chris Dalton8a1bbaa2021-07-28 14:43:07 -060027 GrPathStencilCoverOp(SkArenaAlloc* arena,
28 const SkMatrix& viewMatrix,
29 const SkPath& path,
30 GrPaint&& paint,
31 GrAAType aaType,
Robert Phillips832f3fb2021-08-18 13:05:15 -040032 GrTessellationPathFlags pathFlags,
Chris Daltonbaae2dd2021-06-25 14:52:49 -060033 const SkRect& drawBounds)
Chris Dalton70a0d2c2021-01-26 12:01:21 -070034 : GrDrawOp(ClassID())
Chris Dalton8a1bbaa2021-07-28 14:43:07 -060035 , fPathDrawList(arena->make<PathDrawList>(viewMatrix, path))
36 , fTotalCombinedPathVerbCnt(path.countVerbs())
37 , fPathCount(1)
Chris Dalton917f9192021-06-08 14:32:37 -060038 , fPathFlags(pathFlags)
Chris Dalton8a1bbaa2021-07-28 14:43:07 -060039 , fAAType(aaType)
40 , fColor(paint.getColor4f())
41 , fProcessors(std::move(paint)) {
42 this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo);
43 SkDEBUGCODE(fOriginalDrawBounds = drawBounds;)
44 }
45
46 // Constructs a GrPathStencilCoverOp from an existing draw list.
47 // FIXME: The only user of this method is the atlas. We should move the GrProgramInfos into
48 // GrPathTessellator so the atlas can use that directly instead of going through this class.
49 GrPathStencilCoverOp(const PathDrawList* pathDrawList,
50 int totalCombinedVerbCnt,
51 int pathCount,
52 GrPaint&& paint,
53 GrAAType aaType,
Robert Phillips832f3fb2021-08-18 13:05:15 -040054 GrTessellationPathFlags pathFlags,
Chris Dalton8a1bbaa2021-07-28 14:43:07 -060055 const SkRect& drawBounds)
56 : GrDrawOp(ClassID())
57 , fPathDrawList(pathDrawList)
58 , fTotalCombinedPathVerbCnt(totalCombinedVerbCnt)
59 , fPathCount(pathCount)
60 , fPathFlags(pathFlags)
Chris Dalton70a0d2c2021-01-26 12:01:21 -070061 , fAAType(aaType)
62 , fColor(paint.getColor4f())
63 , fProcessors(std::move(paint)) {
Chris Daltonbaae2dd2021-06-25 14:52:49 -060064 this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo);
65 SkDEBUGCODE(fOriginalDrawBounds = drawBounds;)
Chris Dalton70a0d2c2021-01-26 12:01:21 -070066 }
67
Chris Dalton031d76b2021-06-08 16:32:00 -060068 const char* name() const override { return "GrPathStencilCoverOp"; }
Robert Phillips294723d2021-06-17 09:23:58 -040069 void visitProxies(const GrVisitProxyFunc&) const override;
Chris Dalton70a0d2c2021-01-26 12:01:21 -070070 FixedFunctionFlags fixedFunctionFlags() const override;
Chris Dalton57ab06c2021-04-22 12:57:28 -060071 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override;
Chris Dalton70a0d2c2021-01-26 12:01:21 -070072
Chris Dalton8a1bbaa2021-07-28 14:43:07 -060073 // All paths in fPathDrawList are required to have the same fill type.
74 SkPathFillType pathFillType() const {
75 return fPathDrawList->fPath.getFillType();
76 }
77
Chris Dalton70a0d2c2021-01-26 12:01:21 -070078 // Chooses the rendering method we will use and creates the corresponding tessellator and
Chris Dalton031d76b2021-06-08 16:32:00 -060079 // stencil/cover programs.
Chris Dalton2f733ec2021-06-01 12:11:57 -060080 void prePreparePrograms(const GrTessellationShader::ProgramArgs&, GrAppliedClip&& clip);
Chris Dalton70a0d2c2021-01-26 12:01:21 -070081
82 void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*,
John Stiles52cb1d02021-06-02 11:58:05 -040083 const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override;
Chris Dalton70a0d2c2021-01-26 12:01:21 -070084 void onPrepare(GrOpFlushState*) override;
85 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
86
Chris Dalton8a1bbaa2021-07-28 14:43:07 -060087 const PathDrawList* fPathDrawList;
88 const int fTotalCombinedPathVerbCnt;
89 const int fPathCount;
Robert Phillips832f3fb2021-08-18 13:05:15 -040090 const GrTessellationPathFlags fPathFlags;
Chris Dalton70a0d2c2021-01-26 12:01:21 -070091 const GrAAType fAAType;
92 SkPMColor4f fColor;
93 GrProcessorSet fProcessors;
Chris Daltonbaae2dd2021-06-25 14:52:49 -060094 SkDEBUGCODE(SkRect fOriginalDrawBounds;)
Chris Dalton70a0d2c2021-01-26 12:01:21 -070095
96 // Decided during prePreparePrograms.
97 GrPathTessellator* fTessellator = nullptr;
98 const GrProgramInfo* fStencilFanProgram = nullptr;
99 const GrProgramInfo* fStencilPathProgram = nullptr;
Chris Dalton031d76b2021-06-08 16:32:00 -0600100 const GrProgramInfo* fCoverBBoxProgram = nullptr;
Chris Dalton70a0d2c2021-01-26 12:01:21 -0700101
102 // Filled during onPrepare.
103 sk_sp<const GrBuffer> fFanBuffer;
104 int fFanBaseVertex = 0;
105 int fFanVertexCount = 0;
106
Chris Daltonc91dd692021-05-24 15:04:47 -0600107 sk_sp<const GrBuffer> fBBoxBuffer;
108 int fBBoxBaseInstance = 0;
109
Chris Daltona05ccc32021-06-29 19:42:13 -0600110 // Only used if sk_VertexID is not supported.
111 sk_sp<const GrGpuBuffer> fBBoxVertexBufferIfNoIDSupport;
112
Chris Dalton70a0d2c2021-01-26 12:01:21 -0700113 friend class GrOp; // For ctor.
114};
115
116#endif