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 SkBitmap blueBM; |
| 1631 make_bm(&blueBM, 100, 100, SkColorSetARGB(255, 0, 0, 255), true); |
| 1632 SkBitmap redBM; |
| 1633 make_bm(&redBM, 100, 100, SkColorSetARGB(255, 255, 0, 0), true); |
| 1634 SkPaint semiTransparent; |
| 1635 semiTransparent.setAlpha(0x80); |
| 1636 |
| 1637 SkPictureRecorder recorder; |
| 1638 SkCanvas* canvas = recorder.beginRecording(100, 100); |
| 1639 canvas->drawARGB(0, 0, 0, 0); |
| 1640 |
| 1641 canvas->saveLayer(0, &semiTransparent); |
| 1642 canvas->drawBitmap(blueBM, 25, 25); |
| 1643 canvas->drawBitmap(redBM, 50, 50); |
| 1644 canvas->restore(); |
| 1645 |
| 1646 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 1647 |
| 1648 // Now replay the picture back on another canvas |
| 1649 // and check a couple of its pixels. |
| 1650 SkBitmap replayBM; |
| 1651 make_bm(&replayBM, 100, 100, SK_ColorBLACK, false); |
| 1652 SkCanvas replayCanvas(replayBM); |
| 1653 picture->draw(&replayCanvas); |
| 1654 replayCanvas.flush(); |
| 1655 |
| 1656 // With the bug present, at (55, 55) we would get a fully opaque red |
| 1657 // intead of a dark red. |
| 1658 REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080); |
| 1659 REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000); |
| 1660 } |
OLD | NEW |