blob: b83d67f39e2417f8d6de65d908574fae2c1114df [file] [log] [blame]
commit-bot@chromium.org78a10782013-08-21 19:27:48 +00001
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"
joshualittb542bae2015-07-28 09:58:39 -070010
joshualitt7f9c9eb2015-08-21 11:08:00 -070011#include "GrBatchAtlas.h"
bsalomon682c2692015-05-22 14:01:46 -070012#include "GrContextOptions.h"
jvanverth629162d2015-11-08 08:07:24 -080013#include "GrDrawContext.h"
robertphillips77a2e522015-10-17 07:43:27 -070014#include "GrDrawingManager.h"
bsalomon3582d3e2015-02-13 14:20:05 -080015#include "GrGpuResourceCacheAccess.h"
bsalomon0ea80f42015-02-11 10:49:59 -080016#include "GrResourceCache.h"
jvanverth0671b962015-12-08 18:53:44 -080017
18#include "SkGpuDevice.h"
jvanverth629162d2015-11-08 08:07:24 -080019#include "SkGrPriv.h"
mtkleinb9eb4ac2015-02-02 18:26:03 -080020#include "SkString.h"
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000021
joshualitte8042922015-12-11 06:11:21 -080022#include "text/GrBatchFontCache.h"
23#include "text/GrTextBlobCache.h"
24
joshualitt7f9c9eb2015-08-21 11:08:00 -070025namespace GrTest {
26void 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
robertphillips0dfa62c2015-11-16 06:23:31 -080050void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target, GrRenderTarget* rt) {
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000051 SkASSERT(!fContext);
52
53 fContext.reset(SkRef(ctx));
54 fDrawTarget.reset(SkRef(target));
robertphillips0dfa62c2015-11-16 06:23:31 -080055 fRenderTarget.reset(SkRef(rt));
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000056}
57
robertphillips504ce5d2015-11-16 11:02:05 -080058void GrContext::getTestTarget(GrTestTarget* tar, GrRenderTarget* rt) {
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000059 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().
robertphillips504ce5d2015-11-16 11:02:05 -080064 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;
robertphillips0dfa62c2015-11-16 06:23:31 -080071
robertphillips504ce5d2015-11-16 11:02:05 -080072 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();
robertphillips0dfa62c2015-11-16 06:23:31 -080079 }
robertphillips0dfa62c2015-11-16 06:23:31 -080080
81 SkAutoTUnref<GrDrawTarget> dt(fDrawingManager->newDrawTarget(rt));
82 tar->init(this, dt, rt);
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000083}
84
joshualitt17d833b2015-08-03 10:17:44 -070085void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) {
86 fTextBlobCache->setBudget(bytes);
87}
88
joshualittda04e0e2015-08-19 08:16:43 -070089void GrContext::setTextContextAtlasSizes_ForTesting(const GrBatchAtlasConfig* configs) {
90 fBatchFontCache->setAtlasSizes_ForTesting(configs);
91}
92
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000093///////////////////////////////////////////////////////////////////////////////
94
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000095void GrContext::purgeAllUnlockedResources() {
bsalomon0ea80f42015-02-11 10:49:59 -080096 fResourceCache->purgeAllUnlocked();
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000097}
bsalomon33435572014-11-05 14:47:41 -080098
joshualitte45c81c2015-12-02 09:05:37 -080099void GrContext::resetGpuStats() const {
100#if GR_GPU_STATS
101 fGpu->stats()->reset();
102#endif
103}
104
mtkleinb9eb4ac2015-02-02 18:26:03 -0800105void GrContext::dumpCacheStats(SkString* out) const {
106#if GR_CACHE_STATS
bsalomon0ea80f42015-02-11 10:49:59 -0800107 fResourceCache->dumpStats(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800108#endif
109}
110
joshualittdc5685a2015-12-02 14:08:25 -0800111void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
112 SkTArray<double>* values) const {
113#if GR_CACHE_STATS
114 fResourceCache->dumpStatsKeyValuePairs(keys, values);
115#endif
116}
117
mtkleinb9eb4ac2015-02-02 18:26:03 -0800118void GrContext::printCacheStats() const {
119 SkString out;
120 this->dumpCacheStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800121 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800122}
123
124void GrContext::dumpGpuStats(SkString* out) const {
125#if GR_GPU_STATS
126 return fGpu->stats()->dump(out);
127#endif
128}
129
joshualitte45c81c2015-12-02 09:05:37 -0800130void 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
mtkleinb9eb4ac2015-02-02 18:26:03 -0800137void GrContext::printGpuStats() const {
138 SkString out;
139 this->dumpGpuStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800140 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800141}
142
jvanverth0671b962015-12-08 18:53:44 -0800143GrTexture* GrContext::getFontAtlasTexture(GrMaskFormat format) {
jvanverth629162d2015-11-08 08:07:24 -0800144 GrBatchFontCache* cache = this->getBatchFontCache();
145
jvanverth0671b962015-12-08 18:53:44 -0800146 return cache->getTexture(format);
147}
jvanverth629162d2015-11-08 08:07:24 -0800148
jvanverth0671b962015-12-08 18:53:44 -0800149void SkGpuDevice::drawTexture(GrTexture* tex, const SkRect& dst, const SkPaint& paint) {
jvanverth629162d2015-11-08 08:07:24 -0800150 GrPaint grPaint;
151 SkMatrix mat;
152 mat.reset();
jvanverth0671b962015-12-08 18:53:44 -0800153 if (!SkPaintToGrPaint(this->context(), paint, mat, &grPaint)) {
jvanverth629162d2015-11-08 08:07:24 -0800154 return;
155 }
156 SkMatrix textureMat;
157 textureMat.reset();
jvanverth0671b962015-12-08 18:53:44 -0800158 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();
jvanverth629162d2015-11-08 08:07:24 -0800162
jvanverth0671b962015-12-08 18:53:44 -0800163 grPaint.addColorTextureProcessor(tex, textureMat);
jvanverth629162d2015-11-08 08:07:24 -0800164
165 GrClip clip;
jvanverth0671b962015-12-08 18:53:44 -0800166 fDrawContext->drawRect(clip, grPaint, mat, dst);
jvanverth629162d2015-11-08 08:07:24 -0800167}
168
jvanverth0671b962015-12-08 18:53:44 -0800169
mtkleinb9eb4ac2015-02-02 18:26:03 -0800170#if GR_GPU_STATS
171void GrGpu::Stats::dump(SkString* out) {
172 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
173 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800174 out->appendf("Textures Created: %d\n", fTextureCreates);
175 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800176 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700177 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700178 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800179}
joshualitte45c81c2015-12-02 09:05:37 -0800180
181void 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);
jvanverth17aa0472016-01-05 10:41:27 -0800186 keys->push_back(SkString("transfers_to_texture")); values->push_back(fTransfersToTexture);
joshualitte45c81c2015-12-02 09:05:37 -0800187 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
mtkleinb9eb4ac2015-02-02 18:26:03 -0800191#endif
192
193#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800194void 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
bsalomon0ea80f42015-02-11 10:49:59 -0800209void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800210 this->validate();
211
bsalomonf320e042015-02-17 15:09:34 -0800212 Stats stats;
213
robertphillips60029a52015-11-09 13:51:06 -0800214 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800215
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"
bsalomon6dc6f5f2015-06-18 09:12:16 -0700221 " (%d budgeted, %d external(%d borrowed, %d adopted), %d locked, %d scratch %.2g%% full), high %d\n",
robertphillips60029a52015-11-09 13:51:06 -0800222 stats.fTotal, fBudgetedCount, stats.fExternal, stats.fBorrowed,
223 stats.fAdopted, stats.fNumNonPurgeable, stats.fScratch, countUtilization,
224 fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800225 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800226 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
227 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800228}
229
joshualittdc5685a2015-12-02 14:08:25 -0800230void 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
mtkleinb9eb4ac2015-02-02 18:26:03 -0800247#endif
248
bsalomonddf30e62015-02-19 11:38:44 -0800249///////////////////////////////////////////////////////////////////////////////
250
251void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800252
bsalomon33435572014-11-05 14:47:41 -0800253///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800254
255#define ASSERT_SINGLE_OWNER \
256 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);)
257#define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; }
258
259void GrDrawContext::internal_drawBatch(const GrPipelineBuilder& pipelineBuilder,
260 GrDrawBatch* batch) {
261 ASSERT_SINGLE_OWNER
262 RETURN_IF_ABANDONED
263 SkDEBUGCODE(this->validate();)
264
265 this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
266}
267
268#undef ASSERT_SINGLE_OWNER
269#undef RETURN_IF_ABANDONED
270
271///////////////////////////////////////////////////////////////////////////////
bsalomon33435572014-11-05 14:47:41 -0800272// Code for the mock context. It's built on a mock GrGpu class that does nothing.
273////
274
bsalomon33435572014-11-05 14:47:41 -0800275#include "GrGpu.h"
276
egdaniel8dd688b2015-01-22 10:16:09 -0800277class GrPipeline;
joshualittd53a8272014-11-10 16:03:14 -0800278
bsalomon41e4384e2016-01-08 09:12:44 -0800279class MockCaps : public GrCaps {
280public:
281 explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {}
282 bool isConfigTexturable(GrPixelConfig config) const override { return false; }
283 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; }
284private:
285 typedef GrCaps INHERITED;
286};
287
bsalomon33435572014-11-05 14:47:41 -0800288class MockGpu : public GrGpu {
289public:
bsalomon682c2692015-05-22 14:01:46 -0700290 MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
bsalomon41e4384e2016-01-08 09:12:44 -0800291 fCaps.reset(new MockCaps(options));
bsalomon682c2692015-05-22 14:01:46 -0700292 }
mtklein36352bf2015-03-25 18:17:31 -0700293 ~MockGpu() override {}
bsalomon33435572014-11-05 14:47:41 -0800294
bsalomonf0674512015-07-28 13:26:15 -0700295 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
296 GrPixelConfig readConfig, DrawPreference*,
297 ReadPixelTempDrawInfo*) override { return false; }
298
299 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, size_t rowBytes,
300 GrPixelConfig srcConfig, DrawPreference*,
301 WritePixelTempDrawInfo*) override { return false; }
bsalomon39826022015-07-23 08:07:21 -0700302
joshualitt465283c2015-09-11 08:19:35 -0700303 void buildProgramDesc(GrProgramDesc*, const GrPrimitiveProcessor&,
304 const GrPipeline&) const override {}
bsalomon33435572014-11-05 14:47:41 -0800305
mtklein36352bf2015-03-25 18:17:31 -0700306 void discard(GrRenderTarget*) override {}
bsalomon33435572014-11-05 14:47:41 -0800307
joshualitt1cbdcde2015-08-21 11:53:29 -0700308 bool onCopySurface(GrSurface* dst,
309 GrSurface* src,
310 const SkIRect& srcRect,
311 const SkIPoint& dstPoint) override { return false; };
bsalomonf90a02b2014-11-26 12:28:00 -0800312
joshualitt1c735482015-07-13 08:08:25 -0700313 bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const override {
bsalomonf90a02b2014-11-26 12:28:00 -0800314 return false;
315 }
joshualitt3322fa42014-11-07 08:48:51 -0800316
bsalomon6dea83f2015-12-03 12:58:06 -0800317 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {};
318
bsalomon33435572014-11-05 14:47:41 -0800319private:
mtklein36352bf2015-03-25 18:17:31 -0700320 void onResetContext(uint32_t resetBits) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800321
bsalomoncb02b382015-08-12 11:14:50 -0700322 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
323
egdanielb0e1be22015-04-22 13:27:39 -0700324 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle lifeCycle,
325 const void* srcData, size_t rowBytes) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700326 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800327 }
328
egdanielb0e1be22015-04-22 13:27:39 -0700329 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle,
mtklein36352bf2015-03-25 18:17:31 -0700330 const void* srcData) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700331 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800332 }
333
bsalomon6dc6f5f2015-06-18 09:12:16 -0700334 GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&,
halcanary96fcdcc2015-08-27 07:41:13 -0700335 GrWrapOwnership) override { return nullptr; }
bsalomonf90a02b2014-11-26 12:28:00 -0800336
bsalomon6dc6f5f2015-06-18 09:12:16 -0700337 GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
338 GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700339 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800340 }
341
halcanary96fcdcc2015-08-27 07:41:13 -0700342 GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) override { return nullptr; }
bsalomonf90a02b2014-11-26 12:28:00 -0800343
halcanary96fcdcc2015-08-27 07:41:13 -0700344 GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) override { return nullptr; }
bsalomonf90a02b2014-11-26 12:28:00 -0800345
jvanverth73063dc2015-12-03 09:15:47 -0800346 GrTransferBuffer* onCreateTransferBuffer(size_t, TransferType) override { return nullptr; }
347
egdaniel51c8d402015-08-06 10:54:13 -0700348 void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800349
mtklein36352bf2015-03-25 18:17:31 -0700350 void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800351
bsalomone64eb572015-05-07 11:35:55 -0700352 void onDraw(const DrawArgs&, const GrNonInstancedVertices&) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800353
bsalomon6cb3cbe2015-07-30 07:34:27 -0700354 bool onReadPixels(GrSurface* surface,
bsalomonf90a02b2014-11-26 12:28:00 -0800355 int left, int top, int width, int height,
356 GrPixelConfig,
357 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700358 size_t rowBytes) override {
bsalomonf90a02b2014-11-26 12:28:00 -0800359 return false;
bsalomon33435572014-11-05 14:47:41 -0800360 }
361
bsalomon6cb3cbe2015-07-30 07:34:27 -0700362 bool onWritePixels(GrSurface* surface,
363 int left, int top, int width, int height,
364 GrPixelConfig config, const void* buffer,
365 size_t rowBytes) override {
bsalomon33435572014-11-05 14:47:41 -0800366 return false;
367 }
368
jvanverth17aa0472016-01-05 10:41:27 -0800369 bool onTransferPixels(GrSurface* surface,
370 int left, int top, int width, int height,
371 GrPixelConfig config, GrTransferBuffer* buffer,
372 size_t offset, size_t rowBytes) override {
373 return false;
374 }
375
mtklein36352bf2015-03-25 18:17:31 -0700376 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
bsalomonf90a02b2014-11-26 12:28:00 -0800377
egdanielec00d942015-09-14 12:56:10 -0700378 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
379 int width,
380 int height) override {
381 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800382 }
383
mtklein36352bf2015-03-25 18:17:31 -0700384 void clearStencil(GrRenderTarget* target) override {}
bsalomon33435572014-11-05 14:47:41 -0800385
jvanverth88957922015-07-14 11:02:52 -0700386 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
387 GrPixelConfig config) const override {
388 return 0;
389 }
bsalomon67d76202015-11-11 12:40:42 -0800390 bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
391 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) const override {}
jvanverth672bb7f2015-07-13 07:19:57 -0700392
bsalomon33435572014-11-05 14:47:41 -0800393 typedef GrGpu INHERITED;
394};
395
396GrContext* GrContext::CreateMockContext() {
halcanary385fe4d2015-08-26 13:07:48 -0700397 GrContext* context = new GrContext;
bsalomon33435572014-11-05 14:47:41 -0800398
399 context->initMockContext();
400 return context;
401}
402
403void GrContext::initMockContext() {
bsalomon682c2692015-05-22 14:01:46 -0700404 GrContextOptions options;
joshualitt8b081592015-06-01 16:17:03 -0700405 options.fGeometryBufferMapThreshold = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700406 SkASSERT(nullptr == fGpu);
halcanary385fe4d2015-08-26 13:07:48 -0700407 fGpu = new MockGpu(this, options);
bsalomon33435572014-11-05 14:47:41 -0800408 SkASSERT(fGpu);
bsalomon69cfe952015-11-30 13:27:47 -0800409 this->initCommon(options);
bsalomon33435572014-11-05 14:47:41 -0800410
411 // We delete these because we want to test the cache starting with zero resources. Also, none of
412 // these objects are required for any of tests that use this context. TODO: make stop allocating
413 // resources in the buffer pools.
robertphillips77a2e522015-10-17 07:43:27 -0700414 fDrawingManager->abandon();
bsalomon33435572014-11-05 14:47:41 -0800415}