Index: src/gpu/vk/GrVkTexture.cpp |
diff --git a/src/gpu/vk/GrVkTexture.cpp b/src/gpu/vk/GrVkTexture.cpp |
index 8278d2743748a80028aa171bf6ededb7efe47421..c2a30a27f4184bb00317c963bcb776a51a85bd7c 100644 |
--- a/src/gpu/vk/GrVkTexture.cpp |
+++ b/src/gpu/vk/GrVkTexture.cpp |
@@ -24,7 +24,8 @@ GrVkTexture::GrVkTexture(GrVkGpu* gpu, |
: GrSurface(gpu, desc) |
, GrVkImage(imageResource) |
, INHERITED(gpu, desc, kSampler2D_GrSLType, desc.fIsMipMapped) |
- , fTextureView(view) { |
+ , fTextureView(view) |
+ , fLinearTextureView(nullptr) { |
this->registerWithCache(budgeted); |
} |
@@ -36,7 +37,8 @@ GrVkTexture::GrVkTexture(GrVkGpu* gpu, |
: GrSurface(gpu, desc) |
, GrVkImage(imageResource) |
, INHERITED(gpu, desc, kSampler2D_GrSLType, desc.fIsMipMapped) |
- , fTextureView(view) { |
+ , fTextureView(view) |
+ , fLinearTextureView(nullptr) { |
this->registerWithCacheWrapped(); |
} |
@@ -48,7 +50,8 @@ GrVkTexture::GrVkTexture(GrVkGpu* gpu, |
: GrSurface(gpu, desc) |
, GrVkImage(imageResource) |
, INHERITED(gpu, desc, kSampler2D_GrSLType, desc.fIsMipMapped) |
- , fTextureView(view) {} |
+ , fTextureView(view) |
+ , fLinearTextureView(nullptr) {} |
template<typename ResourceType> |
@@ -126,6 +129,7 @@ GrVkTexture* GrVkTexture::CreateWrappedTexture(GrVkGpu* gpu, |
GrVkTexture::~GrVkTexture() { |
// either release or abandon should have been called by the owner of this object. |
SkASSERT(!fTextureView); |
+ SkASSERT(!fLinearTextureView); |
} |
void GrVkTexture::onRelease() { |
@@ -135,6 +139,11 @@ void GrVkTexture::onRelease() { |
fTextureView = nullptr; |
} |
+ if (fLinearTextureView) { |
+ fLinearTextureView->unref(this->getVkGpu()); |
+ fLinearTextureView = nullptr; |
+ } |
+ |
this->releaseImage(this->getVkGpu()); |
INHERITED::onRelease(); |
@@ -146,6 +155,11 @@ void GrVkTexture::onAbandon() { |
fTextureView = nullptr; |
} |
+ if (fLinearTextureView) { |
+ fLinearTextureView->unrefAndAbandon(); |
+ fLinearTextureView = nullptr; |
+ } |
+ |
this->abandonImage(); |
INHERITED::onAbandon(); |
} |
@@ -160,6 +174,22 @@ GrVkGpu* GrVkTexture::getVkGpu() const { |
return static_cast<GrVkGpu*>(this->getGpu()); |
} |
+const GrVkImageView* GrVkTexture::textureView(bool allowSRGB) { |
+ VkFormat linearFormat; |
+ if (allowSRGB || !GrVkFormatIsSRGB(fResource->fFormat, &linearFormat)) { |
+ return fTextureView; |
+ } |
+ |
+ if (!fLinearTextureView) { |
+ fLinearTextureView = GrVkImageView::Create(this->getVkGpu(), fResource->fImage, |
+ linearFormat, GrVkImageView::kColor_Type, |
+ fResource->fLevelCount); |
+ SkASSERT(fLinearTextureView); |
+ } |
+ |
+ return fLinearTextureView; |
+} |
+ |
bool GrVkTexture::reallocForMipmap(const GrVkGpu* gpu, uint32_t mipLevels) { |
if (mipLevels == 1) { |
// don't need to do anything for a 1x1 texture |
@@ -210,6 +240,10 @@ bool GrVkTexture::reallocForMipmap(const GrVkGpu* gpu, uint32_t mipLevels) { |
oldResource->unref(gpu); |
oldView->unref(gpu); |
+ if (fLinearTextureView) { |
+ fLinearTextureView->unref(gpu); |
+ fLinearTextureView = nullptr; |
+ } |
fResource = imageResource; |
fTextureView = textureView; |
fCurrentLayout = VK_IMAGE_LAYOUT_UNDEFINED; |