Fix SkImage::asLegacyBitmap() rowBytes assert
When reusing the pixel ref, we need to observe its rowBytes. R=reed@google.com Review URL: https://codereview.chromium.org/1227413002
This commit is contained in:
parent
694307c9f1
commit
ea561bf055
@ -270,7 +270,7 @@ bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) c
|
||||
// pixelref since the caller might call setImmutable() themselves
|
||||
// (thus changing our state).
|
||||
if (fBitmap.isImmutable()) {
|
||||
bitmap->setInfo(fBitmap.info());
|
||||
bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
|
||||
bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin());
|
||||
return true;
|
||||
}
|
||||
|
@ -390,6 +390,25 @@ static void test_image_readpixels(skiatest::Reporter* reporter, SkImage* image,
|
||||
REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected));
|
||||
}
|
||||
|
||||
static void check_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* image,
|
||||
const SkBitmap& bitmap, SkImage::LegacyBitmapMode mode) {
|
||||
REPORTER_ASSERT(reporter, image->width() == bitmap.width());
|
||||
REPORTER_ASSERT(reporter, image->height() == bitmap.height());
|
||||
REPORTER_ASSERT(reporter, image->isOpaque() == bitmap.isOpaque());
|
||||
|
||||
if (SkImage::kRO_LegacyBitmapMode == mode) {
|
||||
REPORTER_ASSERT(reporter, bitmap.isImmutable());
|
||||
}
|
||||
|
||||
SkAutoLockPixels alp(bitmap);
|
||||
REPORTER_ASSERT(reporter, bitmap.getPixels());
|
||||
|
||||
const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType());
|
||||
SkPMColor imageColor;
|
||||
REPORTER_ASSERT(reporter, image->readPixels(info, &imageColor, sizeof(SkPMColor), 0, 0));
|
||||
REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0));
|
||||
}
|
||||
|
||||
static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* image) {
|
||||
const SkImage::LegacyBitmapMode modes[] = {
|
||||
SkImage::kRO_LegacyBitmapMode,
|
||||
@ -398,22 +417,18 @@ static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* imag
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(modes); ++i) {
|
||||
SkBitmap bitmap;
|
||||
REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, modes[i]));
|
||||
check_legacy_bitmap(reporter, image, bitmap, modes[i]);
|
||||
|
||||
REPORTER_ASSERT(reporter, image->width() == bitmap.width());
|
||||
REPORTER_ASSERT(reporter, image->height() == bitmap.height());
|
||||
REPORTER_ASSERT(reporter, image->isOpaque() == bitmap.isOpaque());
|
||||
// Test subsetting to exercise the rowBytes logic.
|
||||
SkBitmap tmp;
|
||||
REPORTER_ASSERT(reporter, bitmap.extractSubset(&tmp, SkIRect::MakeWH(image->width() / 2,
|
||||
image->height() / 2)));
|
||||
SkAutoTUnref<SkImage> subsetImage(SkImage::NewFromBitmap(tmp));
|
||||
REPORTER_ASSERT(reporter, subsetImage);
|
||||
|
||||
bitmap.lockPixels();
|
||||
REPORTER_ASSERT(reporter, bitmap.getPixels());
|
||||
|
||||
const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType());
|
||||
SkPMColor imageColor;
|
||||
REPORTER_ASSERT(reporter, image->readPixels(info, &imageColor, sizeof(SkPMColor), 0, 0));
|
||||
REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0));
|
||||
|
||||
if (SkImage::kRO_LegacyBitmapMode == modes[i]) {
|
||||
REPORTER_ASSERT(reporter, bitmap.isImmutable());
|
||||
}
|
||||
SkBitmap subsetBitmap;
|
||||
REPORTER_ASSERT(reporter, subsetImage->asLegacyBitmap(&subsetBitmap, modes[i]));
|
||||
check_legacy_bitmap(reporter, subsetImage, subsetBitmap, modes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user