1 /* 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 15 class 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 19 // MSAA if AA is desired. 20 class GrPathStencilFillOp : public GrDrawOp { 21 private: 22 DEFINE_OP_CLASS_ID 23 GrPathStencilFillOp(const SkMatrix & viewMatrix,const SkPath & path,GrPaint && paint,GrAAType aaType,GrTessellationPathRenderer::OpFlags opFlags)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::kNo, IsHairline::kNo); 36 } 37 name()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*, GrClampType) override; 42 43 // Chooses the rendering method we will use and creates the corresponding tessellator and 44 // stencil/fill programs. 45 void prePreparePrograms(const GrPathShader::ProgramArgs&, GrAppliedClip&& clip); 46 47 void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*, 48 const GrXferProcessor::DstProxyView&, GrXferBarrierFlags, 49 GrLoadOp colorLoadOp) override; 50 void onPrepare(GrOpFlushState*) override; 51 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; 52 53 const GrTessellationPathRenderer::OpFlags fOpFlags; 54 const SkMatrix fViewMatrix; 55 const SkPath fPath; 56 const GrAAType fAAType; 57 SkPMColor4f fColor; 58 GrProcessorSet fProcessors; 59 60 // Decided during prePreparePrograms. 61 GrPathTessellator* fTessellator = nullptr; 62 const GrProgramInfo* fStencilFanProgram = nullptr; 63 const GrProgramInfo* fStencilPathProgram = nullptr; 64 const GrProgramInfo* fFillBBoxProgram = nullptr; 65 66 // Filled during onPrepare. 67 sk_sp<const GrBuffer> fFanBuffer; 68 int fFanBaseVertex = 0; 69 int fFanVertexCount = 0; 70 71 friend class GrOp; // For ctor. 72 }; 73 74 #endif 75