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