commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 1 | /* |
| 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" |
joshualitt | b542bae | 2015-07-28 09:58:39 -0700 | [diff] [blame] | 9 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 10 | #include "GrContextOptions.h" |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 11 | #include "GrDrawOpAtlas.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 12 | #include "GrDrawingManager.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 13 | #include "GrGpuResourceCacheAccess.h" |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 14 | #include "GrPipelineBuilder.h" |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 15 | #include "GrRenderTargetContextPriv.h" |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 16 | #include "GrRenderTargetProxy.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 17 | #include "GrResourceCache.h" |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 18 | |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 19 | #include "SkGrPriv.h" |
Robert Phillips | 22f4a1f | 2016-12-20 08:57:26 -0500 | [diff] [blame] | 20 | #include "SkImage_Gpu.h" |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 21 | #include "SkMathPriv.h" |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 22 | #include "SkString.h" |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 23 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 24 | #include "text/GrAtlasGlyphCache.h" |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 25 | #include "text/GrTextBlobCache.h" |
| 26 | |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 27 | namespace GrTest { |
| 28 | void 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 Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 31 | int dim = GrDrawOpAtlas::kGlyphMaxDim; |
| 32 | GrDrawOpAtlasConfig configs[3]; |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 33 | configs[kA8_GrMaskFormat].fWidth = dim; |
| 34 | configs[kA8_GrMaskFormat].fHeight = dim; |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 35 | configs[kA8_GrMaskFormat].fLog2Width = SkNextLog2(dim); |
| 36 | configs[kA8_GrMaskFormat].fLog2Height = SkNextLog2(dim); |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 37 | configs[kA8_GrMaskFormat].fPlotWidth = dim; |
| 38 | configs[kA8_GrMaskFormat].fPlotHeight = dim; |
| 39 | |
| 40 | configs[kA565_GrMaskFormat].fWidth = dim; |
| 41 | configs[kA565_GrMaskFormat].fHeight = dim; |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 42 | configs[kA565_GrMaskFormat].fLog2Width = SkNextLog2(dim); |
| 43 | configs[kA565_GrMaskFormat].fLog2Height = SkNextLog2(dim); |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 44 | configs[kA565_GrMaskFormat].fPlotWidth = dim; |
| 45 | configs[kA565_GrMaskFormat].fPlotHeight = dim; |
| 46 | |
| 47 | configs[kARGB_GrMaskFormat].fWidth = dim; |
| 48 | configs[kARGB_GrMaskFormat].fHeight = dim; |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 49 | configs[kARGB_GrMaskFormat].fLog2Width = SkNextLog2(dim); |
| 50 | configs[kARGB_GrMaskFormat].fLog2Height = SkNextLog2(dim); |
joshualitt | 7f9c9eb | 2015-08-21 11:08:00 -0700 | [diff] [blame] | 51 | configs[kARGB_GrMaskFormat].fPlotWidth = dim; |
| 52 | configs[kARGB_GrMaskFormat].fPlotHeight = dim; |
| 53 | |
| 54 | context->setTextContextAtlasSizes_ForTesting(configs); |
| 55 | } |
| 56 | }; |
| 57 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 58 | bool GrSurfaceProxy::isWrapped_ForTesting() const { |
| 59 | return SkToBool(fTarget); |
| 60 | } |
| 61 | |
| 62 | bool GrRenderTargetContext::isWrapped_ForTesting() const { |
| 63 | return fRenderTargetProxy->isWrapped_ForTesting(); |
| 64 | } |
| 65 | |
joshualitt | 17d833b | 2015-08-03 10:17:44 -0700 | [diff] [blame] | 66 | void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) { |
| 67 | fTextBlobCache->setBudget(bytes); |
| 68 | } |
| 69 | |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 70 | void GrContext::setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs) { |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 71 | fAtlasGlyphCache->setAtlasSizes_ForTesting(configs); |
joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 72 | } |
| 73 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 74 | /////////////////////////////////////////////////////////////////////////////// |
| 75 | |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 76 | void GrContext::purgeAllUnlockedResources() { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 77 | fResourceCache->purgeAllUnlocked(); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 78 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 79 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 80 | void GrContext::resetGpuStats() const { |
| 81 | #if GR_GPU_STATS |
| 82 | fGpu->stats()->reset(); |
| 83 | #endif |
| 84 | } |
| 85 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 86 | void GrContext::dumpCacheStats(SkString* out) const { |
| 87 | #if GR_CACHE_STATS |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 88 | fResourceCache->dumpStats(out); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 89 | #endif |
| 90 | } |
| 91 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 92 | void GrContext::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 93 | SkTArray<double>* values) const { |
| 94 | #if GR_CACHE_STATS |
| 95 | fResourceCache->dumpStatsKeyValuePairs(keys, values); |
| 96 | #endif |
| 97 | } |
| 98 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 99 | void GrContext::printCacheStats() const { |
| 100 | SkString out; |
| 101 | this->dumpCacheStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 102 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void GrContext::dumpGpuStats(SkString* out) const { |
| 106 | #if GR_GPU_STATS |
| 107 | return fGpu->stats()->dump(out); |
| 108 | #endif |
| 109 | } |
| 110 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 111 | void GrContext::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 112 | SkTArray<double>* values) const { |
| 113 | #if GR_GPU_STATS |
| 114 | return fGpu->stats()->dumpKeyValuePairs(keys, values); |
| 115 | #endif |
| 116 | } |
| 117 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 118 | void GrContext::printGpuStats() const { |
| 119 | SkString out; |
| 120 | this->dumpGpuStats(&out); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 121 | SkDebugf("%s", out.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Robert Phillips | c37e614 | 2017-01-20 10:03:25 -0500 | [diff] [blame] | 124 | sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format) { |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 125 | GrAtlasGlyphCache* cache = this->getAtlasGlyphCache(); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 126 | |
Robert Phillips | 22f4a1f | 2016-12-20 08:57:26 -0500 | [diff] [blame] | 127 | GrTexture* tex = cache->getTexture(format); |
| 128 | sk_sp<SkImage> image(new SkImage_Gpu(tex->width(), tex->height(), |
| 129 | kNeedNewImageUniqueID, kPremul_SkAlphaType, |
| 130 | sk_ref_sp(tex), nullptr, SkBudgeted::kNo)); |
| 131 | return image; |
jvanverth | 0671b96 | 2015-12-08 18:53:44 -0800 | [diff] [blame] | 132 | } |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 133 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 134 | #if GR_GPU_STATS |
| 135 | void GrGpu::Stats::dump(SkString* out) { |
| 136 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 137 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 138 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 139 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 140 | out->appendf("Transfers to Texture: %d\n", fTransfersToTexture); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 141 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 142 | out->appendf("Number of draws: %d\n", fNumDraws); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 143 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 144 | |
| 145 | void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) { |
| 146 | keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds); |
| 147 | keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 148 | keys->push_back(SkString("texture_uploads")); values->push_back(fTextureUploads); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 149 | keys->push_back(SkString("number_of_draws")); values->push_back(fNumDraws); |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 150 | keys->push_back(SkString("number_of_failed_draws")); values->push_back(fNumFailedDraws); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 151 | } |
| 152 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 153 | #endif |
| 154 | |
| 155 | #if GR_CACHE_STATS |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 156 | void GrResourceCache::getStats(Stats* stats) const { |
| 157 | stats->reset(); |
| 158 | |
| 159 | stats->fTotal = this->getResourceCount(); |
| 160 | stats->fNumNonPurgeable = fNonpurgeableResources.count(); |
| 161 | stats->fNumPurgeable = fPurgeableQueue.count(); |
| 162 | |
| 163 | for (int i = 0; i < fNonpurgeableResources.count(); ++i) { |
| 164 | stats->update(fNonpurgeableResources[i]); |
| 165 | } |
| 166 | for (int i = 0; i < fPurgeableQueue.count(); ++i) { |
| 167 | stats->update(fPurgeableQueue.at(i)); |
| 168 | } |
| 169 | } |
| 170 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 171 | void GrResourceCache::dumpStats(SkString* out) const { |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 172 | this->validate(); |
| 173 | |
bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 174 | Stats stats; |
| 175 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 176 | this->getStats(&stats); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 177 | |
| 178 | float countUtilization = (100.f * fBudgetedCount) / fMaxCount; |
| 179 | float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes; |
| 180 | |
| 181 | out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes); |
| 182 | out->appendf("\t\tEntry Count: current %d" |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 183 | " (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n", |
| 184 | stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable, |
| 185 | stats.fScratch, countUtilization, fHighWaterCount); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 186 | out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n", |
bsalomon | f320e04 | 2015-02-17 15:09:34 -0800 | [diff] [blame] | 187 | SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization, |
| 188 | SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes)); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 189 | } |
| 190 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 191 | void GrResourceCache::dumpStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 192 | SkTArray<double>* values) const { |
| 193 | this->validate(); |
| 194 | |
| 195 | Stats stats; |
| 196 | this->getStats(&stats); |
| 197 | |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 198 | keys->push_back(SkString("gpu_cache_purgable_entries")); values->push_back(stats.fNumPurgeable); |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 199 | } |
| 200 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 201 | #endif |
| 202 | |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 203 | /////////////////////////////////////////////////////////////////////////////// |
| 204 | |
| 205 | void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 206 | |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 207 | #ifdef SK_DEBUG |
| 208 | int GrResourceCache::countUniqueKeysWithTag(const char* tag) const { |
| 209 | int count = 0; |
| 210 | UniqueHash::ConstIter iter(&fUniqueHash); |
| 211 | while (!iter.done()) { |
| 212 | if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) { |
| 213 | ++count; |
| 214 | } |
| 215 | ++iter; |
| 216 | } |
| 217 | return count; |
| 218 | } |
| 219 | #endif |
| 220 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 221 | /////////////////////////////////////////////////////////////////////////////// |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 222 | |
| 223 | #define ASSERT_SINGLE_OWNER \ |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 224 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->fSingleOwner);) |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 225 | #define RETURN_IF_ABANDONED if (fRenderTargetContext->drawingManager()->wasAbandoned()) { return; } |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 226 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 227 | void GrRenderTargetContextPriv::testingOnly_addDrawOp(GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 228 | GrAAType aaType, |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 229 | std::unique_ptr<GrDrawOp> |
| 230 | op, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 231 | const GrUserStencilSettings* uss, |
| 232 | bool snapToCenters) { |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 233 | ASSERT_SINGLE_OWNER |
| 234 | RETURN_IF_ABANDONED |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 235 | SkDEBUGCODE(fRenderTargetContext->validate();) |
| 236 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, |
Brian Salomon | 1951f3d | 2016-12-09 16:07:12 -0500 | [diff] [blame] | 237 | "GrRenderTargetContext::testingOnly_addDrawOp"); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 238 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 239 | GrPipelineBuilder pipelineBuilder(std::move(paint), aaType); |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 240 | if (uss) { |
| 241 | pipelineBuilder.setUserStencil(uss); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 242 | } |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 243 | pipelineBuilder.setSnapVerticesToPixelCenters(snapToCenters); |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 244 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 245 | fRenderTargetContext->getOpList()->addDrawOp(pipelineBuilder, fRenderTargetContext, GrNoClip(), |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 246 | std::move(op)); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | #undef ASSERT_SINGLE_OWNER |
| 250 | #undef RETURN_IF_ABANDONED |
| 251 | |
| 252 | /////////////////////////////////////////////////////////////////////////////// |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 253 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 254 | GrRenderTarget::Flags GrRenderTargetProxy::testingOnly_getFlags() const { |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 255 | return fFlags; |
| 256 | } |
| 257 | |
| 258 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 259 | // Code for the mock context. It's built on a mock GrGpu class that does nothing. |
| 260 | //// |
| 261 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 262 | #include "GrGpu.h" |
| 263 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 264 | class GrPipeline; |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 265 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 266 | class MockCaps : public GrCaps { |
| 267 | public: |
| 268 | explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {} |
| 269 | bool isConfigTexturable(GrPixelConfig config) const override { return false; } |
| 270 | bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; } |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 271 | bool canConfigBeImageStorage(GrPixelConfig) const override { return false; } |
| 272 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 273 | private: |
| 274 | typedef GrCaps INHERITED; |
| 275 | }; |
| 276 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 277 | class MockGpu : public GrGpu { |
| 278 | public: |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 279 | MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 280 | fCaps.reset(new MockCaps(options)); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 281 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 282 | ~MockGpu() override {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 283 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 284 | bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes, |
| 285 | GrPixelConfig readConfig, DrawPreference*, |
| 286 | ReadPixelTempDrawInfo*) override { return false; } |
| 287 | |
cblume | ed82800 | 2016-02-16 13:00:01 -0800 | [diff] [blame] | 288 | bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 289 | GrPixelConfig srcConfig, DrawPreference*, |
| 290 | WritePixelTempDrawInfo*) override { return false; } |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 291 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 292 | bool onCopySurface(GrSurface* dst, |
| 293 | GrSurface* src, |
| 294 | const SkIRect& srcRect, |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 295 | const SkIPoint& dstPoint) override { return false; } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 296 | |
csmartdalton | c25c5d7 | 2016-11-01 07:03:59 -0700 | [diff] [blame] | 297 | void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&, |
| 298 | int* effectiveSampleCnt, SamplePattern*) override { |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 299 | *effectiveSampleCnt = rt->desc().fSampleCnt; |
| 300 | } |
| 301 | |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 302 | bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc) const override { |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 303 | return false; |
| 304 | } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 305 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 306 | GrGpuCommandBuffer* createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&, |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 307 | const GrGpuCommandBuffer::LoadAndStoreInfo&) override { |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 308 | return nullptr; |
| 309 | } |
| 310 | |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 311 | void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override {} |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 312 | |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 313 | GrFence SK_WARN_UNUSED_RESULT insertFence() const override { return 0; } |
| 314 | bool waitFence(GrFence, uint64_t) const override { return true; } |
| 315 | void deleteFence(GrFence) const override {} |
Brian Osman | 9ad1f92 | 2017-02-23 17:06:10 -0500 | [diff] [blame^] | 316 | void flush() override {} |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 317 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 318 | private: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 319 | void onResetContext(uint32_t resetBits) override {} |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 320 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 321 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
| 322 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 323 | GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 324 | const SkTArray<GrMipLevel>& texels) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 325 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 326 | } |
| 327 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 328 | GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 329 | const SkTArray<GrMipLevel>& texels) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 330 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 331 | } |
| 332 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 333 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 334 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 335 | } |
| 336 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 337 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, |
| 338 | GrWrapOwnership) override { |
| 339 | return nullptr; |
| 340 | } |
| 341 | |
| 342 | sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 343 | return nullptr; |
| 344 | } |
| 345 | |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 346 | GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override { |
| 347 | return nullptr; |
| 348 | } |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 349 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 350 | gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; } |
| 351 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 352 | bool onReadPixels(GrSurface* surface, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 353 | int left, int top, int width, int height, |
| 354 | GrPixelConfig, |
| 355 | void* buffer, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 356 | size_t rowBytes) override { |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 357 | return false; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 358 | } |
| 359 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 360 | bool onWritePixels(GrSurface* surface, |
| 361 | int left, int top, int width, int height, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 362 | GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 363 | return false; |
| 364 | } |
| 365 | |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 366 | bool onTransferPixels(GrSurface* surface, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 367 | int left, int top, int width, int height, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 368 | GrPixelConfig config, GrBuffer* transferBuffer, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 369 | size_t offset, size_t rowBytes) override { |
| 370 | return false; |
| 371 | } |
| 372 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 373 | void onResolveRenderTarget(GrRenderTarget* target) override { return; } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 374 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 375 | GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, |
| 376 | int width, |
| 377 | int height) override { |
| 378 | return nullptr; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 379 | } |
| 380 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 381 | void clearStencil(GrRenderTarget* target) override {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 382 | |
jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 383 | GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 384 | GrPixelConfig config, bool isRT) override { |
cblume | 6121405 | 2016-01-26 09:10:48 -0800 | [diff] [blame] | 385 | return 0; |
jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 386 | } |
bsalomon | 67d7620 | 2015-11-11 12:40:42 -0800 | [diff] [blame] | 387 | bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; } |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 388 | void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {} |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 389 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 390 | typedef GrGpu INHERITED; |
| 391 | }; |
| 392 | |
| 393 | GrContext* GrContext::CreateMockContext() { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 394 | GrContext* context = new GrContext; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 395 | |
| 396 | context->initMockContext(); |
| 397 | return context; |
| 398 | } |
| 399 | |
| 400 | void GrContext::initMockContext() { |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 401 | GrContextOptions options; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 402 | options.fBufferMapThreshold = 0; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 403 | SkASSERT(nullptr == fGpu); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 404 | fGpu = new MockGpu(this, options); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 405 | SkASSERT(fGpu); |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 406 | this->initCommon(options); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 407 | |
| 408 | // We delete these because we want to test the cache starting with zero resources. Also, none of |
| 409 | // these objects are required for any of tests that use this context. TODO: make stop allocating |
| 410 | // resources in the buffer pools. |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 411 | fDrawingManager->abandon(); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 412 | } |