Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Greg Daniel | 54bfb18 | 2018-11-20 17:12:36 -0500 | [diff] [blame] | 8 | |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 9 | #include "include/gpu/GrDirectContext.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 10 | |
Adlai Holler | 3acc69a | 2020-10-13 08:20:51 -0400 | [diff] [blame] | 11 | #include "include/core/SkTraceMemoryDump.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/gpu/GrContextThreadSafeProxy.h" |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 13 | #include "src/core/SkTaskGroup.h" |
| 14 | #include "src/gpu/GrClientMappedBufferManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrContextThreadSafeProxyPriv.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrDirectContextPriv.h" |
Adlai Holler | 4aa4c60 | 2020-10-12 13:58:52 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrDrawingManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrGpu.h" |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrResourceProvider.h" |
| 20 | #include "src/gpu/GrShaderUtils.h" |
Adlai Holler | 3acc69a | 2020-10-13 08:20:51 -0400 | [diff] [blame] | 21 | #include "src/image/SkImage_GpuBase.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 22 | |
Adlai Holler | 4aa4c60 | 2020-10-12 13:58:52 -0400 | [diff] [blame] | 23 | #include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/effects/GrSkSLFP.h" |
| 25 | #include "src/gpu/gl/GrGLGpu.h" |
| 26 | #include "src/gpu/mock/GrMockGpu.h" |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 27 | #include "src/gpu/ops/GrSmallPathAtlasMgr.h" |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 28 | #include "src/gpu/text/GrAtlasManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 29 | #include "src/gpu/text/GrStrikeCache.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 30 | #ifdef SK_METAL |
Jim Van Verth | 351c9b5 | 2020-11-12 15:21:11 -0500 | [diff] [blame] | 31 | #include "include/gpu/mtl/GrMtlBackendContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 32 | #include "src/gpu/mtl/GrMtlTrampoline.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 33 | #endif |
| 34 | #ifdef SK_VULKAN |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 35 | #include "src/gpu/vk/GrVkGpu.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 36 | #endif |
Jim Van Verth | d2d4c5e | 2020-02-19 14:57:58 -0500 | [diff] [blame] | 37 | #ifdef SK_DIRECT3D |
| 38 | #include "src/gpu/d3d/GrD3DGpu.h" |
| 39 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 40 | #ifdef SK_DAWN |
Mike Klein | 52337de | 2019-07-25 09:00:52 -0500 | [diff] [blame] | 41 | #include "src/gpu/dawn/GrDawnGpu.h" |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 42 | #endif |
Adlai Holler | 6d0745b | 2020-10-13 13:29:00 -0400 | [diff] [blame] | 43 | #include <memory> |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 44 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 45 | #if GR_TEST_UTILS |
| 46 | # include "include/utils/SkRandom.h" |
| 47 | # if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 48 | # include <sanitizer/lsan_interface.h> |
| 49 | # endif |
| 50 | #endif |
| 51 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 52 | #define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(this->singleOwner()) |
| 53 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 54 | GrDirectContext::GrDirectContext(GrBackendApi backend, const GrContextOptions& options) |
Robert Phillips | 3262bc8 | 2020-08-10 12:11:58 -0400 | [diff] [blame] | 55 | : INHERITED(GrContextThreadSafeProxyPriv::Make(backend, options)) { |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 56 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 57 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 58 | GrDirectContext::~GrDirectContext() { |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 59 | ASSERT_SINGLE_OWNER |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 60 | // this if-test protects against the case where the context is being destroyed |
| 61 | // before having been fully created |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 62 | if (fGpu) { |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 63 | this->flushAndSubmit(); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 64 | } |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 65 | |
Greg Daniel | a89b430 | 2021-01-29 10:48:40 -0500 | [diff] [blame^] | 66 | // We need to make sure all work is finished on the gpu before we start releasing resources. |
| 67 | this->syncAllOutstandingGpuWork(/*shouldExecuteWhileAbandoned=*/false); |
| 68 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 69 | this->destroyDrawingManager(); |
| 70 | fMappedBufferManager.reset(); |
| 71 | |
| 72 | // Ideally we could just let the ptr drop, but resource cache queries this ptr in releaseAll. |
| 73 | if (fResourceCache) { |
| 74 | fResourceCache->releaseAll(); |
| 75 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 76 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 77 | |
Adlai Holler | 61a591c | 2020-10-12 12:38:33 -0400 | [diff] [blame] | 78 | sk_sp<GrContextThreadSafeProxy> GrDirectContext::threadSafeProxy() { |
| 79 | return INHERITED::threadSafeProxy(); |
| 80 | } |
| 81 | |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame] | 82 | void GrDirectContext::resetGLTextureBindings() { |
| 83 | if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) { |
| 84 | return; |
| 85 | } |
| 86 | fGpu->resetTextureBindings(); |
| 87 | } |
| 88 | |
| 89 | void GrDirectContext::resetContext(uint32_t state) { |
| 90 | ASSERT_SINGLE_OWNER |
| 91 | fGpu->markContextDirty(state); |
| 92 | } |
| 93 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 94 | void GrDirectContext::abandonContext() { |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame] | 95 | if (INHERITED::abandoned()) { |
| 96 | return; |
| 97 | } |
| 98 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 99 | INHERITED::abandonContext(); |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame] | 100 | |
Greg Daniel | a89b430 | 2021-01-29 10:48:40 -0500 | [diff] [blame^] | 101 | // We need to make sure all work is finished on the gpu before we start releasing resources. |
| 102 | this->syncAllOutstandingGpuWork(this->caps()->mustSyncGpuDuringAbandon()); |
| 103 | |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame] | 104 | fStrikeCache->freeAll(); |
| 105 | |
| 106 | fMappedBufferManager->abandon(); |
| 107 | |
| 108 | fResourceProvider->abandon(); |
| 109 | |
Robert Phillips | eb999bc | 2020-11-03 08:41:47 -0500 | [diff] [blame] | 110 | // abandon first so destructors don't try to free the resources in the API. |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame] | 111 | fResourceCache->abandonAll(); |
| 112 | |
| 113 | fGpu->disconnect(GrGpu::DisconnectType::kAbandon); |
| 114 | |
| 115 | fMappedBufferManager.reset(); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 116 | if (fSmallPathAtlasMgr) { |
| 117 | fSmallPathAtlasMgr->reset(); |
| 118 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 119 | fAtlasManager->freeAll(); |
| 120 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 121 | |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame] | 122 | bool GrDirectContext::abandoned() { |
| 123 | if (INHERITED::abandoned()) { |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | if (fGpu && fGpu->isDeviceLost()) { |
| 128 | this->abandonContext(); |
| 129 | return true; |
| 130 | } |
| 131 | return false; |
| 132 | } |
| 133 | |
Adlai Holler | 61a591c | 2020-10-12 12:38:33 -0400 | [diff] [blame] | 134 | bool GrDirectContext::oomed() { return fGpu ? fGpu->checkAndResetOOMed() : false; } |
| 135 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 136 | void GrDirectContext::releaseResourcesAndAbandonContext() { |
Adlai Holler | 61a591c | 2020-10-12 12:38:33 -0400 | [diff] [blame] | 137 | if (INHERITED::abandoned()) { |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | INHERITED::abandonContext(); |
| 142 | |
Greg Daniel | a89b430 | 2021-01-29 10:48:40 -0500 | [diff] [blame^] | 143 | // We need to make sure all work is finished on the gpu before we start releasing resources. |
| 144 | this->syncAllOutstandingGpuWork(/*shouldExecuteWhileAbandoned=*/true); |
| 145 | |
Adlai Holler | 61a591c | 2020-10-12 12:38:33 -0400 | [diff] [blame] | 146 | fMappedBufferManager.reset(); |
| 147 | |
| 148 | fResourceProvider->abandon(); |
| 149 | |
| 150 | // Release all resources in the backend 3D API. |
| 151 | fResourceCache->releaseAll(); |
| 152 | |
| 153 | fGpu->disconnect(GrGpu::DisconnectType::kCleanup); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 154 | if (fSmallPathAtlasMgr) { |
| 155 | fSmallPathAtlasMgr->reset(); |
| 156 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 157 | fAtlasManager->freeAll(); |
| 158 | } |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 159 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 160 | void GrDirectContext::freeGpuResources() { |
Adlai Holler | 4aa4c60 | 2020-10-12 13:58:52 -0400 | [diff] [blame] | 161 | ASSERT_SINGLE_OWNER |
| 162 | |
| 163 | if (this->abandoned()) { |
| 164 | return; |
| 165 | } |
| 166 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 167 | this->flushAndSubmit(); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 168 | if (fSmallPathAtlasMgr) { |
| 169 | fSmallPathAtlasMgr->reset(); |
| 170 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 171 | fAtlasManager->freeAll(); |
Robert Phillips | 56181ba | 2019-03-08 12:00:45 -0500 | [diff] [blame] | 172 | |
Adlai Holler | 4aa4c60 | 2020-10-12 13:58:52 -0400 | [diff] [blame] | 173 | // TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here. |
| 174 | // Some slack in the GrTextBlob's implementation requires it though. That could be fixed. |
| 175 | fStrikeCache->freeAll(); |
| 176 | |
| 177 | this->drawingManager()->freeGpuResources(); |
| 178 | |
| 179 | fResourceCache->purgeAllUnlocked(); |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 180 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 181 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 182 | bool GrDirectContext::init() { |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 183 | ASSERT_SINGLE_OWNER |
| 184 | if (!fGpu) { |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 185 | return false; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 186 | } |
| 187 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 188 | fThreadSafeProxy->priv().init(fGpu->refCaps()); |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 189 | if (!INHERITED::init()) { |
| 190 | return false; |
| 191 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 192 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 193 | SkASSERT(this->getTextBlobCache()); |
| 194 | SkASSERT(this->threadSafeCache()); |
| 195 | |
| 196 | fStrikeCache = std::make_unique<GrStrikeCache>(); |
Brian Salomon | be1084b | 2021-01-26 13:29:30 -0500 | [diff] [blame] | 197 | fResourceCache = std::make_unique<GrResourceCache>(this->singleOwner(), this->contextID()); |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 198 | fResourceCache->setProxyProvider(this->proxyProvider()); |
| 199 | fResourceCache->setThreadSafeCache(this->threadSafeCache()); |
| 200 | fResourceProvider = std::make_unique<GrResourceProvider>(fGpu.get(), fResourceCache.get(), |
| 201 | this->singleOwner()); |
| 202 | fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID()); |
| 203 | |
| 204 | fDidTestPMConversions = false; |
| 205 | |
| 206 | // DDL TODO: we need to think through how the task group & persistent cache |
| 207 | // get passed on to/shared between all the DDLRecorders created with this context. |
| 208 | if (this->options().fExecutor) { |
| 209 | fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor); |
| 210 | } |
| 211 | |
| 212 | fPersistentCache = this->options().fPersistentCache; |
| 213 | fShaderErrorHandler = this->options().fShaderErrorHandler; |
| 214 | if (!fShaderErrorHandler) { |
| 215 | fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler(); |
| 216 | } |
| 217 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 218 | GrDrawOpAtlas::AllowMultitexturing allowMultitexturing; |
| 219 | if (GrContextOptions::Enable::kNo == this->options().fAllowMultipleGlyphCacheTextures || |
| 220 | // multitexturing supported only if range can represent the index + texcoords fully |
| 221 | !(this->caps()->shaderCaps()->floatIs32Bits() || |
| 222 | this->caps()->shaderCaps()->integerSupport())) { |
| 223 | allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kNo; |
| 224 | } else { |
| 225 | allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes; |
| 226 | } |
| 227 | |
| 228 | GrProxyProvider* proxyProvider = this->priv().proxyProvider(); |
| 229 | |
Robert Phillips | 3262bc8 | 2020-08-10 12:11:58 -0400 | [diff] [blame] | 230 | fAtlasManager = std::make_unique<GrAtlasManager>(proxyProvider, |
| 231 | this->options().fGlyphCacheTextureMaximumBytes, |
| 232 | allowMultitexturing); |
| 233 | this->priv().addOnFlushCallbackObject(fAtlasManager.get()); |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 234 | |
| 235 | return true; |
| 236 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 237 | |
Adlai Holler | 3a508e9 | 2020-10-12 13:58:01 -0400 | [diff] [blame] | 238 | void GrDirectContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
| 239 | ASSERT_SINGLE_OWNER |
| 240 | |
| 241 | if (resourceCount) { |
| 242 | *resourceCount = fResourceCache->getBudgetedResourceCount(); |
| 243 | } |
| 244 | if (resourceBytes) { |
| 245 | *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | size_t GrDirectContext::getResourceCachePurgeableBytes() const { |
| 250 | ASSERT_SINGLE_OWNER |
| 251 | return fResourceCache->getPurgeableBytes(); |
| 252 | } |
| 253 | |
| 254 | void GrDirectContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const { |
| 255 | ASSERT_SINGLE_OWNER |
| 256 | if (maxResources) { |
| 257 | *maxResources = -1; |
| 258 | } |
| 259 | if (maxResourceBytes) { |
| 260 | *maxResourceBytes = this->getResourceCacheLimit(); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | size_t GrDirectContext::getResourceCacheLimit() const { |
| 265 | ASSERT_SINGLE_OWNER |
| 266 | return fResourceCache->getMaxResourceBytes(); |
| 267 | } |
| 268 | |
| 269 | void GrDirectContext::setResourceCacheLimits(int unused, size_t maxResourceBytes) { |
| 270 | ASSERT_SINGLE_OWNER |
| 271 | this->setResourceCacheLimit(maxResourceBytes); |
| 272 | } |
| 273 | |
| 274 | void GrDirectContext::setResourceCacheLimit(size_t maxResourceBytes) { |
| 275 | ASSERT_SINGLE_OWNER |
| 276 | fResourceCache->setLimit(maxResourceBytes); |
| 277 | } |
| 278 | |
Adlai Holler | 4aa4c60 | 2020-10-12 13:58:52 -0400 | [diff] [blame] | 279 | void GrDirectContext::purgeUnlockedResources(bool scratchResourcesOnly) { |
| 280 | ASSERT_SINGLE_OWNER |
| 281 | |
| 282 | if (this->abandoned()) { |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | fResourceCache->purgeUnlockedResources(scratchResourcesOnly); |
| 287 | fResourceCache->purgeAsNeeded(); |
| 288 | |
| 289 | // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient |
| 290 | // place to purge stale blobs |
| 291 | this->getTextBlobCache()->purgeStaleBlobs(); |
| 292 | } |
| 293 | |
| 294 | void GrDirectContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) { |
| 295 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 296 | |
| 297 | ASSERT_SINGLE_OWNER |
| 298 | |
| 299 | if (this->abandoned()) { |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | this->checkAsyncWorkCompletion(); |
| 304 | fMappedBufferManager->process(); |
| 305 | auto purgeTime = GrStdSteadyClock::now() - msNotUsed; |
| 306 | |
| 307 | fResourceCache->purgeAsNeeded(); |
| 308 | fResourceCache->purgeResourcesNotUsedSince(purgeTime); |
| 309 | |
| 310 | if (auto ccpr = this->drawingManager()->getCoverageCountingPathRenderer()) { |
| 311 | ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime); |
| 312 | } |
| 313 | |
| 314 | // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient |
| 315 | // place to purge stale blobs |
| 316 | this->getTextBlobCache()->purgeStaleBlobs(); |
| 317 | } |
| 318 | |
| 319 | void GrDirectContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) { |
| 320 | ASSERT_SINGLE_OWNER |
| 321 | |
| 322 | if (this->abandoned()) { |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources); |
| 327 | } |
| 328 | |
Adlai Holler | 3acc69a | 2020-10-13 08:20:51 -0400 | [diff] [blame] | 329 | //////////////////////////////////////////////////////////////////////////////// |
| 330 | bool GrDirectContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[], |
| 331 | bool deleteSemaphoresAfterWait) { |
| 332 | if (!fGpu || fGpu->caps()->semaphoreSupport()) { |
| 333 | return false; |
| 334 | } |
| 335 | GrWrapOwnership ownership = |
| 336 | deleteSemaphoresAfterWait ? kAdopt_GrWrapOwnership : kBorrow_GrWrapOwnership; |
| 337 | for (int i = 0; i < numSemaphores; ++i) { |
| 338 | std::unique_ptr<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore( |
| 339 | waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, ownership); |
| 340 | // If we failed to wrap the semaphore it means the client didn't give us a valid semaphore |
| 341 | // to begin with. Therefore, it is fine to not wait on it. |
| 342 | if (sema) { |
| 343 | fGpu->waitSemaphore(sema.get()); |
| 344 | } |
| 345 | } |
| 346 | return true; |
| 347 | } |
Adlai Holler | 4aa4c60 | 2020-10-12 13:58:52 -0400 | [diff] [blame] | 348 | |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 349 | GrSmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() { |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 350 | if (!fSmallPathAtlasMgr) { |
| 351 | fSmallPathAtlasMgr = std::make_unique<GrSmallPathAtlasMgr>(); |
| 352 | |
| 353 | this->priv().addOnFlushCallbackObject(fSmallPathAtlasMgr.get()); |
| 354 | } |
| 355 | |
| 356 | if (!fSmallPathAtlasMgr->initAtlas(this->proxyProvider(), this->caps())) { |
| 357 | return nullptr; |
| 358 | } |
| 359 | |
| 360 | return fSmallPathAtlasMgr.get(); |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 361 | } |
| 362 | |
Adlai Holler | 3acc69a | 2020-10-13 08:20:51 -0400 | [diff] [blame] | 363 | //////////////////////////////////////////////////////////////////////////////// |
| 364 | |
| 365 | GrSemaphoresSubmitted GrDirectContext::flush(const GrFlushInfo& info) { |
| 366 | ASSERT_SINGLE_OWNER |
| 367 | if (this->abandoned()) { |
| 368 | if (info.fFinishedProc) { |
| 369 | info.fFinishedProc(info.fFinishedContext); |
| 370 | } |
| 371 | if (info.fSubmittedProc) { |
| 372 | info.fSubmittedProc(info.fSubmittedContext, false); |
| 373 | } |
| 374 | return GrSemaphoresSubmitted::kNo; |
| 375 | } |
| 376 | |
Robert Phillips | 80bfda8 | 2020-11-12 09:23:36 -0500 | [diff] [blame] | 377 | return this->drawingManager()->flushSurfaces({}, SkSurface::BackendSurfaceAccess::kNoAccess, |
| 378 | info, nullptr); |
Adlai Holler | 3acc69a | 2020-10-13 08:20:51 -0400 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | bool GrDirectContext::submit(bool syncCpu) { |
| 382 | ASSERT_SINGLE_OWNER |
| 383 | if (this->abandoned()) { |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | if (!fGpu) { |
| 388 | return false; |
| 389 | } |
| 390 | |
| 391 | return fGpu->submitToGpu(syncCpu); |
| 392 | } |
| 393 | |
| 394 | //////////////////////////////////////////////////////////////////////////////// |
| 395 | |
| 396 | void GrDirectContext::checkAsyncWorkCompletion() { |
| 397 | if (fGpu) { |
| 398 | fGpu->checkFinishProcs(); |
| 399 | } |
| 400 | } |
| 401 | |
Greg Daniel | a89b430 | 2021-01-29 10:48:40 -0500 | [diff] [blame^] | 402 | void GrDirectContext::syncAllOutstandingGpuWork(bool shouldExecuteWhileAbandoned) { |
| 403 | if (fGpu && (!this->abandoned() || shouldExecuteWhileAbandoned)) { |
| 404 | fGpu->finishOutstandingGpuWork(); |
| 405 | this->checkAsyncWorkCompletion(); |
| 406 | } |
| 407 | } |
| 408 | |
Adlai Holler | 3acc69a | 2020-10-13 08:20:51 -0400 | [diff] [blame] | 409 | //////////////////////////////////////////////////////////////////////////////// |
| 410 | |
| 411 | void GrDirectContext::storeVkPipelineCacheData() { |
| 412 | if (fGpu) { |
| 413 | fGpu->storeVkPipelineCacheData(); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | //////////////////////////////////////////////////////////////////////////////// |
| 418 | |
| 419 | bool GrDirectContext::supportsDistanceFieldText() const { |
| 420 | return this->caps()->shaderCaps()->supportsDistanceFieldText(); |
| 421 | } |
| 422 | |
| 423 | ////////////////////////////////////////////////////////////////////////////// |
| 424 | |
| 425 | void GrDirectContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 426 | ASSERT_SINGLE_OWNER |
| 427 | fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 428 | traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes", |
| 429 | this->getTextBlobCache()->usedBytes()); |
| 430 | } |
| 431 | |
| 432 | size_t GrDirectContext::ComputeImageSize(sk_sp<SkImage> image, GrMipmapped mipMapped, |
| 433 | bool useNextPow2) { |
| 434 | if (!image->isTextureBacked()) { |
| 435 | return 0; |
| 436 | } |
| 437 | SkImage_GpuBase* gpuImage = static_cast<SkImage_GpuBase*>(as_IB(image.get())); |
| 438 | GrTextureProxy* proxy = gpuImage->peekProxy(); |
| 439 | if (!proxy) { |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | int colorSamplesPerPixel = 1; |
| 444 | return GrSurface::ComputeSize(proxy->backendFormat(), image->dimensions(), |
| 445 | colorSamplesPerPixel, mipMapped, useNextPow2); |
| 446 | } |
| 447 | |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 448 | GrBackendTexture GrDirectContext::createBackendTexture(int width, int height, |
| 449 | const GrBackendFormat& backendFormat, |
| 450 | GrMipmapped mipMapped, |
| 451 | GrRenderable renderable, |
| 452 | GrProtected isProtected) { |
| 453 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 454 | if (this->abandoned()) { |
| 455 | return GrBackendTexture(); |
| 456 | } |
| 457 | |
| 458 | return fGpu->createBackendTexture({width, height}, backendFormat, renderable, |
| 459 | mipMapped, isProtected); |
| 460 | } |
| 461 | |
| 462 | GrBackendTexture GrDirectContext::createBackendTexture(int width, int height, |
| 463 | SkColorType skColorType, |
| 464 | GrMipmapped mipMapped, |
| 465 | GrRenderable renderable, |
| 466 | GrProtected isProtected) { |
| 467 | if (this->abandoned()) { |
| 468 | return GrBackendTexture(); |
| 469 | } |
| 470 | |
| 471 | const GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable); |
| 472 | |
| 473 | return this->createBackendTexture(width, height, format, mipMapped, renderable, isProtected); |
| 474 | } |
| 475 | |
| 476 | static GrBackendTexture create_and_update_backend_texture( |
| 477 | GrDirectContext* dContext, |
| 478 | SkISize dimensions, |
| 479 | const GrBackendFormat& backendFormat, |
| 480 | GrMipmapped mipMapped, |
| 481 | GrRenderable renderable, |
| 482 | GrProtected isProtected, |
| 483 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 484 | const GrGpu::BackendTextureData* data) { |
| 485 | GrGpu* gpu = dContext->priv().getGpu(); |
| 486 | |
| 487 | GrBackendTexture beTex = gpu->createBackendTexture(dimensions, backendFormat, renderable, |
| 488 | mipMapped, isProtected); |
| 489 | if (!beTex.isValid()) { |
| 490 | return {}; |
| 491 | } |
| 492 | |
| 493 | if (!dContext->priv().getGpu()->updateBackendTexture(beTex, |
| 494 | std::move(finishedCallback), |
| 495 | data)) { |
| 496 | dContext->deleteBackendTexture(beTex); |
| 497 | return {}; |
| 498 | } |
| 499 | return beTex; |
| 500 | } |
| 501 | |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 502 | static bool update_texture_with_pixmaps(GrGpu* gpu, |
| 503 | const SkPixmap* srcData, |
| 504 | int numLevels, |
| 505 | const GrBackendTexture& backendTexture, |
| 506 | GrSurfaceOrigin textureOrigin, |
| 507 | sk_sp<GrRefCntedCallback> finishedCallback) { |
Brian Salomon | 07d8c0d | 2021-01-29 09:45:15 -0500 | [diff] [blame] | 508 | bool flip = textureOrigin == kBottomLeft_GrSurfaceOrigin; |
| 509 | bool mustBeTight = !gpu->caps()->writePixelsRowBytesSupport(); |
| 510 | |
| 511 | size_t size = 0; |
| 512 | for (int i = 0; i < numLevels; ++i) { |
| 513 | size_t minRowBytes = srcData[i].info().minRowBytes(); |
| 514 | if (flip || (mustBeTight && srcData[i].rowBytes() != minRowBytes)) { |
| 515 | size += minRowBytes * srcData[i].height(); |
| 516 | } |
| 517 | } |
| 518 | |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 519 | std::unique_ptr<char[]> tempStorage; |
Brian Salomon | 07d8c0d | 2021-01-29 09:45:15 -0500 | [diff] [blame] | 520 | if (size) { |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 521 | tempStorage.reset(new char[size]); |
Brian Salomon | 07d8c0d | 2021-01-29 09:45:15 -0500 | [diff] [blame] | 522 | } |
| 523 | size = 0; |
| 524 | SkAutoSTArray<15, GrPixmap> tempPixmaps(numLevels); |
| 525 | for (int i = 0; i < numLevels; ++i) { |
| 526 | size_t minRowBytes = srcData[i].info().minRowBytes(); |
| 527 | if (flip || (mustBeTight && srcData[i].rowBytes() != minRowBytes)) { |
| 528 | tempPixmaps[i] = {srcData[i].info(), tempStorage.get() + size, minRowBytes}; |
| 529 | SkAssertResult(GrConvertPixels(tempPixmaps[i], srcData[i], flip)); |
| 530 | size += minRowBytes*srcData[i].height(); |
| 531 | } else { |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 532 | tempPixmaps[i] = srcData[i]; |
| 533 | } |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 534 | } |
Brian Salomon | 07d8c0d | 2021-01-29 09:45:15 -0500 | [diff] [blame] | 535 | |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 536 | GrGpu::BackendTextureData data(tempPixmaps.get()); |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 537 | return gpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data); |
| 538 | } |
| 539 | |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 540 | GrBackendTexture GrDirectContext::createBackendTexture(int width, int height, |
| 541 | const GrBackendFormat& backendFormat, |
| 542 | const SkColor4f& color, |
| 543 | GrMipmapped mipMapped, |
| 544 | GrRenderable renderable, |
| 545 | GrProtected isProtected, |
| 546 | GrGpuFinishedProc finishedProc, |
| 547 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 548 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 549 | |
| 550 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 551 | if (this->abandoned()) { |
| 552 | return {}; |
| 553 | } |
| 554 | |
| 555 | GrGpu::BackendTextureData data(color); |
| 556 | return create_and_update_backend_texture(this, {width, height}, |
| 557 | backendFormat, mipMapped, renderable, isProtected, |
| 558 | std::move(finishedCallback), &data); |
| 559 | } |
| 560 | |
| 561 | GrBackendTexture GrDirectContext::createBackendTexture(int width, int height, |
| 562 | SkColorType skColorType, |
| 563 | const SkColor4f& color, |
| 564 | GrMipmapped mipMapped, |
| 565 | GrRenderable renderable, |
| 566 | GrProtected isProtected, |
| 567 | GrGpuFinishedProc finishedProc, |
| 568 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 569 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 570 | |
| 571 | if (this->abandoned()) { |
| 572 | return {}; |
| 573 | } |
| 574 | |
| 575 | GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable); |
| 576 | if (!format.isValid()) { |
| 577 | return {}; |
| 578 | } |
| 579 | |
| 580 | GrColorType grColorType = SkColorTypeToGrColorType(skColorType); |
| 581 | SkColor4f swizzledColor = this->caps()->getWriteSwizzle(format, grColorType).applyTo(color); |
| 582 | |
| 583 | GrGpu::BackendTextureData data(swizzledColor); |
| 584 | return create_and_update_backend_texture(this, {width, height}, format, |
| 585 | mipMapped, renderable, isProtected, |
| 586 | std::move(finishedCallback), &data); |
| 587 | } |
| 588 | |
| 589 | GrBackendTexture GrDirectContext::createBackendTexture(const SkPixmap srcData[], |
| 590 | int numProvidedLevels, |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 591 | GrSurfaceOrigin textureOrigin, |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 592 | GrRenderable renderable, |
| 593 | GrProtected isProtected, |
| 594 | GrGpuFinishedProc finishedProc, |
| 595 | GrGpuFinishedContext finishedContext) { |
| 596 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 597 | |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 598 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 599 | |
| 600 | if (this->abandoned()) { |
| 601 | return {}; |
| 602 | } |
| 603 | |
| 604 | if (!srcData || numProvidedLevels <= 0) { |
| 605 | return {}; |
| 606 | } |
| 607 | |
| 608 | int baseWidth = srcData[0].width(); |
| 609 | int baseHeight = srcData[0].height(); |
| 610 | SkColorType colorType = srcData[0].colorType(); |
| 611 | |
| 612 | GrMipmapped mipMapped = GrMipmapped::kNo; |
| 613 | int numExpectedLevels = 1; |
| 614 | if (numProvidedLevels > 1) { |
| 615 | numExpectedLevels = SkMipmap::ComputeLevelCount(baseWidth, baseHeight) + 1; |
| 616 | mipMapped = GrMipmapped::kYes; |
| 617 | } |
| 618 | |
| 619 | if (numProvidedLevels != numExpectedLevels) { |
| 620 | return {}; |
| 621 | } |
| 622 | |
| 623 | GrBackendFormat backendFormat = this->defaultBackendFormat(colorType, renderable); |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 624 | GrBackendTexture beTex = this->createBackendTexture(srcData[0].width(), |
| 625 | srcData[0].height(), |
| 626 | backendFormat, |
| 627 | mipMapped, |
| 628 | renderable, |
| 629 | isProtected); |
| 630 | if (!beTex.isValid()) { |
| 631 | return {}; |
| 632 | } |
| 633 | if (!update_texture_with_pixmaps(this->priv().getGpu(), |
| 634 | srcData, |
| 635 | numProvidedLevels, |
| 636 | beTex, |
| 637 | textureOrigin, |
| 638 | std::move(finishedCallback))) { |
| 639 | this->deleteBackendTexture(beTex); |
| 640 | return {}; |
| 641 | } |
| 642 | return beTex; |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 643 | } |
| 644 | |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 645 | bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture, |
| 646 | const SkColor4f& color, |
| 647 | GrGpuFinishedProc finishedProc, |
| 648 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 649 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 650 | |
| 651 | if (this->abandoned()) { |
| 652 | return false; |
| 653 | } |
| 654 | |
| 655 | GrGpu::BackendTextureData data(color); |
| 656 | return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data); |
| 657 | } |
| 658 | |
| 659 | bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture, |
| 660 | SkColorType skColorType, |
| 661 | const SkColor4f& color, |
| 662 | GrGpuFinishedProc finishedProc, |
| 663 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 664 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 665 | |
| 666 | if (this->abandoned()) { |
| 667 | return false; |
| 668 | } |
| 669 | |
| 670 | GrBackendFormat format = backendTexture.getBackendFormat(); |
| 671 | GrColorType grColorType = SkColorTypeAndFormatToGrColorType(this->caps(), skColorType, format); |
| 672 | |
| 673 | if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, format)) { |
| 674 | return false; |
| 675 | } |
| 676 | |
| 677 | GrSwizzle swizzle = this->caps()->getWriteSwizzle(format, grColorType); |
| 678 | GrGpu::BackendTextureData data(swizzle.applyTo(color)); |
| 679 | |
| 680 | return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data); |
| 681 | } |
| 682 | |
| 683 | bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture, |
| 684 | const SkPixmap srcData[], |
| 685 | int numLevels, |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 686 | GrSurfaceOrigin textureOrigin, |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 687 | GrGpuFinishedProc finishedProc, |
| 688 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 689 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 690 | |
| 691 | if (this->abandoned()) { |
| 692 | return false; |
| 693 | } |
| 694 | |
| 695 | if (!srcData || numLevels <= 0) { |
| 696 | return false; |
| 697 | } |
| 698 | |
| 699 | int numExpectedLevels = 1; |
| 700 | if (backendTexture.hasMipmaps()) { |
| 701 | numExpectedLevels = SkMipmap::ComputeLevelCount(backendTexture.width(), |
| 702 | backendTexture.height()) + 1; |
| 703 | } |
| 704 | if (numLevels != numExpectedLevels) { |
| 705 | return false; |
| 706 | } |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 707 | return update_texture_with_pixmaps(fGpu.get(), |
| 708 | srcData, |
| 709 | numLevels, |
| 710 | backendTexture, |
| 711 | textureOrigin, |
| 712 | std::move(finishedCallback)); |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 713 | } |
| 714 | |
Adlai Holler | 64e1383 | 2020-10-13 08:21:56 -0400 | [diff] [blame] | 715 | ////////////////////////////////////////////////////////////////////////////// |
| 716 | |
| 717 | static GrBackendTexture create_and_update_compressed_backend_texture( |
| 718 | GrDirectContext* dContext, |
| 719 | SkISize dimensions, |
| 720 | const GrBackendFormat& backendFormat, |
| 721 | GrMipmapped mipMapped, |
| 722 | GrProtected isProtected, |
| 723 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 724 | const GrGpu::BackendTextureData* data) { |
| 725 | GrGpu* gpu = dContext->priv().getGpu(); |
| 726 | |
| 727 | GrBackendTexture beTex = gpu->createCompressedBackendTexture(dimensions, backendFormat, |
| 728 | mipMapped, isProtected); |
| 729 | if (!beTex.isValid()) { |
| 730 | return {}; |
| 731 | } |
| 732 | |
| 733 | if (!dContext->priv().getGpu()->updateCompressedBackendTexture( |
| 734 | beTex, std::move(finishedCallback), data)) { |
| 735 | dContext->deleteBackendTexture(beTex); |
| 736 | return {}; |
| 737 | } |
| 738 | return beTex; |
| 739 | } |
| 740 | |
| 741 | GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height, |
| 742 | const GrBackendFormat& backendFormat, |
| 743 | const SkColor4f& color, |
| 744 | GrMipmapped mipMapped, |
| 745 | GrProtected isProtected, |
| 746 | GrGpuFinishedProc finishedProc, |
| 747 | GrGpuFinishedContext finishedContext) { |
| 748 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 749 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 64e1383 | 2020-10-13 08:21:56 -0400 | [diff] [blame] | 750 | |
| 751 | if (this->abandoned()) { |
| 752 | return {}; |
| 753 | } |
| 754 | |
| 755 | GrGpu::BackendTextureData data(color); |
| 756 | return create_and_update_compressed_backend_texture(this, {width, height}, |
| 757 | backendFormat, mipMapped, isProtected, |
| 758 | std::move(finishedCallback), &data); |
| 759 | } |
| 760 | |
| 761 | GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height, |
| 762 | SkImage::CompressionType compression, |
| 763 | const SkColor4f& color, |
| 764 | GrMipmapped mipMapped, |
| 765 | GrProtected isProtected, |
| 766 | GrGpuFinishedProc finishedProc, |
| 767 | GrGpuFinishedContext finishedContext) { |
| 768 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 769 | GrBackendFormat format = this->compressedBackendFormat(compression); |
| 770 | return this->createCompressedBackendTexture(width, height, format, color, |
| 771 | mipMapped, isProtected, finishedProc, |
| 772 | finishedContext); |
| 773 | } |
| 774 | |
| 775 | GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height, |
| 776 | const GrBackendFormat& backendFormat, |
| 777 | const void* compressedData, |
| 778 | size_t dataSize, |
| 779 | GrMipmapped mipMapped, |
| 780 | GrProtected isProtected, |
| 781 | GrGpuFinishedProc finishedProc, |
| 782 | GrGpuFinishedContext finishedContext) { |
| 783 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 784 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 64e1383 | 2020-10-13 08:21:56 -0400 | [diff] [blame] | 785 | |
| 786 | if (this->abandoned()) { |
| 787 | return {}; |
| 788 | } |
| 789 | |
| 790 | GrGpu::BackendTextureData data(compressedData, dataSize); |
| 791 | return create_and_update_compressed_backend_texture(this, {width, height}, |
| 792 | backendFormat, mipMapped, isProtected, |
| 793 | std::move(finishedCallback), &data); |
| 794 | } |
| 795 | |
| 796 | GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height, |
| 797 | SkImage::CompressionType compression, |
| 798 | const void* data, size_t dataSize, |
| 799 | GrMipmapped mipMapped, |
| 800 | GrProtected isProtected, |
| 801 | GrGpuFinishedProc finishedProc, |
| 802 | GrGpuFinishedContext finishedContext) { |
| 803 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 804 | GrBackendFormat format = this->compressedBackendFormat(compression); |
| 805 | return this->createCompressedBackendTexture(width, height, format, data, dataSize, mipMapped, |
| 806 | isProtected, finishedProc, finishedContext); |
| 807 | } |
| 808 | |
| 809 | bool GrDirectContext::updateCompressedBackendTexture(const GrBackendTexture& backendTexture, |
| 810 | const SkColor4f& color, |
| 811 | GrGpuFinishedProc finishedProc, |
| 812 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 813 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 64e1383 | 2020-10-13 08:21:56 -0400 | [diff] [blame] | 814 | |
| 815 | if (this->abandoned()) { |
| 816 | return false; |
| 817 | } |
| 818 | |
| 819 | GrGpu::BackendTextureData data(color); |
| 820 | return fGpu->updateCompressedBackendTexture(backendTexture, std::move(finishedCallback), &data); |
| 821 | } |
| 822 | |
| 823 | bool GrDirectContext::updateCompressedBackendTexture(const GrBackendTexture& backendTexture, |
| 824 | const void* compressedData, |
| 825 | size_t dataSize, |
| 826 | GrGpuFinishedProc finishedProc, |
| 827 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 828 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 64e1383 | 2020-10-13 08:21:56 -0400 | [diff] [blame] | 829 | |
| 830 | if (this->abandoned()) { |
| 831 | return false; |
| 832 | } |
| 833 | |
| 834 | if (!compressedData) { |
| 835 | return false; |
| 836 | } |
| 837 | |
| 838 | GrGpu::BackendTextureData data(compressedData, dataSize); |
| 839 | |
| 840 | return fGpu->updateCompressedBackendTexture(backendTexture, std::move(finishedCallback), &data); |
| 841 | } |
| 842 | |
Adlai Holler | 6d0745b | 2020-10-13 13:29:00 -0400 | [diff] [blame] | 843 | ////////////////////////////////////////////////////////////////////////////// |
| 844 | |
| 845 | bool GrDirectContext::setBackendTextureState(const GrBackendTexture& backendTexture, |
| 846 | const GrBackendSurfaceMutableState& state, |
| 847 | GrBackendSurfaceMutableState* previousState, |
| 848 | GrGpuFinishedProc finishedProc, |
| 849 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 850 | auto callback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 6d0745b | 2020-10-13 13:29:00 -0400 | [diff] [blame] | 851 | |
| 852 | if (this->abandoned()) { |
| 853 | return false; |
| 854 | } |
| 855 | |
| 856 | return fGpu->setBackendTextureState(backendTexture, state, previousState, std::move(callback)); |
| 857 | } |
| 858 | |
| 859 | |
| 860 | bool GrDirectContext::setBackendRenderTargetState(const GrBackendRenderTarget& backendRenderTarget, |
| 861 | const GrBackendSurfaceMutableState& state, |
| 862 | GrBackendSurfaceMutableState* previousState, |
| 863 | GrGpuFinishedProc finishedProc, |
| 864 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 865 | auto callback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 6d0745b | 2020-10-13 13:29:00 -0400 | [diff] [blame] | 866 | |
| 867 | if (this->abandoned()) { |
| 868 | return false; |
| 869 | } |
| 870 | |
| 871 | return fGpu->setBackendRenderTargetState(backendRenderTarget, state, previousState, |
| 872 | std::move(callback)); |
| 873 | } |
| 874 | |
| 875 | void GrDirectContext::deleteBackendTexture(GrBackendTexture backendTex) { |
| 876 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 877 | // For the Vulkan backend we still must destroy the backend texture when the context is |
| 878 | // abandoned. |
| 879 | if ((this->abandoned() && this->backend() != GrBackendApi::kVulkan) || !backendTex.isValid()) { |
| 880 | return; |
| 881 | } |
| 882 | |
| 883 | fGpu->deleteBackendTexture(backendTex); |
| 884 | } |
| 885 | |
| 886 | ////////////////////////////////////////////////////////////////////////////// |
| 887 | |
| 888 | bool GrDirectContext::precompileShader(const SkData& key, const SkData& data) { |
| 889 | return fGpu->precompileShader(key, data); |
| 890 | } |
| 891 | |
| 892 | #ifdef SK_ENABLE_DUMP_GPU |
| 893 | #include "include/core/SkString.h" |
| 894 | #include "src/utils/SkJSONWriter.h" |
| 895 | SkString GrDirectContext::dump() const { |
| 896 | SkDynamicMemoryWStream stream; |
| 897 | SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty); |
| 898 | writer.beginObject(); |
| 899 | |
| 900 | writer.appendString("backend", GrBackendApiToStr(this->backend())); |
| 901 | |
| 902 | writer.appendName("caps"); |
| 903 | this->caps()->dumpJSON(&writer); |
| 904 | |
| 905 | writer.appendName("gpu"); |
| 906 | this->fGpu->dumpJSON(&writer); |
| 907 | |
| 908 | writer.appendName("context"); |
| 909 | this->dumpJSON(&writer); |
| 910 | |
| 911 | // Flush JSON to the memory stream |
| 912 | writer.endObject(); |
| 913 | writer.flush(); |
| 914 | |
| 915 | // Null terminate the JSON data in the memory stream |
| 916 | stream.write8(0); |
| 917 | |
| 918 | // Allocate a string big enough to hold all the data, then copy out of the stream |
| 919 | SkString result(stream.bytesWritten()); |
| 920 | stream.copyToAndReset(result.writable_str()); |
| 921 | return result; |
| 922 | } |
| 923 | #endif |
| 924 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 925 | #ifdef SK_GL |
Robert Phillips | c7228c6 | 2020-07-14 12:57:39 -0400 | [diff] [blame] | 926 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 927 | /*************************************************************************************************/ |
| 928 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 929 | GrContextOptions defaultOptions; |
Jim Van Verth | 03b8ab2 | 2020-02-24 11:36:15 -0500 | [diff] [blame] | 930 | return MakeGL(std::move(glInterface), defaultOptions); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 931 | } |
| 932 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 933 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(const GrContextOptions& options) { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 934 | return MakeGL(nullptr, options); |
| 935 | } |
| 936 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 937 | sk_sp<GrDirectContext> GrDirectContext::MakeGL() { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 938 | GrContextOptions defaultOptions; |
| 939 | return MakeGL(nullptr, defaultOptions); |
| 940 | } |
| 941 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 942 | #if GR_TEST_UTILS |
| 943 | GrGLFunction<GrGLGetErrorFn> make_get_error_with_random_oom(GrGLFunction<GrGLGetErrorFn> original) { |
| 944 | // A SkRandom and a GrGLFunction<GrGLGetErrorFn> are too big to be captured by a |
| 945 | // GrGLFunction<GrGLGetError> (surprise, surprise). So we make a context object and |
| 946 | // capture that by pointer. However, GrGLFunction doesn't support calling a destructor |
| 947 | // on the thing it captures. So we leak the context. |
| 948 | struct GetErrorContext { |
| 949 | SkRandom fRandom; |
| 950 | GrGLFunction<GrGLGetErrorFn> fGetError; |
| 951 | }; |
| 952 | |
| 953 | auto errorContext = new GetErrorContext; |
| 954 | |
| 955 | #if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 956 | __lsan_ignore_object(errorContext); |
| 957 | #endif |
| 958 | |
| 959 | errorContext->fGetError = original; |
| 960 | |
| 961 | return GrGLFunction<GrGLGetErrorFn>([errorContext]() { |
| 962 | GrGLenum error = errorContext->fGetError(); |
| 963 | if (error == GR_GL_NO_ERROR && (errorContext->fRandom.nextU() % 300) == 0) { |
| 964 | error = GR_GL_OUT_OF_MEMORY; |
| 965 | } |
| 966 | return error; |
| 967 | }); |
| 968 | } |
| 969 | #endif |
| 970 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 971 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface, |
| 972 | const GrContextOptions& options) { |
| 973 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kOpenGL, options)); |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 974 | #if GR_TEST_UTILS |
| 975 | if (options.fRandomGLOOM) { |
| 976 | auto copy = sk_make_sp<GrGLInterface>(*glInterface); |
| 977 | copy->fFunctions.fGetError = |
| 978 | make_get_error_with_random_oom(glInterface->fFunctions.fGetError); |
| 979 | #if GR_GL_CHECK_ERROR |
| 980 | // Suppress logging GL errors since we'll be synthetically generating them. |
| 981 | copy->suppressErrorLogging(); |
| 982 | #endif |
| 983 | glInterface = std::move(copy); |
| 984 | } |
| 985 | #endif |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 986 | direct->fGpu = GrGLGpu::Make(std::move(glInterface), options, direct.get()); |
| 987 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 988 | return nullptr; |
| 989 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 990 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 991 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 992 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 993 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 994 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 995 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions) { |
| 996 | GrContextOptions defaultOptions; |
| 997 | return MakeMock(mockOptions, defaultOptions); |
| 998 | } |
| 999 | |
| 1000 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions, |
| 1001 | const GrContextOptions& options) { |
| 1002 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMock, options)); |
| 1003 | |
| 1004 | direct->fGpu = GrMockGpu::Make(mockOptions, options, direct.get()); |
| 1005 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1006 | return nullptr; |
| 1007 | } |
Chris Dalton | a378b45 | 2019-12-11 13:24:11 -0500 | [diff] [blame] | 1008 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1009 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1010 | } |
| 1011 | |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 1012 | #ifdef SK_VULKAN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1013 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1014 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext) { |
| 1015 | GrContextOptions defaultOptions; |
| 1016 | return MakeVulkan(backendContext, defaultOptions); |
| 1017 | } |
| 1018 | |
| 1019 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext, |
| 1020 | const GrContextOptions& options) { |
| 1021 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kVulkan, options)); |
| 1022 | |
| 1023 | direct->fGpu = GrVkGpu::Make(backendContext, options, direct.get()); |
| 1024 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1025 | return nullptr; |
| 1026 | } |
| 1027 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1028 | return direct; |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 1029 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1030 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1031 | |
| 1032 | #ifdef SK_METAL |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1033 | /*************************************************************************************************/ |
Jim Van Verth | 351c9b5 | 2020-11-12 15:21:11 -0500 | [diff] [blame] | 1034 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(const GrMtlBackendContext& backendContext) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1035 | GrContextOptions defaultOptions; |
Jim Van Verth | 351c9b5 | 2020-11-12 15:21:11 -0500 | [diff] [blame] | 1036 | return MakeMetal(backendContext, defaultOptions); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1037 | } |
| 1038 | |
Jim Van Verth | 351c9b5 | 2020-11-12 15:21:11 -0500 | [diff] [blame] | 1039 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(const GrMtlBackendContext& backendContext, |
| 1040 | const GrContextOptions& options) { |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1041 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options)); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1042 | |
Jim Van Verth | 351c9b5 | 2020-11-12 15:21:11 -0500 | [diff] [blame] | 1043 | direct->fGpu = GrMtlTrampoline::MakeGpu(backendContext, options, direct.get()); |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1044 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1045 | return nullptr; |
| 1046 | } |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 1047 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1048 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1049 | } |
Jim Van Verth | 351c9b5 | 2020-11-12 15:21:11 -0500 | [diff] [blame] | 1050 | |
| 1051 | // deprecated |
| 1052 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue) { |
| 1053 | GrContextOptions defaultOptions; |
| 1054 | return MakeMetal(device, queue, defaultOptions); |
| 1055 | } |
| 1056 | |
| 1057 | // deprecated |
| 1058 | // remove include/gpu/mtl/GrMtlBackendContext.h, above, when removed |
| 1059 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue, |
| 1060 | const GrContextOptions& options) { |
| 1061 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options)); |
| 1062 | GrMtlBackendContext backendContext = {}; |
| 1063 | backendContext.fDevice.reset(device); |
| 1064 | backendContext.fQueue.reset(queue); |
| 1065 | |
| 1066 | return GrDirectContext::MakeMetal(backendContext, options); |
| 1067 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1068 | #endif |
| 1069 | |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1070 | #ifdef SK_DIRECT3D |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1071 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1072 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext) { |
| 1073 | GrContextOptions defaultOptions; |
| 1074 | return MakeDirect3D(backendContext, defaultOptions); |
| 1075 | } |
| 1076 | |
| 1077 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext, |
| 1078 | const GrContextOptions& options) { |
| 1079 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDirect3D, options)); |
| 1080 | |
| 1081 | direct->fGpu = GrD3DGpu::Make(backendContext, options, direct.get()); |
| 1082 | if (!direct->init()) { |
Jim Van Verth | d2d4c5e | 2020-02-19 14:57:58 -0500 | [diff] [blame] | 1083 | return nullptr; |
| 1084 | } |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1085 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1086 | return direct; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1087 | } |
| 1088 | #endif |
| 1089 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1090 | #ifdef SK_DAWN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1091 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1092 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1093 | GrContextOptions defaultOptions; |
| 1094 | return MakeDawn(device, defaultOptions); |
| 1095 | } |
| 1096 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1097 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device, |
| 1098 | const GrContextOptions& options) { |
| 1099 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDawn, options)); |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1100 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1101 | direct->fGpu = GrDawnGpu::Make(device, options, direct.get()); |
| 1102 | if (!direct->init()) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1103 | return nullptr; |
| 1104 | } |
| 1105 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1106 | return direct; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1107 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1108 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1109 | #endif |