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

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: use explicit color type when reading pixels 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..0e5ab243621da18d559462a76f8e634719a2b292 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -1610,3 +1610,61 @@ 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.
+
+ SkImageInfo onePixelII = SkImageInfo::Make(1,1,kBGRA_8888_SkColorType,kPremul_SkAlphaType);
robertphillips 2014/07/30 19:03:49 blueBM? - Skia doesn't use '_' in variable names.
dneto 2014/07/30 19:26:20 Done.
+ SkBitmap bm_blue;
+ make_bm(&bm_blue,100,100,SkColorSetARGB(255,0,0,255),true);
robertphillips 2014/07/30 19:03:49 redBM?
dneto 2014/07/30 19:26:20 Done.
+ SkBitmap bm_red;
+ make_bm(&bm_red,100,100,SkColorSetARGB(255,255,0,0),true);
robertphillips 2014/07/30 19:03:50 semiTransparent?
dneto 2014/07/30 19:26:20 Done.
+ SkPaint semi_transparent;
+ semi_transparent.setAlpha(0x80);
+
+ SkPictureRecorder recorder;
+ SkCanvas* canvas = recorder.beginRecording(100,100);
+ canvas->drawARGB(0,0,0,0);
+
+ canvas->saveLayer(0, &semi_transparent);
+ canvas->drawBitmap(bm_blue, 25, 25);
+ canvas->drawBitmap(bm_red, 50, 50);
+ canvas->restore();
+
+ SkPicture* picture = recorder.endRecording();
mtklein 2014/07/30 18:47:26 As written this leaks. Best to clean it up! SkAu
dneto 2014/07/30 19:26:20 Done.
+
+ // Now replay the picture back on another canvas
+ // and check a couple of its pixels.
robertphillips 2014/07/30 19:03:50 replayBM?
dneto 2014/07/30 19:26:20 Done.
+ SkBitmap bm_replay;
+ make_bm(&bm_replay,100,100,SK_ColorBLACK,false);
+ SkCanvas replayCanvas(bm_replay);
+ picture->draw(&replayCanvas);
+ replayCanvas.flush();
+
+ SkColor darkBlue = SkColorSetARGB(0xff,0,0,0x80);
+ SkColor darkRed = SkColorSetARGB(0xff,0x80,0,0);
+
+ uint32_t blueDot = 0xdeadbeef;
+ uint32_t redDot = 0xdeadbeef;
+
+ REPORTER_ASSERT(reporter, replayCanvas.readPixels(onePixelII,&blueDot,4,30,30));
mtklein 2014/07/30 18:47:26 This is all fine, but I think you can replace ever
dneto 2014/07/30 19:26:20 Done.
+ REPORTER_ASSERT(reporter, replayCanvas.readPixels(onePixelII,&redDot,4,55,55));
+
+ REPORTER_ASSERT(reporter, blueDot == darkBlue );
+ // With the bug present, we would get a fully opaque red intead of
+ // a dark red.
+ REPORTER_ASSERT(reporter, redDot == darkRed );
+}
« 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