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