commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 1 | /* |
| 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 Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 9 | #include <algorithm> |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 10 | #include "GrBackendSurface.h" |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 11 | #include "GrContextOptions.h" |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 12 | #include "GrContextPriv.h" |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 13 | #include "GrDrawOpAtlas.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 14 | #include "GrDrawingManager.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 15 | #include "GrGpuResourceCacheAccess.h" |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 16 | #include "GrPipelineBuilder.h" |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 17 | #include "GrRenderTargetContext.h" |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 18 | #include "GrRenderTargetContextPriv.h" |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 19 | #include "GrRenderTargetProxy.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 20 | #include "GrResourceCache.h" |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 21 | #include "GrSemaphore.h" |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 22 | #include "GrSurfaceContextPriv.h" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 23 | #include "SkGr.h" |
Robert Phillips | 22f4a1f | 2016-12-20 08:57:26 -0500 | [diff] [blame] | 24 | #include "SkImage_Gpu.h" |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 25 | #include "SkMathPriv.h" |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 26 | #include "SkString.h" |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 27 | #include "ops/GrMeshDrawOp.h" |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 28 | #include "text/GrAtlasGlyphCache.h" |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 29 | #include "text/GrTextBlobCache.h" |
| 30 | |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 31 | namespace GrTest { |
| 32 | void SetupAlwaysEvictAtlas(GrContext* context) { |
| 33 | // These sizes were selected because they allow each atlas to hold a single plot and will thus |
| 34 | // stress the atlas |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 35 | int dim = GrDrawOpAtlas::kGlyphMaxDim; |
| 36 | GrDrawOpAtlasConfig configs[3]; |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 37 | configs[kA8_GrMaskFormat].fWidth = dim; |
| 38 | configs[kA8_GrMaskFormat].fHeight = dim; |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 39 | configs[kA8_GrMaskFormat].fLog2Width = SkNextLog2(dim); |
| 40 | configs[kA8_GrMaskFormat].fLog2Height = SkNextLog2(dim); |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 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; |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 46 | configs[kA565_GrMaskFormat].fLog2Width = SkNextLog2(dim); |
| 47 | configs[kA565_GrMaskFormat].fLog2Height = SkNextLog2(dim); |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 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; |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 53 | configs[kARGB_GrMaskFormat].fLog2Width = SkNextLog2(dim); |
| 54 | configs[kARGB_GrMaskFormat].fLog2Height = SkNextLog2(dim); |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 55 | configs[kARGB_GrMaskFormat].fPlotWidth = dim; |
| 56 | configs[kARGB_GrMaskFormat].fPlotHeight = dim; |
| 57 | |
| 58 | context->setTextContextAtlasSizes_ForTesting(configs); |
| 59 | } |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 60 | |
| 61 | GrBackendTexture CreateBackendTexture(GrBackend backend, int width, int height, |
| 62 | GrPixelConfig config, GrBackendObject handle) { |
| 63 | if (kOpenGL_GrBackend == backend) { |
| 64 | GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle); |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 65 | return GrBackendTexture(width, height, config, *glInfo); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 66 | } else { |
| 67 | SkASSERT(kVulkan_GrBackend == backend); |
| 68 | GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle); |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 69 | return GrBackendTexture(width, height, *vkInfo); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 74 | bool GrSurfaceProxy::isWrapped_ForTesting() const { |
| 75 | return SkToBool(fTarget); |
| 76 | } |
| 77 | |
| 78 | bool GrRenderTargetContext::isWrapped_ForTesting() const { |
| 79 | return fRenderTargetProxy->isWrapped_ForTesting(); |
| 80 | } |
| 81 | |
joshualitt | 17d833b | 2015-08-03 10:17:44 -0700 | [diff] [blame] | 82 | void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) { |
| 83 | fTextBlobCache->setBudget(bytes); |
| 84 | } |
| 85 | |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 86 | void GrContext::setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs) { |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 87 | fAtlasGlyphCache->setAtlasSizes_ForTesting(configs); |
joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 88 | } |
| 89 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 90 | /////////////////////////////////////////////////////////////////////////////// |
| 91 | |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 92 | void GrContext::purgeAllUnlockedResources() { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 93 | fResourceCache->purgeAllUnlocked(); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 94 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 95 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 96 | void GrContext::resetGpuStats() const { |
| 97 | #if GR_GPU_STATS |
| 98 | fGpu->stats()->reset(); |
| 99 | #endif |
| 100 | } |
| 101 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 102 | void GrContext::dumpCacheStats(SkString* out) const { |
| 103 | #if GR_CACHE_STATS |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 104 | fResourceCache->dumpStats(out); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 105 | #endif |
| 106 | } |
| 107 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 108 | void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 109 | SkTArray<double>* values) const { |
| 110 | #if GR_CACHE_STATS |
| 111 | fResourceCache->dumpStatsKeyValuePairs(keys, values); |
| 112 | #endif |
| 113 | } |
| 114 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 115 | void GrContext::printCacheStats() const { |
| 116 | SkString out; |
| 117 | this->dumpCacheStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 118 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void GrContext::dumpGpuStats(SkString* out) const { |
| 122 | #if GR_GPU_STATS |
| 123 | return fGpu->stats()->dump(out); |
| 124 | #endif |
| 125 | } |
| 126 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 127 | void GrContext::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 128 | SkTArray<double>* values) const { |
| 129 | #if GR_GPU_STATS |
| 130 | return fGpu->stats()->dumpKeyValuePairs(keys, values); |
| 131 | #endif |
| 132 | } |
| 133 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 134 | void GrContext::printGpuStats() const { |
| 135 | SkString out; |
| 136 | this->dumpGpuStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 137 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Robert Phillips | c37e614 | 2017-01-20 10:03:25 -0500 | [diff] [blame] | 140 | sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format) { |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 141 | GrAtlasGlyphCache* cache = this->getAtlasGlyphCache(); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 142 | |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 143 | sk_sp<GrTextureProxy> proxy = cache->getProxy(format); |
| 144 | if (!proxy) { |
| 145 | return nullptr; |
| 146 | } |
| 147 | |
Robert Phillips | b726d58 | 2017-03-09 16:36:32 -0500 | [diff] [blame] | 148 | SkASSERT(proxy->priv().isExact()); |
| 149 | sk_sp<SkImage> image(new SkImage_Gpu(this, kNeedNewImageUniqueID, kPremul_SkAlphaType, |
| 150 | std::move(proxy), nullptr, SkBudgeted::kNo)); |
Robert Phillips | 22f4a1f | 2016-12-20 08:57:26 -0500 | [diff] [blame] | 151 | return image; |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 152 | } |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 153 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 154 | #if GR_GPU_STATS |
| 155 | void GrGpu::Stats::dump(SkString* out) { |
| 156 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 157 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 158 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 159 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 160 | out->appendf("Transfers to Texture: %d\n", fTransfersToTexture); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 161 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 162 | out->appendf("Number of draws: %d\n", fNumDraws); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 163 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 164 | |
| 165 | void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) { |
| 166 | keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds); |
| 167 | keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 168 | keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 169 | keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 170 | keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 171 | } |
| 172 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 173 | #endif |
| 174 | |
| 175 | #if GR_CACHE_STATS |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 176 | void GrResourceCache::getStats(Stats* stats) const { |
| 177 | stats->reset(); |
| 178 | |
| 179 | stats->fTotal = this->getResourceCount(); |
| 180 | stats->fNumNonPurgeable = fNonpurgeableResources.count(); |
| 181 | stats->fNumPurgeable = fPurgeableQueue.count(); |
| 182 | |
| 183 | for (int i = 0; i < fNonpurgeableResources.count(); ++i) { |
| 184 | stats->update(fNonpurgeableResources[i]); |
| 185 | } |
| 186 | for (int i = 0; i < fPurgeableQueue.count(); ++i) { |
| 187 | stats->update(fPurgeableQueue.at(i)); |
| 188 | } |
| 189 | } |
| 190 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 191 | void GrResourceCache::dumpStats(SkString* out) const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 192 | this->validate(); |
| 193 | |
bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 194 | Stats stats; |
| 195 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 196 | this->getStats(&stats); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 197 | |
| 198 | float countUtilization = (100.f * fBudgetedCount) / fMaxCount; |
| 199 | float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes; |
| 200 | |
| 201 | out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes); |
| 202 | out->appendf("\t\tEntry Count: current %d" |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 203 | " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n", |
| 204 | stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable, |
| 205 | stats.fScratch, countUtilization, fHighWaterCount); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 206 | out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n", |
bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 207 | SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization, |
| 208 | SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes)); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 209 | } |
| 210 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 211 | void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 212 | SkTArray<double>* values) const { |
| 213 | this->validate(); |
| 214 | |
| 215 | Stats stats; |
| 216 | this->getStats(&stats); |
| 217 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 218 | keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable); |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 219 | } |
| 220 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 221 | #endif |
| 222 | |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 223 | /////////////////////////////////////////////////////////////////////////////// |
| 224 | |
| 225 | void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 226 | |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 227 | #ifdef SK_DEBUG |
| 228 | int GrResourceCache::countUniqueKeysWithTag(const char* tag) const { |
| 229 | int count = 0; |
| 230 | UniqueHash::ConstIter iter(&fUniqueHash); |
| 231 | while (!iter.done()) { |
| 232 | if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) { |
| 233 | ++count; |
| 234 | } |
| 235 | ++iter; |
| 236 | } |
| 237 | return count; |
| 238 | } |
| 239 | #endif |
| 240 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 241 | /////////////////////////////////////////////////////////////////////////////// |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 242 | |
| 243 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 244 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());) |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 245 | |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 246 | uint32_t GrRenderTargetContextPriv::testingOnly_addLegacyMeshDrawOp( |
| 247 | GrPaint&& paint, |
| 248 | GrAAType aaType, |
| 249 | std::unique_ptr<GrLegacyMeshDrawOp> op, |
| 250 | const GrUserStencilSettings* uss, |
| 251 | bool snapToCenters) { |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 252 | ASSERT_SINGLE_OWNER |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 253 | if (fRenderTargetContext->drawingManager()->wasAbandoned()) { |
| 254 | return SK_InvalidUniqueID; |
| 255 | } |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 256 | SkDEBUGCODE(fRenderTargetContext->validate()); |
| 257 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 258 | "GrRenderTargetContext::testingOnly_addLegacyMeshDrawOp"); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 259 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 260 | GrPipelineBuilder pipelineBuilder(std::move(paint), aaType); |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 261 | if (uss) { |
| 262 | pipelineBuilder.setUserStencil(uss); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 263 | } |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 264 | pipelineBuilder.setSnapVerticesToPixelCenters(snapToCenters); |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 265 | |
Brian Salomon | e14bd80 | 2017-04-04 15:13:25 -0400 | [diff] [blame] | 266 | return fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), GrNoClip(), |
| 267 | std::move(op)); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 270 | uint32_t GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) { |
| 271 | ASSERT_SINGLE_OWNER |
| 272 | if (fRenderTargetContext->drawingManager()->wasAbandoned()) { |
| 273 | return SK_InvalidUniqueID; |
| 274 | } |
| 275 | SkDEBUGCODE(fRenderTargetContext->validate()); |
| 276 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 277 | "GrRenderTargetContext::testingOnly_addDrawOp"); |
| 278 | return fRenderTargetContext->addDrawOp(GrNoClip(), std::move(op)); |
| 279 | } |
| 280 | |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 281 | #undef ASSERT_SINGLE_OWNER |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 282 | |
| 283 | /////////////////////////////////////////////////////////////////////////////// |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 284 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 285 | GrRenderTarget::Flags GrRenderTargetProxy::testingOnly_getFlags() const { |
Brian Salomon | dac5f6b | 2017-02-28 16:11:04 -0500 | [diff] [blame] | 286 | return fRenderTargetFlags; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 290 | // Code for the mock context. It's built on a mock GrGpu class that does nothing. |
| 291 | //// |
| 292 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 293 | #include "GrGpu.h" |
| 294 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 295 | class GrPipeline; |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 296 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 297 | class MockCaps : public GrCaps { |
| 298 | public: |
| 299 | explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {} |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame^] | 300 | bool isConfigTexturable(GrPixelConfig) const override { return false; } |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 301 | bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; } |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 302 | bool canConfigBeImageStorage(GrPixelConfig) const override { return false; } |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 303 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, |
| 304 | bool* rectsMustMatch, bool* disallowSubrect) const override { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 305 | return false; |
| 306 | } |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 307 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 308 | private: |
| 309 | typedef GrCaps INHERITED; |
| 310 | }; |
| 311 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 312 | class MockGpu : public GrGpu { |
| 313 | public: |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 314 | MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 315 | fCaps.reset(new MockCaps(options)); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 316 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 317 | ~MockGpu() override {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 318 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 319 | bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes, |
| 320 | GrPixelConfig readConfig, DrawPreference*, |
| 321 | ReadPixelTempDrawInfo*) override { return false; } |
| 322 | |
cblume | ed82800 | 2016-02-16 13:00:01 -0800 | [diff] [blame] | 323 | bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 324 | GrPixelConfig srcConfig, DrawPreference*, |
| 325 | WritePixelTempDrawInfo*) override { return false; } |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 326 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 327 | bool onCopySurface(GrSurface* dst, |
| 328 | GrSurface* src, |
| 329 | const SkIRect& srcRect, |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 330 | const SkIPoint& dstPoint) override { return false; } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 331 | |
csmartdalton | c25c5d7 | 2016-11-01 07:03:59 -0700 | [diff] [blame] | 332 | void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&, |
| 333 | int* effectiveSampleCnt, SamplePattern*) override { |
Brian Salomon | 154ce91 | 2017-05-17 10:40:02 -0400 | [diff] [blame] | 334 | *effectiveSampleCnt = rt->numStencilSamples(); |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 337 | GrGpuCommandBuffer* createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&, |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 338 | const GrGpuCommandBuffer::LoadAndStoreInfo&) override { |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 339 | return nullptr; |
| 340 | } |
| 341 | |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 342 | void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {} |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 343 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 344 | GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; } |
| 345 | bool waitFence(GrFence, uint64_t) override { return true; } |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 346 | void deleteFence(GrFence) const override {} |
| 347 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 348 | sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore() override { return nullptr; } |
Brian Osman | dc87c95 | 2017-04-28 13:57:38 -0400 | [diff] [blame] | 349 | void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override {} |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 350 | void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {} |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 351 | sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { return nullptr; } |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 352 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 353 | private: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 354 | void onResetContext(uint32_t resetBits) override {} |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 355 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 356 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
| 357 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 358 | GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 359 | const SkTArray<GrMipLevel>& texels) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 360 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 361 | } |
| 362 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 363 | GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 364 | const SkTArray<GrMipLevel>& texels) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 365 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 366 | } |
| 367 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 368 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, |
| 369 | GrSurfaceOrigin, |
| 370 | GrBackendTextureFlags, |
| 371 | int sampleCnt, |
| 372 | GrWrapOwnership) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 373 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 374 | } |
| 375 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 376 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&, |
| 377 | GrSurfaceOrigin) override { |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 378 | return nullptr; |
| 379 | } |
| 380 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 381 | sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, |
| 382 | GrSurfaceOrigin, |
| 383 | int sampleCnt) override { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 384 | return nullptr; |
| 385 | } |
| 386 | |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 387 | GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override { |
| 388 | return nullptr; |
| 389 | } |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 390 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 391 | gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; } |
| 392 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 393 | bool onReadPixels(GrSurface* surface, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 394 | int left, int top, int width, int height, |
| 395 | GrPixelConfig, |
| 396 | void* buffer, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 397 | size_t rowBytes) override { |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 398 | return false; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 399 | } |
| 400 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 401 | bool onWritePixels(GrSurface* surface, |
| 402 | int left, int top, int width, int height, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 403 | GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 404 | return false; |
| 405 | } |
| 406 | |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 407 | bool onTransferPixels(GrSurface* surface, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 408 | int left, int top, int width, int height, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 409 | GrPixelConfig config, GrBuffer* transferBuffer, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 410 | size_t offset, size_t rowBytes) override { |
| 411 | return false; |
| 412 | } |
| 413 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 414 | void onResolveRenderTarget(GrRenderTarget* target) override { return; } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 415 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 416 | GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, |
| 417 | int width, |
| 418 | int height) override { |
| 419 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 420 | } |
| 421 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 422 | void clearStencil(GrRenderTarget* target) override {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 423 | |
jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 424 | GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 425 | GrPixelConfig config, bool isRT) override { |
cblume | 6121405 | 2016-01-26 09:10:48 -0800 | [diff] [blame] | 426 | return 0; |
jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 427 | } |
bsalomon | 67d7620 | 2015-11-11 12:40:42 -0800 | [diff] [blame] | 428 | bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; } |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 429 | void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {} |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 430 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 431 | typedef GrGpu INHERITED; |
| 432 | }; |
| 433 | |
| 434 | GrContext* GrContext::CreateMockContext() { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 435 | GrContext* context = new GrContext; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 436 | |
| 437 | context->initMockContext(); |
| 438 | return context; |
| 439 | } |
| 440 | |
| 441 | void GrContext::initMockContext() { |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 442 | GrContextOptions options; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 443 | options.fBufferMapThreshold = 0; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 444 | SkASSERT(nullptr == fGpu); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 445 | fGpu = new MockGpu(this, options); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 446 | SkASSERT(fGpu); |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 447 | this->initCommon(options); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 448 | |
| 449 | // We delete these because we want to test the cache starting with zero resources. Also, none of |
| 450 | // these objects are required for any of tests that use this context. TODO: make stop allocating |
| 451 | // resources in the buffer pools. |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 452 | fDrawingManager->abandon(); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 453 | } |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 454 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 455 | ////////////////////////////////////////////////////////////////////////////// |
| 456 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 457 | void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) { |
| 458 | fContext->flush(); |
| 459 | fContext->fDrawingManager->testingOnly_removeOnFlushCallbackObject(cb); |
| 460 | } |
| 461 | |
| 462 | void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject* cb) { |
| 463 | int n = std::find(fOnFlushCBObjects.begin(), fOnFlushCBObjects.end(), cb) - |
| 464 | fOnFlushCBObjects.begin(); |
| 465 | SkASSERT(n < fOnFlushCBObjects.count()); |
| 466 | fOnFlushCBObjects.removeShuffle(n); |
| 467 | } |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 468 | |
| 469 | ////////////////////////////////////////////////////////////////////////////// |
| 470 | |
| 471 | #define DRAW_OP_TEST_EXTERN(Op) \ |
| 472 | extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, GrContext*, GrFSAAType); |
| 473 | |
| 474 | #define LEGACY_MESH_DRAW_OP_TEST_EXTERN(Op) \ |
| 475 | extern std::unique_ptr<GrLegacyMeshDrawOp> Op##__Test(SkRandom*, GrContext*); |
| 476 | |
| 477 | #define DRAW_OP_TEST_ENTRY(Op) Op##__Test |
| 478 | |
| 479 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(AAConvexPathOp); |
| 480 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(AAFillRectOp); |
| 481 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(AAFillRectOpLocalMatrix); |
| 482 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp) |
| 483 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(AAHairlineOp); |
| 484 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(AAStrokeRectOp); |
| 485 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(AnalyticRectOp); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 486 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(DashOp); |
| 487 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(DefaultPathOp); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 488 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(GrDrawAtlasOp); |
| 489 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 490 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(SmallPathOp); |
| 491 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(TesselatingPathOp); |
| 492 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(TextBlobOp); |
| 493 | LEGACY_MESH_DRAW_OP_TEST_EXTERN(VerticesOp); |
| 494 | |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 495 | DRAW_OP_TEST_EXTERN(CircleOp) |
| 496 | DRAW_OP_TEST_EXTERN(DIEllipseOp); |
| 497 | DRAW_OP_TEST_EXTERN(EllipseOp); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 498 | DRAW_OP_TEST_EXTERN(NonAAFillRectOp) |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 499 | DRAW_OP_TEST_EXTERN(RRectOp); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 500 | |
| 501 | void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) { |
| 502 | GrContext* context = renderTargetContext->surfPriv().getContext(); |
| 503 | using MakeTestLegacyMeshDrawOpFn = std::unique_ptr<GrLegacyMeshDrawOp>(SkRandom*, GrContext*); |
| 504 | static constexpr MakeTestLegacyMeshDrawOpFn* gLegacyFactories[] = { |
| 505 | DRAW_OP_TEST_ENTRY(AAConvexPathOp), |
| 506 | DRAW_OP_TEST_ENTRY(AAFillRectOp), |
| 507 | DRAW_OP_TEST_ENTRY(AAFillRectOpLocalMatrix), |
| 508 | DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp), |
| 509 | DRAW_OP_TEST_ENTRY(AAHairlineOp), |
| 510 | DRAW_OP_TEST_ENTRY(AAStrokeRectOp), |
| 511 | DRAW_OP_TEST_ENTRY(AnalyticRectOp), |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 512 | DRAW_OP_TEST_ENTRY(DashOp), |
| 513 | DRAW_OP_TEST_ENTRY(DefaultPathOp), |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 514 | DRAW_OP_TEST_ENTRY(GrDrawAtlasOp), |
| 515 | DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp), |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 516 | DRAW_OP_TEST_ENTRY(SmallPathOp), |
| 517 | DRAW_OP_TEST_ENTRY(TesselatingPathOp), |
| 518 | DRAW_OP_TEST_ENTRY(TextBlobOp), |
| 519 | DRAW_OP_TEST_ENTRY(VerticesOp) |
| 520 | }; |
| 521 | |
| 522 | using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*, GrContext*, GrFSAAType); |
| 523 | static constexpr MakeDrawOpFn* gFactories[] = { |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 524 | DRAW_OP_TEST_ENTRY(CircleOp), |
| 525 | DRAW_OP_TEST_ENTRY(DIEllipseOp), |
| 526 | DRAW_OP_TEST_ENTRY(EllipseOp), |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 527 | DRAW_OP_TEST_ENTRY(NonAAFillRectOp), |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 528 | DRAW_OP_TEST_ENTRY(RRectOp), |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | static constexpr size_t kTotal = SK_ARRAY_COUNT(gLegacyFactories) + SK_ARRAY_COUNT(gFactories); |
| 532 | |
| 533 | uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal)); |
| 534 | if (index < SK_ARRAY_COUNT(gLegacyFactories)) { |
| 535 | const GrUserStencilSettings* uss = GrGetRandomStencil(random, context); |
| 536 | // We don't use kHW because we will hit an assertion if the render target is not |
| 537 | // multisampled |
| 538 | static constexpr GrAAType kAATypes[] = {GrAAType::kNone, GrAAType::kCoverage}; |
| 539 | GrAAType aaType = kAATypes[random->nextULessThan(SK_ARRAY_COUNT(kAATypes))]; |
| 540 | bool snapToCenters = random->nextBool(); |
| 541 | auto op = gLegacyFactories[index](random, context); |
| 542 | SkASSERT(op); |
| 543 | renderTargetContext->priv().testingOnly_addLegacyMeshDrawOp( |
| 544 | std::move(paint), aaType, std::move(op), uss, snapToCenters); |
| 545 | } else { |
| 546 | auto op = gFactories[index - SK_ARRAY_COUNT(gLegacyFactories)]( |
| 547 | std::move(paint), random, context, renderTargetContext->fsaaType()); |
| 548 | SkASSERT(op); |
| 549 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
| 550 | } |
| 551 | } |