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 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 8 | #include "GrBackendSurface.h" |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 9 | #include "GrContextOptions.h" |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 10 | #include "GrContextPriv.h" |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 11 | #include "GrDrawOpAtlas.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 12 | #include "GrDrawingManager.h" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 13 | #include "GrGpu.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 14 | #include "GrGpuResourceCacheAccess.h" |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 15 | #include "GrMemoryPool.h" |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 16 | #include "GrRenderTargetContext.h" |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 17 | #include "GrRenderTargetContextPriv.h" |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 18 | #include "GrRenderTargetProxy.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 19 | #include "GrResourceCache.h" |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 20 | #include "GrSemaphore.h" |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 21 | #include "GrSurfaceContextPriv.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 22 | #include "GrTest.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 23 | #include "GrTexture.h" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 24 | #include "SkGr.h" |
Robert Phillips | 22f4a1f | 2016-12-20 08:57:26 -0500 | [diff] [blame] | 25 | #include "SkImage_Gpu.h" |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 26 | #include "SkMathPriv.h" |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 27 | #include "SkString.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 28 | #include "SkTo.h" |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 29 | #include "ccpr/GrCoverageCountingPathRenderer.h" |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 30 | #include "ops/GrMeshDrawOp.h" |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 31 | #include "text/GrGlyphCache.h" |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 32 | #include "text/GrTextBlobCache.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 33 | #include <algorithm> |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 34 | |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 35 | namespace GrTest { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 36 | |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 37 | void SetupAlwaysEvictAtlas(GrContext* context, int dim) { |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 38 | // These sizes were selected because they allow each atlas to hold a single plot and will thus |
| 39 | // stress the atlas |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 40 | GrDrawOpAtlasConfig configs[3]; |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 41 | 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 Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 56 | context->contextPriv().setTextContextAtlasSizes_ForTesting(configs); |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 57 | } |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 58 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 59 | } // namespace GrTest |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 60 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 61 | bool GrSurfaceProxy::isWrapped_ForTesting() const { |
| 62 | return SkToBool(fTarget); |
| 63 | } |
| 64 | |
| 65 | bool GrRenderTargetContext::isWrapped_ForTesting() const { |
| 66 | return fRenderTargetProxy->isWrapped_ForTesting(); |
| 67 | } |
| 68 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 69 | void GrContextPriv::setTextBlobCacheLimit_ForTesting(size_t bytes) { |
| 70 | fContext->fTextBlobCache->setBudget(bytes); |
joshualitt | 17d833b | 2015-08-03 10:17:44 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 73 | void GrContextPriv::setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs) { |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 74 | GrAtlasManager* atlasManager = this->getAtlasManager(); |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 75 | if (atlasManager) { |
| 76 | atlasManager->setAtlasSizes_ForTesting(configs); |
| 77 | } |
joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 78 | } |
| 79 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 80 | /////////////////////////////////////////////////////////////////////////////// |
| 81 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 82 | void GrContextPriv::purgeAllUnlockedResources_ForTesting() { |
| 83 | fContext->fResourceCache->purgeAllUnlocked(); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 84 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 85 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 86 | void GrContextPriv::resetGpuStats() const { |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 87 | #if GR_GPU_STATS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 88 | fContext->fGpu->stats()->reset(); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 89 | #endif |
| 90 | } |
| 91 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 92 | void GrContextPriv::dumpCacheStats(SkString* out) const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 93 | #if GR_CACHE_STATS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 94 | fContext->fResourceCache->dumpStats(out); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 95 | #endif |
| 96 | } |
| 97 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 98 | void GrContextPriv::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 99 | SkTArray<double>* values) const { |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 100 | #if GR_CACHE_STATS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 101 | fContext->fResourceCache->dumpStatsKeyValuePairs(keys, values); |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 102 | #endif |
| 103 | } |
| 104 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 105 | void GrContextPriv::printCacheStats() const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 106 | SkString out; |
| 107 | this->dumpCacheStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 108 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 111 | void GrContextPriv::dumpGpuStats(SkString* out) const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 112 | #if GR_GPU_STATS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 113 | return fContext->fGpu->stats()->dump(out); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 114 | #endif |
| 115 | } |
| 116 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 117 | void GrContextPriv::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 118 | SkTArray<double>* values) const { |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 119 | #if GR_GPU_STATS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 120 | return fContext->fGpu->stats()->dumpKeyValuePairs(keys, values); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 121 | #endif |
| 122 | } |
| 123 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 124 | void GrContextPriv::printGpuStats() const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 125 | SkString out; |
| 126 | this->dumpGpuStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 127 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 130 | sk_sp<SkImage> GrContextPriv::getFontAtlasImage_ForTesting(GrMaskFormat format, unsigned int index) { |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 131 | auto atlasManager = this->getAtlasManager(); |
| 132 | if (!atlasManager) { |
| 133 | return nullptr; |
| 134 | } |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 135 | |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 136 | unsigned int numActiveProxies; |
| 137 | const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(format, &numActiveProxies); |
| 138 | if (index >= numActiveProxies || !proxies || !proxies[index]) { |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 139 | return nullptr; |
| 140 | } |
| 141 | |
Jim Van Verth | 87d18ce | 2018-01-22 12:45:47 -0500 | [diff] [blame] | 142 | SkASSERT(proxies[index]->priv().isExact()); |
Brian Salomon | 8a8dd33 | 2018-05-24 14:08:31 -0400 | [diff] [blame] | 143 | sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID, |
| 144 | kPremul_SkAlphaType, proxies[index], nullptr, |
| 145 | SkBudgeted::kNo)); |
Robert Phillips | 22f4a1f | 2016-12-20 08:57:26 -0500 | [diff] [blame] | 146 | return image; |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 147 | } |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 148 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 149 | #if GR_GPU_STATS |
| 150 | void GrGpu::Stats::dump(SkString* out) { |
| 151 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 152 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 153 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 154 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 155 | out->appendf("Transfers to Texture: %d\n", fTransfersToTexture); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 156 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 157 | out->appendf("Number of draws: %d\n", fNumDraws); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 158 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 159 | |
| 160 | void 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); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 163 | keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 164 | keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 165 | keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 166 | } |
| 167 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 168 | #endif |
| 169 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 170 | GrBackendTexture GrGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 171 | SkColorType colorType, bool isRenderTarget, |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 172 | GrMipMapped mipMapped) { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 173 | GrPixelConfig config = SkColorType2GrPixelConfig(colorType); |
Greg Daniel | 0a7aa14 | 2018-02-21 13:02:32 -0500 | [diff] [blame] | 174 | if (kUnknown_GrPixelConfig == config) { |
| 175 | return GrBackendTexture(); |
| 176 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 177 | return this->createTestingOnlyBackendTexture(pixels, w, h, config, isRenderTarget, mipMapped); |
| 178 | } |
| 179 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 180 | #if GR_CACHE_STATS |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 181 | void 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 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 196 | void GrResourceCache::dumpStats(SkString* out) const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 197 | this->validate(); |
| 198 | |
bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 199 | Stats stats; |
| 200 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 201 | this->getStats(&stats); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 202 | |
| 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" |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 208 | " (%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); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 211 | 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] | 212 | SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization, |
| 213 | SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes)); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 214 | } |
| 215 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 216 | void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 217 | SkTArray<double>* values) const { |
| 218 | this->validate(); |
| 219 | |
| 220 | Stats stats; |
| 221 | this->getStats(&stats); |
| 222 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 223 | keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable); |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 224 | } |
| 225 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 226 | #endif |
| 227 | |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 228 | /////////////////////////////////////////////////////////////////////////////// |
| 229 | |
| 230 | void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 231 | |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 232 | #ifdef SK_DEBUG |
| 233 | int 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 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 246 | /////////////////////////////////////////////////////////////////////////////// |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 247 | |
| 248 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 249 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());) |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 250 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 251 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 252 | uint32_t GrRenderTargetContextPriv::testingOnly_getOpListID() { |
| 253 | return fRenderTargetContext->getOpList()->uniqueID(); |
| 254 | } |
| 255 | |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 256 | uint32_t GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) { |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 257 | return this->testingOnly_addDrawOp(GrNoClip(), std::move(op)); |
| 258 | } |
| 259 | |
| 260 | uint32_t GrRenderTargetContextPriv::testingOnly_addDrawOp(const GrClip& clip, |
| 261 | std::unique_ptr<GrDrawOp> op) { |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 262 | ASSERT_SINGLE_OWNER |
| 263 | if (fRenderTargetContext->drawingManager()->wasAbandoned()) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 264 | fRenderTargetContext->fContext->contextPriv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 265 | return SK_InvalidUniqueID; |
| 266 | } |
| 267 | SkDEBUGCODE(fRenderTargetContext->validate()); |
| 268 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 269 | "GrRenderTargetContext::testingOnly_addDrawOp"); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 270 | return fRenderTargetContext->addDrawOp(clip, std::move(op)); |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 271 | } |
| 272 | |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 273 | #undef ASSERT_SINGLE_OWNER |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 274 | |
| 275 | /////////////////////////////////////////////////////////////////////////////// |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 276 | |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 277 | GrInternalSurfaceFlags GrSurfaceProxy::testingOnly_getFlags() const { |
| 278 | return fSurfaceFlags; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 281 | ////////////////////////////////////////////////////////////////////////////// |
| 282 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 283 | void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) { |
| 284 | fContext->flush(); |
| 285 | fContext->fDrawingManager->testingOnly_removeOnFlushCallbackObject(cb); |
| 286 | } |
| 287 | |
| 288 | void 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 Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 294 | |
| 295 | ////////////////////////////////////////////////////////////////////////////// |
| 296 | |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 297 | void 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 Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 304 | const GrUniqueKey& GrCoverageCountingPathRenderer::testingOnly_getStashedAtlasKey() const { |
| 305 | return fStashedAtlasKey; |
| 306 | } |
| 307 | |
| 308 | ////////////////////////////////////////////////////////////////////////////// |
| 309 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 310 | #define DRAW_OP_TEST_EXTERN(Op) \ |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 311 | extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, GrContext*, GrFSAAType) |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 312 | #define DRAW_OP_TEST_ENTRY(Op) Op##__Test |
| 313 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 314 | DRAW_OP_TEST_EXTERN(AAConvexPathOp); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 315 | DRAW_OP_TEST_EXTERN(AAFillRectOp); |
Brian Salomon | b295573 | 2017-07-13 16:42:55 -0400 | [diff] [blame] | 316 | DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 317 | DRAW_OP_TEST_EXTERN(AAHairlineOp); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 318 | DRAW_OP_TEST_EXTERN(AAStrokeRectOp); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 319 | DRAW_OP_TEST_EXTERN(CircleOp); |
Brian Salomon | 98222ac | 2017-07-12 15:27:54 -0400 | [diff] [blame] | 320 | DRAW_OP_TEST_EXTERN(DashOp); |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 321 | DRAW_OP_TEST_EXTERN(DefaultPathOp); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 322 | DRAW_OP_TEST_EXTERN(DIEllipseOp); |
| 323 | DRAW_OP_TEST_EXTERN(EllipseOp); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 324 | DRAW_OP_TEST_EXTERN(GrAtlasTextOp); |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 325 | DRAW_OP_TEST_EXTERN(GrDrawAtlasOp); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 326 | DRAW_OP_TEST_EXTERN(GrDrawVerticesOp); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 327 | DRAW_OP_TEST_EXTERN(NonAAFillRectOp); |
| 328 | DRAW_OP_TEST_EXTERN(NonAALatticeOp); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 329 | DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp); |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 330 | DRAW_OP_TEST_EXTERN(ShadowRRectOp); |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 331 | DRAW_OP_TEST_EXTERN(SmallPathOp); |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 332 | DRAW_OP_TEST_EXTERN(RegionOp); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 333 | DRAW_OP_TEST_EXTERN(RRectOp); |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 334 | DRAW_OP_TEST_EXTERN(TesselatingPathOp); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 335 | DRAW_OP_TEST_EXTERN(TextureOp); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 336 | |
| 337 | void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) { |
| 338 | GrContext* context = renderTargetContext->surfPriv().getContext(); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 339 | using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*, GrContext*, GrFSAAType); |
| 340 | static constexpr MakeDrawOpFn* gFactories[] = { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 341 | 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 Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 363 | }; |
| 364 | |
Brian Salomon | fc26f3c | 2017-07-14 15:27:56 -0400 | [diff] [blame] | 365 | static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 366 | uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal)); |
Brian Salomon | fc26f3c | 2017-07-14 15:27:56 -0400 | [diff] [blame] | 367 | auto op = gFactories[index]( |
| 368 | std::move(paint), random, context, renderTargetContext->fsaaType()); |
| 369 | SkASSERT(op); |
| 370 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 371 | } |