Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 GrVkTransferBuffer_DEFINED |
| 9 | #define GrVkTransferBuffer_DEFINED |
| 10 | |
cdalton | 8b1bff2 | 2016-03-25 01:54:54 -0700 | [diff] [blame^] | 11 | #include "GrBuffer.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 12 | #include "GrVkBuffer.h" |
| 13 | #include "vk/GrVkInterface.h" |
| 14 | |
| 15 | class GrVkGpu; |
| 16 | |
cdalton | 8b1bff2 | 2016-03-25 01:54:54 -0700 | [diff] [blame^] | 17 | class GrVkTransferBuffer : public GrBuffer, public GrVkBuffer { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 18 | |
| 19 | public: |
| 20 | static GrVkTransferBuffer* Create(GrVkGpu* gpu, size_t size, GrVkBuffer::Type type); |
| 21 | |
| 22 | protected: |
| 23 | void onAbandon() override; |
| 24 | void onRelease() override; |
| 25 | |
| 26 | private: |
| 27 | GrVkTransferBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc, |
| 28 | const GrVkBuffer::Resource* resource); |
| 29 | void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, |
| 30 | const SkString& dumpName) const override; |
| 31 | |
cdalton | 8b1bff2 | 2016-03-25 01:54:54 -0700 | [diff] [blame^] | 32 | void onMap() override { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 33 | if (!this->wasDestroyed()) { |
cdalton | 8b1bff2 | 2016-03-25 01:54:54 -0700 | [diff] [blame^] | 34 | this->GrBuffer::fMapPtr = this->vkMap(this->getVkGpu()); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
| 38 | void onUnmap() override { |
| 39 | if (!this->wasDestroyed()) { |
| 40 | this->vkUnmap(this->getVkGpu()); |
| 41 | } |
| 42 | } |
| 43 | |
cdalton | 8b1bff2 | 2016-03-25 01:54:54 -0700 | [diff] [blame^] | 44 | bool onUpdateData(const void* src, size_t srcSizeInBytes) override { |
| 45 | SkFAIL("Not implemented for transfer buffers."); |
| 46 | return false; |
| 47 | } |
| 48 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 49 | GrVkGpu* getVkGpu() const { |
| 50 | SkASSERT(!this->wasDestroyed()); |
| 51 | return reinterpret_cast<GrVkGpu*>(this->getGpu()); |
| 52 | } |
| 53 | |
cdalton | 8b1bff2 | 2016-03-25 01:54:54 -0700 | [diff] [blame^] | 54 | typedef GrBuffer INHERITED; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | #endif |