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