• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Google Inc.
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 #include "src/gpu/ganesh/ops/QuadPerEdgeAA.h"
9 
10 #include "src/base/SkVx.h"
11 #include "src/gpu/KeyBuilder.h"
12 #include "src/gpu/ganesh/GrCaps.h"
13 #include "src/gpu/ganesh/GrMeshDrawTarget.h"
14 #include "src/gpu/ganesh/GrResourceProvider.h"
15 #include "src/gpu/ganesh/SkGr.h"
16 #include "src/gpu/ganesh/geometry/GrQuadUtils.h"
17 #include "src/gpu/ganesh/glsl/GrGLSLColorSpaceXformHelper.h"
18 #include "src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h"
19 #include "src/gpu/ganesh/glsl/GrGLSLVarying.h"
20 #include "src/gpu/ganesh/glsl/GrGLSLVertexGeoBuilder.h"
21 
22 static_assert((int)GrQuadAAFlags::kLeft   == SkCanvas::kLeft_QuadAAFlag);
23 static_assert((int)GrQuadAAFlags::kTop    == SkCanvas::kTop_QuadAAFlag);
24 static_assert((int)GrQuadAAFlags::kRight  == SkCanvas::kRight_QuadAAFlag);
25 static_assert((int)GrQuadAAFlags::kBottom == SkCanvas::kBottom_QuadAAFlag);
26 static_assert((int)GrQuadAAFlags::kNone   == SkCanvas::kNone_QuadAAFlags);
27 static_assert((int)GrQuadAAFlags::kAll    == SkCanvas::kAll_QuadAAFlags);
28 
29 namespace skgpu::v1::QuadPerEdgeAA {
30 
31 namespace {
32 
33 using VertexSpec = skgpu::v1::QuadPerEdgeAA::VertexSpec;
34 using CoverageMode = skgpu::v1::QuadPerEdgeAA::CoverageMode;
35 using ColorType = skgpu::v1::QuadPerEdgeAA::ColorType;
36 
37 // Generic WriteQuadProc that can handle any VertexSpec. It writes the 4 vertices in triangle strip
38 // order, although the data per-vertex is dependent on the VertexSpec.
write_quad_generic(VertexWriter * vb,const VertexSpec & spec,const GrQuad * deviceQuad,const GrQuad * localQuad,const float coverage[4],const SkPMColor4f & color,const SkRect & geomSubset,const SkRect & texSubset)39 void write_quad_generic(VertexWriter* vb,
40                         const VertexSpec& spec,
41                         const GrQuad* deviceQuad,
42                         const GrQuad* localQuad,
43                         const float coverage[4],
44                         const SkPMColor4f& color,
45                         const SkRect& geomSubset,
46                         const SkRect& texSubset) {
47     static constexpr auto If = VertexWriter::If<float>;
48 
49     SkASSERT(!spec.hasLocalCoords() || localQuad);
50 
51     CoverageMode mode = spec.coverageMode();
52     for (int i = 0; i < 4; ++i) {
53         // save position, this is a float2 or float3 or float4 depending on the combination of
54         // perspective and coverage mode.
55         *vb << deviceQuad->x(i)
56             << deviceQuad->y(i)
57             << If(spec.deviceQuadType() == GrQuad::Type::kPerspective, deviceQuad->w(i))
58             << If(mode == CoverageMode::kWithPosition, coverage[i]);
59 
60         // save color
61         if (spec.hasVertexColors()) {
62             bool wide = spec.colorType() == ColorType::kFloat;
63             *vb << VertexColor(color * (mode == CoverageMode::kWithColor ? coverage[i] : 1), wide);
64         }
65 
66         // save local position
67         if (spec.hasLocalCoords()) {
68             *vb << localQuad->x(i)
69                 << localQuad->y(i)
70                 << If(spec.localQuadType() == GrQuad::Type::kPerspective, localQuad->w(i));
71         }
72 
73         // save the geometry subset
74         if (spec.requiresGeometrySubset()) {
75             *vb << geomSubset;
76         }
77 
78         // save the texture subset
79         if (spec.hasSubset()) {
80             *vb << texSubset;
81         }
82     }
83 }
84 
85 // Specialized WriteQuadProcs for particular VertexSpecs that show up frequently (determined
86 // experimentally through recorded GMs, SKPs, and SVGs, as well as SkiaRenderer's usage patterns):
87 
88 // 2D (XY), no explicit coverage, vertex color, no locals, no geometry subset, no texture subsetn
89 // This represents simple, solid color or shader, non-AA (or AA with cov. as alpha) rects.
write_2d_color(VertexWriter * vb,const VertexSpec & spec,const GrQuad * deviceQuad,const GrQuad * localQuad,const float coverage[4],const SkPMColor4f & color,const SkRect & geomSubset,const SkRect & texSubset)90 void write_2d_color(VertexWriter* vb,
91                     const VertexSpec& spec,
92                     const GrQuad* deviceQuad,
93                     const GrQuad* localQuad,
94                     const float coverage[4],
95                     const SkPMColor4f& color,
96                     const SkRect& geomSubset,
97                     const SkRect& texSubset) {
98     // Assert assumptions about VertexSpec
99     SkASSERT(spec.deviceQuadType() != GrQuad::Type::kPerspective);
100     SkASSERT(!spec.hasLocalCoords());
101     SkASSERT(spec.coverageMode() == CoverageMode::kNone ||
102              spec.coverageMode() == CoverageMode::kWithColor);
103     SkASSERT(spec.hasVertexColors());
104     SkASSERT(!spec.requiresGeometrySubset());
105     SkASSERT(!spec.hasSubset());
106     // We don't assert that localQuad == nullptr, since it is possible for FillRectOp to
107     // accumulate local coords conservatively (paint not trivial), and then after analysis realize
108     // the processors don't need local coordinates.
109 
110     bool wide = spec.colorType() == ColorType::kFloat;
111     for (int i = 0; i < 4; ++i) {
112         // If this is not coverage-with-alpha, make sure coverage == 1 so it doesn't do anything
113         SkASSERT(spec.coverageMode() == CoverageMode::kWithColor || coverage[i] == 1.f);
114         *vb << deviceQuad->x(i)
115             << deviceQuad->y(i)
116             << VertexColor(color * coverage[i], wide);
117     }
118 }
119 
120 // 2D (XY), no explicit coverage, UV locals, no color, no geometry subset, no texture subset
121 // This represents opaque, non AA, textured rects
write_2d_uv(VertexWriter * vb,const VertexSpec & spec,const GrQuad * deviceQuad,const GrQuad * localQuad,const float coverage[4],const SkPMColor4f & color,const SkRect & geomSubset,const SkRect & texSubset)122 void write_2d_uv(VertexWriter* vb,
123                  const VertexSpec& spec,
124                  const GrQuad* deviceQuad,
125                  const GrQuad* localQuad,
126                  const float coverage[4],
127                  const SkPMColor4f& color,
128                  const SkRect& geomSubset,
129                  const SkRect& texSubset) {
130     // Assert assumptions about VertexSpec
131     SkASSERT(spec.deviceQuadType() != GrQuad::Type::kPerspective);
132     SkASSERT(spec.hasLocalCoords() && spec.localQuadType() != GrQuad::Type::kPerspective);
133     SkASSERT(spec.coverageMode() == CoverageMode::kNone);
134     SkASSERT(!spec.hasVertexColors());
135     SkASSERT(!spec.requiresGeometrySubset());
136     SkASSERT(!spec.hasSubset());
137     SkASSERT(localQuad);
138 
139     for (int i = 0; i < 4; ++i) {
140         *vb << deviceQuad->x(i)
141             << deviceQuad->y(i)
142             << localQuad->x(i)
143             << localQuad->y(i);
144     }
145 }
146 
147 // 2D (XY), no explicit coverage, UV locals, vertex color, no geometry or texture subsets
148 // This represents transparent, non AA (or AA with cov. as alpha), textured rects
write_2d_color_uv(VertexWriter * vb,const VertexSpec & spec,const GrQuad * deviceQuad,const GrQuad * localQuad,const float coverage[4],const SkPMColor4f & color,const SkRect & geomSubset,const SkRect & texSubset)149 void write_2d_color_uv(VertexWriter* vb,
150                        const VertexSpec& spec,
151                        const GrQuad* deviceQuad,
152                        const GrQuad* localQuad,
153                        const float coverage[4],
154                        const SkPMColor4f& color,
155                        const SkRect& geomSubset,
156                        const SkRect& texSubset) {
157     // Assert assumptions about VertexSpec
158     SkASSERT(spec.deviceQuadType() != GrQuad::Type::kPerspective);
159     SkASSERT(spec.hasLocalCoords() && spec.localQuadType() != GrQuad::Type::kPerspective);
160     SkASSERT(spec.coverageMode() == CoverageMode::kNone ||
161              spec.coverageMode() == CoverageMode::kWithColor);
162     SkASSERT(spec.hasVertexColors());
163     SkASSERT(!spec.requiresGeometrySubset());
164     SkASSERT(!spec.hasSubset());
165     SkASSERT(localQuad);
166 
167     bool wide = spec.colorType() == ColorType::kFloat;
168     for (int i = 0; i < 4; ++i) {
169         // If this is not coverage-with-alpha, make sure coverage == 1 so it doesn't do anything
170         SkASSERT(spec.coverageMode() == CoverageMode::kWithColor || coverage[i] == 1.f);
171         *vb << deviceQuad->x(i)
172             << deviceQuad->y(i)
173             << VertexColor(color * coverage[i], wide)
174             << localQuad->x(i)
175             << localQuad->y(i);
176     }
177 }
178 
179 // 2D (XY), explicit coverage, UV locals, no color, no geometry subset, no texture subset
180 // This represents opaque, AA, textured rects
write_2d_cov_uv(VertexWriter * vb,const VertexSpec & spec,const GrQuad * deviceQuad,const GrQuad * localQuad,const float coverage[4],const SkPMColor4f & color,const SkRect & geomSubset,const SkRect & texSubset)181 void write_2d_cov_uv(VertexWriter* vb,
182                      const VertexSpec& spec,
183                      const GrQuad* deviceQuad,
184                      const GrQuad* localQuad,
185                      const float coverage[4],
186                      const SkPMColor4f& color,
187                      const SkRect& geomSubset,
188                      const SkRect& texSubset) {
189     // Assert assumptions about VertexSpec
190     SkASSERT(spec.deviceQuadType() != GrQuad::Type::kPerspective);
191     SkASSERT(spec.hasLocalCoords() && spec.localQuadType() != GrQuad::Type::kPerspective);
192     SkASSERT(spec.coverageMode() == CoverageMode::kWithPosition);
193     SkASSERT(!spec.hasVertexColors());
194     SkASSERT(!spec.requiresGeometrySubset());
195     SkASSERT(!spec.hasSubset());
196     SkASSERT(localQuad);
197 
198     for (int i = 0; i < 4; ++i) {
199         *vb << deviceQuad->x(i)
200             << deviceQuad->y(i)
201             << coverage[i]
202             << localQuad->x(i)
203             << localQuad->y(i);
204     }
205 }
206 
207 // NOTE: The three _strict specializations below match the non-strict uv functions above, except
208 // that they also write the UV subset. These are included to benefit SkiaRenderer, which must make
209 // use of both fast and strict constrained subsets. When testing _strict was not that common across
210 // GMS, SKPs, and SVGs but we have little visibility into actual SkiaRenderer statistics. If
211 // SkiaRenderer can avoid subsets more, these 3 functions should probably be removed for simplicity.
212 
213 // 2D (XY), no explicit coverage, UV locals, no color, tex subset but no geometry subset
214 // This represents opaque, non AA, textured rects with strict uv sampling
write_2d_uv_strict(VertexWriter * vb,const VertexSpec & spec,const GrQuad * deviceQuad,const GrQuad * localQuad,const float coverage[4],const SkPMColor4f & color,const SkRect & geomSubset,const SkRect & texSubset)215 void write_2d_uv_strict(VertexWriter* vb,
216                         const VertexSpec& spec,
217                         const GrQuad* deviceQuad,
218                         const GrQuad* localQuad,
219                         const float coverage[4],
220                         const SkPMColor4f& color,
221                         const SkRect& geomSubset,
222                         const SkRect& texSubset) {
223     // Assert assumptions about VertexSpec
224     SkASSERT(spec.deviceQuadType() != GrQuad::Type::kPerspective);
225     SkASSERT(spec.hasLocalCoords() && spec.localQuadType() != GrQuad::Type::kPerspective);
226     SkASSERT(spec.coverageMode() == CoverageMode::kNone);
227     SkASSERT(!spec.hasVertexColors());
228     SkASSERT(!spec.requiresGeometrySubset());
229     SkASSERT(spec.hasSubset());
230     SkASSERT(localQuad);
231 
232     for (int i = 0; i < 4; ++i) {
233         *vb << deviceQuad->x(i)
234             << deviceQuad->y(i)
235             << localQuad->x(i)
236             << localQuad->y(i)
237             << texSubset;
238     }
239 }
240 
241 // 2D (XY), no explicit coverage, UV locals, vertex color, tex subset but no geometry subset
242 // This represents transparent, non AA (or AA with cov. as alpha), textured rects with strict sample
write_2d_color_uv_strict(VertexWriter * vb,const VertexSpec & spec,const GrQuad * deviceQuad,const GrQuad * localQuad,const float coverage[4],const SkPMColor4f & color,const SkRect & geomSubset,const SkRect & texSubset)243 void write_2d_color_uv_strict(VertexWriter* vb,
244                               const VertexSpec& spec,
245                               const GrQuad* deviceQuad,
246                               const GrQuad* localQuad,
247                               const float coverage[4],
248                               const SkPMColor4f& color,
249                               const SkRect& geomSubset,
250                               const SkRect& texSubset) {
251     // Assert assumptions about VertexSpec
252     SkASSERT(spec.deviceQuadType() != GrQuad::Type::kPerspective);
253     SkASSERT(spec.hasLocalCoords() && spec.localQuadType() != GrQuad::Type::kPerspective);
254     SkASSERT(spec.coverageMode() == CoverageMode::kNone ||
255              spec.coverageMode() == CoverageMode::kWithColor);
256     SkASSERT(spec.hasVertexColors());
257     SkASSERT(!spec.requiresGeometrySubset());
258     SkASSERT(spec.hasSubset());
259     SkASSERT(localQuad);
260 
261     bool wide = spec.colorType() == ColorType::kFloat;
262     for (int i = 0; i < 4; ++i) {
263         // If this is not coverage-with-alpha, make sure coverage == 1 so it doesn't do anything
264         SkASSERT(spec.coverageMode() == CoverageMode::kWithColor || coverage[i] == 1.f);
265         *vb << deviceQuad->x(i)
266             << deviceQuad->y(i)
267             << VertexColor(color * coverage[i], wide)
268             << localQuad->x(i)
269             << localQuad->y(i)
270             << texSubset;
271     }
272 }
273 
274 // 2D (XY), explicit coverage, UV locals, no color, tex subset but no geometry subset
275 // This represents opaque, AA, textured rects with strict uv sampling
write_2d_cov_uv_strict(VertexWriter * vb,const VertexSpec & spec,const GrQuad * deviceQuad,const GrQuad * localQuad,const float coverage[4],const SkPMColor4f & color,const SkRect & geomSubset,const SkRect & texSubset)276 void write_2d_cov_uv_strict(VertexWriter* vb,
277                             const VertexSpec& spec,
278                             const GrQuad* deviceQuad,
279                             const GrQuad* localQuad,
280                             const float coverage[4],
281                             const SkPMColor4f& color,
282                             const SkRect& geomSubset,
283                             const SkRect& texSubset) {
284     // Assert assumptions about VertexSpec
285     SkASSERT(spec.deviceQuadType() != GrQuad::Type::kPerspective);
286     SkASSERT(spec.hasLocalCoords() && spec.localQuadType() != GrQuad::Type::kPerspective);
287     SkASSERT(spec.coverageMode() == CoverageMode::kWithPosition);
288     SkASSERT(!spec.hasVertexColors());
289     SkASSERT(!spec.requiresGeometrySubset());
290     SkASSERT(spec.hasSubset());
291     SkASSERT(localQuad);
292 
293     for (int i = 0; i < 4; ++i) {
294         *vb << deviceQuad->x(i)
295             << deviceQuad->y(i)
296             << coverage[i]
297             << localQuad->x(i)
298             << localQuad->y(i)
299             << texSubset;
300     }
301 }
302 
303 } // anonymous namespace
304 
CalcIndexBufferOption(GrAAType aa,int numQuads)305 IndexBufferOption CalcIndexBufferOption(GrAAType aa, int numQuads) {
306     if (aa == GrAAType::kCoverage) {
307         return IndexBufferOption::kPictureFramed;
308     } else if (numQuads > 1) {
309         return IndexBufferOption::kIndexedRects;
310     } else {
311         return IndexBufferOption::kTriStrips;
312     }
313 }
314 
315 // This is a more elaborate version of fitsInBytes() that allows "no color" for white
MinColorType(SkPMColor4f color)316 ColorType MinColorType(SkPMColor4f color) {
317     if (color == SK_PMColor4fWHITE) {
318         return ColorType::kNone;
319     } else {
320         return color.fitsInBytes() ? ColorType::kByte : ColorType::kFloat;
321     }
322 }
323 
324 ////////////////// Tessellator Implementation
325 
GetWriteQuadProc(const VertexSpec & spec)326 Tessellator::WriteQuadProc Tessellator::GetWriteQuadProc(const VertexSpec& spec) {
327     // All specialized writing functions requires 2D geometry and no geometry subset. This is not
328     // the same as just checking device type vs. kRectilinear since non-AA general 2D quads do not
329     // require a geometry subset and could then go through a fast path.
330     if (spec.deviceQuadType() != GrQuad::Type::kPerspective && !spec.requiresGeometrySubset()) {
331         CoverageMode mode = spec.coverageMode();
332         if (spec.hasVertexColors()) {
333             if (mode != CoverageMode::kWithPosition) {
334                 // Vertex colors, but no explicit coverage
335                 if (!spec.hasLocalCoords()) {
336                     // Non-UV with vertex colors (possibly with coverage folded into alpha)
337                     return write_2d_color;
338                 } else if (spec.localQuadType() != GrQuad::Type::kPerspective) {
339                     // UV locals with vertex colors (possibly with coverage-as-alpha)
340                     return spec.hasSubset() ? write_2d_color_uv_strict : write_2d_color_uv;
341                 }
342             }
343             // Else fall through; this is a spec that requires vertex colors and explicit coverage,
344             // which means it's anti-aliased and the FPs don't support coverage as alpha, or
345             // it uses 3D local coordinates.
346         } else if (spec.hasLocalCoords() && spec.localQuadType() != GrQuad::Type::kPerspective) {
347             if (mode == CoverageMode::kWithPosition) {
348                 // UV locals with explicit coverage
349                 return spec.hasSubset() ? write_2d_cov_uv_strict : write_2d_cov_uv;
350             } else {
351                 SkASSERT(mode == CoverageMode::kNone);
352                 return spec.hasSubset() ? write_2d_uv_strict : write_2d_uv;
353             }
354         }
355         // Else fall through to generic vertex function; this is a spec that has no vertex colors
356         // and [no|uvr] local coords, which doesn't happen often enough to warrant specialization.
357     }
358 
359     // Arbitrary spec hits the slow path
360     return write_quad_generic;
361 }
362 
Tessellator(const VertexSpec & spec,char * vertices)363 Tessellator::Tessellator(const VertexSpec& spec, char* vertices)
364         : fVertexSpec(spec)
365         , fVertexWriter{vertices}
366         , fWriteProc(Tessellator::GetWriteQuadProc(spec)) {}
367 
append(GrQuad * deviceQuad,GrQuad * localQuad,const SkPMColor4f & color,const SkRect & uvSubset,GrQuadAAFlags aaFlags)368 void Tessellator::append(GrQuad* deviceQuad, GrQuad* localQuad,
369                          const SkPMColor4f& color, const SkRect& uvSubset, GrQuadAAFlags aaFlags) {
370     // We allow Tessellator to be created with a null vertices pointer for convenience, but it is
371     // assumed it will never actually be used in those cases.
372     SkASSERT(fVertexWriter);
373     SkASSERT(deviceQuad->quadType() <= fVertexSpec.deviceQuadType());
374     SkASSERT(localQuad || !fVertexSpec.hasLocalCoords());
375     SkASSERT(!fVertexSpec.hasLocalCoords() || localQuad->quadType() <= fVertexSpec.localQuadType());
376 
377     static const float kFullCoverage[4] = {1.f, 1.f, 1.f, 1.f};
378     static const float kZeroCoverage[4] = {0.f, 0.f, 0.f, 0.f};
379     static const SkRect kIgnoredSubset = SkRect::MakeEmpty();
380 
381     if (fVertexSpec.usesCoverageAA()) {
382         SkASSERT(fVertexSpec.coverageMode() == CoverageMode::kWithColor ||
383                  fVertexSpec.coverageMode() == CoverageMode::kWithPosition);
384         // Must calculate inner and outer quadrilaterals for the vertex coverage ramps, and possibly
385         // a geometry subset if corners are not right angles
386         SkRect geomSubset;
387         if (fVertexSpec.requiresGeometrySubset()) {
388 #ifdef SK_USE_LEGACY_AA_QUAD_SUBSET
389             geomSubset = deviceQuad->bounds();
390             geomSubset.outset(0.5f, 0.5f); // account for AA expansion
391 #else
392             // Our GP code expects a 0.5 outset rect (coverage is computed as 0 at the values of
393             // the uniform). However, if we have quad edges that aren't supposed to be antialiased
394             // they may lie close to the bounds. So in that case we outset by an additional 0.5.
395             // This is a sort of backup clipping mechanism for cases where quad outsetting of nearly
396             // parallel edges produces long thin extrusions from the original geometry.
397             float outset = aaFlags == GrQuadAAFlags::kAll ? 0.5f : 1.f;
398             geomSubset = deviceQuad->bounds().makeOutset(outset, outset);
399 #endif
400         }
401 
402         if (aaFlags == GrQuadAAFlags::kNone) {
403             // Have to write the coverage AA vertex structure, but there's no math to be done for a
404             // non-aa quad batched into a coverage AA op.
405             fWriteProc(&fVertexWriter, fVertexSpec, deviceQuad, localQuad, kFullCoverage, color,
406                        geomSubset, uvSubset);
407             // Since we pass the same corners in, the outer vertex structure will have 0 area and
408             // the coverage interpolation from 1 to 0 will not be visible.
409             fWriteProc(&fVertexWriter, fVertexSpec, deviceQuad, localQuad, kZeroCoverage, color,
410                        geomSubset, uvSubset);
411         } else {
412             // Reset the tessellation helper to match the current geometry
413             fAAHelper.reset(*deviceQuad, localQuad);
414 
415             // Edge inset/outset distance ordered LBTR, set to 0.5 for a half pixel if the AA flag
416             // is turned on, or 0.0 if the edge is not anti-aliased.
417             skvx::Vec<4, float> edgeDistances;
418             if (aaFlags == GrQuadAAFlags::kAll) {
419                 edgeDistances = 0.5f;
420             } else {
421                 edgeDistances = { (aaFlags & GrQuadAAFlags::kLeft)   ? 0.5f : 0.f,
422                                   (aaFlags & GrQuadAAFlags::kBottom) ? 0.5f : 0.f,
423                                   (aaFlags & GrQuadAAFlags::kTop)    ? 0.5f : 0.f,
424                                   (aaFlags & GrQuadAAFlags::kRight)  ? 0.5f : 0.f };
425             }
426 
427             // Write inner vertices first
428             float coverage[4];
429             fAAHelper.inset(edgeDistances, deviceQuad, localQuad).store(coverage);
430             fWriteProc(&fVertexWriter, fVertexSpec, deviceQuad, localQuad, coverage, color,
431                        geomSubset, uvSubset);
432 
433             // Then outer vertices, which use 0.f for their coverage. If the inset was degenerate
434             // to a line (had all coverages < 1), tweak the outset distance so the outer frame's
435             // narrow axis reaches out to 2px, which gives better animation under translation.
436             const bool hairline = aaFlags == GrQuadAAFlags::kAll &&
437                                   coverage[0] < 1.f &&
438                                   coverage[1] < 1.f &&
439                                   coverage[2] < 1.f &&
440                                   coverage[3] < 1.f;
441             if (hairline) {
442                 skvx::Vec<4, float> len = fAAHelper.getEdgeLengths();
443                 // Using max guards us against trying to scale a degenerate triangle edge of 0 len
444                 // up to 2px. The shuffles are so that edge 0's adjustment is based on the lengths
445                 // of its connecting edges (1 and 2), and so forth.
446                 skvx::Vec<4, float> maxWH = max(skvx::shuffle<1, 0, 3, 2>(len),
447                                                 skvx::shuffle<2, 3, 0, 1>(len));
448                 // wh + 2e' = 2, so e' = (2 - wh) / 2 => e' = e * (2 - wh). But if w or h > 1, then
449                 // 2 - wh < 1 and represents the non-narrow axis so clamp to 1.
450                 edgeDistances *= max(1.f, 2.f - maxWH);
451             }
452             fAAHelper.outset(edgeDistances, deviceQuad, localQuad);
453             fWriteProc(&fVertexWriter, fVertexSpec, deviceQuad, localQuad, kZeroCoverage, color,
454                        geomSubset, uvSubset);
455         }
456     } else {
457         // No outsetting needed, just write a single quad with full coverage
458         SkASSERT(fVertexSpec.coverageMode() == CoverageMode::kNone &&
459                  !fVertexSpec.requiresGeometrySubset());
460         fWriteProc(&fVertexWriter, fVertexSpec, deviceQuad, localQuad, kFullCoverage, color,
461                    kIgnoredSubset, uvSubset);
462     }
463 }
464 
GetIndexBuffer(GrMeshDrawTarget * target,IndexBufferOption indexBufferOption)465 sk_sp<const GrBuffer> GetIndexBuffer(GrMeshDrawTarget* target,
466                                      IndexBufferOption indexBufferOption) {
467     auto resourceProvider = target->resourceProvider();
468 
469     switch (indexBufferOption) {
470         case IndexBufferOption::kPictureFramed: return resourceProvider->refAAQuadIndexBuffer();
471         case IndexBufferOption::kIndexedRects:  return resourceProvider->refNonAAQuadIndexBuffer();
472         case IndexBufferOption::kTriStrips:     // fall through
473         default:                                return nullptr;
474     }
475 }
476 
QuadLimit(IndexBufferOption option)477 int QuadLimit(IndexBufferOption option) {
478     switch (option) {
479         case IndexBufferOption::kPictureFramed: return GrResourceProvider::MaxNumAAQuads();
480         case IndexBufferOption::kIndexedRects:  return GrResourceProvider::MaxNumNonAAQuads();
481         case IndexBufferOption::kTriStrips:     return SK_MaxS32; // not limited by an indexBuffer
482     }
483 
484     SkUNREACHABLE;
485 }
486 
IssueDraw(const GrCaps & caps,GrOpsRenderPass * renderPass,const VertexSpec & spec,int runningQuadCount,int quadsInDraw,int maxVerts,int absVertBufferOffset)487 void IssueDraw(const GrCaps& caps, GrOpsRenderPass* renderPass, const VertexSpec& spec,
488                int runningQuadCount, int quadsInDraw, int maxVerts, int absVertBufferOffset) {
489     if (spec.indexBufferOption() == IndexBufferOption::kTriStrips) {
490         int offset = absVertBufferOffset +
491                                     runningQuadCount * GrResourceProvider::NumVertsPerNonAAQuad();
492         renderPass->draw(4, offset);
493         return;
494     }
495 
496     SkASSERT(spec.indexBufferOption() == IndexBufferOption::kPictureFramed ||
497              spec.indexBufferOption() == IndexBufferOption::kIndexedRects);
498 
499     int maxNumQuads, numIndicesPerQuad, numVertsPerQuad;
500 
501     if (spec.indexBufferOption() == IndexBufferOption::kPictureFramed) {
502         // AA uses 8 vertices and 30 indices per quad, basically nested rectangles
503         maxNumQuads = GrResourceProvider::MaxNumAAQuads();
504         numIndicesPerQuad = GrResourceProvider::NumIndicesPerAAQuad();
505         numVertsPerQuad = GrResourceProvider::NumVertsPerAAQuad();
506     } else {
507         // Non-AA uses 4 vertices and 6 indices per quad
508         maxNumQuads = GrResourceProvider::MaxNumNonAAQuads();
509         numIndicesPerQuad = GrResourceProvider::NumIndicesPerNonAAQuad();
510         numVertsPerQuad = GrResourceProvider::NumVertsPerNonAAQuad();
511     }
512 
513     SkASSERT(runningQuadCount + quadsInDraw <= maxNumQuads);
514 
515     if (caps.avoidLargeIndexBufferDraws()) {
516         // When we need to avoid large index buffer draws we modify the base vertex of the draw
517         // which, in GL, requires rebinding all vertex attrib arrays, so a base index is generally
518         // preferred.
519         int offset = absVertBufferOffset + runningQuadCount * numVertsPerQuad;
520 
521         renderPass->drawIndexPattern(numIndicesPerQuad, quadsInDraw, maxNumQuads, numVertsPerQuad,
522                                      offset);
523     } else {
524         int baseIndex = runningQuadCount * numIndicesPerQuad;
525         int numIndicesToDraw = quadsInDraw * numIndicesPerQuad;
526 
527         int minVertex = runningQuadCount * numVertsPerQuad;
528         int maxVertex = (runningQuadCount + quadsInDraw) * numVertsPerQuad - 1; // inclusive
529 
530         renderPass->drawIndexed(numIndicesToDraw, baseIndex, minVertex, maxVertex,
531                                 absVertBufferOffset);
532     }
533 }
534 
535 ////////////////// VertexSpec Implementation
536 
deviceDimensionality() const537 int VertexSpec::deviceDimensionality() const {
538     return this->deviceQuadType() == GrQuad::Type::kPerspective ? 3 : 2;
539 }
540 
localDimensionality() const541 int VertexSpec::localDimensionality() const {
542     return fHasLocalCoords ? (this->localQuadType() == GrQuad::Type::kPerspective ? 3 : 2) : 0;
543 }
544 
coverageMode() const545 CoverageMode VertexSpec::coverageMode() const {
546     if (this->usesCoverageAA()) {
547         if (this->compatibleWithCoverageAsAlpha() && this->hasVertexColors() &&
548             !this->requiresGeometrySubset()) {
549             // Using a geometric subset acts as a second source of coverage and folding
550             // the original coverage into color makes it impossible to apply the color's
551             // alpha to the geometric subset's coverage when the original shape is clipped.
552             return CoverageMode::kWithColor;
553         } else {
554             return CoverageMode::kWithPosition;
555         }
556     } else {
557         return CoverageMode::kNone;
558     }
559 }
560 
561 // This needs to stay in sync w/ QuadPerEdgeAAGeometryProcessor::initializeAttrs
vertexSize() const562 size_t VertexSpec::vertexSize() const {
563     bool needsPerspective = (this->deviceDimensionality() == 3);
564     CoverageMode coverageMode = this->coverageMode();
565 
566     size_t count = 0;
567 
568     if (coverageMode == CoverageMode::kWithPosition) {
569         if (needsPerspective) {
570             count += GrVertexAttribTypeSize(kFloat4_GrVertexAttribType);
571         } else {
572             count += GrVertexAttribTypeSize(kFloat2_GrVertexAttribType) +
573                      GrVertexAttribTypeSize(kFloat_GrVertexAttribType);
574         }
575     } else {
576         if (needsPerspective) {
577             count += GrVertexAttribTypeSize(kFloat3_GrVertexAttribType);
578         } else {
579             count += GrVertexAttribTypeSize(kFloat2_GrVertexAttribType);
580         }
581     }
582 
583     if (this->requiresGeometrySubset()) {
584         count += GrVertexAttribTypeSize(kFloat4_GrVertexAttribType);
585     }
586 
587     count += this->localDimensionality() * GrVertexAttribTypeSize(kFloat_GrVertexAttribType);
588 
589     if (ColorType::kByte == this->colorType()) {
590         count += GrVertexAttribTypeSize(kUByte4_norm_GrVertexAttribType);
591     } else if (ColorType::kFloat == this->colorType()) {
592         count += GrVertexAttribTypeSize(kFloat4_GrVertexAttribType);
593     }
594 
595     if (this->hasSubset()) {
596         count += GrVertexAttribTypeSize(kFloat4_GrVertexAttribType);
597     }
598 
599     return count;
600 }
601 
602 ////////////////// Geometry Processor Implementation
603 
604 class QuadPerEdgeAAGeometryProcessor : public GrGeometryProcessor {
605 public:
Make(SkArenaAlloc * arena,const VertexSpec & spec)606     static GrGeometryProcessor* Make(SkArenaAlloc* arena, const VertexSpec& spec) {
607         return arena->make([&](void* ptr) {
608             return new (ptr) QuadPerEdgeAAGeometryProcessor(spec);
609         });
610     }
611 
Make(SkArenaAlloc * arena,const VertexSpec & vertexSpec,const GrShaderCaps & caps,const GrBackendFormat & backendFormat,GrSamplerState samplerState,const skgpu::Swizzle & swizzle,sk_sp<GrColorSpaceXform> textureColorSpaceXform,Saturate saturate)612     static GrGeometryProcessor* Make(SkArenaAlloc* arena,
613                                      const VertexSpec& vertexSpec,
614                                      const GrShaderCaps& caps,
615                                      const GrBackendFormat& backendFormat,
616                                      GrSamplerState samplerState,
617                                      const skgpu::Swizzle& swizzle,
618                                      sk_sp<GrColorSpaceXform> textureColorSpaceXform,
619                                      Saturate saturate) {
620         return arena->make([&](void* ptr) {
621             return new (ptr) QuadPerEdgeAAGeometryProcessor(
622                     vertexSpec, caps, backendFormat, samplerState, swizzle,
623                     std::move(textureColorSpaceXform), saturate);
624         });
625     }
626 
name() const627     const char* name() const override { return "QuadPerEdgeAAGeometryProcessor"; }
628 
addToKey(const GrShaderCaps &,KeyBuilder * b) const629     void addToKey(const GrShaderCaps&, KeyBuilder* b) const override {
630         // texturing, device-dimensions are single bit flags
631         b->addBool(fTexSubset.isInitialized(),    "subset");
632         b->addBool(fSampler.isInitialized(),      "textured");
633         b->addBool(fNeedsPerspective,             "perspective");
634         b->addBool((fSaturate == Saturate::kYes), "saturate");
635 
636         b->addBool(fLocalCoord.isInitialized(),   "hasLocalCoords");
637         if (fLocalCoord.isInitialized()) {
638             // 2D (0) or 3D (1)
639             b->addBits(1, (kFloat3_GrVertexAttribType == fLocalCoord.cpuType()), "localCoordsType");
640         }
641         b->addBool(fColor.isInitialized(),        "hasColor");
642         if (fColor.isInitialized()) {
643             // bytes (0) or floats (1)
644             b->addBits(1, (kFloat4_GrVertexAttribType == fColor.cpuType()), "colorType");
645         }
646         // and coverage mode, 00 for none, 01 for withposition, 10 for withcolor, 11 for
647         // position+geomsubset
648         uint32_t coverageKey = 0;
649         SkASSERT(!fGeomSubset.isInitialized() || fCoverageMode == CoverageMode::kWithPosition);
650         if (fCoverageMode != CoverageMode::kNone) {
651             coverageKey = fGeomSubset.isInitialized()
652                                   ? 0x3
653                                   : (CoverageMode::kWithPosition == fCoverageMode ? 0x1 : 0x2);
654         }
655         b->addBits(2, coverageKey, "coverageMode");
656 
657         b->add32(GrColorSpaceXform::XformKey(fTextureColorSpaceXform.get()), "colorSpaceXform");
658     }
659 
makeProgramImpl(const GrShaderCaps &) const660     std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
661         class Impl : public ProgramImpl {
662         public:
663             void setData(const GrGLSLProgramDataManager& pdman,
664                          const GrShaderCaps&,
665                          const GrGeometryProcessor& geomProc) override {
666                 const auto& gp = geomProc.cast<QuadPerEdgeAAGeometryProcessor>();
667                 fTextureColorSpaceXformHelper.setData(pdman, gp.fTextureColorSpaceXform.get());
668             }
669 
670         private:
671             void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
672                 using Interpolation = GrGLSLVaryingHandler::Interpolation;
673 
674                 const auto& gp = args.fGeomProc.cast<QuadPerEdgeAAGeometryProcessor>();
675                 fTextureColorSpaceXformHelper.emitCode(args.fUniformHandler,
676                                                        gp.fTextureColorSpaceXform.get());
677 
678                 args.fVaryingHandler->emitAttributes(gp);
679 
680                 if (gp.fCoverageMode == CoverageMode::kWithPosition) {
681                     // Strip last channel from the vertex attribute to remove coverage and get the
682                     // actual position
683                     if (gp.fNeedsPerspective) {
684                         args.fVertBuilder->codeAppendf("float3 position = %s.xyz;",
685                                                        gp.fPosition.name());
686                     } else {
687                         args.fVertBuilder->codeAppendf("float2 position = %s.xy;",
688                                                        gp.fPosition.name());
689                     }
690                     gpArgs->fPositionVar = {"position",
691                                             gp.fNeedsPerspective ? SkSLType::kFloat3
692                                                                  : SkSLType::kFloat2,
693                                             GrShaderVar::TypeModifier::None};
694                 } else {
695                     // No coverage to eliminate
696                     gpArgs->fPositionVar = gp.fPosition.asShaderVar();
697                 }
698 
699                 // This attribute will be uninitialized if earlier FP analysis determined no
700                 // local coordinates are needed (and this will not include the inline texture
701                 // fetch this GP does before invoking FPs).
702                 gpArgs->fLocalCoordVar = gp.fLocalCoord.asShaderVar();
703 
704                 // Solid color before any texturing gets modulated in
705                 const char* blendDst;
706                 if (gp.fColor.isInitialized()) {
707                     SkASSERT(gp.fCoverageMode != CoverageMode::kWithColor || !gp.fNeedsPerspective);
708                     // The color cannot be flat if the varying coverage has been modulated into it
709                     args.fFragBuilder->codeAppendf("half4 %s;", args.fOutputColor);
710                     args.fVaryingHandler->addPassThroughAttribute(
711                             gp.fColor.asShaderVar(),
712                             args.fOutputColor,
713                             gp.fCoverageMode == CoverageMode::kWithColor
714                                     ? Interpolation::kInterpolated
715                                     : Interpolation::kCanBeFlat);
716                     blendDst = args.fOutputColor;
717                 } else {
718                     // Output color must be initialized to something
719                     args.fFragBuilder->codeAppendf("half4 %s = half4(1);", args.fOutputColor);
720                     blendDst = nullptr;
721                 }
722 
723                 // If there is a texture, must also handle texture coordinates and reading from
724                 // the texture in the fragment shader before continuing to fragment processors.
725                 if (gp.fSampler.isInitialized()) {
726                     // Texture coordinates clamped by the subset on the fragment shader; if the GP
727                     // has a texture, it's guaranteed to have local coordinates
728                     args.fFragBuilder->codeAppend("float2 texCoord;");
729                     if (gp.fLocalCoord.cpuType() == kFloat3_GrVertexAttribType) {
730                         // Can't do a pass through since we need to perform perspective division
731                         GrGLSLVarying v(gp.fLocalCoord.gpuType());
732                         args.fVaryingHandler->addVarying(gp.fLocalCoord.name(), &v);
733                         args.fVertBuilder->codeAppendf("%s = %s;",
734                                                        v.vsOut(), gp.fLocalCoord.name());
735                         args.fFragBuilder->codeAppendf("texCoord = %s.xy / %s.z;",
736                                                        v.fsIn(), v.fsIn());
737                     } else {
738                         args.fVaryingHandler->addPassThroughAttribute(gp.fLocalCoord.asShaderVar(),
739                                                                       "texCoord");
740                     }
741 
742                     // Clamp the now 2D localCoordName variable by the subset if it is provided
743                     if (gp.fTexSubset.isInitialized()) {
744                         args.fFragBuilder->codeAppend("float4 subset;");
745                         args.fVaryingHandler->addPassThroughAttribute(gp.fTexSubset.asShaderVar(),
746                                                                       "subset",
747                                                                       Interpolation::kCanBeFlat);
748                         args.fFragBuilder->codeAppend(
749                                 "texCoord = clamp(texCoord, subset.LT, subset.RB);");
750                     }
751 
752                     // Now modulate the starting output color by the texture lookup
753                     args.fFragBuilder->codeAppendf(
754                             "%s = %s(",
755                             args.fOutputColor,
756                             (gp.fSaturate == Saturate::kYes) ? "saturate" : "");
757                     args.fFragBuilder->appendTextureLookupAndBlend(
758                             blendDst, SkBlendMode::kModulate, args.fTexSamplers[0],
759                             "texCoord", &fTextureColorSpaceXformHelper);
760                     args.fFragBuilder->codeAppend(");");
761                 } else {
762                     // Saturate is only intended for use with a proxy to account for the fact
763                     // that TextureOp skips SkPaint conversion, which normally handles this.
764                     SkASSERT(gp.fSaturate == Saturate::kNo);
765                 }
766 
767                 // And lastly, output the coverage calculation code
768                 if (gp.fCoverageMode == CoverageMode::kWithPosition) {
769                     GrGLSLVarying coverage(SkSLType::kFloat);
770                     args.fVaryingHandler->addVarying("coverage", &coverage);
771                     if (gp.fNeedsPerspective) {
772                         // Multiply by "W" in the vertex shader, then by 1/w (sk_FragCoord.w) in
773                         // the fragment shader to get screen-space linear coverage.
774                         args.fVertBuilder->codeAppendf("%s = %s.w * %s.z;",
775                                                        coverage.vsOut(), gp.fPosition.name(),
776                                                        gp.fPosition.name());
777                         args.fFragBuilder->codeAppendf("float coverage = %s * sk_FragCoord.w;",
778                                                         coverage.fsIn());
779                     } else {
780                         args.fVertBuilder->codeAppendf("%s = %s;",
781                                                        coverage.vsOut(), gp.fCoverage.name());
782                         args.fFragBuilder->codeAppendf("float coverage = %s;", coverage.fsIn());
783                     }
784 
785                     if (gp.fGeomSubset.isInitialized()) {
786                         // Calculate distance from sk_FragCoord to the 4 edges of the subset
787                         // and clamp them to (0, 1). Use the minimum of these and the original
788                         // coverage. This only has to be done in the exterior triangles, the
789                         // interior of the quad geometry can never be clipped by the subset box.
790                         args.fFragBuilder->codeAppend("float4 geoSubset;");
791                         args.fVaryingHandler->addPassThroughAttribute(gp.fGeomSubset.asShaderVar(),
792                                                                       "geoSubset",
793                                                                       Interpolation::kCanBeFlat);
794 #ifdef SK_USE_LEGACY_AA_QUAD_SUBSET
795                         args.fFragBuilder->codeAppend(
796                                 "if (coverage < 0.5) {"
797                                 "   float4 dists4 = clamp(float4(1, 1, -1, -1) * "
798                                         "(sk_FragCoord.xyxy - geoSubset), 0, 1);"
799                                 "   float2 dists2 = dists4.xy * dists4.zw;"
800                                 "   coverage = min(coverage, dists2.x * dists2.y);"
801                                 "}");
802 #else
803                         args.fFragBuilder->codeAppend(
804                                 // This is lifted from GrAARectEffect. It'd be nice if we could
805                                 // invoke a FP from a GP rather than duplicate this code.
806                                 "half4 dists4 = clamp(half4(1, 1, -1, -1) * "
807                                                "half4(sk_FragCoord.xyxy - geoSubset), 0, 1);\n"
808                                 "half2 dists2 = dists4.xy + dists4.zw - 1;\n"
809                                 "half subsetCoverage = dists2.x * dists2.y;\n"
810                                 "coverage = min(coverage, subsetCoverage);");
811 #endif
812                     }
813 
814                     args.fFragBuilder->codeAppendf("half4 %s = half4(half(coverage));",
815                                                    args.fOutputCoverage);
816                 } else {
817                     // Set coverage to 1, since it's either non-AA or the coverage was already
818                     // folded into the output color
819                     SkASSERT(!gp.fGeomSubset.isInitialized());
820                     args.fFragBuilder->codeAppendf("const half4 %s = half4(1);",
821                                                    args.fOutputCoverage);
822                 }
823             }
824 
825             GrGLSLColorSpaceXformHelper fTextureColorSpaceXformHelper;
826         };
827 
828         return std::make_unique<Impl>();
829     }
830 
831 private:
832     using Saturate = skgpu::ganesh::TextureOp::Saturate;
833 
QuadPerEdgeAAGeometryProcessor(const VertexSpec & spec)834     QuadPerEdgeAAGeometryProcessor(const VertexSpec& spec)
835             : INHERITED(kQuadPerEdgeAAGeometryProcessor_ClassID)
836             , fTextureColorSpaceXform(nullptr) {
837         SkASSERT(!spec.hasSubset());
838         this->initializeAttrs(spec);
839         this->setTextureSamplerCnt(0);
840     }
841 
QuadPerEdgeAAGeometryProcessor(const VertexSpec & spec,const GrShaderCaps & caps,const GrBackendFormat & backendFormat,GrSamplerState samplerState,const skgpu::Swizzle & swizzle,sk_sp<GrColorSpaceXform> textureColorSpaceXform,Saturate saturate)842     QuadPerEdgeAAGeometryProcessor(const VertexSpec& spec,
843                                    const GrShaderCaps& caps,
844                                    const GrBackendFormat& backendFormat,
845                                    GrSamplerState samplerState,
846                                    const skgpu::Swizzle& swizzle,
847                                    sk_sp<GrColorSpaceXform> textureColorSpaceXform,
848                                    Saturate saturate)
849             : INHERITED(kQuadPerEdgeAAGeometryProcessor_ClassID)
850             , fSaturate(saturate)
851             , fTextureColorSpaceXform(std::move(textureColorSpaceXform))
852             , fSampler(samplerState, backendFormat, swizzle) {
853         SkASSERT(spec.hasLocalCoords());
854         this->initializeAttrs(spec);
855         this->setTextureSamplerCnt(1);
856     }
857 
858     // This needs to stay in sync w/ VertexSpec::vertexSize
initializeAttrs(const VertexSpec & spec)859     void initializeAttrs(const VertexSpec& spec) {
860         fNeedsPerspective = spec.deviceDimensionality() == 3;
861         fCoverageMode = spec.coverageMode();
862 
863         if (fCoverageMode == CoverageMode::kWithPosition) {
864             if (fNeedsPerspective) {
865                 fPosition = {"positionWithCoverage", kFloat4_GrVertexAttribType, SkSLType::kFloat4};
866             } else {
867                 fPosition = {"position", kFloat2_GrVertexAttribType, SkSLType::kFloat2};
868                 fCoverage = {"coverage", kFloat_GrVertexAttribType, SkSLType::kFloat};
869             }
870         } else {
871             if (fNeedsPerspective) {
872                 fPosition = {"position", kFloat3_GrVertexAttribType, SkSLType::kFloat3};
873             } else {
874                 fPosition = {"position", kFloat2_GrVertexAttribType, SkSLType::kFloat2};
875             }
876         }
877 
878         // Need a geometry subset when the quads are AA and not rectilinear, since their AA
879         // outsetting can go beyond a half pixel.
880         if (spec.requiresGeometrySubset()) {
881             fGeomSubset = {"geomSubset", kFloat4_GrVertexAttribType, SkSLType::kFloat4};
882         }
883 
884         int localDim = spec.localDimensionality();
885         if (localDim == 3) {
886             fLocalCoord = {"localCoord", kFloat3_GrVertexAttribType, SkSLType::kFloat3};
887         } else if (localDim == 2) {
888             fLocalCoord = {"localCoord", kFloat2_GrVertexAttribType, SkSLType::kFloat2};
889         } // else localDim == 0 and attribute remains uninitialized
890 
891         if (spec.hasVertexColors()) {
892             fColor = MakeColorAttribute("color", ColorType::kFloat == spec.colorType());
893         }
894 
895         if (spec.hasSubset()) {
896             fTexSubset = {"texSubset", kFloat4_GrVertexAttribType, SkSLType::kFloat4};
897         }
898 
899         this->setVertexAttributesWithImplicitOffsets(&fPosition, 6);
900     }
901 
onTextureSampler(int) const902     const TextureSampler& onTextureSampler(int) const override { return fSampler; }
903 
904     Attribute fPosition; // May contain coverage as last channel
905     Attribute fCoverage; // Used for non-perspective position to avoid Intel Metal issues
906     Attribute fColor; // May have coverage modulated in if the FPs support it
907     Attribute fLocalCoord;
908     Attribute fGeomSubset; // Screen-space bounding box on geometry+aa outset
909     Attribute fTexSubset; // Texture-space bounding box on local coords
910 
911     // The positions attribute may have coverage built into it, so float3 is an ambiguous type
912     // and may mean 2d with coverage, or 3d with no coverage
913     bool fNeedsPerspective;
914     // Should saturate() be called on the color? Only relevant when created with a texture.
915     Saturate fSaturate = Saturate::kNo;
916     CoverageMode fCoverageMode;
917 
918     // Color space will be null and fSampler.isInitialized() returns false when the GP is configured
919     // to skip texturing.
920     sk_sp<GrColorSpaceXform> fTextureColorSpaceXform;
921     TextureSampler fSampler;
922 
923     using INHERITED = GrGeometryProcessor;
924 };
925 
MakeProcessor(SkArenaAlloc * arena,const VertexSpec & spec)926 GrGeometryProcessor* MakeProcessor(SkArenaAlloc* arena, const VertexSpec& spec) {
927     return QuadPerEdgeAAGeometryProcessor::Make(arena, spec);
928 }
929 
MakeTexturedProcessor(SkArenaAlloc * arena,const VertexSpec & spec,const GrShaderCaps & caps,const GrBackendFormat & backendFormat,GrSamplerState samplerState,const skgpu::Swizzle & swizzle,sk_sp<GrColorSpaceXform> textureColorSpaceXform,Saturate saturate)930 GrGeometryProcessor* MakeTexturedProcessor(SkArenaAlloc* arena,
931                                            const VertexSpec& spec,
932                                            const GrShaderCaps& caps,
933                                            const GrBackendFormat& backendFormat,
934                                            GrSamplerState samplerState,
935                                            const skgpu::Swizzle& swizzle,
936                                            sk_sp<GrColorSpaceXform> textureColorSpaceXform,
937                                            Saturate saturate) {
938     return QuadPerEdgeAAGeometryProcessor::Make(arena, spec, caps, backendFormat, samplerState,
939                                                 swizzle, std::move(textureColorSpaceXform),
940                                                 saturate);
941 }
942 
943 } // namespace skgpu::v1::QuadPerEdgeAA
944