Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(663)

Unified Diff: tests/ImageTest.cpp

Issue 1244093005: Fix SkCanvas::wouldOverwriteEntireSurface() contains test (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: test comment Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageTest.cpp
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index eb8f7615a9c47380efef87a1c4134df048abcfe1..d93815ba9c8900054f891a411faf426c83da694d 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -130,3 +130,38 @@ DEF_TEST(Image_NewRasterCopy, reporter) {
REPORTER_ASSERT(reporter, blue == pixels[2]);
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);
+}
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698