bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 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. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 8 | #include "GrContext.h" |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 9 | #include "GrBackendSemaphore.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 10 | #include "GrDrawingManager.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 11 | #include "GrGpu.h" |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 12 | #include "GrMemoryPool.h" |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 13 | #include "GrPathRendererChain.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 14 | #include "GrProxyProvider.h" |
Brian Salomon | c65aec9 | 2017-03-09 09:03:58 -0500 | [diff] [blame] | 15 | #include "GrRenderTargetProxy.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 16 | #include "GrResourceCache.h" |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 17 | #include "GrResourceProvider.h" |
Greg Daniel | d85f97d | 2017-03-07 13:37:21 -0500 | [diff] [blame] | 18 | #include "GrSemaphore.h" |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 19 | #include "GrSoftwarePathRenderer.h" |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 20 | #include "GrTracing.h" |
Robert Phillips | d5f9cdd | 2018-01-31 09:29:48 -0500 | [diff] [blame] | 21 | #include "SkDeferredDisplayList.h" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 22 | #include "SkGr.h" |
Mike Reed | 7fcfb62 | 2018-02-09 13:26:46 -0500 | [diff] [blame] | 23 | #include "SkImageInfoPriv.h" |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 24 | #include "SkMakeUnique.h" |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 25 | #include "SkSurface_Gpu.h" |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 26 | #include "SkTaskGroup.h" |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 27 | #include "SkTraceMemoryDump.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 28 | #include "effects/GrConfigConversionEffect.h" |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 29 | #include "effects/GrSkSLFP.h" |
Chris Dalton | 6c3879d | 2018-11-01 11:13:19 -0600 | [diff] [blame] | 30 | #include "ccpr/GrCoverageCountingPathRenderer.h" |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 31 | #include "text/GrTextBlobCache.h" |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 32 | #include "text/GrTextContext.h" |
Mike Klein | 0ec1c57 | 2018-12-04 11:52:51 -0500 | [diff] [blame] | 33 | #include <atomic> |
| 34 | #include <unordered_map> |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 35 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 36 | #define ASSERT_OWNED_PROXY(P) \ |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 37 | SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == this) |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 38 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 39 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 40 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 41 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 42 | #define RETURN_IF_ABANDONED if (this->abandoned()) { return; } |
| 43 | #define RETURN_FALSE_IF_ABANDONED if (this->abandoned()) { return false; } |
| 44 | #define RETURN_NULL_IF_ABANDONED if (this->abandoned()) { return nullptr; } |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 45 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 46 | //////////////////////////////////////////////////////////////////////////////// |
| 47 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 48 | GrContext::GrContext(GrBackendApi backend, const GrContextOptions& options, int32_t contextID) |
| 49 | : INHERITED(backend, options, contextID) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 50 | fResourceCache = nullptr; |
| 51 | fResourceProvider = nullptr; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 52 | fGlyphCache = nullptr; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 55 | GrContext::~GrContext() { |
| 56 | ASSERT_SINGLE_OWNER |
| 57 | |
| 58 | if (fDrawingManager) { |
| 59 | fDrawingManager->cleanup(); |
| 60 | } |
| 61 | delete fResourceProvider; |
| 62 | delete fResourceCache; |
| 63 | delete fGlyphCache; |
| 64 | } |
| 65 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 66 | bool GrContext::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) { |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 67 | ASSERT_SINGLE_OWNER |
Robert Phillips | fde6fa0 | 2018-03-02 08:53:14 -0500 | [diff] [blame] | 68 | SkASSERT(fThreadSafeProxy); // needs to have been initialized by derived classes |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 69 | SkASSERT(this->proxyProvider()); |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 70 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 71 | if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | SkASSERT(this->caps()); |
| 76 | |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 77 | if (fGpu) { |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 78 | fResourceCache = new GrResourceCache(this->caps(), this->singleOwner(), this->contextID()); |
| 79 | fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, this->singleOwner(), |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 80 | this->explicitlyAllocateGPUResources()); |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 81 | } |
| 82 | |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 83 | if (fResourceCache) { |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 84 | fResourceCache->setProxyProvider(this->proxyProvider()); |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 85 | } |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 86 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 87 | fDidTestPMConversions = false; |
| 88 | |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 89 | GrPathRendererChain::Options prcOptions; |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 90 | prcOptions.fAllowPathMaskCaching = this->options().fAllowPathMaskCaching; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 91 | #if GR_TEST_UTILS |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 92 | prcOptions.fGpuPathRenderers = this->options().fGpuPathRenderers; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 93 | #endif |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 94 | if (this->options().fDisableCoverageCountingPaths) { |
Chris Dalton | ef12509 | 2018-06-26 18:16:47 -0600 | [diff] [blame] | 95 | prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kCoverageCounting; |
| 96 | } |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 97 | if (this->options().fDisableDistanceFieldPaths) { |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 98 | prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall; |
Brian Osman | b350ae2 | 2017-08-29 16:15:39 -0400 | [diff] [blame] | 99 | } |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 100 | |
Robert Phillips | d5f9cdd | 2018-01-31 09:29:48 -0500 | [diff] [blame] | 101 | if (!fResourceCache) { |
| 102 | // DDL TODO: remove this crippling of the path renderer chain |
| 103 | // Disable the small path renderer bc of the proxies in the atlas. They need to be |
| 104 | // unified when the opLists are added back to the destination drawing manager. |
| 105 | prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall; |
Robert Phillips | 5ffcb4d | 2018-07-03 16:39:40 -0400 | [diff] [blame] | 106 | prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kStencilAndCover; |
Robert Phillips | d5f9cdd | 2018-01-31 09:29:48 -0500 | [diff] [blame] | 107 | } |
| 108 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 109 | GrTextContext::Options textContextOptions; |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 110 | textContextOptions.fMaxDistanceFieldFontSize = this->options().fGlyphsAsPathsFontSize; |
| 111 | textContextOptions.fMinDistanceFieldFontSize = this->options().fMinDistanceFieldFontSize; |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 112 | textContextOptions.fDistanceFieldVerticesAlwaysHaveW = false; |
Brian Salomon | b508696 | 2017-12-13 10:59:33 -0500 | [diff] [blame] | 113 | #if SK_SUPPORT_ATLAS_TEXT |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 114 | if (GrContextOptions::Enable::kYes == this->options().fDistanceFieldGlyphVerticesAlwaysHaveW) { |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 115 | textContextOptions.fDistanceFieldVerticesAlwaysHaveW = true; |
Brian Salomon | b508696 | 2017-12-13 10:59:33 -0500 | [diff] [blame] | 116 | } |
| 117 | #endif |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 118 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 119 | fDrawingManager.reset(new GrDrawingManager(this, prcOptions, textContextOptions, |
Robert Phillips | 7e90be9 | 2019-02-15 12:22:59 -0500 | [diff] [blame^] | 120 | this->singleOwner(), |
| 121 | this->explicitlyAllocateGPUResources(), |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 122 | this->options().fSortRenderTargets, |
| 123 | this->options().fReduceOpListSplitting)); |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 124 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 125 | fGlyphCache = new GrStrikeCache(this->caps(), this->options().fGlyphCacheTextureMaximumBytes); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 126 | |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 127 | fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this, this->contextID())); |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 128 | |
Robert Phillips | fde6fa0 | 2018-03-02 08:53:14 -0500 | [diff] [blame] | 129 | // DDL TODO: we need to think through how the task group & persistent cache |
| 130 | // get passed on to/shared between all the DDLRecorders created with this context. |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 131 | if (this->options().fExecutor) { |
| 132 | fTaskGroup = skstd::make_unique<SkTaskGroup>(*this->options().fExecutor); |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 135 | fPersistentCache = this->options().fPersistentCache; |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 136 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 137 | return true; |
bsalomon@google.com | c0af317 | 2012-06-15 14:10:09 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 140 | sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() { |
| 141 | return fThreadSafeProxy; |
| 142 | } |
| 143 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 144 | GrDrawingManager* GrContext::drawingManager() { |
| 145 | return fDrawingManager.get(); |
| 146 | } |
| 147 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 148 | ////////////////////////////////////////////////////////////////////////////// |
| 149 | |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 150 | void GrContext::abandonContext() { |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 151 | if (this->abandoned()) { |
| 152 | return; |
| 153 | } |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 154 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 155 | INHERITED::abandonContext(); |
| 156 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 157 | fResourceProvider->abandon(); |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 158 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 159 | // Need to cleanup the drawing manager first so all the render targets |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 160 | // will be released/forgotten before they too are abandoned. |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 161 | fDrawingManager->cleanup(); |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 162 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 163 | // abandon first to so destructors |
| 164 | // don't try to free the resources in the API. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 165 | fResourceCache->abandonAll(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 166 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 167 | fGpu->disconnect(GrGpu::DisconnectType::kAbandon); |
| 168 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 169 | fGlyphCache->freeAll(); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 170 | fTextBlobCache->freeAll(); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 171 | |
Khushal | c421ca1 | 2018-06-26 14:38:34 -0700 | [diff] [blame] | 172 | } |
| 173 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 174 | void GrContext::releaseResourcesAndAbandonContext() { |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 175 | if (this->abandoned()) { |
| 176 | return; |
| 177 | } |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 178 | |
| 179 | INHERITED::abandonContext(); |
| 180 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 181 | fResourceProvider->abandon(); |
| 182 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 183 | // Need to cleanup the drawing manager first so all the render targets |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 184 | // will be released/forgotten before they too are abandoned. |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 185 | fDrawingManager->cleanup(); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 186 | |
| 187 | // Release all resources in the backend 3D API. |
| 188 | fResourceCache->releaseAll(); |
| 189 | |
| 190 | fGpu->disconnect(GrGpu::DisconnectType::kCleanup); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 191 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 192 | fGlyphCache->freeAll(); |
joshualitt | 26ffc00 | 2015-04-16 11:24:04 -0700 | [diff] [blame] | 193 | fTextBlobCache->freeAll(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 196 | void GrContext::resetGLTextureBindings() { |
| 197 | if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) { |
| 198 | return; |
| 199 | } |
| 200 | fGpu->resetTextureBindings(); |
| 201 | } |
| 202 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 203 | void GrContext::resetContext(uint32_t state) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 204 | ASSERT_SINGLE_OWNER |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 205 | fGpu->markContextDirty(state); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void GrContext::freeGpuResources() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 209 | ASSERT_SINGLE_OWNER |
| 210 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 211 | fGlyphCache->freeAll(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 212 | |
| 213 | fDrawingManager->freeGpuResources(); |
bsalomon | 3033b9f | 2015-04-13 11:09:56 -0700 | [diff] [blame] | 214 | |
| 215 | fResourceCache->purgeAllUnlocked(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 218 | void GrContext::purgeUnlockedResources(bool scratchResourcesOnly) { |
| 219 | ASSERT_SINGLE_OWNER |
| 220 | fResourceCache->purgeUnlockedResources(scratchResourcesOnly); |
| 221 | fResourceCache->purgeAsNeeded(); |
| 222 | fTextBlobCache->purgeStaleBlobs(); |
| 223 | } |
| 224 | |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 225 | void GrContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) { |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 226 | ASSERT_SINGLE_OWNER |
Chris Dalton | 6c3879d | 2018-11-01 11:13:19 -0600 | [diff] [blame] | 227 | |
| 228 | auto purgeTime = GrStdSteadyClock::now() - msNotUsed; |
| 229 | |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 230 | fResourceCache->purgeAsNeeded(); |
Chris Dalton | 6c3879d | 2018-11-01 11:13:19 -0600 | [diff] [blame] | 231 | fResourceCache->purgeResourcesNotUsedSince(purgeTime); |
| 232 | |
| 233 | if (auto ccpr = fDrawingManager->getCoverageCountingPathRenderer()) { |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 234 | ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime); |
Chris Dalton | 6c3879d | 2018-11-01 11:13:19 -0600 | [diff] [blame] | 235 | } |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 236 | |
| 237 | fTextBlobCache->purgeStaleBlobs(); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 238 | } |
| 239 | |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 240 | void GrContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) { |
| 241 | ASSERT_SINGLE_OWNER |
| 242 | fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources); |
| 243 | } |
| 244 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 245 | void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 246 | ASSERT_SINGLE_OWNER |
| 247 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 248 | if (resourceCount) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 249 | *resourceCount = fResourceCache->getBudgetedResourceCount(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 250 | } |
| 251 | if (resourceBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 252 | *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 253 | } |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 256 | size_t GrContext::getResourceCachePurgeableBytes() const { |
| 257 | ASSERT_SINGLE_OWNER |
| 258 | return fResourceCache->getPurgeableBytes(); |
| 259 | } |
| 260 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 261 | //////////////////////////////////////////////////////////////////////////////// |
| 262 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 263 | int GrContext::maxTextureSize() const { return this->caps()->maxTextureSize(); } |
Brian Salomon | f932a63 | 2018-04-05 12:46:09 -0400 | [diff] [blame] | 264 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 265 | int GrContext::maxRenderTargetSize() const { return this->caps()->maxRenderTargetSize(); } |
Brian Salomon | f932a63 | 2018-04-05 12:46:09 -0400 | [diff] [blame] | 266 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 267 | bool GrContext::colorTypeSupportedAsImage(SkColorType colorType) const { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 268 | GrPixelConfig config = SkColorType2GrPixelConfig(colorType); |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 269 | return this->caps()->isConfigTexturable(config); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | int GrContext::maxSurfaceSampleCountForColorType(SkColorType colorType) const { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 273 | GrPixelConfig config = SkColorType2GrPixelConfig(colorType); |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 274 | return this->caps()->maxRenderTargetSampleCount(config); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | //////////////////////////////////////////////////////////////////////////////// |
| 278 | |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 279 | void GrContext::TextBlobCacheOverBudgetCB(void* data) { |
| 280 | SkASSERT(data); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 281 | // TextBlobs are drawn at the SkGpuDevice level, therefore they cannot rely on |
| 282 | // GrRenderTargetContext to perform a necessary flush. The solution is to move drawText calls |
| 283 | // to below the GrContext level, but this is not trivial because they call drawPath on |
| 284 | // SkGpuDevice. |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 285 | GrContext* context = reinterpret_cast<GrContext*>(data); |
| 286 | context->flush(); |
| 287 | } |
| 288 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 289 | //////////////////////////////////////////////////////////////////////////////// |
| 290 | |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 291 | void GrContext::flush() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 292 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 293 | RETURN_IF_ABANDONED |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 294 | |
| 295 | fDrawingManager->flush(nullptr); |
| 296 | } |
| 297 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 298 | GrSemaphoresSubmitted GrContext::flushAndSignalSemaphores(int numSemaphores, |
| 299 | GrBackendSemaphore signalSemaphores[]) { |
| 300 | ASSERT_SINGLE_OWNER |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 301 | if (this->abandoned()) { |
| 302 | return GrSemaphoresSubmitted::kNo; |
| 303 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 304 | |
| 305 | return fDrawingManager->flush(nullptr, numSemaphores, signalSemaphores); |
| 306 | } |
| 307 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 308 | //////////////////////////////////////////////////////////////////////////////// |
| 309 | |
| 310 | void GrContext::storeVkPipelineCacheData() { |
| 311 | if (fGpu) { |
| 312 | fGpu->storeVkPipelineCacheData(); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | //////////////////////////////////////////////////////////////////////////////// |
| 317 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 318 | std::unique_ptr<GrFragmentProcessor> GrContext::createPMToUPMEffect( |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 319 | std::unique_ptr<GrFragmentProcessor> fp) { |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 320 | ASSERT_SINGLE_OWNER |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 321 | // We should have already called this->validPMUPMConversionExists() in this case |
| 322 | SkASSERT(fDidTestPMConversions); |
| 323 | // ...and it should have succeeded |
| 324 | SkASSERT(this->validPMUPMConversionExists()); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 325 | |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 326 | return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToUnpremul); |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 327 | } |
| 328 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 329 | std::unique_ptr<GrFragmentProcessor> GrContext::createUPMToPMEffect( |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 330 | std::unique_ptr<GrFragmentProcessor> fp) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 331 | ASSERT_SINGLE_OWNER |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 332 | // We should have already called this->validPMUPMConversionExists() in this case |
| 333 | SkASSERT(fDidTestPMConversions); |
| 334 | // ...and it should have succeeded |
| 335 | SkASSERT(this->validPMUPMConversionExists()); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 336 | |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 337 | return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 340 | bool GrContext::validPMUPMConversionExists() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 341 | ASSERT_SINGLE_OWNER |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 342 | if (!fDidTestPMConversions) { |
Brian Osman | 28804f3 | 2017-04-20 10:24:36 -0400 | [diff] [blame] | 343 | fPMUPMConversionsRoundTrip = GrConfigConversionEffect::TestForPreservingPMConversions(this); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 344 | fDidTestPMConversions = true; |
| 345 | } |
| 346 | |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 347 | // The PM<->UPM tests fail or succeed together so we only need to check one. |
Brian Osman | 28804f3 | 2017-04-20 10:24:36 -0400 | [diff] [blame] | 348 | return fPMUPMConversionsRoundTrip; |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 351 | bool GrContext::supportsDistanceFieldText() const { |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 352 | return this->caps()->shaderCaps()->supportsDistanceFieldText(); |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 353 | } |
| 354 | |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 355 | ////////////////////////////////////////////////////////////////////////////// |
| 356 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 357 | // DDL TODO: remove 'maxResources' |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 358 | void GrContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 359 | ASSERT_SINGLE_OWNER |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 360 | if (maxResources) { |
| 361 | *maxResources = fResourceCache->getMaxResourceCount(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 362 | } |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 363 | if (maxResourceBytes) { |
| 364 | *maxResourceBytes = fResourceCache->getMaxResourceBytes(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 368 | void GrContext::setResourceCacheLimits(int maxResources, size_t maxResourceBytes) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 369 | ASSERT_SINGLE_OWNER |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 370 | fResourceCache->setLimits(maxResources, maxResourceBytes); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 371 | } |
| 372 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 373 | ////////////////////////////////////////////////////////////////////////////// |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 374 | void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 375 | ASSERT_SINGLE_OWNER |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 376 | fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 377 | traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes", |
| 378 | fTextBlobCache->usedBytes()); |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 379 | } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 380 | |