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