blob: d265ac20c2fc5190d874b5d45ace9a9adb0f3708 [file] [log] [blame]
Chris Dalton7ae272f2021-06-10 11:45:14 -06001/*
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
Robert Phillips62bd6332021-08-26 09:56:55 -04008#ifndef PathTessellateOp_DEFINED
9#define PathTessellateOp_DEFINED
Chris Dalton7ae272f2021-06-10 11:45:14 -060010
11#include "src/gpu/ops/GrDrawOp.h"
12#include "src/gpu/tessellate/shaders/GrTessellationShader.h"
13
14class GrPathTessellator;
15
Robert Phillips62bd6332021-08-26 09:56:55 -040016namespace skgpu::v1 {
17
Chris Dalton7ae272f2021-06-10 11:45:14 -060018// Tessellates a path directly to the color buffer, using one single render pass. This currently
19// only works for convex paths.
Robert Phillips62bd6332021-08-26 09:56:55 -040020class PathTessellateOp final : public GrDrawOp {
Chris Dalton7ae272f2021-06-10 11:45:14 -060021private:
22 DEFINE_OP_CLASS_ID
23
Robert Phillips62bd6332021-08-26 09:56:55 -040024 PathTessellateOp(const SkMatrix& viewMatrix, const SkPath& path, GrPaint&& paint,
25 GrAAType aaType, const GrUserStencilSettings* stencil,
26 const SkRect& drawBounds)
Chris Dalton7ae272f2021-06-10 11:45:14 -060027 : GrDrawOp(ClassID())
28 , fViewMatrix(viewMatrix)
29 , fPath(path)
30 , fAAType(aaType)
31 , fStencil(stencil)
32 , fColor(paint.getColor4f())
33 , fProcessors(std::move(paint)) {
Chris Daltonbaae2dd2021-06-25 14:52:49 -060034 SkASSERT(!fPath.isInverseFillType());
35 this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo);
Chris Dalton7ae272f2021-06-10 11:45:14 -060036 }
37
Robert Phillips62bd6332021-08-26 09:56:55 -040038 const char* name() const override { return "PathTessellateOp"; }
Chris Dalton7ae272f2021-06-10 11:45:14 -060039 bool usesMSAA() const override { return fAAType == GrAAType::kMSAA; }
Robert Phillips294723d2021-06-17 09:23:58 -040040 void visitProxies(const GrVisitProxyFunc&) const override;
Chris Dalton7ae272f2021-06-10 11:45:14 -060041 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override;
42 bool usesStencil() const override { return !fStencil->isUnused(); }
43
44 void prepareTessellator(const GrTessellationShader::ProgramArgs&, GrAppliedClip&& clip);
45
46 void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*,
47 const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override;
48 void onPrepare(GrOpFlushState*) override;
49 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
50
51 const SkMatrix fViewMatrix;
52 const SkPath fPath;
53 const GrAAType fAAType;
54 const GrUserStencilSettings* const fStencil;
55 SkPMColor4f fColor;
56 GrProcessorSet fProcessors;
57
58 // Decided during prepareTessellator.
59 GrPathTessellator* fTessellator = nullptr;
60 const GrProgramInfo* fTessellationProgram = nullptr;
61
62 friend class GrOp; // For ctor.
63};
64
Robert Phillips62bd6332021-08-26 09:56:55 -040065} // namespace skgpu::v1
66
67#endif // PathTessellateOp_DEFINED