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