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 { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 241 | GrPixelConfig config = SkColorType2GrPixelConfig(colorType); |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 242 | return this->caps()->maxRenderTargetSampleCount(config); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | //////////////////////////////////////////////////////////////////////////////// |
| 246 | |
Greg Daniel | 06be079 | 2019-04-22 15:53:23 -0400 | [diff] [blame] | 247 | bool GrContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[]) { |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 248 | if (!fGpu || fGpu->caps()->semaphoreSupport()) { |
Greg Daniel | 06be079 | 2019-04-22 15:53:23 -0400 | [diff] [blame] | 249 | return false; |
| 250 | } |
| 251 | for (int i = 0; i < numSemaphores; ++i) { |
| 252 | sk_sp<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore( |
| 253 | waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, |
| 254 | kAdopt_GrWrapOwnership); |
| 255 | fGpu->waitSemaphore(std::move(sema)); |
| 256 | } |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | //////////////////////////////////////////////////////////////////////////////// |
| 261 | |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 262 | GrSemaphoresSubmitted GrContext::flush(const GrFlushInfo& info, |
| 263 | const GrPrepareForExternalIORequests& externalRequests) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 264 | ASSERT_SINGLE_OWNER |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 265 | if (this->abandoned()) { |
| 266 | return GrSemaphoresSubmitted::kNo; |
| 267 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 268 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 269 | return this->drawingManager()->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 270 | info, externalRequests); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 273 | //////////////////////////////////////////////////////////////////////////////// |
| 274 | |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 275 | void GrContext::checkAsyncWorkCompletion() { |
| 276 | if (fGpu) { |
| 277 | fGpu->checkFinishProcs(); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | //////////////////////////////////////////////////////////////////////////////// |
| 282 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 283 | void GrContext::storeVkPipelineCacheData() { |
| 284 | if (fGpu) { |
| 285 | fGpu->storeVkPipelineCacheData(); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | //////////////////////////////////////////////////////////////////////////////// |
| 290 | |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 291 | bool GrContext::supportsDistanceFieldText() const { |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 292 | return this->caps()->shaderCaps()->supportsDistanceFieldText(); |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 293 | } |
| 294 | |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 295 | ////////////////////////////////////////////////////////////////////////////// |
| 296 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 297 | // DDL TODO: remove 'maxResources' |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 298 | void GrContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 299 | ASSERT_SINGLE_OWNER |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 300 | if (maxResources) { |
| 301 | *maxResources = fResourceCache->getMaxResourceCount(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 302 | } |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 303 | if (maxResourceBytes) { |
| 304 | *maxResourceBytes = fResourceCache->getMaxResourceBytes(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 308 | void GrContext::setResourceCacheLimits(int maxResources, size_t maxResourceBytes) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 309 | ASSERT_SINGLE_OWNER |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 310 | fResourceCache->setLimits(maxResources, maxResourceBytes); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 311 | } |
| 312 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 313 | ////////////////////////////////////////////////////////////////////////////// |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 314 | void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 315 | ASSERT_SINGLE_OWNER |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 316 | fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 317 | traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes", |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 318 | this->getTextBlobCache()->usedBytes()); |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 319 | } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 320 | |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 321 | ////////////////////////////////////////////////////////////////////////////// |
| 322 | GrBackendTexture GrContext::createBackendTexture(int width, int height, |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 323 | const GrBackendFormat& backendFormat, |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 324 | GrMipMapped mipMapped, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 325 | GrRenderable renderable, |
| 326 | GrProtected isProtected) { |
Brian Salomon | c42eb66 | 2019-06-24 17:13:00 -0400 | [diff] [blame] | 327 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 328 | if (!this->asDirectContext()) { |
| 329 | return GrBackendTexture(); |
| 330 | } |
| 331 | |
| 332 | if (this->abandoned()) { |
| 333 | return GrBackendTexture(); |
| 334 | } |
| 335 | |
| 336 | if (!backendFormat.isValid()) { |
| 337 | return GrBackendTexture(); |
| 338 | } |
| 339 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 340 | return fGpu->createBackendTexture(width, height, backendFormat, |
| 341 | mipMapped, renderable, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 342 | nullptr, 0, nullptr, isProtected); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | GrBackendTexture GrContext::createBackendTexture(int width, int height, |
| 346 | SkColorType colorType, |
| 347 | GrMipMapped mipMapped, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 348 | GrRenderable renderable, |
| 349 | GrProtected isProtected) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 350 | if (!this->asDirectContext()) { |
| 351 | return GrBackendTexture(); |
| 352 | } |
| 353 | |
| 354 | if (this->abandoned()) { |
| 355 | return GrBackendTexture(); |
| 356 | } |
| 357 | |
| 358 | GrBackendFormat format = this->caps()->getBackendFormatFromColorType(colorType); |
| 359 | if (!format.isValid()) { |
| 360 | return GrBackendTexture(); |
| 361 | } |
| 362 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 363 | return this->createBackendTexture(width, height, format, mipMapped, renderable, isProtected); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 364 | } |
| 365 | |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 366 | GrBackendTexture GrContext::createBackendTexture(int width, int height, |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 367 | const GrBackendFormat& backendFormat, |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 368 | const SkColor4f& color, |
| 369 | GrMipMapped mipMapped, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 370 | GrRenderable renderable, |
| 371 | GrProtected isProtected) { |
Brian Salomon | c42eb66 | 2019-06-24 17:13:00 -0400 | [diff] [blame] | 372 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 373 | if (!this->asDirectContext()) { |
| 374 | return GrBackendTexture(); |
| 375 | } |
| 376 | |
| 377 | if (this->abandoned()) { |
| 378 | return GrBackendTexture(); |
| 379 | } |
| 380 | |
| 381 | if (!backendFormat.isValid()) { |
| 382 | return GrBackendTexture(); |
| 383 | } |
| 384 | |
| 385 | return fGpu->createBackendTexture(width, height, backendFormat, |
| 386 | mipMapped, renderable, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 387 | nullptr, 0, &color, isProtected); |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | GrBackendTexture GrContext::createBackendTexture(int width, int height, |
| 391 | SkColorType colorType, |
| 392 | const SkColor4f& color, |
| 393 | GrMipMapped mipMapped, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 394 | GrRenderable renderable, |
| 395 | GrProtected isProtected) { |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 396 | if (!this->asDirectContext()) { |
| 397 | return GrBackendTexture(); |
| 398 | } |
| 399 | |
| 400 | if (this->abandoned()) { |
| 401 | return GrBackendTexture(); |
| 402 | } |
| 403 | |
| 404 | GrBackendFormat format = this->caps()->getBackendFormatFromColorType(colorType); |
| 405 | if (!format.isValid()) { |
| 406 | return GrBackendTexture(); |
| 407 | } |
| 408 | |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 409 | return this->createBackendTexture(width, height, format, color, mipMapped, renderable, |
| 410 | isProtected); |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 411 | } |
| 412 | |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 413 | void GrContext::deleteBackendTexture(GrBackendTexture backendTex) { |
Brian Salomon | c42eb66 | 2019-06-24 17:13:00 -0400 | [diff] [blame] | 414 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 415 | if (this->abandoned() || !backendTex.isValid()) { |
| 416 | return; |
| 417 | } |
| 418 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 419 | fGpu->deleteBackendTexture(backendTex); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 420 | } |
| 421 | |