| 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" |
| joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 12 | #include "GrBatchFontCache.h" |
| bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 13 | #include "GrContextOptions.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" |
| joshualitt | 17d833b | 2015-08-03 10:17:44 -0700 | [diff] [blame] | 17 | #include "GrTextBlobCache.h" |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 18 | #include "SkString.h" |
| commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 19 | |
| joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 20 | namespace GrTest { |
| 21 | void SetupAlwaysEvictAtlas(GrContext* context) { |
| 22 | // These sizes were selected because they allow each atlas to hold a single plot and will thus |
| 23 | // stress the atlas |
| 24 | int dim = GrBatchAtlas::kGlyphMaxDim; |
| 25 | GrBatchAtlasConfig configs[3]; |
| 26 | configs[kA8_GrMaskFormat].fWidth = dim; |
| 27 | configs[kA8_GrMaskFormat].fHeight = dim; |
| 28 | configs[kA8_GrMaskFormat].fPlotWidth = dim; |
| 29 | configs[kA8_GrMaskFormat].fPlotHeight = dim; |
| 30 | |
| 31 | configs[kA565_GrMaskFormat].fWidth = dim; |
| 32 | configs[kA565_GrMaskFormat].fHeight = dim; |
| 33 | configs[kA565_GrMaskFormat].fPlotWidth = dim; |
| 34 | configs[kA565_GrMaskFormat].fPlotHeight = dim; |
| 35 | |
| 36 | configs[kARGB_GrMaskFormat].fWidth = dim; |
| 37 | configs[kARGB_GrMaskFormat].fHeight = dim; |
| 38 | configs[kARGB_GrMaskFormat].fPlotWidth = dim; |
| 39 | configs[kARGB_GrMaskFormat].fPlotHeight = dim; |
| 40 | |
| 41 | context->setTextContextAtlasSizes_ForTesting(configs); |
| 42 | } |
| 43 | }; |
| 44 | |
| jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 45 | void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target) { |
| commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 46 | SkASSERT(!fContext); |
| 47 | |
| 48 | fContext.reset(SkRef(ctx)); |
| 49 | fDrawTarget.reset(SkRef(target)); |
| commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void GrContext::getTestTarget(GrTestTarget* tar) { |
| 53 | this->flush(); |
| 54 | // We could create a proxy GrDrawTarget that passes through to fGpu until ~GrTextTarget() and |
| 55 | // then disconnects. This would help prevent test writers from mixing using the returned |
| 56 | // GrDrawTarget and regular drawing. We could also assert or fail in GrContext drawing methods |
| 57 | // until ~GrTestTarget(). |
| robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 58 | SkAutoTUnref<GrDrawTarget> dt(fDrawingManager->newDrawTarget(nullptr)); |
| robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 59 | tar->init(this, dt); |
| commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| joshualitt | 17d833b | 2015-08-03 10:17:44 -0700 | [diff] [blame] | 62 | void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) { |
| 63 | fTextBlobCache->setBudget(bytes); |
| 64 | } |
| 65 | |
| joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 66 | void GrContext::setTextContextAtlasSizes_ForTesting(const GrBatchAtlasConfig* configs) { |
| 67 | fBatchFontCache->setAtlasSizes_ForTesting(configs); |
| 68 | } |
| 69 | |
| commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 70 | /////////////////////////////////////////////////////////////////////////////// |
| 71 | |
| robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 72 | void GrContext::purgeAllUnlockedResources() { |
| bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 73 | fResourceCache->purgeAllUnlocked(); |
| robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 74 | } |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 75 | |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 76 | void GrContext::dumpCacheStats(SkString* out) const { |
| 77 | #if GR_CACHE_STATS |
| bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 78 | fResourceCache->dumpStats(out); |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 79 | #endif |
| 80 | } |
| 81 | |
| 82 | void GrContext::printCacheStats() const { |
| 83 | SkString out; |
| 84 | this->dumpCacheStats(&out); |
| kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 85 | SkDebugf("%s", out.c_str()); |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void GrContext::dumpGpuStats(SkString* out) const { |
| 89 | #if GR_GPU_STATS |
| 90 | return fGpu->stats()->dump(out); |
| 91 | #endif |
| 92 | } |
| 93 | |
| 94 | void GrContext::printGpuStats() const { |
| 95 | SkString out; |
| 96 | this->dumpGpuStats(&out); |
| kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 97 | SkDebugf("%s", out.c_str()); |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | #if GR_GPU_STATS |
| 101 | void GrGpu::Stats::dump(SkString* out) { |
| 102 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 103 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
| bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 104 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 105 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
| egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 106 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
| joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 107 | out->appendf("Number of draws: %d\n", fNumDraws); |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 108 | } |
| 109 | #endif |
| 110 | |
| 111 | #if GR_CACHE_STATS |
| bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 112 | void GrResourceCache::dumpStats(SkString* out) const { |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 113 | this->validate(); |
| 114 | |
| bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 115 | int locked = fNonpurgeableResources.count(); |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 116 | |
| bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 117 | struct Stats { |
| 118 | int fScratch; |
| bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 119 | int fExternal; |
| 120 | int fBorrowed; |
| 121 | int fAdopted; |
| bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 122 | size_t fUnbudgetedSize; |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 123 | |
| bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 124 | Stats() : fScratch(0), fExternal(0), fBorrowed(0), fAdopted(0), fUnbudgetedSize(0) {} |
| bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 125 | |
| 126 | void update(GrGpuResource* resource) { |
| 127 | if (resource->cacheAccess().isScratch()) { |
| 128 | ++fScratch; |
| 129 | } |
| bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 130 | if (resource->cacheAccess().isExternal()) { |
| 131 | ++fExternal; |
| 132 | } |
| 133 | if (resource->cacheAccess().isBorrowed()) { |
| 134 | ++fBorrowed; |
| 135 | } |
| 136 | if (resource->cacheAccess().isAdopted()) { |
| 137 | ++fAdopted; |
| bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 138 | } |
| 139 | if (!resource->resourcePriv().isBudgeted()) { |
| 140 | fUnbudgetedSize += resource->gpuMemorySize(); |
| 141 | } |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 142 | } |
| bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | Stats stats; |
| 146 | |
| 147 | for (int i = 0; i < fNonpurgeableResources.count(); ++i) { |
| 148 | stats.update(fNonpurgeableResources[i]); |
| 149 | } |
| 150 | for (int i = 0; i < fPurgeableQueue.count(); ++i) { |
| 151 | stats.update(fPurgeableQueue.at(i)); |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | float countUtilization = (100.f * fBudgetedCount) / fMaxCount; |
| 155 | float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes; |
| 156 | |
| 157 | out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes); |
| 158 | out->appendf("\t\tEntry Count: current %d" |
| bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 159 | " (%d budgeted, %d external(%d borrowed, %d adopted), %d locked, %d scratch %.2g%% full), high %d\n", |
| 160 | this->getResourceCount(), fBudgetedCount, stats.fExternal, stats.fBorrowed, |
| 161 | stats.fAdopted, locked, stats.fScratch, countUtilization, fHighWaterCount); |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 162 | 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] | 163 | SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization, |
| 164 | SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes)); |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | #endif |
| 168 | |
| bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 169 | /////////////////////////////////////////////////////////////////////////////// |
| 170 | |
| 171 | void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; } |
| mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 172 | |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 173 | /////////////////////////////////////////////////////////////////////////////// |
| 174 | // Code for the mock context. It's built on a mock GrGpu class that does nothing. |
| 175 | //// |
| 176 | |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 177 | #include "GrGpu.h" |
| 178 | |
| egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 179 | class GrPipeline; |
| joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 180 | |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 181 | class MockGpu : public GrGpu { |
| 182 | public: |
| bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 183 | MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) { |
| halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 184 | fCaps.reset(new GrCaps(options)); |
| bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 185 | } |
| mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 186 | ~MockGpu() override {} |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 187 | |
| bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 188 | bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes, |
| 189 | GrPixelConfig readConfig, DrawPreference*, |
| 190 | ReadPixelTempDrawInfo*) override { return false; } |
| 191 | |
| 192 | bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, size_t rowBytes, |
| 193 | GrPixelConfig srcConfig, DrawPreference*, |
| 194 | WritePixelTempDrawInfo*) override { return false; } |
| bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 195 | |
| joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 196 | void buildProgramDesc(GrProgramDesc*, const GrPrimitiveProcessor&, |
| 197 | const GrPipeline&) const override {} |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 198 | |
| mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 199 | void discard(GrRenderTarget*) override {} |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 200 | |
| joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 201 | bool onCopySurface(GrSurface* dst, |
| 202 | GrSurface* src, |
| 203 | const SkIRect& srcRect, |
| 204 | const SkIPoint& dstPoint) override { return false; }; |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 205 | |
| joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 206 | bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const override { |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 207 | return false; |
| 208 | } |
| joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 209 | |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 210 | private: |
| mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 211 | void onResetContext(uint32_t resetBits) override {} |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 212 | |
| bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 213 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
| 214 | |
| egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 215 | GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle lifeCycle, |
| 216 | const void* srcData, size_t rowBytes) override { |
| halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 217 | return nullptr; |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 220 | GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle, |
| mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 221 | const void* srcData) override { |
| halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 222 | return nullptr; |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 225 | GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, |
| halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 226 | GrWrapOwnership) override { return nullptr; } |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 227 | |
| bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 228 | GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, |
| 229 | GrWrapOwnership) override { |
| halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 230 | return nullptr; |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 233 | GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) override { return nullptr; } |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 234 | |
| halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 235 | GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) override { return nullptr; } |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 236 | |
| egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 237 | void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) override {} |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 238 | |
| mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 239 | void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) override {} |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 240 | |
| bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 241 | void onDraw(const DrawArgs&, const GrNonInstancedVertices&) override {} |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 242 | |
| bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 243 | bool onReadPixels(GrSurface* surface, |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 244 | int left, int top, int width, int height, |
| 245 | GrPixelConfig, |
| 246 | void* buffer, |
| mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 247 | size_t rowBytes) override { |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 248 | return false; |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 249 | } |
| 250 | |
| bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 251 | bool onWritePixels(GrSurface* surface, |
| 252 | int left, int top, int width, int height, |
| 253 | GrPixelConfig config, const void* buffer, |
| 254 | size_t rowBytes) override { |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 255 | return false; |
| 256 | } |
| 257 | |
| mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 258 | void onResolveRenderTarget(GrRenderTarget* target) override { return; } |
| bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 259 | |
| egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 260 | GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, |
| 261 | int width, |
| 262 | int height) override { |
| 263 | return nullptr; |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 266 | void clearStencil(GrRenderTarget* target) override {} |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 267 | |
| jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 268 | GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, |
| 269 | GrPixelConfig config) const override { |
| 270 | return 0; |
| 271 | } |
| 272 | bool isTestingOnlyBackendTexture(GrBackendObject id) const override { return false; } |
| 273 | void deleteTestingOnlyBackendTexture(GrBackendObject id) const override {} |
| jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 274 | |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 275 | typedef GrGpu INHERITED; |
| 276 | }; |
| 277 | |
| 278 | GrContext* GrContext::CreateMockContext() { |
| halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 279 | GrContext* context = new GrContext; |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 280 | |
| 281 | context->initMockContext(); |
| 282 | return context; |
| 283 | } |
| 284 | |
| 285 | void GrContext::initMockContext() { |
| bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 286 | GrContextOptions options; |
| joshualitt | 8b08159 | 2015-06-01 16:17:03 -0700 | [diff] [blame] | 287 | options.fGeometryBufferMapThreshold = 0; |
| halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 288 | SkASSERT(nullptr == fGpu); |
| halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 289 | fGpu = new MockGpu(this, options); |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 290 | SkASSERT(fGpu); |
| bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 291 | this->initCommon(options); |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 292 | |
| 293 | // We delete these because we want to test the cache starting with zero resources. Also, none of |
| 294 | // these objects are required for any of tests that use this context. TODO: make stop allocating |
| 295 | // resources in the buffer pools. |
| robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 296 | fDrawingManager->abandon(); |
| bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 297 | } |