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

Unified Diff: tests/PictureTest.cpp

Issue 430503004: Fix end-of-pattern matching for Skia recording optimization. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Test fixes: leak, var names, lint Created 6 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/SkPictureRecord.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/PictureTest.cpp
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 95ceb051146b859c94076f1e191f5ab74bc7d161..7abef0edc1407206d6b5ea154a4a449d369c70de 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -1610,3 +1610,51 @@ DEF_TEST(Canvas_EmptyBitmap, r) {
test_draw_bitmaps(&canvas);
}
+
+DEF_TEST(DontOptimizeSaveLayerDrawDrawRestore, reporter) {
+ // This test is from crbug.com/344987.
+ // The commands are:
+ // saveLayer with paint that modifies alpha
+ // drawBitmapRectToRect
+ // drawBitmapRectToRect
+ // restore
+ // The bug was that this structure was modified so that:
+ // - The saveLayer and restore were eliminated
+ // - The alpha was only applied to the first drawBitmapRectToRect
+
+ // This test draws blue and red squares inside a 50% transparent
+ // layer. Both colours should show up muted.
+ // When the bug is present, the red square (the second bitmap)
+ // shows upwith full opacity.
+
+ SkBitmap blueBM;
+ make_bm(&blueBM, 100, 100, SkColorSetARGB(255, 0, 0, 255), true);
+ SkBitmap redBM;
+ make_bm(&redBM, 100, 100, SkColorSetARGB(255, 255, 0, 0), true);
+ SkPaint semiTransparent;
+ semiTransparent.setAlpha(0x80);
+
+ SkPictureRecorder recorder;
+ SkCanvas* canvas = recorder.beginRecording(100, 100);
+ canvas->drawARGB(0, 0, 0, 0);
+
+ canvas->saveLayer(0, &semiTransparent);
+ canvas->drawBitmap(blueBM, 25, 25);
+ canvas->drawBitmap(redBM, 50, 50);
+ canvas->restore();
+
+ SkAutoTUnref<SkPicture> picture(recorder.endRecording());
+
+ // Now replay the picture back on another canvas
+ // and check a couple of its pixels.
+ SkBitmap replayBM;
+ make_bm(&replayBM, 100, 100, SK_ColorBLACK, false);
+ SkCanvas replayCanvas(replayBM);
+ picture->draw(&replayCanvas);
+ replayCanvas.flush();
+
+ // With the bug present, at (55, 55) we would get a fully opaque red
+ // intead of a dark red.
+ REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080);
+ REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000);
+}
« no previous file with comments | « src/core/SkPictureRecord.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698