Home | History | Annotate | Download | only in mtl
      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 "GrGpuBuffer.h"
     12 
     13 #import <metal/metal.h>
     14 
     15 class GrMtlCaps;
     16 class GrMtlGpu;
     17 
     18 class GrMtlBuffer: public GrGpuBuffer {
     19 public:
     20     static sk_sp<GrMtlBuffer> Make(GrMtlGpu*, size_t size, GrGpuBufferType intendedType,
     21                                    GrAccessPattern, const void* data = nullptr);
     22 
     23     ~GrMtlBuffer() override;
     24 
     25     id<MTLBuffer> mtlBuffer() const { return fMtlBuffer; }
     26 
     27 protected:
     28     GrMtlBuffer(GrMtlGpu*, size_t size, GrGpuBufferType intendedType, GrAccessPattern);
     29 
     30     void onAbandon() override;
     31     void onRelease() override;
     32 
     33 private:
     34     GrMtlGpu* mtlGpu() const;
     35 
     36     void onMap() override;
     37     void onUnmap() override;
     38     bool onUpdateData(const void* src, size_t srcSizeInBytes) override;
     39 
     40     void internalMap(size_t sizeInBytes);
     41     void internalUnmap(size_t sizeInBytes);
     42 
     43 #ifdef SK_DEBUG
     44     void validate() const;
     45 #endif
     46 
     47     bool fIsDynamic;
     48     id<MTLBuffer> fMtlBuffer;
     49     id<MTLBuffer> fMappedBuffer;
     50 
     51     typedef GrGpuBuffer INHERITED;
     52 };
     53 
     54 #endif
     55