Band-aid for subsetted bitmaps in SKPs.

Partial fix for https://code.google.com/p/skia/issues/detail?id=1301.

Instead of firing an assert when the recorded width and height do
not match the encoded data's width and height, take a subset of
the bitmap of the correct size.

The bitmap may be drawn incorrectly, since it will not necessarily
be the correct subset (though it will be the correct size). The
complete fix will be to record the offset to the stream. Holding off
on that since it will change the PICTURE_VERSION. There is still
more work to do on read/writeBitmap, and I would like to change
PICTURE_VERSION as few times as possible.

BUG=https://code.google.com/p/skia/issues/detail?id=1301
R=djsollen@google.com

Review URL: https://codereview.chromium.org/15159004

git-svn-id: http://skia.googlecode.com/svn/trunk@9169 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
scroggo@google.com 2013-05-16 19:35:39 +00:00
parent 9401deeb10
commit 719a3733ae

View File

@ -197,8 +197,23 @@ void SkOrderedReadBuffer::readBitmap(SkBitmap* bitmap) {
// A non-zero size means the SkBitmap was encoded.
const void* data = this->skip(length);
if (fBitmapDecoder != NULL && fBitmapDecoder(data, length, bitmap)) {
SkASSERT(bitmap->width() == width && bitmap->height() == height);
return;
if (bitmap->width() == width && bitmap->height() == height) {
return;
}
// This case can only be reached if extractSubset was called, so
// the recorded width and height must be smaller than (or equal to
// the encoded width and height.
SkASSERT(width <= bitmap->width() && height <= bitmap->height());
// FIXME: Once the writer is changed to record the (x,y) offset,
// they will be used to store the correct portion of the picture.
SkBitmap subsetBm;
SkIRect subset = SkIRect::MakeWH(width, height);
if (bitmap->extractSubset(&subsetBm, subset)) {
bitmap->swap(subsetBm);
return;
}
}
// This bitmap was encoded when written, but we are unable to decode, possibly due to
// not having a decoder.