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 #include "GrVkUniformBuffer.h" | 8 #include "GrVkUniformBuffer.h" |
9 #include "GrVkGpu.h" | 9 #include "GrVkGpu.h" |
10 | 10 |
| 11 GrVkUniformBuffer* GrVkUniformBuffer::Create(GrVkGpu* gpu, size_t size) { |
| 12 if (0 == size) { |
| 13 return nullptr; |
| 14 } |
| 15 const GrVkResource* resource = nullptr; |
| 16 if (size <= GrVkUniformBuffer::kStandardSize) { |
| 17 resource = gpu->resourceProvider().findOrCreateStandardUniformBufferReso
urce(); |
| 18 } else { |
| 19 resource = CreateResource(gpu, size); |
| 20 } |
| 21 if (!resource) { |
| 22 return nullptr; |
| 23 } |
11 | 24 |
12 GrVkUniformBuffer* GrVkUniformBuffer::Create(GrVkGpu* gpu, size_t size, bool dyn
amic) { | 25 GrVkBuffer::Desc desc; |
| 26 desc.fDynamic = true; |
| 27 desc.fType = GrVkBuffer::kUniform_Type; |
| 28 desc.fSizeInBytes = size; |
| 29 GrVkUniformBuffer* buffer = new GrVkUniformBuffer(gpu, desc, |
| 30 (const GrVkBuffer::Resourc
e*) resource); |
| 31 if (!buffer) { |
| 32 // this will destroy anything we got from the resource provider, |
| 33 // but this avoids a conditional |
| 34 resource->unref(gpu); |
| 35 } |
| 36 return buffer; |
| 37 } |
| 38 |
| 39 const GrVkResource* GrVkUniformBuffer::CreateResource(GrVkGpu* gpu, size_t size)
{ |
13 if (0 == size) { | 40 if (0 == size) { |
14 return nullptr; | 41 return nullptr; |
15 } | 42 } |
16 GrVkBuffer::Desc desc; | 43 GrVkBuffer::Desc desc; |
17 desc.fDynamic = dynamic; | 44 desc.fDynamic = true; |
18 desc.fType = GrVkBuffer::kUniform_Type; | 45 desc.fType = GrVkBuffer::kUniform_Type; |
19 desc.fSizeInBytes = size; | 46 desc.fSizeInBytes = size; |
20 | 47 |
21 const GrVkBuffer::Resource* bufferResource = GrVkBuffer::Create(gpu, desc); | 48 return GrVkBuffer::Create(gpu, desc); |
22 if (!bufferResource) { | 49 } |
23 return nullptr; | 50 |
| 51 void GrVkUniformBuffer::release(const GrVkGpu* gpu) { |
| 52 if (this->size() <= GrVkUniformBuffer::kStandardSize) { |
| 53 (void)fGpu->resourceProvider().recycleStandardUniformBufferResource(this
->resource()); |
24 } | 54 } |
| 55 this->vkRelease(gpu); |
| 56 } |
25 | 57 |
26 GrVkUniformBuffer* buffer = new GrVkUniformBuffer(desc, bufferResource); | 58 void GrVkUniformBuffer::abandon() { |
27 if (!buffer) { | 59 if (this->size() <= GrVkUniformBuffer::kStandardSize) { |
28 bufferResource->unref(gpu); | 60 (void)fGpu->resourceProvider().recycleStandardUniformBufferResource(this
->resource()); |
29 } | 61 } |
30 return buffer; | 62 this->vkAbandon(); |
31 } | 63 } |
OLD | NEW |