diff options
author | 2017-01-17 10:48:53 -0500 | |
---|---|---|
committer | 2017-01-17 16:23:47 +0000 | |
commit | cb6266b5aa5bbfd880532f08eec83b0c585e873f (patch) | |
tree | ed7f02bf09e3ac603ab6b9b579b76fb1f3f85f68 /src/core/SkPixmap.cpp | |
parent | aab259ea9ecabb3addcade3fba72d777bc7673e8 (diff) |
Reland "Add SkImageInfoValidConversion() and SkImageInfoIsValid"
The original is at:
https://skia-review.googlesource.com/c/6887/
The only change to the original is to temporarily comment out
a check in SkImageInfoPriv.h until a Chrome unit test can
be fixed.
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: I6a16f9479bc09e3c87e10c72b0378579f1a70866
Reviewed-on: https://skia-review.googlesource.com/7104
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'src/core/SkPixmap.cpp')
-rw-r--r-- | src/core/SkPixmap.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp index 3e89af65ed..1e24b93a60 100644 --- a/src/core/SkPixmap.cpp +++ b/src/core/SkPixmap.cpp @@ -10,6 +10,7 @@ #include "SkColorPriv.h" #include "SkConfig8888.h" #include "SkData.h" +#include "SkImageInfoPriv.h" #include "SkHalf.h" #include "SkMask.h" #include "SkNx.h" @@ -84,15 +85,13 @@ bool SkPixmap::extractSubset(SkPixmap* result, const SkIRect& subset) const { bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels, size_t dstRB, int x, int y) const { - if (kUnknown_SkColorType == requestedDstInfo.colorType()) { + if (!SkImageInfoValidConversion(requestedDstInfo, fInfo)) { return false; } + if (nullptr == dstPixels || dstRB < requestedDstInfo.minRowBytes()) { return false; } - if (0 == requestedDstInfo.width() || 0 == requestedDstInfo.height()) { - return false; - } SkIRect srcR = SkIRect::MakeXYWH(x, y, requestedDstInfo.width(), requestedDstInfo.height()); if (!srcR.intersect(0, 0, this->width(), this->height())) { |