1 /* 2 * Copyright 2021 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 skgpu_DrawBufferManager_DEFINED 9 #define skgpu_DrawBufferManager_DEFINED 10 11 #include "experimental/graphite/src/DrawTypes.h" 12 #include "include/core/SkRefCnt.h" 13 #include "src/gpu/BufferWriter.h" 14 15 #include <vector> 16 17 namespace skgpu { 18 19 class Buffer; 20 class CommandBuffer; 21 class ResourceProvider; 22 23 class DrawBufferManager { 24 public: 25 DrawBufferManager(ResourceProvider*, size_t uniformStartAlignment); 26 ~DrawBufferManager(); 27 28 std::tuple<VertexWriter, BindBufferInfo> getVertexWriter(size_t requiredBytes); 29 std::tuple<IndexWriter, BindBufferInfo> getIndexWriter(size_t requiredBytes); 30 std::tuple<UniformWriter, BindBufferInfo> getUniformWriter(size_t requiredBytes); 31 32 // Finalizes all buffers and transfers ownership of them to the CommandBuffer. 33 void transferToCommandBuffer(CommandBuffer*); 34 35 private: 36 ResourceProvider* fResourceProvider; 37 38 sk_sp<Buffer> fCurrentVertexBuffer; 39 size_t fVertexOffset = 0; 40 41 sk_sp<Buffer> fCurrentIndexBuffer; 42 size_t fIndexOffset = 0; 43 44 sk_sp<Buffer> fCurrentUniformBuffer; 45 size_t fUniformOffset = 0; 46 47 size_t fUniformStartAlignment; 48 49 std::vector<sk_sp<Buffer>> fUsedBuffers; 50 }; 51 52 } // namespace skgpu 53 54 #endif // skgpu_DrawBufferManager_DEFINED 55