blob: f70aa26e63cb9cc025a4e43f7ec50545345abb2c [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"
Greg Daniel6be35232017-03-01 17:01:09 -050018#include "GrSemaphore.h"
jvanverth0671b962015-12-08 18:53:44 -080019
Brian Osman3b655982017-03-07 16:58:08 -050020#include "SkGr.h"
Robert Phillips22f4a1f2016-12-20 08:57:26 -050021#include "SkImage_Gpu.h"
halcanary4dbbd042016-06-07 17:21:10 -070022#include "SkMathPriv.h"
mtkleinb9eb4ac2015-02-02 18:26:03 -080023#include "SkString.h"
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000024
Brian Salomonf856fd12016-12-16 14:24:34 -050025#include "text/GrAtlasGlyphCache.h"
joshualitte8042922015-12-11 06:11:21 -080026#include "text/GrTextBlobCache.h"
27
joshualitt7f9c9eb2015-08-21 11:08:00 -070028namespace GrTest {
29void SetupAlwaysEvictAtlas(GrContext* context) {
30 // These sizes were selected because they allow each atlas to hold a single plot and will thus
31 // stress the atlas
Brian Salomon2ee084e2016-12-16 18:59:19 -050032 int dim = GrDrawOpAtlas::kGlyphMaxDim;
33 GrDrawOpAtlasConfig configs[3];
joshualitt7f9c9eb2015-08-21 11:08:00 -070034 configs[kA8_GrMaskFormat].fWidth = dim;
35 configs[kA8_GrMaskFormat].fHeight = dim;
jvanverth7023a002016-02-22 11:25:32 -080036 configs[kA8_GrMaskFormat].fLog2Width = SkNextLog2(dim);
37 configs[kA8_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070038 configs[kA8_GrMaskFormat].fPlotWidth = dim;
39 configs[kA8_GrMaskFormat].fPlotHeight = dim;
40
41 configs[kA565_GrMaskFormat].fWidth = dim;
42 configs[kA565_GrMaskFormat].fHeight = dim;
jvanverth7023a002016-02-22 11:25:32 -080043 configs[kA565_GrMaskFormat].fLog2Width = SkNextLog2(dim);
44 configs[kA565_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070045 configs[kA565_GrMaskFormat].fPlotWidth = dim;
46 configs[kA565_GrMaskFormat].fPlotHeight = dim;
47
48 configs[kARGB_GrMaskFormat].fWidth = dim;
49 configs[kARGB_GrMaskFormat].fHeight = dim;
jvanverth7023a002016-02-22 11:25:32 -080050 configs[kARGB_GrMaskFormat].fLog2Width = SkNextLog2(dim);
51 configs[kARGB_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070052 configs[kARGB_GrMaskFormat].fPlotWidth = dim;
53 configs[kARGB_GrMaskFormat].fPlotHeight = dim;
54
55 context->setTextContextAtlasSizes_ForTesting(configs);
56}
57};
58
Robert Phillipseaa86252016-11-08 13:49:39 +000059bool GrSurfaceProxy::isWrapped_ForTesting() const {
60 return SkToBool(fTarget);
61}
62
63bool GrRenderTargetContext::isWrapped_ForTesting() const {
64 return fRenderTargetProxy->isWrapped_ForTesting();
65}
66
joshualitt17d833b2015-08-03 10:17:44 -070067void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) {
68 fTextBlobCache->setBudget(bytes);
69}
70
Brian Salomon2ee084e2016-12-16 18:59:19 -050071void GrContext::setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs) {
Brian Salomonf856fd12016-12-16 14:24:34 -050072 fAtlasGlyphCache->setAtlasSizes_ForTesting(configs);
joshualittda04e0e2015-08-19 08:16:43 -070073}
74
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000075///////////////////////////////////////////////////////////////////////////////
76
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000077void GrContext::purgeAllUnlockedResources() {
bsalomon0ea80f42015-02-11 10:49:59 -080078 fResourceCache->purgeAllUnlocked();
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000079}
bsalomon33435572014-11-05 14:47:41 -080080
joshualitte45c81c2015-12-02 09:05:37 -080081void GrContext::resetGpuStats() const {
82#if GR_GPU_STATS
83 fGpu->stats()->reset();
84#endif
85}
86
mtkleinb9eb4ac2015-02-02 18:26:03 -080087void GrContext::dumpCacheStats(SkString* out) const {
88#if GR_CACHE_STATS
bsalomon0ea80f42015-02-11 10:49:59 -080089 fResourceCache->dumpStats(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -080090#endif
91}
92
joshualittdc5685a2015-12-02 14:08:25 -080093void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
94 SkTArray<double>* values) const {
95#if GR_CACHE_STATS
96 fResourceCache->dumpStatsKeyValuePairs(keys, values);
97#endif
98}
99
mtkleinb9eb4ac2015-02-02 18:26:03 -0800100void GrContext::printCacheStats() const {
101 SkString out;
102 this->dumpCacheStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800103 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800104}
105
106void GrContext::dumpGpuStats(SkString* out) const {
107#if GR_GPU_STATS
108 return fGpu->stats()->dump(out);
109#endif
110}
111
joshualitte45c81c2015-12-02 09:05:37 -0800112void GrContext::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys,
113 SkTArray<double>* values) const {
114#if GR_GPU_STATS
115 return fGpu->stats()->dumpKeyValuePairs(keys, values);
116#endif
117}
118
mtkleinb9eb4ac2015-02-02 18:26:03 -0800119void GrContext::printGpuStats() const {
120 SkString out;
121 this->dumpGpuStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800122 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800123}
124
Robert Phillipsc37e6142017-01-20 10:03:25 -0500125sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format) {
Brian Salomonf856fd12016-12-16 14:24:34 -0500126 GrAtlasGlyphCache* cache = this->getAtlasGlyphCache();
jvanverth629162d2015-11-08 08:07:24 -0800127
Robert Phillips32f28182017-02-28 16:20:03 -0500128 sk_sp<GrTextureProxy> proxy = cache->getProxy(format);
129 if (!proxy) {
130 return nullptr;
131 }
132
Brian Osman32342f02017-03-04 08:12:46 -0500133 GrTexture* tex = proxy->instantiate(this->resourceProvider());
Robert Phillips32f28182017-02-28 16:20:03 -0500134 if (!tex) {
135 return nullptr;
136 }
137
138 // MDB TODO: add proxy-backed SkImage_Gpu's
Robert Phillips22f4a1f2016-12-20 08:57:26 -0500139 sk_sp<SkImage> image(new SkImage_Gpu(tex->width(), tex->height(),
140 kNeedNewImageUniqueID, kPremul_SkAlphaType,
141 sk_ref_sp(tex), nullptr, SkBudgeted::kNo));
142 return image;
jvanverth0671b962015-12-08 18:53:44 -0800143}
jvanverth629162d2015-11-08 08:07:24 -0800144
mtkleinb9eb4ac2015-02-02 18:26:03 -0800145#if GR_GPU_STATS
146void GrGpu::Stats::dump(SkString* out) {
147 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
148 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800149 out->appendf("Textures Created: %d\n", fTextureCreates);
150 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800151 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700152 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700153 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800154}
joshualitte45c81c2015-12-02 09:05:37 -0800155
156void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
157 keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds);
158 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
joshualitte45c81c2015-12-02 09:05:37 -0800159 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800160 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700161 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800162}
163
mtkleinb9eb4ac2015-02-02 18:26:03 -0800164#endif
165
166#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800167void GrResourceCache::getStats(Stats* stats) const {
168 stats->reset();
169
170 stats->fTotal = this->getResourceCount();
171 stats->fNumNonPurgeable = fNonpurgeableResources.count();
172 stats->fNumPurgeable = fPurgeableQueue.count();
173
174 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
175 stats->update(fNonpurgeableResources[i]);
176 }
177 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
178 stats->update(fPurgeableQueue.at(i));
179 }
180}
181
bsalomon0ea80f42015-02-11 10:49:59 -0800182void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800183 this->validate();
184
bsalomonf320e042015-02-17 15:09:34 -0800185 Stats stats;
186
robertphillips60029a52015-11-09 13:51:06 -0800187 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800188
189 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
190 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
191
192 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
193 out->appendf("\t\tEntry Count: current %d"
kkinnunen2e6055b2016-04-22 01:48:29 -0700194 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n",
195 stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable,
196 stats.fScratch, countUtilization, fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800197 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800198 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
199 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800200}
201
joshualittdc5685a2015-12-02 14:08:25 -0800202void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
203 SkTArray<double>* values) const {
204 this->validate();
205
206 Stats stats;
207 this->getStats(&stats);
208
joshualittdc5685a2015-12-02 14:08:25 -0800209 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
joshualittdc5685a2015-12-02 14:08:25 -0800210}
211
mtkleinb9eb4ac2015-02-02 18:26:03 -0800212#endif
213
bsalomonddf30e62015-02-19 11:38:44 -0800214///////////////////////////////////////////////////////////////////////////////
215
216void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800217
Brian Salomon1090da62017-01-06 12:04:19 -0500218#ifdef SK_DEBUG
219int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
220 int count = 0;
221 UniqueHash::ConstIter iter(&fUniqueHash);
222 while (!iter.done()) {
223 if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
224 ++count;
225 }
226 ++iter;
227 }
228 return count;
229}
230#endif
231
bsalomon33435572014-11-05 14:47:41 -0800232///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800233
234#define ASSERT_SINGLE_OWNER \
Brian Osman11052242016-10-27 14:47:55 -0400235 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->fSingleOwner);)
joshualittf5883a62016-01-13 07:47:38 -0800236
Robert Phillipsc0138922017-03-08 11:50:55 -0500237uint32_t GrRenderTargetContextPriv::testingOnly_addDrawOp(GrPaint&& paint,
238 GrAAType aaType,
239 std::unique_ptr<GrDrawOp> op,
240 const GrUserStencilSettings* uss,
241 bool snapToCenters) {
joshualittf5883a62016-01-13 07:47:38 -0800242 ASSERT_SINGLE_OWNER
Robert Phillipsc0138922017-03-08 11:50:55 -0500243 if (fRenderTargetContext->drawingManager()->wasAbandoned()) {
244 return SK_InvalidUniqueID;
245 }
Brian Osman11052242016-10-27 14:47:55 -0400246 SkDEBUGCODE(fRenderTargetContext->validate();)
247 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
Brian Salomon1951f3d2016-12-09 16:07:12 -0500248 "GrRenderTargetContext::testingOnly_addDrawOp");
joshualittf5883a62016-01-13 07:47:38 -0800249
Brian Salomon82f44312017-01-11 13:42:54 -0500250 GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
robertphillips28a838e2016-06-23 14:07:00 -0700251 if (uss) {
252 pipelineBuilder.setUserStencil(uss);
cdalton846c0512016-05-13 10:25:00 -0700253 }
Brian Salomon189098e72017-01-19 09:55:19 -0500254 pipelineBuilder.setSnapVerticesToPixelCenters(snapToCenters);
robertphillips28a838e2016-06-23 14:07:00 -0700255
Robert Phillipsc0138922017-03-08 11:50:55 -0500256 return fRenderTargetContext->addDrawOp(pipelineBuilder, GrNoClip(), std::move(op));
joshualittf5883a62016-01-13 07:47:38 -0800257}
258
259#undef ASSERT_SINGLE_OWNER
joshualittf5883a62016-01-13 07:47:38 -0800260
261///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700262
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400263GrRenderTarget::Flags GrRenderTargetProxy::testingOnly_getFlags() const {
Brian Salomondac5f6b2017-02-28 16:11:04 -0500264 return fRenderTargetFlags;
csmartdaltonf9635992016-08-10 11:09:07 -0700265}
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; }
Brian Salomonf9f45122016-11-29 11:59:17 -0500280 bool canConfigBeImageStorage(GrPixelConfig) const override { return false; }
Brian Salomon467921e2017-03-06 16:17:12 -0500281 bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc) const override {
282 return false;
283 }
Brian Salomonf9f45122016-11-29 11:59:17 -0500284
bsalomon41e4384e2016-01-08 09:12:44 -0800285private:
286 typedef GrCaps INHERITED;
287};
288
bsalomon33435572014-11-05 14:47:41 -0800289class MockGpu : public GrGpu {
290public:
bsalomon682c2692015-05-22 14:01:46 -0700291 MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
bsalomon41e4384e2016-01-08 09:12:44 -0800292 fCaps.reset(new MockCaps(options));
bsalomon682c2692015-05-22 14:01:46 -0700293 }
mtklein36352bf2015-03-25 18:17:31 -0700294 ~MockGpu() override {}
bsalomon33435572014-11-05 14:47:41 -0800295
bsalomonf0674512015-07-28 13:26:15 -0700296 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
297 GrPixelConfig readConfig, DrawPreference*,
298 ReadPixelTempDrawInfo*) override { return false; }
299
cblumeed828002016-02-16 13:00:01 -0800300 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
bsalomonf0674512015-07-28 13:26:15 -0700301 GrPixelConfig srcConfig, DrawPreference*,
302 WritePixelTempDrawInfo*) override { return false; }
bsalomon39826022015-07-23 08:07:21 -0700303
joshualitt1cbdcde2015-08-21 11:53:29 -0700304 bool onCopySurface(GrSurface* dst,
305 GrSurface* src,
306 const SkIRect& srcRect,
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400307 const SkIPoint& dstPoint) override { return false; }
bsalomonf90a02b2014-11-26 12:28:00 -0800308
csmartdaltonc25c5d72016-11-01 07:03:59 -0700309 void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&,
310 int* effectiveSampleCnt, SamplePattern*) override {
cdalton28f45b92016-03-07 13:58:26 -0800311 *effectiveSampleCnt = rt->desc().fSampleCnt;
312 }
313
Brian Salomonc293a292016-11-30 13:38:32 -0500314 GrGpuCommandBuffer* createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&,
egdaniel9cb63402016-06-23 08:37:05 -0700315 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
Greg Daniel6be35232017-03-01 17:01:09 -0500321 GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
322 bool waitFence(GrFence, uint64_t) override { return true; }
jvanverth84741b32016-09-30 08:39:02 -0700323 void deleteFence(GrFence) const override {}
Brian Osman2c2bc112017-02-28 10:02:49 -0500324 void flush() override {}
jvanverth84741b32016-09-30 08:39:02 -0700325
Greg Daniel6be35232017-03-01 17:01:09 -0500326 sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore() override { return nullptr; }
327 void insertSemaphore(sk_sp<GrSemaphore> semaphore) override {}
328 void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {}
329
bsalomon33435572014-11-05 14:47:41 -0800330private:
mtklein36352bf2015-03-25 18:17:31 -0700331 void onResetContext(uint32_t resetBits) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800332
bsalomoncb02b382015-08-12 11:14:50 -0700333 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
334
kkinnunen2e6055b2016-04-22 01:48:29 -0700335 GrTexture* onCreateTexture(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
kkinnunen2e6055b2016-04-22 01:48:29 -0700340 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800341 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700342 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800343 }
344
bungeman6bd52842016-10-27 09:30:08 -0700345 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700346 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800347 }
348
bungeman6bd52842016-10-27 09:30:08 -0700349 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
350 GrWrapOwnership) override {
351 return nullptr;
352 }
353
354 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override {
ericrkf7b8b8a2016-02-24 14:49:51 -0800355 return nullptr;
356 }
357
cdalton1bf3e712016-04-19 10:00:02 -0700358 GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
359 return nullptr;
360 }
jvanverth73063dc2015-12-03 09:15:47 -0800361
csmartdaltone0d36292016-07-29 08:14:20 -0700362 gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
363
bsalomon6cb3cbe2015-07-30 07:34:27 -0700364 bool onReadPixels(GrSurface* surface,
bsalomonf90a02b2014-11-26 12:28:00 -0800365 int left, int top, int width, int height,
366 GrPixelConfig,
367 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700368 size_t rowBytes) override {
bsalomonf90a02b2014-11-26 12:28:00 -0800369 return false;
bsalomon33435572014-11-05 14:47:41 -0800370 }
371
bsalomon6cb3cbe2015-07-30 07:34:27 -0700372 bool onWritePixels(GrSurface* surface,
373 int left, int top, int width, int height,
cblume55f2d2d2016-02-26 13:20:48 -0800374 GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override {
bsalomon33435572014-11-05 14:47:41 -0800375 return false;
376 }
377
jvanverthc3d706f2016-04-20 10:33:27 -0700378 bool onTransferPixels(GrSurface* surface,
jvanverth17aa0472016-01-05 10:41:27 -0800379 int left, int top, int width, int height,
cdalton397536c2016-03-25 12:15:03 -0700380 GrPixelConfig config, GrBuffer* transferBuffer,
jvanverth17aa0472016-01-05 10:41:27 -0800381 size_t offset, size_t rowBytes) override {
382 return false;
383 }
384
mtklein36352bf2015-03-25 18:17:31 -0700385 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
bsalomonf90a02b2014-11-26 12:28:00 -0800386
egdanielec00d942015-09-14 12:56:10 -0700387 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
388 int width,
389 int height) override {
390 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800391 }
392
mtklein36352bf2015-03-25 18:17:31 -0700393 void clearStencil(GrRenderTarget* target) override {}
bsalomon33435572014-11-05 14:47:41 -0800394
jvanverth88957922015-07-14 11:02:52 -0700395 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
egdaniel0a3a7f72016-06-24 09:22:31 -0700396 GrPixelConfig config, bool isRT) override {
cblume61214052016-01-26 09:10:48 -0800397 return 0;
jvanverth88957922015-07-14 11:02:52 -0700398 }
bsalomon67d76202015-11-11 12:40:42 -0800399 bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
bsalomone63ffef2016-02-05 07:17:34 -0800400 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
jvanverth672bb7f2015-07-13 07:19:57 -0700401
bsalomon33435572014-11-05 14:47:41 -0800402 typedef GrGpu INHERITED;
403};
404
405GrContext* GrContext::CreateMockContext() {
halcanary385fe4d2015-08-26 13:07:48 -0700406 GrContext* context = new GrContext;
bsalomon33435572014-11-05 14:47:41 -0800407
408 context->initMockContext();
409 return context;
410}
411
412void GrContext::initMockContext() {
bsalomon682c2692015-05-22 14:01:46 -0700413 GrContextOptions options;
cdalton397536c2016-03-25 12:15:03 -0700414 options.fBufferMapThreshold = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700415 SkASSERT(nullptr == fGpu);
halcanary385fe4d2015-08-26 13:07:48 -0700416 fGpu = new MockGpu(this, options);
bsalomon33435572014-11-05 14:47:41 -0800417 SkASSERT(fGpu);
bsalomon69cfe952015-11-30 13:27:47 -0800418 this->initCommon(options);
bsalomon33435572014-11-05 14:47:41 -0800419
420 // We delete these because we want to test the cache starting with zero resources. Also, none of
421 // these objects are required for any of tests that use this context. TODO: make stop allocating
422 // resources in the buffer pools.
robertphillips77a2e522015-10-17 07:43:27 -0700423 fDrawingManager->abandon();
bsalomon33435572014-11-05 14:47:41 -0800424}