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) 13 : INHERITED(gpu, desc.fSizeInBytes, kIndex_GrBufferType, 14 desc.fDynamic ? kDynamic_GrAccessPattern : kStatic_GrAccessPattern) 15 , GrVkBuffer(desc, bufferResource) { 16 this->registerWithCache(SkBudgeted::kYes); 17 } 18 19 GrVkIndexBuffer* GrVkIndexBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic) { 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 } 35 return buffer; 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 51 void GrVkIndexBuffer::onMap() { 52 if (!this->wasDestroyed()) { 53 this->GrBuffer::fMapPtr = this->vkMap(this->getVkGpu()); 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 } 75