blob: 90e67fd4323f7082f5919ba4292400a15eb0c41f [file] [log] [blame]
Timothy Liang49528b62018-08-02 14:18:37 -04001/*
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
Brian Salomondbf70722019-02-07 11:31:24 -050011#include "GrGpuBuffer.h"
Timothy Liang49528b62018-08-02 14:18:37 -040012
13#import <metal/metal.h>
14
15class GrMtlCaps;
16class GrMtlGpu;
17
Brian Salomondbf70722019-02-07 11:31:24 -050018class GrMtlBuffer: public GrGpuBuffer {
Timothy Liang49528b62018-08-02 14:18:37 -040019public:
Brian Salomonae64c192019-02-05 09:41:37 -050020 static sk_sp<GrMtlBuffer> Make(GrMtlGpu*, size_t size, GrGpuBufferType intendedType,
Brian Salomon12d22642019-01-29 14:38:50 -050021 GrAccessPattern, const void* data = nullptr);
Timothy Liang49528b62018-08-02 14:18:37 -040022
23 ~GrMtlBuffer() override;
24
25 id<MTLBuffer> mtlBuffer() const { return fMtlBuffer; }
26
27protected:
Brian Salomonae64c192019-02-05 09:41:37 -050028 GrMtlBuffer(GrMtlGpu*, size_t size, GrGpuBufferType intendedType, GrAccessPattern);
Timothy Liang49528b62018-08-02 14:18:37 -040029
30 void onAbandon() override;
31 void onRelease() override;
32
33private:
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
Timothy Liang49528b62018-08-02 14:18:37 -040047 bool fIsDynamic;
48 id<MTLBuffer> fMtlBuffer;
49 id<MTLBuffer> fMappedBuffer;
50
Brian Salomondbf70722019-02-07 11:31:24 -050051 typedef GrGpuBuffer INHERITED;
Timothy Liang49528b62018-08-02 14:18:37 -040052};
53
54#endif