Fix SkCanvas::wouldOverwriteEntireSurface() contains test

R=reed@google.com,robertphillips@google.com,bsalomon@google.com

Review URL: https://codereview.chromium.org/1244093005
This commit is contained in:
fmalita 2015-07-22 05:56:16 -07:00 committed by Commit bot
parent 71f5db892e
commit 8c0144ccb1
2 changed files with 36 additions and 1 deletions

View File

@ -70,7 +70,7 @@ bool SkCanvas::wouldOverwriteEntireSurface(const SkRect* rect, const SkPaint* pa
SkRect devRect; SkRect devRect;
this->getTotalMatrix().mapRect(&devRect, *rect); this->getTotalMatrix().mapRect(&devRect, *rect);
if (devRect.contains(bounds)) { if (!devRect.contains(bounds)) {
return false; return false;
} }
} }

View File

@ -130,3 +130,38 @@ DEF_TEST(Image_NewRasterCopy, reporter) {
REPORTER_ASSERT(reporter, blue == pixels[2]); REPORTER_ASSERT(reporter, blue == pixels[2]);
REPORTER_ASSERT(reporter, 0 == pixels[3]); REPORTER_ASSERT(reporter, 0 == pixels[3]);
} }
// Test that a draw that only partially covers the drawing surface isn't
// interpreted as covering the entire drawing surface (i.e., exercise one of the
// conditions of SkCanvas::wouldOverwriteEntireSurface()).
DEF_TEST(Image_RetainSnapshot, reporter) {
const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0);
const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0);
SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
surface->getCanvas()->clear(0xFF00FF00);
SkPMColor pixels[4];
memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect
const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2);
const size_t dstRowBytes = 2 * sizeof(SkPMColor);
SkAutoTUnref<SkImage> image1(surface->newImageSnapshot());
REPORTER_ASSERT(reporter, image1->readPixels(dstInfo, pixels, dstRowBytes, 0, 0));
for (size_t i = 0; i < SK_ARRAY_COUNT(pixels); ++i) {
REPORTER_ASSERT(reporter, pixels[i] == green);
}
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
paint.setColor(SK_ColorRED);
surface->getCanvas()->drawRect(SkRect::MakeXYWH(1, 1, 1, 1), paint);
SkAutoTUnref<SkImage> image2(surface->newImageSnapshot());
REPORTER_ASSERT(reporter, image2->readPixels(dstInfo, pixels, dstRowBytes, 0, 0));
REPORTER_ASSERT(reporter, pixels[0] == green);
REPORTER_ASSERT(reporter, pixels[1] == green);
REPORTER_ASSERT(reporter, pixels[2] == green);
REPORTER_ASSERT(reporter, pixels[3] == red);
}