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" |
joshualitt | b542bae | 2015-07-28 09:58:39 -0700 | [diff] [blame] | 9 | |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 10 | #include "GrBatchAtlas.h" |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 11 | #include "GrContextOptions.h" |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 12 | #include "GrDrawContextPriv.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 13 | #include "GrDrawingManager.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 14 | #include "GrGpuResourceCacheAccess.h" |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 15 | #include "GrPipelineBuilder.h" |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 16 | #include "GrRenderTargetProxy.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 17 | #include "GrResourceCache.h" |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 18 | |
| 19 | #include "SkGpuDevice.h" |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 20 | #include "SkGrPriv.h" |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 21 | #include "SkMathPriv.h" |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 22 | #include "SkString.h" |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 23 | |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 24 | #include "text/GrBatchFontCache.h" |
| 25 | #include "text/GrTextBlobCache.h" |
| 26 | |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 27 | namespace GrTest { |
| 28 | void SetupAlwaysEvictAtlas(GrContext* context) { |
| 29 | // These sizes were selected because they allow each atlas to hold a single plot and will thus |
| 30 | // stress the atlas |
| 31 | int dim = GrBatchAtlas::kGlyphMaxDim; |
| 32 | GrBatchAtlasConfig configs[3]; |
| 33 | configs[kA8_GrMaskFormat].fWidth = dim; |
| 34 | configs[kA8_GrMaskFormat].fHeight = dim; |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 35 | configs[kA8_GrMaskFormat].fLog2Width = SkNextLog2(dim); |
| 36 | configs[kA8_GrMaskFormat].fLog2Height = SkNextLog2(dim); |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 37 | configs[kA8_GrMaskFormat].fPlotWidth = dim; |
| 38 | configs[kA8_GrMaskFormat].fPlotHeight = dim; |
| 39 | |
| 40 | configs[kA565_GrMaskFormat].fWidth = dim; |
| 41 | configs[kA565_GrMaskFormat].fHeight = dim; |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 42 | configs[kA565_GrMaskFormat].fLog2Width = SkNextLog2(dim); |
| 43 | configs[kA565_GrMaskFormat].fLog2Height = SkNextLog2(dim); |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 44 | configs[kA565_GrMaskFormat].fPlotWidth = dim; |
| 45 | configs[kA565_GrMaskFormat].fPlotHeight = dim; |
| 46 | |
| 47 | configs[kARGB_GrMaskFormat].fWidth = dim; |
| 48 | configs[kARGB_GrMaskFormat].fHeight = dim; |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 49 | configs[kARGB_GrMaskFormat].fLog2Width = SkNextLog2(dim); |
| 50 | configs[kARGB_GrMaskFormat].fLog2Height = SkNextLog2(dim); |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 51 | configs[kARGB_GrMaskFormat].fPlotWidth = dim; |
| 52 | configs[kARGB_GrMaskFormat].fPlotHeight = dim; |
| 53 | |
| 54 | context->setTextContextAtlasSizes_ForTesting(configs); |
| 55 | } |
| 56 | }; |
| 57 | |
robertphillips | 87f15c8 | 2016-05-20 11:14:33 -0700 | [diff] [blame] | 58 | void GrTestTarget::init(GrContext* ctx, sk_sp<GrDrawContext> drawContext) { |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 59 | SkASSERT(!fContext); |
| 60 | |
| 61 | fContext.reset(SkRef(ctx)); |
robertphillips | 87f15c8 | 2016-05-20 11:14:33 -0700 | [diff] [blame] | 62 | fDrawContext = drawContext; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 63 | } |
| 64 | |
robertphillips | 87f15c8 | 2016-05-20 11:14:33 -0700 | [diff] [blame] | 65 | void GrContext::getTestTarget(GrTestTarget* tar, sk_sp<GrDrawContext> drawContext) { |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 66 | this->flush(); |
robertphillips | 87f15c8 | 2016-05-20 11:14:33 -0700 | [diff] [blame] | 67 | SkASSERT(drawContext); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 68 | // We could create a proxy GrOpList that passes through to fGpu until ~GrTextTarget() and |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 69 | // then disconnects. This would help prevent test writers from mixing using the returned |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 70 | // GrOpList and regular drawing. We could also assert or fail in GrContext drawing methods |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 71 | // until ~GrTestTarget(). |
robertphillips | 87f15c8 | 2016-05-20 11:14:33 -0700 | [diff] [blame] | 72 | tar->init(this, std::move(drawContext)); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 73 | } |
| 74 | |
joshualitt | 17d833b | 2015-08-03 10:17:44 -0700 | [diff] [blame] | 75 | void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) { |
| 76 | fTextBlobCache->setBudget(bytes); |
| 77 | } |
| 78 | |
joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 79 | void GrContext::setTextContextAtlasSizes_ForTesting(const GrBatchAtlasConfig* configs) { |
| 80 | fBatchFontCache->setAtlasSizes_ForTesting(configs); |
| 81 | } |
| 82 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 83 | /////////////////////////////////////////////////////////////////////////////// |
| 84 | |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 85 | void GrContext::purgeAllUnlockedResources() { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 86 | fResourceCache->purgeAllUnlocked(); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 87 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 88 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 89 | void GrContext::resetGpuStats() const { |
| 90 | #if GR_GPU_STATS |
| 91 | fGpu->stats()->reset(); |
| 92 | #endif |
| 93 | } |
| 94 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 95 | void GrContext::dumpCacheStats(SkString* out) const { |
| 96 | #if GR_CACHE_STATS |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 97 | fResourceCache->dumpStats(out); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 98 | #endif |
| 99 | } |
| 100 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 101 | void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 102 | SkTArray<double>* values) const { |
| 103 | #if GR_CACHE_STATS |
| 104 | fResourceCache->dumpStatsKeyValuePairs(keys, values); |
| 105 | #endif |
| 106 | } |
| 107 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 108 | void GrContext::printCacheStats() const { |
| 109 | SkString out; |
| 110 | this->dumpCacheStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 111 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | void GrContext::dumpGpuStats(SkString* out) const { |
| 115 | #if GR_GPU_STATS |
| 116 | return fGpu->stats()->dump(out); |
| 117 | #endif |
| 118 | } |
| 119 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 120 | void GrContext::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 121 | SkTArray<double>* values) const { |
| 122 | #if GR_GPU_STATS |
| 123 | return fGpu->stats()->dumpKeyValuePairs(keys, values); |
| 124 | #endif |
| 125 | } |
| 126 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 127 | void GrContext::printGpuStats() const { |
| 128 | SkString out; |
| 129 | this->dumpGpuStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 130 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 131 | } |
| 132 | |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 133 | GrTexture* GrContext::getFontAtlasTexture(GrMaskFormat format) { |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 134 | GrBatchFontCache* cache = this->getBatchFontCache(); |
| 135 | |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 136 | return cache->getTexture(format); |
| 137 | } |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 138 | |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 139 | void SkGpuDevice::drawTexture(GrTexture* tex, const SkRect& dst, const SkPaint& paint) { |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 140 | GrPaint grPaint; |
| 141 | SkMatrix mat; |
| 142 | mat.reset(); |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 143 | if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, mat, &grPaint)) { |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 144 | return; |
| 145 | } |
| 146 | SkMatrix textureMat; |
| 147 | textureMat.reset(); |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 148 | textureMat[SkMatrix::kMScaleX] = 1.0f/dst.width(); |
| 149 | textureMat[SkMatrix::kMScaleY] = 1.0f/dst.height(); |
| 150 | textureMat[SkMatrix::kMTransX] = -dst.fLeft/dst.width(); |
| 151 | textureMat[SkMatrix::kMTransY] = -dst.fTop/dst.height(); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 152 | |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 153 | grPaint.addColorTextureProcessor(tex, nullptr, textureMat); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 154 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 155 | fDrawContext->drawRect(GrNoClip(), grPaint, mat, dst); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 156 | } |
| 157 | |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 158 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 159 | #if GR_GPU_STATS |
| 160 | void GrGpu::Stats::dump(SkString* out) { |
| 161 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 162 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 163 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 164 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 165 | out->appendf("Transfers to Texture: %d\n", fTransfersToTexture); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 166 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 167 | out->appendf("Number of draws: %d\n", fNumDraws); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 168 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 169 | |
| 170 | void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) { |
| 171 | keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds); |
| 172 | keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 173 | keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 174 | keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 175 | keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 176 | } |
| 177 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 178 | #endif |
| 179 | |
| 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 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 232 | /////////////////////////////////////////////////////////////////////////////// |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 233 | |
| 234 | #define ASSERT_SINGLE_OWNER \ |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 235 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fDrawContext->fSingleOwner);) |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 236 | #define RETURN_IF_ABANDONED if (fDrawContext->fDrawingManager->wasAbandoned()) { return; } |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 237 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 238 | void GrDrawContextPriv::testingOnly_drawBatch(const GrPaint& paint, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 239 | GrDrawBatch* batch, |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 240 | const GrUserStencilSettings* uss, |
| 241 | bool snapToCenters) { |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 242 | ASSERT_SINGLE_OWNER |
| 243 | RETURN_IF_ABANDONED |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 244 | SkDEBUGCODE(fDrawContext->validate();) |
| 245 | GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::testingOnly_drawBatch"); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 246 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 247 | GrPipelineBuilder pipelineBuilder(paint, fDrawContext->mustUseHWAA(paint)); |
| 248 | if (uss) { |
| 249 | pipelineBuilder.setUserStencil(uss); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 250 | } |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 251 | if (snapToCenters) { |
| 252 | pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, true); |
| 253 | } |
| 254 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 255 | fDrawContext->getOpList()->drawBatch(pipelineBuilder, fDrawContext, GrNoClip(), batch); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | #undef ASSERT_SINGLE_OWNER |
| 259 | #undef RETURN_IF_ABANDONED |
| 260 | |
| 261 | /////////////////////////////////////////////////////////////////////////////// |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 262 | |
| 263 | GrRenderTargetPriv::Flags GrRenderTargetProxy::testingOnly_getFlags() const { |
| 264 | return fFlags; |
| 265 | } |
| 266 | |
| 267 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 268 | // Code for the mock context. It's built on a mock GrGpu class that does nothing. |
| 269 | //// |
| 270 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 271 | #include "GrGpu.h" |
| 272 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 273 | class GrPipeline; |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 274 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 275 | class MockCaps : public GrCaps { |
| 276 | public: |
| 277 | explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {} |
| 278 | bool isConfigTexturable(GrPixelConfig config) const override { return false; } |
| 279 | bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; } |
| 280 | private: |
| 281 | typedef GrCaps INHERITED; |
| 282 | }; |
| 283 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 284 | class MockGpu : public GrGpu { |
| 285 | public: |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 286 | MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 287 | fCaps.reset(new MockCaps(options)); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 288 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 289 | ~MockGpu() override {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 290 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 291 | bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes, |
| 292 | GrPixelConfig readConfig, DrawPreference*, |
| 293 | ReadPixelTempDrawInfo*) override { return false; } |
| 294 | |
cblume | ed82800 | 2016-02-16 13:00:01 -0800 | [diff] [blame] | 295 | bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 296 | GrPixelConfig srcConfig, DrawPreference*, |
| 297 | WritePixelTempDrawInfo*) override { return false; } |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 298 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 299 | bool onCopySurface(GrSurface* dst, |
| 300 | GrSurface* src, |
| 301 | const SkIRect& srcRect, |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 302 | const SkIPoint& dstPoint) override { return false; } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 303 | |
csmartdalton | 0d28e57 | 2016-07-06 09:59:43 -0700 | [diff] [blame] | 304 | void onGetMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&, |
| 305 | int* effectiveSampleCnt, SamplePattern*) override { |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 306 | *effectiveSampleCnt = rt->desc().fSampleCnt; |
| 307 | } |
| 308 | |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 309 | bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc) const override { |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 310 | return false; |
| 311 | } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 312 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 313 | GrGpuCommandBuffer* createCommandBuffer(GrRenderTarget* target, |
| 314 | const GrGpuCommandBuffer::LoadAndStoreInfo&, |
| 315 | const GrGpuCommandBuffer::LoadAndStoreInfo&) override { |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 316 | return nullptr; |
| 317 | } |
| 318 | |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 319 | void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {} |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 320 | |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 321 | GrFence SK_WARN_UNUSED_RESULT insertFence() const override { return 0; } |
| 322 | bool waitFence(GrFence, uint64_t) const override { return true; } |
| 323 | void deleteFence(GrFence) const override {} |
| 324 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 325 | private: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 326 | void onResetContext(uint32_t resetBits) override {} |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 327 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 328 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
| 329 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 330 | GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 331 | const SkTArray<GrMipLevel>& texels) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 332 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 333 | } |
| 334 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 335 | GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 336 | const SkTArray<GrMipLevel>& texels) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 337 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 338 | } |
| 339 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame^] | 340 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 341 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 342 | } |
| 343 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame^] | 344 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, |
| 345 | GrWrapOwnership) override { |
| 346 | return nullptr; |
| 347 | } |
| 348 | |
| 349 | sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 350 | return nullptr; |
| 351 | } |
| 352 | |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 353 | GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override { |
| 354 | return nullptr; |
| 355 | } |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 356 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 357 | gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; } |
| 358 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 359 | bool onReadPixels(GrSurface* surface, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 360 | int left, int top, int width, int height, |
| 361 | GrPixelConfig, |
| 362 | void* buffer, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 363 | size_t rowBytes) override { |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 364 | return false; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 365 | } |
| 366 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 367 | bool onWritePixels(GrSurface* surface, |
| 368 | int left, int top, int width, int height, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 369 | GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 370 | return false; |
| 371 | } |
| 372 | |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 373 | bool onTransferPixels(GrSurface* surface, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 374 | int left, int top, int width, int height, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 375 | GrPixelConfig config, GrBuffer* transferBuffer, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 376 | size_t offset, size_t rowBytes) override { |
| 377 | return false; |
| 378 | } |
| 379 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 380 | void onResolveRenderTarget(GrRenderTarget* target) override { return; } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 381 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 382 | GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, |
| 383 | int width, |
| 384 | int height) override { |
| 385 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 386 | } |
| 387 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 388 | void clearStencil(GrRenderTarget* target) override {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 389 | |
jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 390 | GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 391 | GrPixelConfig config, bool isRT) override { |
cblume | 6121405 | 2016-01-26 09:10:48 -0800 | [diff] [blame] | 392 | return 0; |
jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 393 | } |
bsalomon | 67d7620 | 2015-11-11 12:40:42 -0800 | [diff] [blame] | 394 | bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; } |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 395 | void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {} |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 396 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 397 | typedef GrGpu INHERITED; |
| 398 | }; |
| 399 | |
| 400 | GrContext* GrContext::CreateMockContext() { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 401 | GrContext* context = new GrContext; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 402 | |
| 403 | context->initMockContext(); |
| 404 | return context; |
| 405 | } |
| 406 | |
| 407 | void GrContext::initMockContext() { |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 408 | GrContextOptions options; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 409 | options.fBufferMapThreshold = 0; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 410 | SkASSERT(nullptr == fGpu); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 411 | fGpu = new MockGpu(this, options); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 412 | SkASSERT(fGpu); |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 413 | this->initCommon(options); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 414 | |
| 415 | // We delete these because we want to test the cache starting with zero resources. Also, none of |
| 416 | // these objects are required for any of tests that use this context. TODO: make stop allocating |
| 417 | // resources in the buffer pools. |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 418 | fDrawingManager->abandon(); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 419 | } |