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 GrDawnRingBuffer_DEFINED
9 #define GrDawnRingBuffer_DEFINED
10 
11 #include "src/gpu/GrBuffer.h"
12 #include "src/gpu/dawn/GrDawnBuffer.h"
13 #include "dawn/dawncpp.h"
14 
15 class GrDawnGpu;
16 
17 class GrDawnRingBuffer : public SkRefCnt {
18 public:
19     GrDawnRingBuffer(GrDawnGpu* gpu, dawn::BufferUsage usage);
20     ~GrDawnRingBuffer() override;
21 
22     struct Slice {
SliceSlice23         Slice(dawn::Buffer buffer, int offset) : fBuffer(buffer), fOffset(offset) {}
SliceSlice24         Slice() : fBuffer(nullptr), fOffset(0) {}
SliceSlice25         Slice(const Slice& other) : fBuffer(other.fBuffer), fOffset(other.fOffset) {}
26         Slice& operator=(const Slice& other) {
27             fBuffer = other.fBuffer;
28             fOffset = other.fOffset;
29             return *this;
30         }
31         dawn::Buffer fBuffer;
32         int fOffset;
33     };
34     Slice allocate(int size);
35 
36 private:
37     GrDawnGpu*            fGpu;
38     dawn::BufferUsage     fUsage;
39     dawn::Buffer          fBuffer;
40     int                   fOffset = 0;
41 };
42 
43 #endif
44