blob: f9e676245436a68dcc26c96eae623ad2eca7ac8f [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
8#ifndef GrStrokeOp_DEFINED
9#define GrStrokeOp_DEFINED
10
11#include "include/core/SkStrokeRec.h"
12#include "include/gpu/GrRecordingContext.h"
13#include "src/gpu/GrSTArenaList.h"
14#include "src/gpu/ops/GrDrawOp.h"
15
16class GrStrokeTessellateShader;
17
18// Base class for ops that render opaque, constant-color strokes by linearizing them into sorted
19// "parametric" and "radial" edges. See GrStrokeTessellateShader.
20class GrStrokeOp : public GrDrawOp {
21protected:
22 // The provided matrix must be a similarity matrix for the time being. This is so we can
23 // bootstrap this Op on top of GrStrokeGeometry with minimal modifications.
24 //
25 // Patches can overlap, so until a stencil technique is implemented, the provided paint must be
26 // a constant blended color.
27 GrStrokeOp(uint32_t classID, GrAAType, const SkMatrix&, const SkStrokeRec&, const SkPath&,
28 GrPaint&&);
29
30 const char* name() const override { return "GrStrokeTessellateOp"; }
31 void visitProxies(const VisitProxyFunc& fn) const override { fProcessors.visitProxies(fn); }
32 FixedFunctionFlags fixedFunctionFlags() const override;
33 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
34 bool hasMixedSampledCoverage, GrClampType) override;
35 CombineResult onCombineIfPossible(GrOp*, SkArenaAlloc*, const GrCaps&) override;
36
Chris Dalton55abaf52020-12-08 10:25:13 -070037 void prePreparePrograms(SkArenaAlloc* arena, GrStrokeTessellateShader*,
38 const GrSurfaceProxyView&, GrAppliedClip&&,
39 const GrXferProcessor::DstProxyView&, GrXferBarrierFlags,
40 GrLoadOp colorLoadOp, const GrCaps&);
Chris Dalton0e543092020-11-03 14:09:16 -070041
42 static float NumCombinedSegments(float numParametricSegments, float numRadialSegments) {
43 // The first and last edges are shared by both the parametric and radial sets of edges, so
44 // the total number of edges is:
45 //
46 // numCombinedEdges = numParametricEdges + numRadialEdges - 2
47 //
48 // It's also important to differentiate between the number of edges and segments in a strip:
49 //
50 // numCombinedSegments = numCombinedEdges - 1
51 //
52 // So the total number of segments in the combined strip is:
53 //
54 // numCombinedSegments = numParametricEdges + numRadialEdges - 2 - 1
55 // = numParametricSegments + 1 + numRadialSegments + 1 - 2 - 1
56 // = numParametricSegments + numRadialSegments - 1
57 //
58 return numParametricSegments + numRadialSegments - 1;
59 }
60
61 static float NumParametricSegments(float numCombinedSegments, float numRadialSegments) {
62 // numCombinedSegments = numParametricSegments + numRadialSegments - 1.
63 // (See num_combined_segments()).
64 return std::max(numCombinedSegments + 1 - numRadialSegments, 0.f);
65 }
66
67 const GrAAType fAAType;
68 const SkMatrix fViewMatrix;
69 const SkStrokeRec fStroke;
70 // Controls the number of parametric segments the tessellator adds for each curve. The
71 // tessellator will add enough parametric segments so that the center of each one falls within
72 // 1/parametricIntolerance local path units from the true curve.
73 const float fParametricIntolerance;
74 // Controls the number of radial segments the tessellator adds for each curve. The tessellator
75 // will add this number of radial segments for each radian of rotation, in order to guarantee
76 // smoothness.
77 const float fNumRadialSegmentsPerRadian;
78 SkPMColor4f fColor;
Chris Dalton55abaf52020-12-08 10:25:13 -070079 bool fNeedsStencil = false;
Chris Dalton0e543092020-11-03 14:09:16 -070080 GrProcessorSet fProcessors;
81
82 GrSTArenaList<SkPath> fPathList;
Chris Dalton7b807262020-12-10 10:22:50 -070083 int fTotalCombinedVerbCnt = 0;
84 int fTotalConicWeightCnt = 0;
Chris Dalton0e543092020-11-03 14:09:16 -070085
Chris Dalton55abaf52020-12-08 10:25:13 -070086 const GrProgramInfo* fStencilProgram = nullptr;
87 const GrProgramInfo* fFillProgram = nullptr;
Chris Dalton0e543092020-11-03 14:09:16 -070088};
89
90#endif