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" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 15 | #include "GrGpu.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 16 | #include "GrGpuResourceCacheAccess.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" |
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" |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 28 | #include "ops/GrMeshDrawOp.h" |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 29 | #include "text/GrAtlasGlyphCache.h" |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 30 | #include "text/GrTextBlobCache.h" |
| 31 | |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 32 | namespace GrTest { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 33 | |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 34 | void 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 Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 37 | int dim = GrDrawOpAtlas::kGlyphMaxDim; |
| 38 | GrDrawOpAtlasConfig configs[3]; |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 39 | 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 Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 56 | |
| 57 | GrBackendTexture CreateBackendTexture(GrBackend backend, int width, int height, |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 58 | GrPixelConfig config, GrMipMapped mipMapped, |
| 59 | GrBackendObject handle) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 60 | switch (backend) { |
Mike Reed | d20b5c4 | 2017-06-14 06:03:10 -0400 | [diff] [blame] | 61 | #ifdef SK_VULKAN |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 62 | case kVulkan_GrBackend: { |
| 63 | GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 64 | SkASSERT((GrMipMapped::kYes == mipMapped) == (vkInfo->fLevelCount > 1)); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 65 | return GrBackendTexture(width, height, *vkInfo); |
| 66 | } |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 67 | #endif |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 68 | case kOpenGL_GrBackend: { |
| 69 | GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 70 | return GrBackendTexture(width, height, config, mipMapped, *glInfo); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 71 | } |
| 72 | case kMock_GrBackend: { |
| 73 | GrMockTextureInfo* mockInfo = (GrMockTextureInfo*)(handle); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 74 | return GrBackendTexture(width, height, config, mipMapped, *mockInfo); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 75 | } |
| 76 | default: |
| 77 | return GrBackendTexture(); |
| 78 | } |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 79 | } |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 80 | |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 81 | GrBackendRenderTarget CreateBackendRenderTarget(GrBackend backend, int width, int height, |
| 82 | int sampleCnt, int stencilBits, |
| 83 | GrPixelConfig config, |
| 84 | GrBackendObject handle) { |
| 85 | switch (backend) { |
| 86 | #ifdef SK_VULKAN |
| 87 | case kVulkan_GrBackend: { |
| 88 | GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle); |
| 89 | return GrBackendRenderTarget(width, height, sampleCnt, stencilBits, *vkInfo); |
| 90 | } |
| 91 | #endif |
| 92 | case kOpenGL_GrBackend: { |
Robert Phillips | 7f1b4f8 | 2017-11-28 07:38:39 -0500 | [diff] [blame^] | 93 | GrGLFramebufferInfo glInfo; |
| 94 | glInfo.fFBOID = handle; |
| 95 | return GrBackendRenderTarget(width, height, sampleCnt, stencilBits, config, glInfo); |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 96 | } |
| 97 | case kMock_GrBackend: // fall through |
| 98 | default: |
| 99 | return GrBackendRenderTarget(); |
| 100 | } |
| 101 | } |
| 102 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 103 | } // namespace GrTest |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 104 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 105 | bool GrSurfaceProxy::isWrapped_ForTesting() const { |
| 106 | return SkToBool(fTarget); |
| 107 | } |
| 108 | |
| 109 | bool GrRenderTargetContext::isWrapped_ForTesting() const { |
| 110 | return fRenderTargetProxy->isWrapped_ForTesting(); |
| 111 | } |
| 112 | |
joshualitt | 17d833b | 2015-08-03 10:17:44 -0700 | [diff] [blame] | 113 | void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) { |
| 114 | fTextBlobCache->setBudget(bytes); |
| 115 | } |
| 116 | |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 117 | void GrContext::setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs) { |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 118 | fAtlasGlyphCache->setAtlasSizes_ForTesting(configs); |
joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 119 | } |
| 120 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 121 | /////////////////////////////////////////////////////////////////////////////// |
| 122 | |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 123 | void GrContext::purgeAllUnlockedResources() { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 124 | fResourceCache->purgeAllUnlocked(); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 125 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 126 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 127 | void GrContext::resetGpuStats() const { |
| 128 | #if GR_GPU_STATS |
| 129 | fGpu->stats()->reset(); |
| 130 | #endif |
| 131 | } |
| 132 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 133 | void GrContext::dumpCacheStats(SkString* out) const { |
| 134 | #if GR_CACHE_STATS |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 135 | fResourceCache->dumpStats(out); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 136 | #endif |
| 137 | } |
| 138 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 139 | void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 140 | SkTArray<double>* values) const { |
| 141 | #if GR_CACHE_STATS |
| 142 | fResourceCache->dumpStatsKeyValuePairs(keys, values); |
| 143 | #endif |
| 144 | } |
| 145 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 146 | void GrContext::printCacheStats() const { |
| 147 | SkString out; |
| 148 | this->dumpCacheStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 149 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | void GrContext::dumpGpuStats(SkString* out) const { |
| 153 | #if GR_GPU_STATS |
| 154 | return fGpu->stats()->dump(out); |
| 155 | #endif |
| 156 | } |
| 157 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 158 | void GrContext::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 159 | SkTArray<double>* values) const { |
| 160 | #if GR_GPU_STATS |
| 161 | return fGpu->stats()->dumpKeyValuePairs(keys, values); |
| 162 | #endif |
| 163 | } |
| 164 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 165 | void GrContext::printGpuStats() const { |
| 166 | SkString out; |
| 167 | this->dumpGpuStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 168 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Robert Phillips | c37e614 | 2017-01-20 10:03:25 -0500 | [diff] [blame] | 171 | sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format) { |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 172 | GrAtlasGlyphCache* cache = this->getAtlasGlyphCache(); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 173 | |
Jim Van Verth | a950b63 | 2017-09-12 11:54:11 -0400 | [diff] [blame] | 174 | const sk_sp<GrTextureProxy>* proxies = cache->getProxies(format); |
| 175 | if (!proxies[0]) { |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 176 | return nullptr; |
| 177 | } |
| 178 | |
Jim Van Verth | a950b63 | 2017-09-12 11:54:11 -0400 | [diff] [blame] | 179 | SkASSERT(proxies[0]->priv().isExact()); |
Robert Phillips | b726d58 | 2017-03-09 16:36:32 -0500 | [diff] [blame] | 180 | sk_sp<SkImage> image(new SkImage_Gpu(this, kNeedNewImageUniqueID, kPremul_SkAlphaType, |
Jim Van Verth | a950b63 | 2017-09-12 11:54:11 -0400 | [diff] [blame] | 181 | std::move(proxies[0]), nullptr, SkBudgeted::kNo)); |
Robert Phillips | 22f4a1f | 2016-12-20 08:57:26 -0500 | [diff] [blame] | 182 | return image; |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 183 | } |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 184 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 185 | #if GR_GPU_STATS |
| 186 | void GrGpu::Stats::dump(SkString* out) { |
| 187 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 188 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 189 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 190 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 191 | out->appendf("Transfers to Texture: %d\n", fTransfersToTexture); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 192 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 193 | out->appendf("Number of draws: %d\n", fNumDraws); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 194 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 195 | |
| 196 | void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) { |
| 197 | keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds); |
| 198 | keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 199 | keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 200 | keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 201 | keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 202 | } |
| 203 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 204 | #endif |
| 205 | |
| 206 | #if GR_CACHE_STATS |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 207 | void GrResourceCache::getStats(Stats* stats) const { |
| 208 | stats->reset(); |
| 209 | |
| 210 | stats->fTotal = this->getResourceCount(); |
| 211 | stats->fNumNonPurgeable = fNonpurgeableResources.count(); |
| 212 | stats->fNumPurgeable = fPurgeableQueue.count(); |
| 213 | |
| 214 | for (int i = 0; i < fNonpurgeableResources.count(); ++i) { |
| 215 | stats->update(fNonpurgeableResources[i]); |
| 216 | } |
| 217 | for (int i = 0; i < fPurgeableQueue.count(); ++i) { |
| 218 | stats->update(fPurgeableQueue.at(i)); |
| 219 | } |
| 220 | } |
| 221 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 222 | void GrResourceCache::dumpStats(SkString* out) const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 223 | this->validate(); |
| 224 | |
bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 225 | Stats stats; |
| 226 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 227 | this->getStats(&stats); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 228 | |
| 229 | float countUtilization = (100.f * fBudgetedCount) / fMaxCount; |
| 230 | float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes; |
| 231 | |
| 232 | out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes); |
| 233 | out->appendf("\t\tEntry Count: current %d" |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 234 | " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n", |
| 235 | stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable, |
| 236 | stats.fScratch, countUtilization, fHighWaterCount); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 237 | 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] | 238 | SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization, |
| 239 | SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes)); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 240 | } |
| 241 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 242 | void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 243 | SkTArray<double>* values) const { |
| 244 | this->validate(); |
| 245 | |
| 246 | Stats stats; |
| 247 | this->getStats(&stats); |
| 248 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 249 | keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable); |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 250 | } |
| 251 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 252 | #endif |
| 253 | |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 254 | /////////////////////////////////////////////////////////////////////////////// |
| 255 | |
| 256 | void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 257 | |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 258 | #ifdef SK_DEBUG |
| 259 | int GrResourceCache::countUniqueKeysWithTag(const char* tag) const { |
| 260 | int count = 0; |
| 261 | UniqueHash::ConstIter iter(&fUniqueHash); |
| 262 | while (!iter.done()) { |
| 263 | if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) { |
| 264 | ++count; |
| 265 | } |
| 266 | ++iter; |
| 267 | } |
| 268 | return count; |
| 269 | } |
| 270 | #endif |
| 271 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 272 | /////////////////////////////////////////////////////////////////////////////// |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 273 | |
| 274 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 275 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());) |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 276 | |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 277 | uint32_t GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) { |
| 278 | ASSERT_SINGLE_OWNER |
| 279 | if (fRenderTargetContext->drawingManager()->wasAbandoned()) { |
| 280 | return SK_InvalidUniqueID; |
| 281 | } |
| 282 | SkDEBUGCODE(fRenderTargetContext->validate()); |
| 283 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 284 | "GrRenderTargetContext::testingOnly_addDrawOp"); |
| 285 | return fRenderTargetContext->addDrawOp(GrNoClip(), std::move(op)); |
| 286 | } |
| 287 | |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 288 | #undef ASSERT_SINGLE_OWNER |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 289 | |
| 290 | /////////////////////////////////////////////////////////////////////////////// |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 291 | |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 292 | GrRenderTargetFlags GrRenderTargetProxy::testingOnly_getFlags() const { |
Brian Salomon | dac5f6b | 2017-02-28 16:11:04 -0500 | [diff] [blame] | 293 | return fRenderTargetFlags; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 296 | ////////////////////////////////////////////////////////////////////////////// |
| 297 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 298 | void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) { |
| 299 | fContext->flush(); |
| 300 | fContext->fDrawingManager->testingOnly_removeOnFlushCallbackObject(cb); |
| 301 | } |
| 302 | |
| 303 | void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject* cb) { |
| 304 | int n = std::find(fOnFlushCBObjects.begin(), fOnFlushCBObjects.end(), cb) - |
| 305 | fOnFlushCBObjects.begin(); |
| 306 | SkASSERT(n < fOnFlushCBObjects.count()); |
| 307 | fOnFlushCBObjects.removeShuffle(n); |
| 308 | } |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 309 | |
| 310 | ////////////////////////////////////////////////////////////////////////////// |
| 311 | |
| 312 | #define DRAW_OP_TEST_EXTERN(Op) \ |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 313 | extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, GrContext*, GrFSAAType) |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 314 | #define DRAW_OP_TEST_ENTRY(Op) Op##__Test |
| 315 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 316 | DRAW_OP_TEST_EXTERN(AAConvexPathOp); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 317 | DRAW_OP_TEST_EXTERN(AAFillRectOp); |
Brian Salomon | b295573 | 2017-07-13 16:42:55 -0400 | [diff] [blame] | 318 | DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 319 | DRAW_OP_TEST_EXTERN(AAHairlineOp); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 320 | DRAW_OP_TEST_EXTERN(AAStrokeRectOp); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 321 | DRAW_OP_TEST_EXTERN(CircleOp); |
Brian Salomon | 98222ac | 2017-07-12 15:27:54 -0400 | [diff] [blame] | 322 | DRAW_OP_TEST_EXTERN(DashOp); |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 323 | DRAW_OP_TEST_EXTERN(DefaultPathOp); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 324 | DRAW_OP_TEST_EXTERN(DIEllipseOp); |
| 325 | DRAW_OP_TEST_EXTERN(EllipseOp); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 326 | DRAW_OP_TEST_EXTERN(GrAtlasTextOp); |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 327 | DRAW_OP_TEST_EXTERN(GrDrawAtlasOp); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 328 | DRAW_OP_TEST_EXTERN(GrDrawVerticesOp); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 329 | DRAW_OP_TEST_EXTERN(NonAAFillRectOp); |
| 330 | DRAW_OP_TEST_EXTERN(NonAALatticeOp); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 331 | DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp); |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 332 | DRAW_OP_TEST_EXTERN(ShadowRRectOp); |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 333 | DRAW_OP_TEST_EXTERN(SmallPathOp); |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 334 | DRAW_OP_TEST_EXTERN(RegionOp); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 335 | DRAW_OP_TEST_EXTERN(RRectOp); |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 336 | DRAW_OP_TEST_EXTERN(TesselatingPathOp); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 337 | DRAW_OP_TEST_EXTERN(TextureOp); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 338 | |
| 339 | void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) { |
| 340 | GrContext* context = renderTargetContext->surfPriv().getContext(); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 341 | using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*, GrContext*, GrFSAAType); |
| 342 | static constexpr MakeDrawOpFn* gFactories[] = { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 343 | DRAW_OP_TEST_ENTRY(AAConvexPathOp), |
| 344 | DRAW_OP_TEST_ENTRY(AAFillRectOp), |
| 345 | DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp), |
| 346 | DRAW_OP_TEST_ENTRY(AAHairlineOp), |
| 347 | DRAW_OP_TEST_ENTRY(AAStrokeRectOp), |
| 348 | DRAW_OP_TEST_ENTRY(CircleOp), |
| 349 | DRAW_OP_TEST_ENTRY(DashOp), |
| 350 | DRAW_OP_TEST_ENTRY(DefaultPathOp), |
| 351 | DRAW_OP_TEST_ENTRY(DIEllipseOp), |
| 352 | DRAW_OP_TEST_ENTRY(EllipseOp), |
| 353 | DRAW_OP_TEST_ENTRY(GrAtlasTextOp), |
| 354 | DRAW_OP_TEST_ENTRY(GrDrawAtlasOp), |
| 355 | DRAW_OP_TEST_ENTRY(GrDrawVerticesOp), |
| 356 | DRAW_OP_TEST_ENTRY(NonAAFillRectOp), |
| 357 | DRAW_OP_TEST_ENTRY(NonAALatticeOp), |
| 358 | DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp), |
| 359 | DRAW_OP_TEST_ENTRY(ShadowRRectOp), |
| 360 | DRAW_OP_TEST_ENTRY(SmallPathOp), |
| 361 | DRAW_OP_TEST_ENTRY(RegionOp), |
| 362 | DRAW_OP_TEST_ENTRY(RRectOp), |
| 363 | DRAW_OP_TEST_ENTRY(TesselatingPathOp), |
| 364 | DRAW_OP_TEST_ENTRY(TextureOp), |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 365 | }; |
| 366 | |
Brian Salomon | fc26f3c | 2017-07-14 15:27:56 -0400 | [diff] [blame] | 367 | static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 368 | uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal)); |
Brian Salomon | fc26f3c | 2017-07-14 15:27:56 -0400 | [diff] [blame] | 369 | auto op = gFactories[index]( |
| 370 | std::move(paint), random, context, renderTargetContext->fsaaType()); |
| 371 | SkASSERT(op); |
| 372 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 373 | } |