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" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 12 | #include "GrRenderTargetContextPriv.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 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 58 | void GrTestTarget::init(GrContext* ctx, sk_sp<GrRenderTargetContext> renderTargetContext) { |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 59 | SkASSERT(!fContext); |
| 60 | |
| 61 | fContext.reset(SkRef(ctx)); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 62 | fRenderTargetContext = renderTargetContext; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 65 | bool GrSurfaceProxy::isWrapped_ForTesting() const { |
| 66 | return SkToBool(fTarget); |
| 67 | } |
| 68 | |
| 69 | bool GrRenderTargetContext::isWrapped_ForTesting() const { |
| 70 | return fRenderTargetProxy->isWrapped_ForTesting(); |
| 71 | } |
| 72 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 73 | void GrContext::getTestTarget(GrTestTarget* tar, sk_sp<GrRenderTargetContext> renderTargetContext) { |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 74 | this->flush(); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 75 | SkASSERT(renderTargetContext); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 76 | // 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] | 77 | // 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] | 78 | // 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] | 79 | // until ~GrTestTarget(). |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 80 | tar->init(this, std::move(renderTargetContext)); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 81 | } |
| 82 | |
joshualitt | 17d833b | 2015-08-03 10:17:44 -0700 | [diff] [blame] | 83 | void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) { |
| 84 | fTextBlobCache->setBudget(bytes); |
| 85 | } |
| 86 | |
joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 87 | void GrContext::setTextContextAtlasSizes_ForTesting(const GrBatchAtlasConfig* configs) { |
| 88 | fBatchFontCache->setAtlasSizes_ForTesting(configs); |
| 89 | } |
| 90 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 91 | /////////////////////////////////////////////////////////////////////////////// |
| 92 | |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 93 | void GrContext::purgeAllUnlockedResources() { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 94 | fResourceCache->purgeAllUnlocked(); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 95 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 96 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 97 | void GrContext::resetGpuStats() const { |
| 98 | #if GR_GPU_STATS |
| 99 | fGpu->stats()->reset(); |
| 100 | #endif |
| 101 | } |
| 102 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 103 | void GrContext::dumpCacheStats(SkString* out) const { |
| 104 | #if GR_CACHE_STATS |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 105 | fResourceCache->dumpStats(out); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 106 | #endif |
| 107 | } |
| 108 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 109 | void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 110 | SkTArray<double>* values) const { |
| 111 | #if GR_CACHE_STATS |
| 112 | fResourceCache->dumpStatsKeyValuePairs(keys, values); |
| 113 | #endif |
| 114 | } |
| 115 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 116 | void GrContext::printCacheStats() const { |
| 117 | SkString out; |
| 118 | this->dumpCacheStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 119 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void GrContext::dumpGpuStats(SkString* out) const { |
| 123 | #if GR_GPU_STATS |
| 124 | return fGpu->stats()->dump(out); |
| 125 | #endif |
| 126 | } |
| 127 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 128 | void GrContext::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 129 | SkTArray<double>* values) const { |
| 130 | #if GR_GPU_STATS |
| 131 | return fGpu->stats()->dumpKeyValuePairs(keys, values); |
| 132 | #endif |
| 133 | } |
| 134 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 135 | void GrContext::printGpuStats() const { |
| 136 | SkString out; |
| 137 | this->dumpGpuStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 138 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 139 | } |
| 140 | |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 141 | GrTexture* GrContext::getFontAtlasTexture(GrMaskFormat format) { |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 142 | GrBatchFontCache* cache = this->getBatchFontCache(); |
| 143 | |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 144 | return cache->getTexture(format); |
| 145 | } |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 146 | |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 147 | void SkGpuDevice::drawTexture(GrTexture* tex, const SkRect& dst, const SkPaint& paint) { |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 148 | GrPaint grPaint; |
| 149 | SkMatrix mat; |
| 150 | mat.reset(); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 151 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, mat, &grPaint)) { |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 152 | return; |
| 153 | } |
| 154 | SkMatrix textureMat; |
| 155 | textureMat.reset(); |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 156 | textureMat[SkMatrix::kMScaleX] = 1.0f/dst.width(); |
| 157 | textureMat[SkMatrix::kMScaleY] = 1.0f/dst.height(); |
| 158 | textureMat[SkMatrix::kMTransX] = -dst.fLeft/dst.width(); |
| 159 | textureMat[SkMatrix::kMTransY] = -dst.fTop/dst.height(); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 160 | |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 161 | grPaint.addColorTextureProcessor(tex, nullptr, textureMat); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 162 | |
Brian Salomon | 9f54935 | 2016-12-08 10:35:19 -0500 | [diff] [blame^] | 163 | fRenderTargetContext->drawRect(GrNoClip(), grPaint, GrAA::kNo, mat, dst); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 164 | } |
| 165 | |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 166 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 167 | #if GR_GPU_STATS |
| 168 | void GrGpu::Stats::dump(SkString* out) { |
| 169 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 170 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 171 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 172 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 173 | out->appendf("Transfers to Texture: %d\n", fTransfersToTexture); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 174 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 175 | out->appendf("Number of draws: %d\n", fNumDraws); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 176 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 177 | |
| 178 | void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) { |
| 179 | keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds); |
| 180 | keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 181 | keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 182 | keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 183 | keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 184 | } |
| 185 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 186 | #endif |
| 187 | |
| 188 | #if GR_CACHE_STATS |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 189 | void GrResourceCache::getStats(Stats* stats) const { |
| 190 | stats->reset(); |
| 191 | |
| 192 | stats->fTotal = this->getResourceCount(); |
| 193 | stats->fNumNonPurgeable = fNonpurgeableResources.count(); |
| 194 | stats->fNumPurgeable = fPurgeableQueue.count(); |
| 195 | |
| 196 | for (int i = 0; i < fNonpurgeableResources.count(); ++i) { |
| 197 | stats->update(fNonpurgeableResources[i]); |
| 198 | } |
| 199 | for (int i = 0; i < fPurgeableQueue.count(); ++i) { |
| 200 | stats->update(fPurgeableQueue.at(i)); |
| 201 | } |
| 202 | } |
| 203 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 204 | void GrResourceCache::dumpStats(SkString* out) const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 205 | this->validate(); |
| 206 | |
bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 207 | Stats stats; |
| 208 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 209 | this->getStats(&stats); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 210 | |
| 211 | float countUtilization = (100.f * fBudgetedCount) / fMaxCount; |
| 212 | float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes; |
| 213 | |
| 214 | out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes); |
| 215 | out->appendf("\t\tEntry Count: current %d" |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 216 | " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n", |
| 217 | stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable, |
| 218 | stats.fScratch, countUtilization, fHighWaterCount); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 219 | 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] | 220 | SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization, |
| 221 | SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes)); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 222 | } |
| 223 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 224 | void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 225 | SkTArray<double>* values) const { |
| 226 | this->validate(); |
| 227 | |
| 228 | Stats stats; |
| 229 | this->getStats(&stats); |
| 230 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 231 | keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable); |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 232 | } |
| 233 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 234 | #endif |
| 235 | |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 236 | /////////////////////////////////////////////////////////////////////////////// |
| 237 | |
| 238 | void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 239 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 240 | /////////////////////////////////////////////////////////////////////////////// |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 241 | |
| 242 | #define ASSERT_SINGLE_OWNER \ |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 243 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->fSingleOwner);) |
| 244 | #define RETURN_IF_ABANDONED if (fRenderTargetContext->fDrawingManager->wasAbandoned()) { return; } |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 245 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 246 | void GrRenderTargetContextPriv::testingOnly_drawBatch(const GrPaint& paint, |
Brian Salomon | 9f54935 | 2016-12-08 10:35:19 -0500 | [diff] [blame^] | 247 | GrAAType aaType, |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 248 | GrDrawOp* batch, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 249 | const GrUserStencilSettings* uss, |
| 250 | bool snapToCenters) { |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 251 | ASSERT_SINGLE_OWNER |
| 252 | RETURN_IF_ABANDONED |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 253 | SkDEBUGCODE(fRenderTargetContext->validate();) |
| 254 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
| 255 | "GrRenderTargetContext::testingOnly_drawBatch"); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 256 | |
Brian Salomon | 9f54935 | 2016-12-08 10:35:19 -0500 | [diff] [blame^] | 257 | GrPipelineBuilder pipelineBuilder(paint, aaType); |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 258 | if (uss) { |
| 259 | pipelineBuilder.setUserStencil(uss); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 260 | } |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 261 | if (snapToCenters) { |
| 262 | pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, true); |
| 263 | } |
| 264 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 265 | fRenderTargetContext->getOpList()->addDrawOp(pipelineBuilder, fRenderTargetContext, GrNoClip(), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 266 | batch); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | #undef ASSERT_SINGLE_OWNER |
| 270 | #undef RETURN_IF_ABANDONED |
| 271 | |
| 272 | /////////////////////////////////////////////////////////////////////////////// |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 273 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 274 | GrRenderTarget::Flags GrRenderTargetProxy::testingOnly_getFlags() const { |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 275 | return fFlags; |
| 276 | } |
| 277 | |
| 278 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 279 | // Code for the mock context. It's built on a mock GrGpu class that does nothing. |
| 280 | //// |
| 281 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 282 | #include "GrGpu.h" |
| 283 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 284 | class GrPipeline; |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 285 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 286 | class MockCaps : public GrCaps { |
| 287 | public: |
| 288 | explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {} |
| 289 | bool isConfigTexturable(GrPixelConfig config) const override { return false; } |
| 290 | bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; } |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 291 | bool canConfigBeImageStorage(GrPixelConfig) const override { return false; } |
| 292 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 293 | private: |
| 294 | typedef GrCaps INHERITED; |
| 295 | }; |
| 296 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 297 | class MockGpu : public GrGpu { |
| 298 | public: |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 299 | MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 300 | fCaps.reset(new MockCaps(options)); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 301 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 302 | ~MockGpu() override {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 303 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 304 | bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes, |
| 305 | GrPixelConfig readConfig, DrawPreference*, |
| 306 | ReadPixelTempDrawInfo*) override { return false; } |
| 307 | |
cblume | ed82800 | 2016-02-16 13:00:01 -0800 | [diff] [blame] | 308 | bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 309 | GrPixelConfig srcConfig, DrawPreference*, |
| 310 | WritePixelTempDrawInfo*) override { return false; } |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 311 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 312 | bool onCopySurface(GrSurface* dst, |
| 313 | GrSurface* src, |
| 314 | const SkIRect& srcRect, |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 315 | const SkIPoint& dstPoint) override { return false; } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 316 | |
csmartdalton | c25c5d7 | 2016-11-01 07:03:59 -0700 | [diff] [blame] | 317 | void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&, |
| 318 | int* effectiveSampleCnt, SamplePattern*) override { |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 319 | *effectiveSampleCnt = rt->desc().fSampleCnt; |
| 320 | } |
| 321 | |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 322 | bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc) const override { |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 323 | return false; |
| 324 | } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 325 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 326 | GrGpuCommandBuffer* createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&, |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 327 | const GrGpuCommandBuffer::LoadAndStoreInfo&) override { |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 328 | return nullptr; |
| 329 | } |
| 330 | |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 331 | void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {} |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 332 | |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 333 | GrFence SK_WARN_UNUSED_RESULT insertFence() const override { return 0; } |
| 334 | bool waitFence(GrFence, uint64_t) const override { return true; } |
| 335 | void deleteFence(GrFence) const override {} |
| 336 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 337 | private: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 338 | void onResetContext(uint32_t resetBits) override {} |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 339 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 340 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
| 341 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 342 | GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 343 | const SkTArray<GrMipLevel>& texels) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 344 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 345 | } |
| 346 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 347 | GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 348 | const SkTArray<GrMipLevel>& texels) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 349 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 350 | } |
| 351 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 352 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 353 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 354 | } |
| 355 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 356 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, |
| 357 | GrWrapOwnership) override { |
| 358 | return nullptr; |
| 359 | } |
| 360 | |
| 361 | sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 362 | return nullptr; |
| 363 | } |
| 364 | |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 365 | GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override { |
| 366 | return nullptr; |
| 367 | } |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 368 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 369 | gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; } |
| 370 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 371 | bool onReadPixels(GrSurface* surface, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 372 | int left, int top, int width, int height, |
| 373 | GrPixelConfig, |
| 374 | void* buffer, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 375 | size_t rowBytes) override { |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 376 | return false; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 377 | } |
| 378 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 379 | bool onWritePixels(GrSurface* surface, |
| 380 | int left, int top, int width, int height, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 381 | GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 382 | return false; |
| 383 | } |
| 384 | |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 385 | bool onTransferPixels(GrSurface* surface, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 386 | int left, int top, int width, int height, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 387 | GrPixelConfig config, GrBuffer* transferBuffer, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 388 | size_t offset, size_t rowBytes) override { |
| 389 | return false; |
| 390 | } |
| 391 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 392 | void onResolveRenderTarget(GrRenderTarget* target) override { return; } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 393 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 394 | GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, |
| 395 | int width, |
| 396 | int height) override { |
| 397 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 398 | } |
| 399 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 400 | void clearStencil(GrRenderTarget* target) override {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 401 | |
jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 402 | GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 403 | GrPixelConfig config, bool isRT) override { |
cblume | 6121405 | 2016-01-26 09:10:48 -0800 | [diff] [blame] | 404 | return 0; |
jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 405 | } |
bsalomon | 67d7620 | 2015-11-11 12:40:42 -0800 | [diff] [blame] | 406 | bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; } |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 407 | void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {} |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 408 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 409 | typedef GrGpu INHERITED; |
| 410 | }; |
| 411 | |
| 412 | GrContext* GrContext::CreateMockContext() { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 413 | GrContext* context = new GrContext; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 414 | |
| 415 | context->initMockContext(); |
| 416 | return context; |
| 417 | } |
| 418 | |
| 419 | void GrContext::initMockContext() { |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 420 | GrContextOptions options; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 421 | options.fBufferMapThreshold = 0; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 422 | SkASSERT(nullptr == fGpu); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 423 | fGpu = new MockGpu(this, options); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 424 | SkASSERT(fGpu); |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 425 | this->initCommon(options); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 426 | |
| 427 | // We delete these because we want to test the cache starting with zero resources. Also, none of |
| 428 | // these objects are required for any of tests that use this context. TODO: make stop allocating |
| 429 | // resources in the buffer pools. |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 430 | fDrawingManager->abandon(); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 431 | } |