diff options
author | 2017-01-13 15:50:18 -0500 | |
---|---|---|
committer | 2017-01-14 22:29:03 +0000 | |
commit | 7035f3c466826a4116e2f31deb64d1645ea9441b (patch) | |
tree | c9fa894c3bb2099f7df90ae5143b857ce366f800 | |
parent | 113fd3461eb9b8b96ee2692944839077a20e4ca0 (diff) |
Enforce our rules about valid images when making textures
I'm working to make GrUploadPixmapToTexture more robust
and easier to follow. This is one step on that journey.
BUG=skia:
Change-Id: I3ac39057e20ff8249843bb41ceca25f629aff31c
Reviewed-on: https://skia-review.googlesource.com/7037
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
-rw-r--r-- | src/gpu/SkGr.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 3cca52f2b0..50c7cc25a1 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -23,6 +23,7 @@ #include "SkColorFilter.h" #include "SkConfig8888.h" #include "SkData.h" +#include "SkImageInfoPriv.h" #include "SkMaskFilter.h" #include "SkMessageBus.h" #include "SkMipMap.h" @@ -125,6 +126,10 @@ GrTexture* GrUploadPixmapToTexture(GrContext* ctx, const SkPixmap& pixmap, SkBud SkPixmap tmpPixmap; SkBitmap tmpBitmap; + if (!SkImageInfoIsValid(pixmap.info())) { + return nullptr; + } + const GrCaps* caps = ctx->caps(); GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *caps); @@ -199,6 +204,10 @@ GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware : SkDestinationSurfaceColorMode::kLegacy; + if (!SkImageInfoIsValid(bitmap.info())) { + return nullptr; + } + GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps()); // We don't support Gray8 directly in the GL backend, so fail-over to GrUploadBitmapToTexture. @@ -210,11 +219,6 @@ GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b return nullptr; } - SkASSERT(sizeof(int) <= sizeof(uint32_t)); - if (bitmap.width() < 0 || bitmap.height() < 0) { - return nullptr; - } - SkAutoPixmapUnlock srcUnlocker; if (!bitmap.requestLock(&srcUnlocker)) { return nullptr; @@ -264,6 +268,10 @@ GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b GrTexture* GrUploadMipMapToTexture(GrContext* ctx, const SkImageInfo& info, const GrMipLevel* texels, int mipLevelCount) { + if (!SkImageInfoIsValid(info)) { + return nullptr; + } + const GrCaps* caps = ctx->caps(); return ctx->textureProvider()->createMipMappedTexture(GrImageInfoToSurfaceDesc(info, *caps), SkBudgeted::kYes, texels, |