blob: 5e4d8933bd38eda9934d184ab20e05512762f514 [file] [log] [blame]
Michael Ludwig69858532018-11-28 15:34:34 -05001/*
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 "GrFillRectOp.h"
9
10#include "GrGeometryProcessor.h"
11#include "GrMeshDrawOp.h"
12#include "GrPaint.h"
13#include "GrQuad.h"
14#include "GrQuadPerEdgeAA.h"
15#include "GrSimpleMeshDrawOpHelper.h"
16#include "SkMatrix.h"
17#include "SkRect.h"
18#include "glsl/GrGLSLColorSpaceXformHelper.h"
19#include "glsl/GrGLSLGeometryProcessor.h"
20#include "glsl/GrGLSLVarying.h"
21
22namespace {
23
24using VertexSpec = GrQuadPerEdgeAA::VertexSpec;
25using ColorType = GrQuadPerEdgeAA::ColorType;
26
27// NOTE: This info structure is intentionally modeled after GrTextureOps' Quad so that they can
28// more easily be integrated together in the future.
29class TransformedQuad {
30public:
31 TransformedQuad(const GrPerspQuad& deviceQuad, const GrPerspQuad& localQuad,
32 const SkPMColor4f& color, GrQuadAAFlags aaFlags)
33 : fDeviceQuad(deviceQuad)
34 , fLocalQuad(localQuad)
35 , fColor(color)
36 , fAAFlags(aaFlags) {}
37
38 const GrPerspQuad& deviceQuad() const { return fDeviceQuad; }
39 const GrPerspQuad& localQuad() const { return fLocalQuad; }
40 const SkPMColor4f& color() const { return fColor; }
41 GrQuadAAFlags aaFlags() const { return fAAFlags; }
42
43 void setColor(const SkPMColor4f& color) { fColor = color; }
44
45 SkString dumpInfo(int index) const {
46 SkString str;
47 str.appendf("%d: Color: [%.2f, %.2f, %.2f, %.2f], Edge AA: l%u_t%u_r%u_b%u, \n"
48 " device quad: [(%.2f, %2.f, %.2f), (%.2f, %.2f, %.2f), (%.2f, %.2f, %.2f), "
49 "(%.2f, %.2f, %.2f)],\n"
50 " local quad: [(%.2f, %2.f, %.2f), (%.2f, %.2f, %.2f), (%.2f, %.2f, %.2f), "
51 "(%.2f, %.2f, %.2f)]\n",
52 index, fColor.fR, fColor.fG, fColor.fB, fColor.fA,
53 (uint32_t) (fAAFlags & GrQuadAAFlags::kLeft),
54 (uint32_t) (fAAFlags & GrQuadAAFlags::kTop),
55 (uint32_t) (fAAFlags & GrQuadAAFlags::kRight),
56 (uint32_t) (fAAFlags & GrQuadAAFlags::kBottom),
57 fDeviceQuad.x(0), fDeviceQuad.y(0), fDeviceQuad.w(0),
58 fDeviceQuad.x(1), fDeviceQuad.y(1), fDeviceQuad.w(1),
59 fDeviceQuad.x(2), fDeviceQuad.y(2), fDeviceQuad.w(2),
60 fDeviceQuad.x(3), fDeviceQuad.y(3), fDeviceQuad.w(3),
61 fLocalQuad.x(0), fLocalQuad.y(0), fLocalQuad.w(0),
62 fLocalQuad.x(1), fLocalQuad.y(1), fLocalQuad.w(1),
63 fLocalQuad.x(2), fLocalQuad.y(2), fLocalQuad.w(2),
64 fLocalQuad.x(3), fLocalQuad.y(3), fLocalQuad.w(3));
65 return str;
66 }
67private:
68 // NOTE: The TransformedQuad does not store the types for device and local. The owning op tracks
69 // the most general type for device and local across all of its merged quads.
70 GrPerspQuad fDeviceQuad; // In device space, allowing rects to be combined across view matrices
71 GrPerspQuad fLocalQuad; // Original rect transformed by its local matrix
72 SkPMColor4f fColor;
73 GrQuadAAFlags fAAFlags;
74};
75
Michael Ludwig69858532018-11-28 15:34:34 -050076class FillRectOp final : public GrMeshDrawOp {
77private:
78 using Helper = GrSimpleMeshDrawOpHelperWithStencil;
79
80public:
81 static std::unique_ptr<GrDrawOp> Make(GrContext* context,
82 GrPaint&& paint,
83 GrAAType aaType,
84 GrQuadAAFlags edgeAA,
85 const GrUserStencilSettings* stencilSettings,
86 const GrPerspQuad& deviceQuad,
87 GrQuadType deviceQuadType,
88 const GrPerspQuad& localQuad,
89 GrQuadType localQuadType) {
90 // Clean up deviations between aaType and edgeAA
91 GrResolveAATypeForQuad(aaType, edgeAA, deviceQuad, deviceQuadType, &aaType, &edgeAA);
92
93 // Analyze the paint to see if it is compatible with scissor-clearing
94 SkPMColor4f color = paint.getColor4f();
95 // Only non-null if the paint can be turned into a clear, it can be a local pointer since
96 // the op ctor consumes the value right away if it's provided
97 SkPMColor4f* clearColor = nullptr;
98 if (paint.isTrivial() || paint.isConstantBlendedColor(&color)) {
99 clearColor = &color;
100 }
101
102 return Helper::FactoryHelper<FillRectOp>(context, std::move(paint), clearColor, aaType,
103 edgeAA, stencilSettings, deviceQuad, deviceQuadType, localQuad, localQuadType);
104 }
105
106 // Analysis of the GrPaint to determine the const blend color must be done before, passing
107 // nullptr for constBlendColor disables all scissor-clear optimizations (must keep the
108 // paintColor argument because it is assumed by the GrSimpleMeshDrawOpHelper). Similarly, aaType
109 // is passed to Helper in the initializer list, so incongruities between aaType and edgeFlags
110 // must be resolved prior to calling this constructor.
111 FillRectOp(Helper::MakeArgs args, SkPMColor4f paintColor, const SkPMColor4f* constBlendColor,
112 GrAAType aaType, GrQuadAAFlags edgeFlags, const GrUserStencilSettings* stencil,
113 const GrPerspQuad& deviceQuad, GrQuadType deviceQuadType,
114 const GrPerspQuad& localQuad, GrQuadType localQuadType)
115 : INHERITED(ClassID())
116 , fHelper(args, aaType, stencil)
117 , fDeviceQuadType(static_cast<unsigned>(deviceQuadType))
118 , fLocalQuadType(static_cast<unsigned>(localQuadType)) {
119 if (constBlendColor) {
120 // The GrPaint is compatible with clearing, and the constant blend color overrides the
121 // paint color (although in most cases they are probably the same)
122 paintColor = *constBlendColor;
123 // However, just because the paint is compatible, the device quad must also be a rect
124 // that is non-AA (AA aligned with pixel bounds should have already been turned into
125 // non-AA).
126 fClearCompatible = deviceQuadType == GrQuadType::kRect && aaType == GrAAType::kNone;
127 } else {
128 // Paint isn't clear compatible
129 fClearCompatible = false;
130 }
131
132 fWideColor = !SkPMColor4fFitsInBytes(paintColor);
133
134 // The color stored with the quad is the clear color if a scissor-clear is decided upon
135 // when executing the op.
136 fQuads.emplace_back(deviceQuad, localQuad, paintColor, edgeFlags);
137 this->setBounds(deviceQuad.bounds(), HasAABloat(aaType == GrAAType::kCoverage),
138 IsZeroArea::kNo);
139 }
140
141 const char* name() const override { return "FillRectOp"; }
142
143 void visitProxies(const VisitProxyFunc& func, VisitorType) const override {
144 return fHelper.visitProxies(func);
145 }
146
147#ifdef SK_DEBUG
148 SkString dumpInfo() const override {
149 SkString str;
150 str.appendf("# draws: %d\n", fQuads.count());
151 str.appendf("Clear compatible: %u\n", static_cast<bool>(fClearCompatible));
152 str.appendf("Device quad type: %u, local quad type: %u\n",
153 fDeviceQuadType, fLocalQuadType);
154 str += fHelper.dumpInfo();
155 for (int i = 0; i < fQuads.count(); i++) {
156 str += fQuads[i].dumpInfo(i);
157
158 }
159 str += INHERITED::dumpInfo();
160 return str;
161 }
162#endif
163
164 RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
165 // Initialize aggregate color analysis with the first quad's color (which always exists)
166 SkASSERT(fQuads.count() > 0);
167 GrProcessorAnalysisColor quadColors(fQuads[0].color());
168 // Then combine the colors of any additional quads (e.g. from MakeSet)
169 for (int i = 1; i < fQuads.count(); ++i) {
170 quadColors = GrProcessorAnalysisColor::Combine(quadColors, fQuads[i].color());
Michael Ludwigca91e1f2018-12-10 10:44:44 -0500171 if (quadColors.isUnknown()) {
172 // No point in accumulating additional starting colors, combining cannot make it
173 // less unknown.
174 break;
175 }
Michael Ludwig69858532018-11-28 15:34:34 -0500176 }
Michael Ludwig72ab3462018-12-10 12:43:36 -0500177
178 // If the AA type is coverage, it will be a single value per pixel; if it's not coverage AA
179 // then the coverage is always 1.0, so specify kNone for more optimal blending.
180 GrProcessorAnalysisCoverage coverage = fHelper.aaType() == GrAAType::kCoverage ?
181 GrProcessorAnalysisCoverage::kSingleChannel :
182 GrProcessorAnalysisCoverage::kNone;
183 auto result = fHelper.xpRequiresDstTexture(caps, clip, coverage, &quadColors);
Michael Ludwig69858532018-11-28 15:34:34 -0500184 // If there is a constant color after analysis, that means all of the quads should be set
185 // to the same color (even if they started out with different colors).
186 SkPMColor4f colorOverride;
187 if (quadColors.isConstant(&colorOverride)) {
188 for (int i = 0; i < fQuads.count(); ++i) {
189 fQuads[i].setColor(colorOverride);
190 }
191 }
192
193 return result;
194 }
195
196 FixedFunctionFlags fixedFunctionFlags() const override {
197 // Since the AA type of the whole primitive is kept consistent with the per edge AA flags
198 // the helper's fixed function flags are appropriate.
199 return fHelper.fixedFunctionFlags();
200 }
201
202 DEFINE_OP_CLASS_ID
203
204private:
205 // For GrFillRectOp::MakeSet's use of addQuad
206 // FIXME(reviewer): better to just make addQuad public?
207 friend std::unique_ptr<GrDrawOp> GrFillRectOp::MakeSet(GrContext* context, GrPaint&& paint,
208 GrAAType aaType, const SkMatrix& viewMatrix,
209 const GrRenderTargetContext::QuadSetEntry quads[], int quadCount,
210 const GrUserStencilSettings* stencilSettings);
211
212 void onPrepareDraws(Target* target) override {
213 TRACE_EVENT0("skia", TRACE_FUNC);
214
215 using Domain = GrQuadPerEdgeAA::Domain;
216 static constexpr SkRect kEmptyDomain = SkRect::MakeEmpty();
217
218 VertexSpec vertexSpec(this->deviceQuadType(),
219 fWideColor ? ColorType::kHalf : ColorType::kByte,
220 this->localQuadType(), fHelper.usesLocalCoords(), Domain::kNo,
221 fHelper.aaType());
222
Michael Ludwig467994d2018-12-03 14:58:31 +0000223 sk_sp<GrGeometryProcessor> gp = GrQuadPerEdgeAA::MakeProcessor(vertexSpec);
Michael Ludwig69858532018-11-28 15:34:34 -0500224 size_t vertexSize = gp->vertexStride();
225
226 const GrBuffer* vbuffer;
227 int vertexOffsetInBuffer = 0;
228
229 // Fill the allocated vertex data
230 void* vdata = target->makeVertexSpace(vertexSize, fQuads.count() * 4, &vbuffer,
231 &vertexOffsetInBuffer);
232 if (!vdata) {
233 SkDebugf("Could not allocate vertices\n");
234 return;
235 }
236
237 // vertices pointer advances through vdata based on Tessellate's return value
238 void* vertices = vdata;
239 for (int i = 0; i < fQuads.count(); ++i) {
240 const auto& q = fQuads[i];
241 vertices = GrQuadPerEdgeAA::Tessellate(vertices, vertexSpec, q.deviceQuad(), q.color(),
242 q.localQuad(), kEmptyDomain, q.aaFlags());
243 }
244
245 // Configure the mesh for the vertex data
246 GrMesh* mesh;
247 if (fQuads.count() > 1) {
248 mesh = target->allocMesh(GrPrimitiveType::kTriangles);
249 sk_sp<const GrBuffer> ibuffer = target->resourceProvider()->refQuadIndexBuffer();
250 if (!ibuffer) {
251 SkDebugf("Could not allocate quad indices\n");
252 return;
253 }
254 mesh->setIndexedPatterned(ibuffer.get(), 6, 4, fQuads.count(),
255 GrResourceProvider::QuadCountOfQuadBuffer());
256 } else {
257 mesh = target->allocMesh(GrPrimitiveType::kTriangleStrip);
258 mesh->setNonIndexedNonInstanced(4);
259 }
260 mesh->setVertexData(vbuffer, vertexOffsetInBuffer);
261
262 auto pipe = fHelper.makePipeline(target);
263 target->draw(std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
264 }
265
266 CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
267 TRACE_EVENT0("skia", TRACE_FUNC);
268 const auto* that = t->cast<FillRectOp>();
269
270 // Unlike most users of the draw op helper, this op can merge none-aa and coverage-aa
271 // draw ops together, so pass true as the last argument.
272 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds(), true)) {
273 return CombineResult::kCannotCombine;
274 }
275
276 // If the processor sets are compatible, the two ops are always compatible; it just needs
277 // to adjust the state of the op to be the more general quad and aa types of the two ops.
278
279 // The GrQuadType enum is ordered such that higher values are more general quad types
280 if (that->fDeviceQuadType > fDeviceQuadType) {
281 fDeviceQuadType = that->fDeviceQuadType;
282 }
283 if (that->fLocalQuadType > fLocalQuadType) {
284 fLocalQuadType = that->fLocalQuadType;
285 }
286 fClearCompatible &= that->fClearCompatible;
287 fWideColor |= that->fWideColor;
288
289 // The helper stores the aa type, but isCompatible(with true arg) allows the two ops' aa
290 // types to be none and coverage, in which case this op's aa type must be lifted to coverage
291 // so that quads with no aa edges can be batched with quads that have some/all edges aa'ed.
292 if (fHelper.aaType() == GrAAType::kNone && that->fHelper.aaType() == GrAAType::kCoverage) {
293 fHelper.setAAType(GrAAType::kCoverage);
294 }
295
296 fQuads.push_back_n(that->fQuads.count(), that->fQuads.begin());
297 return CombineResult::kMerged;
298 }
299
300 // Similar to onCombineIfPossible, but adds a quad assuming its op would have been compatible.
301 // But since it's avoiding the op list management, it must update the op's bounds. This is only
302 // used with quad sets, which uses the same view matrix for each quad so this assumes that the
303 // device quad type of the new quad is the same as the op's.
304 void addQuad(TransformedQuad&& quad, GrQuadType localQuadType, GrAAType aaType) {
305 SkASSERT(quad.deviceQuad().quadType() <= this->deviceQuadType());
306
307 // The new quad's aa type should be the same as the first quad's or none, except when the
308 // first quad's aa type was already downgraded to none, in which case the stored type must
309 // be lifted to back to the requested type.
310 if (aaType != fHelper.aaType()) {
311 if (aaType != GrAAType::kNone) {
312 // Original quad was downgraded to non-aa, lift back up to this quad's required type
313 SkASSERT(fHelper.aaType() == GrAAType::kNone);
314 fHelper.setAAType(aaType);
315 }
316 // else the new quad could have been downgraded but the other quads can't be, so don't
317 // reset the op's accumulated aa type.
318 }
319
320 // The new quad's local coordinates could differ
321 if (localQuadType > this->localQuadType()) {
322 fLocalQuadType = static_cast<unsigned>(localQuadType);
323 }
324
325 // clear compatible won't need to be updated, since device quad type and paint is the same,
326 // but this quad has a new color, so maybe update wide color
327 fWideColor |= !SkPMColor4fFitsInBytes(quad.color());
328
329 // Update the bounds and add the quad to this op's storage
330 SkRect newBounds = this->bounds();
331 newBounds.joinPossiblyEmptyRect(quad.deviceQuad().bounds());
332 this->setBounds(newBounds, HasAABloat(fHelper.aaType() == GrAAType::kCoverage),
333 IsZeroArea::kNo);
334 fQuads.push_back(std::move(quad));
335 }
336
337 GrQuadType deviceQuadType() const { return static_cast<GrQuadType>(fDeviceQuadType); }
338 GrQuadType localQuadType() const { return static_cast<GrQuadType>(fLocalQuadType); }
339
340 Helper fHelper;
341 SkSTArray<1, TransformedQuad, true> fQuads;
342
343 // While we always store full GrPerspQuads in memory, if the type is known to be simpler we can
344 // optimize our geometry generation.
345 unsigned fDeviceQuadType: 2;
346 unsigned fLocalQuadType: 2;
347 unsigned fWideColor: 1;
348
349 // True if fQuad produced by a rectangle-preserving view matrix, is pixel aligned or non-AA,
350 // and its paint is a constant blended color.
351 unsigned fClearCompatible: 1;
352
353 typedef GrMeshDrawOp INHERITED;
354};
355
356} // anonymous namespace
357
358namespace GrFillRectOp {
359
Michael Ludwig72ab3462018-12-10 12:43:36 -0500360std::unique_ptr<GrDrawOp> MakePerEdge(GrContext* context,
361 GrPaint&& paint,
362 GrAAType aaType,
363 GrQuadAAFlags edgeAA,
364 const SkMatrix& viewMatrix,
365 const SkRect& rect,
366 const GrUserStencilSettings* stencilSettings) {
Michael Ludwig69858532018-11-28 15:34:34 -0500367 return FillRectOp::Make(context, std::move(paint), aaType, edgeAA, stencilSettings,
368 GrPerspQuad(rect, viewMatrix), GrQuadTypeForTransformedRect(viewMatrix),
369 GrPerspQuad(rect, SkMatrix::I()), GrQuadType::kRect);
370}
371
Michael Ludwig72ab3462018-12-10 12:43:36 -0500372std::unique_ptr<GrDrawOp> MakePerEdgeWithLocalMatrix(GrContext* context,
373 GrPaint&& paint,
374 GrAAType aaType,
375 GrQuadAAFlags edgeAA,
376 const SkMatrix& viewMatrix,
377 const SkMatrix& localMatrix,
378 const SkRect& rect,
379 const GrUserStencilSettings* stencilSettings) {
Michael Ludwig69858532018-11-28 15:34:34 -0500380 GrQuadType localQuadType = GrQuadTypeForTransformedRect(localMatrix);
381 return FillRectOp::Make(context, std::move(paint), aaType, edgeAA, stencilSettings,
382 GrPerspQuad(rect, viewMatrix), GrQuadTypeForTransformedRect(viewMatrix),
383 GrPerspQuad(rect, localMatrix), localQuadType);
384}
385
Michael Ludwig72ab3462018-12-10 12:43:36 -0500386std::unique_ptr<GrDrawOp> MakePerEdgeWithLocalRect(GrContext* context,
387 GrPaint&& paint,
388 GrAAType aaType,
389 GrQuadAAFlags edgeAA,
390 const SkMatrix& viewMatrix,
391 const SkRect& rect,
392 const SkRect& localRect,
393 const GrUserStencilSettings* stencilSettings) {
Michael Ludwig69858532018-11-28 15:34:34 -0500394 return FillRectOp::Make(context, std::move(paint), aaType, edgeAA, stencilSettings,
395 GrPerspQuad(rect, viewMatrix), GrQuadTypeForTransformedRect(viewMatrix),
396 GrPerspQuad(localRect, SkMatrix::I()), GrQuadType::kRect);
397}
398
399std::unique_ptr<GrDrawOp> MakeSet(GrContext* context,
400 GrPaint&& paint,
401 GrAAType aaType,
402 const SkMatrix& viewMatrix,
403 const GrRenderTargetContext::QuadSetEntry quads[],
404 int cnt,
405 const GrUserStencilSettings* stencilSettings) {
406 // First make a draw op for the first quad in the set
407 SkASSERT(cnt > 0);
408 GrQuadType deviceQuadType = GrQuadTypeForTransformedRect(viewMatrix);
409
410 paint.setColor4f(quads[0].fColor);
411 std::unique_ptr<GrDrawOp> op = FillRectOp::Make(context, std::move(paint), aaType,
412 quads[0].fAAFlags, stencilSettings, GrPerspQuad(quads[0].fRect, viewMatrix),
413 deviceQuadType, GrPerspQuad(quads[0].fRect, quads[0].fLocalMatrix),
414 GrQuadTypeForTransformedRect(quads[0].fLocalMatrix));
415 auto* fillRects = op->cast<FillRectOp>();
416
417 // Accumulate remaining quads similar to onCombineIfPossible() without creating an op
418 for (int i = 1; i < cnt; ++i) {
419 GrPerspQuad deviceQuad(quads[i].fRect, viewMatrix);
420
421 GrAAType resolvedAA;
422 GrQuadAAFlags resolvedEdgeFlags;
423 GrResolveAATypeForQuad(aaType, quads[i].fAAFlags, deviceQuad, deviceQuadType,
424 &resolvedAA, &resolvedEdgeFlags);
425
426 fillRects->addQuad({ deviceQuad, GrPerspQuad(quads[i].fRect, quads[i].fLocalMatrix),
427 quads[i].fColor, resolvedEdgeFlags },
428 GrQuadTypeForTransformedRect(quads[i].fLocalMatrix), resolvedAA);
429 }
430
431 return op;
432}
433
Michael Ludwig72ab3462018-12-10 12:43:36 -0500434std::unique_ptr<GrDrawOp> Make(GrContext* context,
435 GrPaint&& paint,
436 GrAAType aaType,
437 const SkMatrix& viewMatrix,
438 const SkRect& rect,
439 const GrUserStencilSettings* stencil) {
440 return MakePerEdge(context, std::move(paint), aaType,
441 aaType == GrAAType::kCoverage ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone,
442 viewMatrix, rect, stencil);
443}
444
445std::unique_ptr<GrDrawOp> MakeWithLocalMatrix(GrContext* context,
446 GrPaint&& paint,
447 GrAAType aaType,
448 const SkMatrix& viewMatrix,
449 const SkMatrix& localMatrix,
450 const SkRect& rect,
451 const GrUserStencilSettings* stencil) {
452 return MakePerEdgeWithLocalMatrix(context, std::move(paint), aaType,
453 aaType == GrAAType::kCoverage ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone,
454 viewMatrix, localMatrix, rect, stencil);
455}
456
457std::unique_ptr<GrDrawOp> MakeWithLocalRect(GrContext* context,
458 GrPaint&& paint,
459 GrAAType aaType,
460 const SkMatrix& viewMatrix,
461 const SkRect& rect,
462 const SkRect& localRect,
463 const GrUserStencilSettings* stencil) {
464 return MakePerEdgeWithLocalRect(context, std::move(paint), aaType,
465 aaType == GrAAType::kCoverage ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone,
466 viewMatrix, rect, localRect, stencil);
467}
468
Michael Ludwig69858532018-11-28 15:34:34 -0500469} // namespace GrFillRectOp
470
471#if GR_TEST_UTILS
472
473#include "GrDrawOpTest.h"
474#include "SkGr.h"
475
476GR_DRAW_OP_TEST_DEFINE(FillRectOp) {
477 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
478 SkRect rect = GrTest::TestRect(random);
479
480 GrAAType aaType = GrAAType::kNone;
481 if (random->nextBool()) {
482 aaType = (fsaaType == GrFSAAType::kUnifiedMSAA) ? GrAAType::kMSAA : GrAAType::kCoverage;
483 }
484 const GrUserStencilSettings* stencil = random->nextBool() ? nullptr
485 : GrGetRandomStencil(random, context);
486
487 GrQuadAAFlags aaFlags = GrQuadAAFlags::kNone;
488 aaFlags |= random->nextBool() ? GrQuadAAFlags::kLeft : GrQuadAAFlags::kNone;
489 aaFlags |= random->nextBool() ? GrQuadAAFlags::kTop : GrQuadAAFlags::kNone;
490 aaFlags |= random->nextBool() ? GrQuadAAFlags::kRight : GrQuadAAFlags::kNone;
491 aaFlags |= random->nextBool() ? GrQuadAAFlags::kBottom : GrQuadAAFlags::kNone;
492
493 if (random->nextBool()) {
494 if (random->nextBool()) {
495 if (random->nextBool()) {
496 // Local matrix with a set op
497 uint32_t extraQuadCt = random->nextRangeU(1, 4);
498 SkTArray<GrRenderTargetContext::QuadSetEntry> quads(extraQuadCt + 1);
499 quads.push_back(
500 {rect, SkPMColor4f::FromBytes_RGBA(SkColorToPremulGrColor(random->nextU())),
501 GrTest::TestMatrixInvertible(random), aaFlags});
502 for (uint32_t i = 0; i < extraQuadCt; ++i) {
503 GrQuadAAFlags aaFlags = GrQuadAAFlags::kNone;
504 aaFlags |= random->nextBool() ? GrQuadAAFlags::kLeft : GrQuadAAFlags::kNone;
505 aaFlags |= random->nextBool() ? GrQuadAAFlags::kTop : GrQuadAAFlags::kNone;
506 aaFlags |= random->nextBool() ? GrQuadAAFlags::kRight : GrQuadAAFlags::kNone;
507 aaFlags |= random->nextBool() ? GrQuadAAFlags::kBottom : GrQuadAAFlags::kNone;
508
509 quads.push_back(
510 {GrTest::TestRect(random),
511 SkPMColor4f::FromBytes_RGBA(SkColorToPremulGrColor(random->nextU())),
512 GrTest::TestMatrixInvertible(random), aaFlags});
513 }
514
515 return GrFillRectOp::MakeSet(context, std::move(paint), aaType, viewMatrix,
516 quads.begin(), quads.count(), stencil);
517 } else {
518 // Single local matrix
519 SkMatrix localMatrix = GrTest::TestMatrixInvertible(random);
Michael Ludwig72ab3462018-12-10 12:43:36 -0500520 return GrFillRectOp::MakePerEdgeWithLocalMatrix(context, std::move(paint), aaType,
521 aaFlags, viewMatrix, localMatrix,
522 rect, stencil);
Michael Ludwig69858532018-11-28 15:34:34 -0500523 }
524 } else {
525 // Pass local rect directly
526 SkRect localRect = GrTest::TestRect(random);
Michael Ludwig72ab3462018-12-10 12:43:36 -0500527 return GrFillRectOp::MakePerEdgeWithLocalRect(context, std::move(paint), aaType,
528 aaFlags, viewMatrix, rect, localRect,
529 stencil);
Michael Ludwig69858532018-11-28 15:34:34 -0500530 }
531 } else {
532 // The simplest constructor
Michael Ludwig72ab3462018-12-10 12:43:36 -0500533 return GrFillRectOp::MakePerEdge(context, std::move(paint), aaType, aaFlags, viewMatrix,
534 rect, stencil);
Michael Ludwig69858532018-11-28 15:34:34 -0500535 }
536}
537
538#endif