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" |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 9 | #include "GrClip.h" |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 10 | #include "GrContextOptions.h" |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 11 | #include "GrContextPriv.h" |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 12 | #include "GrDrawOpAtlas.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 13 | #include "GrDrawingManager.h" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 14 | #include "GrGpu.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 15 | #include "GrGpuResourceCacheAccess.h" |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 16 | #include "GrMemoryPool.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" |
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 | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 33 | |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 34 | #include <algorithm> |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 35 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 36 | bool GrSurfaceProxy::isWrapped_ForTesting() const { |
| 37 | return SkToBool(fTarget); |
| 38 | } |
| 39 | |
| 40 | bool GrRenderTargetContext::isWrapped_ForTesting() const { |
| 41 | return fRenderTargetProxy->isWrapped_ForTesting(); |
| 42 | } |
| 43 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 44 | void GrContextPriv::setTextBlobCacheLimit_ForTesting(size_t bytes) { |
| 45 | fContext->fTextBlobCache->setBudget(bytes); |
joshualitt | 17d833b | 2015-08-03 10:17:44 -0700 | [diff] [blame] | 46 | } |
| 47 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 48 | /////////////////////////////////////////////////////////////////////////////// |
| 49 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 50 | void GrContextPriv::purgeAllUnlockedResources_ForTesting() { |
| 51 | fContext->fResourceCache->purgeAllUnlocked(); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 52 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 53 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 54 | void GrContextPriv::resetGpuStats() const { |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 55 | #if GR_GPU_STATS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 56 | fContext->fGpu->stats()->reset(); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 57 | #endif |
| 58 | } |
| 59 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 60 | void GrContextPriv::dumpCacheStats(SkString* out) const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 61 | #if GR_CACHE_STATS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 62 | fContext->fResourceCache->dumpStats(out); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 63 | #endif |
| 64 | } |
| 65 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 66 | void GrContextPriv::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 67 | SkTArray<double>* values) const { |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 68 | #if GR_CACHE_STATS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 69 | fContext->fResourceCache->dumpStatsKeyValuePairs(keys, values); |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 70 | #endif |
| 71 | } |
| 72 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 73 | void GrContextPriv::printCacheStats() const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 74 | SkString out; |
| 75 | this->dumpCacheStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 76 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 79 | void GrContextPriv::dumpGpuStats(SkString* out) const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 80 | #if GR_GPU_STATS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 81 | return fContext->fGpu->stats()->dump(out); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 82 | #endif |
| 83 | } |
| 84 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 85 | void GrContextPriv::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 86 | SkTArray<double>* values) 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 | return fContext->fGpu->stats()->dumpKeyValuePairs(keys, values); |
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::printGpuStats() const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 93 | SkString out; |
| 94 | this->dumpGpuStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 95 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 98 | sk_sp<SkImage> GrContextPriv::getFontAtlasImage_ForTesting(GrMaskFormat format, unsigned int index) { |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 99 | auto atlasManager = this->getAtlasManager(); |
| 100 | if (!atlasManager) { |
| 101 | return nullptr; |
| 102 | } |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 103 | |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 104 | unsigned int numActiveProxies; |
| 105 | const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(format, &numActiveProxies); |
| 106 | if (index >= numActiveProxies || !proxies || !proxies[index]) { |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 107 | return nullptr; |
| 108 | } |
| 109 | |
Jim Van Verth | 87d18ce | 2018-01-22 12:45:47 -0500 | [diff] [blame] | 110 | SkASSERT(proxies[index]->priv().isExact()); |
Brian Salomon | 8a8dd33 | 2018-05-24 14:08:31 -0400 | [diff] [blame] | 111 | sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID, |
| 112 | kPremul_SkAlphaType, proxies[index], nullptr, |
| 113 | SkBudgeted::kNo)); |
Robert Phillips | 22f4a1f | 2016-12-20 08:57:26 -0500 | [diff] [blame] | 114 | return image; |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 115 | } |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 116 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 117 | #if GR_GPU_STATS |
| 118 | void GrGpu::Stats::dump(SkString* out) { |
| 119 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 120 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 121 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 122 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 123 | out->appendf("Transfers to Texture: %d\n", fTransfersToTexture); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 124 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 125 | out->appendf("Number of draws: %d\n", fNumDraws); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 126 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 127 | |
| 128 | void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) { |
| 129 | keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds); |
| 130 | keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 131 | keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 132 | keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 133 | keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 134 | } |
| 135 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 136 | #endif |
| 137 | |
| 138 | #if GR_CACHE_STATS |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 139 | void GrResourceCache::getStats(Stats* stats) const { |
| 140 | stats->reset(); |
| 141 | |
| 142 | stats->fTotal = this->getResourceCount(); |
| 143 | stats->fNumNonPurgeable = fNonpurgeableResources.count(); |
| 144 | stats->fNumPurgeable = fPurgeableQueue.count(); |
| 145 | |
| 146 | for (int i = 0; i < fNonpurgeableResources.count(); ++i) { |
| 147 | stats->update(fNonpurgeableResources[i]); |
| 148 | } |
| 149 | for (int i = 0; i < fPurgeableQueue.count(); ++i) { |
| 150 | stats->update(fPurgeableQueue.at(i)); |
| 151 | } |
| 152 | } |
| 153 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 154 | void GrResourceCache::dumpStats(SkString* out) const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 155 | this->validate(); |
| 156 | |
bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 157 | Stats stats; |
| 158 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 159 | this->getStats(&stats); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 160 | |
| 161 | float countUtilization = (100.f * fBudgetedCount) / fMaxCount; |
| 162 | float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes; |
| 163 | |
| 164 | out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes); |
| 165 | out->appendf("\t\tEntry Count: current %d" |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 166 | " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n", |
| 167 | stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable, |
| 168 | stats.fScratch, countUtilization, fHighWaterCount); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 169 | 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] | 170 | SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization, |
| 171 | SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes)); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 172 | } |
| 173 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 174 | void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 175 | SkTArray<double>* values) const { |
| 176 | this->validate(); |
| 177 | |
| 178 | Stats stats; |
| 179 | this->getStats(&stats); |
| 180 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 181 | keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable); |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 182 | } |
| 183 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 184 | #endif |
| 185 | |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 186 | /////////////////////////////////////////////////////////////////////////////// |
| 187 | |
| 188 | void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 189 | |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 190 | #ifdef SK_DEBUG |
| 191 | int GrResourceCache::countUniqueKeysWithTag(const char* tag) const { |
| 192 | int count = 0; |
| 193 | UniqueHash::ConstIter iter(&fUniqueHash); |
| 194 | while (!iter.done()) { |
| 195 | if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) { |
| 196 | ++count; |
| 197 | } |
| 198 | ++iter; |
| 199 | } |
| 200 | return count; |
| 201 | } |
| 202 | #endif |
| 203 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 204 | /////////////////////////////////////////////////////////////////////////////// |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 205 | |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 206 | sk_sp<GrTextureProxy> GrProxyProvider::testingOnly_createInstantiatedProxy( |
| 207 | const GrSurfaceDesc& desc, GrSurfaceOrigin origin, SkBackingFit fit, SkBudgeted budgeted) { |
| 208 | sk_sp<GrTexture> tex; |
| 209 | |
| 210 | if (SkBackingFit::kApprox == fit) { |
| 211 | tex = fResourceProvider->createApproxTexture(desc, GrResourceProvider::Flags::kNone); |
| 212 | } else { |
| 213 | tex = fResourceProvider->createTexture(desc, budgeted, GrResourceProvider::Flags::kNone); |
| 214 | } |
| 215 | if (!tex) { |
| 216 | return nullptr; |
| 217 | } |
| 218 | |
| 219 | return this->createWrapped(std::move(tex), origin); |
| 220 | } |
| 221 | |
| 222 | /////////////////////////////////////////////////////////////////////////////// |
| 223 | |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 224 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a90aa2b | 2017-04-10 08:19:26 -0400 | [diff] [blame] | 225 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());) |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 226 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 227 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 228 | uint32_t GrRenderTargetContextPriv::testingOnly_getOpListID() { |
| 229 | return fRenderTargetContext->getOpList()->uniqueID(); |
| 230 | } |
| 231 | |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 232 | void GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) { |
| 233 | this->testingOnly_addDrawOp(GrNoClip(), std::move(op)); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 236 | void GrRenderTargetContextPriv::testingOnly_addDrawOp( |
| 237 | const GrClip& clip, |
| 238 | std::unique_ptr<GrDrawOp> op, |
| 239 | const std::function<GrRenderTargetContext::WillAddOpFn>& willAddFn) { |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 240 | ASSERT_SINGLE_OWNER |
| 241 | if (fRenderTargetContext->drawingManager()->wasAbandoned()) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 242 | fRenderTargetContext->fContext->contextPriv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 243 | return; |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 244 | } |
| 245 | SkDEBUGCODE(fRenderTargetContext->validate()); |
| 246 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 247 | "GrRenderTargetContext::testingOnly_addDrawOp"); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 248 | fRenderTargetContext->addDrawOp(clip, std::move(op), willAddFn); |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 249 | } |
| 250 | |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 251 | #undef ASSERT_SINGLE_OWNER |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 252 | |
| 253 | /////////////////////////////////////////////////////////////////////////////// |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 254 | |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 255 | GrInternalSurfaceFlags GrSurfaceProxy::testingOnly_getFlags() const { |
| 256 | return fSurfaceFlags; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 259 | ////////////////////////////////////////////////////////////////////////////// |
| 260 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 261 | void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) { |
| 262 | fContext->flush(); |
| 263 | fContext->fDrawingManager->testingOnly_removeOnFlushCallbackObject(cb); |
| 264 | } |
| 265 | |
| 266 | void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject* cb) { |
| 267 | int n = std::find(fOnFlushCBObjects.begin(), fOnFlushCBObjects.end(), cb) - |
| 268 | fOnFlushCBObjects.begin(); |
| 269 | SkASSERT(n < fOnFlushCBObjects.count()); |
| 270 | fOnFlushCBObjects.removeShuffle(n); |
| 271 | } |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 272 | |
| 273 | ////////////////////////////////////////////////////////////////////////////// |
| 274 | |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 275 | void GrCoverageCountingPathRenderer::testingOnly_drawPathDirectly(const DrawPathArgs& args) { |
| 276 | // Call onDrawPath() directly: We want to test paths that might fail onCanDrawPath() simply for |
| 277 | // performance reasons, and GrPathRenderer::drawPath() assert that this call returns true. |
| 278 | // The test is responsible to not draw any paths that CCPR is not actually capable of. |
| 279 | this->onDrawPath(args); |
| 280 | } |
| 281 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 282 | const GrUniqueKey& GrCoverageCountingPathRenderer::testingOnly_getStashedAtlasKey() const { |
| 283 | return fStashedAtlasKey; |
| 284 | } |
| 285 | |
| 286 | ////////////////////////////////////////////////////////////////////////////// |
| 287 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 288 | #define DRAW_OP_TEST_EXTERN(Op) \ |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 289 | extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, GrContext*, GrFSAAType) |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 290 | #define DRAW_OP_TEST_ENTRY(Op) Op##__Test |
| 291 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 292 | DRAW_OP_TEST_EXTERN(AAConvexPathOp); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 293 | DRAW_OP_TEST_EXTERN(AAFillRectOp); |
Brian Salomon | b295573 | 2017-07-13 16:42:55 -0400 | [diff] [blame] | 294 | DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 295 | DRAW_OP_TEST_EXTERN(AAHairlineOp); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 296 | DRAW_OP_TEST_EXTERN(AAStrokeRectOp); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 297 | DRAW_OP_TEST_EXTERN(CircleOp); |
Brian Salomon | 98222ac | 2017-07-12 15:27:54 -0400 | [diff] [blame] | 298 | DRAW_OP_TEST_EXTERN(DashOp); |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 299 | DRAW_OP_TEST_EXTERN(DefaultPathOp); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 300 | DRAW_OP_TEST_EXTERN(DIEllipseOp); |
| 301 | DRAW_OP_TEST_EXTERN(EllipseOp); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 302 | DRAW_OP_TEST_EXTERN(GrAtlasTextOp); |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 303 | DRAW_OP_TEST_EXTERN(GrDrawAtlasOp); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 304 | DRAW_OP_TEST_EXTERN(GrDrawVerticesOp); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 305 | DRAW_OP_TEST_EXTERN(NonAAFillRectOp); |
| 306 | DRAW_OP_TEST_EXTERN(NonAALatticeOp); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 307 | DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp); |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 308 | DRAW_OP_TEST_EXTERN(ShadowRRectOp); |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 309 | DRAW_OP_TEST_EXTERN(SmallPathOp); |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 310 | DRAW_OP_TEST_EXTERN(RegionOp); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 311 | DRAW_OP_TEST_EXTERN(RRectOp); |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 312 | DRAW_OP_TEST_EXTERN(TesselatingPathOp); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 313 | DRAW_OP_TEST_EXTERN(TextureOp); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 314 | |
| 315 | void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) { |
| 316 | GrContext* context = renderTargetContext->surfPriv().getContext(); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 317 | using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*, GrContext*, GrFSAAType); |
| 318 | static constexpr MakeDrawOpFn* gFactories[] = { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 319 | DRAW_OP_TEST_ENTRY(AAConvexPathOp), |
| 320 | DRAW_OP_TEST_ENTRY(AAFillRectOp), |
| 321 | DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp), |
| 322 | DRAW_OP_TEST_ENTRY(AAHairlineOp), |
| 323 | DRAW_OP_TEST_ENTRY(AAStrokeRectOp), |
| 324 | DRAW_OP_TEST_ENTRY(CircleOp), |
| 325 | DRAW_OP_TEST_ENTRY(DashOp), |
| 326 | DRAW_OP_TEST_ENTRY(DefaultPathOp), |
| 327 | DRAW_OP_TEST_ENTRY(DIEllipseOp), |
| 328 | DRAW_OP_TEST_ENTRY(EllipseOp), |
| 329 | DRAW_OP_TEST_ENTRY(GrAtlasTextOp), |
| 330 | DRAW_OP_TEST_ENTRY(GrDrawAtlasOp), |
| 331 | DRAW_OP_TEST_ENTRY(GrDrawVerticesOp), |
| 332 | DRAW_OP_TEST_ENTRY(NonAAFillRectOp), |
| 333 | DRAW_OP_TEST_ENTRY(NonAALatticeOp), |
| 334 | DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp), |
| 335 | DRAW_OP_TEST_ENTRY(ShadowRRectOp), |
| 336 | DRAW_OP_TEST_ENTRY(SmallPathOp), |
| 337 | DRAW_OP_TEST_ENTRY(RegionOp), |
| 338 | DRAW_OP_TEST_ENTRY(RRectOp), |
| 339 | DRAW_OP_TEST_ENTRY(TesselatingPathOp), |
| 340 | DRAW_OP_TEST_ENTRY(TextureOp), |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 341 | }; |
| 342 | |
Brian Salomon | fc26f3c | 2017-07-14 15:27:56 -0400 | [diff] [blame] | 343 | static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 344 | uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal)); |
Brian Salomon | fc26f3c | 2017-07-14 15:27:56 -0400 | [diff] [blame] | 345 | auto op = gFactories[index]( |
| 346 | std::move(paint), random, context, renderTargetContext->fsaaType()); |
| 347 | SkASSERT(op); |
| 348 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 349 | } |