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