blob: 975d1ecf94c6e10f03f746fc57f45c3c499a77a2 [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
bsalomon682c2692015-05-22 14:01:46 -070010#include "GrContextOptions.h"
Brian Salomon2ee084e2016-12-16 18:59:19 -050011#include "GrDrawOpAtlas.h"
robertphillips77a2e522015-10-17 07:43:27 -070012#include "GrDrawingManager.h"
bsalomon3582d3e2015-02-13 14:20:05 -080013#include "GrGpuResourceCacheAccess.h"
robertphillips5fa7f302016-07-21 09:21:04 -070014#include "GrPipelineBuilder.h"
Brian Salomon2ee084e2016-12-16 18:59:19 -050015#include "GrRenderTargetContextPriv.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
jvanverth629162d2015-11-08 08:07:24 -080019#include "SkGrPriv.h"
Robert Phillips22f4a1f2016-12-20 08:57:26 -050020#include "SkImage_Gpu.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
Brian Salomonf856fd12016-12-16 14:24:34 -050024#include "text/GrAtlasGlyphCache.h"
joshualitte8042922015-12-11 06:11:21 -080025#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
Brian Salomon2ee084e2016-12-16 18:59:19 -050031 int dim = GrDrawOpAtlas::kGlyphMaxDim;
32 GrDrawOpAtlasConfig configs[3];
joshualitt7f9c9eb2015-08-21 11:08:00 -070033 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
Robert Phillipseaa86252016-11-08 13:49:39 +000058bool GrSurfaceProxy::isWrapped_ForTesting() const {
59 return SkToBool(fTarget);
60}
61
62bool GrRenderTargetContext::isWrapped_ForTesting() const {
63 return fRenderTargetProxy->isWrapped_ForTesting();
64}
65
joshualitt17d833b2015-08-03 10:17:44 -070066void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) {
67 fTextBlobCache->setBudget(bytes);
68}
69
Brian Salomon2ee084e2016-12-16 18:59:19 -050070void GrContext::setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs) {
Brian Salomonf856fd12016-12-16 14:24:34 -050071 fAtlasGlyphCache->setAtlasSizes_ForTesting(configs);
joshualittda04e0e2015-08-19 08:16:43 -070072}
73
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000074///////////////////////////////////////////////////////////////////////////////
75
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000076void GrContext::purgeAllUnlockedResources() {
bsalomon0ea80f42015-02-11 10:49:59 -080077 fResourceCache->purgeAllUnlocked();
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000078}
bsalomon33435572014-11-05 14:47:41 -080079
joshualitte45c81c2015-12-02 09:05:37 -080080void GrContext::resetGpuStats() const {
81#if GR_GPU_STATS
82 fGpu->stats()->reset();
83#endif
84}
85
mtkleinb9eb4ac2015-02-02 18:26:03 -080086void GrContext::dumpCacheStats(SkString* out) const {
87#if GR_CACHE_STATS
bsalomon0ea80f42015-02-11 10:49:59 -080088 fResourceCache->dumpStats(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -080089#endif
90}
91
joshualittdc5685a2015-12-02 14:08:25 -080092void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
93 SkTArray<double>* values) const {
94#if GR_CACHE_STATS
95 fResourceCache->dumpStatsKeyValuePairs(keys, values);
96#endif
97}
98
mtkleinb9eb4ac2015-02-02 18:26:03 -080099void GrContext::printCacheStats() const {
100 SkString out;
101 this->dumpCacheStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800102 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800103}
104
105void GrContext::dumpGpuStats(SkString* out) const {
106#if GR_GPU_STATS
107 return fGpu->stats()->dump(out);
108#endif
109}
110
joshualitte45c81c2015-12-02 09:05:37 -0800111void GrContext::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys,
112 SkTArray<double>* values) const {
113#if GR_GPU_STATS
114 return fGpu->stats()->dumpKeyValuePairs(keys, values);
115#endif
116}
117
mtkleinb9eb4ac2015-02-02 18:26:03 -0800118void GrContext::printGpuStats() const {
119 SkString out;
120 this->dumpGpuStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800121 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800122}
123
Robert Phillipsc37e6142017-01-20 10:03:25 -0500124sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format) {
Brian Salomonf856fd12016-12-16 14:24:34 -0500125 GrAtlasGlyphCache* cache = this->getAtlasGlyphCache();
jvanverth629162d2015-11-08 08:07:24 -0800126
Robert Phillips22f4a1f2016-12-20 08:57:26 -0500127 GrTexture* tex = cache->getTexture(format);
128 sk_sp<SkImage> image(new SkImage_Gpu(tex->width(), tex->height(),
129 kNeedNewImageUniqueID, kPremul_SkAlphaType,
130 sk_ref_sp(tex), nullptr, SkBudgeted::kNo));
131 return image;
jvanverth0671b962015-12-08 18:53:44 -0800132}
jvanverth629162d2015-11-08 08:07:24 -0800133
mtkleinb9eb4ac2015-02-02 18:26:03 -0800134#if GR_GPU_STATS
135void GrGpu::Stats::dump(SkString* out) {
136 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
137 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800138 out->appendf("Textures Created: %d\n", fTextureCreates);
139 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800140 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700141 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700142 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800143}
joshualitte45c81c2015-12-02 09:05:37 -0800144
145void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
146 keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds);
147 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
joshualitte45c81c2015-12-02 09:05:37 -0800148 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800149 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700150 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800151}
152
mtkleinb9eb4ac2015-02-02 18:26:03 -0800153#endif
154
155#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800156void GrResourceCache::getStats(Stats* stats) const {
157 stats->reset();
158
159 stats->fTotal = this->getResourceCount();
160 stats->fNumNonPurgeable = fNonpurgeableResources.count();
161 stats->fNumPurgeable = fPurgeableQueue.count();
162
163 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
164 stats->update(fNonpurgeableResources[i]);
165 }
166 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
167 stats->update(fPurgeableQueue.at(i));
168 }
169}
170
bsalomon0ea80f42015-02-11 10:49:59 -0800171void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800172 this->validate();
173
bsalomonf320e042015-02-17 15:09:34 -0800174 Stats stats;
175
robertphillips60029a52015-11-09 13:51:06 -0800176 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800177
178 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
179 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
180
181 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
182 out->appendf("\t\tEntry Count: current %d"
kkinnunen2e6055b2016-04-22 01:48:29 -0700183 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n",
184 stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable,
185 stats.fScratch, countUtilization, fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800186 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800187 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
188 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800189}
190
joshualittdc5685a2015-12-02 14:08:25 -0800191void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
192 SkTArray<double>* values) const {
193 this->validate();
194
195 Stats stats;
196 this->getStats(&stats);
197
joshualittdc5685a2015-12-02 14:08:25 -0800198 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
joshualittdc5685a2015-12-02 14:08:25 -0800199}
200
mtkleinb9eb4ac2015-02-02 18:26:03 -0800201#endif
202
bsalomonddf30e62015-02-19 11:38:44 -0800203///////////////////////////////////////////////////////////////////////////////
204
205void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800206
Brian Salomon1090da62017-01-06 12:04:19 -0500207#ifdef SK_DEBUG
208int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
209 int count = 0;
210 UniqueHash::ConstIter iter(&fUniqueHash);
211 while (!iter.done()) {
212 if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
213 ++count;
214 }
215 ++iter;
216 }
217 return count;
218}
219#endif
220
bsalomon33435572014-11-05 14:47:41 -0800221///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800222
223#define ASSERT_SINGLE_OWNER \
Brian Osman11052242016-10-27 14:47:55 -0400224 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->fSingleOwner);)
225#define RETURN_IF_ABANDONED if (fRenderTargetContext->fDrawingManager->wasAbandoned()) { return; }
joshualittf5883a62016-01-13 07:47:38 -0800226
Brian Salomon82f44312017-01-11 13:42:54 -0500227void GrRenderTargetContextPriv::testingOnly_addDrawOp(GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500228 GrAAType aaType,
Brian Salomonf8334782017-01-03 09:42:58 -0500229 std::unique_ptr<GrDrawOp>
230 op,
Brian Osman11052242016-10-27 14:47:55 -0400231 const GrUserStencilSettings* uss,
232 bool snapToCenters) {
joshualittf5883a62016-01-13 07:47:38 -0800233 ASSERT_SINGLE_OWNER
234 RETURN_IF_ABANDONED
Brian Osman11052242016-10-27 14:47:55 -0400235 SkDEBUGCODE(fRenderTargetContext->validate();)
236 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
Brian Salomon1951f3d2016-12-09 16:07:12 -0500237 "GrRenderTargetContext::testingOnly_addDrawOp");
joshualittf5883a62016-01-13 07:47:38 -0800238
Brian Salomon82f44312017-01-11 13:42:54 -0500239 GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
robertphillips28a838e2016-06-23 14:07:00 -0700240 if (uss) {
241 pipelineBuilder.setUserStencil(uss);
cdalton846c0512016-05-13 10:25:00 -0700242 }
Brian Salomon189098e72017-01-19 09:55:19 -0500243 pipelineBuilder.setSnapVerticesToPixelCenters(snapToCenters);
robertphillips28a838e2016-06-23 14:07:00 -0700244
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500245 fRenderTargetContext->getOpList()->addDrawOp(pipelineBuilder, fRenderTargetContext, GrNoClip(),
Brian Salomonf8334782017-01-03 09:42:58 -0500246 std::move(op));
joshualittf5883a62016-01-13 07:47:38 -0800247}
248
249#undef ASSERT_SINGLE_OWNER
250#undef RETURN_IF_ABANDONED
251
252///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700253
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400254GrRenderTarget::Flags GrRenderTargetProxy::testingOnly_getFlags() const {
csmartdaltonf9635992016-08-10 11:09:07 -0700255 return fFlags;
256}
257
258///////////////////////////////////////////////////////////////////////////////
bsalomon33435572014-11-05 14:47:41 -0800259// Code for the mock context. It's built on a mock GrGpu class that does nothing.
260////
261
bsalomon33435572014-11-05 14:47:41 -0800262#include "GrGpu.h"
263
egdaniel8dd688b2015-01-22 10:16:09 -0800264class GrPipeline;
joshualittd53a8272014-11-10 16:03:14 -0800265
bsalomon41e4384e2016-01-08 09:12:44 -0800266class MockCaps : public GrCaps {
267public:
268 explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {}
269 bool isConfigTexturable(GrPixelConfig config) const override { return false; }
270 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; }
Brian Salomonf9f45122016-11-29 11:59:17 -0500271 bool canConfigBeImageStorage(GrPixelConfig) const override { return false; }
272
bsalomon41e4384e2016-01-08 09:12:44 -0800273private:
274 typedef GrCaps INHERITED;
275};
276
bsalomon33435572014-11-05 14:47:41 -0800277class MockGpu : public GrGpu {
278public:
bsalomon682c2692015-05-22 14:01:46 -0700279 MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
bsalomon41e4384e2016-01-08 09:12:44 -0800280 fCaps.reset(new MockCaps(options));
bsalomon682c2692015-05-22 14:01:46 -0700281 }
mtklein36352bf2015-03-25 18:17:31 -0700282 ~MockGpu() override {}
bsalomon33435572014-11-05 14:47:41 -0800283
bsalomonf0674512015-07-28 13:26:15 -0700284 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
285 GrPixelConfig readConfig, DrawPreference*,
286 ReadPixelTempDrawInfo*) override { return false; }
287
cblumeed828002016-02-16 13:00:01 -0800288 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
bsalomonf0674512015-07-28 13:26:15 -0700289 GrPixelConfig srcConfig, DrawPreference*,
290 WritePixelTempDrawInfo*) override { return false; }
bsalomon39826022015-07-23 08:07:21 -0700291
joshualitt1cbdcde2015-08-21 11:53:29 -0700292 bool onCopySurface(GrSurface* dst,
293 GrSurface* src,
294 const SkIRect& srcRect,
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400295 const SkIPoint& dstPoint) override { return false; }
bsalomonf90a02b2014-11-26 12:28:00 -0800296
csmartdaltonc25c5d72016-11-01 07:03:59 -0700297 void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&,
298 int* effectiveSampleCnt, SamplePattern*) override {
cdalton28f45b92016-03-07 13:58:26 -0800299 *effectiveSampleCnt = rt->desc().fSampleCnt;
300 }
301
egdaniel4bcd62e2016-08-31 07:37:31 -0700302 bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc) const override {
bsalomonf90a02b2014-11-26 12:28:00 -0800303 return false;
304 }
joshualitt3322fa42014-11-07 08:48:51 -0800305
Brian Salomonc293a292016-11-30 13:38:32 -0500306 GrGpuCommandBuffer* createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&,
egdaniel9cb63402016-06-23 08:37:05 -0700307 const GrGpuCommandBuffer::LoadAndStoreInfo&) override {
egdaniel066df7c2016-06-08 14:02:27 -0700308 return nullptr;
309 }
310
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400311 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {}
bsalomon6dea83f2015-12-03 12:58:06 -0800312
jvanverth84741b32016-09-30 08:39:02 -0700313 GrFence SK_WARN_UNUSED_RESULT insertFence() const override { return 0; }
314 bool waitFence(GrFence, uint64_t) const override { return true; }
315 void deleteFence(GrFence) const override {}
316
bsalomon33435572014-11-05 14:47:41 -0800317private:
mtklein36352bf2015-03-25 18:17:31 -0700318 void onResetContext(uint32_t resetBits) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800319
bsalomoncb02b382015-08-12 11:14:50 -0700320 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
321
kkinnunen2e6055b2016-04-22 01:48:29 -0700322 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800323 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700324 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800325 }
326
kkinnunen2e6055b2016-04-22 01:48:29 -0700327 GrTexture* onCreateCompressedTexture(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
bungeman6bd52842016-10-27 09:30:08 -0700332 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700333 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800334 }
335
bungeman6bd52842016-10-27 09:30:08 -0700336 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
337 GrWrapOwnership) override {
338 return nullptr;
339 }
340
341 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override {
ericrkf7b8b8a2016-02-24 14:49:51 -0800342 return nullptr;
343 }
344
cdalton1bf3e712016-04-19 10:00:02 -0700345 GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
346 return nullptr;
347 }
jvanverth73063dc2015-12-03 09:15:47 -0800348
csmartdaltone0d36292016-07-29 08:14:20 -0700349 gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
350
bsalomon6cb3cbe2015-07-30 07:34:27 -0700351 bool onReadPixels(GrSurface* surface,
bsalomonf90a02b2014-11-26 12:28:00 -0800352 int left, int top, int width, int height,
353 GrPixelConfig,
354 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700355 size_t rowBytes) override {
bsalomonf90a02b2014-11-26 12:28:00 -0800356 return false;
bsalomon33435572014-11-05 14:47:41 -0800357 }
358
bsalomon6cb3cbe2015-07-30 07:34:27 -0700359 bool onWritePixels(GrSurface* surface,
360 int left, int top, int width, int height,
cblume55f2d2d2016-02-26 13:20:48 -0800361 GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override {
bsalomon33435572014-11-05 14:47:41 -0800362 return false;
363 }
364
jvanverthc3d706f2016-04-20 10:33:27 -0700365 bool onTransferPixels(GrSurface* surface,
jvanverth17aa0472016-01-05 10:41:27 -0800366 int left, int top, int width, int height,
cdalton397536c2016-03-25 12:15:03 -0700367 GrPixelConfig config, GrBuffer* transferBuffer,
jvanverth17aa0472016-01-05 10:41:27 -0800368 size_t offset, size_t rowBytes) override {
369 return false;
370 }
371
mtklein36352bf2015-03-25 18:17:31 -0700372 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
bsalomonf90a02b2014-11-26 12:28:00 -0800373
egdanielec00d942015-09-14 12:56:10 -0700374 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
375 int width,
376 int height) override {
377 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800378 }
379
mtklein36352bf2015-03-25 18:17:31 -0700380 void clearStencil(GrRenderTarget* target) override {}
bsalomon33435572014-11-05 14:47:41 -0800381
jvanverth88957922015-07-14 11:02:52 -0700382 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
egdaniel0a3a7f72016-06-24 09:22:31 -0700383 GrPixelConfig config, bool isRT) override {
cblume61214052016-01-26 09:10:48 -0800384 return 0;
jvanverth88957922015-07-14 11:02:52 -0700385 }
bsalomon67d76202015-11-11 12:40:42 -0800386 bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
bsalomone63ffef2016-02-05 07:17:34 -0800387 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
jvanverth672bb7f2015-07-13 07:19:57 -0700388
bsalomon33435572014-11-05 14:47:41 -0800389 typedef GrGpu INHERITED;
390};
391
392GrContext* GrContext::CreateMockContext() {
halcanary385fe4d2015-08-26 13:07:48 -0700393 GrContext* context = new GrContext;
bsalomon33435572014-11-05 14:47:41 -0800394
395 context->initMockContext();
396 return context;
397}
398
399void GrContext::initMockContext() {
bsalomon682c2692015-05-22 14:01:46 -0700400 GrContextOptions options;
cdalton397536c2016-03-25 12:15:03 -0700401 options.fBufferMapThreshold = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700402 SkASSERT(nullptr == fGpu);
halcanary385fe4d2015-08-26 13:07:48 -0700403 fGpu = new MockGpu(this, options);
bsalomon33435572014-11-05 14:47:41 -0800404 SkASSERT(fGpu);
bsalomon69cfe952015-11-30 13:27:47 -0800405 this->initCommon(options);
bsalomon33435572014-11-05 14:47:41 -0800406
407 // We delete these because we want to test the cache starting with zero resources. Also, none of
408 // these objects are required for any of tests that use this context. TODO: make stop allocating
409 // resources in the buffer pools.
robertphillips77a2e522015-10-17 07:43:27 -0700410 fDrawingManager->abandon();
bsalomon33435572014-11-05 14:47:41 -0800411}