blob: 818bf6462d827c927fdbfd0ed5cea9569d4bf9d1 [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();
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);
joshualitte45c81c2015-12-02 09:05:37 -0800189 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800190 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700191 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800192}
193
mtkleinb9eb4ac2015-02-02 18:26:03 -0800194#endif
195
196#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800197void GrResourceCache::getStats(Stats* stats) const {
198 stats->reset();
199
200 stats->fTotal = this->getResourceCount();
201 stats->fNumNonPurgeable = fNonpurgeableResources.count();
202 stats->fNumPurgeable = fPurgeableQueue.count();
203
204 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
205 stats->update(fNonpurgeableResources[i]);
206 }
207 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
208 stats->update(fPurgeableQueue.at(i));
209 }
210}
211
bsalomon0ea80f42015-02-11 10:49:59 -0800212void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800213 this->validate();
214
bsalomonf320e042015-02-17 15:09:34 -0800215 Stats stats;
216
robertphillips60029a52015-11-09 13:51:06 -0800217 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800218
219 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
220 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
221
222 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
223 out->appendf("\t\tEntry Count: current %d"
bsalomon6dc6f5f2015-06-18 09:12:16 -0700224 " (%d budgeted, %d external(%d borrowed, %d adopted), %d locked, %d scratch %.2g%% full), high %d\n",
robertphillips60029a52015-11-09 13:51:06 -0800225 stats.fTotal, fBudgetedCount, stats.fExternal, stats.fBorrowed,
226 stats.fAdopted, stats.fNumNonPurgeable, stats.fScratch, countUtilization,
227 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,
256 GrDrawBatch* batch) {
joshualittf5883a62016-01-13 07:47:38 -0800257 ASSERT_SINGLE_OWNER
258 RETURN_IF_ABANDONED
robertphillips391395d2016-03-02 09:26:36 -0800259 SkDEBUGCODE(fDrawContext->validate();)
260 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::testingOnly_drawBatch");
joshualittf5883a62016-01-13 07:47:38 -0800261
robertphillips391395d2016-03-02 09:26:36 -0800262 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, batch);
joshualittf5883a62016-01-13 07:47:38 -0800263}
264
265#undef ASSERT_SINGLE_OWNER
266#undef RETURN_IF_ABANDONED
267
268///////////////////////////////////////////////////////////////////////////////
bsalomon33435572014-11-05 14:47:41 -0800269// Code for the mock context. It's built on a mock GrGpu class that does nothing.
270////
271
bsalomon33435572014-11-05 14:47:41 -0800272#include "GrGpu.h"
273
egdaniel8dd688b2015-01-22 10:16:09 -0800274class GrPipeline;
joshualittd53a8272014-11-10 16:03:14 -0800275
bsalomon41e4384e2016-01-08 09:12:44 -0800276class MockCaps : public GrCaps {
277public:
278 explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {}
279 bool isConfigTexturable(GrPixelConfig config) const override { return false; }
280 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; }
281private:
282 typedef GrCaps INHERITED;
283};
284
bsalomon33435572014-11-05 14:47:41 -0800285class MockGpu : public GrGpu {
286public:
bsalomon682c2692015-05-22 14:01:46 -0700287 MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
bsalomon41e4384e2016-01-08 09:12:44 -0800288 fCaps.reset(new MockCaps(options));
bsalomon682c2692015-05-22 14:01:46 -0700289 }
mtklein36352bf2015-03-25 18:17:31 -0700290 ~MockGpu() override {}
bsalomon33435572014-11-05 14:47:41 -0800291
bsalomonf0674512015-07-28 13:26:15 -0700292 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
293 GrPixelConfig readConfig, DrawPreference*,
294 ReadPixelTempDrawInfo*) override { return false; }
295
cblumeed828002016-02-16 13:00:01 -0800296 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
bsalomonf0674512015-07-28 13:26:15 -0700297 GrPixelConfig srcConfig, DrawPreference*,
298 WritePixelTempDrawInfo*) override { return false; }
bsalomon39826022015-07-23 08:07:21 -0700299
mtklein36352bf2015-03-25 18:17:31 -0700300 void discard(GrRenderTarget*) override {}
bsalomon33435572014-11-05 14:47:41 -0800301
joshualitt1cbdcde2015-08-21 11:53:29 -0700302 bool onCopySurface(GrSurface* dst,
303 GrSurface* src,
304 const SkIRect& srcRect,
305 const SkIPoint& dstPoint) override { return false; };
bsalomonf90a02b2014-11-26 12:28:00 -0800306
cdalton28f45b92016-03-07 13:58:26 -0800307 void onGetMultisampleSpecs(GrRenderTarget* rt,
308 const GrStencilSettings&,
309 int* effectiveSampleCnt,
310 SkAutoTDeleteArray<SkPoint>*) override {
311 *effectiveSampleCnt = rt->desc().fSampleCnt;
312 }
313
joshualitt1c735482015-07-13 08:08:25 -0700314 bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const override {
bsalomonf90a02b2014-11-26 12:28:00 -0800315 return false;
316 }
joshualitt3322fa42014-11-07 08:48:51 -0800317
bsalomon6dea83f2015-12-03 12:58:06 -0800318 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {};
319
bsalomon33435572014-11-05 14:47:41 -0800320private:
mtklein36352bf2015-03-25 18:17:31 -0700321 void onResetContext(uint32_t resetBits) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800322
bsalomoncb02b382015-08-12 11:14:50 -0700323 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
324
egdanielb0e1be22015-04-22 13:27:39 -0700325 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle lifeCycle,
cblume55f2d2d2016-02-26 13:20:48 -0800326 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700327 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800328 }
329
egdanielb0e1be22015-04-22 13:27:39 -0700330 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle,
cblume55f2d2d2016-02-26 13:20:48 -0800331 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700332 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800333 }
334
bsalomon6dc6f5f2015-06-18 09:12:16 -0700335 GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&,
halcanary96fcdcc2015-08-27 07:41:13 -0700336 GrWrapOwnership) override { return nullptr; }
bsalomonf90a02b2014-11-26 12:28:00 -0800337
bsalomon6dc6f5f2015-06-18 09:12:16 -0700338 GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
339 GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700340 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800341 }
342
kkinnunen49c4c222016-04-01 04:50:37 -0700343 GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override {
ericrkf7b8b8a2016-02-24 14:49:51 -0800344 return nullptr;
345 }
346
cdalton397536c2016-03-25 12:15:03 -0700347 GrBuffer* onCreateBuffer(GrBufferType, size_t, GrAccessPattern) override { return nullptr; }
jvanverth73063dc2015-12-03 09:15:47 -0800348
egdaniel51c8d402015-08-06 10:54:13 -0700349 void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800350
mtklein36352bf2015-03-25 18:17:31 -0700351 void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800352
egdaniel0e1853c2016-03-17 11:35:45 -0700353 void onDraw(const GrPipeline&,
354 const GrPrimitiveProcessor&,
355 const GrMesh*,
356 int meshCount) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800357
bsalomon6cb3cbe2015-07-30 07:34:27 -0700358 bool onReadPixels(GrSurface* surface,
bsalomonf90a02b2014-11-26 12:28:00 -0800359 int left, int top, int width, int height,
360 GrPixelConfig,
361 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700362 size_t rowBytes) override {
bsalomonf90a02b2014-11-26 12:28:00 -0800363 return false;
bsalomon33435572014-11-05 14:47:41 -0800364 }
365
bsalomon6cb3cbe2015-07-30 07:34:27 -0700366 bool onWritePixels(GrSurface* surface,
367 int left, int top, int width, int height,
cblume55f2d2d2016-02-26 13:20:48 -0800368 GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override {
bsalomon33435572014-11-05 14:47:41 -0800369 return false;
370 }
371
jvanverth17aa0472016-01-05 10:41:27 -0800372 bool onTransferPixels(GrSurface* surface,
373 int left, int top, int width, int height,
cdalton397536c2016-03-25 12:15:03 -0700374 GrPixelConfig config, GrBuffer* transferBuffer,
jvanverth17aa0472016-01-05 10:41:27 -0800375 size_t offset, size_t rowBytes) override {
376 return false;
377 }
378
mtklein36352bf2015-03-25 18:17:31 -0700379 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
bsalomonf90a02b2014-11-26 12:28:00 -0800380
egdanielec00d942015-09-14 12:56:10 -0700381 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
382 int width,
383 int height) override {
384 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800385 }
386
mtklein36352bf2015-03-25 18:17:31 -0700387 void clearStencil(GrRenderTarget* target) override {}
bsalomon33435572014-11-05 14:47:41 -0800388
jvanverth88957922015-07-14 11:02:52 -0700389 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
bsalomone63ffef2016-02-05 07:17:34 -0800390 GrPixelConfig config) override {
cblume61214052016-01-26 09:10:48 -0800391 return 0;
jvanverth88957922015-07-14 11:02:52 -0700392 }
bsalomon67d76202015-11-11 12:40:42 -0800393 bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
bsalomone63ffef2016-02-05 07:17:34 -0800394 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
jvanverth672bb7f2015-07-13 07:19:57 -0700395
bsalomon33435572014-11-05 14:47:41 -0800396 typedef GrGpu INHERITED;
397};
398
399GrContext* GrContext::CreateMockContext() {
halcanary385fe4d2015-08-26 13:07:48 -0700400 GrContext* context = new GrContext;
bsalomon33435572014-11-05 14:47:41 -0800401
402 context->initMockContext();
403 return context;
404}
405
406void GrContext::initMockContext() {
bsalomon682c2692015-05-22 14:01:46 -0700407 GrContextOptions options;
cdalton397536c2016-03-25 12:15:03 -0700408 options.fBufferMapThreshold = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700409 SkASSERT(nullptr == fGpu);
halcanary385fe4d2015-08-26 13:07:48 -0700410 fGpu = new MockGpu(this, options);
bsalomon33435572014-11-05 14:47:41 -0800411 SkASSERT(fGpu);
bsalomon69cfe952015-11-30 13:27:47 -0800412 this->initCommon(options);
bsalomon33435572014-11-05 14:47:41 -0800413
414 // We delete these because we want to test the cache starting with zero resources. Also, none of
415 // these objects are required for any of tests that use this context. TODO: make stop allocating
416 // resources in the buffer pools.
robertphillips77a2e522015-10-17 07:43:27 -0700417 fDrawingManager->abandon();
bsalomon33435572014-11-05 14:47:41 -0800418}