• 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/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}
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 
GetIndexBuffer(GrMeshDrawTarget * target,IndexBufferOption indexBufferOption)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 
QuadLimit(IndexBufferOption option)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 
IssueDraw(const GrCaps & caps,GrOpsRenderPass * renderPass,const VertexSpec & spec,int runningQuadCount,int quadsInDraw,int maxVerts,int absVertBufferOffset)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 
name() const626     const char* name() const override { return "QuadPerEdgeAAGeometryProcessor"; }
627 
addToKey(const GrShaderCaps &,GrProcessorKeyBuilder * b) const628     void addToKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
629         // texturing, device-dimensions are single bit flags
630         b->addBool(fTexSubset.isInitialized(),    "subset");
631         b->addBool(fSampler.isInitialized(),      "textured");
632         b->addBool(fNeedsPerspective,             "perspective");
633         b->addBool((fSaturate == Saturate::kYes), "saturate");
634 
635         b->addBool(fLocalCoord.isInitialized(),   "hasLocalCoords");
636         if (fLocalCoord.isInitialized()) {
637             // 2D (0) or 3D (1)
638             b->addBits(1, (kFloat3_GrVertexAttribType == fLocalCoord.cpuType()), "localCoordsType");
639         }
640         b->addBool(fColor.isInitialized(),        "hasColor");
641         if (fColor.isInitialized()) {
642             // bytes (0) or floats (1)
643             b->addBits(1, (kFloat4_GrVertexAttribType == fColor.cpuType()), "colorType");
644         }
645         // and coverage mode, 00 for none, 01 for withposition, 10 for withcolor, 11 for
646         // position+geomsubset
647         uint32_t coverageKey = 0;
648         SkASSERT(!fGeomSubset.isInitialized() || fCoverageMode == CoverageMode::kWithPosition);
649         if (fCoverageMode != CoverageMode::kNone) {
650             coverageKey = fGeomSubset.isInitialized()
651                                   ? 0x3
652                                   : (CoverageMode::kWithPosition == fCoverageMode ? 0x1 : 0x2);
653         }
654         b->addBits(2, coverageKey, "coverageMode");
655 
656         b->add32(GrColorSpaceXform::XformKey(fTextureColorSpaceXform.get()), "colorSpaceXform");
657     }
658 
makeProgramImpl(const GrShaderCaps &) const659     std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
660         class Impl : public ProgramImpl {
661         public:
662             void setData(const GrGLSLProgramDataManager& pdman,
663                          const GrShaderCaps&,
664                          const GrGeometryProcessor& geomProc) override {
665                 const auto& gp = geomProc.cast<QuadPerEdgeAAGeometryProcessor>();
666                 fTextureColorSpaceXformHelper.setData(pdman, gp.fTextureColorSpaceXform.get());
667             }
668 
669         private:
670             void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
671                 using Interpolation = GrGLSLVaryingHandler::Interpolation;
672 
673                 const auto& gp = args.fGeomProc.cast<QuadPerEdgeAAGeometryProcessor>();
674                 fTextureColorSpaceXformHelper.emitCode(args.fUniformHandler,
675                                                        gp.fTextureColorSpaceXform.get());
676 
677                 args.fVaryingHandler->emitAttributes(gp);
678 
679                 if (gp.fCoverageMode == CoverageMode::kWithPosition) {
680                     // Strip last channel from the vertex attribute to remove coverage and get the
681                     // actual position
682                     if (gp.fNeedsPerspective) {
683                         args.fVertBuilder->codeAppendf("float3 position = %s.xyz;",
684                                                        gp.fPosition.name());
685                     } else {
686                         args.fVertBuilder->codeAppendf("float2 position = %s.xy;",
687                                                        gp.fPosition.name());
688                     }
689                     gpArgs->fPositionVar = {"position",
690                                             gp.fNeedsPerspective ? kFloat3_GrSLType
691                                                                  : kFloat2_GrSLType,
692                                             GrShaderVar::TypeModifier::None};
693                 } else {
694                     // No coverage to eliminate
695                     gpArgs->fPositionVar = gp.fPosition.asShaderVar();
696                 }
697 
698                 // This attribute will be uninitialized if earlier FP analysis determined no
699                 // local coordinates are needed (and this will not include the inline texture
700                 // fetch this GP does before invoking FPs).
701                 gpArgs->fLocalCoordVar = gp.fLocalCoord.asShaderVar();
702 
703                 // Solid color before any texturing gets modulated in
704                 const char* blendDst;
705                 if (gp.fColor.isInitialized()) {
706                     SkASSERT(gp.fCoverageMode != CoverageMode::kWithColor || !gp.fNeedsPerspective);
707                     // The color cannot be flat if the varying coverage has been modulated into it
708                     args.fFragBuilder->codeAppendf("half4 %s;", args.fOutputColor);
709                     args.fVaryingHandler->addPassThroughAttribute(
710                             gp.fColor.asShaderVar(),
711                             args.fOutputColor,
712                             gp.fCoverageMode == CoverageMode::kWithColor
713                                     ? Interpolation::kInterpolated
714                                     : Interpolation::kCanBeFlat);
715                     blendDst = args.fOutputColor;
716                 } else {
717                     // Output color must be initialized to something
718                     args.fFragBuilder->codeAppendf("half4 %s = half4(1);", args.fOutputColor);
719                     blendDst = nullptr;
720                 }
721 
722                 // If there is a texture, must also handle texture coordinates and reading from
723                 // the texture in the fragment shader before continuing to fragment processors.
724                 if (gp.fSampler.isInitialized()) {
725                     // Texture coordinates clamped by the subset on the fragment shader; if the GP
726                     // has a texture, it's guaranteed to have local coordinates
727                     args.fFragBuilder->codeAppend("float2 texCoord;");
728                     if (gp.fLocalCoord.cpuType() == kFloat3_GrVertexAttribType) {
729                         // Can't do a pass through since we need to perform perspective division
730                         GrGLSLVarying v(gp.fLocalCoord.gpuType());
731                         args.fVaryingHandler->addVarying(gp.fLocalCoord.name(), &v);
732                         args.fVertBuilder->codeAppendf("%s = %s;",
733                                                        v.vsOut(), gp.fLocalCoord.name());
734                         args.fFragBuilder->codeAppendf("texCoord = %s.xy / %s.z;",
735                                                        v.fsIn(), v.fsIn());
736                     } else {
737                         args.fVaryingHandler->addPassThroughAttribute(gp.fLocalCoord.asShaderVar(),
738                                                                       "texCoord");
739                     }
740 
741                     // Clamp the now 2D localCoordName variable by the subset if it is provided
742                     if (gp.fTexSubset.isInitialized()) {
743                         args.fFragBuilder->codeAppend("float4 subset;");
744                         args.fVaryingHandler->addPassThroughAttribute(gp.fTexSubset.asShaderVar(),
745                                                                       "subset",
746                                                                       Interpolation::kCanBeFlat);
747                         args.fFragBuilder->codeAppend(
748                                 "texCoord = clamp(texCoord, subset.LT, subset.RB);");
749                     }
750 
751                     // Now modulate the starting output color by the texture lookup
752                     args.fFragBuilder->codeAppendf(
753                             "%s = %s(",
754                             args.fOutputColor,
755                             (gp.fSaturate == Saturate::kYes) ? "saturate" : "");
756                     args.fFragBuilder->appendTextureLookupAndBlend(
757                             blendDst, SkBlendMode::kModulate, args.fTexSamplers[0],
758                             "texCoord", &fTextureColorSpaceXformHelper);
759                     args.fFragBuilder->codeAppend(");");
760                 } else {
761                     // Saturate is only intended for use with a proxy to account for the fact
762                     // that TextureOp skips SkPaint conversion, which normally handles this.
763                     SkASSERT(gp.fSaturate == Saturate::kNo);
764                 }
765 
766                 // And lastly, output the coverage calculation code
767                 if (gp.fCoverageMode == CoverageMode::kWithPosition) {
768                     GrGLSLVarying coverage(kFloat_GrSLType);
769                     args.fVaryingHandler->addVarying("coverage", &coverage);
770                     if (gp.fNeedsPerspective) {
771                         // Multiply by "W" in the vertex shader, then by 1/w (sk_FragCoord.w) in
772                         // the fragment shader to get screen-space linear coverage.
773                         args.fVertBuilder->codeAppendf("%s = %s.w * %s.z;",
774                                                        coverage.vsOut(), gp.fPosition.name(),
775                                                        gp.fPosition.name());
776                         args.fFragBuilder->codeAppendf("float coverage = %s * sk_FragCoord.w;",
777                                                         coverage.fsIn());
778                     } else {
779                         args.fVertBuilder->codeAppendf("%s = %s;",
780                                                        coverage.vsOut(), gp.fCoverage.name());
781                         args.fFragBuilder->codeAppendf("float coverage = %s;", coverage.fsIn());
782                     }
783 
784                     if (gp.fGeomSubset.isInitialized()) {
785                         // Calculate distance from sk_FragCoord to the 4 edges of the subset
786                         // and clamp them to (0, 1). Use the minimum of these and the original
787                         // coverage. This only has to be done in the exterior triangles, the
788                         // interior of the quad geometry can never be clipped by the subset box.
789                         args.fFragBuilder->codeAppend("float4 geoSubset;");
790                         args.fVaryingHandler->addPassThroughAttribute(gp.fGeomSubset.asShaderVar(),
791                                                                       "geoSubset",
792                                                                       Interpolation::kCanBeFlat);
793 #ifdef SK_USE_LEGACY_AA_QUAD_SUBSET
794                         args.fFragBuilder->codeAppend(
795                                 "if (coverage < 0.5) {"
796                                 "   float4 dists4 = clamp(float4(1, 1, -1, -1) * "
797                                         "(sk_FragCoord.xyxy - geoSubset), 0, 1);"
798                                 "   float2 dists2 = dists4.xy * dists4.zw;"
799                                 "   coverage = min(coverage, dists2.x * dists2.y);"
800                                 "}");
801 #else
802                         args.fFragBuilder->codeAppend(
803                                 // This is lifted from GrAARectEffect. It'd be nice if we could
804                                 // invoke a FP from a GP rather than duplicate this code.
805                                 "half4 dists4 = clamp(half4(1, 1, -1, -1) * "
806                                                "half4(sk_FragCoord.xyxy - geoSubset), 0, 1);\n"
807                                 "half2 dists2 = dists4.xy + dists4.zw - 1;\n"
808                                 "half subsetCoverage = dists2.x * dists2.y;\n"
809                                 "coverage = min(coverage, subsetCoverage);");
810 #endif
811                     }
812 
813                     args.fFragBuilder->codeAppendf("half4 %s = half4(half(coverage));",
814                                                    args.fOutputCoverage);
815                 } else {
816                     // Set coverage to 1, since it's either non-AA or the coverage was already
817                     // folded into the output color
818                     SkASSERT(!gp.fGeomSubset.isInitialized());
819                     args.fFragBuilder->codeAppendf("const half4 %s = half4(1);",
820                                                    args.fOutputCoverage);
821                 }
822             }
823 
824             GrGLSLColorSpaceXformHelper fTextureColorSpaceXformHelper;
825         };
826 
827         return std::make_unique<Impl>();
828     }
829 
830 private:
831     using Saturate = skgpu::v1::TextureOp::Saturate;
832 
QuadPerEdgeAAGeometryProcessor(const VertexSpec & spec)833     QuadPerEdgeAAGeometryProcessor(const VertexSpec& spec)
834             : INHERITED(kQuadPerEdgeAAGeometryProcessor_ClassID)
835             , fTextureColorSpaceXform(nullptr) {
836         SkASSERT(!spec.hasSubset());
837         this->initializeAttrs(spec);
838         this->setTextureSamplerCnt(0);
839     }
840 
QuadPerEdgeAAGeometryProcessor(const VertexSpec & spec,const GrShaderCaps & caps,const GrBackendFormat & backendFormat,GrSamplerState samplerState,const GrSwizzle & swizzle,sk_sp<GrColorSpaceXform> textureColorSpaceXform,Saturate saturate)841     QuadPerEdgeAAGeometryProcessor(const VertexSpec& spec,
842                                    const GrShaderCaps& caps,
843                                    const GrBackendFormat& backendFormat,
844                                    GrSamplerState samplerState,
845                                    const GrSwizzle& swizzle,
846                                    sk_sp<GrColorSpaceXform> textureColorSpaceXform,
847                                    Saturate saturate)
848             : INHERITED(kQuadPerEdgeAAGeometryProcessor_ClassID)
849             , fSaturate(saturate)
850             , fTextureColorSpaceXform(std::move(textureColorSpaceXform))
851             , fSampler(samplerState, backendFormat, swizzle) {
852         SkASSERT(spec.hasLocalCoords());
853         this->initializeAttrs(spec);
854         this->setTextureSamplerCnt(1);
855     }
856 
857     // This needs to stay in sync w/ VertexSpec::vertexSize
initializeAttrs(const VertexSpec & spec)858     void initializeAttrs(const VertexSpec& spec) {
859         fNeedsPerspective = spec.deviceDimensionality() == 3;
860         fCoverageMode = spec.coverageMode();
861 
862         if (fCoverageMode == CoverageMode::kWithPosition) {
863             if (fNeedsPerspective) {
864                 fPosition = {"positionWithCoverage", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
865             } else {
866                 fPosition = {"position", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
867                 fCoverage = {"coverage", kFloat_GrVertexAttribType, kFloat_GrSLType};
868             }
869         } else {
870             if (fNeedsPerspective) {
871                 fPosition = {"position", kFloat3_GrVertexAttribType, kFloat3_GrSLType};
872             } else {
873                 fPosition = {"position", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
874             }
875         }
876 
877         // Need a geometry subset when the quads are AA and not rectilinear, since their AA
878         // outsetting can go beyond a half pixel.
879         if (spec.requiresGeometrySubset()) {
880             fGeomSubset = {"geomSubset", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
881         }
882 
883         int localDim = spec.localDimensionality();
884         if (localDim == 3) {
885             fLocalCoord = {"localCoord", kFloat3_GrVertexAttribType, kFloat3_GrSLType};
886         } else if (localDim == 2) {
887             fLocalCoord = {"localCoord", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
888         } // else localDim == 0 and attribute remains uninitialized
889 
890         if (spec.hasVertexColors()) {
891             fColor = MakeColorAttribute("color", ColorType::kFloat == spec.colorType());
892         }
893 
894         if (spec.hasSubset()) {
895             fTexSubset = {"texSubset", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
896         }
897 
898         this->setVertexAttributes(&fPosition, 6);
899     }
900 
onTextureSampler(int) const901     const TextureSampler& onTextureSampler(int) const override { return fSampler; }
902 
903     Attribute fPosition; // May contain coverage as last channel
904     Attribute fCoverage; // Used for non-perspective position to avoid Intel Metal issues
905     Attribute fColor; // May have coverage modulated in if the FPs support it
906     Attribute fLocalCoord;
907     Attribute fGeomSubset; // Screen-space bounding box on geometry+aa outset
908     Attribute fTexSubset; // Texture-space bounding box on local coords
909 
910     // The positions attribute may have coverage built into it, so float3 is an ambiguous type
911     // and may mean 2d with coverage, or 3d with no coverage
912     bool fNeedsPerspective;
913     // Should saturate() be called on the color? Only relevant when created with a texture.
914     Saturate fSaturate = Saturate::kNo;
915     CoverageMode fCoverageMode;
916 
917     // Color space will be null and fSampler.isInitialized() returns false when the GP is configured
918     // to skip texturing.
919     sk_sp<GrColorSpaceXform> fTextureColorSpaceXform;
920     TextureSampler fSampler;
921 
922     using INHERITED = GrGeometryProcessor;
923 };
924 
MakeProcessor(SkArenaAlloc * arena,const VertexSpec & spec)925 GrGeometryProcessor* MakeProcessor(SkArenaAlloc* arena, const VertexSpec& spec) {
926     return QuadPerEdgeAAGeometryProcessor::Make(arena, spec);
927 }
928 
MakeTexturedProcessor(SkArenaAlloc * arena,const VertexSpec & spec,const GrShaderCaps & caps,const GrBackendFormat & backendFormat,GrSamplerState samplerState,const GrSwizzle & swizzle,sk_sp<GrColorSpaceXform> textureColorSpaceXform,Saturate saturate)929 GrGeometryProcessor* MakeTexturedProcessor(SkArenaAlloc* arena,
930                                            const VertexSpec& spec,
931                                            const GrShaderCaps& caps,
932                                            const GrBackendFormat& backendFormat,
933                                            GrSamplerState samplerState,
934                                            const GrSwizzle& swizzle,
935                                            sk_sp<GrColorSpaceXform> textureColorSpaceXform,
936                                            Saturate saturate) {
937     return QuadPerEdgeAAGeometryProcessor::Make(arena, spec, caps, backendFormat, samplerState,
938                                                 swizzle, std::move(textureColorSpaceXform),
939                                                 saturate);
940 }
941 
942 } // namespace skgpu::v1::QuadPerEdgeAA
943