blob: 15faffadac402f4db4df34159cef1b7bad01dd56 [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
Robert Phillipsb726d582017-03-09 16:36:32 -0500133 SkASSERT(proxy->priv().isExact());
134 sk_sp<SkImage> image(new SkImage_Gpu(this, kNeedNewImageUniqueID, kPremul_SkAlphaType,
135 std::move(proxy), nullptr, SkBudgeted::kNo));
Robert Phillips22f4a1f2016-12-20 08:57:26 -0500136 return image;
jvanverth0671b962015-12-08 18:53:44 -0800137}
jvanverth629162d2015-11-08 08:07:24 -0800138
mtkleinb9eb4ac2015-02-02 18:26:03 -0800139#if GR_GPU_STATS
140void GrGpu::Stats::dump(SkString* out) {
141 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
142 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800143 out->appendf("Textures Created: %d\n", fTextureCreates);
144 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800145 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700146 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700147 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800148}
joshualitte45c81c2015-12-02 09:05:37 -0800149
150void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
151 keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds);
152 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
joshualitte45c81c2015-12-02 09:05:37 -0800153 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800154 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700155 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800156}
157
mtkleinb9eb4ac2015-02-02 18:26:03 -0800158#endif
159
160#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800161void GrResourceCache::getStats(Stats* stats) const {
162 stats->reset();
163
164 stats->fTotal = this->getResourceCount();
165 stats->fNumNonPurgeable = fNonpurgeableResources.count();
166 stats->fNumPurgeable = fPurgeableQueue.count();
167
168 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
169 stats->update(fNonpurgeableResources[i]);
170 }
171 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
172 stats->update(fPurgeableQueue.at(i));
173 }
174}
175
bsalomon0ea80f42015-02-11 10:49:59 -0800176void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800177 this->validate();
178
bsalomonf320e042015-02-17 15:09:34 -0800179 Stats stats;
180
robertphillips60029a52015-11-09 13:51:06 -0800181 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800182
183 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
184 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
185
186 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
187 out->appendf("\t\tEntry Count: current %d"
kkinnunen2e6055b2016-04-22 01:48:29 -0700188 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n",
189 stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable,
190 stats.fScratch, countUtilization, fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800191 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800192 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
193 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800194}
195
joshualittdc5685a2015-12-02 14:08:25 -0800196void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
197 SkTArray<double>* values) const {
198 this->validate();
199
200 Stats stats;
201 this->getStats(&stats);
202
joshualittdc5685a2015-12-02 14:08:25 -0800203 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
joshualittdc5685a2015-12-02 14:08:25 -0800204}
205
mtkleinb9eb4ac2015-02-02 18:26:03 -0800206#endif
207
bsalomonddf30e62015-02-19 11:38:44 -0800208///////////////////////////////////////////////////////////////////////////////
209
210void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800211
Brian Salomon1090da62017-01-06 12:04:19 -0500212#ifdef SK_DEBUG
213int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
214 int count = 0;
215 UniqueHash::ConstIter iter(&fUniqueHash);
216 while (!iter.done()) {
217 if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
218 ++count;
219 }
220 ++iter;
221 }
222 return count;
223}
224#endif
225
bsalomon33435572014-11-05 14:47:41 -0800226///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800227
228#define ASSERT_SINGLE_OWNER \
Brian Osman11052242016-10-27 14:47:55 -0400229 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->fSingleOwner);)
joshualittf5883a62016-01-13 07:47:38 -0800230
Brian Salomon649a3412017-03-09 13:50:43 -0500231uint32_t GrRenderTargetContextPriv::testingOnly_addMeshDrawOp(GrPaint&& paint,
232 GrAAType aaType,
233 std::unique_ptr<GrMeshDrawOp> op,
234 const GrUserStencilSettings* uss,
235 bool snapToCenters) {
joshualittf5883a62016-01-13 07:47:38 -0800236 ASSERT_SINGLE_OWNER
Robert Phillipsc0138922017-03-08 11:50:55 -0500237 if (fRenderTargetContext->drawingManager()->wasAbandoned()) {
238 return SK_InvalidUniqueID;
239 }
Brian Osman11052242016-10-27 14:47:55 -0400240 SkDEBUGCODE(fRenderTargetContext->validate();)
241 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
Brian Salomon649a3412017-03-09 13:50:43 -0500242 "GrRenderTargetContext::testingOnly_addMeshDrawOp");
joshualittf5883a62016-01-13 07:47:38 -0800243
Brian Salomon82f44312017-01-11 13:42:54 -0500244 GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
robertphillips28a838e2016-06-23 14:07:00 -0700245 if (uss) {
246 pipelineBuilder.setUserStencil(uss);
cdalton846c0512016-05-13 10:25:00 -0700247 }
Brian Salomon189098e72017-01-19 09:55:19 -0500248 pipelineBuilder.setSnapVerticesToPixelCenters(snapToCenters);
robertphillips28a838e2016-06-23 14:07:00 -0700249
Brian Salomon649a3412017-03-09 13:50:43 -0500250 return fRenderTargetContext->addMeshDrawOp(pipelineBuilder, GrNoClip(), std::move(op));
joshualittf5883a62016-01-13 07:47:38 -0800251}
252
253#undef ASSERT_SINGLE_OWNER
joshualittf5883a62016-01-13 07:47:38 -0800254
255///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700256
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400257GrRenderTarget::Flags GrRenderTargetProxy::testingOnly_getFlags() const {
Brian Salomondac5f6b2017-02-28 16:11:04 -0500258 return fRenderTargetFlags;
csmartdaltonf9635992016-08-10 11:09:07 -0700259}
260
261///////////////////////////////////////////////////////////////////////////////
bsalomon33435572014-11-05 14:47:41 -0800262// Code for the mock context. It's built on a mock GrGpu class that does nothing.
263////
264
bsalomon33435572014-11-05 14:47:41 -0800265#include "GrGpu.h"
266
egdaniel8dd688b2015-01-22 10:16:09 -0800267class GrPipeline;
joshualittd53a8272014-11-10 16:03:14 -0800268
bsalomon41e4384e2016-01-08 09:12:44 -0800269class MockCaps : public GrCaps {
270public:
271 explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {}
272 bool isConfigTexturable(GrPixelConfig config) const override { return false; }
273 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; }
Brian Salomonf9f45122016-11-29 11:59:17 -0500274 bool canConfigBeImageStorage(GrPixelConfig) const override { return false; }
Brian Salomon467921e2017-03-06 16:17:12 -0500275 bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc) const override {
276 return false;
277 }
Brian Salomonf9f45122016-11-29 11:59:17 -0500278
bsalomon41e4384e2016-01-08 09:12:44 -0800279private:
280 typedef GrCaps INHERITED;
281};
282
bsalomon33435572014-11-05 14:47:41 -0800283class MockGpu : public GrGpu {
284public:
bsalomon682c2692015-05-22 14:01:46 -0700285 MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
bsalomon41e4384e2016-01-08 09:12:44 -0800286 fCaps.reset(new MockCaps(options));
bsalomon682c2692015-05-22 14:01:46 -0700287 }
mtklein36352bf2015-03-25 18:17:31 -0700288 ~MockGpu() override {}
bsalomon33435572014-11-05 14:47:41 -0800289
bsalomonf0674512015-07-28 13:26:15 -0700290 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
291 GrPixelConfig readConfig, DrawPreference*,
292 ReadPixelTempDrawInfo*) override { return false; }
293
cblumeed828002016-02-16 13:00:01 -0800294 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
bsalomonf0674512015-07-28 13:26:15 -0700295 GrPixelConfig srcConfig, DrawPreference*,
296 WritePixelTempDrawInfo*) override { return false; }
bsalomon39826022015-07-23 08:07:21 -0700297
joshualitt1cbdcde2015-08-21 11:53:29 -0700298 bool onCopySurface(GrSurface* dst,
299 GrSurface* src,
300 const SkIRect& srcRect,
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400301 const SkIPoint& dstPoint) override { return false; }
bsalomonf90a02b2014-11-26 12:28:00 -0800302
csmartdaltonc25c5d72016-11-01 07:03:59 -0700303 void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&,
304 int* effectiveSampleCnt, SamplePattern*) override {
cdalton28f45b92016-03-07 13:58:26 -0800305 *effectiveSampleCnt = rt->desc().fSampleCnt;
306 }
307
Brian Salomonc293a292016-11-30 13:38:32 -0500308 GrGpuCommandBuffer* createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&,
egdaniel9cb63402016-06-23 08:37:05 -0700309 const GrGpuCommandBuffer::LoadAndStoreInfo&) override {
egdaniel066df7c2016-06-08 14:02:27 -0700310 return nullptr;
311 }
312
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400313 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {}
bsalomon6dea83f2015-12-03 12:58:06 -0800314
Greg Daniel6be35232017-03-01 17:01:09 -0500315 GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
316 bool waitFence(GrFence, uint64_t) override { return true; }
jvanverth84741b32016-09-30 08:39:02 -0700317 void deleteFence(GrFence) const override {}
Brian Osman2c2bc112017-02-28 10:02:49 -0500318 void flush() override {}
jvanverth84741b32016-09-30 08:39:02 -0700319
Greg Daniel6be35232017-03-01 17:01:09 -0500320 sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore() override { return nullptr; }
321 void insertSemaphore(sk_sp<GrSemaphore> semaphore) override {}
322 void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {}
323
bsalomon33435572014-11-05 14:47:41 -0800324private:
mtklein36352bf2015-03-25 18:17:31 -0700325 void onResetContext(uint32_t resetBits) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800326
bsalomoncb02b382015-08-12 11:14:50 -0700327 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
328
kkinnunen2e6055b2016-04-22 01:48:29 -0700329 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800330 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700331 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800332 }
333
kkinnunen2e6055b2016-04-22 01:48:29 -0700334 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800335 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700336 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800337 }
338
bungeman6bd52842016-10-27 09:30:08 -0700339 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700340 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800341 }
342
bungeman6bd52842016-10-27 09:30:08 -0700343 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
344 GrWrapOwnership) override {
345 return nullptr;
346 }
347
348 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override {
ericrkf7b8b8a2016-02-24 14:49:51 -0800349 return nullptr;
350 }
351
cdalton1bf3e712016-04-19 10:00:02 -0700352 GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
353 return nullptr;
354 }
jvanverth73063dc2015-12-03 09:15:47 -0800355
csmartdaltone0d36292016-07-29 08:14:20 -0700356 gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
357
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
jvanverthc3d706f2016-04-20 10:33:27 -0700372 bool onTransferPixels(GrSurface* surface,
jvanverth17aa0472016-01-05 10:41:27 -0800373 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,
egdaniel0a3a7f72016-06-24 09:22:31 -0700390 GrPixelConfig config, bool isRT) 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}