Index: src/gpu/GrTextureProvider.cpp |
diff --git a/src/gpu/GrTextureProvider.cpp b/src/gpu/GrTextureProvider.cpp |
index 2d422f717f5e777ff8af2c2dc486465b963a47e9..f1775aba78f38c869611184cbca3fae00c4842c0 100644 |
--- a/src/gpu/GrTextureProvider.cpp |
+++ b/src/gpu/GrTextureProvider.cpp |
@@ -37,6 +37,15 @@ GrTexture* GrTextureProvider::createMipMappedTexture(const GrSurfaceDesc& desc, |
if (this->isAbandoned()) { |
return nullptr; |
} |
+ if (mipLevelCount && !texels) { |
+ return nullptr; |
+ } |
+ for (int i = 0; i < mipLevelCount; ++i) { |
+ if (!texels[i].fPixels) { |
+ return nullptr; |
+ } |
+ } |
+ |
if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && |
!fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
return nullptr; |
@@ -48,8 +57,8 @@ GrTexture* GrTextureProvider::createMipMappedTexture(const GrSurfaceDesc& desc, |
static const uint32_t kFlags = kExact_ScratchTextureFlag | |
kNoCreate_ScratchTextureFlag; |
if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { |
- if (texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
- baseMipLevel.fPixels, baseMipLevel.fRowBytes)) { |
+ if (!texels || texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
+ baseMipLevel.fPixels, baseMipLevel.fRowBytes)) { |
if (SkBudgeted::kNo == budgeted) { |
texture->resourcePriv().makeUnbudgeted(); |
} |
@@ -69,12 +78,16 @@ GrTexture* GrTextureProvider::createMipMappedTexture(const GrSurfaceDesc& desc, |
GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
const void* srcData, size_t rowBytes) { |
- const int mipLevelCount = 1; |
- GrMipLevel texels[mipLevelCount]; |
- texels[0].fPixels = srcData; |
- texels[0].fRowBytes = rowBytes; |
- |
- return this->createMipMappedTexture(desc, budgeted, texels, mipLevelCount); |
+ GrMipLevel tempTexels; |
+ GrMipLevel* texels = nullptr; |
+ int levelCount = 0; |
+ if (srcData) { |
+ tempTexels.fPixels = srcData; |
+ tempTexels.fRowBytes = rowBytes; |
+ texels = &tempTexels; |
+ levelCount = 1; |
+ } |
+ return this->createMipMappedTexture(desc, budgeted, texels, levelCount); |
} |
GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { |
@@ -137,7 +150,7 @@ GrTexture* GrTextureProvider::refScratchTexture(const GrSurfaceDesc& inDesc, |
} |
if (!(kNoCreate_ScratchTextureFlag & flags)) { |
- return fGpu->createTexture(*desc, SkBudgeted::kYes, nullptr, 0); |
+ return fGpu->createTexture(*desc, SkBudgeted::kYes); |
} |
return nullptr; |