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 "GrVkRenderTarget.h" | 8 #include "GrVkRenderTarget.h" |
9 | 9 |
10 #include "GrRenderTargetPriv.h" | 10 #include "GrRenderTargetPriv.h" |
11 #include "GrVkCommandBuffer.h" | 11 #include "GrVkCommandBuffer.h" |
12 #include "GrVkFramebuffer.h" | 12 #include "GrVkFramebuffer.h" |
13 #include "GrVkGpu.h" | 13 #include "GrVkGpu.h" |
14 #include "GrVkImageView.h" | 14 #include "GrVkImageView.h" |
15 #include "GrVkResourceProvider.h" | 15 #include "GrVkResourceProvider.h" |
16 #include "GrVkUtil.h" | 16 #include "GrVkUtil.h" |
17 | 17 |
| 18 #include "vk/GrVkTypes.h" |
| 19 |
18 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) | 20 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) |
19 | 21 |
20 // We're virtually derived from GrSurface (via GrRenderTarget) so its | 22 // We're virtually derived from GrSurface (via GrRenderTarget) so its |
21 // constructor must be explicitly called. | 23 // constructor must be explicitly called. |
22 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, | 24 GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, |
23 const GrSurfaceDesc& desc, | 25 const GrSurfaceDesc& desc, |
24 GrGpuResource::LifeCycle lifeCycle, | 26 GrGpuResource::LifeCycle lifeCycle, |
25 const GrVkImage::Resource* imageResource, | 27 const GrVkImage::Resource* imageResource, |
26 const GrVkImage::Resource* msaaResource, | 28 const GrVkImage::Resource* msaaResource, |
27 const GrVkImageView* colorAttachmentView, | 29 const GrVkImageView* colorAttachmentView, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, desc, lifeCycle, imageR
esource); | 198 GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, desc, lifeCycle, imageR
esource); |
197 // Create() will increment the refCount of the image resource if it succeeds | 199 // Create() will increment the refCount of the image resource if it succeeds |
198 imageResource->unref(gpu); | 200 imageResource->unref(gpu); |
199 return rt; | 201 return rt; |
200 } | 202 } |
201 | 203 |
202 GrVkRenderTarget* | 204 GrVkRenderTarget* |
203 GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu, | 205 GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu, |
204 const GrSurfaceDesc& desc, | 206 const GrSurfaceDesc& desc, |
205 GrGpuResource::LifeCycle lifeCycle, | 207 GrGpuResource::LifeCycle lifeCycle, |
206 const GrVkImage::Resource* imageReso
urce) { | 208 const GrVkTextureInfo* info) { |
207 SkASSERT(imageResource); | 209 SkASSERT(info); |
| 210 // We can wrap a rendertarget without its allocation, as long as we don't ta
ke ownership |
| 211 SkASSERT(VK_NULL_HANDLE != info->fImage); |
| 212 SkASSERT(VK_NULL_HANDLE != info->fAlloc || kAdopted_LifeCycle != lifeCycle); |
208 | 213 |
209 // Note: we assume the caller will unref the imageResource | 214 GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTi
ling) |
210 // Create() will increment the refCount, and we'll unref when we're done wit
h it | 215 ? Resource::kLinearTiling_Flag : Resource::
kNo_Flags; |
211 return GrVkRenderTarget::Create(gpu, desc, lifeCycle, imageResource); | 216 |
| 217 const GrVkImage::Resource* imageResource = new GrVkImage::Resource(info->fIm
age, |
| 218 info->fAl
loc, |
| 219 flags); |
| 220 if (!imageResource) { |
| 221 return nullptr; |
| 222 } |
| 223 |
| 224 GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, desc, lifeCycle, imageR
esource); |
| 225 if (rt) { |
| 226 rt->fCurrentLayout = info->fImageLayout; |
| 227 } |
| 228 // Create() will increment the refCount of the image resource if it succeeds |
| 229 imageResource->unref(gpu); |
| 230 return rt; |
212 } | 231 } |
213 | 232 |
214 bool GrVkRenderTarget::completeStencilAttachment() { | 233 bool GrVkRenderTarget::completeStencilAttachment() { |
215 this->createFramebuffer(this->getVkGpu()); | 234 this->createFramebuffer(this->getVkGpu()); |
216 return true; | 235 return true; |
217 } | 236 } |
218 | 237 |
219 void GrVkRenderTarget::createFramebuffer(GrVkGpu* gpu) { | 238 void GrVkRenderTarget::createFramebuffer(GrVkGpu* gpu) { |
220 if (fFramebuffer) { | 239 if (fFramebuffer) { |
221 fFramebuffer->unref(gpu); | 240 fFramebuffer->unref(gpu); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 400 |
382 return nullptr; | 401 return nullptr; |
383 } | 402 } |
384 | 403 |
385 | 404 |
386 GrVkGpu* GrVkRenderTarget::getVkGpu() const { | 405 GrVkGpu* GrVkRenderTarget::getVkGpu() const { |
387 SkASSERT(!this->wasDestroyed()); | 406 SkASSERT(!this->wasDestroyed()); |
388 return static_cast<GrVkGpu*>(this->getGpu()); | 407 return static_cast<GrVkGpu*>(this->getGpu()); |
389 } | 408 } |
390 | 409 |
OLD | NEW |