blob: 890d26a2abe12b31681f5bcd6ffb91ec1df1ca84 [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"
bsalomon682c2692015-05-22 14:01:46 -07009#include "GrContextOptions.h"
Chris Daltonfe199b72017-05-05 11:26:15 -040010#include "GrContextPriv.h"
Brian Salomon2ee084e2016-12-16 18:59:19 -050011#include "GrDrawOpAtlas.h"
robertphillips77a2e522015-10-17 07:43:27 -070012#include "GrDrawingManager.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040013#include "GrGpu.h"
bsalomon3582d3e2015-02-13 14:20:05 -080014#include "GrGpuResourceCacheAccess.h"
Robert Phillipsc994a932018-06-19 13:09:54 -040015#include "GrMemoryPool.h"
Brian Salomon17726632017-05-12 14:09:46 -040016#include "GrRenderTargetContext.h"
Brian Salomon2ee084e2016-12-16 18:59:19 -050017#include "GrRenderTargetContextPriv.h"
csmartdaltonf9635992016-08-10 11:09:07 -070018#include "GrRenderTargetProxy.h"
bsalomon0ea80f42015-02-11 10:49:59 -080019#include "GrResourceCache.h"
Greg Daniel6be35232017-03-01 17:01:09 -050020#include "GrSemaphore.h"
Brian Salomon17726632017-05-12 14:09:46 -040021#include "GrSurfaceContextPriv.h"
Hal Canaryc640d0d2018-06-13 09:59:02 -040022#include "GrTest.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"
Brian Salomon17726632017-05-12 14:09:46 -040030#include "ops/GrMeshDrawOp.h"
Robert Phillipsc4039ea2018-03-01 11:36:45 -050031#include "text/GrGlyphCache.h"
joshualitte8042922015-12-11 06:11:21 -080032#include "text/GrTextBlobCache.h"
Hal Canaryc640d0d2018-06-13 09:59:02 -040033#include <algorithm>
joshualitte8042922015-12-11 06:11:21 -080034
joshualitt7f9c9eb2015-08-21 11:08:00 -070035namespace GrTest {
Brian Salomond17f6582017-07-19 18:28:58 -040036
Robert Phillipsd2e9f762018-03-07 11:54:37 -050037void SetupAlwaysEvictAtlas(GrContext* context, int dim) {
joshualitt7f9c9eb2015-08-21 11:08:00 -070038 // These sizes were selected because they allow each atlas to hold a single plot and will thus
39 // stress the atlas
Brian Salomon2ee084e2016-12-16 18:59:19 -050040 GrDrawOpAtlasConfig configs[3];
joshualitt7f9c9eb2015-08-21 11:08:00 -070041 configs[kA8_GrMaskFormat].fWidth = dim;
42 configs[kA8_GrMaskFormat].fHeight = dim;
43 configs[kA8_GrMaskFormat].fPlotWidth = dim;
44 configs[kA8_GrMaskFormat].fPlotHeight = dim;
45
46 configs[kA565_GrMaskFormat].fWidth = dim;
47 configs[kA565_GrMaskFormat].fHeight = dim;
48 configs[kA565_GrMaskFormat].fPlotWidth = dim;
49 configs[kA565_GrMaskFormat].fPlotHeight = dim;
50
51 configs[kARGB_GrMaskFormat].fWidth = dim;
52 configs[kARGB_GrMaskFormat].fHeight = dim;
53 configs[kARGB_GrMaskFormat].fPlotWidth = dim;
54 configs[kARGB_GrMaskFormat].fPlotHeight = dim;
55
Robert Phillips0c4b7b12018-03-06 08:20:37 -050056 context->contextPriv().setTextContextAtlasSizes_ForTesting(configs);
joshualitt7f9c9eb2015-08-21 11:08:00 -070057}
Greg Daniel7ef28f32017-04-20 16:41:55 +000058
Brian Salomond17f6582017-07-19 18:28:58 -040059} // namespace GrTest
joshualitt7f9c9eb2015-08-21 11:08:00 -070060
Robert Phillipseaa86252016-11-08 13:49:39 +000061bool GrSurfaceProxy::isWrapped_ForTesting() const {
62 return SkToBool(fTarget);
63}
64
65bool GrRenderTargetContext::isWrapped_ForTesting() const {
66 return fRenderTargetProxy->isWrapped_ForTesting();
67}
68
Robert Phillips0c4b7b12018-03-06 08:20:37 -050069void GrContextPriv::setTextBlobCacheLimit_ForTesting(size_t bytes) {
70 fContext->fTextBlobCache->setBudget(bytes);
joshualitt17d833b2015-08-03 10:17:44 -070071}
72
Robert Phillips0c4b7b12018-03-06 08:20:37 -050073void GrContextPriv::setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs) {
Robert Phillips5a66efb2018-03-07 15:13:18 -050074 GrAtlasManager* atlasManager = this->getAtlasManager();
Robert Phillips1056eb82018-03-01 14:16:41 -050075 if (atlasManager) {
76 atlasManager->setAtlasSizes_ForTesting(configs);
77 }
joshualittda04e0e2015-08-19 08:16:43 -070078}
79
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000080///////////////////////////////////////////////////////////////////////////////
81
Robert Phillips0c4b7b12018-03-06 08:20:37 -050082void GrContextPriv::purgeAllUnlockedResources_ForTesting() {
83 fContext->fResourceCache->purgeAllUnlocked();
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000084}
bsalomon33435572014-11-05 14:47:41 -080085
Robert Phillips0c4b7b12018-03-06 08:20:37 -050086void GrContextPriv::resetGpuStats() const {
joshualitte45c81c2015-12-02 09:05:37 -080087#if GR_GPU_STATS
Robert Phillips0c4b7b12018-03-06 08:20:37 -050088 fContext->fGpu->stats()->reset();
joshualitte45c81c2015-12-02 09:05:37 -080089#endif
90}
91
Robert Phillips0c4b7b12018-03-06 08:20:37 -050092void GrContextPriv::dumpCacheStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -080093#if GR_CACHE_STATS
Robert Phillips0c4b7b12018-03-06 08:20:37 -050094 fContext->fResourceCache->dumpStats(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -080095#endif
96}
97
Robert Phillips0c4b7b12018-03-06 08:20:37 -050098void GrContextPriv::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
99 SkTArray<double>* values) const {
joshualittdc5685a2015-12-02 14:08:25 -0800100#if GR_CACHE_STATS
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500101 fContext->fResourceCache->dumpStatsKeyValuePairs(keys, values);
joshualittdc5685a2015-12-02 14:08:25 -0800102#endif
103}
104
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500105void GrContextPriv::printCacheStats() const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800106 SkString out;
107 this->dumpCacheStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800108 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800109}
110
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500111void GrContextPriv::dumpGpuStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800112#if GR_GPU_STATS
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500113 return fContext->fGpu->stats()->dump(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800114#endif
115}
116
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500117void GrContextPriv::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys,
118 SkTArray<double>* values) const {
joshualitte45c81c2015-12-02 09:05:37 -0800119#if GR_GPU_STATS
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500120 return fContext->fGpu->stats()->dumpKeyValuePairs(keys, values);
joshualitte45c81c2015-12-02 09:05:37 -0800121#endif
122}
123
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500124void GrContextPriv::printGpuStats() const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800125 SkString out;
126 this->dumpGpuStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800127 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800128}
129
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500130sk_sp<SkImage> GrContextPriv::getFontAtlasImage_ForTesting(GrMaskFormat format, unsigned int index) {
Robert Phillips5a66efb2018-03-07 15:13:18 -0500131 auto atlasManager = this->getAtlasManager();
132 if (!atlasManager) {
133 return nullptr;
134 }
jvanverth629162d2015-11-08 08:07:24 -0800135
Jim Van Verthcbeae032018-05-16 14:54:41 -0400136 unsigned int numActiveProxies;
137 const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(format, &numActiveProxies);
138 if (index >= numActiveProxies || !proxies || !proxies[index]) {
Robert Phillips32f28182017-02-28 16:20:03 -0500139 return nullptr;
140 }
141
Jim Van Verth87d18ce2018-01-22 12:45:47 -0500142 SkASSERT(proxies[index]->priv().isExact());
Brian Salomon8a8dd332018-05-24 14:08:31 -0400143 sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID,
144 kPremul_SkAlphaType, proxies[index], nullptr,
145 SkBudgeted::kNo));
Robert Phillips22f4a1f2016-12-20 08:57:26 -0500146 return image;
jvanverth0671b962015-12-08 18:53:44 -0800147}
jvanverth629162d2015-11-08 08:07:24 -0800148
mtkleinb9eb4ac2015-02-02 18:26:03 -0800149#if GR_GPU_STATS
150void GrGpu::Stats::dump(SkString* out) {
151 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
152 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800153 out->appendf("Textures Created: %d\n", fTextureCreates);
154 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800155 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700156 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700157 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800158}
joshualitte45c81c2015-12-02 09:05:37 -0800159
160void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
161 keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds);
162 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
joshualitte45c81c2015-12-02 09:05:37 -0800163 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800164 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700165 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800166}
167
mtkleinb9eb4ac2015-02-02 18:26:03 -0800168#endif
169
Brian Salomon52e943a2018-03-13 09:32:39 -0400170GrBackendTexture GrGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400171 SkColorType colorType, bool isRenderTarget,
Brian Salomonbdecacf2018-02-02 20:32:49 -0500172 GrMipMapped mipMapped) {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400173 GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
Greg Daniel0a7aa142018-02-21 13:02:32 -0500174 if (kUnknown_GrPixelConfig == config) {
175 return GrBackendTexture();
176 }
Brian Salomonbdecacf2018-02-02 20:32:49 -0500177 return this->createTestingOnlyBackendTexture(pixels, w, h, config, isRenderTarget, mipMapped);
178}
179
mtkleinb9eb4ac2015-02-02 18:26:03 -0800180#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800181void GrResourceCache::getStats(Stats* stats) const {
182 stats->reset();
183
184 stats->fTotal = this->getResourceCount();
185 stats->fNumNonPurgeable = fNonpurgeableResources.count();
186 stats->fNumPurgeable = fPurgeableQueue.count();
187
188 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
189 stats->update(fNonpurgeableResources[i]);
190 }
191 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
192 stats->update(fPurgeableQueue.at(i));
193 }
194}
195
bsalomon0ea80f42015-02-11 10:49:59 -0800196void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800197 this->validate();
198
bsalomonf320e042015-02-17 15:09:34 -0800199 Stats stats;
200
robertphillips60029a52015-11-09 13:51:06 -0800201 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800202
203 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
204 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
205
206 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
207 out->appendf("\t\tEntry Count: current %d"
kkinnunen2e6055b2016-04-22 01:48:29 -0700208 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n",
209 stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable,
210 stats.fScratch, countUtilization, fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800211 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800212 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
213 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800214}
215
joshualittdc5685a2015-12-02 14:08:25 -0800216void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
217 SkTArray<double>* values) const {
218 this->validate();
219
220 Stats stats;
221 this->getStats(&stats);
222
joshualittdc5685a2015-12-02 14:08:25 -0800223 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
joshualittdc5685a2015-12-02 14:08:25 -0800224}
225
mtkleinb9eb4ac2015-02-02 18:26:03 -0800226#endif
227
bsalomonddf30e62015-02-19 11:38:44 -0800228///////////////////////////////////////////////////////////////////////////////
229
230void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800231
Brian Salomon1090da62017-01-06 12:04:19 -0500232#ifdef SK_DEBUG
233int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
234 int count = 0;
235 UniqueHash::ConstIter iter(&fUniqueHash);
236 while (!iter.done()) {
237 if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
238 ++count;
239 }
240 ++iter;
241 }
242 return count;
243}
244#endif
245
bsalomon33435572014-11-05 14:47:41 -0800246///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800247
248#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -0400249 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());)
joshualittf5883a62016-01-13 07:47:38 -0800250
Chris Dalton706a6ff2017-11-29 22:01:06 -0700251
Chris Daltona32a3c32017-12-05 10:05:21 -0700252uint32_t GrRenderTargetContextPriv::testingOnly_getOpListID() {
253 return fRenderTargetContext->getOpList()->uniqueID();
254}
255
Brian Salomonac70f842017-05-08 10:43:33 -0400256uint32_t GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) {
Chris Dalton706a6ff2017-11-29 22:01:06 -0700257 return this->testingOnly_addDrawOp(GrNoClip(), std::move(op));
258}
259
260uint32_t GrRenderTargetContextPriv::testingOnly_addDrawOp(const GrClip& clip,
261 std::unique_ptr<GrDrawOp> op) {
Brian Salomonac70f842017-05-08 10:43:33 -0400262 ASSERT_SINGLE_OWNER
263 if (fRenderTargetContext->drawingManager()->wasAbandoned()) {
Robert Phillipsc994a932018-06-19 13:09:54 -0400264 fRenderTargetContext->fContext->contextPriv().opMemoryPool()->release(std::move(op));
Brian Salomonac70f842017-05-08 10:43:33 -0400265 return SK_InvalidUniqueID;
266 }
267 SkDEBUGCODE(fRenderTargetContext->validate());
268 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
269 "GrRenderTargetContext::testingOnly_addDrawOp");
Chris Dalton706a6ff2017-11-29 22:01:06 -0700270 return fRenderTargetContext->addDrawOp(clip, std::move(op));
Brian Salomonac70f842017-05-08 10:43:33 -0400271}
272
joshualittf5883a62016-01-13 07:47:38 -0800273#undef ASSERT_SINGLE_OWNER
joshualittf5883a62016-01-13 07:47:38 -0800274
275///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700276
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400277GrInternalSurfaceFlags GrSurfaceProxy::testingOnly_getFlags() const {
278 return fSurfaceFlags;
csmartdaltonf9635992016-08-10 11:09:07 -0700279}
280
Brian Salomon17726632017-05-12 14:09:46 -0400281//////////////////////////////////////////////////////////////////////////////
282
Chris Daltonfe199b72017-05-05 11:26:15 -0400283void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
284 fContext->flush();
285 fContext->fDrawingManager->testingOnly_removeOnFlushCallbackObject(cb);
286}
287
288void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
289 int n = std::find(fOnFlushCBObjects.begin(), fOnFlushCBObjects.end(), cb) -
290 fOnFlushCBObjects.begin();
291 SkASSERT(n < fOnFlushCBObjects.count());
292 fOnFlushCBObjects.removeShuffle(n);
293}
Brian Salomon17726632017-05-12 14:09:46 -0400294
295//////////////////////////////////////////////////////////////////////////////
296
Chris Daltona2b5b642018-06-24 13:08:57 -0600297void GrCoverageCountingPathRenderer::testingOnly_drawPathDirectly(const DrawPathArgs& args) {
298 // Call onDrawPath() directly: We want to test paths that might fail onCanDrawPath() simply for
299 // performance reasons, and GrPathRenderer::drawPath() assert that this call returns true.
300 // The test is responsible to not draw any paths that CCPR is not actually capable of.
301 this->onDrawPath(args);
302}
303
Chris Dalton4da70192018-06-18 09:51:36 -0600304const GrUniqueKey& GrCoverageCountingPathRenderer::testingOnly_getStashedAtlasKey() const {
305 return fStashedAtlasKey;
306}
307
308//////////////////////////////////////////////////////////////////////////////
309
Brian Salomon17726632017-05-12 14:09:46 -0400310#define DRAW_OP_TEST_EXTERN(Op) \
Brian Salomon815486c2017-07-11 08:52:13 -0400311 extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, GrContext*, GrFSAAType)
Brian Salomon17726632017-05-12 14:09:46 -0400312#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
313
Brian Salomon10978a62017-06-15 16:21:49 -0400314DRAW_OP_TEST_EXTERN(AAConvexPathOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400315DRAW_OP_TEST_EXTERN(AAFillRectOp);
Brian Salomonb2955732017-07-13 16:42:55 -0400316DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
Brian Salomona531f252017-07-07 13:29:28 -0400317DRAW_OP_TEST_EXTERN(AAHairlineOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400318DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400319DRAW_OP_TEST_EXTERN(CircleOp);
Brian Salomon98222ac2017-07-12 15:27:54 -0400320DRAW_OP_TEST_EXTERN(DashOp);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400321DRAW_OP_TEST_EXTERN(DefaultPathOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400322DRAW_OP_TEST_EXTERN(DIEllipseOp);
323DRAW_OP_TEST_EXTERN(EllipseOp);
Brian Salomon44acb5b2017-07-18 19:59:24 -0400324DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
Brian Salomon0088f942017-07-12 11:51:27 -0400325DRAW_OP_TEST_EXTERN(GrDrawAtlasOp);
Brian Salomonc2f42542017-07-12 14:11:22 -0400326DRAW_OP_TEST_EXTERN(GrDrawVerticesOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400327DRAW_OP_TEST_EXTERN(NonAAFillRectOp);
328DRAW_OP_TEST_EXTERN(NonAALatticeOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400329DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
Brian Salomon05969092017-07-13 11:20:51 -0400330DRAW_OP_TEST_EXTERN(ShadowRRectOp);
Brian Salomonfebbd232017-07-11 15:52:02 -0400331DRAW_OP_TEST_EXTERN(SmallPathOp);
Brian Salomonf0366322017-07-11 15:53:05 -0400332DRAW_OP_TEST_EXTERN(RegionOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400333DRAW_OP_TEST_EXTERN(RRectOp);
Brian Salomon9530f7e2017-07-11 09:03:10 -0400334DRAW_OP_TEST_EXTERN(TesselatingPathOp);
Brian Salomon34169692017-08-28 15:32:01 -0400335DRAW_OP_TEST_EXTERN(TextureOp);
Brian Salomon17726632017-05-12 14:09:46 -0400336
337void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
338 GrContext* context = renderTargetContext->surfPriv().getContext();
Brian Salomon17726632017-05-12 14:09:46 -0400339 using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*, GrContext*, GrFSAAType);
340 static constexpr MakeDrawOpFn* gFactories[] = {
Brian Salomon34169692017-08-28 15:32:01 -0400341 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
342 DRAW_OP_TEST_ENTRY(AAFillRectOp),
343 DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
344 DRAW_OP_TEST_ENTRY(AAHairlineOp),
345 DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
346 DRAW_OP_TEST_ENTRY(CircleOp),
347 DRAW_OP_TEST_ENTRY(DashOp),
348 DRAW_OP_TEST_ENTRY(DefaultPathOp),
349 DRAW_OP_TEST_ENTRY(DIEllipseOp),
350 DRAW_OP_TEST_ENTRY(EllipseOp),
351 DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
352 DRAW_OP_TEST_ENTRY(GrDrawAtlasOp),
353 DRAW_OP_TEST_ENTRY(GrDrawVerticesOp),
354 DRAW_OP_TEST_ENTRY(NonAAFillRectOp),
355 DRAW_OP_TEST_ENTRY(NonAALatticeOp),
356 DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
357 DRAW_OP_TEST_ENTRY(ShadowRRectOp),
358 DRAW_OP_TEST_ENTRY(SmallPathOp),
359 DRAW_OP_TEST_ENTRY(RegionOp),
360 DRAW_OP_TEST_ENTRY(RRectOp),
361 DRAW_OP_TEST_ENTRY(TesselatingPathOp),
362 DRAW_OP_TEST_ENTRY(TextureOp),
Brian Salomon17726632017-05-12 14:09:46 -0400363 };
364
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400365 static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
Brian Salomon17726632017-05-12 14:09:46 -0400366 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400367 auto op = gFactories[index](
368 std::move(paint), random, context, renderTargetContext->fsaaType());
369 SkASSERT(op);
370 renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
Brian Salomon17726632017-05-12 14:09:46 -0400371}