blob: 8982015c1e3c4376bb6d78002417948501a87cba [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
Adlai Holler3acc69a2020-10-13 08:20:51 -040011#include "include/core/SkTraceMemoryDump.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/gpu/GrContextThreadSafeProxy.h"
Adlai Holler9555f292020-10-09 09:41:14 -040013#include "src/core/SkTaskGroup.h"
14#include "src/gpu/GrClientMappedBufferManager.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrContextThreadSafeProxyPriv.h"
Adlai Hollera0693042020-10-14 11:23:11 -040016#include "src/gpu/GrDirectContextPriv.h"
Adlai Holler4aa4c602020-10-12 13:58:52 -040017#include "src/gpu/GrDrawingManager.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrGpu.h"
Adlai Holler9555f292020-10-09 09:41:14 -040019#include "src/gpu/GrResourceProvider.h"
20#include "src/gpu/GrShaderUtils.h"
Adlai Holler3acc69a2020-10-13 08:20:51 -040021#include "src/image/SkImage_GpuBase.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050022
Adlai Holler4aa4c602020-10-12 13:58:52 -040023#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "src/gpu/effects/GrSkSLFP.h"
25#include "src/gpu/gl/GrGLGpu.h"
26#include "src/gpu/mock/GrMockGpu.h"
Robert Phillips5edf5102020-08-10 16:30:36 -040027#include "src/gpu/ops/GrSmallPathAtlasMgr.h"
Robert Phillipse19babf2020-04-06 13:57:30 -040028#include "src/gpu/text/GrAtlasManager.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050029#include "src/gpu/text/GrStrikeCache.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050030#ifdef SK_METAL
Mike Kleinc0bd9f92019-04-23 12:05:21 -050031#include "src/gpu/mtl/GrMtlTrampoline.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050032#endif
33#ifdef SK_VULKAN
Mike Kleinc0bd9f92019-04-23 12:05:21 -050034#include "src/gpu/vk/GrVkGpu.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050035#endif
Jim Van Verthd2d4c5e2020-02-19 14:57:58 -050036#ifdef SK_DIRECT3D
37#include "src/gpu/d3d/GrD3DGpu.h"
38#endif
Stephen White985741a2019-07-18 11:43:45 -040039#ifdef SK_DAWN
Mike Klein52337de2019-07-25 09:00:52 -050040#include "src/gpu/dawn/GrDawnGpu.h"
Stephen White985741a2019-07-18 11:43:45 -040041#endif
Adlai Holler6d0745b2020-10-13 13:29:00 -040042#include <memory>
Robert Phillipsa3457b82018-03-08 11:30:12 -050043
Brian Salomon24069eb2020-06-24 10:19:52 -040044#if GR_TEST_UTILS
45# include "include/utils/SkRandom.h"
46# if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
47# include <sanitizer/lsan_interface.h>
48# endif
49#endif
50
Adlai Holler9555f292020-10-09 09:41:14 -040051#define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(this->singleOwner())
52
Robert Phillipsad248452020-06-30 09:27:52 -040053GrDirectContext::GrDirectContext(GrBackendApi backend, const GrContextOptions& options)
Robert Phillips3262bc82020-08-10 12:11:58 -040054 : INHERITED(GrContextThreadSafeProxyPriv::Make(backend, options)) {
Robert Phillipsad248452020-06-30 09:27:52 -040055}
Robert Phillipsa3457b82018-03-08 11:30:12 -050056
Robert Phillipsad248452020-06-30 09:27:52 -040057GrDirectContext::~GrDirectContext() {
Adlai Holler9555f292020-10-09 09:41:14 -040058 ASSERT_SINGLE_OWNER
Robert Phillipsad248452020-06-30 09:27:52 -040059 // this if-test protects against the case where the context is being destroyed
60 // before having been fully created
Adlai Holler9555f292020-10-09 09:41:14 -040061 if (fGpu) {
Greg Daniel0a2464f2020-05-14 15:45:44 -040062 this->flushAndSubmit();
Robert Phillipsa3457b82018-03-08 11:30:12 -050063 }
Adlai Holler9555f292020-10-09 09:41:14 -040064
65 this->destroyDrawingManager();
66 fMappedBufferManager.reset();
67
68 // Ideally we could just let the ptr drop, but resource cache queries this ptr in releaseAll.
69 if (fResourceCache) {
70 fResourceCache->releaseAll();
71 }
Robert Phillipsad248452020-06-30 09:27:52 -040072}
Robert Phillipsa3457b82018-03-08 11:30:12 -050073
Adlai Holler61a591c2020-10-12 12:38:33 -040074sk_sp<GrContextThreadSafeProxy> GrDirectContext::threadSafeProxy() {
75 return INHERITED::threadSafeProxy();
76}
77
Adlai Hollera7a40442020-10-09 09:49:42 -040078void GrDirectContext::resetGLTextureBindings() {
79 if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) {
80 return;
81 }
82 fGpu->resetTextureBindings();
83}
84
85void GrDirectContext::resetContext(uint32_t state) {
86 ASSERT_SINGLE_OWNER
87 fGpu->markContextDirty(state);
88}
89
Robert Phillipsad248452020-06-30 09:27:52 -040090void GrDirectContext::abandonContext() {
Adlai Hollera7a40442020-10-09 09:49:42 -040091 if (INHERITED::abandoned()) {
92 return;
93 }
94
Robert Phillipsad248452020-06-30 09:27:52 -040095 INHERITED::abandonContext();
Adlai Hollera7a40442020-10-09 09:49:42 -040096
97 fStrikeCache->freeAll();
98
99 fMappedBufferManager->abandon();
100
101 fResourceProvider->abandon();
102
Robert Phillipseb999bc2020-11-03 08:41:47 -0500103 // abandon first so destructors don't try to free the resources in the API.
Adlai Hollera7a40442020-10-09 09:49:42 -0400104 fResourceCache->abandonAll();
105
106 fGpu->disconnect(GrGpu::DisconnectType::kAbandon);
107
108 fMappedBufferManager.reset();
Robert Phillips079455c2020-08-11 15:18:46 -0400109 if (fSmallPathAtlasMgr) {
110 fSmallPathAtlasMgr->reset();
111 }
Robert Phillipsad248452020-06-30 09:27:52 -0400112 fAtlasManager->freeAll();
113}
Robert Phillipsa3457b82018-03-08 11:30:12 -0500114
Adlai Hollera7a40442020-10-09 09:49:42 -0400115bool GrDirectContext::abandoned() {
116 if (INHERITED::abandoned()) {
117 return true;
118 }
119
120 if (fGpu && fGpu->isDeviceLost()) {
121 this->abandonContext();
122 return true;
123 }
124 return false;
125}
126
Adlai Holler61a591c2020-10-12 12:38:33 -0400127bool GrDirectContext::oomed() { return fGpu ? fGpu->checkAndResetOOMed() : false; }
128
Robert Phillipsad248452020-06-30 09:27:52 -0400129void GrDirectContext::releaseResourcesAndAbandonContext() {
Adlai Holler61a591c2020-10-12 12:38:33 -0400130 if (INHERITED::abandoned()) {
131 return;
132 }
133
134 INHERITED::abandonContext();
135
136 fMappedBufferManager.reset();
137
138 fResourceProvider->abandon();
139
140 // Release all resources in the backend 3D API.
141 fResourceCache->releaseAll();
142
143 fGpu->disconnect(GrGpu::DisconnectType::kCleanup);
Robert Phillips079455c2020-08-11 15:18:46 -0400144 if (fSmallPathAtlasMgr) {
145 fSmallPathAtlasMgr->reset();
146 }
Robert Phillipsad248452020-06-30 09:27:52 -0400147 fAtlasManager->freeAll();
148}
Robert Phillips6db27c22019-05-01 10:43:56 -0400149
Robert Phillipsad248452020-06-30 09:27:52 -0400150void GrDirectContext::freeGpuResources() {
Adlai Holler4aa4c602020-10-12 13:58:52 -0400151 ASSERT_SINGLE_OWNER
152
153 if (this->abandoned()) {
154 return;
155 }
156
Robert Phillipsad248452020-06-30 09:27:52 -0400157 this->flushAndSubmit();
Robert Phillips079455c2020-08-11 15:18:46 -0400158 if (fSmallPathAtlasMgr) {
159 fSmallPathAtlasMgr->reset();
160 }
Robert Phillipsad248452020-06-30 09:27:52 -0400161 fAtlasManager->freeAll();
Robert Phillips56181ba2019-03-08 12:00:45 -0500162
Adlai Holler4aa4c602020-10-12 13:58:52 -0400163 // TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here.
164 // Some slack in the GrTextBlob's implementation requires it though. That could be fixed.
165 fStrikeCache->freeAll();
166
167 this->drawingManager()->freeGpuResources();
168
169 fResourceCache->purgeAllUnlocked();
Robert Phillipsad248452020-06-30 09:27:52 -0400170}
Robert Phillipsa3457b82018-03-08 11:30:12 -0500171
Robert Phillipsad248452020-06-30 09:27:52 -0400172bool GrDirectContext::init() {
Adlai Holler9555f292020-10-09 09:41:14 -0400173 ASSERT_SINGLE_OWNER
174 if (!fGpu) {
Robert Phillipsad248452020-06-30 09:27:52 -0400175 return false;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500176 }
177
Adlai Holler9555f292020-10-09 09:41:14 -0400178 fThreadSafeProxy->priv().init(fGpu->refCaps());
Robert Phillipsad248452020-06-30 09:27:52 -0400179 if (!INHERITED::init()) {
180 return false;
181 }
Robert Phillipsa3457b82018-03-08 11:30:12 -0500182
Adlai Holler9555f292020-10-09 09:41:14 -0400183 SkASSERT(this->getTextBlobCache());
184 SkASSERT(this->threadSafeCache());
185
186 fStrikeCache = std::make_unique<GrStrikeCache>();
187 fResourceCache = std::make_unique<GrResourceCache>(this->caps(), this->singleOwner(),
188 this->contextID());
189 fResourceCache->setProxyProvider(this->proxyProvider());
190 fResourceCache->setThreadSafeCache(this->threadSafeCache());
191 fResourceProvider = std::make_unique<GrResourceProvider>(fGpu.get(), fResourceCache.get(),
192 this->singleOwner());
193 fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID());
194
195 fDidTestPMConversions = false;
196
197 // DDL TODO: we need to think through how the task group & persistent cache
198 // get passed on to/shared between all the DDLRecorders created with this context.
199 if (this->options().fExecutor) {
200 fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor);
201 }
202
203 fPersistentCache = this->options().fPersistentCache;
204 fShaderErrorHandler = this->options().fShaderErrorHandler;
205 if (!fShaderErrorHandler) {
206 fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler();
207 }
208
Robert Phillipsad248452020-06-30 09:27:52 -0400209 GrDrawOpAtlas::AllowMultitexturing allowMultitexturing;
210 if (GrContextOptions::Enable::kNo == this->options().fAllowMultipleGlyphCacheTextures ||
211 // multitexturing supported only if range can represent the index + texcoords fully
212 !(this->caps()->shaderCaps()->floatIs32Bits() ||
213 this->caps()->shaderCaps()->integerSupport())) {
214 allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kNo;
215 } else {
216 allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes;
217 }
218
219 GrProxyProvider* proxyProvider = this->priv().proxyProvider();
220
Robert Phillips3262bc82020-08-10 12:11:58 -0400221 fAtlasManager = std::make_unique<GrAtlasManager>(proxyProvider,
222 this->options().fGlyphCacheTextureMaximumBytes,
223 allowMultitexturing);
224 this->priv().addOnFlushCallbackObject(fAtlasManager.get());
Robert Phillipsad248452020-06-30 09:27:52 -0400225
226 return true;
227}
Robert Phillipsa3457b82018-03-08 11:30:12 -0500228
Adlai Holler3a508e92020-10-12 13:58:01 -0400229void GrDirectContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
230 ASSERT_SINGLE_OWNER
231
232 if (resourceCount) {
233 *resourceCount = fResourceCache->getBudgetedResourceCount();
234 }
235 if (resourceBytes) {
236 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
237 }
238}
239
240size_t GrDirectContext::getResourceCachePurgeableBytes() const {
241 ASSERT_SINGLE_OWNER
242 return fResourceCache->getPurgeableBytes();
243}
244
245void GrDirectContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const {
246 ASSERT_SINGLE_OWNER
247 if (maxResources) {
248 *maxResources = -1;
249 }
250 if (maxResourceBytes) {
251 *maxResourceBytes = this->getResourceCacheLimit();
252 }
253}
254
255size_t GrDirectContext::getResourceCacheLimit() const {
256 ASSERT_SINGLE_OWNER
257 return fResourceCache->getMaxResourceBytes();
258}
259
260void GrDirectContext::setResourceCacheLimits(int unused, size_t maxResourceBytes) {
261 ASSERT_SINGLE_OWNER
262 this->setResourceCacheLimit(maxResourceBytes);
263}
264
265void GrDirectContext::setResourceCacheLimit(size_t maxResourceBytes) {
266 ASSERT_SINGLE_OWNER
267 fResourceCache->setLimit(maxResourceBytes);
268}
269
Adlai Holler4aa4c602020-10-12 13:58:52 -0400270void GrDirectContext::purgeUnlockedResources(bool scratchResourcesOnly) {
271 ASSERT_SINGLE_OWNER
272
273 if (this->abandoned()) {
274 return;
275 }
276
277 fResourceCache->purgeUnlockedResources(scratchResourcesOnly);
278 fResourceCache->purgeAsNeeded();
279
280 // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
281 // place to purge stale blobs
282 this->getTextBlobCache()->purgeStaleBlobs();
283}
284
285void GrDirectContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) {
286 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
287
288 ASSERT_SINGLE_OWNER
289
290 if (this->abandoned()) {
291 return;
292 }
293
294 this->checkAsyncWorkCompletion();
295 fMappedBufferManager->process();
296 auto purgeTime = GrStdSteadyClock::now() - msNotUsed;
297
298 fResourceCache->purgeAsNeeded();
299 fResourceCache->purgeResourcesNotUsedSince(purgeTime);
300
301 if (auto ccpr = this->drawingManager()->getCoverageCountingPathRenderer()) {
302 ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime);
303 }
304
305 // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
306 // place to purge stale blobs
307 this->getTextBlobCache()->purgeStaleBlobs();
308}
309
310void GrDirectContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) {
311 ASSERT_SINGLE_OWNER
312
313 if (this->abandoned()) {
314 return;
315 }
316
317 fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources);
318}
319
Adlai Holler3acc69a2020-10-13 08:20:51 -0400320////////////////////////////////////////////////////////////////////////////////
321bool GrDirectContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[],
322 bool deleteSemaphoresAfterWait) {
323 if (!fGpu || fGpu->caps()->semaphoreSupport()) {
324 return false;
325 }
326 GrWrapOwnership ownership =
327 deleteSemaphoresAfterWait ? kAdopt_GrWrapOwnership : kBorrow_GrWrapOwnership;
328 for (int i = 0; i < numSemaphores; ++i) {
329 std::unique_ptr<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore(
330 waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, ownership);
331 // If we failed to wrap the semaphore it means the client didn't give us a valid semaphore
332 // to begin with. Therefore, it is fine to not wait on it.
333 if (sema) {
334 fGpu->waitSemaphore(sema.get());
335 }
336 }
337 return true;
338}
Adlai Holler4aa4c602020-10-12 13:58:52 -0400339
Robert Phillips5edf5102020-08-10 16:30:36 -0400340GrSmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() {
Robert Phillips079455c2020-08-11 15:18:46 -0400341 if (!fSmallPathAtlasMgr) {
342 fSmallPathAtlasMgr = std::make_unique<GrSmallPathAtlasMgr>();
343
344 this->priv().addOnFlushCallbackObject(fSmallPathAtlasMgr.get());
345 }
346
347 if (!fSmallPathAtlasMgr->initAtlas(this->proxyProvider(), this->caps())) {
348 return nullptr;
349 }
350
351 return fSmallPathAtlasMgr.get();
Robert Phillips5edf5102020-08-10 16:30:36 -0400352}
353
Adlai Holler3acc69a2020-10-13 08:20:51 -0400354////////////////////////////////////////////////////////////////////////////////
355
356GrSemaphoresSubmitted GrDirectContext::flush(const GrFlushInfo& info) {
357 ASSERT_SINGLE_OWNER
358 if (this->abandoned()) {
359 if (info.fFinishedProc) {
360 info.fFinishedProc(info.fFinishedContext);
361 }
362 if (info.fSubmittedProc) {
363 info.fSubmittedProc(info.fSubmittedContext, false);
364 }
365 return GrSemaphoresSubmitted::kNo;
366 }
367
Robert Phillips80bfda82020-11-12 09:23:36 -0500368 return this->drawingManager()->flushSurfaces({}, SkSurface::BackendSurfaceAccess::kNoAccess,
369 info, nullptr);
Adlai Holler3acc69a2020-10-13 08:20:51 -0400370}
371
372bool GrDirectContext::submit(bool syncCpu) {
373 ASSERT_SINGLE_OWNER
374 if (this->abandoned()) {
375 return false;
376 }
377
378 if (!fGpu) {
379 return false;
380 }
381
382 return fGpu->submitToGpu(syncCpu);
383}
384
385////////////////////////////////////////////////////////////////////////////////
386
387void GrDirectContext::checkAsyncWorkCompletion() {
388 if (fGpu) {
389 fGpu->checkFinishProcs();
390 }
391}
392
393////////////////////////////////////////////////////////////////////////////////
394
395void GrDirectContext::storeVkPipelineCacheData() {
396 if (fGpu) {
397 fGpu->storeVkPipelineCacheData();
398 }
399}
400
401////////////////////////////////////////////////////////////////////////////////
402
403bool GrDirectContext::supportsDistanceFieldText() const {
404 return this->caps()->shaderCaps()->supportsDistanceFieldText();
405}
406
407//////////////////////////////////////////////////////////////////////////////
408
409void GrDirectContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
410 ASSERT_SINGLE_OWNER
411 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
412 traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes",
413 this->getTextBlobCache()->usedBytes());
414}
415
416size_t GrDirectContext::ComputeImageSize(sk_sp<SkImage> image, GrMipmapped mipMapped,
417 bool useNextPow2) {
418 if (!image->isTextureBacked()) {
419 return 0;
420 }
421 SkImage_GpuBase* gpuImage = static_cast<SkImage_GpuBase*>(as_IB(image.get()));
422 GrTextureProxy* proxy = gpuImage->peekProxy();
423 if (!proxy) {
424 return 0;
425 }
426
427 int colorSamplesPerPixel = 1;
428 return GrSurface::ComputeSize(proxy->backendFormat(), image->dimensions(),
429 colorSamplesPerPixel, mipMapped, useNextPow2);
430}
431
Adlai Holler98dd0042020-10-13 10:04:00 -0400432GrBackendTexture GrDirectContext::createBackendTexture(int width, int height,
433 const GrBackendFormat& backendFormat,
434 GrMipmapped mipMapped,
435 GrRenderable renderable,
436 GrProtected isProtected) {
437 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
438 if (this->abandoned()) {
439 return GrBackendTexture();
440 }
441
442 return fGpu->createBackendTexture({width, height}, backendFormat, renderable,
443 mipMapped, isProtected);
444}
445
446GrBackendTexture GrDirectContext::createBackendTexture(int width, int height,
447 SkColorType skColorType,
448 GrMipmapped mipMapped,
449 GrRenderable renderable,
450 GrProtected isProtected) {
451 if (this->abandoned()) {
452 return GrBackendTexture();
453 }
454
455 const GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable);
456
457 return this->createBackendTexture(width, height, format, mipMapped, renderable, isProtected);
458}
459
460static GrBackendTexture create_and_update_backend_texture(
461 GrDirectContext* dContext,
462 SkISize dimensions,
463 const GrBackendFormat& backendFormat,
464 GrMipmapped mipMapped,
465 GrRenderable renderable,
466 GrProtected isProtected,
467 sk_sp<GrRefCntedCallback> finishedCallback,
468 const GrGpu::BackendTextureData* data) {
469 GrGpu* gpu = dContext->priv().getGpu();
470
471 GrBackendTexture beTex = gpu->createBackendTexture(dimensions, backendFormat, renderable,
472 mipMapped, isProtected);
473 if (!beTex.isValid()) {
474 return {};
475 }
476
477 if (!dContext->priv().getGpu()->updateBackendTexture(beTex,
478 std::move(finishedCallback),
479 data)) {
480 dContext->deleteBackendTexture(beTex);
481 return {};
482 }
483 return beTex;
484}
485
486GrBackendTexture GrDirectContext::createBackendTexture(int width, int height,
487 const GrBackendFormat& backendFormat,
488 const SkColor4f& color,
489 GrMipmapped mipMapped,
490 GrRenderable renderable,
491 GrProtected isProtected,
492 GrGpuFinishedProc finishedProc,
493 GrGpuFinishedContext finishedContext) {
Brian Salomon694ff172020-11-04 16:54:28 -0500494 auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler98dd0042020-10-13 10:04:00 -0400495
496 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
497 if (this->abandoned()) {
498 return {};
499 }
500
501 GrGpu::BackendTextureData data(color);
502 return create_and_update_backend_texture(this, {width, height},
503 backendFormat, mipMapped, renderable, isProtected,
504 std::move(finishedCallback), &data);
505}
506
507GrBackendTexture GrDirectContext::createBackendTexture(int width, int height,
508 SkColorType skColorType,
509 const SkColor4f& color,
510 GrMipmapped mipMapped,
511 GrRenderable renderable,
512 GrProtected isProtected,
513 GrGpuFinishedProc finishedProc,
514 GrGpuFinishedContext finishedContext) {
Brian Salomon694ff172020-11-04 16:54:28 -0500515 auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler98dd0042020-10-13 10:04:00 -0400516
517 if (this->abandoned()) {
518 return {};
519 }
520
521 GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable);
522 if (!format.isValid()) {
523 return {};
524 }
525
526 GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
527 SkColor4f swizzledColor = this->caps()->getWriteSwizzle(format, grColorType).applyTo(color);
528
529 GrGpu::BackendTextureData data(swizzledColor);
530 return create_and_update_backend_texture(this, {width, height}, format,
531 mipMapped, renderable, isProtected,
532 std::move(finishedCallback), &data);
533}
534
535GrBackendTexture GrDirectContext::createBackendTexture(const SkPixmap srcData[],
536 int numProvidedLevels,
537 GrRenderable renderable,
538 GrProtected isProtected,
539 GrGpuFinishedProc finishedProc,
540 GrGpuFinishedContext finishedContext) {
541 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
542
Brian Salomon694ff172020-11-04 16:54:28 -0500543 auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler98dd0042020-10-13 10:04:00 -0400544
545 if (this->abandoned()) {
546 return {};
547 }
548
549 if (!srcData || numProvidedLevels <= 0) {
550 return {};
551 }
552
553 int baseWidth = srcData[0].width();
554 int baseHeight = srcData[0].height();
555 SkColorType colorType = srcData[0].colorType();
556
557 GrMipmapped mipMapped = GrMipmapped::kNo;
558 int numExpectedLevels = 1;
559 if (numProvidedLevels > 1) {
560 numExpectedLevels = SkMipmap::ComputeLevelCount(baseWidth, baseHeight) + 1;
561 mipMapped = GrMipmapped::kYes;
562 }
563
564 if (numProvidedLevels != numExpectedLevels) {
565 return {};
566 }
567
568 GrBackendFormat backendFormat = this->defaultBackendFormat(colorType, renderable);
569
570 GrGpu::BackendTextureData data(srcData);
571 return create_and_update_backend_texture(this, {baseWidth, baseHeight},
572 backendFormat, mipMapped, renderable, isProtected,
573 std::move(finishedCallback), &data);
574}
575
Adlai Holler2e0c70d2020-10-13 08:21:37 -0400576bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
577 const SkColor4f& color,
578 GrGpuFinishedProc finishedProc,
579 GrGpuFinishedContext finishedContext) {
Brian Salomon694ff172020-11-04 16:54:28 -0500580 auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler2e0c70d2020-10-13 08:21:37 -0400581
582 if (this->abandoned()) {
583 return false;
584 }
585
586 GrGpu::BackendTextureData data(color);
587 return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
588}
589
590bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
591 SkColorType skColorType,
592 const SkColor4f& color,
593 GrGpuFinishedProc finishedProc,
594 GrGpuFinishedContext finishedContext) {
Brian Salomon694ff172020-11-04 16:54:28 -0500595 auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler2e0c70d2020-10-13 08:21:37 -0400596
597 if (this->abandoned()) {
598 return false;
599 }
600
601 GrBackendFormat format = backendTexture.getBackendFormat();
602 GrColorType grColorType = SkColorTypeAndFormatToGrColorType(this->caps(), skColorType, format);
603
604 if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, format)) {
605 return false;
606 }
607
608 GrSwizzle swizzle = this->caps()->getWriteSwizzle(format, grColorType);
609 GrGpu::BackendTextureData data(swizzle.applyTo(color));
610
611 return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
612}
613
614bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
615 const SkPixmap srcData[],
616 int numLevels,
617 GrGpuFinishedProc finishedProc,
618 GrGpuFinishedContext finishedContext) {
Brian Salomon694ff172020-11-04 16:54:28 -0500619 auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler2e0c70d2020-10-13 08:21:37 -0400620
621 if (this->abandoned()) {
622 return false;
623 }
624
625 if (!srcData || numLevels <= 0) {
626 return false;
627 }
628
629 int numExpectedLevels = 1;
630 if (backendTexture.hasMipmaps()) {
631 numExpectedLevels = SkMipmap::ComputeLevelCount(backendTexture.width(),
632 backendTexture.height()) + 1;
633 }
634 if (numLevels != numExpectedLevels) {
635 return false;
636 }
637
638 GrGpu::BackendTextureData data(srcData);
639 return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
640}
641
Adlai Holler64e13832020-10-13 08:21:56 -0400642//////////////////////////////////////////////////////////////////////////////
643
644static GrBackendTexture create_and_update_compressed_backend_texture(
645 GrDirectContext* dContext,
646 SkISize dimensions,
647 const GrBackendFormat& backendFormat,
648 GrMipmapped mipMapped,
649 GrProtected isProtected,
650 sk_sp<GrRefCntedCallback> finishedCallback,
651 const GrGpu::BackendTextureData* data) {
652 GrGpu* gpu = dContext->priv().getGpu();
653
654 GrBackendTexture beTex = gpu->createCompressedBackendTexture(dimensions, backendFormat,
655 mipMapped, isProtected);
656 if (!beTex.isValid()) {
657 return {};
658 }
659
660 if (!dContext->priv().getGpu()->updateCompressedBackendTexture(
661 beTex, std::move(finishedCallback), data)) {
662 dContext->deleteBackendTexture(beTex);
663 return {};
664 }
665 return beTex;
666}
667
668GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height,
669 const GrBackendFormat& backendFormat,
670 const SkColor4f& color,
671 GrMipmapped mipMapped,
672 GrProtected isProtected,
673 GrGpuFinishedProc finishedProc,
674 GrGpuFinishedContext finishedContext) {
675 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Brian Salomon694ff172020-11-04 16:54:28 -0500676 auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler64e13832020-10-13 08:21:56 -0400677
678 if (this->abandoned()) {
679 return {};
680 }
681
682 GrGpu::BackendTextureData data(color);
683 return create_and_update_compressed_backend_texture(this, {width, height},
684 backendFormat, mipMapped, isProtected,
685 std::move(finishedCallback), &data);
686}
687
688GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height,
689 SkImage::CompressionType compression,
690 const SkColor4f& color,
691 GrMipmapped mipMapped,
692 GrProtected isProtected,
693 GrGpuFinishedProc finishedProc,
694 GrGpuFinishedContext finishedContext) {
695 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
696 GrBackendFormat format = this->compressedBackendFormat(compression);
697 return this->createCompressedBackendTexture(width, height, format, color,
698 mipMapped, isProtected, finishedProc,
699 finishedContext);
700}
701
702GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height,
703 const GrBackendFormat& backendFormat,
704 const void* compressedData,
705 size_t dataSize,
706 GrMipmapped mipMapped,
707 GrProtected isProtected,
708 GrGpuFinishedProc finishedProc,
709 GrGpuFinishedContext finishedContext) {
710 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Brian Salomon694ff172020-11-04 16:54:28 -0500711 auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler64e13832020-10-13 08:21:56 -0400712
713 if (this->abandoned()) {
714 return {};
715 }
716
717 GrGpu::BackendTextureData data(compressedData, dataSize);
718 return create_and_update_compressed_backend_texture(this, {width, height},
719 backendFormat, mipMapped, isProtected,
720 std::move(finishedCallback), &data);
721}
722
723GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int height,
724 SkImage::CompressionType compression,
725 const void* data, size_t dataSize,
726 GrMipmapped mipMapped,
727 GrProtected isProtected,
728 GrGpuFinishedProc finishedProc,
729 GrGpuFinishedContext finishedContext) {
730 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
731 GrBackendFormat format = this->compressedBackendFormat(compression);
732 return this->createCompressedBackendTexture(width, height, format, data, dataSize, mipMapped,
733 isProtected, finishedProc, finishedContext);
734}
735
736bool GrDirectContext::updateCompressedBackendTexture(const GrBackendTexture& backendTexture,
737 const SkColor4f& color,
738 GrGpuFinishedProc finishedProc,
739 GrGpuFinishedContext finishedContext) {
Brian Salomon694ff172020-11-04 16:54:28 -0500740 auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler64e13832020-10-13 08:21:56 -0400741
742 if (this->abandoned()) {
743 return false;
744 }
745
746 GrGpu::BackendTextureData data(color);
747 return fGpu->updateCompressedBackendTexture(backendTexture, std::move(finishedCallback), &data);
748}
749
750bool GrDirectContext::updateCompressedBackendTexture(const GrBackendTexture& backendTexture,
751 const void* compressedData,
752 size_t dataSize,
753 GrGpuFinishedProc finishedProc,
754 GrGpuFinishedContext finishedContext) {
Brian Salomon694ff172020-11-04 16:54:28 -0500755 auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler64e13832020-10-13 08:21:56 -0400756
757 if (this->abandoned()) {
758 return false;
759 }
760
761 if (!compressedData) {
762 return false;
763 }
764
765 GrGpu::BackendTextureData data(compressedData, dataSize);
766
767 return fGpu->updateCompressedBackendTexture(backendTexture, std::move(finishedCallback), &data);
768}
769
Adlai Holler6d0745b2020-10-13 13:29:00 -0400770//////////////////////////////////////////////////////////////////////////////
771
772bool GrDirectContext::setBackendTextureState(const GrBackendTexture& backendTexture,
773 const GrBackendSurfaceMutableState& state,
774 GrBackendSurfaceMutableState* previousState,
775 GrGpuFinishedProc finishedProc,
776 GrGpuFinishedContext finishedContext) {
Brian Salomon694ff172020-11-04 16:54:28 -0500777 auto callback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler6d0745b2020-10-13 13:29:00 -0400778
779 if (this->abandoned()) {
780 return false;
781 }
782
783 return fGpu->setBackendTextureState(backendTexture, state, previousState, std::move(callback));
784}
785
786
787bool GrDirectContext::setBackendRenderTargetState(const GrBackendRenderTarget& backendRenderTarget,
788 const GrBackendSurfaceMutableState& state,
789 GrBackendSurfaceMutableState* previousState,
790 GrGpuFinishedProc finishedProc,
791 GrGpuFinishedContext finishedContext) {
Brian Salomon694ff172020-11-04 16:54:28 -0500792 auto callback = GrRefCntedCallback::Make(finishedProc, finishedContext);
Adlai Holler6d0745b2020-10-13 13:29:00 -0400793
794 if (this->abandoned()) {
795 return false;
796 }
797
798 return fGpu->setBackendRenderTargetState(backendRenderTarget, state, previousState,
799 std::move(callback));
800}
801
802void GrDirectContext::deleteBackendTexture(GrBackendTexture backendTex) {
803 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
804 // For the Vulkan backend we still must destroy the backend texture when the context is
805 // abandoned.
806 if ((this->abandoned() && this->backend() != GrBackendApi::kVulkan) || !backendTex.isValid()) {
807 return;
808 }
809
810 fGpu->deleteBackendTexture(backendTex);
811}
812
813//////////////////////////////////////////////////////////////////////////////
814
815bool GrDirectContext::precompileShader(const SkData& key, const SkData& data) {
816 return fGpu->precompileShader(key, data);
817}
818
819#ifdef SK_ENABLE_DUMP_GPU
820#include "include/core/SkString.h"
821#include "src/utils/SkJSONWriter.h"
822SkString GrDirectContext::dump() const {
823 SkDynamicMemoryWStream stream;
824 SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty);
825 writer.beginObject();
826
827 writer.appendString("backend", GrBackendApiToStr(this->backend()));
828
829 writer.appendName("caps");
830 this->caps()->dumpJSON(&writer);
831
832 writer.appendName("gpu");
833 this->fGpu->dumpJSON(&writer);
834
835 writer.appendName("context");
836 this->dumpJSON(&writer);
837
838 // Flush JSON to the memory stream
839 writer.endObject();
840 writer.flush();
841
842 // Null terminate the JSON data in the memory stream
843 stream.write8(0);
844
845 // Allocate a string big enough to hold all the data, then copy out of the stream
846 SkString result(stream.bytesWritten());
847 stream.copyToAndReset(result.writable_str());
848 return result;
849}
850#endif
851
John Rosascoa9b348f2019-11-08 13:18:15 -0800852#ifdef SK_GL
Robert Phillipsc7228c62020-07-14 12:57:39 -0400853
Robert Phillipsf4f80112020-07-13 16:13:31 -0400854/*************************************************************************************************/
855sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500856 GrContextOptions defaultOptions;
Jim Van Verth03b8ab22020-02-24 11:36:15 -0500857 return MakeGL(std::move(glInterface), defaultOptions);
Robert Phillipsa3457b82018-03-08 11:30:12 -0500858}
859
Robert Phillipsf4f80112020-07-13 16:13:31 -0400860sk_sp<GrDirectContext> GrDirectContext::MakeGL(const GrContextOptions& options) {
Brian Salomonc1b9c102018-04-06 09:18:00 -0400861 return MakeGL(nullptr, options);
862}
863
Robert Phillipsf4f80112020-07-13 16:13:31 -0400864sk_sp<GrDirectContext> GrDirectContext::MakeGL() {
Brian Salomonc1b9c102018-04-06 09:18:00 -0400865 GrContextOptions defaultOptions;
866 return MakeGL(nullptr, defaultOptions);
867}
868
Brian Salomon24069eb2020-06-24 10:19:52 -0400869#if GR_TEST_UTILS
870GrGLFunction<GrGLGetErrorFn> make_get_error_with_random_oom(GrGLFunction<GrGLGetErrorFn> original) {
871 // A SkRandom and a GrGLFunction<GrGLGetErrorFn> are too big to be captured by a
872 // GrGLFunction<GrGLGetError> (surprise, surprise). So we make a context object and
873 // capture that by pointer. However, GrGLFunction doesn't support calling a destructor
874 // on the thing it captures. So we leak the context.
875 struct GetErrorContext {
876 SkRandom fRandom;
877 GrGLFunction<GrGLGetErrorFn> fGetError;
878 };
879
880 auto errorContext = new GetErrorContext;
881
882#if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
883 __lsan_ignore_object(errorContext);
884#endif
885
886 errorContext->fGetError = original;
887
888 return GrGLFunction<GrGLGetErrorFn>([errorContext]() {
889 GrGLenum error = errorContext->fGetError();
890 if (error == GR_GL_NO_ERROR && (errorContext->fRandom.nextU() % 300) == 0) {
891 error = GR_GL_OUT_OF_MEMORY;
892 }
893 return error;
894 });
895}
896#endif
897
Robert Phillipsf4f80112020-07-13 16:13:31 -0400898sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface,
899 const GrContextOptions& options) {
900 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kOpenGL, options));
Brian Salomon24069eb2020-06-24 10:19:52 -0400901#if GR_TEST_UTILS
902 if (options.fRandomGLOOM) {
903 auto copy = sk_make_sp<GrGLInterface>(*glInterface);
904 copy->fFunctions.fGetError =
905 make_get_error_with_random_oom(glInterface->fFunctions.fGetError);
906#if GR_GL_CHECK_ERROR
907 // Suppress logging GL errors since we'll be synthetically generating them.
908 copy->suppressErrorLogging();
909#endif
910 glInterface = std::move(copy);
911 }
912#endif
Robert Phillipsf4f80112020-07-13 16:13:31 -0400913 direct->fGpu = GrGLGpu::Make(std::move(glInterface), options, direct.get());
914 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500915 return nullptr;
916 }
Robert Phillipsf4f80112020-07-13 16:13:31 -0400917 return direct;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500918}
John Rosascoa9b348f2019-11-08 13:18:15 -0800919#endif
Robert Phillipsa3457b82018-03-08 11:30:12 -0500920
Robert Phillipsf4f80112020-07-13 16:13:31 -0400921/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400922sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions) {
923 GrContextOptions defaultOptions;
924 return MakeMock(mockOptions, defaultOptions);
925}
926
927sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions,
928 const GrContextOptions& options) {
929 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMock, options));
930
931 direct->fGpu = GrMockGpu::Make(mockOptions, options, direct.get());
932 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500933 return nullptr;
934 }
Chris Daltona378b452019-12-11 13:24:11 -0500935
Robert Phillipsf4f80112020-07-13 16:13:31 -0400936 return direct;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500937}
938
Greg Danielb4d89562018-10-03 18:44:49 +0000939#ifdef SK_VULKAN
Robert Phillipsf4f80112020-07-13 16:13:31 -0400940/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400941sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext) {
942 GrContextOptions defaultOptions;
943 return MakeVulkan(backendContext, defaultOptions);
944}
945
946sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext,
947 const GrContextOptions& options) {
948 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kVulkan, options));
949
950 direct->fGpu = GrVkGpu::Make(backendContext, options, direct.get());
951 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500952 return nullptr;
953 }
954
Robert Phillipsf4f80112020-07-13 16:13:31 -0400955 return direct;
Greg Danielb4d89562018-10-03 18:44:49 +0000956}
Robert Phillipsf4f80112020-07-13 16:13:31 -0400957#endif
Robert Phillipsa3457b82018-03-08 11:30:12 -0500958
959#ifdef SK_METAL
Robert Phillipsf4f80112020-07-13 16:13:31 -0400960/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400961sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500962 GrContextOptions defaultOptions;
963 return MakeMetal(device, queue, defaultOptions);
964}
965
Robert Phillipsf4f80112020-07-13 16:13:31 -0400966sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue,
967 const GrContextOptions& options) {
968 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options));
Robert Phillipsa3457b82018-03-08 11:30:12 -0500969
Robert Phillipsf4f80112020-07-13 16:13:31 -0400970 direct->fGpu = GrMtlTrampoline::MakeGpu(direct.get(), options, device, queue);
971 if (!direct->init()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -0500972 return nullptr;
973 }
Timothy Liang4e85e802018-06-28 16:37:18 -0400974
Robert Phillipsf4f80112020-07-13 16:13:31 -0400975 return direct;
Robert Phillipsa3457b82018-03-08 11:30:12 -0500976}
977#endif
978
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500979#ifdef SK_DIRECT3D
Robert Phillipsf4f80112020-07-13 16:13:31 -0400980/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -0400981sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext) {
982 GrContextOptions defaultOptions;
983 return MakeDirect3D(backendContext, defaultOptions);
984}
985
986sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext,
987 const GrContextOptions& options) {
988 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDirect3D, options));
989
990 direct->fGpu = GrD3DGpu::Make(backendContext, options, direct.get());
991 if (!direct->init()) {
Jim Van Verthd2d4c5e2020-02-19 14:57:58 -0500992 return nullptr;
993 }
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500994
Robert Phillipsf4f80112020-07-13 16:13:31 -0400995 return direct;
Jim Van Verthb01e12b2020-02-18 14:34:38 -0500996}
997#endif
998
Stephen White985741a2019-07-18 11:43:45 -0400999#ifdef SK_DAWN
Robert Phillipsf4f80112020-07-13 16:13:31 -04001000/*************************************************************************************************/
Robert Phillipsf4f80112020-07-13 16:13:31 -04001001sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device) {
Stephen White985741a2019-07-18 11:43:45 -04001002 GrContextOptions defaultOptions;
1003 return MakeDawn(device, defaultOptions);
1004}
1005
Robert Phillipsf4f80112020-07-13 16:13:31 -04001006sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device,
1007 const GrContextOptions& options) {
1008 sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDawn, options));
Stephen White985741a2019-07-18 11:43:45 -04001009
Robert Phillipsf4f80112020-07-13 16:13:31 -04001010 direct->fGpu = GrDawnGpu::Make(device, options, direct.get());
1011 if (!direct->init()) {
Stephen White985741a2019-07-18 11:43:45 -04001012 return nullptr;
1013 }
1014
Robert Phillipsf4f80112020-07-13 16:13:31 -04001015 return direct;
Stephen White985741a2019-07-18 11:43:45 -04001016}
Robert Phillipsf4f80112020-07-13 16:13:31 -04001017
Stephen White985741a2019-07-18 11:43:45 -04001018#endif