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) { |
| 508 | std::unique_ptr<char[]> tempStorage; |
Brian Salomon | 07d8c0d | 2021-01-29 09:45:15 -0500 | [diff] [blame] | 509 | SkAutoSTArray<15, GrPixmap> tempPixmaps(numLevels); |
Mike Klein | 0928963 | 2021-01-30 15:51:19 +0000 | [diff] [blame^] | 510 | if (textureOrigin == kBottomLeft_GrSurfaceOrigin) { |
| 511 | size_t size = 0; |
| 512 | for (int i = 0; i < numLevels; ++i) { |
| 513 | size += srcData[i].info().minRowBytes()*srcData[i].height(); |
| 514 | } |
| 515 | tempStorage.reset(new char[size]); |
| 516 | size = 0; |
| 517 | for (int i = 0; i < numLevels; ++i) { |
| 518 | size_t tempRB = srcData[i].info().minRowBytes(); |
| 519 | tempPixmaps[i] = {srcData[i].info(), tempStorage.get() + size, tempRB}; |
| 520 | SkAssertResult(GrConvertPixels(tempPixmaps[i], srcData[i], /*flip*/ true)); |
| 521 | size += tempRB*srcData[i].height(); |
| 522 | } |
| 523 | } else { |
| 524 | for (int i = 0; i < numLevels; ++i) { |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 525 | tempPixmaps[i] = srcData[i]; |
| 526 | } |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 527 | } |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 528 | GrGpu::BackendTextureData data(tempPixmaps.get()); |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 529 | return gpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data); |
| 530 | } |
| 531 | |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 532 | GrBackendTexture GrDirectContext::createBackendTexture(int width, int height, |
| 533 | const GrBackendFormat& backendFormat, |
| 534 | const SkColor4f& color, |
| 535 | GrMipmapped mipMapped, |
| 536 | GrRenderable renderable, |
| 537 | GrProtected isProtected, |
| 538 | GrGpuFinishedProc finishedProc, |
| 539 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 540 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 541 | |
| 542 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 543 | if (this->abandoned()) { |
| 544 | return {}; |
| 545 | } |
| 546 | |
| 547 | GrGpu::BackendTextureData data(color); |
| 548 | return create_and_update_backend_texture(this, {width, height}, |
| 549 | backendFormat, mipMapped, renderable, isProtected, |
| 550 | std::move(finishedCallback), &data); |
| 551 | } |
| 552 | |
| 553 | GrBackendTexture GrDirectContext::createBackendTexture(int width, int height, |
| 554 | SkColorType skColorType, |
| 555 | const SkColor4f& color, |
| 556 | GrMipmapped mipMapped, |
| 557 | GrRenderable renderable, |
| 558 | GrProtected isProtected, |
| 559 | GrGpuFinishedProc finishedProc, |
| 560 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 561 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 562 | |
| 563 | if (this->abandoned()) { |
| 564 | return {}; |
| 565 | } |
| 566 | |
| 567 | GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable); |
| 568 | if (!format.isValid()) { |
| 569 | return {}; |
| 570 | } |
| 571 | |
| 572 | GrColorType grColorType = SkColorTypeToGrColorType(skColorType); |
| 573 | SkColor4f swizzledColor = this->caps()->getWriteSwizzle(format, grColorType).applyTo(color); |
| 574 | |
| 575 | GrGpu::BackendTextureData data(swizzledColor); |
| 576 | return create_and_update_backend_texture(this, {width, height}, format, |
| 577 | mipMapped, renderable, isProtected, |
| 578 | std::move(finishedCallback), &data); |
| 579 | } |
| 580 | |
| 581 | GrBackendTexture GrDirectContext::createBackendTexture(const SkPixmap srcData[], |
| 582 | int numProvidedLevels, |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 583 | GrSurfaceOrigin textureOrigin, |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 584 | GrRenderable renderable, |
| 585 | GrProtected isProtected, |
| 586 | GrGpuFinishedProc finishedProc, |
| 587 | GrGpuFinishedContext finishedContext) { |
| 588 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 589 | |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 590 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 591 | |
| 592 | if (this->abandoned()) { |
| 593 | return {}; |
| 594 | } |
| 595 | |
| 596 | if (!srcData || numProvidedLevels <= 0) { |
| 597 | return {}; |
| 598 | } |
| 599 | |
| 600 | int baseWidth = srcData[0].width(); |
| 601 | int baseHeight = srcData[0].height(); |
| 602 | SkColorType colorType = srcData[0].colorType(); |
| 603 | |
| 604 | GrMipmapped mipMapped = GrMipmapped::kNo; |
| 605 | int numExpectedLevels = 1; |
| 606 | if (numProvidedLevels > 1) { |
| 607 | numExpectedLevels = SkMipmap::ComputeLevelCount(baseWidth, baseHeight) + 1; |
| 608 | mipMapped = GrMipmapped::kYes; |
| 609 | } |
| 610 | |
| 611 | if (numProvidedLevels != numExpectedLevels) { |
| 612 | return {}; |
| 613 | } |
| 614 | |
| 615 | GrBackendFormat backendFormat = this->defaultBackendFormat(colorType, renderable); |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 616 | GrBackendTexture beTex = this->createBackendTexture(srcData[0].width(), |
| 617 | srcData[0].height(), |
| 618 | backendFormat, |
| 619 | mipMapped, |
| 620 | renderable, |
| 621 | isProtected); |
| 622 | if (!beTex.isValid()) { |
| 623 | return {}; |
| 624 | } |
| 625 | if (!update_texture_with_pixmaps(this->priv().getGpu(), |
| 626 | srcData, |
| 627 | numProvidedLevels, |
| 628 | beTex, |
| 629 | textureOrigin, |
| 630 | std::move(finishedCallback))) { |
| 631 | this->deleteBackendTexture(beTex); |
| 632 | return {}; |
| 633 | } |
| 634 | return beTex; |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame] | 635 | } |
| 636 | |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 637 | bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture, |
| 638 | const SkColor4f& color, |
| 639 | GrGpuFinishedProc finishedProc, |
| 640 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 641 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 642 | |
| 643 | if (this->abandoned()) { |
| 644 | return false; |
| 645 | } |
| 646 | |
| 647 | GrGpu::BackendTextureData data(color); |
| 648 | return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data); |
| 649 | } |
| 650 | |
| 651 | bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture, |
| 652 | SkColorType skColorType, |
| 653 | const SkColor4f& color, |
| 654 | GrGpuFinishedProc finishedProc, |
| 655 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 656 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 657 | |
| 658 | if (this->abandoned()) { |
| 659 | return false; |
| 660 | } |
| 661 | |
| 662 | GrBackendFormat format = backendTexture.getBackendFormat(); |
| 663 | GrColorType grColorType = SkColorTypeAndFormatToGrColorType(this->caps(), skColorType, format); |
| 664 | |
| 665 | if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, format)) { |
| 666 | return false; |
| 667 | } |
| 668 | |
| 669 | GrSwizzle swizzle = this->caps()->getWriteSwizzle(format, grColorType); |
| 670 | GrGpu::BackendTextureData data(swizzle.applyTo(color)); |
| 671 | |
| 672 | return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data); |
| 673 | } |
| 674 | |
| 675 | bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture, |
| 676 | const SkPixmap srcData[], |
| 677 | int numLevels, |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 678 | GrSurfaceOrigin textureOrigin, |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 679 | GrGpuFinishedProc finishedProc, |
| 680 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 681 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 682 | |
| 683 | if (this->abandoned()) { |
| 684 | return false; |
| 685 | } |
| 686 | |
| 687 | if (!srcData || numLevels <= 0) { |
| 688 | return false; |
| 689 | } |
| 690 | |
| 691 | int numExpectedLevels = 1; |
| 692 | if (backendTexture.hasMipmaps()) { |
| 693 | numExpectedLevels = SkMipmap::ComputeLevelCount(backendTexture.width(), |
| 694 | backendTexture.height()) + 1; |
| 695 | } |
| 696 | if (numLevels != numExpectedLevels) { |
| 697 | return false; |
| 698 | } |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 699 | return update_texture_with_pixmaps(fGpu.get(), |
| 700 | srcData, |
| 701 | numLevels, |
| 702 | backendTexture, |
| 703 | textureOrigin, |
| 704 | std::move(finishedCallback)); |
Adlai Holler | 2e0c70d | 2020-10-13 08:21:37 -0400 | [diff] [blame] | 705 | } |
| 706 | |
Adlai Holler | 64e1383 | 2020-10-13 08:21:56 -0400 | [diff] [blame] | 707 | ////////////////////////////////////////////////////////////////////////////// |
| 708 | |
| 709 | static GrBackendTexture create_and_update_compressed_backend_texture( |
| 710 | GrDirectContext* dContext, |
| 711 | SkISize dimensions, |
| 712 | const GrBackendFormat& backendFormat, |
| 713 | GrMipmapped mipMapped, |
| 714 | GrProtected isProtected, |
| 715 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 716 | const GrGpu::BackendTextureData* data) { |
| 717 | GrGpu* gpu = dContext->priv().getGpu(); |
| 718 | |
| 719 | GrBackendTexture beTex = gpu->createCompressedBackendTexture(dimensions, backendFormat, |
| 720 | mipMapped, isProtected); |
| 721 | if (!beTex.isValid()) { |
| 722 | return {}; |
| 723 | } |
| 724 | |
| 725 | if (!dContext->priv().getGpu()->updateCompressedBackendTexture( |
| 726 | beTex, std::move(finishedCallback), data)) { |
| 727 | dContext->deleteBackendTexture(beTex); |
| 728 | return {}; |
| 729 | } |
| 730 | return beTex; |
| 731 | } |
| 732 | |
| 733 | GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height, |
| 734 | const GrBackendFormat& backendFormat, |
| 735 | const SkColor4f& color, |
| 736 | GrMipmapped mipMapped, |
| 737 | GrProtected isProtected, |
| 738 | GrGpuFinishedProc finishedProc, |
| 739 | GrGpuFinishedContext finishedContext) { |
| 740 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 741 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 64e1383 | 2020-10-13 08:21:56 -0400 | [diff] [blame] | 742 | |
| 743 | if (this->abandoned()) { |
| 744 | return {}; |
| 745 | } |
| 746 | |
| 747 | GrGpu::BackendTextureData data(color); |
| 748 | return create_and_update_compressed_backend_texture(this, {width, height}, |
| 749 | backendFormat, mipMapped, isProtected, |
| 750 | std::move(finishedCallback), &data); |
| 751 | } |
| 752 | |
| 753 | GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height, |
| 754 | SkImage::CompressionType compression, |
| 755 | const SkColor4f& color, |
| 756 | GrMipmapped mipMapped, |
| 757 | GrProtected isProtected, |
| 758 | GrGpuFinishedProc finishedProc, |
| 759 | GrGpuFinishedContext finishedContext) { |
| 760 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 761 | GrBackendFormat format = this->compressedBackendFormat(compression); |
| 762 | return this->createCompressedBackendTexture(width, height, format, color, |
| 763 | mipMapped, isProtected, finishedProc, |
| 764 | finishedContext); |
| 765 | } |
| 766 | |
| 767 | GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height, |
| 768 | const GrBackendFormat& backendFormat, |
| 769 | const void* compressedData, |
| 770 | size_t dataSize, |
| 771 | GrMipmapped mipMapped, |
| 772 | GrProtected isProtected, |
| 773 | GrGpuFinishedProc finishedProc, |
| 774 | GrGpuFinishedContext finishedContext) { |
| 775 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 776 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 64e1383 | 2020-10-13 08:21:56 -0400 | [diff] [blame] | 777 | |
| 778 | if (this->abandoned()) { |
| 779 | return {}; |
| 780 | } |
| 781 | |
| 782 | GrGpu::BackendTextureData data(compressedData, dataSize); |
| 783 | return create_and_update_compressed_backend_texture(this, {width, height}, |
| 784 | backendFormat, mipMapped, isProtected, |
| 785 | std::move(finishedCallback), &data); |
| 786 | } |
| 787 | |
| 788 | GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height, |
| 789 | SkImage::CompressionType compression, |
| 790 | const void* data, size_t dataSize, |
| 791 | GrMipmapped mipMapped, |
| 792 | GrProtected isProtected, |
| 793 | GrGpuFinishedProc finishedProc, |
| 794 | GrGpuFinishedContext finishedContext) { |
| 795 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 796 | GrBackendFormat format = this->compressedBackendFormat(compression); |
| 797 | return this->createCompressedBackendTexture(width, height, format, data, dataSize, mipMapped, |
| 798 | isProtected, finishedProc, finishedContext); |
| 799 | } |
| 800 | |
| 801 | bool GrDirectContext::updateCompressedBackendTexture(const GrBackendTexture& backendTexture, |
| 802 | const SkColor4f& color, |
| 803 | GrGpuFinishedProc finishedProc, |
| 804 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 805 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 64e1383 | 2020-10-13 08:21:56 -0400 | [diff] [blame] | 806 | |
| 807 | if (this->abandoned()) { |
| 808 | return false; |
| 809 | } |
| 810 | |
| 811 | GrGpu::BackendTextureData data(color); |
| 812 | return fGpu->updateCompressedBackendTexture(backendTexture, std::move(finishedCallback), &data); |
| 813 | } |
| 814 | |
| 815 | bool GrDirectContext::updateCompressedBackendTexture(const GrBackendTexture& backendTexture, |
| 816 | const void* compressedData, |
| 817 | size_t dataSize, |
| 818 | GrGpuFinishedProc finishedProc, |
| 819 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 820 | auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 64e1383 | 2020-10-13 08:21:56 -0400 | [diff] [blame] | 821 | |
| 822 | if (this->abandoned()) { |
| 823 | return false; |
| 824 | } |
| 825 | |
| 826 | if (!compressedData) { |
| 827 | return false; |
| 828 | } |
| 829 | |
| 830 | GrGpu::BackendTextureData data(compressedData, dataSize); |
| 831 | |
| 832 | return fGpu->updateCompressedBackendTexture(backendTexture, std::move(finishedCallback), &data); |
| 833 | } |
| 834 | |
Adlai Holler | 6d0745b | 2020-10-13 13:29:00 -0400 | [diff] [blame] | 835 | ////////////////////////////////////////////////////////////////////////////// |
| 836 | |
| 837 | bool GrDirectContext::setBackendTextureState(const GrBackendTexture& backendTexture, |
| 838 | const GrBackendSurfaceMutableState& state, |
| 839 | GrBackendSurfaceMutableState* previousState, |
| 840 | GrGpuFinishedProc finishedProc, |
| 841 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 842 | auto callback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 6d0745b | 2020-10-13 13:29:00 -0400 | [diff] [blame] | 843 | |
| 844 | if (this->abandoned()) { |
| 845 | return false; |
| 846 | } |
| 847 | |
| 848 | return fGpu->setBackendTextureState(backendTexture, state, previousState, std::move(callback)); |
| 849 | } |
| 850 | |
| 851 | |
| 852 | bool GrDirectContext::setBackendRenderTargetState(const GrBackendRenderTarget& backendRenderTarget, |
| 853 | const GrBackendSurfaceMutableState& state, |
| 854 | GrBackendSurfaceMutableState* previousState, |
| 855 | GrGpuFinishedProc finishedProc, |
| 856 | GrGpuFinishedContext finishedContext) { |
Brian Salomon | 694ff17 | 2020-11-04 16:54:28 -0500 | [diff] [blame] | 857 | auto callback = GrRefCntedCallback::Make(finishedProc, finishedContext); |
Adlai Holler | 6d0745b | 2020-10-13 13:29:00 -0400 | [diff] [blame] | 858 | |
| 859 | if (this->abandoned()) { |
| 860 | return false; |
| 861 | } |
| 862 | |
| 863 | return fGpu->setBackendRenderTargetState(backendRenderTarget, state, previousState, |
| 864 | std::move(callback)); |
| 865 | } |
| 866 | |
| 867 | void GrDirectContext::deleteBackendTexture(GrBackendTexture backendTex) { |
| 868 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 869 | // For the Vulkan backend we still must destroy the backend texture when the context is |
| 870 | // abandoned. |
| 871 | if ((this->abandoned() && this->backend() != GrBackendApi::kVulkan) || !backendTex.isValid()) { |
| 872 | return; |
| 873 | } |
| 874 | |
| 875 | fGpu->deleteBackendTexture(backendTex); |
| 876 | } |
| 877 | |
| 878 | ////////////////////////////////////////////////////////////////////////////// |
| 879 | |
| 880 | bool GrDirectContext::precompileShader(const SkData& key, const SkData& data) { |
| 881 | return fGpu->precompileShader(key, data); |
| 882 | } |
| 883 | |
| 884 | #ifdef SK_ENABLE_DUMP_GPU |
| 885 | #include "include/core/SkString.h" |
| 886 | #include "src/utils/SkJSONWriter.h" |
| 887 | SkString GrDirectContext::dump() const { |
| 888 | SkDynamicMemoryWStream stream; |
| 889 | SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty); |
| 890 | writer.beginObject(); |
| 891 | |
| 892 | writer.appendString("backend", GrBackendApiToStr(this->backend())); |
| 893 | |
| 894 | writer.appendName("caps"); |
| 895 | this->caps()->dumpJSON(&writer); |
| 896 | |
| 897 | writer.appendName("gpu"); |
| 898 | this->fGpu->dumpJSON(&writer); |
| 899 | |
| 900 | writer.appendName("context"); |
| 901 | this->dumpJSON(&writer); |
| 902 | |
| 903 | // Flush JSON to the memory stream |
| 904 | writer.endObject(); |
| 905 | writer.flush(); |
| 906 | |
| 907 | // Null terminate the JSON data in the memory stream |
| 908 | stream.write8(0); |
| 909 | |
| 910 | // Allocate a string big enough to hold all the data, then copy out of the stream |
| 911 | SkString result(stream.bytesWritten()); |
| 912 | stream.copyToAndReset(result.writable_str()); |
| 913 | return result; |
| 914 | } |
| 915 | #endif |
| 916 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 917 | #ifdef SK_GL |
Robert Phillips | c7228c6 | 2020-07-14 12:57:39 -0400 | [diff] [blame] | 918 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 919 | /*************************************************************************************************/ |
| 920 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 921 | GrContextOptions defaultOptions; |
Jim Van Verth | 03b8ab2 | 2020-02-24 11:36:15 -0500 | [diff] [blame] | 922 | return MakeGL(std::move(glInterface), defaultOptions); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 923 | } |
| 924 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 925 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(const GrContextOptions& options) { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 926 | return MakeGL(nullptr, options); |
| 927 | } |
| 928 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 929 | sk_sp<GrDirectContext> GrDirectContext::MakeGL() { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 930 | GrContextOptions defaultOptions; |
| 931 | return MakeGL(nullptr, defaultOptions); |
| 932 | } |
| 933 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 934 | #if GR_TEST_UTILS |
| 935 | GrGLFunction<GrGLGetErrorFn> make_get_error_with_random_oom(GrGLFunction<GrGLGetErrorFn> original) { |
| 936 | // A SkRandom and a GrGLFunction<GrGLGetErrorFn> are too big to be captured by a |
| 937 | // GrGLFunction<GrGLGetError> (surprise, surprise). So we make a context object and |
| 938 | // capture that by pointer. However, GrGLFunction doesn't support calling a destructor |
| 939 | // on the thing it captures. So we leak the context. |
| 940 | struct GetErrorContext { |
| 941 | SkRandom fRandom; |
| 942 | GrGLFunction<GrGLGetErrorFn> fGetError; |
| 943 | }; |
| 944 | |
| 945 | auto errorContext = new GetErrorContext; |
| 946 | |
| 947 | #if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 948 | __lsan_ignore_object(errorContext); |
| 949 | #endif |
| 950 | |
| 951 | errorContext->fGetError = original; |
| 952 | |
| 953 | return GrGLFunction<GrGLGetErrorFn>([errorContext]() { |
| 954 | GrGLenum error = errorContext->fGetError(); |
| 955 | if (error == GR_GL_NO_ERROR && (errorContext->fRandom.nextU() % 300) == 0) { |
| 956 | error = GR_GL_OUT_OF_MEMORY; |
| 957 | } |
| 958 | return error; |
| 959 | }); |
| 960 | } |
| 961 | #endif |
| 962 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 963 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface, |
| 964 | const GrContextOptions& options) { |
| 965 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kOpenGL, options)); |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 966 | #if GR_TEST_UTILS |
| 967 | if (options.fRandomGLOOM) { |
| 968 | auto copy = sk_make_sp<GrGLInterface>(*glInterface); |
| 969 | copy->fFunctions.fGetError = |
| 970 | make_get_error_with_random_oom(glInterface->fFunctions.fGetError); |
| 971 | #if GR_GL_CHECK_ERROR |
| 972 | // Suppress logging GL errors since we'll be synthetically generating them. |
| 973 | copy->suppressErrorLogging(); |
| 974 | #endif |
| 975 | glInterface = std::move(copy); |
| 976 | } |
| 977 | #endif |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 978 | direct->fGpu = GrGLGpu::Make(std::move(glInterface), options, direct.get()); |
| 979 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 980 | return nullptr; |
| 981 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 982 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 983 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 984 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 985 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 986 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 987 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions) { |
| 988 | GrContextOptions defaultOptions; |
| 989 | return MakeMock(mockOptions, defaultOptions); |
| 990 | } |
| 991 | |
| 992 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions, |
| 993 | const GrContextOptions& options) { |
| 994 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMock, options)); |
| 995 | |
| 996 | direct->fGpu = GrMockGpu::Make(mockOptions, options, direct.get()); |
| 997 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 998 | return nullptr; |
| 999 | } |
Chris Dalton | a378b45 | 2019-12-11 13:24:11 -0500 | [diff] [blame] | 1000 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1001 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1002 | } |
| 1003 | |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 1004 | #ifdef SK_VULKAN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1005 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1006 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext) { |
| 1007 | GrContextOptions defaultOptions; |
| 1008 | return MakeVulkan(backendContext, defaultOptions); |
| 1009 | } |
| 1010 | |
| 1011 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext, |
| 1012 | const GrContextOptions& options) { |
| 1013 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kVulkan, options)); |
| 1014 | |
| 1015 | direct->fGpu = GrVkGpu::Make(backendContext, options, direct.get()); |
| 1016 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1017 | return nullptr; |
| 1018 | } |
| 1019 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1020 | return direct; |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 1021 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1022 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1023 | |
| 1024 | #ifdef SK_METAL |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1025 | /*************************************************************************************************/ |
Jim Van Verth | 351c9b5 | 2020-11-12 15:21:11 -0500 | [diff] [blame] | 1026 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(const GrMtlBackendContext& backendContext) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1027 | GrContextOptions defaultOptions; |
Jim Van Verth | 351c9b5 | 2020-11-12 15:21:11 -0500 | [diff] [blame] | 1028 | return MakeMetal(backendContext, defaultOptions); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1029 | } |
| 1030 | |
Jim Van Verth | 351c9b5 | 2020-11-12 15:21:11 -0500 | [diff] [blame] | 1031 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(const GrMtlBackendContext& backendContext, |
| 1032 | const GrContextOptions& options) { |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1033 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options)); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1034 | |
Jim Van Verth | 351c9b5 | 2020-11-12 15:21:11 -0500 | [diff] [blame] | 1035 | direct->fGpu = GrMtlTrampoline::MakeGpu(backendContext, options, direct.get()); |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1036 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1037 | return nullptr; |
| 1038 | } |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 1039 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1040 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1041 | } |
Jim Van Verth | 351c9b5 | 2020-11-12 15:21:11 -0500 | [diff] [blame] | 1042 | |
| 1043 | // deprecated |
| 1044 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue) { |
| 1045 | GrContextOptions defaultOptions; |
| 1046 | return MakeMetal(device, queue, defaultOptions); |
| 1047 | } |
| 1048 | |
| 1049 | // deprecated |
| 1050 | // remove include/gpu/mtl/GrMtlBackendContext.h, above, when removed |
| 1051 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue, |
| 1052 | const GrContextOptions& options) { |
| 1053 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options)); |
| 1054 | GrMtlBackendContext backendContext = {}; |
| 1055 | backendContext.fDevice.reset(device); |
| 1056 | backendContext.fQueue.reset(queue); |
| 1057 | |
| 1058 | return GrDirectContext::MakeMetal(backendContext, options); |
| 1059 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1060 | #endif |
| 1061 | |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1062 | #ifdef SK_DIRECT3D |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1063 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1064 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext) { |
| 1065 | GrContextOptions defaultOptions; |
| 1066 | return MakeDirect3D(backendContext, defaultOptions); |
| 1067 | } |
| 1068 | |
| 1069 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext, |
| 1070 | const GrContextOptions& options) { |
| 1071 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDirect3D, options)); |
| 1072 | |
| 1073 | direct->fGpu = GrD3DGpu::Make(backendContext, options, direct.get()); |
| 1074 | if (!direct->init()) { |
Jim Van Verth | d2d4c5e | 2020-02-19 14:57:58 -0500 | [diff] [blame] | 1075 | return nullptr; |
| 1076 | } |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1077 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1078 | return direct; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 1079 | } |
| 1080 | #endif |
| 1081 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1082 | #ifdef SK_DAWN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1083 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1084 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1085 | GrContextOptions defaultOptions; |
| 1086 | return MakeDawn(device, defaultOptions); |
| 1087 | } |
| 1088 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1089 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device, |
| 1090 | const GrContextOptions& options) { |
| 1091 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDawn, options)); |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1092 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1093 | direct->fGpu = GrDawnGpu::Make(device, options, direct.get()); |
| 1094 | if (!direct->init()) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1095 | return nullptr; |
| 1096 | } |
| 1097 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1098 | return direct; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1099 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 1100 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1101 | #endif |