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 | /*************************************************************************************************/ |
Jim Van Verth | 03b8ab2 | 2020-02-24 11:36:15 -0500 | [diff] [blame] | 121 | sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> glInterface) { |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 122 | return GrDirectContext::MakeGL(std::move(glInterface)); |
| 123 | } |
| 124 | |
| 125 | sk_sp<GrContext> GrContext::MakeGL(const GrContextOptions& options) { |
| 126 | return GrDirectContext::MakeGL(options); |
| 127 | } |
| 128 | |
| 129 | sk_sp<GrContext> GrContext::MakeGL() { |
| 130 | return GrDirectContext::MakeGL(); |
| 131 | } |
| 132 | |
| 133 | sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> glInterface, |
| 134 | const GrContextOptions& options) { |
| 135 | return GrDirectContext::MakeGL(std::move(glInterface), options); |
| 136 | } |
| 137 | |
| 138 | /*************************************************************************************************/ |
| 139 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 140 | GrContextOptions defaultOptions; |
Jim Van Verth | 03b8ab2 | 2020-02-24 11:36:15 -0500 | [diff] [blame] | 141 | return MakeGL(std::move(glInterface), defaultOptions); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 142 | } |
| 143 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 144 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(const GrContextOptions& options) { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 145 | return MakeGL(nullptr, options); |
| 146 | } |
| 147 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 148 | sk_sp<GrDirectContext> GrDirectContext::MakeGL() { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 149 | GrContextOptions defaultOptions; |
| 150 | return MakeGL(nullptr, defaultOptions); |
| 151 | } |
| 152 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 153 | #if GR_TEST_UTILS |
| 154 | GrGLFunction<GrGLGetErrorFn> make_get_error_with_random_oom(GrGLFunction<GrGLGetErrorFn> original) { |
| 155 | // A SkRandom and a GrGLFunction<GrGLGetErrorFn> are too big to be captured by a |
| 156 | // GrGLFunction<GrGLGetError> (surprise, surprise). So we make a context object and |
| 157 | // capture that by pointer. However, GrGLFunction doesn't support calling a destructor |
| 158 | // on the thing it captures. So we leak the context. |
| 159 | struct GetErrorContext { |
| 160 | SkRandom fRandom; |
| 161 | GrGLFunction<GrGLGetErrorFn> fGetError; |
| 162 | }; |
| 163 | |
| 164 | auto errorContext = new GetErrorContext; |
| 165 | |
| 166 | #if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 167 | __lsan_ignore_object(errorContext); |
| 168 | #endif |
| 169 | |
| 170 | errorContext->fGetError = original; |
| 171 | |
| 172 | return GrGLFunction<GrGLGetErrorFn>([errorContext]() { |
| 173 | GrGLenum error = errorContext->fGetError(); |
| 174 | if (error == GR_GL_NO_ERROR && (errorContext->fRandom.nextU() % 300) == 0) { |
| 175 | error = GR_GL_OUT_OF_MEMORY; |
| 176 | } |
| 177 | return error; |
| 178 | }); |
| 179 | } |
| 180 | #endif |
| 181 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 182 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface, |
| 183 | const GrContextOptions& options) { |
| 184 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kOpenGL, options)); |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 185 | #if GR_TEST_UTILS |
| 186 | if (options.fRandomGLOOM) { |
| 187 | auto copy = sk_make_sp<GrGLInterface>(*glInterface); |
| 188 | copy->fFunctions.fGetError = |
| 189 | make_get_error_with_random_oom(glInterface->fFunctions.fGetError); |
| 190 | #if GR_GL_CHECK_ERROR |
| 191 | // Suppress logging GL errors since we'll be synthetically generating them. |
| 192 | copy->suppressErrorLogging(); |
| 193 | #endif |
| 194 | glInterface = std::move(copy); |
| 195 | } |
| 196 | #endif |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 197 | direct->fGpu = GrGLGpu::Make(std::move(glInterface), options, direct.get()); |
| 198 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 199 | return nullptr; |
| 200 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 201 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 202 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 203 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 204 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 205 | /*************************************************************************************************/ |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 206 | sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions) { |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 207 | return GrDirectContext::MakeMock(mockOptions); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions, |
| 211 | const GrContextOptions& options) { |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 212 | return GrDirectContext::MakeMock(mockOptions, options); |
| 213 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 214 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 215 | /*************************************************************************************************/ |
| 216 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions) { |
| 217 | GrContextOptions defaultOptions; |
| 218 | return MakeMock(mockOptions, defaultOptions); |
| 219 | } |
| 220 | |
| 221 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions, |
| 222 | const GrContextOptions& options) { |
| 223 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMock, options)); |
| 224 | |
| 225 | direct->fGpu = GrMockGpu::Make(mockOptions, options, direct.get()); |
| 226 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 227 | return nullptr; |
| 228 | } |
Chris Dalton | a378b45 | 2019-12-11 13:24:11 -0500 | [diff] [blame] | 229 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 230 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 231 | } |
| 232 | |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 233 | #ifdef SK_VULKAN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 234 | /*************************************************************************************************/ |
| 235 | sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext& backendContext) { |
| 236 | return GrDirectContext::MakeVulkan(backendContext); |
Greg Daniel | 10a83da | 2018-06-14 09:31:11 -0400 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext& backendContext, |
| 240 | const GrContextOptions& options) { |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 241 | return GrDirectContext::MakeVulkan(backendContext, options); |
| 242 | } |
Greg Daniel | 10a83da | 2018-06-14 09:31:11 -0400 | [diff] [blame] | 243 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 244 | /*************************************************************************************************/ |
| 245 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext) { |
| 246 | GrContextOptions defaultOptions; |
| 247 | return MakeVulkan(backendContext, defaultOptions); |
| 248 | } |
| 249 | |
| 250 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext, |
| 251 | const GrContextOptions& options) { |
| 252 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kVulkan, options)); |
| 253 | |
| 254 | direct->fGpu = GrVkGpu::Make(backendContext, options, direct.get()); |
| 255 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 256 | return nullptr; |
| 257 | } |
| 258 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 259 | return direct; |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 260 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 261 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 262 | |
| 263 | #ifdef SK_METAL |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 264 | /*************************************************************************************************/ |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 265 | sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue) { |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 266 | return GrDirectContext::MakeMetal(device, queue); |
| 267 | } |
| 268 | |
| 269 | sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue, const GrContextOptions& options) { |
| 270 | return GrDirectContext::MakeMetal(device, queue, options); |
| 271 | } |
| 272 | |
| 273 | /*************************************************************************************************/ |
| 274 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 275 | GrContextOptions defaultOptions; |
| 276 | return MakeMetal(device, queue, defaultOptions); |
| 277 | } |
| 278 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 279 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue, |
| 280 | const GrContextOptions& options) { |
| 281 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options)); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 282 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 283 | direct->fGpu = GrMtlTrampoline::MakeGpu(direct.get(), options, device, queue); |
| 284 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 285 | return nullptr; |
| 286 | } |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 287 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 288 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 289 | } |
| 290 | #endif |
| 291 | |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 292 | #ifdef SK_DIRECT3D |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 293 | /*************************************************************************************************/ |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 294 | sk_sp<GrContext> GrContext::MakeDirect3D(const GrD3DBackendContext& backendContext) { |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 295 | return GrDirectContext::MakeDirect3D(backendContext); |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | sk_sp<GrContext> GrContext::MakeDirect3D(const GrD3DBackendContext& backendContext, |
| 299 | const GrContextOptions& options) { |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 300 | return GrDirectContext::MakeDirect3D(backendContext, options); |
| 301 | } |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 302 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 303 | /*************************************************************************************************/ |
| 304 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext) { |
| 305 | GrContextOptions defaultOptions; |
| 306 | return MakeDirect3D(backendContext, defaultOptions); |
| 307 | } |
| 308 | |
| 309 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext, |
| 310 | const GrContextOptions& options) { |
| 311 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDirect3D, options)); |
| 312 | |
| 313 | direct->fGpu = GrD3DGpu::Make(backendContext, options, direct.get()); |
| 314 | if (!direct->init()) { |
Jim Van Verth | d2d4c5e | 2020-02-19 14:57:58 -0500 | [diff] [blame] | 315 | return nullptr; |
| 316 | } |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 317 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 318 | return direct; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 319 | } |
| 320 | #endif |
| 321 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 322 | #ifdef SK_DAWN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 323 | /*************************************************************************************************/ |
Stephen White | a521c96 | 2019-12-04 09:57:48 -0500 | [diff] [blame] | 324 | sk_sp<GrContext> GrContext::MakeDawn(const wgpu::Device& device) { |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 325 | return GrDirectContext::MakeDawn(device); |
| 326 | } |
| 327 | |
| 328 | sk_sp<GrContext> GrContext::MakeDawn(const wgpu::Device& device, const GrContextOptions& options) { |
| 329 | return GrDirectContext::MakeDawn(device, options); |
| 330 | } |
| 331 | |
| 332 | /*************************************************************************************************/ |
| 333 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 334 | GrContextOptions defaultOptions; |
| 335 | return MakeDawn(device, defaultOptions); |
| 336 | } |
| 337 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 338 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device, |
| 339 | const GrContextOptions& options) { |
| 340 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDawn, options)); |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 341 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 342 | direct->fGpu = GrDawnGpu::Make(device, options, direct.get()); |
| 343 | if (!direct->init()) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 344 | return nullptr; |
| 345 | } |
| 346 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 347 | return direct; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 348 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame^] | 349 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 350 | #endif |