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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrContextThreadSafeProxy.h" |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame^] | 12 | #include "src/core/SkTaskGroup.h" |
| 13 | #include "src/gpu/GrClientMappedBufferManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrContextPriv.h" |
| 15 | #include "src/gpu/GrContextThreadSafeProxyPriv.h" |
| 16 | #include "src/gpu/GrGpu.h" |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame^] | 17 | #include "src/gpu/GrResourceProvider.h" |
| 18 | #include "src/gpu/GrShaderUtils.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 19 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/effects/GrSkSLFP.h" |
| 21 | #include "src/gpu/gl/GrGLGpu.h" |
| 22 | #include "src/gpu/mock/GrMockGpu.h" |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 23 | #include "src/gpu/ops/GrSmallPathAtlasMgr.h" |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 24 | #include "src/gpu/text/GrAtlasManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/text/GrStrikeCache.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 26 | #ifdef SK_METAL |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/gpu/mtl/GrMtlTrampoline.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 28 | #endif |
| 29 | #ifdef SK_VULKAN |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 30 | #include "src/gpu/vk/GrVkGpu.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 31 | #endif |
Jim Van Verth | d2d4c5e | 2020-02-19 14:57:58 -0500 | [diff] [blame] | 32 | #ifdef SK_DIRECT3D |
| 33 | #include "src/gpu/d3d/GrD3DGpu.h" |
| 34 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 35 | #ifdef SK_DAWN |
Mike Klein | 52337de | 2019-07-25 09:00:52 -0500 | [diff] [blame] | 36 | #include "src/gpu/dawn/GrDawnGpu.h" |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 37 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 38 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 39 | #if GR_TEST_UTILS |
| 40 | # include "include/utils/SkRandom.h" |
| 41 | # if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 42 | # include <sanitizer/lsan_interface.h> |
| 43 | # endif |
| 44 | #endif |
| 45 | |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 46 | #ifdef SK_DISABLE_REDUCE_OPLIST_SPLITTING |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 47 | static const bool kDefaultReduceOpsTaskSplitting = false; |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 48 | #else |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 49 | static const bool kDefaultReduceOpsTaskSplitting = false; |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 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 | |
| 66 | this->destroyDrawingManager(); |
| 67 | fMappedBufferManager.reset(); |
| 68 | |
| 69 | // Ideally we could just let the ptr drop, but resource cache queries this ptr in releaseAll. |
| 70 | if (fResourceCache) { |
| 71 | fResourceCache->releaseAll(); |
| 72 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 73 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 74 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 75 | void GrDirectContext::abandonContext() { |
| 76 | INHERITED::abandonContext(); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 77 | if (fSmallPathAtlasMgr) { |
| 78 | fSmallPathAtlasMgr->reset(); |
| 79 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 80 | fAtlasManager->freeAll(); |
| 81 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 82 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 83 | void GrDirectContext::releaseResourcesAndAbandonContext() { |
| 84 | INHERITED::releaseResourcesAndAbandonContext(); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 85 | if (fSmallPathAtlasMgr) { |
| 86 | fSmallPathAtlasMgr->reset(); |
| 87 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 88 | fAtlasManager->freeAll(); |
| 89 | } |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 90 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 91 | void GrDirectContext::freeGpuResources() { |
| 92 | this->flushAndSubmit(); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 93 | if (fSmallPathAtlasMgr) { |
| 94 | fSmallPathAtlasMgr->reset(); |
| 95 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 96 | fAtlasManager->freeAll(); |
Robert Phillips | 56181ba | 2019-03-08 12:00:45 -0500 | [diff] [blame] | 97 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 98 | INHERITED::freeGpuResources(); |
| 99 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 100 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 101 | bool GrDirectContext::init() { |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame^] | 102 | ASSERT_SINGLE_OWNER |
| 103 | if (!fGpu) { |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 104 | return false; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 105 | } |
| 106 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame^] | 107 | fThreadSafeProxy->priv().init(fGpu->refCaps()); |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 108 | if (!INHERITED::init()) { |
| 109 | return false; |
| 110 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 111 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame^] | 112 | SkASSERT(this->getTextBlobCache()); |
| 113 | SkASSERT(this->threadSafeCache()); |
| 114 | |
| 115 | fStrikeCache = std::make_unique<GrStrikeCache>(); |
| 116 | fResourceCache = std::make_unique<GrResourceCache>(this->caps(), this->singleOwner(), |
| 117 | this->contextID()); |
| 118 | fResourceCache->setProxyProvider(this->proxyProvider()); |
| 119 | fResourceCache->setThreadSafeCache(this->threadSafeCache()); |
| 120 | fResourceProvider = std::make_unique<GrResourceProvider>(fGpu.get(), fResourceCache.get(), |
| 121 | this->singleOwner()); |
| 122 | fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID()); |
| 123 | |
| 124 | fDidTestPMConversions = false; |
| 125 | |
| 126 | // DDL TODO: we need to think through how the task group & persistent cache |
| 127 | // get passed on to/shared between all the DDLRecorders created with this context. |
| 128 | if (this->options().fExecutor) { |
| 129 | fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor); |
| 130 | } |
| 131 | |
| 132 | fPersistentCache = this->options().fPersistentCache; |
| 133 | fShaderErrorHandler = this->options().fShaderErrorHandler; |
| 134 | if (!fShaderErrorHandler) { |
| 135 | fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler(); |
| 136 | } |
| 137 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 138 | bool reduceOpsTaskSplitting = kDefaultReduceOpsTaskSplitting; |
| 139 | if (GrContextOptions::Enable::kNo == this->options().fReduceOpsTaskSplitting) { |
| 140 | reduceOpsTaskSplitting = false; |
| 141 | } else if (GrContextOptions::Enable::kYes == this->options().fReduceOpsTaskSplitting) { |
| 142 | reduceOpsTaskSplitting = true; |
| 143 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 144 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 145 | this->setupDrawingManager(true, reduceOpsTaskSplitting); |
| 146 | |
| 147 | GrDrawOpAtlas::AllowMultitexturing allowMultitexturing; |
| 148 | if (GrContextOptions::Enable::kNo == this->options().fAllowMultipleGlyphCacheTextures || |
| 149 | // multitexturing supported only if range can represent the index + texcoords fully |
| 150 | !(this->caps()->shaderCaps()->floatIs32Bits() || |
| 151 | this->caps()->shaderCaps()->integerSupport())) { |
| 152 | allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kNo; |
| 153 | } else { |
| 154 | allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes; |
| 155 | } |
| 156 | |
| 157 | GrProxyProvider* proxyProvider = this->priv().proxyProvider(); |
| 158 | |
Robert Phillips | 3262bc8 | 2020-08-10 12:11:58 -0400 | [diff] [blame] | 159 | fAtlasManager = std::make_unique<GrAtlasManager>(proxyProvider, |
| 160 | this->options().fGlyphCacheTextureMaximumBytes, |
| 161 | allowMultitexturing); |
| 162 | this->priv().addOnFlushCallbackObject(fAtlasManager.get()); |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 163 | |
| 164 | return true; |
| 165 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 166 | |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 167 | GrSmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() { |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 168 | if (!fSmallPathAtlasMgr) { |
| 169 | fSmallPathAtlasMgr = std::make_unique<GrSmallPathAtlasMgr>(); |
| 170 | |
| 171 | this->priv().addOnFlushCallbackObject(fSmallPathAtlasMgr.get()); |
| 172 | } |
| 173 | |
| 174 | if (!fSmallPathAtlasMgr->initAtlas(this->proxyProvider(), this->caps())) { |
| 175 | return nullptr; |
| 176 | } |
| 177 | |
| 178 | return fSmallPathAtlasMgr.get(); |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 179 | } |
| 180 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 181 | #ifdef SK_GL |
Robert Phillips | c7228c6 | 2020-07-14 12:57:39 -0400 | [diff] [blame] | 182 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 183 | /*************************************************************************************************/ |
| 184 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 185 | GrContextOptions defaultOptions; |
Jim Van Verth | 03b8ab2 | 2020-02-24 11:36:15 -0500 | [diff] [blame] | 186 | return MakeGL(std::move(glInterface), defaultOptions); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 187 | } |
| 188 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 189 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(const GrContextOptions& options) { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 190 | return MakeGL(nullptr, options); |
| 191 | } |
| 192 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 193 | sk_sp<GrDirectContext> GrDirectContext::MakeGL() { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 194 | GrContextOptions defaultOptions; |
| 195 | return MakeGL(nullptr, defaultOptions); |
| 196 | } |
| 197 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 198 | #if GR_TEST_UTILS |
| 199 | GrGLFunction<GrGLGetErrorFn> make_get_error_with_random_oom(GrGLFunction<GrGLGetErrorFn> original) { |
| 200 | // A SkRandom and a GrGLFunction<GrGLGetErrorFn> are too big to be captured by a |
| 201 | // GrGLFunction<GrGLGetError> (surprise, surprise). So we make a context object and |
| 202 | // capture that by pointer. However, GrGLFunction doesn't support calling a destructor |
| 203 | // on the thing it captures. So we leak the context. |
| 204 | struct GetErrorContext { |
| 205 | SkRandom fRandom; |
| 206 | GrGLFunction<GrGLGetErrorFn> fGetError; |
| 207 | }; |
| 208 | |
| 209 | auto errorContext = new GetErrorContext; |
| 210 | |
| 211 | #if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 212 | __lsan_ignore_object(errorContext); |
| 213 | #endif |
| 214 | |
| 215 | errorContext->fGetError = original; |
| 216 | |
| 217 | return GrGLFunction<GrGLGetErrorFn>([errorContext]() { |
| 218 | GrGLenum error = errorContext->fGetError(); |
| 219 | if (error == GR_GL_NO_ERROR && (errorContext->fRandom.nextU() % 300) == 0) { |
| 220 | error = GR_GL_OUT_OF_MEMORY; |
| 221 | } |
| 222 | return error; |
| 223 | }); |
| 224 | } |
| 225 | #endif |
| 226 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 227 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface, |
| 228 | const GrContextOptions& options) { |
| 229 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kOpenGL, options)); |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 230 | #if GR_TEST_UTILS |
| 231 | if (options.fRandomGLOOM) { |
| 232 | auto copy = sk_make_sp<GrGLInterface>(*glInterface); |
| 233 | copy->fFunctions.fGetError = |
| 234 | make_get_error_with_random_oom(glInterface->fFunctions.fGetError); |
| 235 | #if GR_GL_CHECK_ERROR |
| 236 | // Suppress logging GL errors since we'll be synthetically generating them. |
| 237 | copy->suppressErrorLogging(); |
| 238 | #endif |
| 239 | glInterface = std::move(copy); |
| 240 | } |
| 241 | #endif |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 242 | direct->fGpu = GrGLGpu::Make(std::move(glInterface), options, direct.get()); |
| 243 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 244 | return nullptr; |
| 245 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 246 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 247 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 248 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 249 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 250 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 251 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions) { |
| 252 | GrContextOptions defaultOptions; |
| 253 | return MakeMock(mockOptions, defaultOptions); |
| 254 | } |
| 255 | |
| 256 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions, |
| 257 | const GrContextOptions& options) { |
| 258 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMock, options)); |
| 259 | |
| 260 | direct->fGpu = GrMockGpu::Make(mockOptions, options, direct.get()); |
| 261 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 262 | return nullptr; |
| 263 | } |
Chris Dalton | a378b45 | 2019-12-11 13:24:11 -0500 | [diff] [blame] | 264 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 265 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 266 | } |
| 267 | |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 268 | #ifdef SK_VULKAN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 269 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 270 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext) { |
| 271 | GrContextOptions defaultOptions; |
| 272 | return MakeVulkan(backendContext, defaultOptions); |
| 273 | } |
| 274 | |
| 275 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext, |
| 276 | const GrContextOptions& options) { |
| 277 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kVulkan, options)); |
| 278 | |
| 279 | direct->fGpu = GrVkGpu::Make(backendContext, options, direct.get()); |
| 280 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 281 | return nullptr; |
| 282 | } |
| 283 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 284 | return direct; |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 285 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 286 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 287 | |
| 288 | #ifdef SK_METAL |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 289 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 290 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 291 | GrContextOptions defaultOptions; |
| 292 | return MakeMetal(device, queue, defaultOptions); |
| 293 | } |
| 294 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 295 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue, |
| 296 | const GrContextOptions& options) { |
| 297 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options)); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 298 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 299 | direct->fGpu = GrMtlTrampoline::MakeGpu(direct.get(), options, device, queue); |
| 300 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 301 | return nullptr; |
| 302 | } |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 303 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 304 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 305 | } |
| 306 | #endif |
| 307 | |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 308 | #ifdef SK_DIRECT3D |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 309 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 310 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext) { |
| 311 | GrContextOptions defaultOptions; |
| 312 | return MakeDirect3D(backendContext, defaultOptions); |
| 313 | } |
| 314 | |
| 315 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext, |
| 316 | const GrContextOptions& options) { |
| 317 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDirect3D, options)); |
| 318 | |
| 319 | direct->fGpu = GrD3DGpu::Make(backendContext, options, direct.get()); |
| 320 | if (!direct->init()) { |
Jim Van Verth | d2d4c5e | 2020-02-19 14:57:58 -0500 | [diff] [blame] | 321 | return nullptr; |
| 322 | } |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 323 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 324 | return direct; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 325 | } |
| 326 | #endif |
| 327 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 328 | #ifdef SK_DAWN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 329 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 330 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 331 | GrContextOptions defaultOptions; |
| 332 | return MakeDawn(device, defaultOptions); |
| 333 | } |
| 334 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 335 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device, |
| 336 | const GrContextOptions& options) { |
| 337 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDawn, options)); |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 338 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 339 | direct->fGpu = GrDawnGpu::Make(device, options, direct.get()); |
| 340 | if (!direct->init()) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 341 | return nullptr; |
| 342 | } |
| 343 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 344 | return direct; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 345 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 346 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 347 | #endif |