OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBlurImageFilter.h" | 8 #include "SkBlurImageFilter.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 1592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1603 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1603 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1604 } | 1604 } |
1605 | 1605 |
1606 DEF_TEST(Canvas_EmptyBitmap, r) { | 1606 DEF_TEST(Canvas_EmptyBitmap, r) { |
1607 SkBitmap dst; | 1607 SkBitmap dst; |
1608 dst.allocN32Pixels(10, 10); | 1608 dst.allocN32Pixels(10, 10); |
1609 SkCanvas canvas(dst); | 1609 SkCanvas canvas(dst); |
1610 | 1610 |
1611 test_draw_bitmaps(&canvas); | 1611 test_draw_bitmaps(&canvas); |
1612 } | 1612 } |
1613 | |
1614 DEF_TEST(DontOptimizeSaveLayerDrawDrawRestore, reporter) { | |
1615 // This test is from crbug.com/344987. | |
1616 // The commands are: | |
1617 // saveLayer with paint that modifies alpha | |
1618 // drawBitmapRectToRect | |
1619 // drawBitmapRectToRect | |
1620 // restore | |
1621 // The bug was that this structure was modified so that: | |
1622 // - The saveLayer and restore were eliminated | |
1623 // - The alpha was only applied to the first drawBitmapRectToRect | |
1624 | |
1625 // This test draws blue and red squares inside a 50% transparent | |
1626 // layer. Both colours should show up muted. | |
1627 // When the bug is present, the red square (the second bitmap) | |
1628 // shows upwith full opacity. | |
1629 | |
1630 SkImageInfo onePixelII = SkImageInfo::Make(1,1,kBGRA_8888_SkColorType,kPremu l_SkAlphaType); | |
robertphillips
2014/07/30 19:03:49
blueBM? - Skia doesn't use '_' in variable names.
dneto
2014/07/30 19:26:20
Done.
| |
1631 SkBitmap bm_blue; | |
1632 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.
| |
1633 SkBitmap bm_red; | |
1634 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.
| |
1635 SkPaint semi_transparent; | |
1636 semi_transparent.setAlpha(0x80); | |
1637 | |
1638 SkPictureRecorder recorder; | |
1639 SkCanvas* canvas = recorder.beginRecording(100,100); | |
1640 canvas->drawARGB(0,0,0,0); | |
1641 | |
1642 canvas->saveLayer(0, &semi_transparent); | |
1643 canvas->drawBitmap(bm_blue, 25, 25); | |
1644 canvas->drawBitmap(bm_red, 50, 50); | |
1645 canvas->restore(); | |
1646 | |
1647 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.
| |
1648 | |
1649 // Now replay the picture back on another canvas | |
1650 // and check a couple of its pixels. | |
robertphillips
2014/07/30 19:03:50
replayBM?
dneto
2014/07/30 19:26:20
Done.
| |
1651 SkBitmap bm_replay; | |
1652 make_bm(&bm_replay,100,100,SK_ColorBLACK,false); | |
1653 SkCanvas replayCanvas(bm_replay); | |
1654 picture->draw(&replayCanvas); | |
1655 replayCanvas.flush(); | |
1656 | |
1657 SkColor darkBlue = SkColorSetARGB(0xff,0,0,0x80); | |
1658 SkColor darkRed = SkColorSetARGB(0xff,0x80,0,0); | |
1659 | |
1660 uint32_t blueDot = 0xdeadbeef; | |
1661 uint32_t redDot = 0xdeadbeef; | |
1662 | |
1663 REPORTER_ASSERT(reporter, replayCanvas.readPixels(onePixelII,&blueDot,4,30,3 0)); | |
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.
| |
1664 REPORTER_ASSERT(reporter, replayCanvas.readPixels(onePixelII,&redDot,4,55,55 )); | |
1665 | |
1666 REPORTER_ASSERT(reporter, blueDot == darkBlue ); | |
1667 // With the bug present, we would get a fully opaque red intead of | |
1668 // a dark red. | |
1669 REPORTER_ASSERT(reporter, redDot == darkRed ); | |
1670 } | |
OLD | NEW |