blob: 4a63d0aa4d6b4fe0bdb326859d4fa4c7bab0ec8e [file] [log] [blame]
Chris Dalton0e543092020-11-03 14:09:16 -07001/*
2 * Copyright 2020 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 Dalton05007df2021-02-04 00:24:52 -07008#ifndef GrStrokeTessellateOp_DEFINED
9#define GrStrokeTessellateOp_DEFINED
Chris Dalton0e543092020-11-03 14:09:16 -070010
11#include "include/core/SkStrokeRec.h"
Chris Dalton0e543092020-11-03 14:09:16 -070012#include "src/gpu/GrSTArenaList.h"
Chris Dalton22241002021-02-04 09:47:40 -070013#include "src/gpu/ops/GrMeshDrawOp.h"
14#include "src/gpu/tessellate/GrPathShader.h"
Chris Dalton0e543092020-11-03 14:09:16 -070015
Chris Dalton22241002021-02-04 09:47:40 -070016class GrRecordingContext;
17
18// Prepares GPU data for, and then draws a stroke's tessellated geometry.
19class GrStrokeTessellator {
20public:
21 // Called before draw(). Prepares GPU buffers containing the geometry to tessellate.
22 virtual void prepare(GrMeshDrawOp::Target*, const SkMatrix&, const GrSTArenaList<SkPath>&,
23 const SkStrokeRec&, int totalCombinedVerbCnt) = 0;
24
25 // Issues draw calls for the tessellated stroie. The caller is responsible for binding its
26 // desired pipeline ahead of time.
27 virtual void draw(GrOpFlushState*) const = 0;
28
29 virtual ~GrStrokeTessellator() {}
30};
Chris Dalton0e543092020-11-03 14:09:16 -070031
32// Base class for ops that render opaque, constant-color strokes by linearizing them into sorted
33// "parametric" and "radial" edges. See GrStrokeTessellateShader.
Chris Dalton05007df2021-02-04 00:24:52 -070034class GrStrokeTessellateOp : public GrDrawOp {
Chris Dalton22241002021-02-04 09:47:40 -070035public:
Chris Dalton0e543092020-11-03 14:09:16 -070036 // The provided matrix must be a similarity matrix for the time being. This is so we can
37 // bootstrap this Op on top of GrStrokeGeometry with minimal modifications.
38 //
39 // Patches can overlap, so until a stencil technique is implemented, the provided paint must be
40 // a constant blended color.
Chris Dalton05007df2021-02-04 00:24:52 -070041 GrStrokeTessellateOp(GrAAType, const SkMatrix&, const SkPath&, const SkStrokeRec&, GrPaint&&);
Chris Dalton0e543092020-11-03 14:09:16 -070042
Chris Dalton22241002021-02-04 09:47:40 -070043protected:
44 DEFINE_OP_CLASS_ID
45
Chris Dalton05007df2021-02-04 00:24:52 -070046 const char* name() const override { return "GrStrokeTessellateOp"; }
Chris Daltonb0643342020-12-15 01:04:12 -070047 void visitProxies(const VisitProxyFunc& fn) const override;
Chris Dalton0e543092020-11-03 14:09:16 -070048 FixedFunctionFlags fixedFunctionFlags() const override;
49 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
50 bool hasMixedSampledCoverage, GrClampType) override;
51 CombineResult onCombineIfPossible(GrOp*, SkArenaAlloc*, const GrCaps&) override;
52
Chris Dalton22241002021-02-04 09:47:40 -070053 // Creates the tessellator and the stencil/fill program(s) we will use with it.
54 void prePrepareTessellator(GrPathShader::ProgramArgs&&, GrAppliedClip&&);
Chris Dalton0e543092020-11-03 14:09:16 -070055
Chris Dalton22241002021-02-04 09:47:40 -070056 void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*,
57 const GrXferProcessor::DstProxyView&, GrXferBarrierFlags,
58 GrLoadOp colorLoadOp) override;
Chris Dalton0e543092020-11-03 14:09:16 -070059
Chris Dalton22241002021-02-04 09:47:40 -070060 void onPrepare(GrOpFlushState*) override;
Chris Dalton0e543092020-11-03 14:09:16 -070061
Chris Dalton22241002021-02-04 09:47:40 -070062 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
Chris Dalton06b52ad2020-12-15 10:01:35 -070063
Chris Dalton0e543092020-11-03 14:09:16 -070064 const GrAAType fAAType;
65 const SkMatrix fViewMatrix;
66 const SkStrokeRec fStroke;
Chris Dalton0e543092020-11-03 14:09:16 -070067 SkPMColor4f fColor;
Chris Dalton55abaf52020-12-08 10:25:13 -070068 bool fNeedsStencil = false;
Chris Dalton0e543092020-11-03 14:09:16 -070069 GrProcessorSet fProcessors;
70
71 GrSTArenaList<SkPath> fPathList;
Chris Dalton7b807262020-12-10 10:22:50 -070072 int fTotalCombinedVerbCnt = 0;
Chris Dalton22241002021-02-04 09:47:40 -070073 bool fHasConics = false;
Chris Dalton0e543092020-11-03 14:09:16 -070074
Chris Dalton22241002021-02-04 09:47:40 -070075 GrStrokeTessellator* fTessellator = nullptr;
76 const GrProgramInfo* fStencilProgram = nullptr; // Only used if the stroke has transparency.
Chris Dalton55abaf52020-12-08 10:25:13 -070077 const GrProgramInfo* fFillProgram = nullptr;
Chris Dalton0e543092020-11-03 14:09:16 -070078};
79
80#endif