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/GrContextPriv.h" |
| 16 | #include "src/gpu/GrContextThreadSafeProxyPriv.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 |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 31 | #include "src/gpu/mtl/GrMtlTrampoline.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 32 | #endif |
| 33 | #ifdef SK_VULKAN |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 34 | #include "src/gpu/vk/GrVkGpu.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 35 | #endif |
Jim Van Verth | d2d4c5e | 2020-02-19 14:57:58 -0500 | [diff] [blame] | 36 | #ifdef SK_DIRECT3D |
| 37 | #include "src/gpu/d3d/GrD3DGpu.h" |
| 38 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 39 | #ifdef SK_DAWN |
Mike Klein | 52337de | 2019-07-25 09:00:52 -0500 | [diff] [blame] | 40 | #include "src/gpu/dawn/GrDawnGpu.h" |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 41 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 42 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 43 | #if GR_TEST_UTILS |
| 44 | # include "include/utils/SkRandom.h" |
| 45 | # if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 46 | # include <sanitizer/lsan_interface.h> |
| 47 | # endif |
| 48 | #endif |
| 49 | |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 50 | #ifdef SK_DISABLE_REDUCE_OPLIST_SPLITTING |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 51 | static const bool kDefaultReduceOpsTaskSplitting = false; |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 52 | #else |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 53 | static const bool kDefaultReduceOpsTaskSplitting = false; |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 54 | #endif |
| 55 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 56 | #define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(this->singleOwner()) |
| 57 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 58 | GrDirectContext::GrDirectContext(GrBackendApi backend, const GrContextOptions& options) |
Robert Phillips | 3262bc8 | 2020-08-10 12:11:58 -0400 | [diff] [blame] | 59 | : INHERITED(GrContextThreadSafeProxyPriv::Make(backend, options)) { |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 60 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 61 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 62 | GrDirectContext::~GrDirectContext() { |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 63 | ASSERT_SINGLE_OWNER |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 64 | // this if-test protects against the case where the context is being destroyed |
| 65 | // before having been fully created |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 66 | if (fGpu) { |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 67 | this->flushAndSubmit(); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 68 | } |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 69 | |
| 70 | this->destroyDrawingManager(); |
| 71 | fMappedBufferManager.reset(); |
| 72 | |
| 73 | // Ideally we could just let the ptr drop, but resource cache queries this ptr in releaseAll. |
| 74 | if (fResourceCache) { |
| 75 | fResourceCache->releaseAll(); |
| 76 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 77 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 78 | |
Adlai Holler | 61a591c | 2020-10-12 12:38:33 -0400 | [diff] [blame] | 79 | sk_sp<GrContextThreadSafeProxy> GrDirectContext::threadSafeProxy() { |
| 80 | return INHERITED::threadSafeProxy(); |
| 81 | } |
| 82 | |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame] | 83 | void GrDirectContext::resetGLTextureBindings() { |
| 84 | if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) { |
| 85 | return; |
| 86 | } |
| 87 | fGpu->resetTextureBindings(); |
| 88 | } |
| 89 | |
| 90 | void GrDirectContext::resetContext(uint32_t state) { |
| 91 | ASSERT_SINGLE_OWNER |
| 92 | fGpu->markContextDirty(state); |
| 93 | } |
| 94 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 95 | void GrDirectContext::abandonContext() { |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame] | 96 | if (INHERITED::abandoned()) { |
| 97 | return; |
| 98 | } |
| 99 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 100 | INHERITED::abandonContext(); |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame] | 101 | |
| 102 | fStrikeCache->freeAll(); |
| 103 | |
| 104 | fMappedBufferManager->abandon(); |
| 105 | |
| 106 | fResourceProvider->abandon(); |
| 107 | |
| 108 | // abandon first to so destructors |
| 109 | // don't try to free the resources in the API. |
| 110 | fResourceCache->abandonAll(); |
| 111 | |
| 112 | fGpu->disconnect(GrGpu::DisconnectType::kAbandon); |
| 113 | |
| 114 | fMappedBufferManager.reset(); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 115 | if (fSmallPathAtlasMgr) { |
| 116 | fSmallPathAtlasMgr->reset(); |
| 117 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 118 | fAtlasManager->freeAll(); |
| 119 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 120 | |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame] | 121 | bool GrDirectContext::abandoned() { |
| 122 | if (INHERITED::abandoned()) { |
| 123 | return true; |
| 124 | } |
| 125 | |
| 126 | if (fGpu && fGpu->isDeviceLost()) { |
| 127 | this->abandonContext(); |
| 128 | return true; |
| 129 | } |
| 130 | return false; |
| 131 | } |
| 132 | |
Adlai Holler | 61a591c | 2020-10-12 12:38:33 -0400 | [diff] [blame] | 133 | bool GrDirectContext::oomed() { return fGpu ? fGpu->checkAndResetOOMed() : false; } |
| 134 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 135 | void GrDirectContext::releaseResourcesAndAbandonContext() { |
Adlai Holler | 61a591c | 2020-10-12 12:38:33 -0400 | [diff] [blame] | 136 | if (INHERITED::abandoned()) { |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | INHERITED::abandonContext(); |
| 141 | |
| 142 | fMappedBufferManager.reset(); |
| 143 | |
| 144 | fResourceProvider->abandon(); |
| 145 | |
| 146 | // Release all resources in the backend 3D API. |
| 147 | fResourceCache->releaseAll(); |
| 148 | |
| 149 | fGpu->disconnect(GrGpu::DisconnectType::kCleanup); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 150 | if (fSmallPathAtlasMgr) { |
| 151 | fSmallPathAtlasMgr->reset(); |
| 152 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 153 | fAtlasManager->freeAll(); |
| 154 | } |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 155 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 156 | void GrDirectContext::freeGpuResources() { |
Adlai Holler | 4aa4c60 | 2020-10-12 13:58:52 -0400 | [diff] [blame] | 157 | ASSERT_SINGLE_OWNER |
| 158 | |
| 159 | if (this->abandoned()) { |
| 160 | return; |
| 161 | } |
| 162 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 163 | this->flushAndSubmit(); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 164 | if (fSmallPathAtlasMgr) { |
| 165 | fSmallPathAtlasMgr->reset(); |
| 166 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 167 | fAtlasManager->freeAll(); |
Robert Phillips | 56181ba | 2019-03-08 12:00:45 -0500 | [diff] [blame] | 168 | |
Adlai Holler | 4aa4c60 | 2020-10-12 13:58:52 -0400 | [diff] [blame] | 169 | // TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here. |
| 170 | // Some slack in the GrTextBlob's implementation requires it though. That could be fixed. |
| 171 | fStrikeCache->freeAll(); |
| 172 | |
| 173 | this->drawingManager()->freeGpuResources(); |
| 174 | |
| 175 | fResourceCache->purgeAllUnlocked(); |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 176 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 177 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 178 | bool GrDirectContext::init() { |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 179 | ASSERT_SINGLE_OWNER |
| 180 | if (!fGpu) { |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 181 | return false; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 182 | } |
| 183 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 184 | fThreadSafeProxy->priv().init(fGpu->refCaps()); |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 185 | if (!INHERITED::init()) { |
| 186 | return false; |
| 187 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 188 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 189 | SkASSERT(this->getTextBlobCache()); |
| 190 | SkASSERT(this->threadSafeCache()); |
| 191 | |
| 192 | fStrikeCache = std::make_unique<GrStrikeCache>(); |
| 193 | fResourceCache = std::make_unique<GrResourceCache>(this->caps(), this->singleOwner(), |
| 194 | this->contextID()); |
| 195 | fResourceCache->setProxyProvider(this->proxyProvider()); |
| 196 | fResourceCache->setThreadSafeCache(this->threadSafeCache()); |
| 197 | fResourceProvider = std::make_unique<GrResourceProvider>(fGpu.get(), fResourceCache.get(), |
| 198 | this->singleOwner()); |
| 199 | fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID()); |
| 200 | |
| 201 | fDidTestPMConversions = false; |
| 202 | |
| 203 | // DDL TODO: we need to think through how the task group & persistent cache |
| 204 | // get passed on to/shared between all the DDLRecorders created with this context. |
| 205 | if (this->options().fExecutor) { |
| 206 | fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor); |
| 207 | } |
| 208 | |
| 209 | fPersistentCache = this->options().fPersistentCache; |
| 210 | fShaderErrorHandler = this->options().fShaderErrorHandler; |
| 211 | if (!fShaderErrorHandler) { |
| 212 | fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler(); |
| 213 | } |
| 214 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 215 | bool reduceOpsTaskSplitting = kDefaultReduceOpsTaskSplitting; |
| 216 | if (GrContextOptions::Enable::kNo == this->options().fReduceOpsTaskSplitting) { |
| 217 | reduceOpsTaskSplitting = false; |
| 218 | } else if (GrContextOptions::Enable::kYes == this->options().fReduceOpsTaskSplitting) { |
| 219 | reduceOpsTaskSplitting = true; |
| 220 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 221 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 222 | this->setupDrawingManager(true, reduceOpsTaskSplitting); |
| 223 | |
| 224 | GrDrawOpAtlas::AllowMultitexturing allowMultitexturing; |
| 225 | if (GrContextOptions::Enable::kNo == this->options().fAllowMultipleGlyphCacheTextures || |
| 226 | // multitexturing supported only if range can represent the index + texcoords fully |
| 227 | !(this->caps()->shaderCaps()->floatIs32Bits() || |
| 228 | this->caps()->shaderCaps()->integerSupport())) { |
| 229 | allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kNo; |
| 230 | } else { |
| 231 | allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes; |
| 232 | } |
| 233 | |
| 234 | GrProxyProvider* proxyProvider = this->priv().proxyProvider(); |
| 235 | |
Robert Phillips | 3262bc8 | 2020-08-10 12:11:58 -0400 | [diff] [blame] | 236 | fAtlasManager = std::make_unique<GrAtlasManager>(proxyProvider, |
| 237 | this->options().fGlyphCacheTextureMaximumBytes, |
| 238 | allowMultitexturing); |
| 239 | this->priv().addOnFlushCallbackObject(fAtlasManager.get()); |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 240 | |
| 241 | return true; |
| 242 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 243 | |
Adlai Holler | 3a508e9 | 2020-10-12 13:58:01 -0400 | [diff] [blame] | 244 | void GrDirectContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
| 245 | ASSERT_SINGLE_OWNER |
| 246 | |
| 247 | if (resourceCount) { |
| 248 | *resourceCount = fResourceCache->getBudgetedResourceCount(); |
| 249 | } |
| 250 | if (resourceBytes) { |
| 251 | *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | size_t GrDirectContext::getResourceCachePurgeableBytes() const { |
| 256 | ASSERT_SINGLE_OWNER |
| 257 | return fResourceCache->getPurgeableBytes(); |
| 258 | } |
| 259 | |
| 260 | void GrDirectContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const { |
| 261 | ASSERT_SINGLE_OWNER |
| 262 | if (maxResources) { |
| 263 | *maxResources = -1; |
| 264 | } |
| 265 | if (maxResourceBytes) { |
| 266 | *maxResourceBytes = this->getResourceCacheLimit(); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | size_t GrDirectContext::getResourceCacheLimit() const { |
| 271 | ASSERT_SINGLE_OWNER |
| 272 | return fResourceCache->getMaxResourceBytes(); |
| 273 | } |
| 274 | |
| 275 | void GrDirectContext::setResourceCacheLimits(int unused, size_t maxResourceBytes) { |
| 276 | ASSERT_SINGLE_OWNER |
| 277 | this->setResourceCacheLimit(maxResourceBytes); |
| 278 | } |
| 279 | |
| 280 | void GrDirectContext::setResourceCacheLimit(size_t maxResourceBytes) { |
| 281 | ASSERT_SINGLE_OWNER |
| 282 | fResourceCache->setLimit(maxResourceBytes); |
| 283 | } |
| 284 | |
Adlai Holler | 4aa4c60 | 2020-10-12 13:58:52 -0400 | [diff] [blame] | 285 | void GrDirectContext::purgeUnlockedResources(bool scratchResourcesOnly) { |
| 286 | ASSERT_SINGLE_OWNER |
| 287 | |
| 288 | if (this->abandoned()) { |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | fResourceCache->purgeUnlockedResources(scratchResourcesOnly); |
| 293 | fResourceCache->purgeAsNeeded(); |
| 294 | |
| 295 | // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient |
| 296 | // place to purge stale blobs |
| 297 | this->getTextBlobCache()->purgeStaleBlobs(); |
| 298 | } |
| 299 | |
| 300 | void GrDirectContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) { |
| 301 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 302 | |
| 303 | ASSERT_SINGLE_OWNER |
| 304 | |
| 305 | if (this->abandoned()) { |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | this->checkAsyncWorkCompletion(); |
| 310 | fMappedBufferManager->process(); |
| 311 | auto purgeTime = GrStdSteadyClock::now() - msNotUsed; |
| 312 | |
| 313 | fResourceCache->purgeAsNeeded(); |
| 314 | fResourceCache->purgeResourcesNotUsedSince(purgeTime); |
| 315 | |
| 316 | if (auto ccpr = this->drawingManager()->getCoverageCountingPathRenderer()) { |
| 317 | ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime); |
| 318 | } |
| 319 | |
| 320 | // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient |
| 321 | // place to purge stale blobs |
| 322 | this->getTextBlobCache()->purgeStaleBlobs(); |
| 323 | } |
| 324 | |
| 325 | void GrDirectContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) { |
| 326 | ASSERT_SINGLE_OWNER |
| 327 | |
| 328 | if (this->abandoned()) { |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources); |
| 333 | } |
| 334 | |
Adlai Holler | 3acc69a | 2020-10-13 08:20:51 -0400 | [diff] [blame] | 335 | //////////////////////////////////////////////////////////////////////////////// |
| 336 | bool GrDirectContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[], |
| 337 | bool deleteSemaphoresAfterWait) { |
| 338 | if (!fGpu || fGpu->caps()->semaphoreSupport()) { |
| 339 | return false; |
| 340 | } |
| 341 | GrWrapOwnership ownership = |
| 342 | deleteSemaphoresAfterWait ? kAdopt_GrWrapOwnership : kBorrow_GrWrapOwnership; |
| 343 | for (int i = 0; i < numSemaphores; ++i) { |
| 344 | std::unique_ptr<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore( |
| 345 | waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, ownership); |
| 346 | // If we failed to wrap the semaphore it means the client didn't give us a valid semaphore |
| 347 | // to begin with. Therefore, it is fine to not wait on it. |
| 348 | if (sema) { |
| 349 | fGpu->waitSemaphore(sema.get()); |
| 350 | } |
| 351 | } |
| 352 | return true; |
| 353 | } |
Adlai Holler | 4aa4c60 | 2020-10-12 13:58:52 -0400 | [diff] [blame] | 354 | |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 355 | GrSmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() { |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 356 | if (!fSmallPathAtlasMgr) { |
| 357 | fSmallPathAtlasMgr = std::make_unique<GrSmallPathAtlasMgr>(); |
| 358 | |
| 359 | this->priv().addOnFlushCallbackObject(fSmallPathAtlasMgr.get()); |
| 360 | } |
| 361 | |
| 362 | if (!fSmallPathAtlasMgr->initAtlas(this->proxyProvider(), this->caps())) { |
| 363 | return nullptr; |
| 364 | } |
| 365 | |
| 366 | return fSmallPathAtlasMgr.get(); |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 367 | } |
| 368 | |
Adlai Holler | 3acc69a | 2020-10-13 08:20:51 -0400 | [diff] [blame] | 369 | //////////////////////////////////////////////////////////////////////////////// |
| 370 | |
| 371 | GrSemaphoresSubmitted GrDirectContext::flush(const GrFlushInfo& info) { |
| 372 | ASSERT_SINGLE_OWNER |
| 373 | if (this->abandoned()) { |
| 374 | if (info.fFinishedProc) { |
| 375 | info.fFinishedProc(info.fFinishedContext); |
| 376 | } |
| 377 | if (info.fSubmittedProc) { |
| 378 | info.fSubmittedProc(info.fSubmittedContext, false); |
| 379 | } |
| 380 | return GrSemaphoresSubmitted::kNo; |
| 381 | } |
| 382 | |
| 383 | bool flushed = this->drawingManager()->flush( |
| 384 | nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, info, nullptr); |
| 385 | |
| 386 | if (!flushed || (!this->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) { |
| 387 | return GrSemaphoresSubmitted::kNo; |
| 388 | } |
| 389 | return GrSemaphoresSubmitted::kYes; |
| 390 | } |
| 391 | |
| 392 | bool GrDirectContext::submit(bool syncCpu) { |
| 393 | ASSERT_SINGLE_OWNER |
| 394 | if (this->abandoned()) { |
| 395 | return false; |
| 396 | } |
| 397 | |
| 398 | if (!fGpu) { |
| 399 | return false; |
| 400 | } |
| 401 | |
| 402 | return fGpu->submitToGpu(syncCpu); |
| 403 | } |
| 404 | |
| 405 | //////////////////////////////////////////////////////////////////////////////// |
| 406 | |
| 407 | void GrDirectContext::checkAsyncWorkCompletion() { |
| 408 | if (fGpu) { |
| 409 | fGpu->checkFinishProcs(); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | //////////////////////////////////////////////////////////////////////////////// |
| 414 | |
| 415 | void GrDirectContext::storeVkPipelineCacheData() { |
| 416 | if (fGpu) { |
| 417 | fGpu->storeVkPipelineCacheData(); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | //////////////////////////////////////////////////////////////////////////////// |
| 422 | |
| 423 | bool GrDirectContext::supportsDistanceFieldText() const { |
| 424 | return this->caps()->shaderCaps()->supportsDistanceFieldText(); |
| 425 | } |
| 426 | |
| 427 | ////////////////////////////////////////////////////////////////////////////// |
| 428 | |
| 429 | void GrDirectContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 430 | ASSERT_SINGLE_OWNER |
| 431 | fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 432 | traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes", |
| 433 | this->getTextBlobCache()->usedBytes()); |
| 434 | } |
| 435 | |
| 436 | size_t GrDirectContext::ComputeImageSize(sk_sp<SkImage> image, GrMipmapped mipMapped, |
| 437 | bool useNextPow2) { |
| 438 | if (!image->isTextureBacked()) { |
| 439 | return 0; |
| 440 | } |
| 441 | SkImage_GpuBase* gpuImage = static_cast<SkImage_GpuBase*>(as_IB(image.get())); |
| 442 | GrTextureProxy* proxy = gpuImage->peekProxy(); |
| 443 | if (!proxy) { |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | int colorSamplesPerPixel = 1; |
| 448 | return GrSurface::ComputeSize(proxy->backendFormat(), image->dimensions(), |
| 449 | colorSamplesPerPixel, mipMapped, useNextPow2); |
| 450 | } |
| 451 | |
Adlai Holler | 98dd004 | 2020-10-13 10:04:00 -0400 | [diff] [blame^] | 452 | GrBackendTexture GrDirectContext::createBackendTexture(int width, int height, |
| 453 | const GrBackendFormat& backendFormat, |
| 454 | GrMipmapped mipMapped, |
| 455 | GrRenderable renderable, |
| 456 | GrProtected isProtected) { |
| 457 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 458 | if (this->abandoned()) { |
| 459 | return GrBackendTexture(); |
| 460 | } |
| 461 | |
| 462 | return fGpu->createBackendTexture({width, height}, backendFormat, renderable, |
| 463 | mipMapped, isProtected); |
| 464 | } |
| 465 | |
| 466 | GrBackendTexture GrDirectContext::createBackendTexture(int width, int height, |
| 467 | SkColorType skColorType, |
| 468 | GrMipmapped mipMapped, |
| 469 | GrRenderable renderable, |
| 470 | GrProtected isProtected) { |
| 471 | if (this->abandoned()) { |
| 472 | return GrBackendTexture(); |
| 473 | } |
| 474 | |
| 475 | const GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable); |
| 476 | |
| 477 | return this->createBackendTexture(width, height, format, mipMapped, renderable, isProtected); |
| 478 | } |
| 479 | |
| 480 | static GrBackendTexture create_and_update_backend_texture( |
| 481 | GrDirectContext* dContext, |
| 482 | SkISize dimensions, |
| 483 | const GrBackendFormat& backendFormat, |
| 484 | GrMipmapped mipMapped, |
| 485 | GrRenderable renderable, |
| 486 | GrProtected isProtected, |
| 487 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 488 | const GrGpu::BackendTextureData* data) { |
| 489 | GrGpu* gpu = dContext->priv().getGpu(); |
| 490 | |
| 491 | GrBackendTexture beTex = gpu->createBackendTexture(dimensions, backendFormat, renderable, |
| 492 | mipMapped, isProtected); |
| 493 | if (!beTex.isValid()) { |
| 494 | return {}; |
| 495 | } |
| 496 | |
| 497 | if (!dContext->priv().getGpu()->updateBackendTexture(beTex, |
| 498 | std::move(finishedCallback), |
| 499 | data)) { |
| 500 | dContext->deleteBackendTexture(beTex); |
| 501 | return {}; |
| 502 | } |
| 503 | return beTex; |
| 504 | } |
| 505 | |
| 506 | GrBackendTexture GrDirectContext::createBackendTexture(int width, int height, |
| 507 | const GrBackendFormat& backendFormat, |
| 508 | const SkColor4f& color, |
| 509 | GrMipmapped mipMapped, |
| 510 | GrRenderable renderable, |
| 511 | GrProtected isProtected, |
| 512 | GrGpuFinishedProc finishedProc, |
| 513 | GrGpuFinishedContext finishedContext) { |
| 514 | sk_sp<GrRefCntedCallback> finishedCallback; |
| 515 | if (finishedProc) { |
| 516 | finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext)); |
| 517 | } |
| 518 | |
| 519 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 520 | if (this->abandoned()) { |
| 521 | return {}; |
| 522 | } |
| 523 | |
| 524 | GrGpu::BackendTextureData data(color); |
| 525 | return create_and_update_backend_texture(this, {width, height}, |
| 526 | backendFormat, mipMapped, renderable, isProtected, |
| 527 | std::move(finishedCallback), &data); |
| 528 | } |
| 529 | |
| 530 | GrBackendTexture GrDirectContext::createBackendTexture(int width, int height, |
| 531 | SkColorType skColorType, |
| 532 | const SkColor4f& color, |
| 533 | GrMipmapped mipMapped, |
| 534 | GrRenderable renderable, |
| 535 | GrProtected isProtected, |
| 536 | GrGpuFinishedProc finishedProc, |
| 537 | GrGpuFinishedContext finishedContext) { |
| 538 | sk_sp<GrRefCntedCallback> finishedCallback; |
| 539 | if (finishedProc) { |
| 540 | finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext)); |
| 541 | } |
| 542 | |
| 543 | if (this->abandoned()) { |
| 544 | return {}; |
| 545 | } |
| 546 | |
| 547 | GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable); |
| 548 | if (!format.isValid()) { |
| 549 | return {}; |
| 550 | } |
| 551 | |
| 552 | GrColorType grColorType = SkColorTypeToGrColorType(skColorType); |
| 553 | SkColor4f swizzledColor = this->caps()->getWriteSwizzle(format, grColorType).applyTo(color); |
| 554 | |
| 555 | GrGpu::BackendTextureData data(swizzledColor); |
| 556 | return create_and_update_backend_texture(this, {width, height}, format, |
| 557 | mipMapped, renderable, isProtected, |
| 558 | std::move(finishedCallback), &data); |
| 559 | } |
| 560 | |
| 561 | GrBackendTexture GrDirectContext::createBackendTexture(const SkPixmap srcData[], |
| 562 | int numProvidedLevels, |
| 563 | GrRenderable renderable, |
| 564 | GrProtected isProtected, |
| 565 | GrGpuFinishedProc finishedProc, |
| 566 | GrGpuFinishedContext finishedContext) { |
| 567 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 568 | |
| 569 | sk_sp<GrRefCntedCallback> finishedCallback; |
| 570 | if (finishedProc) { |
| 571 | finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext)); |
| 572 | } |
| 573 | |
| 574 | if (this->abandoned()) { |
| 575 | return {}; |
| 576 | } |
| 577 | |
| 578 | if (!srcData || numProvidedLevels <= 0) { |
| 579 | return {}; |
| 580 | } |
| 581 | |
| 582 | int baseWidth = srcData[0].width(); |
| 583 | int baseHeight = srcData[0].height(); |
| 584 | SkColorType colorType = srcData[0].colorType(); |
| 585 | |
| 586 | GrMipmapped mipMapped = GrMipmapped::kNo; |
| 587 | int numExpectedLevels = 1; |
| 588 | if (numProvidedLevels > 1) { |
| 589 | numExpectedLevels = SkMipmap::ComputeLevelCount(baseWidth, baseHeight) + 1; |
| 590 | mipMapped = GrMipmapped::kYes; |
| 591 | } |
| 592 | |
| 593 | if (numProvidedLevels != numExpectedLevels) { |
| 594 | return {}; |
| 595 | } |
| 596 | |
| 597 | GrBackendFormat backendFormat = this->defaultBackendFormat(colorType, renderable); |
| 598 | |
| 599 | GrGpu::BackendTextureData data(srcData); |
| 600 | return create_and_update_backend_texture(this, {baseWidth, baseHeight}, |
| 601 | backendFormat, mipMapped, renderable, isProtected, |
| 602 | std::move(finishedCallback), &data); |
| 603 | } |
| 604 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 605 | #ifdef SK_GL |
Robert Phillips | c7228c6 | 2020-07-14 12:57:39 -0400 | [diff] [blame] | 606 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 607 | /*************************************************************************************************/ |
| 608 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 609 | GrContextOptions defaultOptions; |
Jim Van Verth | 03b8ab2 | 2020-02-24 11:36:15 -0500 | [diff] [blame] | 610 | return MakeGL(std::move(glInterface), defaultOptions); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 611 | } |
| 612 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 613 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(const GrContextOptions& options) { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 614 | return MakeGL(nullptr, options); |
| 615 | } |
| 616 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 617 | sk_sp<GrDirectContext> GrDirectContext::MakeGL() { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 618 | GrContextOptions defaultOptions; |
| 619 | return MakeGL(nullptr, defaultOptions); |
| 620 | } |
| 621 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 622 | #if GR_TEST_UTILS |
| 623 | GrGLFunction<GrGLGetErrorFn> make_get_error_with_random_oom(GrGLFunction<GrGLGetErrorFn> original) { |
| 624 | // A SkRandom and a GrGLFunction<GrGLGetErrorFn> are too big to be captured by a |
| 625 | // GrGLFunction<GrGLGetError> (surprise, surprise). So we make a context object and |
| 626 | // capture that by pointer. However, GrGLFunction doesn't support calling a destructor |
| 627 | // on the thing it captures. So we leak the context. |
| 628 | struct GetErrorContext { |
| 629 | SkRandom fRandom; |
| 630 | GrGLFunction<GrGLGetErrorFn> fGetError; |
| 631 | }; |
| 632 | |
| 633 | auto errorContext = new GetErrorContext; |
| 634 | |
| 635 | #if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 636 | __lsan_ignore_object(errorContext); |
| 637 | #endif |
| 638 | |
| 639 | errorContext->fGetError = original; |
| 640 | |
| 641 | return GrGLFunction<GrGLGetErrorFn>([errorContext]() { |
| 642 | GrGLenum error = errorContext->fGetError(); |
| 643 | if (error == GR_GL_NO_ERROR && (errorContext->fRandom.nextU() % 300) == 0) { |
| 644 | error = GR_GL_OUT_OF_MEMORY; |
| 645 | } |
| 646 | return error; |
| 647 | }); |
| 648 | } |
| 649 | #endif |
| 650 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 651 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface, |
| 652 | const GrContextOptions& options) { |
| 653 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kOpenGL, options)); |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 654 | #if GR_TEST_UTILS |
| 655 | if (options.fRandomGLOOM) { |
| 656 | auto copy = sk_make_sp<GrGLInterface>(*glInterface); |
| 657 | copy->fFunctions.fGetError = |
| 658 | make_get_error_with_random_oom(glInterface->fFunctions.fGetError); |
| 659 | #if GR_GL_CHECK_ERROR |
| 660 | // Suppress logging GL errors since we'll be synthetically generating them. |
| 661 | copy->suppressErrorLogging(); |
| 662 | #endif |
| 663 | glInterface = std::move(copy); |
| 664 | } |
| 665 | #endif |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 666 | direct->fGpu = GrGLGpu::Make(std::move(glInterface), options, direct.get()); |
| 667 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 668 | return nullptr; |
| 669 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 670 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 671 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 672 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 673 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 674 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 675 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions) { |
| 676 | GrContextOptions defaultOptions; |
| 677 | return MakeMock(mockOptions, defaultOptions); |
| 678 | } |
| 679 | |
| 680 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions, |
| 681 | const GrContextOptions& options) { |
| 682 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMock, options)); |
| 683 | |
| 684 | direct->fGpu = GrMockGpu::Make(mockOptions, options, direct.get()); |
| 685 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 686 | return nullptr; |
| 687 | } |
Chris Dalton | a378b45 | 2019-12-11 13:24:11 -0500 | [diff] [blame] | 688 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 689 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 690 | } |
| 691 | |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 692 | #ifdef SK_VULKAN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 693 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 694 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext) { |
| 695 | GrContextOptions defaultOptions; |
| 696 | return MakeVulkan(backendContext, defaultOptions); |
| 697 | } |
| 698 | |
| 699 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext, |
| 700 | const GrContextOptions& options) { |
| 701 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kVulkan, options)); |
| 702 | |
| 703 | direct->fGpu = GrVkGpu::Make(backendContext, options, direct.get()); |
| 704 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 705 | return nullptr; |
| 706 | } |
| 707 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 708 | return direct; |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 709 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 710 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 711 | |
| 712 | #ifdef SK_METAL |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 713 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 714 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 715 | GrContextOptions defaultOptions; |
| 716 | return MakeMetal(device, queue, defaultOptions); |
| 717 | } |
| 718 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 719 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue, |
| 720 | const GrContextOptions& options) { |
| 721 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options)); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 722 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 723 | direct->fGpu = GrMtlTrampoline::MakeGpu(direct.get(), options, device, queue); |
| 724 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 725 | return nullptr; |
| 726 | } |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 727 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 728 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 729 | } |
| 730 | #endif |
| 731 | |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 732 | #ifdef SK_DIRECT3D |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 733 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 734 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext) { |
| 735 | GrContextOptions defaultOptions; |
| 736 | return MakeDirect3D(backendContext, defaultOptions); |
| 737 | } |
| 738 | |
| 739 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext, |
| 740 | const GrContextOptions& options) { |
| 741 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDirect3D, options)); |
| 742 | |
| 743 | direct->fGpu = GrD3DGpu::Make(backendContext, options, direct.get()); |
| 744 | if (!direct->init()) { |
Jim Van Verth | d2d4c5e | 2020-02-19 14:57:58 -0500 | [diff] [blame] | 745 | return nullptr; |
| 746 | } |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 747 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 748 | return direct; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 749 | } |
| 750 | #endif |
| 751 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 752 | #ifdef SK_DAWN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 753 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 754 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 755 | GrContextOptions defaultOptions; |
| 756 | return MakeDawn(device, defaultOptions); |
| 757 | } |
| 758 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 759 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device, |
| 760 | const GrContextOptions& options) { |
| 761 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDawn, options)); |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 762 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 763 | direct->fGpu = GrDawnGpu::Make(device, options, direct.get()); |
| 764 | if (!direct->init()) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 765 | return nullptr; |
| 766 | } |
| 767 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 768 | return direct; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 769 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 770 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 771 | #endif |