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