blob: 2e34d2ff5bd75e5a04b7c0f1e15502574894391f [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
Greg Daniel7ef28f32017-04-20 16:41:55 +000010#include "GrBackendSurface.h"
bsalomon682c2692015-05-22 14:01:46 -070011#include "GrContextOptions.h"
Brian Salomon2ee084e2016-12-16 18:59:19 -050012#include "GrDrawOpAtlas.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"
Brian Salomon2ee084e2016-12-16 18:59:19 -050016#include "GrRenderTargetContextPriv.h"
csmartdaltonf9635992016-08-10 11:09:07 -070017#include "GrRenderTargetProxy.h"
bsalomon0ea80f42015-02-11 10:49:59 -080018#include "GrResourceCache.h"
Greg Daniel6be35232017-03-01 17:01:09 -050019#include "GrSemaphore.h"
jvanverth0671b962015-12-08 18:53:44 -080020
Brian Osman3b655982017-03-07 16:58:08 -050021#include "SkGr.h"
Robert Phillips22f4a1f2016-12-20 08:57:26 -050022#include "SkImage_Gpu.h"
halcanary4dbbd042016-06-07 17:21:10 -070023#include "SkMathPriv.h"
mtkleinb9eb4ac2015-02-02 18:26:03 -080024#include "SkString.h"
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000025
Brian Salomonf856fd12016-12-16 14:24:34 -050026#include "text/GrAtlasGlyphCache.h"
joshualitte8042922015-12-11 06:11:21 -080027#include "text/GrTextBlobCache.h"
28
joshualitt7f9c9eb2015-08-21 11:08:00 -070029namespace GrTest {
30void SetupAlwaysEvictAtlas(GrContext* context) {
31 // These sizes were selected because they allow each atlas to hold a single plot and will thus
32 // stress the atlas
Brian Salomon2ee084e2016-12-16 18:59:19 -050033 int dim = GrDrawOpAtlas::kGlyphMaxDim;
34 GrDrawOpAtlasConfig configs[3];
joshualitt7f9c9eb2015-08-21 11:08:00 -070035 configs[kA8_GrMaskFormat].fWidth = dim;
36 configs[kA8_GrMaskFormat].fHeight = dim;
jvanverth7023a002016-02-22 11:25:32 -080037 configs[kA8_GrMaskFormat].fLog2Width = SkNextLog2(dim);
38 configs[kA8_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070039 configs[kA8_GrMaskFormat].fPlotWidth = dim;
40 configs[kA8_GrMaskFormat].fPlotHeight = dim;
41
42 configs[kA565_GrMaskFormat].fWidth = dim;
43 configs[kA565_GrMaskFormat].fHeight = dim;
jvanverth7023a002016-02-22 11:25:32 -080044 configs[kA565_GrMaskFormat].fLog2Width = SkNextLog2(dim);
45 configs[kA565_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070046 configs[kA565_GrMaskFormat].fPlotWidth = dim;
47 configs[kA565_GrMaskFormat].fPlotHeight = dim;
48
49 configs[kARGB_GrMaskFormat].fWidth = dim;
50 configs[kARGB_GrMaskFormat].fHeight = dim;
jvanverth7023a002016-02-22 11:25:32 -080051 configs[kARGB_GrMaskFormat].fLog2Width = SkNextLog2(dim);
52 configs[kARGB_GrMaskFormat].fLog2Height = SkNextLog2(dim);
joshualitt7f9c9eb2015-08-21 11:08:00 -070053 configs[kARGB_GrMaskFormat].fPlotWidth = dim;
54 configs[kARGB_GrMaskFormat].fPlotHeight = dim;
55
56 context->setTextContextAtlasSizes_ForTesting(configs);
57}
Greg Daniel7ef28f32017-04-20 16:41:55 +000058
59GrBackendTexture CreateBackendTexture(GrBackend backend, int width, int height,
60 GrPixelConfig config, GrBackendObject handle) {
61 if (kOpenGL_GrBackend == backend) {
62 GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle);
63 return GrBackendTexture(width, height, config, glInfo);
64 } else {
65 SkASSERT(kVulkan_GrBackend == backend);
66 GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle);
67 return GrBackendTexture(width, height, vkInfo);
68 }
69}
joshualitt7f9c9eb2015-08-21 11:08:00 -070070};
71
Robert Phillipseaa86252016-11-08 13:49:39 +000072bool GrSurfaceProxy::isWrapped_ForTesting() const {
73 return SkToBool(fTarget);
74}
75
76bool GrRenderTargetContext::isWrapped_ForTesting() const {
77 return fRenderTargetProxy->isWrapped_ForTesting();
78}
79
joshualitt17d833b2015-08-03 10:17:44 -070080void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) {
81 fTextBlobCache->setBudget(bytes);
82}
83
Brian Salomon2ee084e2016-12-16 18:59:19 -050084void GrContext::setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs) {
Brian Salomonf856fd12016-12-16 14:24:34 -050085 fAtlasGlyphCache->setAtlasSizes_ForTesting(configs);
joshualittda04e0e2015-08-19 08:16:43 -070086}
87
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000088///////////////////////////////////////////////////////////////////////////////
89
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000090void GrContext::purgeAllUnlockedResources() {
bsalomon0ea80f42015-02-11 10:49:59 -080091 fResourceCache->purgeAllUnlocked();
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000092}
bsalomon33435572014-11-05 14:47:41 -080093
joshualitte45c81c2015-12-02 09:05:37 -080094void GrContext::resetGpuStats() const {
95#if GR_GPU_STATS
96 fGpu->stats()->reset();
97#endif
98}
99
mtkleinb9eb4ac2015-02-02 18:26:03 -0800100void GrContext::dumpCacheStats(SkString* out) const {
101#if GR_CACHE_STATS
bsalomon0ea80f42015-02-11 10:49:59 -0800102 fResourceCache->dumpStats(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800103#endif
104}
105
joshualittdc5685a2015-12-02 14:08:25 -0800106void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
107 SkTArray<double>* values) const {
108#if GR_CACHE_STATS
109 fResourceCache->dumpStatsKeyValuePairs(keys, values);
110#endif
111}
112
mtkleinb9eb4ac2015-02-02 18:26:03 -0800113void GrContext::printCacheStats() const {
114 SkString out;
115 this->dumpCacheStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800116 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800117}
118
119void GrContext::dumpGpuStats(SkString* out) const {
120#if GR_GPU_STATS
121 return fGpu->stats()->dump(out);
122#endif
123}
124
joshualitte45c81c2015-12-02 09:05:37 -0800125void GrContext::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys,
126 SkTArray<double>* values) const {
127#if GR_GPU_STATS
128 return fGpu->stats()->dumpKeyValuePairs(keys, values);
129#endif
130}
131
mtkleinb9eb4ac2015-02-02 18:26:03 -0800132void GrContext::printGpuStats() const {
133 SkString out;
134 this->dumpGpuStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800135 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800136}
137
Robert Phillipsc37e6142017-01-20 10:03:25 -0500138sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format) {
Brian Salomonf856fd12016-12-16 14:24:34 -0500139 GrAtlasGlyphCache* cache = this->getAtlasGlyphCache();
jvanverth629162d2015-11-08 08:07:24 -0800140
Robert Phillips32f28182017-02-28 16:20:03 -0500141 sk_sp<GrTextureProxy> proxy = cache->getProxy(format);
142 if (!proxy) {
143 return nullptr;
144 }
145
Robert Phillipsb726d582017-03-09 16:36:32 -0500146 SkASSERT(proxy->priv().isExact());
147 sk_sp<SkImage> image(new SkImage_Gpu(this, kNeedNewImageUniqueID, kPremul_SkAlphaType,
148 std::move(proxy), nullptr, SkBudgeted::kNo));
Robert Phillips22f4a1f2016-12-20 08:57:26 -0500149 return image;
jvanverth0671b962015-12-08 18:53:44 -0800150}
jvanverth629162d2015-11-08 08:07:24 -0800151
mtkleinb9eb4ac2015-02-02 18:26:03 -0800152#if GR_GPU_STATS
153void GrGpu::Stats::dump(SkString* out) {
154 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
155 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800156 out->appendf("Textures Created: %d\n", fTextureCreates);
157 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800158 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700159 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700160 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800161}
joshualitte45c81c2015-12-02 09:05:37 -0800162
163void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
164 keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds);
165 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
joshualitte45c81c2015-12-02 09:05:37 -0800166 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800167 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700168 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800169}
170
mtkleinb9eb4ac2015-02-02 18:26:03 -0800171#endif
172
173#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800174void GrResourceCache::getStats(Stats* stats) const {
175 stats->reset();
176
177 stats->fTotal = this->getResourceCount();
178 stats->fNumNonPurgeable = fNonpurgeableResources.count();
179 stats->fNumPurgeable = fPurgeableQueue.count();
180
181 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
182 stats->update(fNonpurgeableResources[i]);
183 }
184 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
185 stats->update(fPurgeableQueue.at(i));
186 }
187}
188
bsalomon0ea80f42015-02-11 10:49:59 -0800189void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800190 this->validate();
191
bsalomonf320e042015-02-17 15:09:34 -0800192 Stats stats;
193
robertphillips60029a52015-11-09 13:51:06 -0800194 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800195
196 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
197 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
198
199 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
200 out->appendf("\t\tEntry Count: current %d"
kkinnunen2e6055b2016-04-22 01:48:29 -0700201 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n",
202 stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable,
203 stats.fScratch, countUtilization, fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800204 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800205 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
206 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800207}
208
joshualittdc5685a2015-12-02 14:08:25 -0800209void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
210 SkTArray<double>* values) const {
211 this->validate();
212
213 Stats stats;
214 this->getStats(&stats);
215
joshualittdc5685a2015-12-02 14:08:25 -0800216 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
joshualittdc5685a2015-12-02 14:08:25 -0800217}
218
mtkleinb9eb4ac2015-02-02 18:26:03 -0800219#endif
220
bsalomonddf30e62015-02-19 11:38:44 -0800221///////////////////////////////////////////////////////////////////////////////
222
223void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800224
Brian Salomon1090da62017-01-06 12:04:19 -0500225#ifdef SK_DEBUG
226int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
227 int count = 0;
228 UniqueHash::ConstIter iter(&fUniqueHash);
229 while (!iter.done()) {
230 if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
231 ++count;
232 }
233 ++iter;
234 }
235 return count;
236}
237#endif
238
bsalomon33435572014-11-05 14:47:41 -0800239///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800240
241#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -0400242 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());)
joshualittf5883a62016-01-13 07:47:38 -0800243
Brian Salomond3ccb0a2017-04-03 10:38:00 -0400244uint32_t GrRenderTargetContextPriv::testingOnly_addLegacyMeshDrawOp(
245 GrPaint&& paint,
246 GrAAType aaType,
247 std::unique_ptr<GrLegacyMeshDrawOp> op,
248 const GrUserStencilSettings* uss,
249 bool snapToCenters) {
joshualittf5883a62016-01-13 07:47:38 -0800250 ASSERT_SINGLE_OWNER
Robert Phillipsc0138922017-03-08 11:50:55 -0500251 if (fRenderTargetContext->drawingManager()->wasAbandoned()) {
252 return SK_InvalidUniqueID;
253 }
Brian Salomond3ccb0a2017-04-03 10:38:00 -0400254 SkDEBUGCODE(fRenderTargetContext->validate();) GR_AUDIT_TRAIL_AUTO_FRAME(
255 fRenderTargetContext->fAuditTrail, "GrRenderTargetContext::testingOnly_addMeshDrawOp");
joshualittf5883a62016-01-13 07:47:38 -0800256
Brian Salomon82f44312017-01-11 13:42:54 -0500257 GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
robertphillips28a838e2016-06-23 14:07:00 -0700258 if (uss) {
259 pipelineBuilder.setUserStencil(uss);
cdalton846c0512016-05-13 10:25:00 -0700260 }
Brian Salomon189098e72017-01-19 09:55:19 -0500261 pipelineBuilder.setSnapVerticesToPixelCenters(snapToCenters);
robertphillips28a838e2016-06-23 14:07:00 -0700262
Brian Salomone14bd802017-04-04 15:13:25 -0400263 return fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), GrNoClip(),
264 std::move(op));
joshualittf5883a62016-01-13 07:47:38 -0800265}
266
267#undef ASSERT_SINGLE_OWNER
joshualittf5883a62016-01-13 07:47:38 -0800268
269///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700270
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400271GrRenderTarget::Flags GrRenderTargetProxy::testingOnly_getFlags() const {
Brian Salomondac5f6b2017-02-28 16:11:04 -0500272 return fRenderTargetFlags;
csmartdaltonf9635992016-08-10 11:09:07 -0700273}
274
275///////////////////////////////////////////////////////////////////////////////
bsalomon33435572014-11-05 14:47:41 -0800276// Code for the mock context. It's built on a mock GrGpu class that does nothing.
277////
278
bsalomon33435572014-11-05 14:47:41 -0800279#include "GrGpu.h"
280
egdaniel8dd688b2015-01-22 10:16:09 -0800281class GrPipeline;
joshualittd53a8272014-11-10 16:03:14 -0800282
bsalomon41e4384e2016-01-08 09:12:44 -0800283class MockCaps : public GrCaps {
284public:
285 explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {}
286 bool isConfigTexturable(GrPixelConfig config) const override { return false; }
287 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; }
Brian Salomonf9f45122016-11-29 11:59:17 -0500288 bool canConfigBeImageStorage(GrPixelConfig) const override { return false; }
Robert Phillipsbf25d432017-04-07 10:08:53 -0400289 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
290 bool* rectsMustMatch, bool* disallowSubrect) const override {
Brian Salomon467921e2017-03-06 16:17:12 -0500291 return false;
292 }
Brian Salomonf9f45122016-11-29 11:59:17 -0500293
bsalomon41e4384e2016-01-08 09:12:44 -0800294private:
295 typedef GrCaps INHERITED;
296};
297
bsalomon33435572014-11-05 14:47:41 -0800298class MockGpu : public GrGpu {
299public:
bsalomon682c2692015-05-22 14:01:46 -0700300 MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
bsalomon41e4384e2016-01-08 09:12:44 -0800301 fCaps.reset(new MockCaps(options));
bsalomon682c2692015-05-22 14:01:46 -0700302 }
mtklein36352bf2015-03-25 18:17:31 -0700303 ~MockGpu() override {}
bsalomon33435572014-11-05 14:47:41 -0800304
bsalomonf0674512015-07-28 13:26:15 -0700305 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
306 GrPixelConfig readConfig, DrawPreference*,
307 ReadPixelTempDrawInfo*) override { return false; }
308
cblumeed828002016-02-16 13:00:01 -0800309 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
bsalomonf0674512015-07-28 13:26:15 -0700310 GrPixelConfig srcConfig, DrawPreference*,
311 WritePixelTempDrawInfo*) override { return false; }
bsalomon39826022015-07-23 08:07:21 -0700312
joshualitt1cbdcde2015-08-21 11:53:29 -0700313 bool onCopySurface(GrSurface* dst,
314 GrSurface* src,
315 const SkIRect& srcRect,
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400316 const SkIPoint& dstPoint) override { return false; }
bsalomonf90a02b2014-11-26 12:28:00 -0800317
csmartdaltonc25c5d72016-11-01 07:03:59 -0700318 void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&,
319 int* effectiveSampleCnt, SamplePattern*) override {
cdalton28f45b92016-03-07 13:58:26 -0800320 *effectiveSampleCnt = rt->desc().fSampleCnt;
321 }
322
Brian Salomonc293a292016-11-30 13:38:32 -0500323 GrGpuCommandBuffer* createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&,
egdaniel9cb63402016-06-23 08:37:05 -0700324 const GrGpuCommandBuffer::LoadAndStoreInfo&) override {
egdaniel066df7c2016-06-08 14:02:27 -0700325 return nullptr;
326 }
327
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400328 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {}
bsalomon6dea83f2015-12-03 12:58:06 -0800329
Greg Daniel6be35232017-03-01 17:01:09 -0500330 GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
331 bool waitFence(GrFence, uint64_t) override { return true; }
jvanverth84741b32016-09-30 08:39:02 -0700332 void deleteFence(GrFence) const override {}
Brian Osman2c2bc112017-02-28 10:02:49 -0500333 void flush() override {}
jvanverth84741b32016-09-30 08:39:02 -0700334
Greg Daniel6be35232017-03-01 17:01:09 -0500335 sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore() override { return nullptr; }
336 void insertSemaphore(sk_sp<GrSemaphore> semaphore) override {}
337 void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {}
338
bsalomon33435572014-11-05 14:47:41 -0800339private:
mtklein36352bf2015-03-25 18:17:31 -0700340 void onResetContext(uint32_t resetBits) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800341
bsalomoncb02b382015-08-12 11:14:50 -0700342 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
343
kkinnunen2e6055b2016-04-22 01:48:29 -0700344 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800345 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700346 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800347 }
348
kkinnunen2e6055b2016-04-22 01:48:29 -0700349 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800350 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700351 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800352 }
353
Greg Daniel7ef28f32017-04-20 16:41:55 +0000354 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
355 GrSurfaceOrigin,
356 GrBackendTextureFlags,
357 int sampleCnt,
358 GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700359 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800360 }
361
Brian Osman0b791f52017-03-10 08:30:22 -0500362 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override {
bungeman6bd52842016-10-27 09:30:08 -0700363 return nullptr;
364 }
365
Greg Daniel7ef28f32017-04-20 16:41:55 +0000366 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
367 GrSurfaceOrigin,
368 int sampleCnt) override {
ericrkf7b8b8a2016-02-24 14:49:51 -0800369 return nullptr;
370 }
371
cdalton1bf3e712016-04-19 10:00:02 -0700372 GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
373 return nullptr;
374 }
jvanverth73063dc2015-12-03 09:15:47 -0800375
csmartdaltone0d36292016-07-29 08:14:20 -0700376 gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
377
bsalomon6cb3cbe2015-07-30 07:34:27 -0700378 bool onReadPixels(GrSurface* surface,
bsalomonf90a02b2014-11-26 12:28:00 -0800379 int left, int top, int width, int height,
380 GrPixelConfig,
381 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700382 size_t rowBytes) override {
bsalomonf90a02b2014-11-26 12:28:00 -0800383 return false;
bsalomon33435572014-11-05 14:47:41 -0800384 }
385
bsalomon6cb3cbe2015-07-30 07:34:27 -0700386 bool onWritePixels(GrSurface* surface,
387 int left, int top, int width, int height,
cblume55f2d2d2016-02-26 13:20:48 -0800388 GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override {
bsalomon33435572014-11-05 14:47:41 -0800389 return false;
390 }
391
jvanverthc3d706f2016-04-20 10:33:27 -0700392 bool onTransferPixels(GrSurface* surface,
jvanverth17aa0472016-01-05 10:41:27 -0800393 int left, int top, int width, int height,
cdalton397536c2016-03-25 12:15:03 -0700394 GrPixelConfig config, GrBuffer* transferBuffer,
jvanverth17aa0472016-01-05 10:41:27 -0800395 size_t offset, size_t rowBytes) override {
396 return false;
397 }
398
mtklein36352bf2015-03-25 18:17:31 -0700399 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
bsalomonf90a02b2014-11-26 12:28:00 -0800400
egdanielec00d942015-09-14 12:56:10 -0700401 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
402 int width,
403 int height) override {
404 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800405 }
406
mtklein36352bf2015-03-25 18:17:31 -0700407 void clearStencil(GrRenderTarget* target) override {}
bsalomon33435572014-11-05 14:47:41 -0800408
jvanverth88957922015-07-14 11:02:52 -0700409 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
egdaniel0a3a7f72016-06-24 09:22:31 -0700410 GrPixelConfig config, bool isRT) override {
cblume61214052016-01-26 09:10:48 -0800411 return 0;
jvanverth88957922015-07-14 11:02:52 -0700412 }
bsalomon67d76202015-11-11 12:40:42 -0800413 bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
bsalomone63ffef2016-02-05 07:17:34 -0800414 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
jvanverth672bb7f2015-07-13 07:19:57 -0700415
bsalomon33435572014-11-05 14:47:41 -0800416 typedef GrGpu INHERITED;
417};
418
419GrContext* GrContext::CreateMockContext() {
halcanary385fe4d2015-08-26 13:07:48 -0700420 GrContext* context = new GrContext;
bsalomon33435572014-11-05 14:47:41 -0800421
422 context->initMockContext();
423 return context;
424}
425
426void GrContext::initMockContext() {
bsalomon682c2692015-05-22 14:01:46 -0700427 GrContextOptions options;
cdalton397536c2016-03-25 12:15:03 -0700428 options.fBufferMapThreshold = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700429 SkASSERT(nullptr == fGpu);
halcanary385fe4d2015-08-26 13:07:48 -0700430 fGpu = new MockGpu(this, options);
bsalomon33435572014-11-05 14:47:41 -0800431 SkASSERT(fGpu);
bsalomon69cfe952015-11-30 13:27:47 -0800432 this->initCommon(options);
bsalomon33435572014-11-05 14:47:41 -0800433
434 // We delete these because we want to test the cache starting with zero resources. Also, none of
435 // these objects are required for any of tests that use this context. TODO: make stop allocating
436 // resources in the buffer pools.
robertphillips77a2e522015-10-17 07:43:27 -0700437 fDrawingManager->abandon();
bsalomon33435572014-11-05 14:47:41 -0800438}