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>
This commit is contained in:
Brian Osman 2017-01-13 15:50:18 -05:00 committed by Skia Commit-Bot
parent 113fd3461e
commit 7035f3c466

View File

@ -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,