blob: c338680b9680aa8aa79385ddc596ed0dc2fabb4b [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
8#include "GrTest.h"
Brian Salomon17726632017-05-12 14:09:46 -04009#include <algorithm>
Greg Daniel7ef28f32017-04-20 16:41:55 +000010#include "GrBackendSurface.h"
bsalomon682c2692015-05-22 14:01:46 -070011#include "GrContextOptions.h"
Chris Daltonfe199b72017-05-05 11:26:15 -040012#include "GrContextPriv.h"
Brian Salomon2ee084e2016-12-16 18:59:19 -050013#include "GrDrawOpAtlas.h"
robertphillips77a2e522015-10-17 07:43:27 -070014#include "GrDrawingManager.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040015#include "GrGpu.h"
bsalomon3582d3e2015-02-13 14:20:05 -080016#include "GrGpuResourceCacheAccess.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"
Brian Salomon17726632017-05-12 14:09:46 -040028#include "ops/GrMeshDrawOp.h"
Brian Salomonf856fd12016-12-16 14:24:34 -050029#include "text/GrAtlasGlyphCache.h"
joshualitte8042922015-12-11 06:11:21 -080030#include "text/GrTextBlobCache.h"
31
joshualitt7f9c9eb2015-08-21 11:08:00 -070032namespace GrTest {
Brian Salomond17f6582017-07-19 18:28:58 -040033
joshualitt7f9c9eb2015-08-21 11:08:00 -070034void SetupAlwaysEvictAtlas(GrContext* context) {
35 // These sizes were selected because they allow each atlas to hold a single plot and will thus
36 // stress the atlas
Brian Salomon2ee084e2016-12-16 18:59:19 -050037 int dim = GrDrawOpAtlas::kGlyphMaxDim;
38 GrDrawOpAtlasConfig configs[3];
joshualitt7f9c9eb2015-08-21 11:08:00 -070039 configs[kA8_GrMaskFormat].fWidth = dim;
40 configs[kA8_GrMaskFormat].fHeight = dim;
41 configs[kA8_GrMaskFormat].fPlotWidth = dim;
42 configs[kA8_GrMaskFormat].fPlotHeight = dim;
43
44 configs[kA565_GrMaskFormat].fWidth = dim;
45 configs[kA565_GrMaskFormat].fHeight = dim;
46 configs[kA565_GrMaskFormat].fPlotWidth = dim;
47 configs[kA565_GrMaskFormat].fPlotHeight = dim;
48
49 configs[kARGB_GrMaskFormat].fWidth = dim;
50 configs[kARGB_GrMaskFormat].fHeight = dim;
51 configs[kARGB_GrMaskFormat].fPlotWidth = dim;
52 configs[kARGB_GrMaskFormat].fPlotHeight = dim;
53
54 context->setTextContextAtlasSizes_ForTesting(configs);
55}
Greg Daniel7ef28f32017-04-20 16:41:55 +000056
57GrBackendTexture CreateBackendTexture(GrBackend backend, int width, int height,
Greg Daniel177e6952017-10-12 12:27:11 -040058 GrPixelConfig config, GrMipMapped mipMapped,
59 GrBackendObject handle) {
Brian Salomond17f6582017-07-19 18:28:58 -040060 switch (backend) {
Mike Reedd20b5c42017-06-14 06:03:10 -040061#ifdef SK_VULKAN
Brian Salomond17f6582017-07-19 18:28:58 -040062 case kVulkan_GrBackend: {
63 GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle);
Greg Daniel177e6952017-10-12 12:27:11 -040064 SkASSERT((GrMipMapped::kYes == mipMapped) == (vkInfo->fLevelCount > 1));
Brian Salomond17f6582017-07-19 18:28:58 -040065 return GrBackendTexture(width, height, *vkInfo);
66 }
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000067#endif
Brian Salomond17f6582017-07-19 18:28:58 -040068 case kOpenGL_GrBackend: {
69 GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle);
Greg Danielf5d87582017-12-18 14:48:15 -050070 SkASSERT(glInfo->fFormat);
71 return GrBackendTexture(width, height, mipMapped, *glInfo);
Brian Salomond17f6582017-07-19 18:28:58 -040072 }
73 case kMock_GrBackend: {
74 GrMockTextureInfo* mockInfo = (GrMockTextureInfo*)(handle);
Greg Daniel177e6952017-10-12 12:27:11 -040075 return GrBackendTexture(width, height, config, mipMapped, *mockInfo);
Brian Salomond17f6582017-07-19 18:28:58 -040076 }
77 default:
78 return GrBackendTexture();
79 }
Greg Daniel7ef28f32017-04-20 16:41:55 +000080}
Brian Salomond17f6582017-07-19 18:28:58 -040081
82} // namespace GrTest
joshualitt7f9c9eb2015-08-21 11:08:00 -070083
Robert Phillipseaa86252016-11-08 13:49:39 +000084bool GrSurfaceProxy::isWrapped_ForTesting() const {
85 return SkToBool(fTarget);
86}
87
88bool GrRenderTargetContext::isWrapped_ForTesting() const {
89 return fRenderTargetProxy->isWrapped_ForTesting();
90}
91
joshualitt17d833b2015-08-03 10:17:44 -070092void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) {
93 fTextBlobCache->setBudget(bytes);
94}
95
Brian Salomon2ee084e2016-12-16 18:59:19 -050096void GrContext::setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs) {
Brian Salomonf856fd12016-12-16 14:24:34 -050097 fAtlasGlyphCache->setAtlasSizes_ForTesting(configs);
joshualittda04e0e2015-08-19 08:16:43 -070098}
99
commit-bot@chromium.org78a10782013-08-21 19:27:48 +0000100///////////////////////////////////////////////////////////////////////////////
101
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000102void GrContext::purgeAllUnlockedResources() {
bsalomon0ea80f42015-02-11 10:49:59 -0800103 fResourceCache->purgeAllUnlocked();
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000104}
bsalomon33435572014-11-05 14:47:41 -0800105
joshualitte45c81c2015-12-02 09:05:37 -0800106void GrContext::resetGpuStats() const {
107#if GR_GPU_STATS
108 fGpu->stats()->reset();
109#endif
110}
111
mtkleinb9eb4ac2015-02-02 18:26:03 -0800112void GrContext::dumpCacheStats(SkString* out) const {
113#if GR_CACHE_STATS
bsalomon0ea80f42015-02-11 10:49:59 -0800114 fResourceCache->dumpStats(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800115#endif
116}
117
joshualittdc5685a2015-12-02 14:08:25 -0800118void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
119 SkTArray<double>* values) const {
120#if GR_CACHE_STATS
121 fResourceCache->dumpStatsKeyValuePairs(keys, values);
122#endif
123}
124
mtkleinb9eb4ac2015-02-02 18:26:03 -0800125void GrContext::printCacheStats() const {
126 SkString out;
127 this->dumpCacheStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800128 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800129}
130
131void GrContext::dumpGpuStats(SkString* out) const {
132#if GR_GPU_STATS
133 return fGpu->stats()->dump(out);
134#endif
135}
136
joshualitte45c81c2015-12-02 09:05:37 -0800137void GrContext::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys,
138 SkTArray<double>* values) const {
139#if GR_GPU_STATS
140 return fGpu->stats()->dumpKeyValuePairs(keys, values);
141#endif
142}
143
mtkleinb9eb4ac2015-02-02 18:26:03 -0800144void GrContext::printGpuStats() const {
145 SkString out;
146 this->dumpGpuStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800147 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800148}
149
Jim Van Verth87d18ce2018-01-22 12:45:47 -0500150sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format, uint32_t index) {
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500151 GrAtlasGlyphCache* cache = this->contextPriv().getAtlasGlyphCache();
jvanverth629162d2015-11-08 08:07:24 -0800152
Jim Van Vertha950b632017-09-12 11:54:11 -0400153 const sk_sp<GrTextureProxy>* proxies = cache->getProxies(format);
Jim Van Verth87d18ce2018-01-22 12:45:47 -0500154 if (index >= cache->getAtlasPageCount(format) || !proxies[index]) {
Robert Phillips32f28182017-02-28 16:20:03 -0500155 return nullptr;
156 }
157
Jim Van Verth87d18ce2018-01-22 12:45:47 -0500158 SkASSERT(proxies[index]->priv().isExact());
Robert Phillipsb726d582017-03-09 16:36:32 -0500159 sk_sp<SkImage> image(new SkImage_Gpu(this, kNeedNewImageUniqueID, kPremul_SkAlphaType,
Robert Phillipsde9cef22018-01-23 10:59:47 -0500160 proxies[index], nullptr, SkBudgeted::kNo));
Robert Phillips22f4a1f2016-12-20 08:57:26 -0500161 return image;
jvanverth0671b962015-12-08 18:53:44 -0800162}
jvanverth629162d2015-11-08 08:07:24 -0800163
mtkleinb9eb4ac2015-02-02 18:26:03 -0800164#if GR_GPU_STATS
165void GrGpu::Stats::dump(SkString* out) {
166 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
167 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800168 out->appendf("Textures Created: %d\n", fTextureCreates);
169 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800170 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700171 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700172 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800173}
joshualitte45c81c2015-12-02 09:05:37 -0800174
175void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
176 keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds);
177 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
joshualitte45c81c2015-12-02 09:05:37 -0800178 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800179 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700180 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800181}
182
mtkleinb9eb4ac2015-02-02 18:26:03 -0800183#endif
184
Brian Salomonbdecacf2018-02-02 20:32:49 -0500185GrBackendTexture GrGpu::createTestingOnlyBackendTexture(void* pixels, int w, int h,
186 SkColorType colorType, bool isRenderTarget,
187 GrMipMapped mipMapped) {
188 GrPixelConfig config = SkImageInfo2GrPixelConfig(colorType, nullptr, *this->caps());
189 return this->createTestingOnlyBackendTexture(pixels, w, h, config, isRenderTarget, mipMapped);
190}
191
mtkleinb9eb4ac2015-02-02 18:26:03 -0800192#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800193void GrResourceCache::getStats(Stats* stats) const {
194 stats->reset();
195
196 stats->fTotal = this->getResourceCount();
197 stats->fNumNonPurgeable = fNonpurgeableResources.count();
198 stats->fNumPurgeable = fPurgeableQueue.count();
199
200 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
201 stats->update(fNonpurgeableResources[i]);
202 }
203 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
204 stats->update(fPurgeableQueue.at(i));
205 }
206}
207
bsalomon0ea80f42015-02-11 10:49:59 -0800208void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800209 this->validate();
210
bsalomonf320e042015-02-17 15:09:34 -0800211 Stats stats;
212
robertphillips60029a52015-11-09 13:51:06 -0800213 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800214
215 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
216 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
217
218 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
219 out->appendf("\t\tEntry Count: current %d"
kkinnunen2e6055b2016-04-22 01:48:29 -0700220 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n",
221 stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable,
222 stats.fScratch, countUtilization, fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800223 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800224 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
225 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800226}
227
joshualittdc5685a2015-12-02 14:08:25 -0800228void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
229 SkTArray<double>* values) const {
230 this->validate();
231
232 Stats stats;
233 this->getStats(&stats);
234
joshualittdc5685a2015-12-02 14:08:25 -0800235 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
joshualittdc5685a2015-12-02 14:08:25 -0800236}
237
mtkleinb9eb4ac2015-02-02 18:26:03 -0800238#endif
239
bsalomonddf30e62015-02-19 11:38:44 -0800240///////////////////////////////////////////////////////////////////////////////
241
242void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800243
Brian Salomon1090da62017-01-06 12:04:19 -0500244#ifdef SK_DEBUG
245int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
246 int count = 0;
247 UniqueHash::ConstIter iter(&fUniqueHash);
248 while (!iter.done()) {
249 if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
250 ++count;
251 }
252 ++iter;
253 }
254 return count;
255}
256#endif
257
bsalomon33435572014-11-05 14:47:41 -0800258///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800259
260#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -0400261 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());)
joshualittf5883a62016-01-13 07:47:38 -0800262
Chris Dalton706a6ff2017-11-29 22:01:06 -0700263
Chris Daltona32a3c32017-12-05 10:05:21 -0700264uint32_t GrRenderTargetContextPriv::testingOnly_getOpListID() {
265 return fRenderTargetContext->getOpList()->uniqueID();
266}
267
Brian Salomonac70f842017-05-08 10:43:33 -0400268uint32_t GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) {
Chris Dalton706a6ff2017-11-29 22:01:06 -0700269 return this->testingOnly_addDrawOp(GrNoClip(), std::move(op));
270}
271
272uint32_t GrRenderTargetContextPriv::testingOnly_addDrawOp(const GrClip& clip,
273 std::unique_ptr<GrDrawOp> op) {
Brian Salomonac70f842017-05-08 10:43:33 -0400274 ASSERT_SINGLE_OWNER
275 if (fRenderTargetContext->drawingManager()->wasAbandoned()) {
276 return SK_InvalidUniqueID;
277 }
278 SkDEBUGCODE(fRenderTargetContext->validate());
279 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
280 "GrRenderTargetContext::testingOnly_addDrawOp");
Chris Dalton706a6ff2017-11-29 22:01:06 -0700281 return fRenderTargetContext->addDrawOp(clip, std::move(op));
Brian Salomonac70f842017-05-08 10:43:33 -0400282}
283
joshualittf5883a62016-01-13 07:47:38 -0800284#undef ASSERT_SINGLE_OWNER
joshualittf5883a62016-01-13 07:47:38 -0800285
286///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700287
Robert Phillipsc4f0a822017-06-13 08:11:36 -0400288GrRenderTargetFlags GrRenderTargetProxy::testingOnly_getFlags() const {
Brian Salomondac5f6b2017-02-28 16:11:04 -0500289 return fRenderTargetFlags;
csmartdaltonf9635992016-08-10 11:09:07 -0700290}
291
Brian Salomon17726632017-05-12 14:09:46 -0400292//////////////////////////////////////////////////////////////////////////////
293
Chris Daltonfe199b72017-05-05 11:26:15 -0400294void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
295 fContext->flush();
296 fContext->fDrawingManager->testingOnly_removeOnFlushCallbackObject(cb);
297}
298
299void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
300 int n = std::find(fOnFlushCBObjects.begin(), fOnFlushCBObjects.end(), cb) -
301 fOnFlushCBObjects.begin();
302 SkASSERT(n < fOnFlushCBObjects.count());
303 fOnFlushCBObjects.removeShuffle(n);
304}
Brian Salomon17726632017-05-12 14:09:46 -0400305
306//////////////////////////////////////////////////////////////////////////////
307
Greg Daniel2a303902018-02-20 10:25:54 -0500308GrPixelConfig GrBackendTexture::testingOnly_getPixelConfig() const {
309 return fConfig;
310}
311
312GrPixelConfig GrBackendRenderTarget::testingOnly_getPixelConfig() const {
313 return fConfig;
314}
315
316//////////////////////////////////////////////////////////////////////////////
317
Brian Salomon17726632017-05-12 14:09:46 -0400318#define DRAW_OP_TEST_EXTERN(Op) \
Brian Salomon815486c2017-07-11 08:52:13 -0400319 extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, GrContext*, GrFSAAType)
Brian Salomon17726632017-05-12 14:09:46 -0400320#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
321
Brian Salomon10978a62017-06-15 16:21:49 -0400322DRAW_OP_TEST_EXTERN(AAConvexPathOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400323DRAW_OP_TEST_EXTERN(AAFillRectOp);
Brian Salomonb2955732017-07-13 16:42:55 -0400324DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
Brian Salomona531f252017-07-07 13:29:28 -0400325DRAW_OP_TEST_EXTERN(AAHairlineOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400326DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400327DRAW_OP_TEST_EXTERN(CircleOp);
Brian Salomon98222ac2017-07-12 15:27:54 -0400328DRAW_OP_TEST_EXTERN(DashOp);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400329DRAW_OP_TEST_EXTERN(DefaultPathOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400330DRAW_OP_TEST_EXTERN(DIEllipseOp);
331DRAW_OP_TEST_EXTERN(EllipseOp);
Brian Salomon44acb5b2017-07-18 19:59:24 -0400332DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
Brian Salomon0088f942017-07-12 11:51:27 -0400333DRAW_OP_TEST_EXTERN(GrDrawAtlasOp);
Brian Salomonc2f42542017-07-12 14:11:22 -0400334DRAW_OP_TEST_EXTERN(GrDrawVerticesOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400335DRAW_OP_TEST_EXTERN(NonAAFillRectOp);
336DRAW_OP_TEST_EXTERN(NonAALatticeOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400337DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
Brian Salomon05969092017-07-13 11:20:51 -0400338DRAW_OP_TEST_EXTERN(ShadowRRectOp);
Brian Salomonfebbd232017-07-11 15:52:02 -0400339DRAW_OP_TEST_EXTERN(SmallPathOp);
Brian Salomonf0366322017-07-11 15:53:05 -0400340DRAW_OP_TEST_EXTERN(RegionOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400341DRAW_OP_TEST_EXTERN(RRectOp);
Brian Salomon9530f7e2017-07-11 09:03:10 -0400342DRAW_OP_TEST_EXTERN(TesselatingPathOp);
Brian Salomon34169692017-08-28 15:32:01 -0400343DRAW_OP_TEST_EXTERN(TextureOp);
Brian Salomon17726632017-05-12 14:09:46 -0400344
345void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
346 GrContext* context = renderTargetContext->surfPriv().getContext();
Brian Salomon17726632017-05-12 14:09:46 -0400347 using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*, GrContext*, GrFSAAType);
348 static constexpr MakeDrawOpFn* gFactories[] = {
Brian Salomon34169692017-08-28 15:32:01 -0400349 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
350 DRAW_OP_TEST_ENTRY(AAFillRectOp),
351 DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
352 DRAW_OP_TEST_ENTRY(AAHairlineOp),
353 DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
354 DRAW_OP_TEST_ENTRY(CircleOp),
355 DRAW_OP_TEST_ENTRY(DashOp),
356 DRAW_OP_TEST_ENTRY(DefaultPathOp),
357 DRAW_OP_TEST_ENTRY(DIEllipseOp),
358 DRAW_OP_TEST_ENTRY(EllipseOp),
359 DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
360 DRAW_OP_TEST_ENTRY(GrDrawAtlasOp),
361 DRAW_OP_TEST_ENTRY(GrDrawVerticesOp),
362 DRAW_OP_TEST_ENTRY(NonAAFillRectOp),
363 DRAW_OP_TEST_ENTRY(NonAALatticeOp),
364 DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
365 DRAW_OP_TEST_ENTRY(ShadowRRectOp),
366 DRAW_OP_TEST_ENTRY(SmallPathOp),
367 DRAW_OP_TEST_ENTRY(RegionOp),
368 DRAW_OP_TEST_ENTRY(RRectOp),
369 DRAW_OP_TEST_ENTRY(TesselatingPathOp),
370 DRAW_OP_TEST_ENTRY(TextureOp),
Brian Salomon17726632017-05-12 14:09:46 -0400371 };
372
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400373 static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
Brian Salomon17726632017-05-12 14:09:46 -0400374 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400375 auto op = gFactories[index](
376 std::move(paint), random, context, renderTargetContext->fsaaType());
377 SkASSERT(op);
378 renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
Brian Salomon17726632017-05-12 14:09:46 -0400379}