aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrResourceProvider.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/GrResourceProvider.cpp')
-rw-r--r--src/gpu/GrResourceProvider.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index 226a034bea..9cf4e6c3e7 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -46,6 +46,28 @@ GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSin
fQuadIndexBufferKey = gQuadIndexBufferKey;
}
+bool validate_desc(const GrSurfaceDesc& desc, const GrCaps& caps, int levelCount = 0) {
+ if (desc.fWidth <= 0 || desc.fHeight <= 0) {
+ return false;
+ }
+ if (!caps.isConfigTexturable(desc.fConfig)) {
+ return false;
+ }
+ if (desc.fFlags & kRenderTarget_GrSurfaceFlag) {
+ if (!caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+ return false;
+ }
+ } else {
+ if (desc.fSampleCnt) {
+ return false;
+ }
+ }
+ if (levelCount > 1 && (GrPixelConfigIsSint(desc.fConfig) || !caps.mipMapSupport())) {
+ return false;
+ }
+ return true;
+}
+
sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
const GrMipLevel texels[], int mipLevelCount,
SkDestinationSurfaceColorMode mipColorMode) {
@@ -57,8 +79,7 @@ sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, Sk
return nullptr;
}
- GrMipMapped mipMapped = mipLevelCount > 1 ? GrMipMapped::kYes : GrMipMapped::kNo;
- if (!fCaps->validateSurfaceDesc(desc, mipMapped)) {
+ if (!validate_desc(desc, *fCaps, mipLevelCount)) {
return nullptr;
}
@@ -103,7 +124,7 @@ sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc,
return nullptr;
}
- if (!fCaps->validateSurfaceDesc(desc, GrMipMapped::kNo)) {
+ if (!validate_desc(desc, *fCaps)) {
return nullptr;
}
@@ -135,11 +156,12 @@ sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc,
sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
uint32_t flags) {
ASSERT_SINGLE_OWNER
+
if (this->isAbandoned()) {
return nullptr;
}
- if (!fCaps->validateSurfaceDesc(desc, GrMipMapped::kNo)) {
+ if (!validate_desc(desc, *fCaps)) {
return nullptr;
}
@@ -160,7 +182,7 @@ sk_sp<GrTexture> GrResourceProvider::createApproxTexture(const GrSurfaceDesc& de
return nullptr;
}
- if (!fCaps->validateSurfaceDesc(desc, GrMipMapped::kNo)) {
+ if (!validate_desc(desc, *fCaps)) {
return nullptr;
}
@@ -189,7 +211,7 @@ sk_sp<GrTexture> GrResourceProvider::refScratchTexture(const GrSurfaceDesc& desc
uint32_t flags) {
ASSERT_SINGLE_OWNER
SkASSERT(!this->isAbandoned());
- SkASSERT(fCaps->validateSurfaceDesc(desc, GrMipMapped::kNo));
+ SkASSERT(validate_desc(desc, *fCaps));
// We could make initial clears work with scratch textures but it is a rare case so we just opt
// to fall back to making a new texture.