• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/core/SkTraceMemoryDump.h"
9 #include "src/gpu/vk/GrVkGpu.h"
10 #include "src/gpu/vk/GrVkTransferBuffer.h"
11 
Make(GrVkGpu * gpu,size_t size,GrVkBuffer::Type type)12 sk_sp<GrVkTransferBuffer> GrVkTransferBuffer::Make(GrVkGpu* gpu, size_t size,
13                                                    GrVkBuffer::Type type) {
14     GrVkBuffer::Desc desc;
15     desc.fDynamic = true;
16     SkASSERT(GrVkBuffer::kCopyRead_Type == type || GrVkBuffer::kCopyWrite_Type == type);
17     desc.fType = type;
18     desc.fSizeInBytes = size;
19 
20     const GrVkBuffer::Resource* bufferResource = GrVkBuffer::Create(gpu, desc);
21     if (!bufferResource) {
22         return nullptr;
23     }
24 
25     GrVkTransferBuffer* buffer = new GrVkTransferBuffer(gpu, desc, bufferResource);
26     if (!buffer) {
27         bufferResource->unref(gpu);
28     }
29     return sk_sp<GrVkTransferBuffer>(buffer);
30 }
31 
GrVkTransferBuffer(GrVkGpu * gpu,const GrVkBuffer::Desc & desc,const GrVkBuffer::Resource * bufferResource)32 GrVkTransferBuffer::GrVkTransferBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
33                                        const GrVkBuffer::Resource* bufferResource)
34         : INHERITED(gpu, desc.fSizeInBytes,
35                     kCopyRead_Type == desc.fType ? GrGpuBufferType::kXferCpuToGpu
36                                                  : GrGpuBufferType::kXferGpuToCpu,
37                     kStream_GrAccessPattern)
38         , GrVkBuffer(desc, bufferResource) {
39     this->registerWithCache(SkBudgeted::kYes);
40 }
41 
onRelease()42 void GrVkTransferBuffer::onRelease() {
43     if (!this->wasDestroyed()) {
44         this->vkRelease(this->getVkGpu());
45     }
46 
47     INHERITED::onRelease();
48 }
49 
onAbandon()50 void GrVkTransferBuffer::onAbandon() {
51     this->vkAbandon();
52     INHERITED::onAbandon();
53 }
54 
setMemoryBacking(SkTraceMemoryDump * traceMemoryDump,const SkString & dumpName) const55 void GrVkTransferBuffer::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
56                                           const SkString& dumpName) const {
57     SkString buffer_id;
58     buffer_id.appendU64((uint64_t)this->buffer());
59     traceMemoryDump->setMemoryBacking(dumpName.c_str(), "vk_buffer",
60                                       buffer_id.c_str());
61 }
62