1 /* 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 8 #ifndef GrMtlBuffer_DEFINED 9 #define GrMtlBuffer_DEFINED 10 11 #include "src/gpu/GrGpuBuffer.h" 12 #include "src/gpu/mtl/GrMtlUniformHandler.h" 13 14 #import <Metal/Metal.h> 15 16 class GrMtlCaps; 17 class GrMtlGpu; 18 19 class GrMtlBuffer: public GrGpuBuffer { 20 public: 21 static sk_sp<GrMtlBuffer> Make(GrMtlGpu*, size_t size, GrGpuBufferType intendedType, 22 GrAccessPattern, const void* data = nullptr); 23 24 ~GrMtlBuffer() override; 25 mtlBuffer()26 id<MTLBuffer> mtlBuffer() const { return fMtlBuffer; } offset()27 size_t offset() const { return fOffset; } 28 29 protected: 30 GrMtlBuffer(GrMtlGpu*, size_t size, GrGpuBufferType intendedType, GrAccessPattern); 31 32 void onAbandon() override; 33 void onRelease() override; 34 35 private: 36 GrMtlGpu* mtlGpu() const; 37 38 void onMap() override; 39 void onUnmap() override; 40 bool onUpdateData(const void* src, size_t srcSizeInBytes) override; 41 42 void internalMap(size_t sizeInBytes); 43 void internalUnmap(size_t sizeInBytes); 44 45 #ifdef SK_DEBUG 46 void validate() const; 47 #endif 48 49 bool fIsDynamic; 50 id<MTLBuffer> fMtlBuffer; 51 size_t fOffset; // offset into shared buffer for dynamic buffers 52 id<MTLBuffer> fMappedBuffer; // buffer used by static buffers for uploads 53 54 using INHERITED = GrGpuBuffer; 55 }; 56 57 #endif 58