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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/private/SkDeferredDisplayList.h" |
| 12 | #include "include/private/SkImageInfoPriv.h" |
| 13 | #include "src/core/SkMakeUnique.h" |
| 14 | #include "src/core/SkTaskGroup.h" |
| 15 | #include "src/gpu/GrDrawingManager.h" |
| 16 | #include "src/gpu/GrGpu.h" |
| 17 | #include "src/gpu/GrMemoryPool.h" |
| 18 | #include "src/gpu/GrPathRendererChain.h" |
| 19 | #include "src/gpu/GrProxyProvider.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrRenderTargetProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 30 | #include "src/gpu/text/GrTextBlobCache.h" |
| 31 | #include "src/gpu/text/GrTextContext.h" |
| 32 | #include "src/image/SkSurface_Gpu.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; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 54 | GrContext::~GrContext() { |
| 55 | ASSERT_SINGLE_OWNER |
| 56 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 57 | if (this->drawingManager()) { |
| 58 | this->drawingManager()->cleanup(); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 59 | } |
| 60 | delete fResourceProvider; |
| 61 | delete fResourceCache; |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 64 | bool GrContext::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) { |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 65 | ASSERT_SINGLE_OWNER |
Robert Phillips | fde6fa0 | 2018-03-02 08:53:14 -0500 | [diff] [blame] | 66 | SkASSERT(fThreadSafeProxy); // needs to have been initialized by derived classes |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 67 | SkASSERT(this->proxyProvider()); |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 68 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 69 | if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | SkASSERT(this->caps()); |
Herb Derby | a00da61 | 2019-03-04 17:10:01 -0500 | [diff] [blame] | 74 | SkASSERT(this->getGrStrikeCache()); |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 75 | SkASSERT(this->getTextBlobCache()); |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 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()); |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 79 | fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, this->singleOwner()); |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 80 | } |
| 81 | |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 82 | if (fResourceCache) { |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 83 | fResourceCache->setProxyProvider(this->proxyProvider()); |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 84 | } |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 85 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 86 | fDidTestPMConversions = false; |
| 87 | |
Robert Phillips | fde6fa0 | 2018-03-02 08:53:14 -0500 | [diff] [blame] | 88 | // DDL TODO: we need to think through how the task group & persistent cache |
| 89 | // 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] | 90 | if (this->options().fExecutor) { |
| 91 | fTaskGroup = skstd::make_unique<SkTaskGroup>(*this->options().fExecutor); |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 92 | } |
| 93 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 94 | fPersistentCache = this->options().fPersistentCache; |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 95 | fShaderErrorHandler = this->options().fShaderErrorHandler; |
| 96 | if (!fShaderErrorHandler) { |
| 97 | fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler(); |
| 98 | } |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 99 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 100 | return true; |
bsalomon@google.com | c0af317 | 2012-06-15 14:10:09 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 103 | sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() { |
| 104 | return fThreadSafeProxy; |
| 105 | } |
| 106 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 107 | ////////////////////////////////////////////////////////////////////////////// |
| 108 | |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 109 | void GrContext::abandonContext() { |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 110 | if (this->abandoned()) { |
| 111 | return; |
| 112 | } |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 113 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 114 | INHERITED::abandonContext(); |
| 115 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 116 | fResourceProvider->abandon(); |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 117 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 118 | // Need to cleanup the drawing manager first so all the render targets |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 119 | // will be released/forgotten before they too are abandoned. |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 120 | this->drawingManager()->cleanup(); |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 121 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 122 | // abandon first to so destructors |
| 123 | // don't try to free the resources in the API. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 124 | fResourceCache->abandonAll(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 125 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 126 | fGpu->disconnect(GrGpu::DisconnectType::kAbandon); |
Khushal | c421ca1 | 2018-06-26 14:38:34 -0700 | [diff] [blame] | 127 | } |
| 128 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 129 | void GrContext::releaseResourcesAndAbandonContext() { |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 130 | if (this->abandoned()) { |
| 131 | return; |
| 132 | } |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 133 | |
| 134 | INHERITED::abandonContext(); |
| 135 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 136 | fResourceProvider->abandon(); |
| 137 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 138 | // Need to cleanup the drawing manager first so all the render targets |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 139 | // will be released/forgotten before they too are abandoned. |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 140 | this->drawingManager()->cleanup(); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 141 | |
| 142 | // Release all resources in the backend 3D API. |
| 143 | fResourceCache->releaseAll(); |
| 144 | |
| 145 | fGpu->disconnect(GrGpu::DisconnectType::kCleanup); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 148 | void GrContext::resetGLTextureBindings() { |
| 149 | if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) { |
| 150 | return; |
| 151 | } |
| 152 | fGpu->resetTextureBindings(); |
| 153 | } |
| 154 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 155 | void GrContext::resetContext(uint32_t state) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 156 | ASSERT_SINGLE_OWNER |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 157 | fGpu->markContextDirty(state); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | void GrContext::freeGpuResources() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 161 | ASSERT_SINGLE_OWNER |
| 162 | |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 163 | // TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here. |
| 164 | // 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] | 165 | this->getGrStrikeCache()->freeAll(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 166 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 167 | this->drawingManager()->freeGpuResources(); |
bsalomon | 3033b9f | 2015-04-13 11:09:56 -0700 | [diff] [blame] | 168 | |
| 169 | fResourceCache->purgeAllUnlocked(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 172 | void GrContext::purgeUnlockedResources(bool scratchResourcesOnly) { |
| 173 | ASSERT_SINGLE_OWNER |
| 174 | fResourceCache->purgeUnlockedResources(scratchResourcesOnly); |
| 175 | fResourceCache->purgeAsNeeded(); |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 176 | |
| 177 | // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient |
| 178 | // place to purge stale blobs |
| 179 | this->getTextBlobCache()->purgeStaleBlobs(); |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 182 | void GrContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) { |
Yuqian Li | 40aa85f | 2019-07-02 13:45:00 -0700 | [diff] [blame] | 183 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 184 | |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 185 | ASSERT_SINGLE_OWNER |
Chris Dalton | 6c3879d | 2018-11-01 11:13:19 -0600 | [diff] [blame] | 186 | |
| 187 | auto purgeTime = GrStdSteadyClock::now() - msNotUsed; |
| 188 | |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 189 | fResourceCache->purgeAsNeeded(); |
Chris Dalton | 6c3879d | 2018-11-01 11:13:19 -0600 | [diff] [blame] | 190 | fResourceCache->purgeResourcesNotUsedSince(purgeTime); |
| 191 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 192 | if (auto ccpr = this->drawingManager()->getCoverageCountingPathRenderer()) { |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 193 | ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime); |
Chris Dalton | 6c3879d | 2018-11-01 11:13:19 -0600 | [diff] [blame] | 194 | } |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 195 | |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 196 | // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient |
| 197 | // place to purge stale blobs |
| 198 | this->getTextBlobCache()->purgeStaleBlobs(); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 199 | } |
| 200 | |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 201 | void GrContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) { |
| 202 | ASSERT_SINGLE_OWNER |
| 203 | fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources); |
| 204 | } |
| 205 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 206 | void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 207 | ASSERT_SINGLE_OWNER |
| 208 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 209 | if (resourceCount) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 210 | *resourceCount = fResourceCache->getBudgetedResourceCount(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 211 | } |
| 212 | if (resourceBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 213 | *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 214 | } |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 217 | size_t GrContext::getResourceCachePurgeableBytes() const { |
| 218 | ASSERT_SINGLE_OWNER |
| 219 | return fResourceCache->getPurgeableBytes(); |
| 220 | } |
| 221 | |
Adrienne Walker | 0f82797 | 2019-03-26 13:46:14 -0700 | [diff] [blame] | 222 | size_t GrContext::ComputeTextureSize(SkColorType type, int width, int height, GrMipMapped mipMapped, |
| 223 | bool useNextPow2) { |
| 224 | int colorSamplesPerPixel = 1; |
| 225 | return GrSurface::ComputeSize(SkColorType2GrPixelConfig(type), width, height, |
| 226 | colorSamplesPerPixel, mipMapped, useNextPow2); |
| 227 | } |
| 228 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 229 | //////////////////////////////////////////////////////////////////////////////// |
| 230 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 231 | int GrContext::maxTextureSize() const { return this->caps()->maxTextureSize(); } |
Brian Salomon | f932a63 | 2018-04-05 12:46:09 -0400 | [diff] [blame] | 232 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 233 | int GrContext::maxRenderTargetSize() const { return this->caps()->maxRenderTargetSize(); } |
Brian Salomon | f932a63 | 2018-04-05 12:46:09 -0400 | [diff] [blame] | 234 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 235 | bool GrContext::colorTypeSupportedAsImage(SkColorType colorType) const { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 236 | GrPixelConfig config = SkColorType2GrPixelConfig(colorType); |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 237 | return this->caps()->isConfigTexturable(config); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | int GrContext::maxSurfaceSampleCountForColorType(SkColorType colorType) const { |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 241 | GrBackendFormat format = |
| 242 | this->caps()->getDefaultBackendFormat(SkColorTypeToGrColorType(colorType), |
| 243 | GrRenderable::kYes); |
| 244 | return this->caps()->maxRenderTargetSampleCount(format); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | //////////////////////////////////////////////////////////////////////////////// |
| 248 | |
Greg Daniel | 06be079 | 2019-04-22 15:53:23 -0400 | [diff] [blame] | 249 | bool GrContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[]) { |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 250 | if (!fGpu || fGpu->caps()->semaphoreSupport()) { |
Greg Daniel | 06be079 | 2019-04-22 15:53:23 -0400 | [diff] [blame] | 251 | return false; |
| 252 | } |
| 253 | for (int i = 0; i < numSemaphores; ++i) { |
| 254 | sk_sp<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore( |
| 255 | waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, |
| 256 | kAdopt_GrWrapOwnership); |
| 257 | fGpu->waitSemaphore(std::move(sema)); |
| 258 | } |
| 259 | return true; |
| 260 | } |
| 261 | |
| 262 | //////////////////////////////////////////////////////////////////////////////// |
| 263 | |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 264 | GrSemaphoresSubmitted GrContext::flush(const GrFlushInfo& info, |
| 265 | const GrPrepareForExternalIORequests& externalRequests) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 266 | ASSERT_SINGLE_OWNER |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 267 | if (this->abandoned()) { |
| 268 | return GrSemaphoresSubmitted::kNo; |
| 269 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 270 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 271 | return this->drawingManager()->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 272 | info, externalRequests); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 275 | //////////////////////////////////////////////////////////////////////////////// |
| 276 | |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 277 | void GrContext::checkAsyncWorkCompletion() { |
| 278 | if (fGpu) { |
| 279 | fGpu->checkFinishProcs(); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | //////////////////////////////////////////////////////////////////////////////// |
| 284 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 285 | void GrContext::storeVkPipelineCacheData() { |
| 286 | if (fGpu) { |
| 287 | fGpu->storeVkPipelineCacheData(); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | //////////////////////////////////////////////////////////////////////////////// |
| 292 | |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 293 | bool GrContext::supportsDistanceFieldText() const { |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 294 | return this->caps()->shaderCaps()->supportsDistanceFieldText(); |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 295 | } |
| 296 | |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 297 | ////////////////////////////////////////////////////////////////////////////// |
| 298 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 299 | // DDL TODO: remove 'maxResources' |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 300 | void GrContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 301 | ASSERT_SINGLE_OWNER |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 302 | if (maxResources) { |
| 303 | *maxResources = fResourceCache->getMaxResourceCount(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 304 | } |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 305 | if (maxResourceBytes) { |
| 306 | *maxResourceBytes = fResourceCache->getMaxResourceBytes(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 310 | void GrContext::setResourceCacheLimits(int maxResources, size_t maxResourceBytes) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 311 | ASSERT_SINGLE_OWNER |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 312 | fResourceCache->setLimits(maxResources, maxResourceBytes); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 313 | } |
| 314 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 315 | ////////////////////////////////////////////////////////////////////////////// |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 316 | void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 317 | ASSERT_SINGLE_OWNER |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 318 | fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 319 | traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes", |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 320 | this->getTextBlobCache()->usedBytes()); |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 321 | } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 322 | |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 323 | ////////////////////////////////////////////////////////////////////////////// |
| 324 | GrBackendTexture GrContext::createBackendTexture(int width, int height, |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 325 | const GrBackendFormat& backendFormat, |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 326 | GrMipMapped mipMapped, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 327 | GrRenderable renderable, |
| 328 | GrProtected isProtected) { |
Brian Salomon | c42eb66 | 2019-06-24 17:13:00 -0400 | [diff] [blame] | 329 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 330 | if (!this->asDirectContext()) { |
| 331 | return GrBackendTexture(); |
| 332 | } |
| 333 | |
| 334 | if (this->abandoned()) { |
| 335 | return GrBackendTexture(); |
| 336 | } |
| 337 | |
| 338 | if (!backendFormat.isValid()) { |
| 339 | return GrBackendTexture(); |
| 340 | } |
| 341 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 342 | return fGpu->createBackendTexture(width, height, backendFormat, |
| 343 | mipMapped, renderable, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 344 | nullptr, 0, nullptr, isProtected); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | GrBackendTexture GrContext::createBackendTexture(int width, int height, |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 348 | SkColorType skColorType, |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 349 | GrMipMapped mipMapped, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 350 | GrRenderable renderable, |
| 351 | GrProtected isProtected) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 352 | if (!this->asDirectContext()) { |
| 353 | return GrBackendTexture(); |
| 354 | } |
| 355 | |
| 356 | if (this->abandoned()) { |
| 357 | return GrBackendTexture(); |
| 358 | } |
| 359 | |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 360 | const GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 361 | if (!format.isValid()) { |
| 362 | return GrBackendTexture(); |
| 363 | } |
| 364 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 365 | return this->createBackendTexture(width, height, format, mipMapped, renderable, isProtected); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 366 | } |
| 367 | |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 368 | GrBackendTexture GrContext::createBackendTexture(const SkSurfaceCharacterization& c) { |
| 369 | const GrCaps* caps = this->caps(); |
| 370 | |
| 371 | if (!this->asDirectContext() || !c.isValid()) { |
| 372 | return GrBackendTexture(); |
| 373 | } |
| 374 | |
| 375 | if (this->abandoned()) { |
| 376 | return GrBackendTexture(); |
| 377 | } |
| 378 | |
| 379 | if (c.usesGLFBO0()) { |
| 380 | // If we are making the surface we will never use FBO0. |
| 381 | return GrBackendTexture(); |
| 382 | } |
| 383 | |
| 384 | if (c.vulkanSecondaryCBCompatible()) { |
| 385 | return {}; |
| 386 | } |
| 387 | |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 388 | const GrBackendFormat format = this->defaultBackendFormat(c.colorType(), GrRenderable::kYes); |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 389 | if (!format.isValid()) { |
| 390 | return GrBackendTexture(); |
| 391 | } |
| 392 | |
| 393 | if (!SkSurface_Gpu::Valid(caps, format)) { |
| 394 | return GrBackendTexture(); |
| 395 | } |
| 396 | |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 397 | GrBackendTexture result = this->createBackendTexture(c.width(), c.height(), format, |
| 398 | GrMipMapped(c.isMipMapped()), |
| 399 | GrRenderable::kYes, |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 400 | c.isProtected()); |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 401 | SkASSERT(c.isCompatible(result)); |
| 402 | return result; |
| 403 | } |
| 404 | |
| 405 | GrBackendTexture GrContext::createBackendTexture(const SkSurfaceCharacterization& c, |
| 406 | const SkColor4f& color) { |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 407 | if (!this->asDirectContext() || !c.isValid()) { |
| 408 | return GrBackendTexture(); |
| 409 | } |
| 410 | |
| 411 | if (this->abandoned()) { |
| 412 | return GrBackendTexture(); |
| 413 | } |
| 414 | |
| 415 | if (c.usesGLFBO0()) { |
| 416 | // If we are making the surface we will never use FBO0. |
| 417 | return GrBackendTexture(); |
| 418 | } |
| 419 | |
| 420 | if (c.vulkanSecondaryCBCompatible()) { |
| 421 | return {}; |
| 422 | } |
| 423 | |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 424 | const GrBackendFormat format = this->defaultBackendFormat(c.colorType(), GrRenderable::kYes); |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 425 | if (!format.isValid()) { |
| 426 | return GrBackendTexture(); |
| 427 | } |
| 428 | |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 429 | if (!SkSurface_Gpu::Valid(this->caps(), format)) { |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 430 | return GrBackendTexture(); |
| 431 | } |
| 432 | |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 433 | GrBackendTexture result = this->createBackendTexture(c.width(), c.height(), format, color, |
| 434 | GrMipMapped(c.isMipMapped()), |
| 435 | GrRenderable::kYes, |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 436 | c.isProtected()); |
Robert Phillips | 02dc030 | 2019-07-02 17:58:27 -0400 | [diff] [blame] | 437 | SkASSERT(c.isCompatible(result)); |
| 438 | return result; |
| 439 | } |
| 440 | |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 441 | GrBackendTexture GrContext::createBackendTexture(int width, int height, |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 442 | const GrBackendFormat& backendFormat, |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 443 | const SkColor4f& color, |
| 444 | GrMipMapped mipMapped, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 445 | GrRenderable renderable, |
| 446 | GrProtected isProtected) { |
Brian Salomon | c42eb66 | 2019-06-24 17:13:00 -0400 | [diff] [blame] | 447 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 448 | if (!this->asDirectContext()) { |
| 449 | return GrBackendTexture(); |
| 450 | } |
| 451 | |
| 452 | if (this->abandoned()) { |
| 453 | return GrBackendTexture(); |
| 454 | } |
| 455 | |
| 456 | if (!backendFormat.isValid()) { |
| 457 | return GrBackendTexture(); |
| 458 | } |
| 459 | |
| 460 | return fGpu->createBackendTexture(width, height, backendFormat, |
| 461 | mipMapped, renderable, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 462 | nullptr, 0, &color, isProtected); |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | GrBackendTexture GrContext::createBackendTexture(int width, int height, |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 466 | SkColorType skColorType, |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 467 | const SkColor4f& color, |
| 468 | GrMipMapped mipMapped, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 469 | GrRenderable renderable, |
| 470 | GrProtected isProtected) { |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 471 | if (!this->asDirectContext()) { |
| 472 | return GrBackendTexture(); |
| 473 | } |
| 474 | |
| 475 | if (this->abandoned()) { |
| 476 | return GrBackendTexture(); |
| 477 | } |
| 478 | |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 479 | GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable); |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 480 | if (!format.isValid()) { |
| 481 | return GrBackendTexture(); |
| 482 | } |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 483 | |
| 484 | GrColorType grColorType = SkColorTypeToGrColorType(skColorType); |
| 485 | SkColor4f swizzledColor = this->caps()->getOutputSwizzle(format, grColorType).applyTo(color); |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 486 | |
Brian Salomon | b450f3b | 2019-07-09 09:36:51 -0400 | [diff] [blame] | 487 | return this->createBackendTexture(width, height, format, swizzledColor, mipMapped, renderable, |
| 488 | isProtected); |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 489 | } |
| 490 | |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 491 | void GrContext::deleteBackendTexture(GrBackendTexture backendTex) { |
Brian Salomon | c42eb66 | 2019-06-24 17:13:00 -0400 | [diff] [blame] | 492 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 493 | if (this->abandoned() || !backendTex.isValid()) { |
| 494 | return; |
| 495 | } |
| 496 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 497 | fGpu->deleteBackendTexture(backendTex); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 498 | } |
| 499 | |