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