| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrVkBuffer_DEFINED | 8 #ifndef GrVkBuffer_DEFINED |
| 9 #define GrVkBuffer_DEFINED | 9 #define GrVkBuffer_DEFINED |
| 10 | 10 |
| 11 #include "GrVkResource.h" | 11 #include "GrVkResource.h" |
| 12 #include "vk/GrVkDefines.h" | 12 #include "vk/GrVkDefines.h" |
| 13 #include "vk/GrVkTypes.h" | 13 #include "vk/GrVkTypes.h" |
| 14 | 14 |
| 15 class GrVkGpu; | 15 class GrVkGpu; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * This class serves as the base of GrVk*Buffer classes. It was written to avoid
code | 18 * This class serves as the base of GrVk*Buffer classes. It was written to avoid
code |
| 19 * duplication in those classes. | 19 * duplication in those classes. |
| 20 */ | 20 */ |
| 21 class GrVkBuffer : public SkNoncopyable { | 21 class GrVkBuffer : public SkNoncopyable { |
| 22 public: | 22 public: |
| 23 virtual ~GrVkBuffer() { | 23 virtual ~GrVkBuffer() { |
| 24 // either release or abandon should have been called by the owner of thi
s object. | 24 // either release or abandon should have been called by the owner of thi
s object. |
| 25 SkASSERT(!fResource); | 25 SkASSERT(!fResource); |
| 26 delete [] (unsigned char*)fMapPtr; |
| 26 } | 27 } |
| 27 | 28 |
| 28 VkBuffer buffer() const { return fResource->fBuffer; } | 29 VkBuffer buffer() const { return fResource->fBuffer; } |
| 29 const GrVkAlloc& alloc() const { return fResource->fAlloc; } | 30 const GrVkAlloc& alloc() const { return fResource->fAlloc; } |
| 30 const GrVkRecycledResource* resource() const { return fResource; } | 31 const GrVkRecycledResource* resource() const { return fResource; } |
| 31 size_t size() const { return fDesc.fSizeInBytes; } | 32 size_t size() const { return fDesc.fSizeInBytes; } |
| 32 VkDeviceSize offset() const { return fOffset; } | 33 VkDeviceSize offset() const { return fOffset; } |
| 33 | 34 |
| 34 void addMemoryBarrier(const GrVkGpu* gpu, | 35 void addMemoryBarrier(const GrVkGpu* gpu, |
| 35 VkAccessFlags srcAccessMask, | 36 VkAccessFlags srcAccessMask, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 // convenience routine for raw buffer creation | 79 // convenience routine for raw buffer creation |
| 79 static const Resource* Create(const GrVkGpu* gpu, | 80 static const Resource* Create(const GrVkGpu* gpu, |
| 80 const Desc& descriptor); | 81 const Desc& descriptor); |
| 81 | 82 |
| 82 GrVkBuffer(const Desc& desc, const GrVkBuffer::Resource* resource) | 83 GrVkBuffer(const Desc& desc, const GrVkBuffer::Resource* resource) |
| 83 : fDesc(desc), fResource(resource), fOffset(0), fMapPtr(nullptr) { | 84 : fDesc(desc), fResource(resource), fOffset(0), fMapPtr(nullptr) { |
| 84 } | 85 } |
| 85 | 86 |
| 86 void* vkMap(const GrVkGpu* gpu); | 87 void* vkMap(GrVkGpu* gpu) { |
| 87 void vkUnmap(GrVkGpu* gpu); | 88 this->internalMap(gpu, fDesc.fSizeInBytes); |
| 89 return fMapPtr; |
| 90 } |
| 91 void vkUnmap(GrVkGpu* gpu) { this->internalUnmap(gpu, this->size()); } |
| 92 |
| 88 // If the caller passes in a non null createdNewBuffer, this function will s
et the bool to true | 93 // If the caller passes in a non null createdNewBuffer, this function will s
et the bool to true |
| 89 // if it creates a new VkBuffer to upload the data to. | 94 // if it creates a new VkBuffer to upload the data to. |
| 90 bool vkUpdateData(GrVkGpu* gpu, const void* src, size_t srcSizeInBytes, | 95 bool vkUpdateData(GrVkGpu* gpu, const void* src, size_t srcSizeInBytes, |
| 91 bool* createdNewBuffer = nullptr); | 96 bool* createdNewBuffer = nullptr); |
| 92 | 97 |
| 93 void vkAbandon(); | 98 void vkAbandon(); |
| 94 void vkRelease(const GrVkGpu* gpu); | 99 void vkRelease(const GrVkGpu* gpu); |
| 95 | 100 |
| 96 private: | 101 private: |
| 97 virtual const Resource* createResource(GrVkGpu* gpu, | 102 virtual const Resource* createResource(GrVkGpu* gpu, |
| 98 const Desc& descriptor) { | 103 const Desc& descriptor) { |
| 99 return Create(gpu, descriptor); | 104 return Create(gpu, descriptor); |
| 100 } | 105 } |
| 101 | 106 |
| 107 void internalMap(GrVkGpu* gpu, size_t size, bool* createdNewBuffer = nullptr
); |
| 108 void internalUnmap(GrVkGpu* gpu, size_t size); |
| 109 |
| 102 void validate() const; | 110 void validate() const; |
| 103 bool vkIsMapped() const; | 111 bool vkIsMapped() const; |
| 104 | 112 |
| 105 Desc fDesc; | 113 Desc fDesc; |
| 106 const Resource* fResource; | 114 const Resource* fResource; |
| 107 VkDeviceSize fOffset; | 115 VkDeviceSize fOffset; |
| 108 void* fMapPtr; | 116 void* fMapPtr; |
| 109 | 117 |
| 110 typedef SkNoncopyable INHERITED; | 118 typedef SkNoncopyable INHERITED; |
| 111 }; | 119 }; |
| 112 | 120 |
| 113 #endif | 121 #endif |
| OLD | NEW |