blob: dcdcc4734aaec060a02a04f6928c540f04cc4edc [file] [log] [blame]
Robert Phillipsa3457b82018-03-08 11:30:12 -05001/*
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 Daniel54bfb182018-11-20 17:12:36 -05008
Robert Phillipsb7bfbc22020-07-01 12:55:01 -04009#include "include/gpu/GrDirectContext.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrContextThreadSafeProxy.h"
Adlai Holler9555f292020-10-09 09:41:14 -040012#include "src/core/SkTaskGroup.h"
13#include "src/gpu/GrClientMappedBufferManager.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrContextPriv.h"
15#include "src/gpu/GrContextThreadSafeProxyPriv.h"
16#include "src/gpu/GrGpu.h"
Adlai Holler9555f292020-10-09 09:41:14 -040017#include "src/gpu/GrResourceProvider.h"
18#include "src/gpu/GrShaderUtils.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050019
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/effects/GrSkSLFP.h"
21#include "src/gpu/gl/GrGLGpu.h"
22#include "src/gpu/mock/GrMockGpu.h"
Robert Phillips5edf5102020-08-10 16:30:36 -040023#include "src/gpu/ops/GrSmallPathAtlasMgr.h"
Robert Phillipse19babf2020-04-06 13:57:30 -040024#include "src/gpu/text/GrAtlasManager.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "src/gpu/text/GrStrikeCache.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050026#ifdef SK_METAL
Mike Kleinc0bd9f92019-04-23 12:05:21 -050027#include "src/gpu/mtl/GrMtlTrampoline.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050028#endif
29#ifdef SK_VULKAN
Mike Kleinc0bd9f92019-04-23 12:05:21 -050030#include "src/gpu/vk/GrVkGpu.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050031#endif
Jim Van Verthd2d4c5e2020-02-19 14:57:58 -050032#ifdef SK_DIRECT3D
33#include "src/gpu/d3d/GrD3DGpu.h"
34#endif
Stephen White985741a2019-07-18 11:43:45 -040035#ifdef SK_DAWN
Mike Klein52337de2019-07-25 09:00:52 -050036#include "src/gpu/dawn/GrDawnGpu.h"
Stephen White985741a2019-07-18 11:43:45 -040037#endif
Robert Phillipsa3457b82018-03-08 11:30:12 -050038
Brian Salomon24069eb2020-06-24 10:19:52 -040039#if GR_TEST_UTILS
40# include "include/utils/SkRandom.h"
41# if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
42# include <sanitizer/lsan_interface.h>
43# endif
44#endif
45
Robert Phillips6db27c22019-05-01 10:43:56 -040046#ifdef SK_DISABLE_REDUCE_OPLIST_SPLITTING
Greg Danielf41b2bd2019-08-22 16:19:24 -040047static const bool kDefaultReduceOpsTaskSplitting = false;
Robert Phillips6db27c22019-05-01 10:43:56 -040048#else
Greg Danielf41b2bd2019-08-22 16:19:24 -040049static const bool kDefaultReduceOpsTaskSplitting = false;
Robert Phillips6db27c22019-05-01 10:43:56 -040050#endif
51
Adlai Holler9555f292020-10-09 09:41:14 -040052#define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(this->singleOwner())
53
Robert Phillipsad248452020-06-30 09:27:52 -040054GrDirectContext::GrDirectContext(GrBackendApi backend, const GrContextOptions& options)
Robert Phillips3262bc82020-08-10 12:11:58 -040055 : INHERITED(GrContextThreadSafeProxyPriv::Make(backend, options)) {
Robert Phillipsad248452020-06-30 09:27:52 -040056}
Robert Phillipsa3457b82018-03-08 11:30:12 -050057
Robert Phillipsad248452020-06-30 09:27:52 -040058GrDirectContext::~GrDirectContext() {
Adlai Holler9555f292020-10-09 09:41:14 -040059 ASSERT_SINGLE_OWNER
Robert Phillipsad248452020-06-30 09:27:52 -040060 // this if-test protects against the case where the context is being destroyed
61 // before having been fully created
Adlai Holler9555f292020-10-09 09:41:14 -040062 if (fGpu) {
Greg Daniel0a2464f2020-05-14 15:45:44 -040063 this->flushAndSubmit();
Robert Phillipsa3457b82018-03-08 11:30:12 -050064 }
Adlai Holler9555f292020-10-09 09:41:14 -040065
66 this->destroyDrawingManager();
67 fMappedBufferManager.reset();
68
69 // Ideally we could just let the ptr drop, but resource cache queries this ptr in releaseAll.
70 if (fResourceCache) {
71 fResourceCache->releaseAll();
72 }
Robert Phillipsad248452020-06-30 09:27:52 -040073}
Robert Phillipsa3457b82018-03-08 11:30:12 -050074
Adlai Holler61a591c2020-10-12 12:38:33 -040075sk_sp<GrContextThreadSafeProxy> GrDirectContext::threadSafeProxy() {
76 return INHERITED::threadSafeProxy();
77}
78
Adlai Hollera7a40442020-10-09 09:49:42 -040079void GrDirectContext::resetGLTextureBindings() {
80 if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) {
81 return;
82 }
83 fGpu->resetTextureBindings();
84}
85
86void GrDirectContext::resetContext(uint32_t state) {
87 ASSERT_SINGLE_OWNER
88 fGpu->markContextDirty(state);
89}
90
Robert Phillipsad248452020-06-30 09:27:52 -040091void GrDirectContext::abandonContext() {
Adlai Hollera7a40442020-10-09 09:49:42 -040092 if (INHERITED::abandoned()) {
93 return;
94 }
95
Robert Phillipsad248452020-06-30 09:27:52 -040096 INHERITED::abandonContext();
Adlai Hollera7a40442020-10-09 09:49:42 -040097
98 fStrikeCache->freeAll();
99
100 fMappedBufferManager->abandon();
101
102 fResourceProvider->abandon();
103
104 // abandon first to so destructors
105 // don't try to free the resources in the API.
106 fResourceCache->abandonAll();
107
108 fGpu->disconnect(GrGpu::DisconnectType::kAbandon);
109
110 fMappedBufferManager.reset();
Robert Phillips079455c2020-08-11 15:18:46 -0400111 if (fSmallPathAtlasMgr) {
112 fSmallPathAtlasMgr->reset();
113 }
Robert Phillipsad248452020-06-30 09:27:52 -0400114 fAtlasManager->freeAll();
115}
Robert Phillipsa3457b82018-03-08 11:30:12 -0500116
Adlai Hollera7a40442020-10-09 09:49:42 -0400117bool GrDirectContext::abandoned() {
118 if (INHERITED::abandoned()) {
119 return true;
120 }
121
122 if (fGpu && fGpu->isDeviceLost()) {
123 this->abandonContext();
124 return true;
125 }
126 return false;
127}
128
Adlai Holler61a591c2020-10-12 12:38:33 -0400129bool GrDirectContext::oomed() { return fGpu ? fGpu->checkAndResetOOMed() : false; }
130
Robert Phillipsad248452020-06-30 09:27:52 -0400131void GrDirectContext::releaseResourcesAndAbandonContext() {
Adlai Holler61a591c2020-10-12 12:38:33 -0400132 if (INHERITED::abandoned()) {
133 return;
134 }
135
136 INHERITED::abandonContext();
137
138 fMappedBufferManager.reset();
139
140 fResourceProvider->abandon();
141
142 // Release all resources in the backend 3D API.
143 fResourceCache->releaseAll();
144
145 fGpu->disconnect(GrGpu::DisconnectType::kCleanup);
Robert Phillips079455c2020-08-11 15:18:46 -0400146 if (fSmallPathAtlasMgr) {
147 fSmallPathAtlasMgr->reset();
148 }
Robert Phillipsad248452020-06-30 09:27:52 -0400149 fAtlasManager->freeAll();
150}
Robert Phillips6db27c22019-05-01 10:43:56 -0400151
Robert Phillipsad248452020-06-30 09:27:52 -0400152void GrDirectContext::freeGpuResources() {
153 this->flushAndSubmit();
Robert Phillips079455c2020-08-11 15:18:46 -0400154 if (fSmallPathAtlasMgr) {
155 fSmallPathAtlasMgr->reset();
156 }
Robert Phillipsad248452020-06-30 09:27:52 -0400157 fAtlasManager->freeAll();
Robert Phillips56181ba2019-03-08 12:00:45 -0500158
Robert Phillipsad248452020-06-30 09:27:52 -0400159 INHERITED::freeGpuResources();
160}
Robert Phillipsa3457b82018-03-08 11:30:12 -0500161
Robert Phillipsad248452020-06-30 09:27:52 -0400162bool GrDirectContext::init() {
Adlai Holler9555f292020-10-09 09:41:14 -0400163 ASSERT_SINGLE_OWNER
164 if (!fGpu) {
Robert Phillipsad248452020-06-30 09:27:52 -0400165 return false;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500166 }
167
Adlai Holler9555f292020-10-09 09:41:14 -0400168 fThreadSafeProxy->priv().init(fGpu->refCaps());
Robert Phillipsad248452020-06-30 09:27:52 -0400169 if (!INHERITED::init()) {
170 return false;
171 }
Robert Phillipsa3457b82018-03-08 11:30:12 -0500172
Adlai Holler9555f292020-10-09 09:41:14 -0400173 SkASSERT(this->getTextBlobCache());
174 SkASSERT(this->threadSafeCache());
175
176 fStrikeCache = std::make_unique<GrStrikeCache>();
177 fResourceCache = std::make_unique<GrResourceCache>(this->caps(), this->singleOwner(),
178 this->contextID());
179 fResourceCache->setProxyProvider(this->proxyProvider());
180 fResourceCache->setThreadSafeCache(this->threadSafeCache());
181 fResourceProvider = std::make_unique<GrResourceProvider>(fGpu.get(), fResourceCache.get(),
182 this->singleOwner());
183 fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID());
184
185 fDidTestPMConversions = false;
186
187 // DDL TODO: we need to think through how the task group & persistent cache
188 // get passed on to/shared between all the DDLRecorders created with this context.
189 if (this->options().fExecutor) {
190 fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor);
191 }
192
193 fPersistentCache = this->options().fPersistentCache;
194 fShaderErrorHandler = this->options().fShaderErrorHandler;
195 if (!fShaderErrorHandler) {
196 fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler();
197 }
198
Robert Phillipsad248452020-06-30 09:27:52 -0400199 bool reduceOpsTaskSplitting = kDefaultReduceOpsTaskSplitting;
200 if (GrContextOptions::Enable::kNo == this->options().fReduceOpsTaskSplitting) {
201 reduceOpsTaskSplitting = false;
202 } else if (GrContextOptions::Enable::kYes == this->options().fReduceOpsTaskSplitting) {
203 reduceOpsTaskSplitting = true;
204 }
Robert Phillipsa3457b82018-03-08 11:30:12 -0500205
Robert Phillipsad248452020-06-30 09:27:52 -0400206 this->setupDrawingManager(true, reduceOpsTaskSplitting);
207
208 GrDrawOpAtlas::AllowMultitexturing allowMultitexturing;
209 if (GrContextOptions::Enable::kNo == this->options().fAllowMultipleGlyphCacheTextures ||
210 // multitexturing supported only if range can represent the index + texcoords fully
211 !(this->caps()->shaderCaps()->floatIs32Bits() ||
212 this->caps()->shaderCaps()->integerSupport())) {
213 allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kNo;
214 } else {
215 allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes;
216 }
217
218 GrProxyProvider* proxyProvider = this->priv().proxyProvider();
219
Robert Phillips3262bc82020-08-10 12:11:58 -0400220 fAtlasManager = std::make_unique<GrAtlasManager>(proxyProvider,
221 this->options().fGlyphCacheTextureMaximumBytes,
222 allowMultitexturing);
223 this->priv().addOnFlushCallbackObject(fAtlasManager.get());
Robert Phillipsad248452020-06-30 09:27:52 -0400224
225 return true;
226}
Robert Phillipsa3457b82018-03-08 11:30:12 -0500227
Adlai Holler3a508e92020-10-12 13:58:01 -0400228void GrDirectContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
229 ASSERT_SINGLE_OWNER
230
231 if (resourceCount) {
232 *resourceCount = fResourceCache->getBudgetedResourceCount();
233 }
234 if (resourceBytes) {
235 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
236 }
237}
238
239size_t GrDirectContext::getResourceCachePurgeableBytes() const {
240 ASSERT_SINGLE_OWNER
241 return fResourceCache->getPurgeableBytes();
242}
243
244void GrDirectContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const {
245 ASSERT_SINGLE_OWNER
246 if (maxResources) {
247 *maxResources = -1;
248 }
249 if (maxResourceBytes) {
250 *maxResourceBytes = this->getResourceCacheLimit();
251 }
252}
253
254size_t GrDirectContext::getResourceCacheLimit() const {
255 ASSERT_SINGLE_OWNER
256 return fResourceCache->getMaxResourceBytes();
257}
258
259void GrDirectContext::setResourceCacheLimits(int unused, size_t maxResourceBytes) {
260 ASSERT_SINGLE_OWNER
261 this->setResourceCacheLimit(maxResourceBytes);
262}
263
264void GrDirectContext::setResourceCacheLimit(size_t maxResourceBytes) {
265 ASSERT_SINGLE_OWNER
266 fResourceCache->setLimit(maxResourceBytes);
267}
268
Robert Phillips5edf5102020-08-10 16:30:36 -0400269GrSmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() {
Robert Phillips079455c2020-08-11 15:18:46 -0400270 if (!fSmallPathAtlasMgr) {
271 fSmallPathAtlasMgr = std::make_unique<GrSmallPathAtlasMgr>();
272
273 this->priv().addOnFlushCallbackObject(fSmallPathAtlasMgr.get());
274 }
275
276 if (!fSmallPathAtlasMgr->initAtlas(this->proxyProvider(), this->caps())) {
277 return nullptr;
278 }
279
280 return fSmallPathAtlasMgr.get();
Robert Phillips5edf5102020-08-10 16:30:36 -0400281}
282
John Rosascoa9b348f2019-11-08 13:18:15 -0800283#ifdef SK_GL
Robert Phillipsc7228c62020-07-14 12:57:39 -0400284
Robert Phillipsf4f80112020-07-13 16:13:31 -0400285/*************************************************************************************************/
286sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500287 GrContextOptions defaultOptions;
Jim Van Verth03b8ab22020-02-24 11:36:15 -0500288 return MakeGL(std::move(glInterface), defaultOptions);
Robert Phillipsa3457b82018-03-08 11:30:12 -0500289}
290
Robert Phillipsf4f80112020-07-13 16:13:31 -0400291sk_sp<GrDirectContext> GrDirectContext::MakeGL(const GrContextOptions& options) {
Brian Salomonc1b9c102018-04-06 09:18:00 -0400292 return MakeGL(nullptr, options);
293}
294
Robert Phillipsf4f80112020-07-13 16:13:31 -0400295sk_sp<GrDirectContext> GrDirectContext::MakeGL() {
Brian Salomonc1b9c102018-04-06 09:18:00 -0400296 GrContextOptions defaultOptions;
297 return MakeGL(nullptr, defaultOptions);
298}
299
Brian Salomon24069eb2020-06-24 10:19:52 -0400300#if GR_TEST_UTILS
301GrGLFunction<GrGLGetErrorFn> make_get_error_with_random_oom(GrGLFunction<GrGLGetErrorFn> original) {
302 // A SkRandom and a GrGLFunction<GrGLGetErrorFn> are too big to be captured by a
303 // GrGLFunction<GrGLGetError> (surprise, surprise). So we make a context object and
304 // capture that by pointer. However, GrGLFunction doesn't support calling a destructor
305 // on the thing it captures. So we leak the context.
306 struct GetErrorContext {
307 SkRandom fRandom;
308 GrGLFunction<GrGLGetErrorFn> fGetError;
309 };
310
311 auto errorContext = new GetErrorContext;
312
313#if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
314 __lsan_ignore_object(errorContext);
315#endif
316
317 errorContext->fGetError = original;
318
319 return GrGLFunction<GrGLGetErrorFn>([errorContext]() {
320 GrGLenum error = errorContext->fGetError();
321 if (error == GR_GL_NO_ERROR && (errorContext->fRandom.nextU() % 300) == 0) {
322 error = GR_GL_OUT_OF_MEMORY;
323 }
324 return error;
325 });
326}
327#endif
328
Robert Phillipsf4f80112020-07-13 16:13:31 -0400329sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface,
330 const GrContextOptions& options) {
331 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kOpenGL, options));
Brian Salomon24069eb2020-06-24 10:19:52 -0400332#if GR_TEST_UTILS
333 if (options.fRandomGLOOM) {
334 auto copy = sk_make_sp<GrGLInterface>(*glInterface);
335 copy->fFunctions.fGetError =
336 make_get_error_with_random_oom(glInterface->fFunctions.fGetError);
337#if GR_GL_CHECK_ERROR
338 // Suppress logging GL errors since we'll be synthetically generating them.
339 copy->suppressErrorLogging();
340#endif
341 glInterface = std::move(copy);
342 }
343#endif
Robert Phillipsf4f80112020-07-13 16:13:31 -0400344 direct->fGpu = GrGLGpu::Make(std::move(glInterface), options, direct.get());
345 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500346 return nullptr;
347 }
Robert Phillipsf4f80112020-07-13 16:13:31 -0400348 return direct;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500349}
John Rosascoa9b348f2019-11-08 13:18:15 -0800350#endif
Robert Phillipsa3457b82018-03-08 11:30:12 -0500351
Robert Phillipsf4f80112020-07-13 16:13:31 -0400352/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400353sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions) {
354 GrContextOptions defaultOptions;
355 return MakeMock(mockOptions, defaultOptions);
356}
357
358sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions,
359 const GrContextOptions& options) {
360 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMock, options));
361
362 direct->fGpu = GrMockGpu::Make(mockOptions, options, direct.get());
363 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500364 return nullptr;
365 }
Chris Daltona378b452019-12-11 13:24:11 -0500366
Robert Phillipsf4f80112020-07-13 16:13:31 -0400367 return direct;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500368}
369
Greg Danielb4d89562018-10-03 18:44:49 +0000370#ifdef SK_VULKAN
Robert Phillipsf4f80112020-07-13 16:13:31 -0400371/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400372sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext) {
373 GrContextOptions defaultOptions;
374 return MakeVulkan(backendContext, defaultOptions);
375}
376
377sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext,
378 const GrContextOptions& options) {
379 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kVulkan, options));
380
381 direct->fGpu = GrVkGpu::Make(backendContext, options, direct.get());
382 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500383 return nullptr;
384 }
385
Robert Phillipsf4f80112020-07-13 16:13:31 -0400386 return direct;
Greg Danielb4d89562018-10-03 18:44:49 +0000387}
Robert Phillipsf4f80112020-07-13 16:13:31 -0400388#endif
Robert Phillipsa3457b82018-03-08 11:30:12 -0500389
390#ifdef SK_METAL
Robert Phillipsf4f80112020-07-13 16:13:31 -0400391/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400392sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500393 GrContextOptions defaultOptions;
394 return MakeMetal(device, queue, defaultOptions);
395}
396
Robert Phillipsf4f80112020-07-13 16:13:31 -0400397sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue,
398 const GrContextOptions& options) {
399 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options));
Robert Phillipsa3457b82018-03-08 11:30:12 -0500400
Robert Phillipsf4f80112020-07-13 16:13:31 -0400401 direct->fGpu = GrMtlTrampoline::MakeGpu(direct.get(), options, device, queue);
402 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500403 return nullptr;
404 }
Timothy Liang4e85e802018-06-28 16:37:18 -0400405
Robert Phillipsf4f80112020-07-13 16:13:31 -0400406 return direct;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500407}
408#endif
409
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500410#ifdef SK_DIRECT3D
Robert Phillipsf4f80112020-07-13 16:13:31 -0400411/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400412sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext) {
413 GrContextOptions defaultOptions;
414 return MakeDirect3D(backendContext, defaultOptions);
415}
416
417sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext,
418 const GrContextOptions& options) {
419 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDirect3D, options));
420
421 direct->fGpu = GrD3DGpu::Make(backendContext, options, direct.get());
422 if (!direct->init()) {
Jim Van Verthd2d4c5e2020-02-19 14:57:58 -0500423 return nullptr;
424 }
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500425
Robert Phillipsf4f80112020-07-13 16:13:31 -0400426 return direct;
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500427}
428#endif
429
Stephen White985741a2019-07-18 11:43:45 -0400430#ifdef SK_DAWN
Robert Phillipsf4f80112020-07-13 16:13:31 -0400431/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400432sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device) {
Stephen White985741a2019-07-18 11:43:45 -0400433 GrContextOptions defaultOptions;
434 return MakeDawn(device, defaultOptions);
435}
436
Robert Phillipsf4f80112020-07-13 16:13:31 -0400437sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device,
438 const GrContextOptions& options) {
439 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDawn, options));
Stephen White985741a2019-07-18 11:43:45 -0400440
Robert Phillipsf4f80112020-07-13 16:13:31 -0400441 direct->fGpu = GrDawnGpu::Make(device, options, direct.get());
442 if (!direct->init()) {
Stephen White985741a2019-07-18 11:43:45 -0400443 return nullptr;
444 }
445
Robert Phillipsf4f80112020-07-13 16:13:31 -0400446 return direct;
Stephen White985741a2019-07-18 11:43:45 -0400447}
Robert Phillipsf4f80112020-07-13 16:13:31 -0400448
Stephen White985741a2019-07-18 11:43:45 -0400449#endif