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 | #include "GrVkVertexBuffer.h" |
| 9 | #include "GrVkGpu.h" |
| 10 | |
| 11 | GrVkVertexBuffer::GrVkVertexBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc, |
| 12 | const GrVkBuffer::Resource* bufferResource) |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 13 | : INHERITED(gpu, desc.fSizeInBytes, kVertex_GrBufferType, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 14 | desc.fDynamic ? kDynamic_GrAccessPattern : kStatic_GrAccessPattern, false) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 15 | , GrVkBuffer(desc, bufferResource) { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame^] | 16 | this->registerWithCache(SkBudgeted::kYes); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | GrVkVertexBuffer* GrVkVertexBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic) { |
| 20 | GrVkBuffer::Desc desc; |
| 21 | desc.fDynamic = dynamic; |
| 22 | desc.fType = GrVkBuffer::kVertex_Type; |
| 23 | desc.fSizeInBytes = size; |
| 24 | |
| 25 | const GrVkBuffer::Resource* bufferResource = GrVkBuffer::Create(gpu, desc); |
| 26 | if (!bufferResource) { |
| 27 | return nullptr; |
| 28 | } |
| 29 | |
| 30 | GrVkVertexBuffer* buffer = new GrVkVertexBuffer(gpu, desc, bufferResource); |
| 31 | if (!buffer) { |
| 32 | bufferResource->unref(gpu); |
| 33 | } |
| 34 | return buffer; |
| 35 | } |
| 36 | |
| 37 | void GrVkVertexBuffer::onRelease() { |
| 38 | if (!this->wasDestroyed()) { |
| 39 | this->vkRelease(this->getVkGpu()); |
| 40 | } |
| 41 | |
| 42 | INHERITED::onRelease(); |
| 43 | } |
| 44 | |
| 45 | void GrVkVertexBuffer::onAbandon() { |
| 46 | this->vkAbandon(); |
| 47 | INHERITED::onAbandon(); |
| 48 | } |
| 49 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 50 | void GrVkVertexBuffer::onMap() { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 51 | if (!this->wasDestroyed()) { |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 52 | this->GrBuffer::fMapPtr = this->vkMap(this->getVkGpu()); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
| 56 | void GrVkVertexBuffer::onUnmap() { |
| 57 | if (!this->wasDestroyed()) { |
| 58 | this->vkUnmap(this->getVkGpu()); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | bool GrVkVertexBuffer::onUpdateData(const void* src, size_t srcSizeInBytes) { |
| 63 | if (!this->wasDestroyed()) { |
| 64 | return this->vkUpdateData(this->getVkGpu(), src, srcSizeInBytes); |
| 65 | } else { |
| 66 | return false; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | GrVkGpu* GrVkVertexBuffer::getVkGpu() const { |
| 71 | SkASSERT(!this->wasDestroyed()); |
| 72 | return static_cast<GrVkGpu*>(this->getGpu()); |
| 73 | } |