Chromium Code Reviews| 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" |
| 11 #include "GrTexturePriv.h" | |
| 11 #include "GrVkUtil.h" | 12 #include "GrVkUtil.h" |
| 13 #include "SkMipmap.h" | |
| 12 | 14 |
| 13 #include "vk/GrVkTypes.h" | 15 #include "vk/GrVkTypes.h" |
| 14 | 16 |
| 15 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) | 17 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) |
| 16 | 18 |
| 17 // Because this class is virtually derived from GrSurface we must explicitly cal l its constructor. | 19 // Because this class is virtually derived from GrSurface we must explicitly cal l its constructor. |
| 18 GrVkTexture::GrVkTexture(GrVkGpu* gpu, | 20 GrVkTexture::GrVkTexture(GrVkGpu* gpu, |
| 19 SkBudgeted budgeted, | 21 SkBudgeted budgeted, |
| 20 const GrSurfaceDesc& desc, | 22 const GrSurfaceDesc& desc, |
| 21 const GrVkImage::Resource* imageResource, | 23 const GrVkImage::Resource* imageResource, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 , fTextureView(view) {} | 55 , fTextureView(view) {} |
| 54 | 56 |
| 55 | 57 |
| 56 template<typename ResourceType> | 58 template<typename ResourceType> |
| 57 GrVkTexture* GrVkTexture::Create(GrVkGpu* gpu, | 59 GrVkTexture* GrVkTexture::Create(GrVkGpu* gpu, |
| 58 ResourceType type, | 60 ResourceType type, |
| 59 const GrSurfaceDesc& desc, | 61 const GrSurfaceDesc& desc, |
| 60 VkFormat format, | 62 VkFormat format, |
| 61 const GrVkImage::Resource* imageResource) { | 63 const GrVkImage::Resource* imageResource) { |
| 62 VkImage image = imageResource->fImage; | 64 VkImage image = imageResource->fImage; |
| 65 | |
| 66 uint32_t mipLevels = 1; | |
| 67 // TODO: enable when mipLevel loading is implemented in GrVkGpu | |
| 68 //if (desc.fIsMipMapped) { | |
| 69 // mipLevels = SkMipMap::ComputeLevelCount(this->width(), this->height()) ; | |
| 70 //} | |
| 63 const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, format, | 71 const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, format, |
| 64 GrVkImageView::kColor _Type); | 72 GrVkImageView::kColor _Type, mipLevels); |
| 65 if (!imageView) { | 73 if (!imageView) { |
| 66 return nullptr; | 74 return nullptr; |
| 67 } | 75 } |
| 68 | 76 |
| 69 return new GrVkTexture(gpu, type, desc, imageResource, imageView); | 77 return new GrVkTexture(gpu, type, desc, imageResource, imageView); |
| 70 } | 78 } |
| 71 | 79 |
| 72 GrVkTexture* GrVkTexture::CreateNewTexture(GrVkGpu* gpu, SkBudgeted budgeted, | 80 GrVkTexture* GrVkTexture::CreateNewTexture(GrVkGpu* gpu, SkBudgeted budgeted, |
| 73 const GrSurfaceDesc& desc, | 81 const GrSurfaceDesc& desc, |
| 74 const GrVkImage::ImageDesc& imageDesc ) { | 82 const GrVkImage::ImageDesc& imageDesc ) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 | 158 |
| 151 GrBackendObject GrVkTexture::getTextureHandle() const { | 159 GrBackendObject GrVkTexture::getTextureHandle() const { |
| 152 // Currently just passing back the pointer to the Resource as the handle | 160 // Currently just passing back the pointer to the Resource as the handle |
| 153 return (GrBackendObject)&fResource; | 161 return (GrBackendObject)&fResource; |
| 154 } | 162 } |
| 155 | 163 |
| 156 GrVkGpu* GrVkTexture::getVkGpu() const { | 164 GrVkGpu* GrVkTexture::getVkGpu() const { |
| 157 SkASSERT(!this->wasDestroyed()); | 165 SkASSERT(!this->wasDestroyed()); |
| 158 return static_cast<GrVkGpu*>(this->getGpu()); | 166 return static_cast<GrVkGpu*>(this->getGpu()); |
| 159 } | 167 } |
| 168 | |
| 169 bool GrVkTexture::reallocForMipmap(GrVkGpu* gpu) { | |
| 170 const GrVkImage::Resource* oldResource = fResource; | |
| 171 | |
| 172 // Does this even make sense for rendertargets? | |
| 173 bool renderTarget = SkToBool(fDesc.fFlags & kRenderTarget_GrSurfaceFlag); | |
| 174 | |
| 175 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; | |
| 176 if (renderTarget) { | |
| 177 usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; | |
| 178 } | |
| 179 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_ BIT; | |
| 180 | |
| 181 uint32_t mipLevels = SkMipMap::ComputeLevelCount(this->width(), this->height ()); | |
|
egdaniel
2016/04/25 21:01:09
if mipLevels == 1 should we just return here? I gu
jvanverth1
2016/04/26 14:18:26
Done.
| |
| 182 | |
| 183 GrVkImage::ImageDesc imageDesc; | |
| 184 imageDesc.fImageType = VK_IMAGE_TYPE_2D; | |
| 185 imageDesc.fFormat = oldResource->fFormat; | |
| 186 imageDesc.fWidth = fDesc.fWidth; | |
| 187 imageDesc.fHeight = fDesc.fHeight; | |
| 188 imageDesc.fLevels = mipLevels; | |
| 189 imageDesc.fSamples = 1; | |
| 190 imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL; | |
| 191 imageDesc.fUsageFlags = usageFlags; | |
| 192 imageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; | |
| 193 | |
| 194 const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im ageDesc); | |
| 195 if (!imageResource) { | |
| 196 return false; | |
| 197 } | |
| 198 | |
| 199 // have to create a new image view for new resource | |
| 200 const GrVkImageView* oldView = fTextureView; | |
| 201 VkImage image = imageResource->fImage; | |
| 202 const GrVkImageView* textureView = GrVkImageView::Create(gpu, image, imageRe source->fFormat, | |
| 203 GrVkImageView::kCol or_Type, mipLevels); | |
| 204 if (!textureView) { | |
| 205 imageResource->unref(gpu); | |
| 206 return false; | |
| 207 } | |
| 208 | |
| 209 oldResource->unref(gpu); | |
| 210 oldView->unref(gpu); | |
| 211 fResource = imageResource; | |
| 212 fTextureView = textureView; | |
| 213 | |
| 214 return true; | |
| 215 } | |
| OLD | NEW |