diff options
author | Matt Sarett <msarett@google.com> | 2017-01-13 12:29:08 -0500 |
---|---|---|
committer | Matt Sarett <msarett@google.com> | 2017-01-13 18:48:00 +0000 |
commit | cf5d6caff7a58f1c7ecc36d9a91ccdada5fc7b78 (patch) | |
tree | 918f47bdc667daab329de6ce01318e5cd6232dce /src/image | |
parent | 0497f088bb41338b1b1400556b9b690decc846fa (diff) |
Add SkImageInfoValidConversion() and SkImageInfoIsValid
The idea is share these standards for the following:
SkImage::readPixels()
SkCanvas::readPixels()
SkCanvas::writePixels()
SkBitmap::readPixels()
SkPixmap::readPixels()
On the raster side, SkPixmap::readPixels() is the right
place to check, because all raster calls go through
there eventually. Then at lower levels (ex: SkPixelInfo),
we can assert.
There's not really a unifying location for gpu calls,
so I've added this in multiple places. I haven't really
dug into the gpu code to SkASSERT() on invalid cases
that we will have already caught.
Follow-up work:
Similar refactor for SkReadPixelRec::trim().
Code cleanup in SkPixelInfo::CopyPixels()
BUG=skia:6021
Change-Id: I91ecce10e46c1a6530f0af24a9eb8226dbecaaa2
Reviewed-on: https://skia-review.googlesource.com/6887
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index faccf8dd8b..b56b1bab15 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -24,6 +24,7 @@ #include "SkGrPriv.h" #include "SkImage_Gpu.h" #include "SkImageCacherator.h" +#include "SkImageInfoPriv.h" #include "SkMipMap.h" #include "SkPixelRef.h" @@ -124,6 +125,10 @@ static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) bool SkImage_Gpu::onReadPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, int srcX, int srcY, CachingHint) const { + if (!SkImageInfoValidConversion(info, this->onImageInfo())) { + return false; + } + GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getContext()->caps()); uint32_t flags = 0; if (kUnpremul_SkAlphaType == info.alphaType() && kPremul_SkAlphaType == fAlphaType) { |