| 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(const 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
     ()); | 
|  | 182     if (mipLevels == 1) { | 
|  | 183         // don't need to do anything for a 1x1 texture | 
|  | 184         return false; | 
|  | 185     } | 
|  | 186 | 
|  | 187     GrVkImage::ImageDesc imageDesc; | 
|  | 188     imageDesc.fImageType = VK_IMAGE_TYPE_2D; | 
|  | 189     imageDesc.fFormat = oldResource->fFormat; | 
|  | 190     imageDesc.fWidth = fDesc.fWidth; | 
|  | 191     imageDesc.fHeight = fDesc.fHeight; | 
|  | 192     imageDesc.fLevels = mipLevels; | 
|  | 193     imageDesc.fSamples = 1; | 
|  | 194     imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL; | 
|  | 195     imageDesc.fUsageFlags = usageFlags; | 
|  | 196     imageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; | 
|  | 197 | 
|  | 198     const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im
     ageDesc); | 
|  | 199     if (!imageResource) { | 
|  | 200         return false; | 
|  | 201     } | 
|  | 202 | 
|  | 203     // have to create a new image view for new resource | 
|  | 204     const GrVkImageView* oldView = fTextureView; | 
|  | 205     VkImage image = imageResource->fImage; | 
|  | 206     const GrVkImageView* textureView = GrVkImageView::Create(gpu, image, imageRe
     source->fFormat, | 
|  | 207                                                              GrVkImageView::kCol
     or_Type, mipLevels); | 
|  | 208     if (!textureView) { | 
|  | 209         imageResource->unref(gpu); | 
|  | 210         return false; | 
|  | 211     } | 
|  | 212 | 
|  | 213     oldResource->unref(gpu); | 
|  | 214     oldView->unref(gpu); | 
|  | 215     fResource = imageResource; | 
|  | 216     fTextureView = textureView; | 
|  | 217     this->texturePriv().setMaxMipMapLevel(mipLevels); | 
|  | 218 | 
|  | 219     return true; | 
|  | 220 } | 
| OLD | NEW | 
|---|