blob: 43b9b38477769393da038a3edb750682476d1374 [file] [log] [blame]
commit-bot@chromium.org78a10782013-08-21 19:27:48 +00001/*
2 * Copyright 2013 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
Greg Daniel7ef28f32017-04-20 16:41:55 +00008#include "GrBackendSurface.h"
Robert Phillips646f6372018-09-25 09:31:10 -04009#include "GrClip.h"
bsalomon682c2692015-05-22 14:01:46 -070010#include "GrContextOptions.h"
Chris Daltonfe199b72017-05-05 11:26:15 -040011#include "GrContextPriv.h"
Brian Salomon2ee084e2016-12-16 18:59:19 -050012#include "GrDrawOpAtlas.h"
robertphillips77a2e522015-10-17 07:43:27 -070013#include "GrDrawingManager.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040014#include "GrGpu.h"
bsalomon3582d3e2015-02-13 14:20:05 -080015#include "GrGpuResourceCacheAccess.h"
Robert Phillipsc994a932018-06-19 13:09:54 -040016#include "GrMemoryPool.h"
Brian Salomon17726632017-05-12 14:09:46 -040017#include "GrRenderTargetContext.h"
Brian Salomon2ee084e2016-12-16 18:59:19 -050018#include "GrRenderTargetContextPriv.h"
csmartdaltonf9635992016-08-10 11:09:07 -070019#include "GrRenderTargetProxy.h"
bsalomon0ea80f42015-02-11 10:49:59 -080020#include "GrResourceCache.h"
Greg Daniel6be35232017-03-01 17:01:09 -050021#include "GrSemaphore.h"
Brian Salomon17726632017-05-12 14:09:46 -040022#include "GrSurfaceContextPriv.h"
Robert Phillips646e4292017-06-13 12:44:56 -040023#include "GrTexture.h"
Brian Osman3b655982017-03-07 16:58:08 -050024#include "SkGr.h"
Robert Phillips22f4a1f2016-12-20 08:57:26 -050025#include "SkImage_Gpu.h"
halcanary4dbbd042016-06-07 17:21:10 -070026#include "SkMathPriv.h"
mtkleinb9eb4ac2015-02-02 18:26:03 -080027#include "SkString.h"
Hal Canaryc640d0d2018-06-13 09:59:02 -040028#include "SkTo.h"
Chris Dalton4da70192018-06-18 09:51:36 -060029#include "ccpr/GrCoverageCountingPathRenderer.h"
Chris Dalton351e80c2019-01-06 22:51:00 -070030#include "ccpr/GrCCPathCache.h"
Brian Salomon17726632017-05-12 14:09:46 -040031#include "ops/GrMeshDrawOp.h"
Robert Phillipsc4039ea2018-03-01 11:36:45 -050032#include "text/GrGlyphCache.h"
joshualitte8042922015-12-11 06:11:21 -080033#include "text/GrTextBlobCache.h"
Hal Canary8a001442018-09-19 11:31:27 -040034
Hal Canaryc640d0d2018-06-13 09:59:02 -040035#include <algorithm>
joshualitte8042922015-12-11 06:11:21 -080036
Robert Phillipseaa86252016-11-08 13:49:39 +000037bool GrSurfaceProxy::isWrapped_ForTesting() const {
38 return SkToBool(fTarget);
39}
40
41bool GrRenderTargetContext::isWrapped_ForTesting() const {
42 return fRenderTargetProxy->isWrapped_ForTesting();
43}
44
Robert Phillips0c4b7b12018-03-06 08:20:37 -050045void GrContextPriv::setTextBlobCacheLimit_ForTesting(size_t bytes) {
46 fContext->fTextBlobCache->setBudget(bytes);
joshualitt17d833b2015-08-03 10:17:44 -070047}
48
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000049///////////////////////////////////////////////////////////////////////////////
50
Robert Phillips0c4b7b12018-03-06 08:20:37 -050051void GrContextPriv::purgeAllUnlockedResources_ForTesting() {
52 fContext->fResourceCache->purgeAllUnlocked();
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000053}
bsalomon33435572014-11-05 14:47:41 -080054
Robert Phillips0c4b7b12018-03-06 08:20:37 -050055void GrContextPriv::resetGpuStats() const {
joshualitte45c81c2015-12-02 09:05:37 -080056#if GR_GPU_STATS
Robert Phillips0c4b7b12018-03-06 08:20:37 -050057 fContext->fGpu->stats()->reset();
joshualitte45c81c2015-12-02 09:05:37 -080058#endif
59}
60
Robert Phillips0c4b7b12018-03-06 08:20:37 -050061void GrContextPriv::dumpCacheStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -080062#if GR_CACHE_STATS
Robert Phillips0c4b7b12018-03-06 08:20:37 -050063 fContext->fResourceCache->dumpStats(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -080064#endif
65}
66
Robert Phillips0c4b7b12018-03-06 08:20:37 -050067void GrContextPriv::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
68 SkTArray<double>* values) const {
joshualittdc5685a2015-12-02 14:08:25 -080069#if GR_CACHE_STATS
Robert Phillips0c4b7b12018-03-06 08:20:37 -050070 fContext->fResourceCache->dumpStatsKeyValuePairs(keys, values);
joshualittdc5685a2015-12-02 14:08:25 -080071#endif
72}
73
Robert Phillips0c4b7b12018-03-06 08:20:37 -050074void GrContextPriv::printCacheStats() const {
mtkleinb9eb4ac2015-02-02 18:26:03 -080075 SkString out;
76 this->dumpCacheStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -080077 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -080078}
79
Robert Phillips0c4b7b12018-03-06 08:20:37 -050080void GrContextPriv::dumpGpuStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -080081#if GR_GPU_STATS
Robert Phillips0c4b7b12018-03-06 08:20:37 -050082 return fContext->fGpu->stats()->dump(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -080083#endif
84}
85
Robert Phillips0c4b7b12018-03-06 08:20:37 -050086void GrContextPriv::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys,
87 SkTArray<double>* values) const {
joshualitte45c81c2015-12-02 09:05:37 -080088#if GR_GPU_STATS
Robert Phillips0c4b7b12018-03-06 08:20:37 -050089 return fContext->fGpu->stats()->dumpKeyValuePairs(keys, values);
joshualitte45c81c2015-12-02 09:05:37 -080090#endif
91}
92
Robert Phillips0c4b7b12018-03-06 08:20:37 -050093void GrContextPriv::printGpuStats() const {
mtkleinb9eb4ac2015-02-02 18:26:03 -080094 SkString out;
95 this->dumpGpuStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -080096 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -080097}
98
Robert Phillips0c4b7b12018-03-06 08:20:37 -050099sk_sp<SkImage> GrContextPriv::getFontAtlasImage_ForTesting(GrMaskFormat format, unsigned int index) {
Robert Phillips5a66efb2018-03-07 15:13:18 -0500100 auto atlasManager = this->getAtlasManager();
101 if (!atlasManager) {
102 return nullptr;
103 }
jvanverth629162d2015-11-08 08:07:24 -0800104
Jim Van Verthcbeae032018-05-16 14:54:41 -0400105 unsigned int numActiveProxies;
106 const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(format, &numActiveProxies);
107 if (index >= numActiveProxies || !proxies || !proxies[index]) {
Robert Phillips32f28182017-02-28 16:20:03 -0500108 return nullptr;
109 }
110
Jim Van Verth87d18ce2018-01-22 12:45:47 -0500111 SkASSERT(proxies[index]->priv().isExact());
Brian Salomon8a8dd332018-05-24 14:08:31 -0400112 sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID,
Brian Salomonf05e6d32018-12-20 08:41:41 -0500113 kPremul_SkAlphaType, proxies[index], nullptr));
Robert Phillips22f4a1f2016-12-20 08:57:26 -0500114 return image;
jvanverth0671b962015-12-08 18:53:44 -0800115}
jvanverth629162d2015-11-08 08:07:24 -0800116
mtkleinb9eb4ac2015-02-02 18:26:03 -0800117#if GR_GPU_STATS
118void GrGpu::Stats::dump(SkString* out) {
119 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
120 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800121 out->appendf("Textures Created: %d\n", fTextureCreates);
122 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800123 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700124 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700125 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800126}
joshualitte45c81c2015-12-02 09:05:37 -0800127
128void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
129 keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds);
130 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
joshualitte45c81c2015-12-02 09:05:37 -0800131 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800132 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700133 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800134}
135
mtkleinb9eb4ac2015-02-02 18:26:03 -0800136#endif
137
138#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800139void GrResourceCache::getStats(Stats* stats) const {
140 stats->reset();
141
142 stats->fTotal = this->getResourceCount();
143 stats->fNumNonPurgeable = fNonpurgeableResources.count();
144 stats->fNumPurgeable = fPurgeableQueue.count();
145
146 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
147 stats->update(fNonpurgeableResources[i]);
148 }
149 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
150 stats->update(fPurgeableQueue.at(i));
151 }
152}
153
bsalomon0ea80f42015-02-11 10:49:59 -0800154void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800155 this->validate();
156
bsalomonf320e042015-02-17 15:09:34 -0800157 Stats stats;
158
robertphillips60029a52015-11-09 13:51:06 -0800159 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800160
161 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
162 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
163
164 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
165 out->appendf("\t\tEntry Count: current %d"
kkinnunen2e6055b2016-04-22 01:48:29 -0700166 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n",
167 stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable,
168 stats.fScratch, countUtilization, fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800169 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800170 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
171 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800172}
173
joshualittdc5685a2015-12-02 14:08:25 -0800174void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
175 SkTArray<double>* values) const {
176 this->validate();
177
178 Stats stats;
179 this->getStats(&stats);
180
joshualittdc5685a2015-12-02 14:08:25 -0800181 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
joshualittdc5685a2015-12-02 14:08:25 -0800182}
183
mtkleinb9eb4ac2015-02-02 18:26:03 -0800184#endif
185
bsalomonddf30e62015-02-19 11:38:44 -0800186///////////////////////////////////////////////////////////////////////////////
187
188void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800189
Brian Salomon1090da62017-01-06 12:04:19 -0500190#ifdef SK_DEBUG
191int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
192 int count = 0;
193 UniqueHash::ConstIter iter(&fUniqueHash);
194 while (!iter.done()) {
195 if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
196 ++count;
197 }
198 ++iter;
199 }
200 return count;
201}
202#endif
203
bsalomon33435572014-11-05 14:47:41 -0800204///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800205
Chris Daltond004e0b2018-09-27 09:28:03 -0600206sk_sp<GrTextureProxy> GrProxyProvider::testingOnly_createInstantiatedProxy(
207 const GrSurfaceDesc& desc, GrSurfaceOrigin origin, SkBackingFit fit, SkBudgeted budgeted) {
208 sk_sp<GrTexture> tex;
209
210 if (SkBackingFit::kApprox == fit) {
211 tex = fResourceProvider->createApproxTexture(desc, GrResourceProvider::Flags::kNone);
212 } else {
213 tex = fResourceProvider->createTexture(desc, budgeted, GrResourceProvider::Flags::kNone);
214 }
215 if (!tex) {
216 return nullptr;
217 }
218
219 return this->createWrapped(std::move(tex), origin);
220}
221
222///////////////////////////////////////////////////////////////////////////////
223
joshualittf5883a62016-01-13 07:47:38 -0800224#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -0400225 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());)
joshualittf5883a62016-01-13 07:47:38 -0800226
Chris Dalton706a6ff2017-11-29 22:01:06 -0700227
Chris Daltona32a3c32017-12-05 10:05:21 -0700228uint32_t GrRenderTargetContextPriv::testingOnly_getOpListID() {
229 return fRenderTargetContext->getOpList()->uniqueID();
230}
231
Brian Salomon348a0372018-10-31 10:42:18 -0400232void GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) {
233 this->testingOnly_addDrawOp(GrNoClip(), std::move(op));
Chris Dalton706a6ff2017-11-29 22:01:06 -0700234}
235
Brian Salomon348a0372018-10-31 10:42:18 -0400236void GrRenderTargetContextPriv::testingOnly_addDrawOp(
237 const GrClip& clip,
238 std::unique_ptr<GrDrawOp> op,
239 const std::function<GrRenderTargetContext::WillAddOpFn>& willAddFn) {
Brian Salomonac70f842017-05-08 10:43:33 -0400240 ASSERT_SINGLE_OWNER
241 if (fRenderTargetContext->drawingManager()->wasAbandoned()) {
Robert Phillipsc994a932018-06-19 13:09:54 -0400242 fRenderTargetContext->fContext->contextPriv().opMemoryPool()->release(std::move(op));
Brian Salomon348a0372018-10-31 10:42:18 -0400243 return;
Brian Salomonac70f842017-05-08 10:43:33 -0400244 }
245 SkDEBUGCODE(fRenderTargetContext->validate());
246 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
247 "GrRenderTargetContext::testingOnly_addDrawOp");
Brian Salomon348a0372018-10-31 10:42:18 -0400248 fRenderTargetContext->addDrawOp(clip, std::move(op), willAddFn);
Brian Salomonac70f842017-05-08 10:43:33 -0400249}
250
joshualittf5883a62016-01-13 07:47:38 -0800251#undef ASSERT_SINGLE_OWNER
joshualittf5883a62016-01-13 07:47:38 -0800252
253///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700254
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400255GrInternalSurfaceFlags GrSurfaceProxy::testingOnly_getFlags() const {
256 return fSurfaceFlags;
csmartdaltonf9635992016-08-10 11:09:07 -0700257}
258
Brian Salomon17726632017-05-12 14:09:46 -0400259//////////////////////////////////////////////////////////////////////////////
260
Chris Daltonfe199b72017-05-05 11:26:15 -0400261void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
262 fContext->flush();
263 fContext->fDrawingManager->testingOnly_removeOnFlushCallbackObject(cb);
264}
265
266void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
267 int n = std::find(fOnFlushCBObjects.begin(), fOnFlushCBObjects.end(), cb) -
268 fOnFlushCBObjects.begin();
269 SkASSERT(n < fOnFlushCBObjects.count());
270 fOnFlushCBObjects.removeShuffle(n);
271}
Brian Salomon17726632017-05-12 14:09:46 -0400272
273//////////////////////////////////////////////////////////////////////////////
274
Chris Daltona2b5b642018-06-24 13:08:57 -0600275void GrCoverageCountingPathRenderer::testingOnly_drawPathDirectly(const DrawPathArgs& args) {
276 // Call onDrawPath() directly: We want to test paths that might fail onCanDrawPath() simply for
277 // performance reasons, and GrPathRenderer::drawPath() assert that this call returns true.
278 // The test is responsible to not draw any paths that CCPR is not actually capable of.
279 this->onDrawPath(args);
280}
281
Chris Dalton351e80c2019-01-06 22:51:00 -0700282const GrCCPerFlushResources*
283GrCoverageCountingPathRenderer::testingOnly_getCurrentFlushResources() {
284 SkASSERT(fFlushing);
285 if (fFlushingPaths.empty()) {
286 return nullptr;
287 }
288 // All pending paths should share the same resources.
289 const GrCCPerFlushResources* resources = fFlushingPaths.front()->fFlushResources.get();
290#ifdef SK_DEBUG
291 for (const auto& flushingPaths : fFlushingPaths) {
292 SkASSERT(flushingPaths->fFlushResources.get() == resources);
293 }
294#endif
295 return resources;
Chris Dalton4da70192018-06-18 09:51:36 -0600296}
297
Chris Dalton351e80c2019-01-06 22:51:00 -0700298const GrCCPathCache* GrCoverageCountingPathRenderer::testingOnly_getPathCache() const {
299 return fPathCache.get();
300}
301
302const GrTexture* GrCCPerFlushResources::testingOnly_frontCopyAtlasTexture() const {
303 if (fCopyAtlasStack.empty()) {
304 return nullptr;
305 }
306 const GrTextureProxy* proxy = fCopyAtlasStack.front().textureProxy();
307 return (proxy) ? proxy->peekTexture() : nullptr;
308}
309
310const GrTexture* GrCCPerFlushResources::testingOnly_frontRenderedAtlasTexture() const {
311 if (fRenderedAtlasStack.empty()) {
312 return nullptr;
313 }
314 const GrTextureProxy* proxy = fRenderedAtlasStack.front().textureProxy();
315 return (proxy) ? proxy->peekTexture() : nullptr;
316}
317
318const SkTHashTable<GrCCPathCache::HashNode, const GrCCPathCache::Key&>&
319GrCCPathCache::testingOnly_getHashTable() const {
320 return fHashTable;
321}
322
323const SkTInternalLList<GrCCPathCacheEntry>& GrCCPathCache::testingOnly_getLRU() const {
324 return fLRU;
325}
326
327int GrCCPathCacheEntry::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
328
329int GrCCCachedAtlas::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
330
Chris Dalton4da70192018-06-18 09:51:36 -0600331//////////////////////////////////////////////////////////////////////////////
332
Brian Salomon17726632017-05-12 14:09:46 -0400333#define DRAW_OP_TEST_EXTERN(Op) \
Brian Salomon815486c2017-07-11 08:52:13 -0400334 extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, GrContext*, GrFSAAType)
Brian Salomon17726632017-05-12 14:09:46 -0400335#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
336
Brian Salomon10978a62017-06-15 16:21:49 -0400337DRAW_OP_TEST_EXTERN(AAConvexPathOp);
Brian Salomonb2955732017-07-13 16:42:55 -0400338DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
Brian Salomona531f252017-07-07 13:29:28 -0400339DRAW_OP_TEST_EXTERN(AAHairlineOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400340DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400341DRAW_OP_TEST_EXTERN(CircleOp);
Brian Salomon98222ac2017-07-12 15:27:54 -0400342DRAW_OP_TEST_EXTERN(DashOp);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400343DRAW_OP_TEST_EXTERN(DefaultPathOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400344DRAW_OP_TEST_EXTERN(DIEllipseOp);
345DRAW_OP_TEST_EXTERN(EllipseOp);
Michael Ludwig69858532018-11-28 15:34:34 -0500346DRAW_OP_TEST_EXTERN(FillRectOp);
Brian Salomon44acb5b2017-07-18 19:59:24 -0400347DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
Brian Salomon0088f942017-07-12 11:51:27 -0400348DRAW_OP_TEST_EXTERN(GrDrawAtlasOp);
Brian Salomonc2f42542017-07-12 14:11:22 -0400349DRAW_OP_TEST_EXTERN(GrDrawVerticesOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400350DRAW_OP_TEST_EXTERN(NonAALatticeOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400351DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
Brian Salomon05969092017-07-13 11:20:51 -0400352DRAW_OP_TEST_EXTERN(ShadowRRectOp);
Brian Salomonfebbd232017-07-11 15:52:02 -0400353DRAW_OP_TEST_EXTERN(SmallPathOp);
Brian Salomonf0366322017-07-11 15:53:05 -0400354DRAW_OP_TEST_EXTERN(RegionOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400355DRAW_OP_TEST_EXTERN(RRectOp);
Brian Salomon9530f7e2017-07-11 09:03:10 -0400356DRAW_OP_TEST_EXTERN(TesselatingPathOp);
Brian Salomon34169692017-08-28 15:32:01 -0400357DRAW_OP_TEST_EXTERN(TextureOp);
Brian Salomon17726632017-05-12 14:09:46 -0400358
359void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
360 GrContext* context = renderTargetContext->surfPriv().getContext();
Brian Salomon17726632017-05-12 14:09:46 -0400361 using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*, GrContext*, GrFSAAType);
362 static constexpr MakeDrawOpFn* gFactories[] = {
Brian Salomon34169692017-08-28 15:32:01 -0400363 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
Brian Salomon34169692017-08-28 15:32:01 -0400364 DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
365 DRAW_OP_TEST_ENTRY(AAHairlineOp),
366 DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
367 DRAW_OP_TEST_ENTRY(CircleOp),
368 DRAW_OP_TEST_ENTRY(DashOp),
369 DRAW_OP_TEST_ENTRY(DefaultPathOp),
370 DRAW_OP_TEST_ENTRY(DIEllipseOp),
371 DRAW_OP_TEST_ENTRY(EllipseOp),
Michael Ludwig69858532018-11-28 15:34:34 -0500372 DRAW_OP_TEST_ENTRY(FillRectOp),
Brian Salomon34169692017-08-28 15:32:01 -0400373 DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
374 DRAW_OP_TEST_ENTRY(GrDrawAtlasOp),
375 DRAW_OP_TEST_ENTRY(GrDrawVerticesOp),
Brian Salomon34169692017-08-28 15:32:01 -0400376 DRAW_OP_TEST_ENTRY(NonAALatticeOp),
377 DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
378 DRAW_OP_TEST_ENTRY(ShadowRRectOp),
379 DRAW_OP_TEST_ENTRY(SmallPathOp),
380 DRAW_OP_TEST_ENTRY(RegionOp),
381 DRAW_OP_TEST_ENTRY(RRectOp),
382 DRAW_OP_TEST_ENTRY(TesselatingPathOp),
383 DRAW_OP_TEST_ENTRY(TextureOp),
Brian Salomon17726632017-05-12 14:09:46 -0400384 };
385
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400386 static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
Brian Salomon17726632017-05-12 14:09:46 -0400387 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400388 auto op = gFactories[index](
389 std::move(paint), random, context, renderTargetContext->fsaaType());
390 SkASSERT(op);
391 renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
Brian Salomon17726632017-05-12 14:09:46 -0400392}