1 /*
2  * Copyright 2019 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 GrDawnBuffer_DEFINED
9 #define GrDawnBuffer_DEFINED
10 
11 #include "src/gpu/GrGpuBuffer.h"
12 #include "dawn/webgpu_cpp.h"
13 
14 class GrDawnGpu;
15 
16 class GrDawnBuffer : public GrGpuBuffer {
17 public:
18     GrDawnBuffer(GrDawnGpu* gpu, size_t sizeInBytes, GrGpuBufferType type, GrAccessPattern pattern);
19 
20     ~GrDawnBuffer() override;
21 
22     void onMap() override;
23     void onUnmap() override;
24     bool onUpdateData(const void* src, size_t srcSizeInBytes) override;
25 
26     GrDawnGpu* getDawnGpu() const;
get()27     wgpu::Buffer get() const { return fBuffer; }
28 
29     void mapWriteAsync();
30     void mapReadAsync();
31 
setMapPtr(void * mapPtr)32     void setMapPtr(void* mapPtr) {
33         fMapPtr = mapPtr;
34     }
35 
36 private:
37     wgpu::Buffer fBuffer;
38 
39     enum class Mappable {
40         kNot,
41         kReadOnly,
42         kWriteOnly,
43     };
44     Mappable fMappable = Mappable::kNot;
45 
46     wgpu::Buffer fStagingBuffer;
47     size_t fStagingOffset = 0;
48 
49     using INHERITED = GrGpuBuffer;
50 };
51 
52 #endif
53