blob: 07994aa51051e509e8cca9b3937851f64bc1d19e [file] [log] [blame]
joshualitt9c80b5f2015-08-13 10:05:51 -07001/*
Brian Salomonac70f842017-05-08 10:43:33 -04002 * Copyright 2017 Google Inc.
joshualitt9c80b5f2015-08-13 10:05:51 -07003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Brian Salomonac70f842017-05-08 10:43:33 -04008#include "GrAppliedClip.h"
joshualitt9c80b5f2015-08-13 10:05:51 -07009#include "GrColor.h"
10#include "GrDefaultGeoProcFactory.h"
Brian Salomon17726632017-05-12 14:09:46 -040011#include "GrDrawOpTest.h"
Brian Salomondad29232016-12-01 16:40:24 -050012#include "GrMeshDrawOp.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050013#include "GrOpFlushState.h"
joshualitt9c80b5f2015-08-13 10:05:51 -070014#include "GrPrimitiveProcessor.h"
joshualittae5b2c62015-08-19 08:48:41 -070015#include "GrQuad.h"
Brian Salomonbaaf4392017-06-15 09:59:23 -040016#include "GrRectOpFactory.h"
Brian Salomondad29232016-12-01 16:40:24 -050017#include "GrResourceProvider.h"
Brian Salomonac70f842017-05-08 10:43:33 -040018#include "GrSimpleMeshDrawOpHelper.h"
reeda39667c2016-08-22 06:39:49 -070019#include "SkMatrixPriv.h"
20
Brian Salomonac70f842017-05-08 10:43:33 -040021static const int kVertsPerRect = 4;
22static const int kIndicesPerRect = 6;
joshualitt2244c272015-08-21 10:33:15 -070023
Brian Salomon53e4c3c2016-12-21 11:38:53 -050024/** We always use per-vertex colors so that rects can be combined across color changes. Sometimes
joshualitt2244c272015-08-21 10:33:15 -070025 we have explicit local coords and sometimes not. We *could* always provide explicit local
26 coords and just duplicate the positions when the caller hasn't provided a local coord rect,
27 but we haven't seen a use case which frequently switches between local rect and no local
28 rect draws.
29
30 The vertex attrib order is always pos, color, [local coords].
31 */
Brian Salomon8c852be2017-01-04 10:44:42 -050032static sk_sp<GrGeometryProcessor> make_gp() {
robertphillips6abd1d12016-07-01 09:06:56 -070033 using namespace GrDefaultGeoProcFactory;
Brian Salomon3de0aee2017-01-29 09:34:17 -050034 return GrDefaultGeoProcFactory::Make(Color::kPremulGrColorAttribute_Type, Coverage::kSolid_Type,
Brian Salomon8c852be2017-01-04 10:44:42 -050035 LocalCoords::kHasExplicit_Type, SkMatrix::I());
robertphillips6abd1d12016-07-01 09:06:56 -070036}
37
Brian Salomonac70f842017-05-08 10:43:33 -040038static sk_sp<GrGeometryProcessor> make_perspective_gp(const SkMatrix& viewMatrix,
39 bool hasExplicitLocalCoords,
40 const SkMatrix* localMatrix) {
41 SkASSERT(viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPerspective()));
42
43 using namespace GrDefaultGeoProcFactory;
44
45 // If we have perspective on the viewMatrix then we won't map on the CPU, nor will we map
46 // the local rect on the cpu (in case the localMatrix also has perspective).
47 // Otherwise, if we have a local rect, then we apply the localMatrix directly to the localRect
48 // to generate vertex local coords
49 if (viewMatrix.hasPerspective()) {
50 LocalCoords localCoords(hasExplicitLocalCoords ? LocalCoords::kHasExplicit_Type
51 : LocalCoords::kUsePosition_Type,
52 localMatrix);
53 return GrDefaultGeoProcFactory::Make(Color::kPremulGrColorAttribute_Type,
54 Coverage::kSolid_Type, localCoords, viewMatrix);
55 } else if (hasExplicitLocalCoords) {
56 LocalCoords localCoords(LocalCoords::kHasExplicit_Type, localMatrix);
57 return GrDefaultGeoProcFactory::Make(Color::kPremulGrColorAttribute_Type,
58 Coverage::kSolid_Type, localCoords, SkMatrix::I());
59 } else {
60 LocalCoords localCoords(LocalCoords::kUsePosition_Type, localMatrix);
61 return GrDefaultGeoProcFactory::MakeForDeviceSpace(Color::kPremulGrColorAttribute_Type,
62 Coverage::kSolid_Type, localCoords,
63 viewMatrix);
64 }
65}
66
joshualitt2244c272015-08-21 10:33:15 -070067static void tesselate(intptr_t vertices,
68 size_t vertexStride,
69 GrColor color,
robertphillips6abd1d12016-07-01 09:06:56 -070070 const SkMatrix* viewMatrix,
joshualitt2244c272015-08-21 10:33:15 -070071 const SkRect& rect,
joshualitt8cce8f12015-08-26 06:23:39 -070072 const GrQuad* localQuad) {
joshualitt2244c272015-08-21 10:33:15 -070073 SkPoint* positions = reinterpret_cast<SkPoint*>(vertices);
74
Brian Salomon6a639042016-12-14 11:08:17 -050075 positions->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vertexStride);
joshualitt2244c272015-08-21 10:33:15 -070076
robertphillips6abd1d12016-07-01 09:06:56 -070077 if (viewMatrix) {
Brian Salomonac70f842017-05-08 10:43:33 -040078 SkMatrixPriv::MapPointsWithStride(*viewMatrix, positions, vertexStride, kVertsPerRect);
joshualitt8cce8f12015-08-26 06:23:39 -070079 }
80
81 // Setup local coords
joshualitt2244c272015-08-21 10:33:15 -070082 // TODO we should only do this if local coords are being read
joshualitt8cce8f12015-08-26 06:23:39 -070083 if (localQuad) {
joshualitt2244c272015-08-21 10:33:15 -070084 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
Brian Salomonac70f842017-05-08 10:43:33 -040085 for (int i = 0; i < kVertsPerRect; i++) {
Brian Salomon6a639042016-12-14 11:08:17 -050086 SkPoint* coords =
87 reinterpret_cast<SkPoint*>(vertices + kLocalOffset + i * vertexStride);
joshualitt8cce8f12015-08-26 06:23:39 -070088 *coords = localQuad->point(i);
joshualitt2244c272015-08-21 10:33:15 -070089 }
90 }
91
92 static const int kColorOffset = sizeof(SkPoint);
93 GrColor* vertColor = reinterpret_cast<GrColor*>(vertices + kColorOffset);
94 for (int j = 0; j < 4; ++j) {
95 *vertColor = color;
Brian Salomon6a639042016-12-14 11:08:17 -050096 vertColor = (GrColor*)((intptr_t)vertColor + vertexStride);
joshualitt2244c272015-08-21 10:33:15 -070097 }
98}
99
Brian Salomonac70f842017-05-08 10:43:33 -0400100namespace {
bsalomon08d14152016-06-30 12:45:18 -0700101
Brian Salomonac70f842017-05-08 10:43:33 -0400102class NonAAFillRectOp final : public GrMeshDrawOp {
103private:
104 using Helper = GrSimpleMeshDrawOpHelperWithStencil;
105
106public:
107 static std::unique_ptr<GrDrawOp> Make(GrPaint&& paint, const SkMatrix& viewMatrix,
108 const SkRect& rect, const SkRect* localRect,
109 const SkMatrix* localMatrix, GrAAType aaType,
110 const GrUserStencilSettings* stencilSettings) {
111 SkASSERT(GrAAType::kCoverage != aaType);
112 return Helper::FactoryHelper<NonAAFillRectOp>(std::move(paint), viewMatrix, rect, localRect,
113 localMatrix, aaType, stencilSettings);
114 }
115
116 NonAAFillRectOp() = delete;
117
118 NonAAFillRectOp(const Helper::MakeArgs& args, GrColor color, const SkMatrix& viewMatrix,
119 const SkRect& rect, const SkRect* localRect, const SkMatrix* localMatrix,
120 GrAAType aaType, const GrUserStencilSettings* stencilSettings)
121 : INHERITED(ClassID()), fHelper(args, aaType, stencilSettings) {
Chris Dalton1d616352017-05-31 12:51:23 -0600122
Brian Salomon6a639042016-12-14 11:08:17 -0500123 SkASSERT(!viewMatrix.hasPerspective() && (!localMatrix || !localMatrix->hasPerspective()));
bsalomon9d7f1842016-07-01 08:01:36 -0700124 RectInfo& info = fRects.push_back();
125 info.fColor = color;
126 info.fViewMatrix = viewMatrix;
127 info.fRect = rect;
128 if (localRect && localMatrix) {
129 info.fLocalQuad.setFromMappedRect(*localRect, *localMatrix);
130 } else if (localRect) {
131 info.fLocalQuad.set(*localRect);
132 } else if (localMatrix) {
133 info.fLocalQuad.setFromMappedRect(rect, *localMatrix);
134 } else {
135 info.fLocalQuad.set(rect);
136 }
bsalomon88cf17d2016-07-08 06:40:56 -0700137 this->setTransformedBounds(fRects[0].fRect, viewMatrix, HasAABloat::kNo, IsZeroArea::kNo);
bsalomon9d7f1842016-07-01 08:01:36 -0700138 }
bsalomon08d14152016-06-30 12:45:18 -0700139
Brian Salomon6a639042016-12-14 11:08:17 -0500140 const char* name() const override { return "NonAAFillRectOp"; }
bsalomon08d14152016-06-30 12:45:18 -0700141
142 SkString dumpInfo() const override {
143 SkString str;
Brian Salomonac70f842017-05-08 10:43:33 -0400144 str.append(GrMeshDrawOp::dumpInfo());
Brian Salomon53e4c3c2016-12-21 11:38:53 -0500145 str.appendf("# combined: %d\n", fRects.count());
bsalomon9d7f1842016-07-01 08:01:36 -0700146 for (int i = 0; i < fRects.count(); ++i) {
147 const RectInfo& info = fRects[i];
Brian Salomon6a639042016-12-14 11:08:17 -0500148 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", i,
149 info.fColor, info.fRect.fLeft, info.fRect.fTop, info.fRect.fRight,
150 info.fRect.fBottom);
bsalomon08d14152016-06-30 12:45:18 -0700151 }
Brian Salomon82dfd3d2017-06-14 12:30:35 -0400152 str += fHelper.dumpInfo();
153 str += INHERITED::dumpInfo();
bsalomon08d14152016-06-30 12:45:18 -0700154 return str;
155 }
156
Brian Salomonf86d37b2017-06-16 10:04:34 -0400157 RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
Brian Salomonac70f842017-05-08 10:43:33 -0400158 GrColor* color = &fRects.front().fColor;
159 return fHelper.xpRequiresDstTexture(caps, clip, GrProcessorAnalysisCoverage::kNone, color);
160 }
161
162 FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
163
164 DEFINE_OP_CLASS_ID
165
bsalomon08d14152016-06-30 12:45:18 -0700166private:
Brian Salomon91326c32017-08-09 16:02:19 -0400167 void onPrepareDraws(Target* target) override {
Brian Salomon8c852be2017-01-04 10:44:42 -0500168 sk_sp<GrGeometryProcessor> gp = make_gp();
bsalomon08d14152016-06-30 12:45:18 -0700169 if (!gp) {
170 SkDebugf("Couldn't create GrGeometryProcessor\n");
171 return;
172 }
bsalomonbc9b6a42016-07-01 05:35:51 -0700173 SkASSERT(gp->getVertexStride() ==
174 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr));
bsalomon08d14152016-06-30 12:45:18 -0700175
176 size_t vertexStride = gp->getVertexStride();
Brian Salomonac70f842017-05-08 10:43:33 -0400177 int rectCount = fRects.count();
bsalomon08d14152016-06-30 12:45:18 -0700178
Hal Canary144caf52016-11-07 17:57:18 -0500179 sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer());
Chris Dalton3809bab2017-06-13 10:55:06 -0600180 PatternHelper helper(GrPrimitiveType::kTriangles);
Chris Daltonbca46e22017-05-15 11:03:26 -0600181 void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect,
182 kIndicesPerRect, rectCount);
bsalomon08d14152016-06-30 12:45:18 -0700183 if (!vertices || !indexBuffer) {
184 SkDebugf("Could not allocate vertices\n");
185 return;
186 }
187
Brian Salomonac70f842017-05-08 10:43:33 -0400188 for (int i = 0; i < rectCount; i++) {
Brian Salomon6a639042016-12-14 11:08:17 -0500189 intptr_t verts =
Brian Salomonac70f842017-05-08 10:43:33 -0400190 reinterpret_cast<intptr_t>(vertices) + i * kVertsPerRect * vertexStride;
robertphillips6abd1d12016-07-01 09:06:56 -0700191 tesselate(verts, vertexStride, fRects[i].fColor, &fRects[i].fViewMatrix,
bsalomon9d7f1842016-07-01 08:01:36 -0700192 fRects[i].fRect, &fRects[i].fLocalQuad);
bsalomon08d14152016-06-30 12:45:18 -0700193 }
Brian Salomonac70f842017-05-08 10:43:33 -0400194 helper.recordDraw(target, gp.get(), fHelper.makePipeline(target));
bsalomon08d14152016-06-30 12:45:18 -0700195 }
196
Brian Salomon25a88092016-12-01 09:36:50 -0500197 bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
Brian Salomon6a639042016-12-14 11:08:17 -0500198 NonAAFillRectOp* that = t->cast<NonAAFillRectOp>();
Brian Salomonac70f842017-05-08 10:43:33 -0400199 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
bsalomon08d14152016-06-30 12:45:18 -0700200 return false;
201 }
bsalomon9d7f1842016-07-01 08:01:36 -0700202 fRects.push_back_n(that->fRects.count(), that->fRects.begin());
bsalomon88cf17d2016-07-08 06:40:56 -0700203 this->joinBounds(*that);
bsalomon08d14152016-06-30 12:45:18 -0700204 return true;
205 }
206
bsalomon9d7f1842016-07-01 08:01:36 -0700207 struct RectInfo {
208 GrColor fColor;
209 SkMatrix fViewMatrix;
210 SkRect fRect;
211 GrQuad fLocalQuad;
212 };
213
Brian Salomonac70f842017-05-08 10:43:33 -0400214 Helper fHelper;
bsalomon9d7f1842016-07-01 08:01:36 -0700215 SkSTArray<1, RectInfo, true> fRects;
Brian Salomonac70f842017-05-08 10:43:33 -0400216 typedef GrMeshDrawOp INHERITED;
joshualitt2244c272015-08-21 10:33:15 -0700217};
218
Brian Salomonac70f842017-05-08 10:43:33 -0400219// We handle perspective in the local matrix or viewmatrix with special ops.
220class NonAAFillRectPerspectiveOp final : public GrMeshDrawOp {
221private:
222 using Helper = GrSimpleMeshDrawOpHelperWithStencil;
223
224public:
225 static std::unique_ptr<GrDrawOp> Make(GrPaint&& paint, const SkMatrix& viewMatrix,
226 const SkRect& rect, const SkRect* localRect,
227 const SkMatrix* localMatrix, GrAAType aaType,
228 const GrUserStencilSettings* stencilSettings) {
229 SkASSERT(GrAAType::kCoverage != aaType);
230 return Helper::FactoryHelper<NonAAFillRectPerspectiveOp>(std::move(paint), viewMatrix, rect,
231 localRect, localMatrix, aaType,
232 stencilSettings);
233 }
234
235 NonAAFillRectPerspectiveOp() = delete;
236
237 NonAAFillRectPerspectiveOp(const Helper::MakeArgs& args, GrColor color,
238 const SkMatrix& viewMatrix, const SkRect& rect,
239 const SkRect* localRect, const SkMatrix* localMatrix,
240 GrAAType aaType, const GrUserStencilSettings* stencilSettings)
241 : INHERITED(ClassID())
242 , fHelper(args, aaType, stencilSettings)
243 , fViewMatrix(viewMatrix) {
244 SkASSERT(viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPerspective()));
245 RectInfo& info = fRects.push_back();
246 info.fColor = color;
247 info.fRect = rect;
248 fHasLocalRect = SkToBool(localRect);
249 fHasLocalMatrix = SkToBool(localMatrix);
250 if (fHasLocalMatrix) {
251 fLocalMatrix = *localMatrix;
252 }
253 if (fHasLocalRect) {
254 info.fLocalRect = *localRect;
255 }
256 this->setTransformedBounds(rect, viewMatrix, HasAABloat::kNo, IsZeroArea::kNo);
257 }
258
259 const char* name() const override { return "NonAAFillRectPerspectiveOp"; }
260
261 SkString dumpInfo() const override {
262 SkString str;
263 str.appendf("# combined: %d\n", fRects.count());
264 for (int i = 0; i < fRects.count(); ++i) {
265 const RectInfo& geo = fRects[0];
266 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", i,
267 geo.fColor, geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight,
268 geo.fRect.fBottom);
269 }
Brian Salomon82dfd3d2017-06-14 12:30:35 -0400270 str += fHelper.dumpInfo();
271 str += INHERITED::dumpInfo();
Brian Salomonac70f842017-05-08 10:43:33 -0400272 return str;
273 }
274
Brian Salomonf86d37b2017-06-16 10:04:34 -0400275 RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
Brian Salomonac70f842017-05-08 10:43:33 -0400276 GrColor* color = &fRects.front().fColor;
277 return fHelper.xpRequiresDstTexture(caps, clip, GrProcessorAnalysisCoverage::kNone, color);
278 }
279
280 FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
281
282 DEFINE_OP_CLASS_ID
283
284private:
Brian Salomon91326c32017-08-09 16:02:19 -0400285 void onPrepareDraws(Target* target) override {
Brian Salomonac70f842017-05-08 10:43:33 -0400286 sk_sp<GrGeometryProcessor> gp = make_perspective_gp(
287 fViewMatrix, fHasLocalRect, fHasLocalMatrix ? &fLocalMatrix : nullptr);
288 if (!gp) {
289 SkDebugf("Couldn't create GrGeometryProcessor\n");
290 return;
291 }
292 SkASSERT(fHasLocalRect
293 ? gp->getVertexStride() ==
294 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)
295 : gp->getVertexStride() ==
296 sizeof(GrDefaultGeoProcFactory::PositionColorAttr));
297
298 size_t vertexStride = gp->getVertexStride();
299 int rectCount = fRects.count();
300
301 sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer());
Chris Dalton3809bab2017-06-13 10:55:06 -0600302 PatternHelper helper(GrPrimitiveType::kTriangles);
Chris Daltonbca46e22017-05-15 11:03:26 -0600303 void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect,
304 kIndicesPerRect, rectCount);
Brian Salomonac70f842017-05-08 10:43:33 -0400305 if (!vertices || !indexBuffer) {
306 SkDebugf("Could not allocate vertices\n");
307 return;
308 }
309
310 for (int i = 0; i < rectCount; i++) {
311 const RectInfo& info = fRects[i];
312 intptr_t verts =
313 reinterpret_cast<intptr_t>(vertices) + i * kVertsPerRect * vertexStride;
314 if (fHasLocalRect) {
315 GrQuad quad(info.fLocalRect);
316 tesselate(verts, vertexStride, info.fColor, nullptr, info.fRect, &quad);
317 } else {
318 tesselate(verts, vertexStride, info.fColor, nullptr, info.fRect, nullptr);
319 }
320 }
321 helper.recordDraw(target, gp.get(), fHelper.makePipeline(target));
322 }
323
324 bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
325 NonAAFillRectPerspectiveOp* that = t->cast<NonAAFillRectPerspectiveOp>();
326 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
327 return false;
328 }
329
330 // We could combine across perspective vm changes if we really wanted to.
331 if (!fViewMatrix.cheapEqualTo(that->fViewMatrix)) {
332 return false;
333 }
334 if (fHasLocalRect != that->fHasLocalRect) {
335 return false;
336 }
337 if (fHasLocalMatrix && !fLocalMatrix.cheapEqualTo(that->fLocalMatrix)) {
338 return false;
339 }
340
341 fRects.push_back_n(that->fRects.count(), that->fRects.begin());
342 this->joinBounds(*that);
343 return true;
344 }
345
346 struct RectInfo {
347 SkRect fRect;
348 GrColor fColor;
349 SkRect fLocalRect;
350 };
351
352 SkSTArray<1, RectInfo, true> fRects;
353 Helper fHelper;
354 bool fHasLocalMatrix;
355 bool fHasLocalRect;
356 SkMatrix fLocalMatrix;
357 SkMatrix fViewMatrix;
358
359 typedef GrMeshDrawOp INHERITED;
360};
361
362} // anonymous namespace
363
Brian Salomonbaaf4392017-06-15 09:59:23 -0400364namespace GrRectOpFactory {
bsalomonb8cbd202016-06-30 13:09:48 -0700365
Brian Salomonbaaf4392017-06-15 09:59:23 -0400366std::unique_ptr<GrDrawOp> MakeNonAAFill(GrPaint&& paint, const SkMatrix& viewMatrix,
367 const SkRect& rect, GrAAType aaType,
368 const GrUserStencilSettings* stencilSettings) {
369 if (viewMatrix.hasPerspective()) {
370 return NonAAFillRectPerspectiveOp::Make(std::move(paint), viewMatrix, rect, nullptr,
371 nullptr, aaType, stencilSettings);
Brian Salomon1ec03f32017-06-14 09:49:26 -0400372 } else {
Brian Salomonbaaf4392017-06-15 09:59:23 -0400373 return NonAAFillRectOp::Make(std::move(paint), viewMatrix, rect, nullptr, nullptr, aaType,
374 stencilSettings);
Brian Salomon1ec03f32017-06-14 09:49:26 -0400375 }
376}
377
Brian Salomonbaaf4392017-06-15 09:59:23 -0400378std::unique_ptr<GrDrawOp> MakeNonAAFillWithLocalMatrix(
379 GrPaint&& paint, const SkMatrix& viewMatrix, const SkMatrix& localMatrix,
380 const SkRect& rect, GrAAType aaType, const GrUserStencilSettings* stencilSettings) {
381 if (viewMatrix.hasPerspective() || localMatrix.hasPerspective()) {
382 return NonAAFillRectPerspectiveOp::Make(std::move(paint), viewMatrix, rect, nullptr,
383 &localMatrix, aaType, stencilSettings);
384 } else {
385 return NonAAFillRectOp::Make(std::move(paint), viewMatrix, rect, nullptr, &localMatrix,
386 aaType, stencilSettings);
387 }
388}
389
390std::unique_ptr<GrDrawOp> MakeNonAAFillWithLocalRect(GrPaint&& paint, const SkMatrix& viewMatrix,
391 const SkRect& rect, const SkRect& localRect,
392 GrAAType aaType) {
393 if (viewMatrix.hasPerspective()) {
394 return NonAAFillRectPerspectiveOp::Make(std::move(paint), viewMatrix, rect, &localRect,
395 nullptr, aaType, nullptr);
396 } else {
397 return NonAAFillRectOp::Make(std::move(paint), viewMatrix, rect, &localRect, nullptr,
398 aaType, nullptr);
399 }
400}
401
402} // namespace GrRectOpFactory
joshualitt9c80b5f2015-08-13 10:05:51 -0700403
404///////////////////////////////////////////////////////////////////////////////////////////////////
Brian Salomon17726632017-05-12 14:09:46 -0400405
Brian Salomon0c26a9d2017-07-06 10:09:38 -0400406#if GR_TEST_UTILS
407
Brian Salomon17726632017-05-12 14:09:46 -0400408GR_DRAW_OP_TEST_DEFINE(NonAAFillRectOp) {
409 SkRect rect = GrTest::TestRect(random);
410 SkRect localRect = GrTest::TestRect(random);
411 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
412 SkMatrix localMatrix = GrTest::TestMatrix(random);
Brian Salomon17726632017-05-12 14:09:46 -0400413 const GrUserStencilSettings* stencil = GrGetRandomStencil(random, context);
414 GrAAType aaType = GrAAType::kNone;
415 if (fsaaType == GrFSAAType::kUnifiedMSAA) {
416 aaType = random->nextBool() ? GrAAType::kMSAA : GrAAType::kNone;
417 }
Brian Salomonbaaf4392017-06-15 09:59:23 -0400418 const SkRect* lr = random->nextBool() ? &localRect : nullptr;
419 const SkMatrix* lm = random->nextBool() ? &localMatrix : nullptr;
420 if (viewMatrix.hasPerspective() || (lm && lm->hasPerspective())) {
421 return NonAAFillRectPerspectiveOp::Make(std::move(paint), viewMatrix, rect, lr, lm, aaType,
422 stencil);
423 } else {
424 return NonAAFillRectOp::Make(std::move(paint), viewMatrix, rect, lr, lm, aaType, stencil);
425 }
Brian Salomon17726632017-05-12 14:09:46 -0400426}
Brian Salomon0c26a9d2017-07-06 10:09:38 -0400427
428#endif