| 1 | /* |
|---|---|
| 2 | * Copyright 2020 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 GrStagingBuffer_DEFINED |
| 9 | #define GrStagingBuffer_DEFINED |
| 10 | |
| 11 | #include "src/core/SkTInternalLList.h" |
| 12 | |
| 13 | class GrGpu; |
| 14 | |
| 15 | class GrStagingBuffer { |
| 16 | public: |
| 17 | GrStagingBuffer(GrGpu* gpu, size_t size, void* data) : fGpu(gpu), fSize(size), fData(data) {} |
| 18 | virtual ~GrStagingBuffer() { |
| 19 | fGpu = nullptr; |
| 20 | } |
| 21 | void markAvailable(void* data); |
| 22 | struct Slice { |
| 23 | Slice(GrStagingBuffer* buffer, int offset, void* data) |
| 24 | : fBuffer(buffer), fOffset(offset), fData(data) {} |
| 25 | GrStagingBuffer* fBuffer; |
| 26 | int fOffset; |
| 27 | void* fData; |
| 28 | }; |
| 29 | size_t remaining() const { return fSize - fOffset; } |
| 30 | GrGpu* getGpu() const { return fGpu; } |
| 31 | void unmap(); |
| 32 | Slice allocate(size_t size); |
| 33 | private: |
| 34 | virtual void onUnmap() = 0; |
| 35 | |
| 36 | GrGpu* fGpu; |
| 37 | size_t fSize; |
| 38 | size_t fOffset = 0; |
| 39 | void* fData; |
| 40 | |
| 41 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrStagingBuffer); |
| 42 | }; |
| 43 | |
| 44 | #endif |
| 45 |