| 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 "GrVkTexture.h" | 8 #include "GrVkTexture.h" |
| 9 #include "GrVkGpu.h" | 9 #include "GrVkGpu.h" |
| 10 #include "GrVkImageView.h" | 10 #include "GrVkImageView.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 : GrSurface(gpu, desc) | 48 : GrSurface(gpu, desc) |
| 49 , GrVkImage(imageResource) | 49 , GrVkImage(imageResource) |
| 50 , INHERITED(gpu, desc, kSampler2D_GrSLType, desc.fIsMipMapped) | 50 , INHERITED(gpu, desc, kSampler2D_GrSLType, desc.fIsMipMapped) |
| 51 , fTextureView(view) {} | 51 , fTextureView(view) {} |
| 52 | 52 |
| 53 | 53 |
| 54 template<typename ResourceType> | 54 template<typename ResourceType> |
| 55 GrVkTexture* GrVkTexture::Create(GrVkGpu* gpu, | 55 GrVkTexture* GrVkTexture::Create(GrVkGpu* gpu, |
| 56 ResourceType type, | 56 ResourceType type, |
| 57 const GrSurfaceDesc& desc, | 57 const GrSurfaceDesc& desc, |
| 58 VkFormat format, uint32_t levels, | 58 VkFormat format, |
| 59 const GrVkImage::Resource* imageResource) { | 59 const GrVkImage::Resource* imageResource) { |
| 60 VkImage image = imageResource->fImage; | 60 VkImage image = imageResource->fImage; |
| 61 | 61 |
| 62 const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, format, | 62 const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, format, |
| 63 GrVkImageView::kColor
_Type, | 63 GrVkImageView::kColor
_Type, |
| 64 levels); | 64 imageResource->fLevel
Count); |
| 65 if (!imageView) { | 65 if (!imageView) { |
| 66 return nullptr; | 66 return nullptr; |
| 67 } | 67 } |
| 68 | 68 |
| 69 return new GrVkTexture(gpu, type, desc, imageResource, imageView); | 69 return new GrVkTexture(gpu, type, desc, imageResource, imageView); |
| 70 } | 70 } |
| 71 | 71 |
| 72 GrVkTexture* GrVkTexture::CreateNewTexture(GrVkGpu* gpu, SkBudgeted budgeted, | 72 GrVkTexture* GrVkTexture::CreateNewTexture(GrVkGpu* gpu, SkBudgeted budgeted, |
| 73 const GrSurfaceDesc& desc, | 73 const GrSurfaceDesc& desc, |
| 74 const GrVkImage::ImageDesc& imageDesc
) { | 74 const GrVkImage::ImageDesc& imageDesc
) { |
| 75 SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT); | 75 SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT); |
| 76 | 76 |
| 77 const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im
ageDesc); | 77 const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im
ageDesc); |
| 78 if (!imageResource) { | 78 if (!imageResource) { |
| 79 return nullptr; | 79 return nullptr; |
| 80 } | 80 } |
| 81 | 81 |
| 82 GrVkTexture* texture = Create(gpu, budgeted, desc, imageDesc.fFormat, imageD
esc.fLevels, | 82 GrVkTexture* texture = Create(gpu, budgeted, desc, imageDesc.fFormat, imageR
esource); |
| 83 imageResource); | |
| 84 // Create() will increment the refCount of the image resource if it succeeds | 83 // Create() will increment the refCount of the image resource if it succeeds |
| 85 imageResource->unref(gpu); | 84 imageResource->unref(gpu); |
| 86 | 85 |
| 87 return texture; | 86 return texture; |
| 88 } | 87 } |
| 89 | 88 |
| 90 GrVkTexture* GrVkTexture::CreateWrappedTexture(GrVkGpu* gpu, | 89 GrVkTexture* GrVkTexture::CreateWrappedTexture(GrVkGpu* gpu, |
| 91 const GrSurfaceDesc& desc, | 90 const GrSurfaceDesc& desc, |
| 92 GrWrapOwnership ownership, | 91 GrWrapOwnership ownership, |
| 93 VkFormat format, | 92 VkFormat format, |
| 94 const GrVkTextureInfo* info) { | 93 const GrVkTextureInfo* info) { |
| 95 SkASSERT(info); | 94 SkASSERT(info); |
| 96 // Wrapped textures require both image and allocation (because they can be m
apped) | 95 // Wrapped textures require both image and allocation (because they can be m
apped) |
| 97 SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc); | 96 SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc); |
| 98 | 97 |
| 99 GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTi
ling) | 98 GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTi
ling) |
| 100 ? Resource::kLinearTiling_Flag : Resource::
kNo_Flags; | 99 ? Resource::kLinearTiling_Flag : Resource::
kNo_Flags; |
| 101 | 100 |
| 102 const GrVkImage::Resource* imageResource; | 101 const GrVkImage::Resource* imageResource; |
| 103 if (kBorrow_GrWrapOwnership == ownership) { | 102 if (kBorrow_GrWrapOwnership == ownership) { |
| 104 imageResource = new GrVkImage::BorrowedResource(info->fImage, | 103 imageResource = new GrVkImage::BorrowedResource(info->fImage, |
| 105 info->fAlloc, | 104 info->fAlloc, |
| 106 flags, | 105 info->fFormat, |
| 107 info->fFormat); | 106 info->fLevelCount, |
| 107 flags); |
| 108 } else { | 108 } else { |
| 109 imageResource = new GrVkImage::Resource(info->fImage, info->fAlloc, flag
s, info->fFormat); | 109 imageResource = new GrVkImage::Resource(info->fImage, info->fAlloc, info
->fFormat, |
| 110 info->fLevelCount, flags); |
| 110 } | 111 } |
| 111 if (!imageResource) { | 112 if (!imageResource) { |
| 112 return nullptr; | 113 return nullptr; |
| 113 } | 114 } |
| 114 | 115 |
| 115 // We have no other information so we have to assume that wrapped textures h
ave only one level | 116 GrVkTexture* texture = Create(gpu, kWrapped, desc, format, imageResource); |
| 116 GrVkTexture* texture = Create(gpu, kWrapped, desc, format, 1, imageResource)
; | |
| 117 if (texture) { | 117 if (texture) { |
| 118 texture->fCurrentLayout = info->fImageLayout; | 118 texture->fCurrentLayout = info->fImageLayout; |
| 119 } | 119 } |
| 120 // Create() will increment the refCount of the image resource if it succeeds | 120 // Create() will increment the refCount of the image resource if it succeeds |
| 121 imageResource->unref(gpu); | 121 imageResource->unref(gpu); |
| 122 | 122 |
| 123 return texture; | 123 return texture; |
| 124 } | 124 } |
| 125 | 125 |
| 126 GrVkTexture::~GrVkTexture() { | 126 GrVkTexture::~GrVkTexture() { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 209 } |
| 210 | 210 |
| 211 oldResource->unref(gpu); | 211 oldResource->unref(gpu); |
| 212 oldView->unref(gpu); | 212 oldView->unref(gpu); |
| 213 fResource = imageResource; | 213 fResource = imageResource; |
| 214 fTextureView = textureView; | 214 fTextureView = textureView; |
| 215 this->texturePriv().setMaxMipMapLevel(mipLevels); | 215 this->texturePriv().setMaxMipMapLevel(mipLevels); |
| 216 | 216 |
| 217 return true; | 217 return true; |
| 218 } | 218 } |
| OLD | NEW |