blob: 8574399d74e7940e7b6cf6bab8435675321c7cea [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"
Brian Osman11052242016-10-27 14:47:55 -040012#include "GrRenderTargetContextPriv.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
Brian Osman11052242016-10-27 14:47:55 -040058void GrTestTarget::init(GrContext* ctx, sk_sp<GrRenderTargetContext> renderTargetContext) {
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000059 SkASSERT(!fContext);
60
61 fContext.reset(SkRef(ctx));
Brian Osman11052242016-10-27 14:47:55 -040062 fRenderTargetContext = renderTargetContext;
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000063}
64
Robert Phillipseaa86252016-11-08 13:49:39 +000065bool GrSurfaceProxy::isWrapped_ForTesting() const {
66 return SkToBool(fTarget);
67}
68
69bool GrRenderTargetContext::isWrapped_ForTesting() const {
70 return fRenderTargetProxy->isWrapped_ForTesting();
71}
72
Brian Osman11052242016-10-27 14:47:55 -040073void GrContext::getTestTarget(GrTestTarget* tar, sk_sp<GrRenderTargetContext> renderTargetContext) {
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000074 this->flush();
Brian Osman11052242016-10-27 14:47:55 -040075 SkASSERT(renderTargetContext);
Robert Phillipsf2361d22016-10-25 14:20:06 -040076 // We could create a proxy GrOpList that passes through to fGpu until ~GrTextTarget() and
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000077 // then disconnects. This would help prevent test writers from mixing using the returned
Robert Phillipsf2361d22016-10-25 14:20:06 -040078 // GrOpList and regular drawing. We could also assert or fail in GrContext drawing methods
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000079 // until ~GrTestTarget().
Brian Osman11052242016-10-27 14:47:55 -040080 tar->init(this, std::move(renderTargetContext));
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000081}
82
joshualitt17d833b2015-08-03 10:17:44 -070083void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) {
84 fTextBlobCache->setBudget(bytes);
85}
86
joshualittda04e0e2015-08-19 08:16:43 -070087void GrContext::setTextContextAtlasSizes_ForTesting(const GrBatchAtlasConfig* configs) {
88 fBatchFontCache->setAtlasSizes_ForTesting(configs);
89}
90
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000091///////////////////////////////////////////////////////////////////////////////
92
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000093void GrContext::purgeAllUnlockedResources() {
bsalomon0ea80f42015-02-11 10:49:59 -080094 fResourceCache->purgeAllUnlocked();
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000095}
bsalomon33435572014-11-05 14:47:41 -080096
joshualitte45c81c2015-12-02 09:05:37 -080097void GrContext::resetGpuStats() const {
98#if GR_GPU_STATS
99 fGpu->stats()->reset();
100#endif
101}
102
mtkleinb9eb4ac2015-02-02 18:26:03 -0800103void GrContext::dumpCacheStats(SkString* out) const {
104#if GR_CACHE_STATS
bsalomon0ea80f42015-02-11 10:49:59 -0800105 fResourceCache->dumpStats(out);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800106#endif
107}
108
joshualittdc5685a2015-12-02 14:08:25 -0800109void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
110 SkTArray<double>* values) const {
111#if GR_CACHE_STATS
112 fResourceCache->dumpStatsKeyValuePairs(keys, values);
113#endif
114}
115
mtkleinb9eb4ac2015-02-02 18:26:03 -0800116void GrContext::printCacheStats() const {
117 SkString out;
118 this->dumpCacheStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800119 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800120}
121
122void GrContext::dumpGpuStats(SkString* out) const {
123#if GR_GPU_STATS
124 return fGpu->stats()->dump(out);
125#endif
126}
127
joshualitte45c81c2015-12-02 09:05:37 -0800128void GrContext::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys,
129 SkTArray<double>* values) const {
130#if GR_GPU_STATS
131 return fGpu->stats()->dumpKeyValuePairs(keys, values);
132#endif
133}
134
mtkleinb9eb4ac2015-02-02 18:26:03 -0800135void GrContext::printGpuStats() const {
136 SkString out;
137 this->dumpGpuStats(&out);
kkinnunen297aaf92015-02-19 06:32:12 -0800138 SkDebugf("%s", out.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800139}
140
jvanverth0671b962015-12-08 18:53:44 -0800141GrTexture* GrContext::getFontAtlasTexture(GrMaskFormat format) {
jvanverth629162d2015-11-08 08:07:24 -0800142 GrBatchFontCache* cache = this->getBatchFontCache();
143
jvanverth0671b962015-12-08 18:53:44 -0800144 return cache->getTexture(format);
145}
jvanverth629162d2015-11-08 08:07:24 -0800146
jvanverth0671b962015-12-08 18:53:44 -0800147void SkGpuDevice::drawTexture(GrTexture* tex, const SkRect& dst, const SkPaint& paint) {
jvanverth629162d2015-11-08 08:07:24 -0800148 GrPaint grPaint;
149 SkMatrix mat;
150 mat.reset();
Brian Osman11052242016-10-27 14:47:55 -0400151 if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, mat, &grPaint)) {
jvanverth629162d2015-11-08 08:07:24 -0800152 return;
153 }
154 SkMatrix textureMat;
155 textureMat.reset();
jvanverth0671b962015-12-08 18:53:44 -0800156 textureMat[SkMatrix::kMScaleX] = 1.0f/dst.width();
157 textureMat[SkMatrix::kMScaleY] = 1.0f/dst.height();
158 textureMat[SkMatrix::kMTransX] = -dst.fLeft/dst.width();
159 textureMat[SkMatrix::kMTransY] = -dst.fTop/dst.height();
jvanverth629162d2015-11-08 08:07:24 -0800160
brianosman54f30c12016-07-18 10:53:52 -0700161 grPaint.addColorTextureProcessor(tex, nullptr, textureMat);
jvanverth629162d2015-11-08 08:07:24 -0800162
Brian Osman11052242016-10-27 14:47:55 -0400163 fRenderTargetContext->drawRect(GrNoClip(), grPaint, mat, dst);
jvanverth629162d2015-11-08 08:07:24 -0800164}
165
jvanverth0671b962015-12-08 18:53:44 -0800166
mtkleinb9eb4ac2015-02-02 18:26:03 -0800167#if GR_GPU_STATS
168void GrGpu::Stats::dump(SkString* out) {
169 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
170 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800171 out->appendf("Textures Created: %d\n", fTextureCreates);
172 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800173 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700174 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700175 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800176}
joshualitte45c81c2015-12-02 09:05:37 -0800177
178void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
179 keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds);
180 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
joshualitte45c81c2015-12-02 09:05:37 -0800181 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800182 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700183 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800184}
185
mtkleinb9eb4ac2015-02-02 18:26:03 -0800186#endif
187
188#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800189void GrResourceCache::getStats(Stats* stats) const {
190 stats->reset();
191
192 stats->fTotal = this->getResourceCount();
193 stats->fNumNonPurgeable = fNonpurgeableResources.count();
194 stats->fNumPurgeable = fPurgeableQueue.count();
195
196 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
197 stats->update(fNonpurgeableResources[i]);
198 }
199 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
200 stats->update(fPurgeableQueue.at(i));
201 }
202}
203
bsalomon0ea80f42015-02-11 10:49:59 -0800204void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800205 this->validate();
206
bsalomonf320e042015-02-17 15:09:34 -0800207 Stats stats;
208
robertphillips60029a52015-11-09 13:51:06 -0800209 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800210
211 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
212 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
213
214 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
215 out->appendf("\t\tEntry Count: current %d"
kkinnunen2e6055b2016-04-22 01:48:29 -0700216 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n",
217 stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable,
218 stats.fScratch, countUtilization, fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800219 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800220 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
221 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800222}
223
joshualittdc5685a2015-12-02 14:08:25 -0800224void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
225 SkTArray<double>* values) const {
226 this->validate();
227
228 Stats stats;
229 this->getStats(&stats);
230
joshualittdc5685a2015-12-02 14:08:25 -0800231 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
joshualittdc5685a2015-12-02 14:08:25 -0800232}
233
mtkleinb9eb4ac2015-02-02 18:26:03 -0800234#endif
235
bsalomonddf30e62015-02-19 11:38:44 -0800236///////////////////////////////////////////////////////////////////////////////
237
238void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800239
bsalomon33435572014-11-05 14:47:41 -0800240///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800241
242#define ASSERT_SINGLE_OWNER \
Brian Osman11052242016-10-27 14:47:55 -0400243 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->fSingleOwner);)
244#define RETURN_IF_ABANDONED if (fRenderTargetContext->fDrawingManager->wasAbandoned()) { return; }
joshualittf5883a62016-01-13 07:47:38 -0800245
Brian Osman11052242016-10-27 14:47:55 -0400246void GrRenderTargetContextPriv::testingOnly_drawBatch(const GrPaint& paint,
247 GrDrawBatch* batch,
248 const GrUserStencilSettings* uss,
249 bool snapToCenters) {
joshualittf5883a62016-01-13 07:47:38 -0800250 ASSERT_SINGLE_OWNER
251 RETURN_IF_ABANDONED
Brian Osman11052242016-10-27 14:47:55 -0400252 SkDEBUGCODE(fRenderTargetContext->validate();)
253 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
254 "GrRenderTargetContext::testingOnly_drawBatch");
joshualittf5883a62016-01-13 07:47:38 -0800255
Brian Osman11052242016-10-27 14:47:55 -0400256 GrPipelineBuilder pipelineBuilder(paint, fRenderTargetContext->mustUseHWAA(paint));
robertphillips28a838e2016-06-23 14:07:00 -0700257 if (uss) {
258 pipelineBuilder.setUserStencil(uss);
cdalton846c0512016-05-13 10:25:00 -0700259 }
robertphillips28a838e2016-06-23 14:07:00 -0700260 if (snapToCenters) {
261 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, true);
262 }
263
Brian Osman11052242016-10-27 14:47:55 -0400264 fRenderTargetContext->getOpList()->drawBatch(pipelineBuilder, fRenderTargetContext, GrNoClip(),
265 batch);
joshualittf5883a62016-01-13 07:47:38 -0800266}
267
268#undef ASSERT_SINGLE_OWNER
269#undef RETURN_IF_ABANDONED
270
271///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700272
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400273GrRenderTarget::Flags GrRenderTargetProxy::testingOnly_getFlags() const {
csmartdaltonf9635992016-08-10 11:09:07 -0700274 return fFlags;
275}
276
277///////////////////////////////////////////////////////////////////////////////
bsalomon33435572014-11-05 14:47:41 -0800278// Code for the mock context. It's built on a mock GrGpu class that does nothing.
279////
280
bsalomon33435572014-11-05 14:47:41 -0800281#include "GrGpu.h"
282
egdaniel8dd688b2015-01-22 10:16:09 -0800283class GrPipeline;
joshualittd53a8272014-11-10 16:03:14 -0800284
bsalomon41e4384e2016-01-08 09:12:44 -0800285class MockCaps : public GrCaps {
286public:
287 explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {}
288 bool isConfigTexturable(GrPixelConfig config) const override { return false; }
289 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; }
290private:
291 typedef GrCaps INHERITED;
292};
293
bsalomon33435572014-11-05 14:47:41 -0800294class MockGpu : public GrGpu {
295public:
bsalomon682c2692015-05-22 14:01:46 -0700296 MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
bsalomon41e4384e2016-01-08 09:12:44 -0800297 fCaps.reset(new MockCaps(options));
bsalomon682c2692015-05-22 14:01:46 -0700298 }
mtklein36352bf2015-03-25 18:17:31 -0700299 ~MockGpu() override {}
bsalomon33435572014-11-05 14:47:41 -0800300
bsalomonf0674512015-07-28 13:26:15 -0700301 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
302 GrPixelConfig readConfig, DrawPreference*,
303 ReadPixelTempDrawInfo*) override { return false; }
304
cblumeed828002016-02-16 13:00:01 -0800305 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
bsalomonf0674512015-07-28 13:26:15 -0700306 GrPixelConfig srcConfig, DrawPreference*,
307 WritePixelTempDrawInfo*) override { return false; }
bsalomon39826022015-07-23 08:07:21 -0700308
joshualitt1cbdcde2015-08-21 11:53:29 -0700309 bool onCopySurface(GrSurface* dst,
310 GrSurface* src,
311 const SkIRect& srcRect,
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400312 const SkIPoint& dstPoint) override { return false; }
bsalomonf90a02b2014-11-26 12:28:00 -0800313
csmartdaltonc25c5d72016-11-01 07:03:59 -0700314 void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&,
315 int* effectiveSampleCnt, SamplePattern*) override {
cdalton28f45b92016-03-07 13:58:26 -0800316 *effectiveSampleCnt = rt->desc().fSampleCnt;
317 }
318
egdaniel4bcd62e2016-08-31 07:37:31 -0700319 bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc) const override {
bsalomonf90a02b2014-11-26 12:28:00 -0800320 return false;
321 }
joshualitt3322fa42014-11-07 08:48:51 -0800322
egdaniel9cb63402016-06-23 08:37:05 -0700323 GrGpuCommandBuffer* createCommandBuffer(GrRenderTarget* target,
324 const GrGpuCommandBuffer::LoadAndStoreInfo&,
325 const GrGpuCommandBuffer::LoadAndStoreInfo&) override {
egdaniel066df7c2016-06-08 14:02:27 -0700326 return nullptr;
327 }
328
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400329 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {}
bsalomon6dea83f2015-12-03 12:58:06 -0800330
jvanverth84741b32016-09-30 08:39:02 -0700331 GrFence SK_WARN_UNUSED_RESULT insertFence() const override { return 0; }
332 bool waitFence(GrFence, uint64_t) const override { return true; }
333 void deleteFence(GrFence) const override {}
334
bsalomon33435572014-11-05 14:47:41 -0800335private:
mtklein36352bf2015-03-25 18:17:31 -0700336 void onResetContext(uint32_t resetBits) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800337
bsalomoncb02b382015-08-12 11:14:50 -0700338 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
339
kkinnunen2e6055b2016-04-22 01:48:29 -0700340 GrTexture* onCreateTexture(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
kkinnunen2e6055b2016-04-22 01:48:29 -0700345 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800346 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700347 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800348 }
349
bungeman6bd52842016-10-27 09:30:08 -0700350 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700351 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800352 }
353
bungeman6bd52842016-10-27 09:30:08 -0700354 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
355 GrWrapOwnership) override {
356 return nullptr;
357 }
358
359 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override {
ericrkf7b8b8a2016-02-24 14:49:51 -0800360 return nullptr;
361 }
362
cdalton1bf3e712016-04-19 10:00:02 -0700363 GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
364 return nullptr;
365 }
jvanverth73063dc2015-12-03 09:15:47 -0800366
csmartdaltone0d36292016-07-29 08:14:20 -0700367 gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
368
bsalomon6cb3cbe2015-07-30 07:34:27 -0700369 bool onReadPixels(GrSurface* surface,
bsalomonf90a02b2014-11-26 12:28:00 -0800370 int left, int top, int width, int height,
371 GrPixelConfig,
372 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700373 size_t rowBytes) override {
bsalomonf90a02b2014-11-26 12:28:00 -0800374 return false;
bsalomon33435572014-11-05 14:47:41 -0800375 }
376
bsalomon6cb3cbe2015-07-30 07:34:27 -0700377 bool onWritePixels(GrSurface* surface,
378 int left, int top, int width, int height,
cblume55f2d2d2016-02-26 13:20:48 -0800379 GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override {
bsalomon33435572014-11-05 14:47:41 -0800380 return false;
381 }
382
jvanverthc3d706f2016-04-20 10:33:27 -0700383 bool onTransferPixels(GrSurface* surface,
jvanverth17aa0472016-01-05 10:41:27 -0800384 int left, int top, int width, int height,
cdalton397536c2016-03-25 12:15:03 -0700385 GrPixelConfig config, GrBuffer* transferBuffer,
jvanverth17aa0472016-01-05 10:41:27 -0800386 size_t offset, size_t rowBytes) override {
387 return false;
388 }
389
mtklein36352bf2015-03-25 18:17:31 -0700390 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
bsalomonf90a02b2014-11-26 12:28:00 -0800391
egdanielec00d942015-09-14 12:56:10 -0700392 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
393 int width,
394 int height) override {
395 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800396 }
397
mtklein36352bf2015-03-25 18:17:31 -0700398 void clearStencil(GrRenderTarget* target) override {}
bsalomon33435572014-11-05 14:47:41 -0800399
jvanverth88957922015-07-14 11:02:52 -0700400 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
egdaniel0a3a7f72016-06-24 09:22:31 -0700401 GrPixelConfig config, bool isRT) override {
cblume61214052016-01-26 09:10:48 -0800402 return 0;
jvanverth88957922015-07-14 11:02:52 -0700403 }
bsalomon67d76202015-11-11 12:40:42 -0800404 bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
bsalomone63ffef2016-02-05 07:17:34 -0800405 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
jvanverth672bb7f2015-07-13 07:19:57 -0700406
bsalomon33435572014-11-05 14:47:41 -0800407 typedef GrGpu INHERITED;
408};
409
410GrContext* GrContext::CreateMockContext() {
halcanary385fe4d2015-08-26 13:07:48 -0700411 GrContext* context = new GrContext;
bsalomon33435572014-11-05 14:47:41 -0800412
413 context->initMockContext();
414 return context;
415}
416
417void GrContext::initMockContext() {
bsalomon682c2692015-05-22 14:01:46 -0700418 GrContextOptions options;
cdalton397536c2016-03-25 12:15:03 -0700419 options.fBufferMapThreshold = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700420 SkASSERT(nullptr == fGpu);
halcanary385fe4d2015-08-26 13:07:48 -0700421 fGpu = new MockGpu(this, options);
bsalomon33435572014-11-05 14:47:41 -0800422 SkASSERT(fGpu);
bsalomon69cfe952015-11-30 13:27:47 -0800423 this->initCommon(options);
bsalomon33435572014-11-05 14:47:41 -0800424
425 // We delete these because we want to test the cache starting with zero resources. Also, none of
426 // these objects are required for any of tests that use this context. TODO: make stop allocating
427 // resources in the buffer pools.
robertphillips77a2e522015-10-17 07:43:27 -0700428 fDrawingManager->abandon();
bsalomon33435572014-11-05 14:47:41 -0800429}