blob: cc34f2168297a98ee5e55e72b936df7c5b7545ef [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
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
Brian Salomon2ee084e2016-12-16 18:59:19 -050087void GrContext::setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs) {
Brian Salomonf856fd12016-12-16 14:24:34 -050088 fAtlasGlyphCache->setAtlasSizes_ForTesting(configs);
joshualittda04e0e2015-08-19 08:16:43 -070089}
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
Robert Phillipsc37e6142017-01-20 10:03:25 -0500141sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format) {
Brian Salomonf856fd12016-12-16 14:24:34 -0500142 GrAtlasGlyphCache* cache = this->getAtlasGlyphCache();
jvanverth629162d2015-11-08 08:07:24 -0800143
Robert Phillips22f4a1f2016-12-20 08:57:26 -0500144 GrTexture* tex = cache->getTexture(format);
145 sk_sp<SkImage> image(new SkImage_Gpu(tex->width(), tex->height(),
146 kNeedNewImageUniqueID, kPremul_SkAlphaType,
147 sk_ref_sp(tex), nullptr, SkBudgeted::kNo));
148 return image;
jvanverth0671b962015-12-08 18:53:44 -0800149}
jvanverth629162d2015-11-08 08:07:24 -0800150
mtkleinb9eb4ac2015-02-02 18:26:03 -0800151#if GR_GPU_STATS
152void GrGpu::Stats::dump(SkString* out) {
153 out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
154 out->appendf("Shader Compilations: %d\n", fShaderCompilations);
bsalomonb12ea412015-02-02 21:19:50 -0800155 out->appendf("Textures Created: %d\n", fTextureCreates);
156 out->appendf("Texture Uploads: %d\n", fTextureUploads);
jvanverth17aa0472016-01-05 10:41:27 -0800157 out->appendf("Transfers to Texture: %d\n", fTransfersToTexture);
egdaniel8dc7c3a2015-04-16 11:22:42 -0700158 out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates);
joshualitt87a5c9f2015-09-08 13:42:05 -0700159 out->appendf("Number of draws: %d\n", fNumDraws);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800160}
joshualitte45c81c2015-12-02 09:05:37 -0800161
162void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
163 keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds);
164 keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations);
joshualitte45c81c2015-12-02 09:05:37 -0800165 keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads);
joshualitte45c81c2015-12-02 09:05:37 -0800166 keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws);
bsalomon1d417a82016-03-23 11:50:26 -0700167 keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws);
joshualitte45c81c2015-12-02 09:05:37 -0800168}
169
mtkleinb9eb4ac2015-02-02 18:26:03 -0800170#endif
171
172#if GR_CACHE_STATS
robertphillips60029a52015-11-09 13:51:06 -0800173void GrResourceCache::getStats(Stats* stats) const {
174 stats->reset();
175
176 stats->fTotal = this->getResourceCount();
177 stats->fNumNonPurgeable = fNonpurgeableResources.count();
178 stats->fNumPurgeable = fPurgeableQueue.count();
179
180 for (int i = 0; i < fNonpurgeableResources.count(); ++i) {
181 stats->update(fNonpurgeableResources[i]);
182 }
183 for (int i = 0; i < fPurgeableQueue.count(); ++i) {
184 stats->update(fPurgeableQueue.at(i));
185 }
186}
187
bsalomon0ea80f42015-02-11 10:49:59 -0800188void GrResourceCache::dumpStats(SkString* out) const {
mtkleinb9eb4ac2015-02-02 18:26:03 -0800189 this->validate();
190
bsalomonf320e042015-02-17 15:09:34 -0800191 Stats stats;
192
robertphillips60029a52015-11-09 13:51:06 -0800193 this->getStats(&stats);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800194
195 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
196 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
197
198 out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
199 out->appendf("\t\tEntry Count: current %d"
kkinnunen2e6055b2016-04-22 01:48:29 -0700200 " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n",
201 stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable,
202 stats.fScratch, countUtilization, fHighWaterCount);
mtkleinb9eb4ac2015-02-02 18:26:03 -0800203 out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
bsalomonf320e042015-02-17 15:09:34 -0800204 SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
205 SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
mtkleinb9eb4ac2015-02-02 18:26:03 -0800206}
207
joshualittdc5685a2015-12-02 14:08:25 -0800208void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys,
209 SkTArray<double>* values) const {
210 this->validate();
211
212 Stats stats;
213 this->getStats(&stats);
214
joshualittdc5685a2015-12-02 14:08:25 -0800215 keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable);
joshualittdc5685a2015-12-02 14:08:25 -0800216}
217
mtkleinb9eb4ac2015-02-02 18:26:03 -0800218#endif
219
bsalomonddf30e62015-02-19 11:38:44 -0800220///////////////////////////////////////////////////////////////////////////////
221
222void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800223
Brian Salomon1090da62017-01-06 12:04:19 -0500224#ifdef SK_DEBUG
225int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
226 int count = 0;
227 UniqueHash::ConstIter iter(&fUniqueHash);
228 while (!iter.done()) {
229 if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
230 ++count;
231 }
232 ++iter;
233 }
234 return count;
235}
236#endif
237
bsalomon33435572014-11-05 14:47:41 -0800238///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -0800239
240#define ASSERT_SINGLE_OWNER \
Brian Osman11052242016-10-27 14:47:55 -0400241 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->fSingleOwner);)
242#define RETURN_IF_ABANDONED if (fRenderTargetContext->fDrawingManager->wasAbandoned()) { return; }
joshualittf5883a62016-01-13 07:47:38 -0800243
Brian Salomon82f44312017-01-11 13:42:54 -0500244void GrRenderTargetContextPriv::testingOnly_addDrawOp(GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500245 GrAAType aaType,
Brian Salomonf8334782017-01-03 09:42:58 -0500246 std::unique_ptr<GrDrawOp>
247 op,
Brian Osman11052242016-10-27 14:47:55 -0400248 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,
Brian Salomon1951f3d2016-12-09 16:07:12 -0500254 "GrRenderTargetContext::testingOnly_addDrawOp");
joshualittf5883a62016-01-13 07:47:38 -0800255
Brian Salomon82f44312017-01-11 13:42:54 -0500256 GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
robertphillips28a838e2016-06-23 14:07:00 -0700257 if (uss) {
258 pipelineBuilder.setUserStencil(uss);
cdalton846c0512016-05-13 10:25:00 -0700259 }
Brian Salomon189098e72017-01-19 09:55:19 -0500260 pipelineBuilder.setSnapVerticesToPixelCenters(snapToCenters);
robertphillips28a838e2016-06-23 14:07:00 -0700261
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500262 fRenderTargetContext->getOpList()->addDrawOp(pipelineBuilder, fRenderTargetContext, GrNoClip(),
Brian Salomonf8334782017-01-03 09:42:58 -0500263 std::move(op));
joshualittf5883a62016-01-13 07:47:38 -0800264}
265
266#undef ASSERT_SINGLE_OWNER
267#undef RETURN_IF_ABANDONED
268
269///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700270
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400271GrRenderTarget::Flags GrRenderTargetProxy::testingOnly_getFlags() const {
csmartdaltonf9635992016-08-10 11:09:07 -0700272 return fFlags;
273}
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; }
289
bsalomon41e4384e2016-01-08 09:12:44 -0800290private:
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
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
jvanverth84741b32016-09-30 08:39:02 -0700330 GrFence SK_WARN_UNUSED_RESULT insertFence() const override { return 0; }
331 bool waitFence(GrFence, uint64_t) const override { return true; }
332 void deleteFence(GrFence) const override {}
333
bsalomon33435572014-11-05 14:47:41 -0800334private:
mtklein36352bf2015-03-25 18:17:31 -0700335 void onResetContext(uint32_t resetBits) override {}
bsalomonf90a02b2014-11-26 12:28:00 -0800336
bsalomoncb02b382015-08-12 11:14:50 -0700337 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
338
kkinnunen2e6055b2016-04-22 01:48:29 -0700339 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800340 const SkTArray<GrMipLevel>& texels) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700341 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800342 }
343
kkinnunen2e6055b2016-04-22 01:48:29 -0700344 GrTexture* onCreateCompressedTexture(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
bungeman6bd52842016-10-27 09:30:08 -0700349 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override {
halcanary96fcdcc2015-08-27 07:41:13 -0700350 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800351 }
352
bungeman6bd52842016-10-27 09:30:08 -0700353 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
354 GrWrapOwnership) override {
355 return nullptr;
356 }
357
358 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override {
ericrkf7b8b8a2016-02-24 14:49:51 -0800359 return nullptr;
360 }
361
cdalton1bf3e712016-04-19 10:00:02 -0700362 GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
363 return nullptr;
364 }
jvanverth73063dc2015-12-03 09:15:47 -0800365
csmartdaltone0d36292016-07-29 08:14:20 -0700366 gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
367
bsalomon6cb3cbe2015-07-30 07:34:27 -0700368 bool onReadPixels(GrSurface* surface,
bsalomonf90a02b2014-11-26 12:28:00 -0800369 int left, int top, int width, int height,
370 GrPixelConfig,
371 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700372 size_t rowBytes) override {
bsalomonf90a02b2014-11-26 12:28:00 -0800373 return false;
bsalomon33435572014-11-05 14:47:41 -0800374 }
375
bsalomon6cb3cbe2015-07-30 07:34:27 -0700376 bool onWritePixels(GrSurface* surface,
377 int left, int top, int width, int height,
cblume55f2d2d2016-02-26 13:20:48 -0800378 GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override {
bsalomon33435572014-11-05 14:47:41 -0800379 return false;
380 }
381
jvanverthc3d706f2016-04-20 10:33:27 -0700382 bool onTransferPixels(GrSurface* surface,
jvanverth17aa0472016-01-05 10:41:27 -0800383 int left, int top, int width, int height,
cdalton397536c2016-03-25 12:15:03 -0700384 GrPixelConfig config, GrBuffer* transferBuffer,
jvanverth17aa0472016-01-05 10:41:27 -0800385 size_t offset, size_t rowBytes) override {
386 return false;
387 }
388
mtklein36352bf2015-03-25 18:17:31 -0700389 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
bsalomonf90a02b2014-11-26 12:28:00 -0800390
egdanielec00d942015-09-14 12:56:10 -0700391 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
392 int width,
393 int height) override {
394 return nullptr;
bsalomon33435572014-11-05 14:47:41 -0800395 }
396
mtklein36352bf2015-03-25 18:17:31 -0700397 void clearStencil(GrRenderTarget* target) override {}
bsalomon33435572014-11-05 14:47:41 -0800398
jvanverth88957922015-07-14 11:02:52 -0700399 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
egdaniel0a3a7f72016-06-24 09:22:31 -0700400 GrPixelConfig config, bool isRT) override {
cblume61214052016-01-26 09:10:48 -0800401 return 0;
jvanverth88957922015-07-14 11:02:52 -0700402 }
bsalomon67d76202015-11-11 12:40:42 -0800403 bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
bsalomone63ffef2016-02-05 07:17:34 -0800404 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
jvanverth672bb7f2015-07-13 07:19:57 -0700405
bsalomon33435572014-11-05 14:47:41 -0800406 typedef GrGpu INHERITED;
407};
408
409GrContext* GrContext::CreateMockContext() {
halcanary385fe4d2015-08-26 13:07:48 -0700410 GrContext* context = new GrContext;
bsalomon33435572014-11-05 14:47:41 -0800411
412 context->initMockContext();
413 return context;
414}
415
416void GrContext::initMockContext() {
bsalomon682c2692015-05-22 14:01:46 -0700417 GrContextOptions options;
cdalton397536c2016-03-25 12:15:03 -0700418 options.fBufferMapThreshold = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700419 SkASSERT(nullptr == fGpu);
halcanary385fe4d2015-08-26 13:07:48 -0700420 fGpu = new MockGpu(this, options);
bsalomon33435572014-11-05 14:47:41 -0800421 SkASSERT(fGpu);
bsalomon69cfe952015-11-30 13:27:47 -0800422 this->initCommon(options);
bsalomon33435572014-11-05 14:47:41 -0800423
424 // We delete these because we want to test the cache starting with zero resources. Also, none of
425 // these objects are required for any of tests that use this context. TODO: make stop allocating
426 // resources in the buffer pools.
robertphillips77a2e522015-10-17 07:43:27 -0700427 fDrawingManager->abandon();
bsalomon33435572014-11-05 14:47:41 -0800428}