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) 13 : INHERITED(gpu, desc.fSizeInBytes, kVertex_GrBufferType, 14 desc.fDynamic ? kDynamic_GrAccessPattern : kStatic_GrAccessPattern) 15 , GrVkBuffer(desc, bufferResource) { 16 this->registerWithCache(SkBudgeted::kYes); 17 } 18 19 sk_sp<GrVkVertexBuffer> GrVkVertexBuffer::Make(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 sk_sp<GrVkVertexBuffer>(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 50 void GrVkVertexBuffer::onMap() { 51 if (!this->wasDestroyed()) { 52 this->GrBuffer::fMapPtr = this->vkMap(this->getVkGpu()); 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 } 74