1 /* 2 * Copyright 2021 Google LLC 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 8 #ifndef skgpu_graphite_MtlSharedContext_DEFINED 9 #define skgpu_graphite_MtlSharedContext_DEFINED 10 11 #include "src/gpu/graphite/SharedContext.h" 12 13 #include "include/ports/SkCFObject.h" 14 15 #include "include/gpu/graphite/mtl/MtlBackendContext.h" 16 #include "src/gpu/graphite/mtl/MtlCaps.h" 17 18 #import <Metal/Metal.h> 19 20 namespace skgpu { 21 class MtlMemoryAllocator; 22 } 23 24 namespace skgpu::graphite { 25 struct ContextOptions; 26 27 class MtlSharedContext final : public SharedContext { 28 public: 29 static sk_sp<SharedContext> Make(const MtlBackendContext&, const ContextOptions&); 30 ~MtlSharedContext() override; 31 memoryAllocator()32 skgpu::MtlMemoryAllocator* memoryAllocator() const { return fMemoryAllocator.get(); } 33 device()34 id<MTLDevice> device() const { return fDevice.get(); } 35 mtlCaps()36 const MtlCaps& mtlCaps() const { return static_cast<const MtlCaps&>(*this->caps()); } 37 38 std::unique_ptr<ResourceProvider> makeResourceProvider(SingleOwner*) override; 39 40 private: 41 42 MtlSharedContext(sk_cfp<id<MTLDevice>>, 43 sk_sp<skgpu::MtlMemoryAllocator> memoryAllocator, 44 std::unique_ptr<const MtlCaps>); 45 46 sk_sp<skgpu::MtlMemoryAllocator> fMemoryAllocator; 47 48 sk_cfp<id<MTLDevice>> fDevice; 49 }; 50 51 } // namespace skgpu::graphite 52 53 #endif // skgpu_graphite_MtlSharedContext_DEFINED 54