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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkTraceMemoryDump.h" |
| 9 | #include "include/gpu/GrBackendSemaphore.h" |
| 10 | #include "include/gpu/GrContext.h" |
| 11 | #include "include/private/GrRenderTargetProxy.h" |
| 12 | #include "include/private/SkDeferredDisplayList.h" |
| 13 | #include "include/private/SkImageInfoPriv.h" |
| 14 | #include "src/core/SkMakeUnique.h" |
| 15 | #include "src/core/SkTaskGroup.h" |
| 16 | #include "src/gpu/GrDrawingManager.h" |
| 17 | #include "src/gpu/GrGpu.h" |
| 18 | #include "src/gpu/GrMemoryPool.h" |
| 19 | #include "src/gpu/GrPathRendererChain.h" |
| 20 | #include "src/gpu/GrProxyProvider.h" |
| 21 | #include "src/gpu/GrResourceCache.h" |
| 22 | #include "src/gpu/GrResourceProvider.h" |
| 23 | #include "src/gpu/GrSemaphore.h" |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 24 | #include "src/gpu/GrShaderUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/GrSoftwarePathRenderer.h" |
| 26 | #include "src/gpu/GrTracing.h" |
| 27 | #include "src/gpu/SkGr.h" |
| 28 | #include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h" |
| 29 | #include "src/gpu/effects/GrSkSLFP.h" |
| 30 | #include "src/gpu/effects/generated/GrConfigConversionEffect.h" |
| 31 | #include "src/gpu/text/GrTextBlobCache.h" |
| 32 | #include "src/gpu/text/GrTextContext.h" |
| 33 | #include "src/image/SkSurface_Gpu.h" |
Mike Klein | 0ec1c57 | 2018-12-04 11:52:51 -0500 | [diff] [blame] | 34 | #include <atomic> |
| 35 | #include <unordered_map> |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 36 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 37 | #define ASSERT_OWNED_PROXY(P) \ |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 38 | SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == this) |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 39 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 40 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 41 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 42 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 43 | #define RETURN_IF_ABANDONED if (this->abandoned()) { return; } |
| 44 | #define RETURN_FALSE_IF_ABANDONED if (this->abandoned()) { return false; } |
| 45 | #define RETURN_NULL_IF_ABANDONED if (this->abandoned()) { return nullptr; } |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 46 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 47 | //////////////////////////////////////////////////////////////////////////////// |
| 48 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 49 | GrContext::GrContext(GrBackendApi backend, const GrContextOptions& options, int32_t contextID) |
| 50 | : INHERITED(backend, options, contextID) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 51 | fResourceCache = nullptr; |
| 52 | fResourceProvider = 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 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 58 | if (this->drawingManager()) { |
| 59 | this->drawingManager()->cleanup(); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 60 | } |
| 61 | delete fResourceProvider; |
| 62 | delete fResourceCache; |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 63 | } |
| 64 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 65 | bool GrContext::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) { |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 66 | ASSERT_SINGLE_OWNER |
Robert Phillips | fde6fa0 | 2018-03-02 08:53:14 -0500 | [diff] [blame] | 67 | SkASSERT(fThreadSafeProxy); // needs to have been initialized by derived classes |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 68 | SkASSERT(this->proxyProvider()); |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 69 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 70 | if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) { |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | SkASSERT(this->caps()); |
Herb Derby | a00da61 | 2019-03-04 17:10:01 -0500 | [diff] [blame] | 75 | SkASSERT(this->getGrStrikeCache()); |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 76 | SkASSERT(this->getTextBlobCache()); |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 77 | |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 78 | if (fGpu) { |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 79 | fResourceCache = new GrResourceCache(this->caps(), this->singleOwner(), this->contextID()); |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 80 | fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, this->singleOwner()); |
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 | |
Robert Phillips | fde6fa0 | 2018-03-02 08:53:14 -0500 | [diff] [blame] | 89 | // DDL TODO: we need to think through how the task group & persistent cache |
| 90 | // 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] | 91 | if (this->options().fExecutor) { |
| 92 | fTaskGroup = skstd::make_unique<SkTaskGroup>(*this->options().fExecutor); |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 93 | } |
| 94 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 95 | fPersistentCache = this->options().fPersistentCache; |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 96 | fShaderErrorHandler = this->options().fShaderErrorHandler; |
| 97 | if (!fShaderErrorHandler) { |
| 98 | fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler(); |
| 99 | } |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 100 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 101 | return true; |
bsalomon@google.com | c0af317 | 2012-06-15 14:10:09 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 104 | sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() { |
| 105 | return fThreadSafeProxy; |
| 106 | } |
| 107 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 108 | ////////////////////////////////////////////////////////////////////////////// |
| 109 | |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 110 | void GrContext::abandonContext() { |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 111 | if (this->abandoned()) { |
| 112 | return; |
| 113 | } |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 114 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 115 | INHERITED::abandonContext(); |
| 116 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 117 | fResourceProvider->abandon(); |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 118 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 119 | // Need to cleanup the drawing manager first so all the render targets |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 120 | // will be released/forgotten before they too are abandoned. |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 121 | this->drawingManager()->cleanup(); |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 122 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 123 | // abandon first to so destructors |
| 124 | // don't try to free the resources in the API. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 125 | fResourceCache->abandonAll(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 126 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 127 | fGpu->disconnect(GrGpu::DisconnectType::kAbandon); |
Khushal | c421ca1 | 2018-06-26 14:38:34 -0700 | [diff] [blame] | 128 | } |
| 129 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 130 | void GrContext::releaseResourcesAndAbandonContext() { |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 131 | if (this->abandoned()) { |
| 132 | return; |
| 133 | } |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 134 | |
| 135 | INHERITED::abandonContext(); |
| 136 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 137 | fResourceProvider->abandon(); |
| 138 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 139 | // Need to cleanup the drawing manager first so all the render targets |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 140 | // will be released/forgotten before they too are abandoned. |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 141 | this->drawingManager()->cleanup(); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 142 | |
| 143 | // Release all resources in the backend 3D API. |
| 144 | fResourceCache->releaseAll(); |
| 145 | |
| 146 | fGpu->disconnect(GrGpu::DisconnectType::kCleanup); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 149 | void GrContext::resetGLTextureBindings() { |
| 150 | if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) { |
| 151 | return; |
| 152 | } |
| 153 | fGpu->resetTextureBindings(); |
| 154 | } |
| 155 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 156 | void GrContext::resetContext(uint32_t state) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 157 | ASSERT_SINGLE_OWNER |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 158 | fGpu->markContextDirty(state); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | void GrContext::freeGpuResources() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 162 | ASSERT_SINGLE_OWNER |
| 163 | |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 164 | // TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here. |
| 165 | // Some slack in the GrTextBlob's implementation requires it though. That could be fixed. |
Herb Derby | a00da61 | 2019-03-04 17:10:01 -0500 | [diff] [blame] | 166 | this->getGrStrikeCache()->freeAll(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 167 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 168 | this->drawingManager()->freeGpuResources(); |
bsalomon | 3033b9f | 2015-04-13 11:09:56 -0700 | [diff] [blame] | 169 | |
| 170 | fResourceCache->purgeAllUnlocked(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 173 | void GrContext::purgeUnlockedResources(bool scratchResourcesOnly) { |
| 174 | ASSERT_SINGLE_OWNER |
| 175 | fResourceCache->purgeUnlockedResources(scratchResourcesOnly); |
| 176 | fResourceCache->purgeAsNeeded(); |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 177 | |
| 178 | // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient |
| 179 | // place to purge stale blobs |
| 180 | this->getTextBlobCache()->purgeStaleBlobs(); |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 181 | } |
| 182 | |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 183 | void GrContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) { |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 184 | ASSERT_SINGLE_OWNER |
Chris Dalton | 6c3879d | 2018-11-01 11:13:19 -0600 | [diff] [blame] | 185 | |
| 186 | auto purgeTime = GrStdSteadyClock::now() - msNotUsed; |
| 187 | |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 188 | fResourceCache->purgeAsNeeded(); |
Chris Dalton | 6c3879d | 2018-11-01 11:13:19 -0600 | [diff] [blame] | 189 | fResourceCache->purgeResourcesNotUsedSince(purgeTime); |
| 190 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 191 | if (auto ccpr = this->drawingManager()->getCoverageCountingPathRenderer()) { |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 192 | ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime); |
Chris Dalton | 6c3879d | 2018-11-01 11:13:19 -0600 | [diff] [blame] | 193 | } |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 194 | |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 195 | // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient |
| 196 | // place to purge stale blobs |
| 197 | this->getTextBlobCache()->purgeStaleBlobs(); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 200 | void GrContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) { |
| 201 | ASSERT_SINGLE_OWNER |
| 202 | fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources); |
| 203 | } |
| 204 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 205 | void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 206 | ASSERT_SINGLE_OWNER |
| 207 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 208 | if (resourceCount) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 209 | *resourceCount = fResourceCache->getBudgetedResourceCount(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 210 | } |
| 211 | if (resourceBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 212 | *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 213 | } |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 216 | size_t GrContext::getResourceCachePurgeableBytes() const { |
| 217 | ASSERT_SINGLE_OWNER |
| 218 | return fResourceCache->getPurgeableBytes(); |
| 219 | } |
| 220 | |
Adrienne Walker | 0f82797 | 2019-03-26 13:46:14 -0700 | [diff] [blame] | 221 | size_t GrContext::ComputeTextureSize(SkColorType type, int width, int height, GrMipMapped mipMapped, |
| 222 | bool useNextPow2) { |
| 223 | int colorSamplesPerPixel = 1; |
| 224 | return GrSurface::ComputeSize(SkColorType2GrPixelConfig(type), width, height, |
| 225 | colorSamplesPerPixel, mipMapped, useNextPow2); |
| 226 | } |
| 227 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 228 | //////////////////////////////////////////////////////////////////////////////// |
| 229 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 230 | int GrContext::maxTextureSize() const { return this->caps()->maxTextureSize(); } |
Brian Salomon | f932a63 | 2018-04-05 12:46:09 -0400 | [diff] [blame] | 231 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 232 | int GrContext::maxRenderTargetSize() const { return this->caps()->maxRenderTargetSize(); } |
Brian Salomon | f932a63 | 2018-04-05 12:46:09 -0400 | [diff] [blame] | 233 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 234 | bool GrContext::colorTypeSupportedAsImage(SkColorType colorType) const { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 235 | GrPixelConfig config = SkColorType2GrPixelConfig(colorType); |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 236 | return this->caps()->isConfigTexturable(config); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | int GrContext::maxSurfaceSampleCountForColorType(SkColorType colorType) const { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 240 | GrPixelConfig config = SkColorType2GrPixelConfig(colorType); |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 241 | return this->caps()->maxRenderTargetSampleCount(config); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | //////////////////////////////////////////////////////////////////////////////// |
| 245 | |
Greg Daniel | 06be079 | 2019-04-22 15:53:23 -0400 | [diff] [blame] | 246 | bool GrContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[]) { |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 247 | if (!fGpu || fGpu->caps()->semaphoreSupport()) { |
Greg Daniel | 06be079 | 2019-04-22 15:53:23 -0400 | [diff] [blame] | 248 | return false; |
| 249 | } |
| 250 | for (int i = 0; i < numSemaphores; ++i) { |
| 251 | sk_sp<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore( |
| 252 | waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, |
| 253 | kAdopt_GrWrapOwnership); |
| 254 | fGpu->waitSemaphore(std::move(sema)); |
| 255 | } |
| 256 | return true; |
| 257 | } |
| 258 | |
| 259 | //////////////////////////////////////////////////////////////////////////////// |
| 260 | |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 261 | GrSemaphoresSubmitted GrContext::flush(const GrFlushInfo& info, |
| 262 | const GrPrepareForExternalIORequests& externalRequests) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 263 | ASSERT_SINGLE_OWNER |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 264 | if (this->abandoned()) { |
| 265 | return GrSemaphoresSubmitted::kNo; |
| 266 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 267 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 268 | return this->drawingManager()->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 269 | info, externalRequests); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 272 | //////////////////////////////////////////////////////////////////////////////// |
| 273 | |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 274 | void GrContext::checkAsyncWorkCompletion() { |
| 275 | if (fGpu) { |
| 276 | fGpu->checkFinishProcs(); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | //////////////////////////////////////////////////////////////////////////////// |
| 281 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 282 | void GrContext::storeVkPipelineCacheData() { |
| 283 | if (fGpu) { |
| 284 | fGpu->storeVkPipelineCacheData(); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | //////////////////////////////////////////////////////////////////////////////// |
| 289 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 290 | std::unique_ptr<GrFragmentProcessor> GrContext::createPMToUPMEffect( |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 291 | std::unique_ptr<GrFragmentProcessor> fp) { |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 292 | ASSERT_SINGLE_OWNER |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 293 | // We should have already called this->validPMUPMConversionExists() in this case |
| 294 | SkASSERT(fDidTestPMConversions); |
| 295 | // ...and it should have succeeded |
| 296 | SkASSERT(this->validPMUPMConversionExists()); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 297 | |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 298 | return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToUnpremul); |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 299 | } |
| 300 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 301 | std::unique_ptr<GrFragmentProcessor> GrContext::createUPMToPMEffect( |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 302 | std::unique_ptr<GrFragmentProcessor> fp) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 303 | ASSERT_SINGLE_OWNER |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 304 | // We should have already called this->validPMUPMConversionExists() in this case |
| 305 | SkASSERT(fDidTestPMConversions); |
| 306 | // ...and it should have succeeded |
| 307 | SkASSERT(this->validPMUPMConversionExists()); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 308 | |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 309 | return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 312 | bool GrContext::validPMUPMConversionExists() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 313 | ASSERT_SINGLE_OWNER |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 314 | if (!fDidTestPMConversions) { |
Brian Osman | 28804f3 | 2017-04-20 10:24:36 -0400 | [diff] [blame] | 315 | fPMUPMConversionsRoundTrip = GrConfigConversionEffect::TestForPreservingPMConversions(this); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 316 | fDidTestPMConversions = true; |
| 317 | } |
| 318 | |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 319 | // 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] | 320 | return fPMUPMConversionsRoundTrip; |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 323 | bool GrContext::supportsDistanceFieldText() const { |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 324 | return this->caps()->shaderCaps()->supportsDistanceFieldText(); |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 325 | } |
| 326 | |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 327 | ////////////////////////////////////////////////////////////////////////////// |
| 328 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 329 | // DDL TODO: remove 'maxResources' |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 330 | void GrContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 331 | ASSERT_SINGLE_OWNER |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 332 | if (maxResources) { |
| 333 | *maxResources = fResourceCache->getMaxResourceCount(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 334 | } |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 335 | if (maxResourceBytes) { |
| 336 | *maxResourceBytes = fResourceCache->getMaxResourceBytes(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 340 | void GrContext::setResourceCacheLimits(int maxResources, size_t maxResourceBytes) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 341 | ASSERT_SINGLE_OWNER |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 342 | fResourceCache->setLimits(maxResources, maxResourceBytes); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 343 | } |
| 344 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 345 | ////////////////////////////////////////////////////////////////////////////// |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 346 | void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 347 | ASSERT_SINGLE_OWNER |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 348 | fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 349 | traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes", |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 350 | this->getTextBlobCache()->usedBytes()); |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 351 | } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 352 | |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 353 | ////////////////////////////////////////////////////////////////////////////// |
| 354 | GrBackendTexture GrContext::createBackendTexture(int width, int height, |
| 355 | GrBackendFormat backendFormat, |
| 356 | GrMipMapped mipMapped, |
| 357 | GrRenderable renderable) { |
| 358 | if (!this->asDirectContext()) { |
| 359 | return GrBackendTexture(); |
| 360 | } |
| 361 | |
| 362 | if (this->abandoned()) { |
| 363 | return GrBackendTexture(); |
| 364 | } |
| 365 | |
| 366 | if (!backendFormat.isValid()) { |
| 367 | return GrBackendTexture(); |
| 368 | } |
| 369 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame^] | 370 | return fGpu->createBackendTexture(width, height, backendFormat, |
| 371 | mipMapped, renderable, |
| 372 | nullptr, 0); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | GrBackendTexture GrContext::createBackendTexture(int width, int height, |
| 376 | SkColorType colorType, |
| 377 | GrMipMapped mipMapped, |
| 378 | GrRenderable renderable) { |
| 379 | if (!this->asDirectContext()) { |
| 380 | return GrBackendTexture(); |
| 381 | } |
| 382 | |
| 383 | if (this->abandoned()) { |
| 384 | return GrBackendTexture(); |
| 385 | } |
| 386 | |
| 387 | GrBackendFormat format = this->caps()->getBackendFormatFromColorType(colorType); |
| 388 | if (!format.isValid()) { |
| 389 | return GrBackendTexture(); |
| 390 | } |
| 391 | |
| 392 | return this->createBackendTexture(width, height, format, mipMapped, renderable); |
| 393 | } |
| 394 | |
| 395 | void GrContext::deleteBackendTexture(GrBackendTexture backendTex) { |
| 396 | if (this->abandoned() || !backendTex.isValid()) { |
| 397 | return; |
| 398 | } |
| 399 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame^] | 400 | fGpu->deleteBackendTexture(backendTex); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 401 | } |
| 402 | |