blob: 387ef32ffd0b424d228a8644d5bfd47b66f57656 [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"
robertphillips5fa7f302016-07-21 09:21:04 -070015#include "GrPipelineBuilder.h"
csmartdaltonf9635992016-08-10 11:09:07 -070016#include "GrRenderTargetProxy.h"
bsalomon0ea80f42015-02-11 10:49:59 -080017#include "GrResourceCache.h"
jvanverth0671b962015-12-08 18:53:44 -080018
19#include "SkGpuDevice.h"
jvanverth629162d2015-11-08 08:07:24 -080020#include "SkGrPriv.h"
halcanary4dbbd042016-06-07 17:21:10 -070021#include "SkMathPriv.h"
mtkleinb9eb4ac2015-02-02 18:26:03 -080022#include "SkString.h"
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000023
joshualitte8042922015-12-11 06:11:21 -080024#include "text/GrBatchFontCache.h"
25#include "text/GrTextBlobCache.h"
26
joshualitt7f9c9eb2015-08-21 11:08:00 -070027namespace GrTest {
28void SetupAlwaysEvictAtlas(GrContext* context) {
29 // These sizes were selected because they allow each atlas to hold a single plot and will thus
30 // stress the atlas
31 int dim = GrBatchAtlas::kGlyphMaxDim;
32 GrBatchAtlasConfig configs[3];
33 configs[kA8_GrMaskFormat].fWidth = dim;
34 configs[kA8_GrMaskFormat].fHeight = dim;
jvanverth7023a002016-02-22 11:25:32 -080035 configs[kA8_GrMaskFormat].fLog2Width = SkNextLog2(dim);
36 configs[kA8_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070037 configs[kA8_GrMaskFormat].fPlotWidth = dim;
38 configs[kA8_GrMaskFormat].fPlotHeight = dim;
39
40 configs[kA565_GrMaskFormat].fWidth = dim;
41 configs[kA565_GrMaskFormat].fHeight = dim;
jvanverth7023a002016-02-22 11:25:32 -080042 configs[kA565_GrMaskFormat].fLog2Width = SkNextLog2(dim);
43 configs[kA565_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070044 configs[kA565_GrMaskFormat].fPlotWidth = dim;
45 configs[kA565_GrMaskFormat].fPlotHeight = dim;
46
47 configs[kARGB_GrMaskFormat].fWidth = dim;
48 configs[kARGB_GrMaskFormat].fHeight = dim;
jvanverth7023a002016-02-22 11:25:32 -080049 configs[kARGB_GrMaskFormat].fLog2Width = SkNextLog2(dim);
50 configs[kARGB_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070051 configs[kARGB_GrMaskFormat].fPlotWidth = dim;
52 configs[kARGB_GrMaskFormat].fPlotHeight = dim;
53
54 context->setTextContextAtlasSizes_ForTesting(configs);
55}
56};
57
robertphillips87f15c82016-05-20 11:14:33 -070058void GrTestTarget::init(GrContext* ctx, sk_sp<GrDrawContext> drawContext) {
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000059 SkASSERT(!fContext);
60
61 fContext.reset(SkRef(ctx));
robertphillips87f15c82016-05-20 11:14:33 -070062 fDrawContext = drawContext;
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000063}
64
robertphillips87f15c82016-05-20 11:14:33 -070065void GrContext::getTestTarget(GrTestTarget* tar, sk_sp<GrDrawContext> drawContext) {
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000066 this->flush();
robertphillips87f15c82016-05-20 11:14:33 -070067 SkASSERT(drawContext);
Robert Phillipsf2361d22016-10-25 14:20:06 -040068 // We could create a proxy GrOpList that passes through to fGpu until ~GrTextTarget() and
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000069 // then disconnects. This would help prevent test writers from mixing using the returned
Robert Phillipsf2361d22016-10-25 14:20:06 -040070 // GrOpList and regular drawing. We could also assert or fail in GrContext drawing methods
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000071 // until ~GrTestTarget().
robertphillips87f15c82016-05-20 11:14:33 -070072 tar->init(this, std::move(drawContext));
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000073}
74
joshualitt17d833b2015-08-03 10:17:44 -070075void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) {
76 fTextBlobCache->setBudget(bytes);
77}
78
joshualittda04e0e2015-08-19 08:16:43 -070079void GrContext::setTextContextAtlasSizes_ForTesting(const GrBatchAtlasConfig* configs) {
80 fBatchFontCache->setAtlasSizes_ForTesting(configs);
81}
82
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000083///////////////////////////////////////////////////////////////////////////////
84
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000085void GrContext::purgeAllUnlockedResources() {
bsalomon0ea80f42015-02-11 10:49:59 -080086 fResourceCache->purgeAllUnlocked();
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000087}
bsalomon33435572014-11-05 14:47:41 -080088
joshualitte45c81c2015-12-02 09:05:37 -080089void GrContext::resetGpuStats() const {
90#if GR_GPU_STATS
91 fGpu->stats()->reset();
92#endif
93}
94
mtkleinb9eb4ac2015-02-02 18:26:03 -080095void GrContext::dumpCacheStats(SkString* out) const {
96#if GR_CACHE_STATS
bsalomon0ea80f42015-02-11 10:49:59 -080097 fResourceCache->dumpStats(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -080098#endif
99}
100
joshualittdc5685a2015-12-02 14:08:25 -0800101void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
102 SkTArray<double>* values) const {
103#if GR_CACHE_STATS
104 fResourceCache->dumpStatsKeyValuePairs(keys, values);
105#endif
106}
107
mtkleinb9eb4ac2015-02-02 18:26:03 -0800108void GrContext::printCacheStats() const {
109 SkString out;
110 this->dumpCacheStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800111 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800112}
113
114void GrContext::dumpGpuStats(SkString* out) const {
115#if GR_GPU_STATS
116 return fGpu->stats()->dump(out);
117#endif
118}
119
joshualitte45c81c2015-12-02 09:05:37 -0800120void GrContext::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys,
121 SkTArray<double>* values) const {
122#if GR_GPU_STATS
123 return fGpu->stats()->dumpKeyValuePairs(keys, values);
124#endif
125}
126
mtkleinb9eb4ac2015-02-02 18:26:03 -0800127void GrContext::printGpuStats() const {
128 SkString out;
129 this->dumpGpuStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800130 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800131}
132
jvanverth0671b962015-12-08 18:53:44 -0800133GrTexture* GrContext::getFontAtlasTexture(GrMaskFormat format) {
jvanverth629162d2015-11-08 08:07:24 -0800134 GrBatchFontCache* cache = this->getBatchFontCache();
135
jvanverth0671b962015-12-08 18:53:44 -0800136 return cache->getTexture(format);
137}
jvanverth629162d2015-11-08 08:07:24 -0800138
jvanverth0671b962015-12-08 18:53:44 -0800139void SkGpuDevice::drawTexture(GrTexture* tex, const SkRect& dst, const SkPaint& paint) {
jvanverth629162d2015-11-08 08:07:24 -0800140 GrPaint grPaint;
141 SkMatrix mat;
142 mat.reset();
brianosman8fe485b2016-07-25 12:31:51 -0700143 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, mat, &grPaint)) {
jvanverth629162d2015-11-08 08:07:24 -0800144 return;
145 }
146 SkMatrix textureMat;
147 textureMat.reset();
jvanverth0671b962015-12-08 18:53:44 -0800148 textureMat[SkMatrix::kMScaleX] = 1.0f/dst.width();
149 textureMat[SkMatrix::kMScaleY] = 1.0f/dst.height();
150 textureMat[SkMatrix::kMTransX] = -dst.fLeft/dst.width();
151 textureMat[SkMatrix::kMTransY] = -dst.fTop/dst.height();
jvanverth629162d2015-11-08 08:07:24 -0800152
brianosman54f30c12016-07-18 10:53:52 -0700153 grPaint.addColorTextureProcessor(tex, nullptr, textureMat);
jvanverth629162d2015-11-08 08:07:24 -0800154
cdalton846c0512016-05-13 10:25:00 -0700155 fDrawContext->drawRect(GrNoClip(), grPaint, mat, dst);
jvanverth629162d2015-11-08 08:07:24 -0800156}
157
jvanverth0671b962015-12-08 18:53:44 -0800158
mtkleinb9eb4ac2015-02-02 18:26:03 -0800159#if GR_GPU_STATS
160void GrGpu::Stats::dump(SkString* out) {
161 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
162 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800163 out->appendf("Textures Created: %d\n", fTextureCreates);
164 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800165 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700166 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700167 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800168}
joshualitte45c81c2015-12-02 09:05:37 -0800169
170void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
171 keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds);
172 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
joshualitte45c81c2015-12-02 09:05:37 -0800173 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800174 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700175 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800176}
177
mtkleinb9eb4ac2015-02-02 18:26:03 -0800178#endif
179
180#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800181void GrResourceCache::getStats(Stats* stats) const {
182 stats->reset();
183
184 stats->fTotal = this->getResourceCount();
185 stats->fNumNonPurgeable = fNonpurgeableResources.count();
186 stats->fNumPurgeable = fPurgeableQueue.count();
187
188 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
189 stats->update(fNonpurgeableResources[i]);
190 }
191 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
192 stats->update(fPurgeableQueue.at(i));
193 }
194}
195
bsalomon0ea80f42015-02-11 10:49:59 -0800196void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800197 this->validate();
198
bsalomonf320e042015-02-17 15:09:34 -0800199 Stats stats;
200
robertphillips60029a52015-11-09 13:51:06 -0800201 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800202
203 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
204 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
205
206 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
207 out->appendf("\t\tEntry Count: current %d"
kkinnunen2e6055b2016-04-22 01:48:29 -0700208 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n",
209 stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable,
210 stats.fScratch, countUtilization, fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800211 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800212 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
213 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800214}
215
joshualittdc5685a2015-12-02 14:08:25 -0800216void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
217 SkTArray<double>* values) const {
218 this->validate();
219
220 Stats stats;
221 this->getStats(&stats);
222
joshualittdc5685a2015-12-02 14:08:25 -0800223 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
joshualittdc5685a2015-12-02 14:08:25 -0800224}
225
mtkleinb9eb4ac2015-02-02 18:26:03 -0800226#endif
227
bsalomonddf30e62015-02-19 11:38:44 -0800228///////////////////////////////////////////////////////////////////////////////
229
230void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800231
bsalomon33435572014-11-05 14:47:41 -0800232///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800233
234#define ASSERT_SINGLE_OWNER \
robertphillips391395d2016-03-02 09:26:36 -0800235 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fDrawContext->fSingleOwner);)
robertphillips7761d612016-05-16 09:14:53 -0700236#define RETURN_IF_ABANDONED if (fDrawContext->fDrawingManager->wasAbandoned()) { return; }
joshualittf5883a62016-01-13 07:47:38 -0800237
robertphillips28a838e2016-06-23 14:07:00 -0700238void GrDrawContextPriv::testingOnly_drawBatch(const GrPaint& paint,
cdalton862cff32016-05-12 15:09:48 -0700239 GrDrawBatch* batch,
robertphillips28a838e2016-06-23 14:07:00 -0700240 const GrUserStencilSettings* uss,
241 bool snapToCenters) {
joshualittf5883a62016-01-13 07:47:38 -0800242 ASSERT_SINGLE_OWNER
243 RETURN_IF_ABANDONED
robertphillips391395d2016-03-02 09:26:36 -0800244 SkDEBUGCODE(fDrawContext->validate();)
245 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::testingOnly_drawBatch");
joshualittf5883a62016-01-13 07:47:38 -0800246
robertphillips28a838e2016-06-23 14:07:00 -0700247 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->mustUseHWAA(paint));
248 if (uss) {
249 pipelineBuilder.setUserStencil(uss);
cdalton846c0512016-05-13 10:25:00 -0700250 }
robertphillips28a838e2016-06-23 14:07:00 -0700251 if (snapToCenters) {
252 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, true);
253 }
254
Robert Phillipsf2361d22016-10-25 14:20:06 -0400255 fDrawContext->getOpList()->drawBatch(pipelineBuilder, fDrawContext, GrNoClip(), batch);
joshualittf5883a62016-01-13 07:47:38 -0800256}
257
258#undef ASSERT_SINGLE_OWNER
259#undef RETURN_IF_ABANDONED
260
261///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700262
263GrRenderTargetPriv::Flags GrRenderTargetProxy::testingOnly_getFlags() const {
264 return fFlags;
265}
266
267///////////////////////////////////////////////////////////////////////////////
bsalomon33435572014-11-05 14:47:41 -0800268// Code for the mock context. It's built on a mock GrGpu class that does nothing.
269////
270
bsalomon33435572014-11-05 14:47:41 -0800271#include "GrGpu.h"
272
egdaniel8dd688b2015-01-22 10:16:09 -0800273class GrPipeline;
joshualittd53a8272014-11-10 16:03:14 -0800274
bsalomon41e4384e2016-01-08 09:12:44 -0800275class MockCaps : public GrCaps {
276public:
277 explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {}
278 bool isConfigTexturable(GrPixelConfig config) const override { return false; }
279 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; }
280private:
281 typedef GrCaps INHERITED;
282};
283
bsalomon33435572014-11-05 14:47:41 -0800284class MockGpu : public GrGpu {
285public:
bsalomon682c2692015-05-22 14:01:46 -0700286 MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
bsalomon41e4384e2016-01-08 09:12:44 -0800287 fCaps.reset(new MockCaps(options));
bsalomon682c2692015-05-22 14:01:46 -0700288 }
mtklein36352bf2015-03-25 18:17:31 -0700289 ~MockGpu() override {}
bsalomon33435572014-11-05 14:47:41 -0800290
bsalomonf0674512015-07-28 13:26:15 -0700291 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
292 GrPixelConfig readConfig, DrawPreference*,
293 ReadPixelTempDrawInfo*) override { return false; }
294
cblumeed828002016-02-16 13:00:01 -0800295 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
bsalomonf0674512015-07-28 13:26:15 -0700296 GrPixelConfig srcConfig, DrawPreference*,
297 WritePixelTempDrawInfo*) override { return false; }
bsalomon39826022015-07-23 08:07:21 -0700298
joshualitt1cbdcde2015-08-21 11:53:29 -0700299 bool onCopySurface(GrSurface* dst,
300 GrSurface* src,
301 const SkIRect& srcRect,
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400302 const SkIPoint& dstPoint) override { return false; }
bsalomonf90a02b2014-11-26 12:28:00 -0800303
csmartdalton0d28e572016-07-06 09:59:43 -0700304 void onGetMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&,
305 int* effectiveSampleCnt, SamplePattern*) override {
cdalton28f45b92016-03-07 13:58:26 -0800306 *effectiveSampleCnt = rt->desc().fSampleCnt;
307 }
308
egdaniel4bcd62e2016-08-31 07:37:31 -0700309 bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc) const override {
bsalomonf90a02b2014-11-26 12:28:00 -0800310 return false;
311 }
joshualitt3322fa42014-11-07 08:48:51 -0800312
egdaniel9cb63402016-06-23 08:37:05 -0700313 GrGpuCommandBuffer* createCommandBuffer(GrRenderTarget* target,
314 const GrGpuCommandBuffer::LoadAndStoreInfo&,
315 const GrGpuCommandBuffer::LoadAndStoreInfo&) override {
egdaniel066df7c2016-06-08 14:02:27 -0700316 return nullptr;
317 }
318
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400319 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {}
bsalomon6dea83f2015-12-03 12:58:06 -0800320
jvanverth84741b32016-09-30 08:39:02 -0700321 GrFence SK_WARN_UNUSED_RESULT insertFence() const override { return 0; }
322 bool waitFence(GrFence, uint64_t) const override { return true; }
323 void deleteFence(GrFence) const 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
kkinnunen2e6055b2016-04-22 01:48:29 -0700330 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
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
kkinnunen2e6055b2016-04-22 01:48:29 -0700335 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800336 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700337 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800338 }
339
bungeman6bd52842016-10-27 09:30:08 -0700340 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700341 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800342 }
343
bungeman6bd52842016-10-27 09:30:08 -0700344 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
345 GrWrapOwnership) override {
346 return nullptr;
347 }
348
349 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override {
ericrkf7b8b8a2016-02-24 14:49:51 -0800350 return nullptr;
351 }
352
cdalton1bf3e712016-04-19 10:00:02 -0700353 GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
354 return nullptr;
355 }
jvanverth73063dc2015-12-03 09:15:47 -0800356
csmartdaltone0d36292016-07-29 08:14:20 -0700357 gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
358
bsalomon6cb3cbe2015-07-30 07:34:27 -0700359 bool onReadPixels(GrSurface* surface,
bsalomonf90a02b2014-11-26 12:28:00 -0800360 int left, int top, int width, int height,
361 GrPixelConfig,
362 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700363 size_t rowBytes) override {
bsalomonf90a02b2014-11-26 12:28:00 -0800364 return false;
bsalomon33435572014-11-05 14:47:41 -0800365 }
366
bsalomon6cb3cbe2015-07-30 07:34:27 -0700367 bool onWritePixels(GrSurface* surface,
368 int left, int top, int width, int height,
cblume55f2d2d2016-02-26 13:20:48 -0800369 GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override {
bsalomon33435572014-11-05 14:47:41 -0800370 return false;
371 }
372
jvanverthc3d706f2016-04-20 10:33:27 -0700373 bool onTransferPixels(GrSurface* surface,
jvanverth17aa0472016-01-05 10:41:27 -0800374 int left, int top, int width, int height,
cdalton397536c2016-03-25 12:15:03 -0700375 GrPixelConfig config, GrBuffer* transferBuffer,
jvanverth17aa0472016-01-05 10:41:27 -0800376 size_t offset, size_t rowBytes) override {
377 return false;
378 }
379
mtklein36352bf2015-03-25 18:17:31 -0700380 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
bsalomonf90a02b2014-11-26 12:28:00 -0800381
egdanielec00d942015-09-14 12:56:10 -0700382 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
383 int width,
384 int height) override {
385 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800386 }
387
mtklein36352bf2015-03-25 18:17:31 -0700388 void clearStencil(GrRenderTarget* target) override {}
bsalomon33435572014-11-05 14:47:41 -0800389
jvanverth88957922015-07-14 11:02:52 -0700390 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
egdaniel0a3a7f72016-06-24 09:22:31 -0700391 GrPixelConfig config, bool isRT) override {
cblume61214052016-01-26 09:10:48 -0800392 return 0;
jvanverth88957922015-07-14 11:02:52 -0700393 }
bsalomon67d76202015-11-11 12:40:42 -0800394 bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
bsalomone63ffef2016-02-05 07:17:34 -0800395 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
jvanverth672bb7f2015-07-13 07:19:57 -0700396
bsalomon33435572014-11-05 14:47:41 -0800397 typedef GrGpu INHERITED;
398};
399
400GrContext* GrContext::CreateMockContext() {
halcanary385fe4d2015-08-26 13:07:48 -0700401 GrContext* context = new GrContext;
bsalomon33435572014-11-05 14:47:41 -0800402
403 context->initMockContext();
404 return context;
405}
406
407void GrContext::initMockContext() {
bsalomon682c2692015-05-22 14:01:46 -0700408 GrContextOptions options;
cdalton397536c2016-03-25 12:15:03 -0700409 options.fBufferMapThreshold = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700410 SkASSERT(nullptr == fGpu);
halcanary385fe4d2015-08-26 13:07:48 -0700411 fGpu = new MockGpu(this, options);
bsalomon33435572014-11-05 14:47:41 -0800412 SkASSERT(fGpu);
bsalomon69cfe952015-11-30 13:27:47 -0800413 this->initCommon(options);
bsalomon33435572014-11-05 14:47:41 -0800414
415 // We delete these because we want to test the cache starting with zero resources. Also, none of
416 // these objects are required for any of tests that use this context. TODO: make stop allocating
417 // resources in the buffer pools.
robertphillips77a2e522015-10-17 07:43:27 -0700418 fDrawingManager->abandon();
bsalomon33435572014-11-05 14:47:41 -0800419}