| 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 "GrVkStencilAttachment.h" | 8 #include "GrVkStencilAttachment.h" |
| 9 #include "GrVkGpu.h" | 9 #include "GrVkGpu.h" |
| 10 #include "GrVkImage.h" | 10 #include "GrVkImage.h" |
| 11 #include "GrVkImageView.h" | 11 #include "GrVkImageView.h" |
| 12 #include "GrVkUtil.h" | 12 #include "GrVkUtil.h" |
| 13 | 13 |
| 14 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) | 14 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) |
| 15 | 15 |
| 16 GrVkStencilAttachment::GrVkStencilAttachment(GrVkGpu* gpu, | 16 GrVkStencilAttachment::GrVkStencilAttachment(GrVkGpu* gpu, |
| 17 GrGpuResource::LifeCycle lifeCycle, | |
| 18 const Format& format, | 17 const Format& format, |
| 19 const GrVkImage::ImageDesc& desc, | 18 const GrVkImage::ImageDesc& desc, |
| 20 const GrVkImage::Resource* imageRes
ource, | 19 const GrVkImage::Resource* imageRes
ource, |
| 21 const GrVkImageView* stencilView) | 20 const GrVkImageView* stencilView) |
| 22 : GrStencilAttachment(gpu, lifeCycle, desc.fWidth, desc.fHeight, | 21 : GrStencilAttachment(gpu, desc.fWidth, desc.fHeight, |
| 23 format.fStencilBits, desc.fSamples) | 22 format.fStencilBits, desc.fSamples) |
| 24 , GrVkImage(imageResource) | 23 , GrVkImage(imageResource) |
| 25 , fFormat(format) | 24 , fFormat(format) |
| 26 , fStencilView(stencilView) { | 25 , fStencilView(stencilView) { |
| 27 this->registerWithCache(); | 26 this->registerWithCache(SkBudgeted::kYes); |
| 28 stencilView->ref(); | 27 stencilView->ref(); |
| 29 } | 28 } |
| 30 | 29 |
| 31 GrVkStencilAttachment* GrVkStencilAttachment::Create(GrVkGpu* gpu, | 30 GrVkStencilAttachment* GrVkStencilAttachment::Create(GrVkGpu* gpu, |
| 32 GrGpuResource::LifeCycle li
feCycle, | |
| 33 int width, | 31 int width, |
| 34 int height, | 32 int height, |
| 35 int sampleCnt, | 33 int sampleCnt, |
| 36 const Format& format) { | 34 const Format& format) { |
| 37 GrVkImage::ImageDesc imageDesc; | 35 GrVkImage::ImageDesc imageDesc; |
| 38 imageDesc.fImageType = VK_IMAGE_TYPE_2D; | 36 imageDesc.fImageType = VK_IMAGE_TYPE_2D; |
| 39 imageDesc.fFormat = format.fInternalFormat; | 37 imageDesc.fFormat = format.fInternalFormat; |
| 40 imageDesc.fWidth = width; | 38 imageDesc.fWidth = width; |
| 41 imageDesc.fHeight = height; | 39 imageDesc.fHeight = height; |
| 42 imageDesc.fLevels = 1; | 40 imageDesc.fLevels = 1; |
| 43 imageDesc.fSamples = sampleCnt; | 41 imageDesc.fSamples = sampleCnt; |
| 44 imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL; | 42 imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL; |
| 45 imageDesc.fUsageFlags = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | | 43 imageDesc.fUsageFlags = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 46 VK_IMAGE_USAGE_TRANSFER_DST_BIT; | 44 VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 47 imageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; | 45 imageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 48 | 46 |
| 49 const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im
ageDesc); | 47 const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im
ageDesc); |
| 50 if (!imageResource) { | 48 if (!imageResource) { |
| 51 return nullptr; | 49 return nullptr; |
| 52 } | 50 } |
| 53 | 51 |
| 54 const GrVkImageView* imageView = GrVkImageView::Create(gpu, imageResource->f
Image, | 52 const GrVkImageView* imageView = GrVkImageView::Create(gpu, imageResource->f
Image, |
| 55 format.fInternalForma
t, | 53 format.fInternalForma
t, |
| 56 GrVkImageView::kStenc
il_Type); | 54 GrVkImageView::kStenc
il_Type); |
| 57 if (!imageView) { | 55 if (!imageView) { |
| 58 imageResource->unref(gpu); | 56 imageResource->unref(gpu); |
| 59 return nullptr; | 57 return nullptr; |
| 60 } | 58 } |
| 61 | 59 |
| 62 GrVkStencilAttachment* stencil = new GrVkStencilAttachment(gpu, lifeCycle, f
ormat, imageDesc, | 60 GrVkStencilAttachment* stencil = new GrVkStencilAttachment(gpu, format, imag
eDesc, |
| 63 imageResource, im
ageView); | 61 imageResource, im
ageView); |
| 64 imageResource->unref(gpu); | 62 imageResource->unref(gpu); |
| 65 imageView->unref(gpu); | 63 imageView->unref(gpu); |
| 66 | 64 |
| 67 return stencil; | 65 return stencil; |
| 68 } | 66 } |
| 69 | 67 |
| 70 GrVkStencilAttachment::~GrVkStencilAttachment() { | 68 GrVkStencilAttachment::~GrVkStencilAttachment() { |
| 71 // should have been released or abandoned first | 69 // should have been released or abandoned first |
| 72 SkASSERT(!fStencilView); | 70 SkASSERT(!fStencilView); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 94 this->abandonImage(); | 92 this->abandonImage(); |
| 95 fStencilView->unrefAndAbandon(); | 93 fStencilView->unrefAndAbandon(); |
| 96 fStencilView = nullptr; | 94 fStencilView = nullptr; |
| 97 GrStencilAttachment::onAbandon(); | 95 GrStencilAttachment::onAbandon(); |
| 98 } | 96 } |
| 99 | 97 |
| 100 GrVkGpu* GrVkStencilAttachment::getVkGpu() const { | 98 GrVkGpu* GrVkStencilAttachment::getVkGpu() const { |
| 101 SkASSERT(!this->wasDestroyed()); | 99 SkASSERT(!this->wasDestroyed()); |
| 102 return static_cast<GrVkGpu*>(this->getGpu()); | 100 return static_cast<GrVkGpu*>(this->getGpu()); |
| 103 } | 101 } |
| OLD | NEW |