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