blob: f2e8f3f939fe8003761e0c81fa3cfa619dcccb09 [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"
Adlai Holler4aa4c602020-10-12 13:58:52 -040016#include "src/gpu/GrDrawingManager.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/gpu/GrGpu.h"
Adlai Holler9555f292020-10-09 09:41:14 -040018#include "src/gpu/GrResourceProvider.h"
19#include "src/gpu/GrShaderUtils.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050020
Adlai Holler4aa4c602020-10-12 13:58:52 -040021#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "src/gpu/effects/GrSkSLFP.h"
23#include "src/gpu/gl/GrGLGpu.h"
24#include "src/gpu/mock/GrMockGpu.h"
Robert Phillips5edf5102020-08-10 16:30:36 -040025#include "src/gpu/ops/GrSmallPathAtlasMgr.h"
Robert Phillipse19babf2020-04-06 13:57:30 -040026#include "src/gpu/text/GrAtlasManager.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050027#include "src/gpu/text/GrStrikeCache.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050028#ifdef SK_METAL
Mike Kleinc0bd9f92019-04-23 12:05:21 -050029#include "src/gpu/mtl/GrMtlTrampoline.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050030#endif
31#ifdef SK_VULKAN
Mike Kleinc0bd9f92019-04-23 12:05:21 -050032#include "src/gpu/vk/GrVkGpu.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050033#endif
Jim Van Verthd2d4c5e2020-02-19 14:57:58 -050034#ifdef SK_DIRECT3D
35#include "src/gpu/d3d/GrD3DGpu.h"
36#endif
Stephen White985741a2019-07-18 11:43:45 -040037#ifdef SK_DAWN
Mike Klein52337de2019-07-25 09:00:52 -050038#include "src/gpu/dawn/GrDawnGpu.h"
Stephen White985741a2019-07-18 11:43:45 -040039#endif
Robert Phillipsa3457b82018-03-08 11:30:12 -050040
Brian Salomon24069eb2020-06-24 10:19:52 -040041#if GR_TEST_UTILS
42# include "include/utils/SkRandom.h"
43# if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
44# include <sanitizer/lsan_interface.h>
45# endif
46#endif
47
Robert Phillips6db27c22019-05-01 10:43:56 -040048#ifdef SK_DISABLE_REDUCE_OPLIST_SPLITTING
Greg Danielf41b2bd2019-08-22 16:19:24 -040049static const bool kDefaultReduceOpsTaskSplitting = false;
Robert Phillips6db27c22019-05-01 10:43:56 -040050#else
Greg Danielf41b2bd2019-08-22 16:19:24 -040051static const bool kDefaultReduceOpsTaskSplitting = false;
Robert Phillips6db27c22019-05-01 10:43:56 -040052#endif
53
Adlai Holler9555f292020-10-09 09:41:14 -040054#define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(this->singleOwner())
55
Robert Phillipsad248452020-06-30 09:27:52 -040056GrDirectContext::GrDirectContext(GrBackendApi backend, const GrContextOptions& options)
Robert Phillips3262bc82020-08-10 12:11:58 -040057 : INHERITED(GrContextThreadSafeProxyPriv::Make(backend, options)) {
Robert Phillipsad248452020-06-30 09:27:52 -040058}
Robert Phillipsa3457b82018-03-08 11:30:12 -050059
Robert Phillipsad248452020-06-30 09:27:52 -040060GrDirectContext::~GrDirectContext() {
Adlai Holler9555f292020-10-09 09:41:14 -040061 ASSERT_SINGLE_OWNER
Robert Phillipsad248452020-06-30 09:27:52 -040062 // this if-test protects against the case where the context is being destroyed
63 // before having been fully created
Adlai Holler9555f292020-10-09 09:41:14 -040064 if (fGpu) {
Greg Daniel0a2464f2020-05-14 15:45:44 -040065 this->flushAndSubmit();
Robert Phillipsa3457b82018-03-08 11:30:12 -050066 }
Adlai Holler9555f292020-10-09 09:41:14 -040067
68 this->destroyDrawingManager();
69 fMappedBufferManager.reset();
70
71 // Ideally we could just let the ptr drop, but resource cache queries this ptr in releaseAll.
72 if (fResourceCache) {
73 fResourceCache->releaseAll();
74 }
Robert Phillipsad248452020-06-30 09:27:52 -040075}
Robert Phillipsa3457b82018-03-08 11:30:12 -050076
Adlai Holler61a591c2020-10-12 12:38:33 -040077sk_sp<GrContextThreadSafeProxy> GrDirectContext::threadSafeProxy() {
78 return INHERITED::threadSafeProxy();
79}
80
Adlai Hollera7a40442020-10-09 09:49:42 -040081void GrDirectContext::resetGLTextureBindings() {
82 if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) {
83 return;
84 }
85 fGpu->resetTextureBindings();
86}
87
88void GrDirectContext::resetContext(uint32_t state) {
89 ASSERT_SINGLE_OWNER
90 fGpu->markContextDirty(state);
91}
92
Robert Phillipsad248452020-06-30 09:27:52 -040093void GrDirectContext::abandonContext() {
Adlai Hollera7a40442020-10-09 09:49:42 -040094 if (INHERITED::abandoned()) {
95 return;
96 }
97
Robert Phillipsad248452020-06-30 09:27:52 -040098 INHERITED::abandonContext();
Adlai Hollera7a40442020-10-09 09:49:42 -040099
100 fStrikeCache->freeAll();
101
102 fMappedBufferManager->abandon();
103
104 fResourceProvider->abandon();
105
106 // abandon first to so destructors
107 // don't try to free the resources in the API.
108 fResourceCache->abandonAll();
109
110 fGpu->disconnect(GrGpu::DisconnectType::kAbandon);
111
112 fMappedBufferManager.reset();
Robert Phillips079455c2020-08-11 15:18:46 -0400113 if (fSmallPathAtlasMgr) {
114 fSmallPathAtlasMgr->reset();
115 }
Robert Phillipsad248452020-06-30 09:27:52 -0400116 fAtlasManager->freeAll();
117}
Robert Phillipsa3457b82018-03-08 11:30:12 -0500118
Adlai Hollera7a40442020-10-09 09:49:42 -0400119bool GrDirectContext::abandoned() {
120 if (INHERITED::abandoned()) {
121 return true;
122 }
123
124 if (fGpu && fGpu->isDeviceLost()) {
125 this->abandonContext();
126 return true;
127 }
128 return false;
129}
130
Adlai Holler61a591c2020-10-12 12:38:33 -0400131bool GrDirectContext::oomed() { return fGpu ? fGpu->checkAndResetOOMed() : false; }
132
Robert Phillipsad248452020-06-30 09:27:52 -0400133void GrDirectContext::releaseResourcesAndAbandonContext() {
Adlai Holler61a591c2020-10-12 12:38:33 -0400134 if (INHERITED::abandoned()) {
135 return;
136 }
137
138 INHERITED::abandonContext();
139
140 fMappedBufferManager.reset();
141
142 fResourceProvider->abandon();
143
144 // Release all resources in the backend 3D API.
145 fResourceCache->releaseAll();
146
147 fGpu->disconnect(GrGpu::DisconnectType::kCleanup);
Robert Phillips079455c2020-08-11 15:18:46 -0400148 if (fSmallPathAtlasMgr) {
149 fSmallPathAtlasMgr->reset();
150 }
Robert Phillipsad248452020-06-30 09:27:52 -0400151 fAtlasManager->freeAll();
152}
Robert Phillips6db27c22019-05-01 10:43:56 -0400153
Robert Phillipsad248452020-06-30 09:27:52 -0400154void GrDirectContext::freeGpuResources() {
Adlai Holler4aa4c602020-10-12 13:58:52 -0400155 ASSERT_SINGLE_OWNER
156
157 if (this->abandoned()) {
158 return;
159 }
160
Robert Phillipsad248452020-06-30 09:27:52 -0400161 this->flushAndSubmit();
Robert Phillips079455c2020-08-11 15:18:46 -0400162 if (fSmallPathAtlasMgr) {
163 fSmallPathAtlasMgr->reset();
164 }
Robert Phillipsad248452020-06-30 09:27:52 -0400165 fAtlasManager->freeAll();
Robert Phillips56181ba2019-03-08 12:00:45 -0500166
Adlai Holler4aa4c602020-10-12 13:58:52 -0400167 // TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here.
168 // Some slack in the GrTextBlob's implementation requires it though. That could be fixed.
169 fStrikeCache->freeAll();
170
171 this->drawingManager()->freeGpuResources();
172
173 fResourceCache->purgeAllUnlocked();
Robert Phillipsad248452020-06-30 09:27:52 -0400174}
Robert Phillipsa3457b82018-03-08 11:30:12 -0500175
Robert Phillipsad248452020-06-30 09:27:52 -0400176bool GrDirectContext::init() {
Adlai Holler9555f292020-10-09 09:41:14 -0400177 ASSERT_SINGLE_OWNER
178 if (!fGpu) {
Robert Phillipsad248452020-06-30 09:27:52 -0400179 return false;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500180 }
181
Adlai Holler9555f292020-10-09 09:41:14 -0400182 fThreadSafeProxy->priv().init(fGpu->refCaps());
Robert Phillipsad248452020-06-30 09:27:52 -0400183 if (!INHERITED::init()) {
184 return false;
185 }
Robert Phillipsa3457b82018-03-08 11:30:12 -0500186
Adlai Holler9555f292020-10-09 09:41:14 -0400187 SkASSERT(this->getTextBlobCache());
188 SkASSERT(this->threadSafeCache());
189
190 fStrikeCache = std::make_unique<GrStrikeCache>();
191 fResourceCache = std::make_unique<GrResourceCache>(this->caps(), this->singleOwner(),
192 this->contextID());
193 fResourceCache->setProxyProvider(this->proxyProvider());
194 fResourceCache->setThreadSafeCache(this->threadSafeCache());
195 fResourceProvider = std::make_unique<GrResourceProvider>(fGpu.get(), fResourceCache.get(),
196 this->singleOwner());
197 fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID());
198
199 fDidTestPMConversions = false;
200
201 // DDL TODO: we need to think through how the task group & persistent cache
202 // get passed on to/shared between all the DDLRecorders created with this context.
203 if (this->options().fExecutor) {
204 fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor);
205 }
206
207 fPersistentCache = this->options().fPersistentCache;
208 fShaderErrorHandler = this->options().fShaderErrorHandler;
209 if (!fShaderErrorHandler) {
210 fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler();
211 }
212
Robert Phillipsad248452020-06-30 09:27:52 -0400213 bool reduceOpsTaskSplitting = kDefaultReduceOpsTaskSplitting;
214 if (GrContextOptions::Enable::kNo == this->options().fReduceOpsTaskSplitting) {
215 reduceOpsTaskSplitting = false;
216 } else if (GrContextOptions::Enable::kYes == this->options().fReduceOpsTaskSplitting) {
217 reduceOpsTaskSplitting = true;
218 }
Robert Phillipsa3457b82018-03-08 11:30:12 -0500219
Robert Phillipsad248452020-06-30 09:27:52 -0400220 this->setupDrawingManager(true, reduceOpsTaskSplitting);
221
222 GrDrawOpAtlas::AllowMultitexturing allowMultitexturing;
223 if (GrContextOptions::Enable::kNo == this->options().fAllowMultipleGlyphCacheTextures ||
224 // multitexturing supported only if range can represent the index + texcoords fully
225 !(this->caps()->shaderCaps()->floatIs32Bits() ||
226 this->caps()->shaderCaps()->integerSupport())) {
227 allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kNo;
228 } else {
229 allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes;
230 }
231
232 GrProxyProvider* proxyProvider = this->priv().proxyProvider();
233
Robert Phillips3262bc82020-08-10 12:11:58 -0400234 fAtlasManager = std::make_unique<GrAtlasManager>(proxyProvider,
235 this->options().fGlyphCacheTextureMaximumBytes,
236 allowMultitexturing);
237 this->priv().addOnFlushCallbackObject(fAtlasManager.get());
Robert Phillipsad248452020-06-30 09:27:52 -0400238
239 return true;
240}
Robert Phillipsa3457b82018-03-08 11:30:12 -0500241
Adlai Holler3a508e92020-10-12 13:58:01 -0400242void GrDirectContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
243 ASSERT_SINGLE_OWNER
244
245 if (resourceCount) {
246 *resourceCount = fResourceCache->getBudgetedResourceCount();
247 }
248 if (resourceBytes) {
249 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
250 }
251}
252
253size_t GrDirectContext::getResourceCachePurgeableBytes() const {
254 ASSERT_SINGLE_OWNER
255 return fResourceCache->getPurgeableBytes();
256}
257
258void GrDirectContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const {
259 ASSERT_SINGLE_OWNER
260 if (maxResources) {
261 *maxResources = -1;
262 }
263 if (maxResourceBytes) {
264 *maxResourceBytes = this->getResourceCacheLimit();
265 }
266}
267
268size_t GrDirectContext::getResourceCacheLimit() const {
269 ASSERT_SINGLE_OWNER
270 return fResourceCache->getMaxResourceBytes();
271}
272
273void GrDirectContext::setResourceCacheLimits(int unused, size_t maxResourceBytes) {
274 ASSERT_SINGLE_OWNER
275 this->setResourceCacheLimit(maxResourceBytes);
276}
277
278void GrDirectContext::setResourceCacheLimit(size_t maxResourceBytes) {
279 ASSERT_SINGLE_OWNER
280 fResourceCache->setLimit(maxResourceBytes);
281}
282
Adlai Holler4aa4c602020-10-12 13:58:52 -0400283void GrDirectContext::purgeUnlockedResources(bool scratchResourcesOnly) {
284 ASSERT_SINGLE_OWNER
285
286 if (this->abandoned()) {
287 return;
288 }
289
290 fResourceCache->purgeUnlockedResources(scratchResourcesOnly);
291 fResourceCache->purgeAsNeeded();
292
293 // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
294 // place to purge stale blobs
295 this->getTextBlobCache()->purgeStaleBlobs();
296}
297
298void GrDirectContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) {
299 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
300
301 ASSERT_SINGLE_OWNER
302
303 if (this->abandoned()) {
304 return;
305 }
306
307 this->checkAsyncWorkCompletion();
308 fMappedBufferManager->process();
309 auto purgeTime = GrStdSteadyClock::now() - msNotUsed;
310
311 fResourceCache->purgeAsNeeded();
312 fResourceCache->purgeResourcesNotUsedSince(purgeTime);
313
314 if (auto ccpr = this->drawingManager()->getCoverageCountingPathRenderer()) {
315 ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime);
316 }
317
318 // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
319 // place to purge stale blobs
320 this->getTextBlobCache()->purgeStaleBlobs();
321}
322
323void GrDirectContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) {
324 ASSERT_SINGLE_OWNER
325
326 if (this->abandoned()) {
327 return;
328 }
329
330 fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources);
331}
332
333
Robert Phillips5edf5102020-08-10 16:30:36 -0400334GrSmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() {
Robert Phillips079455c2020-08-11 15:18:46 -0400335 if (!fSmallPathAtlasMgr) {
336 fSmallPathAtlasMgr = std::make_unique<GrSmallPathAtlasMgr>();
337
338 this->priv().addOnFlushCallbackObject(fSmallPathAtlasMgr.get());
339 }
340
341 if (!fSmallPathAtlasMgr->initAtlas(this->proxyProvider(), this->caps())) {
342 return nullptr;
343 }
344
345 return fSmallPathAtlasMgr.get();
Robert Phillips5edf5102020-08-10 16:30:36 -0400346}
347
John Rosascoa9b348f2019-11-08 13:18:15 -0800348#ifdef SK_GL
Robert Phillipsc7228c62020-07-14 12:57:39 -0400349
Robert Phillipsf4f80112020-07-13 16:13:31 -0400350/*************************************************************************************************/
351sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500352 GrContextOptions defaultOptions;
Jim Van Verth03b8ab22020-02-24 11:36:15 -0500353 return MakeGL(std::move(glInterface), defaultOptions);
Robert Phillipsa3457b82018-03-08 11:30:12 -0500354}
355
Robert Phillipsf4f80112020-07-13 16:13:31 -0400356sk_sp<GrDirectContext> GrDirectContext::MakeGL(const GrContextOptions& options) {
Brian Salomonc1b9c102018-04-06 09:18:00 -0400357 return MakeGL(nullptr, options);
358}
359
Robert Phillipsf4f80112020-07-13 16:13:31 -0400360sk_sp<GrDirectContext> GrDirectContext::MakeGL() {
Brian Salomonc1b9c102018-04-06 09:18:00 -0400361 GrContextOptions defaultOptions;
362 return MakeGL(nullptr, defaultOptions);
363}
364
Brian Salomon24069eb2020-06-24 10:19:52 -0400365#if GR_TEST_UTILS
366GrGLFunction<GrGLGetErrorFn> make_get_error_with_random_oom(GrGLFunction<GrGLGetErrorFn> original) {
367 // A SkRandom and a GrGLFunction<GrGLGetErrorFn> are too big to be captured by a
368 // GrGLFunction<GrGLGetError> (surprise, surprise). So we make a context object and
369 // capture that by pointer. However, GrGLFunction doesn't support calling a destructor
370 // on the thing it captures. So we leak the context.
371 struct GetErrorContext {
372 SkRandom fRandom;
373 GrGLFunction<GrGLGetErrorFn> fGetError;
374 };
375
376 auto errorContext = new GetErrorContext;
377
378#if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
379 __lsan_ignore_object(errorContext);
380#endif
381
382 errorContext->fGetError = original;
383
384 return GrGLFunction<GrGLGetErrorFn>([errorContext]() {
385 GrGLenum error = errorContext->fGetError();
386 if (error == GR_GL_NO_ERROR && (errorContext->fRandom.nextU() % 300) == 0) {
387 error = GR_GL_OUT_OF_MEMORY;
388 }
389 return error;
390 });
391}
392#endif
393
Robert Phillipsf4f80112020-07-13 16:13:31 -0400394sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface,
395 const GrContextOptions& options) {
396 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kOpenGL, options));
Brian Salomon24069eb2020-06-24 10:19:52 -0400397#if GR_TEST_UTILS
398 if (options.fRandomGLOOM) {
399 auto copy = sk_make_sp<GrGLInterface>(*glInterface);
400 copy->fFunctions.fGetError =
401 make_get_error_with_random_oom(glInterface->fFunctions.fGetError);
402#if GR_GL_CHECK_ERROR
403 // Suppress logging GL errors since we'll be synthetically generating them.
404 copy->suppressErrorLogging();
405#endif
406 glInterface = std::move(copy);
407 }
408#endif
Robert Phillipsf4f80112020-07-13 16:13:31 -0400409 direct->fGpu = GrGLGpu::Make(std::move(glInterface), options, direct.get());
410 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500411 return nullptr;
412 }
Robert Phillipsf4f80112020-07-13 16:13:31 -0400413 return direct;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500414}
John Rosascoa9b348f2019-11-08 13:18:15 -0800415#endif
Robert Phillipsa3457b82018-03-08 11:30:12 -0500416
Robert Phillipsf4f80112020-07-13 16:13:31 -0400417/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400418sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions) {
419 GrContextOptions defaultOptions;
420 return MakeMock(mockOptions, defaultOptions);
421}
422
423sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions,
424 const GrContextOptions& options) {
425 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMock, options));
426
427 direct->fGpu = GrMockGpu::Make(mockOptions, options, direct.get());
428 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500429 return nullptr;
430 }
Chris Daltona378b452019-12-11 13:24:11 -0500431
Robert Phillipsf4f80112020-07-13 16:13:31 -0400432 return direct;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500433}
434
Greg Danielb4d89562018-10-03 18:44:49 +0000435#ifdef SK_VULKAN
Robert Phillipsf4f80112020-07-13 16:13:31 -0400436/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400437sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext) {
438 GrContextOptions defaultOptions;
439 return MakeVulkan(backendContext, defaultOptions);
440}
441
442sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext,
443 const GrContextOptions& options) {
444 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kVulkan, options));
445
446 direct->fGpu = GrVkGpu::Make(backendContext, options, direct.get());
447 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500448 return nullptr;
449 }
450
Robert Phillipsf4f80112020-07-13 16:13:31 -0400451 return direct;
Greg Danielb4d89562018-10-03 18:44:49 +0000452}
Robert Phillipsf4f80112020-07-13 16:13:31 -0400453#endif
Robert Phillipsa3457b82018-03-08 11:30:12 -0500454
455#ifdef SK_METAL
Robert Phillipsf4f80112020-07-13 16:13:31 -0400456/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400457sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500458 GrContextOptions defaultOptions;
459 return MakeMetal(device, queue, defaultOptions);
460}
461
Robert Phillipsf4f80112020-07-13 16:13:31 -0400462sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue,
463 const GrContextOptions& options) {
464 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options));
Robert Phillipsa3457b82018-03-08 11:30:12 -0500465
Robert Phillipsf4f80112020-07-13 16:13:31 -0400466 direct->fGpu = GrMtlTrampoline::MakeGpu(direct.get(), options, device, queue);
467 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500468 return nullptr;
469 }
Timothy Liang4e85e802018-06-28 16:37:18 -0400470
Robert Phillipsf4f80112020-07-13 16:13:31 -0400471 return direct;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500472}
473#endif
474
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500475#ifdef SK_DIRECT3D
Robert Phillipsf4f80112020-07-13 16:13:31 -0400476/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400477sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext) {
478 GrContextOptions defaultOptions;
479 return MakeDirect3D(backendContext, defaultOptions);
480}
481
482sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext,
483 const GrContextOptions& options) {
484 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDirect3D, options));
485
486 direct->fGpu = GrD3DGpu::Make(backendContext, options, direct.get());
487 if (!direct->init()) {
Jim Van Verthd2d4c5e2020-02-19 14:57:58 -0500488 return nullptr;
489 }
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500490
Robert Phillipsf4f80112020-07-13 16:13:31 -0400491 return direct;
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500492}
493#endif
494
Stephen White985741a2019-07-18 11:43:45 -0400495#ifdef SK_DAWN
Robert Phillipsf4f80112020-07-13 16:13:31 -0400496/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400497sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device) {
Stephen White985741a2019-07-18 11:43:45 -0400498 GrContextOptions defaultOptions;
499 return MakeDawn(device, defaultOptions);
500}
501
Robert Phillipsf4f80112020-07-13 16:13:31 -0400502sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device,
503 const GrContextOptions& options) {
504 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDawn, options));
Stephen White985741a2019-07-18 11:43:45 -0400505
Robert Phillipsf4f80112020-07-13 16:13:31 -0400506 direct->fGpu = GrDawnGpu::Make(device, options, direct.get());
507 if (!direct->init()) {
Stephen White985741a2019-07-18 11:43:45 -0400508 return nullptr;
509 }
510
Robert Phillipsf4f80112020-07-13 16:13:31 -0400511 return direct;
Stephen White985741a2019-07-18 11:43:45 -0400512}
Robert Phillipsf4f80112020-07-13 16:13:31 -0400513
Stephen White985741a2019-07-18 11:43:45 -0400514#endif