blob: 874567dc62ee6c58486197e7bd5af961d90ab179 [file] [log] [blame]
commit-bot@chromium.org78a10782013-08-21 19:27:48 +00001/*
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"
joshualittb542bae2015-07-28 09:58:39 -07009
joshualitt7f9c9eb2015-08-21 11:08:00 -070010#include "GrBatchAtlas.h"
bsalomon682c2692015-05-22 14:01:46 -070011#include "GrContextOptions.h"
robertphillips391395d2016-03-02 09:26:36 -080012#include "GrDrawContextPriv.h"
robertphillips77a2e522015-10-17 07:43:27 -070013#include "GrDrawingManager.h"
bsalomon3582d3e2015-02-13 14:20:05 -080014#include "GrGpuResourceCacheAccess.h"
bsalomon0ea80f42015-02-11 10:49:59 -080015#include "GrResourceCache.h"
jvanverth0671b962015-12-08 18:53:44 -080016
17#include "SkGpuDevice.h"
jvanverth629162d2015-11-08 08:07:24 -080018#include "SkGrPriv.h"
mtkleinb9eb4ac2015-02-02 18:26:03 -080019#include "SkString.h"
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000020
joshualitte8042922015-12-11 06:11:21 -080021#include "text/GrBatchFontCache.h"
22#include "text/GrTextBlobCache.h"
23
joshualitt7f9c9eb2015-08-21 11:08:00 -070024namespace GrTest {
25void 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;
jvanverth7023a002016-02-22 11:25:32 -080032 configs[kA8_GrMaskFormat].fLog2Width = SkNextLog2(dim);
33 configs[kA8_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070034 configs[kA8_GrMaskFormat].fPlotWidth = dim;
35 configs[kA8_GrMaskFormat].fPlotHeight = dim;
36
37 configs[kA565_GrMaskFormat].fWidth = dim;
38 configs[kA565_GrMaskFormat].fHeight = dim;
jvanverth7023a002016-02-22 11:25:32 -080039 configs[kA565_GrMaskFormat].fLog2Width = SkNextLog2(dim);
40 configs[kA565_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070041 configs[kA565_GrMaskFormat].fPlotWidth = dim;
42 configs[kA565_GrMaskFormat].fPlotHeight = dim;
43
44 configs[kARGB_GrMaskFormat].fWidth = dim;
45 configs[kARGB_GrMaskFormat].fHeight = dim;
jvanverth7023a002016-02-22 11:25:32 -080046 configs[kARGB_GrMaskFormat].fLog2Width = SkNextLog2(dim);
47 configs[kARGB_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070048 configs[kARGB_GrMaskFormat].fPlotWidth = dim;
49 configs[kARGB_GrMaskFormat].fPlotHeight = dim;
50
51 context->setTextContextAtlasSizes_ForTesting(configs);
52}
53};
54
robertphillips0dfa62c2015-11-16 06:23:31 -080055void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target, GrRenderTarget* rt) {
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000056 SkASSERT(!fContext);
57
58 fContext.reset(SkRef(ctx));
59 fDrawTarget.reset(SkRef(target));
robertphillips0dfa62c2015-11-16 06:23:31 -080060 fRenderTarget.reset(SkRef(rt));
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000061}
62
robertphillips504ce5d2015-11-16 11:02:05 -080063void GrContext::getTestTarget(GrTestTarget* tar, GrRenderTarget* rt) {
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000064 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().
robertphillips504ce5d2015-11-16 11:02:05 -080069 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;
robertphillips0dfa62c2015-11-16 06:23:31 -080076
bsalomon5ec26ae2016-02-25 08:33:02 -080077 SkAutoTUnref<GrTexture> texture(this->textureProvider()->createTexture(
78 desc, SkBudgeted::kNo, nullptr, 0));
robertphillips504ce5d2015-11-16 11:02:05 -080079 if (nullptr == texture) {
80 return;
81 }
82 SkASSERT(nullptr != texture->asRenderTarget());
83 rt = texture->asRenderTarget();
robertphillips0dfa62c2015-11-16 06:23:31 -080084 }
robertphillips0dfa62c2015-11-16 06:23:31 -080085
86 SkAutoTUnref<GrDrawTarget> dt(fDrawingManager->newDrawTarget(rt));
87 tar->init(this, dt, rt);
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000088}
89
joshualitt17d833b2015-08-03 10:17:44 -070090void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) {
91 fTextBlobCache->setBudget(bytes);
92}
93
joshualittda04e0e2015-08-19 08:16:43 -070094void GrContext::setTextContextAtlasSizes_ForTesting(const GrBatchAtlasConfig* configs) {
95 fBatchFontCache->setAtlasSizes_ForTesting(configs);
96}
97
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000098///////////////////////////////////////////////////////////////////////////////
99
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000100void GrContext::purgeAllUnlockedResources() {
bsalomon0ea80f42015-02-11 10:49:59 -0800101 fResourceCache->purgeAllUnlocked();
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000102}
bsalomon33435572014-11-05 14:47:41 -0800103
joshualitte45c81c2015-12-02 09:05:37 -0800104void GrContext::resetGpuStats() const {
105#if GR_GPU_STATS
106 fGpu->stats()->reset();
107#endif
108}
109
mtkleinb9eb4ac2015-02-02 18:26:03 -0800110void GrContext::dumpCacheStats(SkString* out) const {
111#if GR_CACHE_STATS
bsalomon0ea80f42015-02-11 10:49:59 -0800112 fResourceCache->dumpStats(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800113#endif
114}
115
joshualittdc5685a2015-12-02 14:08:25 -0800116void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
117 SkTArray<double>* values) const {
118#if GR_CACHE_STATS
119 fResourceCache->dumpStatsKeyValuePairs(keys, values);
120#endif
121}
122
mtkleinb9eb4ac2015-02-02 18:26:03 -0800123void GrContext::printCacheStats() const {
124 SkString out;
125 this->dumpCacheStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800126 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800127}
128
129void GrContext::dumpGpuStats(SkString* out) const {
130#if GR_GPU_STATS
131 return fGpu->stats()->dump(out);
132#endif
133}
134
joshualitte45c81c2015-12-02 09:05:37 -0800135void 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
mtkleinb9eb4ac2015-02-02 18:26:03 -0800142void GrContext::printGpuStats() const {
143 SkString out;
144 this->dumpGpuStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800145 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800146}
147
jvanverth0671b962015-12-08 18:53:44 -0800148GrTexture* GrContext::getFontAtlasTexture(GrMaskFormat format) {
jvanverth629162d2015-11-08 08:07:24 -0800149 GrBatchFontCache* cache = this->getBatchFontCache();
150
jvanverth0671b962015-12-08 18:53:44 -0800151 return cache->getTexture(format);
152}
jvanverth629162d2015-11-08 08:07:24 -0800153
jvanverth0671b962015-12-08 18:53:44 -0800154void SkGpuDevice::drawTexture(GrTexture* tex, const SkRect& dst, const SkPaint& paint) {
jvanverth629162d2015-11-08 08:07:24 -0800155 GrPaint grPaint;
156 SkMatrix mat;
157 mat.reset();
brianosman898235c2016-04-06 07:38:23 -0700158 if (!SkPaintToGrPaint(this->context(), paint, mat,
brianosmanb461d342016-04-13 13:10:14 -0700159 this->surfaceProps().isGammaCorrect(), &grPaint)) {
jvanverth629162d2015-11-08 08:07:24 -0800160 return;
161 }
162 SkMatrix textureMat;
163 textureMat.reset();
jvanverth0671b962015-12-08 18:53:44 -0800164 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();
jvanverth629162d2015-11-08 08:07:24 -0800168
jvanverth0671b962015-12-08 18:53:44 -0800169 grPaint.addColorTextureProcessor(tex, textureMat);
jvanverth629162d2015-11-08 08:07:24 -0800170
171 GrClip clip;
jvanverth0671b962015-12-08 18:53:44 -0800172 fDrawContext->drawRect(clip, grPaint, mat, dst);
jvanverth629162d2015-11-08 08:07:24 -0800173}
174
jvanverth0671b962015-12-08 18:53:44 -0800175
mtkleinb9eb4ac2015-02-02 18:26:03 -0800176#if GR_GPU_STATS
177void GrGpu::Stats::dump(SkString* out) {
178 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
179 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800180 out->appendf("Textures Created: %d\n", fTextureCreates);
181 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800182 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700183 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700184 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800185}
joshualitte45c81c2015-12-02 09:05:37 -0800186
187void 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);
joshualitte45c81c2015-12-02 09:05:37 -0800190 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800191 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700192 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800193}
194
mtkleinb9eb4ac2015-02-02 18:26:03 -0800195#endif
196
197#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800198void 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
bsalomon0ea80f42015-02-11 10:49:59 -0800213void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800214 this->validate();
215
bsalomonf320e042015-02-17 15:09:34 -0800216 Stats stats;
217
robertphillips60029a52015-11-09 13:51:06 -0800218 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800219
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"
kkinnunen2e6055b2016-04-22 01:48:29 -0700225 " (%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);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800228 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800229 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
230 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800231}
232
joshualittdc5685a2015-12-02 14:08:25 -0800233void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
234 SkTArray<double>* values) const {
235 this->validate();
236
237 Stats stats;
238 this->getStats(&stats);
239
joshualittdc5685a2015-12-02 14:08:25 -0800240 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
joshualittdc5685a2015-12-02 14:08:25 -0800241}
242
mtkleinb9eb4ac2015-02-02 18:26:03 -0800243#endif
244
bsalomonddf30e62015-02-19 11:38:44 -0800245///////////////////////////////////////////////////////////////////////////////
246
247void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800248
bsalomon33435572014-11-05 14:47:41 -0800249///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800250
251#define ASSERT_SINGLE_OWNER \
robertphillips391395d2016-03-02 09:26:36 -0800252 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fDrawContext->fSingleOwner);)
253#define RETURN_IF_ABANDONED if (fDrawContext->fDrawingManager->abandoned()) { return; }
joshualittf5883a62016-01-13 07:47:38 -0800254
robertphillips391395d2016-03-02 09:26:36 -0800255void GrDrawContextPriv::testingOnly_drawBatch(const GrPipelineBuilder& pipelineBuilder,
cdalton862cff32016-05-12 15:09:48 -0700256 GrDrawBatch* batch,
257 const GrClip* clip) {
joshualittf5883a62016-01-13 07:47:38 -0800258 ASSERT_SINGLE_OWNER
259 RETURN_IF_ABANDONED
robertphillips391395d2016-03-02 09:26:36 -0800260 SkDEBUGCODE(fDrawContext->validate();)
261 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::testingOnly_drawBatch");
joshualittf5883a62016-01-13 07:47:38 -0800262
cdalton862cff32016-05-12 15:09:48 -0700263 const GrClip& drawClip = clip ? *clip : GrClip::WideOpen();
264 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, drawClip, batch);
joshualittf5883a62016-01-13 07:47:38 -0800265}
266
267#undef ASSERT_SINGLE_OWNER
268#undef RETURN_IF_ABANDONED
269
270///////////////////////////////////////////////////////////////////////////////
bsalomon33435572014-11-05 14:47:41 -0800271// Code for the mock context. It's built on a mock GrGpu class that does nothing.
272////
273
bsalomon33435572014-11-05 14:47:41 -0800274#include "GrGpu.h"
275
egdaniel8dd688b2015-01-22 10:16:09 -0800276class GrPipeline;
joshualittd53a8272014-11-10 16:03:14 -0800277
bsalomon41e4384e2016-01-08 09:12:44 -0800278class MockCaps : public GrCaps {
279public:
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; }
283private:
284 typedef GrCaps INHERITED;
285};
286
bsalomon33435572014-11-05 14:47:41 -0800287class MockGpu : public GrGpu {
288public:
bsalomon682c2692015-05-22 14:01:46 -0700289 MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
bsalomon41e4384e2016-01-08 09:12:44 -0800290 fCaps.reset(new MockCaps(options));
bsalomon682c2692015-05-22 14:01:46 -0700291 }
mtklein36352bf2015-03-25 18:17:31 -0700292 ~MockGpu() override {}
bsalomon33435572014-11-05 14:47:41 -0800293
bsalomonf0674512015-07-28 13:26:15 -0700294 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
295 GrPixelConfig readConfig, DrawPreference*,
296 ReadPixelTempDrawInfo*) override { return false; }
297
cblumeed828002016-02-16 13:00:01 -0800298 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
bsalomonf0674512015-07-28 13:26:15 -0700299 GrPixelConfig srcConfig, DrawPreference*,
300 WritePixelTempDrawInfo*) override { return false; }
bsalomon39826022015-07-23 08:07:21 -0700301
mtklein36352bf2015-03-25 18:17:31 -0700302 void discard(GrRenderTarget*) override {}
bsalomon33435572014-11-05 14:47:41 -0800303
joshualitt1cbdcde2015-08-21 11:53:29 -0700304 bool onCopySurface(GrSurface* dst,
305 GrSurface* src,
306 const SkIRect& srcRect,
307 const SkIPoint& dstPoint) override { return false; };
bsalomonf90a02b2014-11-26 12:28:00 -0800308
cdalton28f45b92016-03-07 13:58:26 -0800309 void onGetMultisampleSpecs(GrRenderTarget* rt,
310 const GrStencilSettings&,
311 int* effectiveSampleCnt,
312 SkAutoTDeleteArray<SkPoint>*) override {
313 *effectiveSampleCnt = rt->desc().fSampleCnt;
314 }
315
joshualitt1c735482015-07-13 08:08:25 -0700316 bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const override {
bsalomonf90a02b2014-11-26 12:28:00 -0800317 return false;
318 }
joshualitt3322fa42014-11-07 08:48:51 -0800319
bsalomon6dea83f2015-12-03 12:58:06 -0800320 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {};
321
bsalomon33435572014-11-05 14:47:41 -0800322private:
mtklein36352bf2015-03-25 18:17:31 -0700323 void onResetContext(uint32_t resetBits) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800324
bsalomoncb02b382015-08-12 11:14:50 -0700325 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
326
kkinnunen2e6055b2016-04-22 01:48:29 -0700327 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800328 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700329 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800330 }
331
kkinnunen2e6055b2016-04-22 01:48:29 -0700332 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800333 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700334 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800335 }
336
bsalomon6dc6f5f2015-06-18 09:12:16 -0700337 GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&,
halcanary96fcdcc2015-08-27 07:41:13 -0700338 GrWrapOwnership) override { return nullptr; }
bsalomonf90a02b2014-11-26 12:28:00 -0800339
bsalomon6dc6f5f2015-06-18 09:12:16 -0700340 GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
341 GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700342 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800343 }
344
kkinnunen49c4c222016-04-01 04:50:37 -0700345 GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override {
ericrkf7b8b8a2016-02-24 14:49:51 -0800346 return nullptr;
347 }
348
cdalton1bf3e712016-04-19 10:00:02 -0700349 GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
350 return nullptr;
351 }
jvanverth73063dc2015-12-03 09:15:47 -0800352
egdaniel51c8d402015-08-06 10:54:13 -0700353 void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800354
mtklein36352bf2015-03-25 18:17:31 -0700355 void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800356
egdaniel0e1853c2016-03-17 11:35:45 -0700357 void onDraw(const GrPipeline&,
358 const GrPrimitiveProcessor&,
359 const GrMesh*,
360 int meshCount) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800361
bsalomon6cb3cbe2015-07-30 07:34:27 -0700362 bool onReadPixels(GrSurface* surface,
bsalomonf90a02b2014-11-26 12:28:00 -0800363 int left, int top, int width, int height,
364 GrPixelConfig,
365 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700366 size_t rowBytes) override {
bsalomonf90a02b2014-11-26 12:28:00 -0800367 return false;
bsalomon33435572014-11-05 14:47:41 -0800368 }
369
bsalomon6cb3cbe2015-07-30 07:34:27 -0700370 bool onWritePixels(GrSurface* surface,
371 int left, int top, int width, int height,
cblume55f2d2d2016-02-26 13:20:48 -0800372 GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override {
bsalomon33435572014-11-05 14:47:41 -0800373 return false;
374 }
375
jvanverthc3d706f2016-04-20 10:33:27 -0700376 bool onTransferPixels(GrSurface* surface,
jvanverth17aa0472016-01-05 10:41:27 -0800377 int left, int top, int width, int height,
cdalton397536c2016-03-25 12:15:03 -0700378 GrPixelConfig config, GrBuffer* transferBuffer,
jvanverth17aa0472016-01-05 10:41:27 -0800379 size_t offset, size_t rowBytes) override {
380 return false;
381 }
382
mtklein36352bf2015-03-25 18:17:31 -0700383 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
bsalomonf90a02b2014-11-26 12:28:00 -0800384
egdanielec00d942015-09-14 12:56:10 -0700385 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
386 int width,
387 int height) override {
388 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800389 }
390
mtklein36352bf2015-03-25 18:17:31 -0700391 void clearStencil(GrRenderTarget* target) override {}
bsalomon33435572014-11-05 14:47:41 -0800392
jvanverth88957922015-07-14 11:02:52 -0700393 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
bsalomone63ffef2016-02-05 07:17:34 -0800394 GrPixelConfig config) override {
cblume61214052016-01-26 09:10:48 -0800395 return 0;
jvanverth88957922015-07-14 11:02:52 -0700396 }
bsalomon67d76202015-11-11 12:40:42 -0800397 bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
bsalomone63ffef2016-02-05 07:17:34 -0800398 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
jvanverth672bb7f2015-07-13 07:19:57 -0700399
bsalomon33435572014-11-05 14:47:41 -0800400 typedef GrGpu INHERITED;
401};
402
403GrContext* GrContext::CreateMockContext() {
halcanary385fe4d2015-08-26 13:07:48 -0700404 GrContext* context = new GrContext;
bsalomon33435572014-11-05 14:47:41 -0800405
406 context->initMockContext();
407 return context;
408}
409
410void GrContext::initMockContext() {
bsalomon682c2692015-05-22 14:01:46 -0700411 GrContextOptions options;
cdalton397536c2016-03-25 12:15:03 -0700412 options.fBufferMapThreshold = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700413 SkASSERT(nullptr == fGpu);
halcanary385fe4d2015-08-26 13:07:48 -0700414 fGpu = new MockGpu(this, options);
bsalomon33435572014-11-05 14:47:41 -0800415 SkASSERT(fGpu);
bsalomon69cfe952015-11-30 13:27:47 -0800416 this->initCommon(options);
bsalomon33435572014-11-05 14:47:41 -0800417
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.
robertphillips77a2e522015-10-17 07:43:27 -0700421 fDrawingManager->abandon();
bsalomon33435572014-11-05 14:47:41 -0800422}