| 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 "GrTexturePriv.h" |
| 12 #include "GrVkTextureRenderTarget.h" |
| 12 #include "GrVkUtil.h" | 13 #include "GrVkUtil.h" |
| 13 | 14 |
| 14 #include "vk/GrVkTypes.h" | 15 #include "vk/GrVkTypes.h" |
| 15 | 16 |
| 16 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) | 17 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) |
| 17 | 18 |
| 18 // 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. |
| 19 GrVkTexture::GrVkTexture(GrVkGpu* gpu, | 20 GrVkTexture::GrVkTexture(GrVkGpu* gpu, |
| 20 SkBudgeted budgeted, | 21 SkBudgeted budgeted, |
| 21 const GrSurfaceDesc& desc, | 22 const GrSurfaceDesc& desc, |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 if (!fLinearTextureView) { | 155 if (!fLinearTextureView) { |
| 155 fLinearTextureView = GrVkImageView::Create(this->getVkGpu(), fInfo.fImag
e, | 156 fLinearTextureView = GrVkImageView::Create(this->getVkGpu(), fInfo.fImag
e, |
| 156 linearFormat, GrVkImageView::
kColor_Type, | 157 linearFormat, GrVkImageView::
kColor_Type, |
| 157 fInfo.fLevelCount); | 158 fInfo.fLevelCount); |
| 158 SkASSERT(fLinearTextureView); | 159 SkASSERT(fLinearTextureView); |
| 159 } | 160 } |
| 160 | 161 |
| 161 return fLinearTextureView; | 162 return fLinearTextureView; |
| 162 } | 163 } |
| 163 | 164 |
| 164 bool GrVkTexture::reallocForMipmap(const GrVkGpu* gpu, uint32_t mipLevels) { | 165 bool GrVkTexture::reallocForMipmap(GrVkGpu* gpu, uint32_t mipLevels) { |
| 165 if (mipLevels == 1) { | 166 if (mipLevels == 1) { |
| 166 // don't need to do anything for a 1x1 texture | 167 // don't need to do anything for a 1x1 texture |
| 167 return false; | 168 return false; |
| 168 } | 169 } |
| 169 | 170 |
| 170 const GrVkResource* oldResource = this->resource(); | 171 const GrVkResource* oldResource = this->resource(); |
| 171 | 172 |
| 172 // We shouldn't realloc something that doesn't belong to us | 173 // We shouldn't realloc something that doesn't belong to us |
| 173 if (fIsBorrowed) { | 174 if (fIsBorrowed) { |
| 174 return false; | 175 return false; |
| 175 } | 176 } |
| 176 | 177 |
| 177 // Does this even make sense for rendertargets? | |
| 178 bool renderTarget = SkToBool(fDesc.fFlags & kRenderTarget_GrSurfaceFlag); | 178 bool renderTarget = SkToBool(fDesc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 179 | 179 |
| 180 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; | 180 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 181 if (renderTarget) { | 181 if (renderTarget) { |
| 182 usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; | 182 usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 183 } | 183 } |
| 184 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_
BIT; | 184 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_
BIT; |
| 185 | 185 |
| 186 GrVkImage::ImageDesc imageDesc; | 186 GrVkImage::ImageDesc imageDesc; |
| 187 imageDesc.fImageType = VK_IMAGE_TYPE_2D; | 187 imageDesc.fImageType = VK_IMAGE_TYPE_2D; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 202 // have to create a new image view for new resource | 202 // have to create a new image view for new resource |
| 203 const GrVkImageView* oldView = fTextureView; | 203 const GrVkImageView* oldView = fTextureView; |
| 204 VkImage image = info.fImage; | 204 VkImage image = info.fImage; |
| 205 const GrVkImageView* textureView = GrVkImageView::Create(gpu, image, info.fF
ormat, | 205 const GrVkImageView* textureView = GrVkImageView::Create(gpu, image, info.fF
ormat, |
| 206 GrVkImageView::kCol
or_Type, mipLevels); | 206 GrVkImageView::kCol
or_Type, mipLevels); |
| 207 if (!textureView) { | 207 if (!textureView) { |
| 208 GrVkImage::DestroyImageInfo(gpu, &info); | 208 GrVkImage::DestroyImageInfo(gpu, &info); |
| 209 return false; | 209 return false; |
| 210 } | 210 } |
| 211 | 211 |
| 212 if (renderTarget) { |
| 213 GrVkTextureRenderTarget* texRT = static_cast<GrVkTextureRenderTarget*>(t
his); |
| 214 if (!texRT->updateForMipmap(gpu, info)) { |
| 215 GrVkImage::DestroyImageInfo(gpu, &info); |
| 216 return false; |
| 217 } |
| 218 } |
| 219 |
| 212 oldResource->unref(gpu); | 220 oldResource->unref(gpu); |
| 213 oldView->unref(gpu); | 221 oldView->unref(gpu); |
| 214 if (fLinearTextureView) { | 222 if (fLinearTextureView) { |
| 215 fLinearTextureView->unref(gpu); | 223 fLinearTextureView->unref(gpu); |
| 216 fLinearTextureView = nullptr; | 224 fLinearTextureView = nullptr; |
| 217 } | 225 } |
| 218 | 226 |
| 219 this->setNewResource(info.fImage, info.fAlloc, info.fImageTiling); | 227 this->setNewResource(info.fImage, info.fAlloc, info.fImageTiling); |
| 220 fTextureView = textureView; | 228 fTextureView = textureView; |
| 221 fInfo = info; | 229 fInfo = info; |
| 222 this->texturePriv().setMaxMipMapLevel(mipLevels); | 230 this->texturePriv().setMaxMipMapLevel(mipLevels); |
| 223 | 231 |
| 224 return true; | 232 return true; |
| 225 } | 233 } |
| OLD | NEW |