blob: dc14016973cc8636dada0a168bdae9949cc38975 [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"
jvanverth629162d2015-11-08 08:07:24 -080012#include "GrDrawContext.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();
jvanverth0671b962015-12-08 18:53:44 -0800158 if (!SkPaintToGrPaint(this->context(), paint, mat, &grPaint)) {
jvanverth629162d2015-11-08 08:07:24 -0800159 return;
160 }
161 SkMatrix textureMat;
162 textureMat.reset();
jvanverth0671b962015-12-08 18:53:44 -0800163 textureMat[SkMatrix::kMScaleX] = 1.0f/dst.width();
164 textureMat[SkMatrix::kMScaleY] = 1.0f/dst.height();
165 textureMat[SkMatrix::kMTransX] = -dst.fLeft/dst.width();
166 textureMat[SkMatrix::kMTransY] = -dst.fTop/dst.height();
jvanverth629162d2015-11-08 08:07:24 -0800167
jvanverth0671b962015-12-08 18:53:44 -0800168 grPaint.addColorTextureProcessor(tex, textureMat);
jvanverth629162d2015-11-08 08:07:24 -0800169
170 GrClip clip;
jvanverth0671b962015-12-08 18:53:44 -0800171 fDrawContext->drawRect(clip, grPaint, mat, dst);
jvanverth629162d2015-11-08 08:07:24 -0800172}
173
jvanverth0671b962015-12-08 18:53:44 -0800174
mtkleinb9eb4ac2015-02-02 18:26:03 -0800175#if GR_GPU_STATS
176void GrGpu::Stats::dump(SkString* out) {
177 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
178 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800179 out->appendf("Textures Created: %d\n", fTextureCreates);
180 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800181 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700182 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700183 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800184}
joshualitte45c81c2015-12-02 09:05:37 -0800185
186void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
187 keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds);
188 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
189 keys->push_back(SkString("textures_created")); values->push_back(fTextureCreates);
190 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800191 keys->push_back(SkString("transfers_to_texture")); values->push_back(fTransfersToTexture);
joshualitte45c81c2015-12-02 09:05:37 -0800192 keys->push_back(SkString("stencil_buffer_creates")); values->push_back(fStencilAttachmentCreates);
193 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
194}
195
mtkleinb9eb4ac2015-02-02 18:26:03 -0800196#endif
197
198#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800199void GrResourceCache::getStats(Stats* stats) const {
200 stats->reset();
201
202 stats->fTotal = this->getResourceCount();
203 stats->fNumNonPurgeable = fNonpurgeableResources.count();
204 stats->fNumPurgeable = fPurgeableQueue.count();
205
206 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
207 stats->update(fNonpurgeableResources[i]);
208 }
209 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
210 stats->update(fPurgeableQueue.at(i));
211 }
212}
213
bsalomon0ea80f42015-02-11 10:49:59 -0800214void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800215 this->validate();
216
bsalomonf320e042015-02-17 15:09:34 -0800217 Stats stats;
218
robertphillips60029a52015-11-09 13:51:06 -0800219 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800220
221 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
222 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
223
224 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
225 out->appendf("\t\tEntry Count: current %d"
bsalomon6dc6f5f2015-06-18 09:12:16 -0700226 " (%d budgeted, %d external(%d borrowed, %d adopted), %d locked, %d scratch %.2g%% full), high %d\n",
robertphillips60029a52015-11-09 13:51:06 -0800227 stats.fTotal, fBudgetedCount, stats.fExternal, stats.fBorrowed,
228 stats.fAdopted, stats.fNumNonPurgeable, stats.fScratch, countUtilization,
229 fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800230 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800231 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
232 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800233}
234
joshualittdc5685a2015-12-02 14:08:25 -0800235void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
236 SkTArray<double>* values) const {
237 this->validate();
238
239 Stats stats;
240 this->getStats(&stats);
241
242 keys->push_back(SkString("gpu_cache_total_entries")); values->push_back(stats.fTotal);
243 keys->push_back(SkString("gpu_cache_external_entries")); values->push_back(stats.fExternal);
244 keys->push_back(SkString("gpu_cache_borrowed_entries")); values->push_back(stats.fBorrowed);
245 keys->push_back(SkString("gpu_cache_adopted_entries")); values->push_back(stats.fAdopted);
246 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
247 keys->push_back(SkString("gpu_cache_non_purgable_entries")); values->push_back(stats.fNumNonPurgeable);
248 keys->push_back(SkString("gpu_cache_scratch_entries")); values->push_back(stats.fScratch);
249 keys->push_back(SkString("gpu_cache_unbudgeted_size")); values->push_back((double)stats.fUnbudgetedSize);
250}
251
mtkleinb9eb4ac2015-02-02 18:26:03 -0800252#endif
253
bsalomonddf30e62015-02-19 11:38:44 -0800254///////////////////////////////////////////////////////////////////////////////
255
256void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800257
bsalomon33435572014-11-05 14:47:41 -0800258///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800259
260#define ASSERT_SINGLE_OWNER \
261 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);)
262#define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; }
263
264void GrDrawContext::internal_drawBatch(const GrPipelineBuilder& pipelineBuilder,
265 GrDrawBatch* batch) {
266 ASSERT_SINGLE_OWNER
267 RETURN_IF_ABANDONED
268 SkDEBUGCODE(this->validate();)
joshualittde83b412016-01-14 09:58:36 -0800269 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::internal_drawBatch");
joshualittf5883a62016-01-13 07:47:38 -0800270
271 this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
272}
273
274#undef ASSERT_SINGLE_OWNER
275#undef RETURN_IF_ABANDONED
276
277///////////////////////////////////////////////////////////////////////////////
bsalomon33435572014-11-05 14:47:41 -0800278// Code for the mock context. It's built on a mock GrGpu class that does nothing.
279////
280
bsalomon33435572014-11-05 14:47:41 -0800281#include "GrGpu.h"
282
egdaniel8dd688b2015-01-22 10:16:09 -0800283class GrPipeline;
joshualittd53a8272014-11-10 16:03:14 -0800284
bsalomon41e4384e2016-01-08 09:12:44 -0800285class MockCaps : public GrCaps {
286public:
287 explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {}
288 bool isConfigTexturable(GrPixelConfig config) const override { return false; }
289 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; }
290private:
291 typedef GrCaps INHERITED;
292};
293
bsalomon33435572014-11-05 14:47:41 -0800294class MockGpu : public GrGpu {
295public:
bsalomon682c2692015-05-22 14:01:46 -0700296 MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
bsalomon41e4384e2016-01-08 09:12:44 -0800297 fCaps.reset(new MockCaps(options));
bsalomon682c2692015-05-22 14:01:46 -0700298 }
mtklein36352bf2015-03-25 18:17:31 -0700299 ~MockGpu() override {}
bsalomon33435572014-11-05 14:47:41 -0800300
bsalomonf0674512015-07-28 13:26:15 -0700301 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
302 GrPixelConfig readConfig, DrawPreference*,
303 ReadPixelTempDrawInfo*) override { return false; }
304
cblumeed828002016-02-16 13:00:01 -0800305 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
bsalomonf0674512015-07-28 13:26:15 -0700306 GrPixelConfig srcConfig, DrawPreference*,
307 WritePixelTempDrawInfo*) override { return false; }
bsalomon39826022015-07-23 08:07:21 -0700308
joshualitt465283c2015-09-11 08:19:35 -0700309 void buildProgramDesc(GrProgramDesc*, const GrPrimitiveProcessor&,
310 const GrPipeline&) const override {}
bsalomon33435572014-11-05 14:47:41 -0800311
mtklein36352bf2015-03-25 18:17:31 -0700312 void discard(GrRenderTarget*) override {}
bsalomon33435572014-11-05 14:47:41 -0800313
joshualitt1cbdcde2015-08-21 11:53:29 -0700314 bool onCopySurface(GrSurface* dst,
315 GrSurface* src,
316 const SkIRect& srcRect,
317 const SkIPoint& dstPoint) override { return false; };
bsalomonf90a02b2014-11-26 12:28:00 -0800318
joshualitt1c735482015-07-13 08:08:25 -0700319 bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const override {
bsalomonf90a02b2014-11-26 12:28:00 -0800320 return false;
321 }
joshualitt3322fa42014-11-07 08:48:51 -0800322
bsalomon6dea83f2015-12-03 12:58:06 -0800323 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {};
324
bsalomon33435572014-11-05 14:47:41 -0800325private:
mtklein36352bf2015-03-25 18:17:31 -0700326 void onResetContext(uint32_t resetBits) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800327
bsalomoncb02b382015-08-12 11:14:50 -0700328 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
329
egdanielb0e1be22015-04-22 13:27:39 -0700330 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle lifeCycle,
331 const void* srcData, size_t rowBytes) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700332 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800333 }
334
egdanielb0e1be22015-04-22 13:27:39 -0700335 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle,
mtklein36352bf2015-03-25 18:17:31 -0700336 const void* srcData) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700337 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800338 }
339
bsalomon6dc6f5f2015-06-18 09:12:16 -0700340 GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&,
halcanary96fcdcc2015-08-27 07:41:13 -0700341 GrWrapOwnership) override { return nullptr; }
bsalomonf90a02b2014-11-26 12:28:00 -0800342
bsalomon6dc6f5f2015-06-18 09:12:16 -0700343 GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
344 GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700345 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800346 }
347
ericrkf7b8b8a2016-02-24 14:49:51 -0800348 GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&,
349 GrWrapOwnership) override {
350 return nullptr;
351 }
352
halcanary96fcdcc2015-08-27 07:41:13 -0700353 GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) override { return nullptr; }
bsalomonf90a02b2014-11-26 12:28:00 -0800354
halcanary96fcdcc2015-08-27 07:41:13 -0700355 GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) override { return nullptr; }
bsalomonf90a02b2014-11-26 12:28:00 -0800356
jvanverth73063dc2015-12-03 09:15:47 -0800357 GrTransferBuffer* onCreateTransferBuffer(size_t, TransferType) override { return nullptr; }
358
egdaniel51c8d402015-08-06 10:54:13 -0700359 void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800360
mtklein36352bf2015-03-25 18:17:31 -0700361 void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800362
bsalomone64eb572015-05-07 11:35:55 -0700363 void onDraw(const DrawArgs&, const GrNonInstancedVertices&) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800364
bsalomon6cb3cbe2015-07-30 07:34:27 -0700365 bool onReadPixels(GrSurface* surface,
bsalomonf90a02b2014-11-26 12:28:00 -0800366 int left, int top, int width, int height,
367 GrPixelConfig,
368 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700369 size_t rowBytes) override {
bsalomonf90a02b2014-11-26 12:28:00 -0800370 return false;
bsalomon33435572014-11-05 14:47:41 -0800371 }
372
bsalomon6cb3cbe2015-07-30 07:34:27 -0700373 bool onWritePixels(GrSurface* surface,
374 int left, int top, int width, int height,
375 GrPixelConfig config, const void* buffer,
376 size_t rowBytes) override {
bsalomon33435572014-11-05 14:47:41 -0800377 return false;
378 }
379
jvanverth17aa0472016-01-05 10:41:27 -0800380 bool onTransferPixels(GrSurface* surface,
381 int left, int top, int width, int height,
382 GrPixelConfig config, GrTransferBuffer* buffer,
383 size_t offset, size_t rowBytes) override {
384 return false;
385 }
386
mtklein36352bf2015-03-25 18:17:31 -0700387 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
bsalomonf90a02b2014-11-26 12:28:00 -0800388
egdanielec00d942015-09-14 12:56:10 -0700389 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
390 int width,
391 int height) override {
392 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800393 }
394
mtklein36352bf2015-03-25 18:17:31 -0700395 void clearStencil(GrRenderTarget* target) override {}
bsalomon33435572014-11-05 14:47:41 -0800396
jvanverth88957922015-07-14 11:02:52 -0700397 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
bsalomone63ffef2016-02-05 07:17:34 -0800398 GrPixelConfig config) override {
cblume61214052016-01-26 09:10:48 -0800399 return 0;
jvanverth88957922015-07-14 11:02:52 -0700400 }
bsalomon67d76202015-11-11 12:40:42 -0800401 bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
bsalomone63ffef2016-02-05 07:17:34 -0800402 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
jvanverth672bb7f2015-07-13 07:19:57 -0700403
bsalomon33435572014-11-05 14:47:41 -0800404 typedef GrGpu INHERITED;
405};
406
407GrContext* GrContext::CreateMockContext() {
halcanary385fe4d2015-08-26 13:07:48 -0700408 GrContext* context = new GrContext;
bsalomon33435572014-11-05 14:47:41 -0800409
410 context->initMockContext();
411 return context;
412}
413
414void GrContext::initMockContext() {
bsalomon682c2692015-05-22 14:01:46 -0700415 GrContextOptions options;
joshualitt8b081592015-06-01 16:17:03 -0700416 options.fGeometryBufferMapThreshold = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700417 SkASSERT(nullptr == fGpu);
halcanary385fe4d2015-08-26 13:07:48 -0700418 fGpu = new MockGpu(this, options);
bsalomon33435572014-11-05 14:47:41 -0800419 SkASSERT(fGpu);
bsalomon69cfe952015-11-30 13:27:47 -0800420 this->initCommon(options);
bsalomon33435572014-11-05 14:47:41 -0800421
422 // We delete these because we want to test the cache starting with zero resources. Also, none of
423 // these objects are required for any of tests that use this context. TODO: make stop allocating
424 // resources in the buffer pools.
robertphillips77a2e522015-10-17 07:43:27 -0700425 fDrawingManager->abandon();
bsalomon33435572014-11-05 14:47:41 -0800426}