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_MtlMemoryAllocatorImpl_DEFINED 9 #define skgpu_MtlMemoryAllocatorImpl_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/gpu/mtl/MtlMemoryAllocator.h" 13 14 #import <Metal/Metal.h> 15 16 namespace skgpu { 17 18 class MtlMemoryAllocatorImpl : public MtlMemoryAllocator { 19 public: 20 static sk_sp<MtlMemoryAllocator> Make(id<MTLDevice>); 21 ~MtlMemoryAllocatorImpl()22 ~MtlMemoryAllocatorImpl() override {} 23 24 id<MTLBuffer> newBufferWithLength(NSUInteger length, MTLResourceOptions options, 25 sk_sp<skgpu::MtlAlloc>* allocation) override; 26 id<MTLTexture> newTextureWithDescriptor(MTLTextureDescriptor* texDesc, 27 sk_sp<skgpu::MtlAlloc>* allocation) override; 28 29 class Alloc : public MtlAlloc { 30 public: Alloc()31 Alloc() {} ~Alloc()32 ~Alloc() override { 33 // TODO: free allocation 34 } 35 private: 36 friend class MtlMemoryAllocatorImpl; 37 // TODO: allocation data goes here 38 }; 39 40 private: MtlMemoryAllocatorImpl(id<MTLDevice> device)41 MtlMemoryAllocatorImpl(id<MTLDevice> device) : fDevice(device) {} 42 43 id<MTLDevice> fDevice; 44 }; 45 46 } // namespace skgpu 47 48 #endif // skgpu_MtlMemoryAllocatorImpl_DEFINED 49