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 "src/gpu/vk/GrVkGpu.h"
9 #include "src/gpu/vk/GrVkVertexBuffer.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, GrGpuBufferType::kVertex,
14 desc.fDynamic ? kDynamic_GrAccessPattern : kStatic_GrAccessPattern)
15 , GrVkBuffer(desc, bufferResource) {
16 this->registerWithCache(SkBudgeted::kYes);
17 }
18
Make(GrVkGpu * gpu,size_t size,bool dynamic)19 sk_sp<GrVkVertexBuffer> GrVkVertexBuffer::Make(GrVkGpu* gpu, size_t size, bool dynamic) {
20 GrVkBuffer::Desc desc;
21 desc.fDynamic = gpu->protectedContext() ? true : 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
onRelease()37 void GrVkVertexBuffer::onRelease() {
38 if (!this->wasDestroyed()) {
39 this->vkRelease(this->getVkGpu());
40 }
41
42 INHERITED::onRelease();
43 }
44
onAbandon()45 void GrVkVertexBuffer::onAbandon() {
46 if (!this->wasDestroyed()) {
47 this->vkRelease(this->getVkGpu());
48 }
49 INHERITED::onAbandon();
50 }
51
onMap()52 void GrVkVertexBuffer::onMap() {
53 if (!this->wasDestroyed()) {
54 this->GrGpuBuffer::fMapPtr = this->vkMap(this->getVkGpu());
55 }
56 }
57
onUnmap()58 void GrVkVertexBuffer::onUnmap() {
59 if (!this->wasDestroyed()) {
60 this->vkUnmap(this->getVkGpu());
61 }
62 }
63
onUpdateData(const void * src,size_t srcSizeInBytes)64 bool GrVkVertexBuffer::onUpdateData(const void* src, size_t srcSizeInBytes) {
65 if (!this->wasDestroyed()) {
66 return this->vkUpdateData(this->getVkGpu(), src, srcSizeInBytes);
67 } else {
68 return false;
69 }
70 }
71
getVkGpu() const72 GrVkGpu* GrVkVertexBuffer::getVkGpu() const {
73 SkASSERT(!this->wasDestroyed());
74 return static_cast<GrVkGpu*>(this->getGpu());
75 }
76