Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 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 "GrVkRenderTarget.h" |
| 9 | |
| 10 | #include "GrRenderTargetPriv.h" |
| 11 | #include "GrVkCommandBuffer.h" |
| 12 | #include "GrVkFramebuffer.h" |
| 13 | #include "GrVkGpu.h" |
| 14 | #include "GrVkImageView.h" |
| 15 | #include "GrVkResourceProvider.h" |
| 16 | #include "GrVkUtil.h" |
| 17 | |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 18 | #include "vk/GrVkTypes.h" |
| 19 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 20 | #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) |
| 21 | |
| 22 | // We're virtually derived from GrSurface (via GrRenderTarget) so its |
| 23 | // constructor must be explicitly called. |
| 24 | GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 25 | SkBudgeted budgeted, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 26 | const GrSurfaceDesc& desc, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 27 | const GrVkImage::Resource* imageResource, |
| 28 | const GrVkImage::Resource* msaaResource, |
| 29 | const GrVkImageView* colorAttachmentView, |
| 30 | const GrVkImageView* resolveAttachmentView) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 31 | : GrSurface(gpu, desc) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 32 | , GrVkImage(imageResource) |
| 33 | // for the moment we only support 1:1 color to stencil |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 34 | , GrRenderTarget(gpu, desc, kUnified_SampleConfig) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 35 | , fFramebuffer(nullptr) |
| 36 | , fColorAttachmentView(colorAttachmentView) |
| 37 | , fMSAAImageResource(msaaResource) |
| 38 | , fResolveAttachmentView(resolveAttachmentView) |
| 39 | , fCachedSimpleRenderPass(nullptr) { |
| 40 | SkASSERT(desc.fSampleCnt); |
| 41 | // The plus 1 is to account for the resolve texture. |
| 42 | fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct? |
| 43 | this->createFramebuffer(gpu); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 44 | this->registerWithCache(budgeted); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 45 | msaaResource->ref(); |
| 46 | } |
| 47 | |
| 48 | // We're virtually derived from GrSurface (via GrRenderTarget) so its |
| 49 | // constructor must be explicitly called. |
| 50 | GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, |
| 51 | const GrSurfaceDesc& desc, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 52 | const GrVkImage::Resource* imageResource, |
| 53 | const GrVkImage::Resource* msaaResource, |
| 54 | const GrVkImageView* colorAttachmentView, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 55 | const GrVkImageView* resolveAttachmentView) |
| 56 | : GrSurface(gpu, desc) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 57 | , GrVkImage(imageResource) |
| 58 | // for the moment we only support 1:1 color to stencil |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 59 | , GrRenderTarget(gpu, desc, kUnified_SampleConfig) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 60 | , fFramebuffer(nullptr) |
| 61 | , fColorAttachmentView(colorAttachmentView) |
| 62 | , fMSAAImageResource(msaaResource) |
| 63 | , fResolveAttachmentView(resolveAttachmentView) |
| 64 | , fCachedSimpleRenderPass(nullptr) { |
| 65 | SkASSERT(desc.fSampleCnt); |
| 66 | // The plus 1 is to account for the resolve texture. |
| 67 | fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct? |
| 68 | this->createFramebuffer(gpu); |
| 69 | msaaResource->ref(); |
| 70 | } |
| 71 | |
| 72 | // We're virtually derived from GrSurface (via GrRenderTarget) so its |
| 73 | // constructor must be explicitly called. |
| 74 | GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 75 | SkBudgeted budgeted, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 76 | const GrSurfaceDesc& desc, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 77 | const GrVkImage::Resource* imageResource, |
| 78 | const GrVkImageView* colorAttachmentView) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 79 | : GrSurface(gpu, desc) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 80 | , GrVkImage(imageResource) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 81 | , GrRenderTarget(gpu, desc, kUnified_SampleConfig) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 82 | , fFramebuffer(nullptr) |
| 83 | , fColorAttachmentView(colorAttachmentView) |
| 84 | , fMSAAImageResource(nullptr) |
| 85 | , fResolveAttachmentView(nullptr) |
| 86 | , fCachedSimpleRenderPass(nullptr) { |
| 87 | SkASSERT(!desc.fSampleCnt); |
| 88 | fColorValuesPerPixel = 1; |
| 89 | this->createFramebuffer(gpu); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 90 | this->registerWithCache(budgeted); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | // We're virtually derived from GrSurface (via GrRenderTarget) so its |
| 94 | // constructor must be explicitly called. |
| 95 | GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, |
| 96 | const GrSurfaceDesc& desc, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 97 | const GrVkImage::Resource* imageResource, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 98 | const GrVkImageView* colorAttachmentView) |
| 99 | : GrSurface(gpu, desc) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 100 | , GrVkImage(imageResource) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 101 | , GrRenderTarget(gpu, desc, kUnified_SampleConfig) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 102 | , fFramebuffer(nullptr) |
| 103 | , fColorAttachmentView(colorAttachmentView) |
| 104 | , fMSAAImageResource(nullptr) |
| 105 | , fResolveAttachmentView(nullptr) |
| 106 | , fCachedSimpleRenderPass(nullptr) { |
| 107 | SkASSERT(!desc.fSampleCnt); |
| 108 | fColorValuesPerPixel = 1; |
| 109 | this->createFramebuffer(gpu); |
| 110 | } |
| 111 | |
| 112 | GrVkRenderTarget* |
| 113 | GrVkRenderTarget::Create(GrVkGpu* gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 114 | SkBudgeted budgeted, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 115 | const GrSurfaceDesc& desc, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 116 | const GrVkImage::Resource* imageResource) { |
| 117 | VkFormat pixelFormat; |
| 118 | GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 119 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 120 | VkImage colorImage; |
| 121 | |
| 122 | // create msaa surface if necessary |
| 123 | const GrVkImage::Resource* msaaResource = nullptr; |
| 124 | const GrVkImageView* resolveAttachmentView = nullptr; |
| 125 | if (desc.fSampleCnt) { |
| 126 | GrVkImage::ImageDesc msImageDesc; |
| 127 | msImageDesc.fImageType = VK_IMAGE_TYPE_2D; |
| 128 | msImageDesc.fFormat = pixelFormat; |
| 129 | msImageDesc.fWidth = desc.fWidth; |
| 130 | msImageDesc.fHeight = desc.fHeight; |
| 131 | msImageDesc.fLevels = 1; |
| 132 | msImageDesc.fSamples = desc.fSampleCnt; |
| 133 | msImageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL; |
| 134 | msImageDesc.fUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 135 | msImageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 136 | |
| 137 | msaaResource = GrVkImage::CreateResource(gpu, msImageDesc); |
| 138 | |
| 139 | if (!msaaResource) { |
| 140 | return nullptr; |
| 141 | } |
| 142 | |
| 143 | // Set color attachment image |
| 144 | colorImage = msaaResource->fImage; |
| 145 | |
| 146 | // Create Resolve attachment view |
| 147 | resolveAttachmentView = GrVkImageView::Create(gpu, imageResource->fImage, pixelFormat, |
| 148 | GrVkImageView::kColor_Type); |
| 149 | if (!resolveAttachmentView) { |
| 150 | msaaResource->unref(gpu); |
| 151 | return nullptr; |
| 152 | } |
| 153 | } else { |
| 154 | // Set color attachment image |
| 155 | colorImage = imageResource->fImage; |
| 156 | } |
| 157 | |
| 158 | // Get color attachment view |
| 159 | const GrVkImageView* colorAttachmentView = GrVkImageView::Create(gpu, colorImage, pixelFormat, |
| 160 | GrVkImageView::kColor_Type); |
| 161 | if (!colorAttachmentView) { |
| 162 | if (msaaResource) { |
| 163 | resolveAttachmentView->unref(gpu); |
| 164 | msaaResource->unref(gpu); |
| 165 | } |
| 166 | return NULL; |
| 167 | } |
| 168 | |
| 169 | GrVkRenderTarget* texRT; |
| 170 | if (msaaResource) { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 171 | texRT = new GrVkRenderTarget(gpu, budgeted, desc, imageResource, msaaResource, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 172 | colorAttachmentView, resolveAttachmentView); |
| 173 | msaaResource->unref(gpu); |
| 174 | } else { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 175 | texRT = new GrVkRenderTarget(gpu, budgeted, desc, imageResource, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 176 | colorAttachmentView); |
| 177 | } |
| 178 | |
| 179 | return texRT; |
| 180 | } |
| 181 | |
| 182 | GrVkRenderTarget* |
| 183 | GrVkRenderTarget::CreateNewRenderTarget(GrVkGpu* gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 184 | SkBudgeted budgeted, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 185 | const GrSurfaceDesc& desc, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 186 | const GrVkImage::ImageDesc& imageDesc) { |
| 187 | SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
| 188 | |
| 189 | const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, imageDesc); |
| 190 | if (!imageResource) { |
| 191 | return nullptr; |
| 192 | } |
| 193 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 194 | GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, budgeted, desc, imageResource); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 195 | // Create() will increment the refCount of the image resource if it succeeds |
| 196 | imageResource->unref(gpu); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 197 | return rt; |
| 198 | } |
| 199 | |
| 200 | GrVkRenderTarget* |
| 201 | GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu, |
| 202 | const GrSurfaceDesc& desc, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 203 | GrWrapOwnership ownership, |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 204 | const GrVkTextureInfo* info) { |
| 205 | SkASSERT(info); |
| 206 | // We can wrap a rendertarget without its allocation, as long as we don't take ownership |
| 207 | SkASSERT(VK_NULL_HANDLE != info->fImage); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 208 | SkASSERT(VK_NULL_HANDLE != info->fAlloc || kAdopt_GrWrapOwnership != ownership); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 209 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 210 | GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTiling) |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 211 | ? Resource::kLinearTiling_Flag : Resource::kNo_Flags; |
| 212 | |
jvanverth | fe170d2 | 2016-03-22 13:15:44 -0700 | [diff] [blame] | 213 | const GrVkImage::Resource* imageResource; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 214 | if (kBorrow_GrWrapOwnership == ownership) { |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 215 | imageResource = new GrVkImage::BorrowedResource(info->fImage, |
| 216 | info->fAlloc, |
| 217 | flags, |
| 218 | info->fFormat); |
jvanverth | fe170d2 | 2016-03-22 13:15:44 -0700 | [diff] [blame] | 219 | } else { |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 220 | imageResource = new GrVkImage::Resource(info->fImage, info->fAlloc, flags, info->fFormat); |
jvanverth | fe170d2 | 2016-03-22 13:15:44 -0700 | [diff] [blame] | 221 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 222 | if (!imageResource) { |
| 223 | return nullptr; |
| 224 | } |
| 225 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 226 | GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, SkBudgeted::kNo, desc, imageResource); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 227 | if (rt) { |
| 228 | rt->fCurrentLayout = info->fImageLayout; |
| 229 | } |
| 230 | // Create() will increment the refCount of the image resource if it succeeds |
| 231 | imageResource->unref(gpu); |
jvanverth | fe170d2 | 2016-03-22 13:15:44 -0700 | [diff] [blame] | 232 | |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 233 | return rt; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | bool GrVkRenderTarget::completeStencilAttachment() { |
| 237 | this->createFramebuffer(this->getVkGpu()); |
| 238 | return true; |
| 239 | } |
| 240 | |
| 241 | void GrVkRenderTarget::createFramebuffer(GrVkGpu* gpu) { |
| 242 | if (fFramebuffer) { |
| 243 | fFramebuffer->unref(gpu); |
| 244 | } |
| 245 | if (fCachedSimpleRenderPass) { |
| 246 | fCachedSimpleRenderPass->unref(gpu); |
| 247 | } |
| 248 | |
| 249 | // Vulkan requires us to create a compatible renderpass before we can create our framebuffer, |
| 250 | // so we use this to get a (cached) basic renderpass, only for creation. |
| 251 | fCachedSimpleRenderPass = gpu->resourceProvider().findOrCreateCompatibleRenderPass(*this); |
| 252 | |
| 253 | // Stencil attachment view is stored in the base RT stencil attachment |
| 254 | const GrVkImageView* stencilView = this->stencilAttachmentView(); |
| 255 | fFramebuffer = GrVkFramebuffer::Create(gpu, this->width(), this->height(), |
| 256 | fCachedSimpleRenderPass, fColorAttachmentView, |
| 257 | fResolveAttachmentView, stencilView); |
| 258 | SkASSERT(fFramebuffer); |
| 259 | } |
| 260 | |
| 261 | void GrVkRenderTarget::getAttachmentsDescriptor( |
| 262 | GrVkRenderPass::AttachmentsDescriptor* desc, |
| 263 | GrVkRenderPass::AttachmentFlags* attachmentFlags) const { |
| 264 | int colorSamples = this->numColorSamples(); |
| 265 | VkFormat colorFormat; |
| 266 | GrPixelConfigToVkFormat(this->config(), &colorFormat); |
| 267 | desc->fColor.fFormat = colorFormat; |
| 268 | desc->fColor.fSamples = colorSamples ? colorSamples : 1; |
| 269 | *attachmentFlags = GrVkRenderPass::kColor_AttachmentFlag; |
| 270 | uint32_t attachmentCount = 1; |
| 271 | if (colorSamples > 0) { |
| 272 | desc->fResolve.fFormat = colorFormat; |
| 273 | desc->fResolve.fSamples = 1; |
| 274 | *attachmentFlags |= GrVkRenderPass::kResolve_AttachmentFlag; |
| 275 | ++attachmentCount; |
| 276 | } |
| 277 | |
| 278 | const GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment(); |
| 279 | if (stencil) { |
| 280 | const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAttachment*>(stencil); |
| 281 | desc->fStencil.fFormat = vkStencil->vkFormat(); |
| 282 | desc->fStencil.fSamples = vkStencil->numSamples() ? vkStencil->numSamples() : 1; |
| 283 | // Currently in vulkan stencil and color attachments must all have same number of samples |
| 284 | SkASSERT(desc->fColor.fSamples == desc->fStencil.fSamples); |
| 285 | *attachmentFlags |= GrVkRenderPass::kStencil_AttachmentFlag; |
| 286 | ++attachmentCount; |
| 287 | } |
| 288 | desc->fAttachmentCount = attachmentCount; |
| 289 | } |
| 290 | |
| 291 | GrVkRenderTarget::~GrVkRenderTarget() { |
| 292 | // either release or abandon should have been called by the owner of this object. |
| 293 | SkASSERT(!fMSAAImageResource); |
| 294 | SkASSERT(!fResolveAttachmentView); |
| 295 | SkASSERT(!fColorAttachmentView); |
| 296 | SkASSERT(!fFramebuffer); |
| 297 | SkASSERT(!fCachedSimpleRenderPass); |
| 298 | } |
| 299 | |
| 300 | void GrVkRenderTarget::addResources(GrVkCommandBuffer& commandBuffer) const { |
| 301 | commandBuffer.addResource(this->framebuffer()); |
| 302 | commandBuffer.addResource(this->resource()); |
| 303 | commandBuffer.addResource(this->colorAttachmentView()); |
| 304 | if (this->msaaImageResource()) { |
| 305 | commandBuffer.addResource(this->msaaImageResource()); |
| 306 | commandBuffer.addResource(this->resolveAttachmentView()); |
| 307 | } |
| 308 | if (this->stencilImageResource()) { |
| 309 | commandBuffer.addResource(this->stencilImageResource()); |
| 310 | commandBuffer.addResource(this->stencilAttachmentView()); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | void GrVkRenderTarget::releaseInternalObjects() { |
| 315 | GrVkGpu* gpu = this->getVkGpu(); |
| 316 | |
| 317 | if (fMSAAImageResource) { |
| 318 | fMSAAImageResource->unref(gpu); |
| 319 | fMSAAImageResource = nullptr; |
| 320 | } |
| 321 | |
| 322 | if (fResolveAttachmentView) { |
| 323 | fResolveAttachmentView->unref(gpu); |
| 324 | fResolveAttachmentView = nullptr; |
| 325 | } |
| 326 | if (fColorAttachmentView) { |
| 327 | fColorAttachmentView->unref(gpu); |
| 328 | fColorAttachmentView = nullptr; |
| 329 | } |
| 330 | if (fFramebuffer) { |
| 331 | fFramebuffer->unref(gpu); |
| 332 | fFramebuffer = nullptr; |
| 333 | } |
| 334 | if (fCachedSimpleRenderPass) { |
| 335 | fCachedSimpleRenderPass->unref(gpu); |
| 336 | fCachedSimpleRenderPass = nullptr; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | void GrVkRenderTarget::abandonInternalObjects() { |
| 341 | if (fMSAAImageResource) { |
| 342 | fMSAAImageResource->unrefAndAbandon(); |
| 343 | fMSAAImageResource = nullptr; |
| 344 | } |
| 345 | |
| 346 | if (fResolveAttachmentView) { |
| 347 | fResolveAttachmentView->unrefAndAbandon(); |
| 348 | fResolveAttachmentView = nullptr; |
| 349 | } |
| 350 | if (fColorAttachmentView) { |
| 351 | fColorAttachmentView->unrefAndAbandon(); |
| 352 | fColorAttachmentView = nullptr; |
| 353 | } |
| 354 | if (fFramebuffer) { |
| 355 | fFramebuffer->unrefAndAbandon(); |
| 356 | fFramebuffer = nullptr; |
| 357 | } |
| 358 | if (fCachedSimpleRenderPass) { |
| 359 | fCachedSimpleRenderPass->unrefAndAbandon(); |
| 360 | fCachedSimpleRenderPass = nullptr; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | void GrVkRenderTarget::onRelease() { |
| 365 | this->releaseInternalObjects(); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 366 | this->releaseImage(this->getVkGpu()); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 367 | GrRenderTarget::onRelease(); |
| 368 | } |
| 369 | |
| 370 | void GrVkRenderTarget::onAbandon() { |
| 371 | this->abandonInternalObjects(); |
| 372 | this->abandonImage(); |
| 373 | GrRenderTarget::onAbandon(); |
| 374 | } |
| 375 | |
| 376 | |
| 377 | GrBackendObject GrVkRenderTarget::getRenderTargetHandle() const { |
| 378 | // Currently just passing back the pointer to the main Image::Resource as the handle |
| 379 | return (GrBackendObject)&fResource; |
| 380 | } |
| 381 | |
| 382 | const GrVkImage::Resource* GrVkRenderTarget::stencilImageResource() const { |
| 383 | const GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment(); |
| 384 | if (stencil) { |
| 385 | const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAttachment*>(stencil); |
| 386 | return vkStencil->imageResource(); |
| 387 | } |
| 388 | |
| 389 | return nullptr; |
| 390 | } |
| 391 | |
| 392 | const GrVkImageView* GrVkRenderTarget::stencilAttachmentView() const { |
| 393 | const GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment(); |
| 394 | if (stencil) { |
| 395 | const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAttachment*>(stencil); |
| 396 | return vkStencil->stencilView(); |
| 397 | } |
| 398 | |
| 399 | return nullptr; |
| 400 | } |
| 401 | |
| 402 | |
| 403 | GrVkGpu* GrVkRenderTarget::getVkGpu() const { |
| 404 | SkASSERT(!this->wasDestroyed()); |
| 405 | return static_cast<GrVkGpu*>(this->getGpu()); |
| 406 | } |