1 /*
2 * Copyright 2017 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 "GrVkTexelBuffer.h"
9
10 #include "GrVkGpu.h"
11
GrVkTexelBuffer(GrVkGpu * gpu,const GrVkBuffer::Desc & desc,const GrVkBuffer::Resource * bufferResource)12 GrVkTexelBuffer::GrVkTexelBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
13 const GrVkBuffer::Resource* bufferResource)
14 : INHERITED(gpu, desc.fSizeInBytes, kTexel_GrBufferType,
15 kDynamic_GrAccessPattern)
16 , GrVkBuffer(desc, bufferResource) {
17 this->registerWithCache(SkBudgeted::kYes);
18 }
19
Create(GrVkGpu * gpu,size_t size,bool dynamic)20 GrVkTexelBuffer* GrVkTexelBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic) {
21 GrVkBuffer::Desc desc;
22 desc.fDynamic = dynamic;
23 desc.fType = GrVkBuffer::kTexel_Type;
24 desc.fSizeInBytes = size;
25
26 const GrVkBuffer::Resource* bufferResource = GrVkBuffer::Create(gpu, desc);
27 if (!bufferResource) {
28 return nullptr;
29 }
30 GrVkTexelBuffer* buffer = new GrVkTexelBuffer(gpu, desc, bufferResource);
31 if (!buffer) {
32 bufferResource->unref(gpu);
33 }
34 return buffer;
35 }
36
onRelease()37 void GrVkTexelBuffer::onRelease() {
38 if (!this->wasDestroyed()) {
39 this->vkRelease(this->getVkGpu());
40 }
41
42 INHERITED::onRelease();
43 }
44
onAbandon()45 void GrVkTexelBuffer::onAbandon() {
46 this->vkAbandon();
47 INHERITED::onAbandon();
48 }
49
onMap()50 void GrVkTexelBuffer::onMap() {
51 if (!this->wasDestroyed()) {
52 this->GrBuffer::fMapPtr = this->vkMap(this->getVkGpu());
53 }
54 }
55
onUnmap()56 void GrVkTexelBuffer::onUnmap() {
57 if (!this->wasDestroyed()) {
58 this->vkUnmap(this->getVkGpu());
59 }
60 }
61
onUpdateData(const void * src,size_t srcSizeInBytes)62 bool GrVkTexelBuffer::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
getVkGpu() const70 GrVkGpu* GrVkTexelBuffer::getVkGpu() const {
71 SkASSERT(!this->wasDestroyed());
72 return static_cast<GrVkGpu*>(this->getGpu());
73 }
74