/* * Copyright 2021 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "src/gpu/graphite/mtl/MtlSharedContext.h" #include "include/gpu/graphite/BackendTexture.h" #include "include/gpu/graphite/TextureInfo.h" #include "src/gpu/graphite/Caps.h" #include "src/gpu/graphite/GlobalCache.h" #include "src/gpu/graphite/Log.h" #include "src/gpu/graphite/mtl/MtlCommandBuffer.h" #include "src/gpu/graphite/mtl/MtlResourceProvider.h" #include "src/gpu/graphite/mtl/MtlTexture.h" #include "src/gpu/mtl/MtlMemoryAllocatorImpl.h" namespace skgpu::graphite { sk_sp MtlSharedContext::Make(const MtlBackendContext& context, const ContextOptions& options) { if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) { // no warning needed } else { SKGPU_LOG_E("Skia's Graphite backend no longer supports this OS version."); #ifdef SK_BUILD_FOR_IOS SKGPU_LOG_E("Minimum supported version is iOS/tvOS 13.0."); #else SKGPU_LOG_E("Minimum supported version is MacOS 10.15."); #endif return nullptr; } sk_cfp> device = sk_ret_cfp((id)(context.fDevice.get())); std::unique_ptr caps(new MtlCaps(device.get(), options)); // TODO: Add memory allocator to context once we figure out synchronization sk_sp memoryAllocator = skgpu::MtlMemoryAllocatorImpl::Make(device.get()); if (!memoryAllocator) { SkDEBUGFAIL("No supplied Metal memory allocator and unable to create one internally."); return nullptr; } return sk_sp(new MtlSharedContext(std::move(device), std::move(memoryAllocator), std::move(caps))); } MtlSharedContext::MtlSharedContext(sk_cfp> device, sk_sp memoryAllocator, std::unique_ptr caps) : skgpu::graphite::SharedContext(std::move(caps), BackendApi::kMetal) , fMemoryAllocator(std::move(memoryAllocator)) , fDevice(std::move(device)) {} MtlSharedContext::~MtlSharedContext() { // need to clear out resources before the allocator (if any) is removed this->globalCache()->deleteResources(); } std::unique_ptr MtlSharedContext::makeResourceProvider( SingleOwner* singleOwner, uint32_t recorderID, size_t resourceBudget, bool /* avoidBufferAlloc */) { return std::unique_ptr(new MtlResourceProvider(this, singleOwner, recorderID, resourceBudget)); } } // namespace skgpu::graphite