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
GrVkVertexBuffer(GrVkGpu * gpu,const GrVkBuffer::Desc & desc,const GrVkBuffer::Resource * bufferResource)11 GrVkVertexBuffer::GrVkVertexBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
12 const GrVkBuffer::Resource* bufferResource)
13 : INHERITED(gpu, desc.fSizeInBytes, desc.fDynamic, false)
14 , GrVkBuffer(desc, bufferResource) {
15 this->registerWithCache();
16 }
17
Create(GrVkGpu * gpu,size_t size,bool dynamic)18 GrVkVertexBuffer* GrVkVertexBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic) {
19 GrVkBuffer::Desc desc;
20 desc.fDynamic = dynamic;
21 desc.fType = GrVkBuffer::kVertex_Type;
22 desc.fSizeInBytes = size;
23
24 const GrVkBuffer::Resource* bufferResource = GrVkBuffer::Create(gpu, desc);
25 if (!bufferResource) {
26 return nullptr;
27 }
28
29 GrVkVertexBuffer* buffer = new GrVkVertexBuffer(gpu, desc, bufferResource);
30 if (!buffer) {
31 bufferResource->unref(gpu);
32 }
33 return buffer;
34 }
35
onRelease()36 void GrVkVertexBuffer::onRelease() {
37 if (!this->wasDestroyed()) {
38 this->vkRelease(this->getVkGpu());
39 }
40
41 INHERITED::onRelease();
42 }
43
onAbandon()44 void GrVkVertexBuffer::onAbandon() {
45 this->vkAbandon();
46 INHERITED::onAbandon();
47 }
48
onMap()49 void* GrVkVertexBuffer::onMap() {
50 if (!this->wasDestroyed()) {
51 return this->vkMap(this->getVkGpu());
52 } else {
53 return NULL;
54 }
55 }
56
onUnmap()57 void GrVkVertexBuffer::onUnmap() {
58 if (!this->wasDestroyed()) {
59 this->vkUnmap(this->getVkGpu());
60 }
61 }
62
onUpdateData(const void * src,size_t srcSizeInBytes)63 bool GrVkVertexBuffer::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
getVkGpu() const71 GrVkGpu* GrVkVertexBuffer::getVkGpu() const {
72 SkASSERT(!this->wasDestroyed());
73 return static_cast<GrVkGpu*>(this->getGpu());
74 }
75
76