Add checks for failed SkImageInfo2GrPixelConfig calls

Bug: skia:7645
Change-Id: I32b9326fb43490ef6a7a99527243b68d89184ae1
Reviewed-on: https://skia-review.googlesource.com/109083
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Greg Daniel 2018-02-21 13:02:32 -05:00 committed by Skia Commit-Bot
parent 32f72e25bd
commit 0a7aa14bf3
11 changed files with 25 additions and 0 deletions

View File

@ -92,6 +92,7 @@ DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
desc.fWidth = 2 * S;
desc.fHeight = 2 * S;
desc.fConfig = SkImageInfo2GrPixelConfig(ii, *context->caps());
SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
sk_sp<GrTextureProxy> proxy = proxyProvider->createTextureProxy(desc, SkBudgeted::kNo,
gTextureData.get(), 0);

View File

@ -93,6 +93,7 @@ protected:
desc.fWidth = fBmp.width();
desc.fHeight = fBmp.height();
desc.fConfig = SkImageInfo2GrPixelConfig(fBmp.info(), *context->caps());
SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
sk_sp<GrTextureProxy> proxy = proxyProvider->createTextureProxy(desc, SkBudgeted::kYes,
fBmp.getPixels(),

View File

@ -94,6 +94,7 @@ protected:
desc.fWidth = fBmp[i].width();
desc.fHeight = fBmp[i].height();
desc.fConfig = SkImageInfo2GrPixelConfig(fBmp[i].info(), *context->caps());
SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
proxy[i] = proxyProvider->createTextureProxy(desc, SkBudgeted::kYes,
fBmp[i].getPixels(),
@ -225,6 +226,7 @@ protected:
desc.fWidth = fBmp[index].width();
desc.fHeight = fBmp[index].height();
desc.fConfig = SkImageInfo2GrPixelConfig(fBmp[index].info(), *context->caps());
SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
proxy[i] = proxyProvider->createTextureProxy(desc, SkBudgeted::kYes,
fBmp[index].getPixels(),

View File

@ -448,6 +448,10 @@ std::unique_ptr<GrFragmentProcessor> ColorTableEffect::Make(GrContext* context,
desc.fContext = context;
desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info(), *context->caps());
if (kUnknown_GrPixelConfig == desc.fConfig) {
return nullptr;
}
GrTextureStripAtlas* atlas = GrTextureStripAtlas::GetAtlas(desc);
int row = atlas->lockRow(bitmap);
sk_sp<GrTextureProxy> proxy;

View File

@ -214,6 +214,10 @@ sk_sp<GrTextureProxy> GrProxyProvider::createTextureProxy(sk_sp<SkImage> srcImag
GrPixelConfig config = SkImageInfo2GrPixelConfig(as_IB(srcImage)->onImageInfo(),
*this->caps());
if (kUnknown_GrPixelConfig == config) {
return nullptr;
}
if (SkToBool(flags & kRenderTarget_GrSurfaceFlag)) {
sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, config);
if (!sampleCnt) {

View File

@ -159,6 +159,9 @@ sk_sp<GrRenderTargetContext> SkGpuDevice::MakeRenderTargetContext(
}
GrPixelConfig config = SkImageInfo2GrPixelConfig(origInfo, *context->caps());
if (kUnknown_GrPixelConfig == config) {
return nullptr;
}
// This method is used to create SkGpuDevice's for SkSurface_Gpus. In this case
// they need to be exact.
return context->makeDeferredRenderTargetContext(

View File

@ -165,6 +165,7 @@ public:
GrGpu* gpu = context->contextPriv().getGpu();
GrPixelConfig config = SkImageInfo2GrPixelConfig(fColorType, nullptr, *context->caps());
SkASSERT(kUnknown_GrPixelConfig != config);
*backend = gpu->createTestingOnlyBackendTexture(nullptr, fWidth, fHeight,
config, true, GrMipMapped::kNo);

View File

@ -199,6 +199,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
for (auto colorType : { kAlpha_8_SkColorType, kRGBA_8888_SkColorType }) {
for (auto numSamples : {1, 4}) {
GrPixelConfig config = SkImageInfo2GrPixelConfig(colorType, nullptr, caps);
SkASSERT(kUnknown_GrPixelConfig != config);
int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config);
if (!supportedNumSamples) {

View File

@ -1010,6 +1010,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCreationWithColorSpace_Gpu, reporter,
static const int kSize = 10;
GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *context->caps());
SkASSERT(kUnknown_GrPixelConfig != config);
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
nullptr, kSize, kSize, config, true, GrMipMapped::kNo);

View File

@ -187,6 +187,9 @@ GrBackendTexture GrGpu::createTestingOnlyBackendTexture(void* pixels, int w, int
SkColorType colorType, bool isRenderTarget,
GrMipMapped mipMapped) {
GrPixelConfig config = SkImageInfo2GrPixelConfig(colorType, nullptr, *this->caps());
if (kUnknown_GrPixelConfig == config) {
return GrBackendTexture();
}
return this->createTestingOnlyBackendTexture(pixels, w, h, config, isRenderTarget, mipMapped);
}

View File

@ -292,6 +292,10 @@ int main(int argc, char** argv) {
GrPixelConfig grPixConfig = SkImageInfo2GrPixelConfig(config->getColorType(),
config->getColorSpace(),
*ctx->caps());
if (kUnknown_GrPixelConfig == grPixConfig) {
exitf(ExitErr::kUnavailable, "failed to get GrPixelConfig from SkColorType: %d",
config->getColorType());
}
int supportedSampleCount =
ctx->caps()->getRenderTargetSampleCount(config->getSamples(), grPixConfig);
if (supportedSampleCount != config->getSamples()) {