blob: 03a8d54a6d999f135435d26070925e1895e35dae [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///////////////////////////////////////////////////////////////////////////////
254// Code for the mock context. It's built on a mock GrGpu class that does nothing.
255////
256
bsalomon33435572014-11-05 14:47:41 -0800257#include "GrGpu.h"
258
egdaniel8dd688b2015-01-22 10:16:09 -0800259class GrPipeline;
joshualittd53a8272014-11-10 16:03:14 -0800260
bsalomon33435572014-11-05 14:47:41 -0800261class MockGpu : public GrGpu {
262public:
bsalomon682c2692015-05-22 14:01:46 -0700263 MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
halcanary385fe4d2015-08-26 13:07:48 -0700264 fCaps.reset(new GrCaps(options));
bsalomon682c2692015-05-22 14:01:46 -0700265 }
mtklein36352bf2015-03-25 18:17:31 -0700266 ~MockGpu() override {}
bsalomon33435572014-11-05 14:47:41 -0800267
bsalomonf0674512015-07-28 13:26:15 -0700268 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; }
bsalomon39826022015-07-23 08:07:21 -0700275
joshualitt465283c2015-09-11 08:19:35 -0700276 void buildProgramDesc(GrProgramDesc*, const GrPrimitiveProcessor&,
277 const GrPipeline&) const override {}
bsalomon33435572014-11-05 14:47:41 -0800278
mtklein36352bf2015-03-25 18:17:31 -0700279 void discard(GrRenderTarget*) override {}
bsalomon33435572014-11-05 14:47:41 -0800280
joshualitt1cbdcde2015-08-21 11:53:29 -0700281 bool onCopySurface(GrSurface* dst,
282 GrSurface* src,
283 const SkIRect& srcRect,
284 const SkIPoint& dstPoint) override { return false; };
bsalomonf90a02b2014-11-26 12:28:00 -0800285
joshualitt1c735482015-07-13 08:08:25 -0700286 bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const override {
bsalomonf90a02b2014-11-26 12:28:00 -0800287 return false;
288 }
joshualitt3322fa42014-11-07 08:48:51 -0800289
bsalomon6dea83f2015-12-03 12:58:06 -0800290 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {};
291
bsalomon33435572014-11-05 14:47:41 -0800292private:
mtklein36352bf2015-03-25 18:17:31 -0700293 void onResetContext(uint32_t resetBits) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800294
bsalomoncb02b382015-08-12 11:14:50 -0700295 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
296
egdanielb0e1be22015-04-22 13:27:39 -0700297 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle lifeCycle,
298 const void* srcData, size_t rowBytes) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700299 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800300 }
301
egdanielb0e1be22015-04-22 13:27:39 -0700302 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle,
mtklein36352bf2015-03-25 18:17:31 -0700303 const void* srcData) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700304 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800305 }
306
bsalomon6dc6f5f2015-06-18 09:12:16 -0700307 GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&,
halcanary96fcdcc2015-08-27 07:41:13 -0700308 GrWrapOwnership) override { return nullptr; }
bsalomonf90a02b2014-11-26 12:28:00 -0800309
bsalomon6dc6f5f2015-06-18 09:12:16 -0700310 GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
311 GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700312 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800313 }
314
halcanary96fcdcc2015-08-27 07:41:13 -0700315 GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) override { return nullptr; }
bsalomonf90a02b2014-11-26 12:28:00 -0800316
halcanary96fcdcc2015-08-27 07:41:13 -0700317 GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) override { return nullptr; }
bsalomonf90a02b2014-11-26 12:28:00 -0800318
jvanverth73063dc2015-12-03 09:15:47 -0800319 GrTransferBuffer* onCreateTransferBuffer(size_t, TransferType) override { return nullptr; }
320
egdaniel51c8d402015-08-06 10:54:13 -0700321 void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800322
mtklein36352bf2015-03-25 18:17:31 -0700323 void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800324
bsalomone64eb572015-05-07 11:35:55 -0700325 void onDraw(const DrawArgs&, const GrNonInstancedVertices&) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800326
bsalomon6cb3cbe2015-07-30 07:34:27 -0700327 bool onReadPixels(GrSurface* surface,
bsalomonf90a02b2014-11-26 12:28:00 -0800328 int left, int top, int width, int height,
329 GrPixelConfig,
330 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700331 size_t rowBytes) override {
bsalomonf90a02b2014-11-26 12:28:00 -0800332 return false;
bsalomon33435572014-11-05 14:47:41 -0800333 }
334
bsalomon6cb3cbe2015-07-30 07:34:27 -0700335 bool onWritePixels(GrSurface* surface,
336 int left, int top, int width, int height,
337 GrPixelConfig config, const void* buffer,
338 size_t rowBytes) override {
bsalomon33435572014-11-05 14:47:41 -0800339 return false;
340 }
341
jvanverth17aa0472016-01-05 10:41:27 -0800342 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
mtklein36352bf2015-03-25 18:17:31 -0700349 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
bsalomonf90a02b2014-11-26 12:28:00 -0800350
egdanielec00d942015-09-14 12:56:10 -0700351 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
352 int width,
353 int height) override {
354 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800355 }
356
mtklein36352bf2015-03-25 18:17:31 -0700357 void clearStencil(GrRenderTarget* target) override {}
bsalomon33435572014-11-05 14:47:41 -0800358
jvanverth88957922015-07-14 11:02:52 -0700359 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
360 GrPixelConfig config) const override {
361 return 0;
362 }
bsalomon67d76202015-11-11 12:40:42 -0800363 bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
364 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) const override {}
jvanverth672bb7f2015-07-13 07:19:57 -0700365
bsalomon33435572014-11-05 14:47:41 -0800366 typedef GrGpu INHERITED;
367};
368
369GrContext* GrContext::CreateMockContext() {
halcanary385fe4d2015-08-26 13:07:48 -0700370 GrContext* context = new GrContext;
bsalomon33435572014-11-05 14:47:41 -0800371
372 context->initMockContext();
373 return context;
374}
375
376void GrContext::initMockContext() {
bsalomon682c2692015-05-22 14:01:46 -0700377 GrContextOptions options;
joshualitt8b081592015-06-01 16:17:03 -0700378 options.fGeometryBufferMapThreshold = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700379 SkASSERT(nullptr == fGpu);
halcanary385fe4d2015-08-26 13:07:48 -0700380 fGpu = new MockGpu(this, options);
bsalomon33435572014-11-05 14:47:41 -0800381 SkASSERT(fGpu);
bsalomon69cfe952015-11-30 13:27:47 -0800382 this->initCommon(options);
bsalomon33435572014-11-05 14:47:41 -0800383
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.
robertphillips77a2e522015-10-17 07:43:27 -0700387 fDrawingManager->abandon();
bsalomon33435572014-11-05 14:47:41 -0800388}