Index: src/gpu/vk/GrVkTextureRenderTarget.cpp |
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.cpp b/src/gpu/vk/GrVkTextureRenderTarget.cpp |
index c33a6800b837a2647c0c282273ead8b35eb3f351..b92ea661fb3de5ec490919b1224d5dcd4b7dcee1 100644 |
--- a/src/gpu/vk/GrVkTextureRenderTarget.cpp |
+++ b/src/gpu/vk/GrVkTextureRenderTarget.cpp |
@@ -18,20 +18,19 @@ |
#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) |
-template<typename ResourceType> |
GrVkTextureRenderTarget* GrVkTextureRenderTarget::Create(GrVkGpu* gpu, |
- ResourceType resourceType, |
const GrSurfaceDesc& desc, |
- VkFormat format, |
- const GrVkImage::Resource* imageResource) { |
- VkImage image = imageResource->fImage; |
+ const GrVkImageInfo& info, |
+ SkBudgeted budgeted, |
+ GrVkImage::Wrapped wrapped) { |
+ VkImage image = info.fImage; |
// Create the texture ImageView |
uint32_t mipLevels = 1; |
//TODO: does a mipmapped textureRenderTarget make sense? |
//if (desc.fIsMipMapped) { |
// mipLevels = SkMipMap::ComputeLevelCount(this->width(), this->height()) + 1; |
//} |
- const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, format, |
+ const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, info.fFormat, |
GrVkImageView::kColor_Type, mipLevels); |
if (!imageView) { |
return nullptr; |
@@ -43,7 +42,7 @@ GrVkTextureRenderTarget* GrVkTextureRenderTarget::Create(GrVkGpu* gpu, |
VkImage colorImage; |
// create msaa surface if necessary |
- const GrVkImage::Resource* msaaImageResource = nullptr; |
+ GrVkImageInfo msInfo; |
const GrVkImageView* resolveAttachmentView = nullptr; |
if (desc.fSampleCnt) { |
GrVkImage::ImageDesc msImageDesc; |
@@ -57,65 +56,74 @@ GrVkTextureRenderTarget* GrVkTextureRenderTarget::Create(GrVkGpu* gpu, |
msImageDesc.fUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
msImageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
- msaaImageResource = GrVkImage::CreateResource(gpu, msImageDesc); |
- |
- if (!msaaImageResource) { |
- imageView->unref(gpu); |
+ if (!GrVkImage::InitImageInfo(gpu, msImageDesc, &msInfo)) { |
return nullptr; |
} |
// Set color attachment image |
- colorImage = msaaImageResource->fImage; |
+ colorImage = msInfo.fImage; |
// Create resolve attachment view if necessary. |
// If the format matches, this is the same as the texture imageView. |
- if (pixelFormat == format) { |
+ if (pixelFormat == info.fFormat) { |
resolveAttachmentView = imageView; |
resolveAttachmentView->ref(); |
} else { |
resolveAttachmentView = GrVkImageView::Create(gpu, image, pixelFormat, |
GrVkImageView::kColor_Type, 1); |
if (!resolveAttachmentView) { |
- msaaImageResource->unref(gpu); |
+ GrVkImage::DestroyImageInfo(gpu, &msInfo); |
imageView->unref(gpu); |
return nullptr; |
} |
} |
} else { |
// Set color attachment image |
- colorImage = imageResource->fImage; |
+ colorImage = info.fImage; |
} |
const GrVkImageView* colorAttachmentView; |
// Get color attachment view. |
// If the format matches and there's no multisampling, |
// this is the same as the texture imageView |
- if (pixelFormat == format && !resolveAttachmentView) { |
+ if (pixelFormat == info.fFormat && !resolveAttachmentView) { |
colorAttachmentView = imageView; |
colorAttachmentView->ref(); |
} else { |
colorAttachmentView = GrVkImageView::Create(gpu, colorImage, pixelFormat, |
GrVkImageView::kColor_Type, 1); |
if (!colorAttachmentView) { |
- if (msaaImageResource) { |
+ if (desc.fSampleCnt) { |
resolveAttachmentView->unref(gpu); |
- msaaImageResource->unref(gpu); |
+ GrVkImage::DestroyImageInfo(gpu, &msInfo); |
} |
imageView->unref(gpu); |
return nullptr; |
} |
} |
GrVkTextureRenderTarget* texRT; |
- if (msaaImageResource) { |
- texRT = new GrVkTextureRenderTarget(gpu, resourceType, desc, |
- imageResource, imageView, msaaImageResource, |
- colorAttachmentView, |
- resolveAttachmentView); |
- msaaImageResource->unref(gpu); |
+ if (desc.fSampleCnt) { |
+ if (GrVkImage::kNot_Wrapped == wrapped) { |
+ texRT = new GrVkTextureRenderTarget(gpu, budgeted, desc, |
+ info, imageView, msInfo, |
+ colorAttachmentView, |
+ resolveAttachmentView); |
+ } else { |
+ texRT = new GrVkTextureRenderTarget(gpu, desc, |
+ info, imageView, msInfo, |
+ colorAttachmentView, |
+ resolveAttachmentView, wrapped); |
+ } |
} else { |
- texRT = new GrVkTextureRenderTarget(gpu, resourceType, desc, |
- imageResource, imageView, |
- colorAttachmentView); |
+ if (GrVkImage::kNot_Wrapped == wrapped) { |
+ texRT = new GrVkTextureRenderTarget(gpu, budgeted, desc, |
+ info, imageView, |
+ colorAttachmentView); |
+ } else { |
+ texRT = new GrVkTextureRenderTarget(gpu, desc, |
+ info, imageView, |
+ colorAttachmentView, wrapped); |
+ } |
} |
return texRT; |
} |
@@ -128,16 +136,15 @@ GrVkTextureRenderTarget::CreateNewTextureRenderTarget(GrVkGpu* gpu, |
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT); |
- const GrVkImage::Resource* imageRsrc = GrVkImage::CreateResource(gpu, imageDesc); |
- |
- if (!imageRsrc) { |
+ GrVkImageInfo info; |
+ if (!GrVkImage::InitImageInfo(gpu, imageDesc, &info)) { |
return nullptr; |
} |
- GrVkTextureRenderTarget* trt = Create(gpu, budgeted, desc, imageDesc.fFormat, |
- imageRsrc); |
- // Create() will increment the refCount of the image resource if it succeeds |
- imageRsrc->unref(gpu); |
+ GrVkTextureRenderTarget* trt = Create(gpu, desc, info, budgeted, GrVkImage::kNot_Wrapped); |
+ if (!trt) { |
+ GrVkImage::DestroyImageInfo(gpu, &info); |
+ } |
return trt; |
} |
@@ -146,35 +153,16 @@ GrVkTextureRenderTarget* |
GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(GrVkGpu* gpu, |
const GrSurfaceDesc& desc, |
GrWrapOwnership ownership, |
- VkFormat format, |
- const GrVkTextureInfo* info) { |
+ const GrVkImageInfo* info) { |
SkASSERT(info); |
// Wrapped textures require both image and allocation (because they can be mapped) |
SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc); |
- GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTiling) |
- ? Resource::kLinearTiling_Flag : Resource::kNo_Flags; |
+ |
+ GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImage::kBorrowed_Wrapped |
+ : GrVkImage::kAdopted_Wrapped; |
- const GrVkImage::Resource* imageResource; |
- if (kBorrow_GrWrapOwnership == ownership) { |
- imageResource = new GrVkImage::BorrowedResource(info->fImage, |
- info->fAlloc, |
- info->fFormat, |
- info->fLevelCount, |
- flags); |
- } else { |
- imageResource = new GrVkImage::Resource(info->fImage, info->fAlloc, info->fFormat, |
- info->fLevelCount, flags); |
- } |
- if (!imageResource) { |
- return nullptr; |
- } |
- GrVkTextureRenderTarget* trt = Create(gpu, kWrapped, desc, format, imageResource); |
- if (trt) { |
- trt->fCurrentLayout = info->fImageLayout; |
- } |
- // Create() will increment the refCount of the image resource if it succeeds |
- imageResource->unref(gpu); |
+ GrVkTextureRenderTarget* trt = Create(gpu, desc, *info, SkBudgeted::kNo, wrapped); |
return trt; |
} |