| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "cc/test/fake_picture_pile_impl.h" | 6 #include "cc/test/fake_picture_pile_impl.h" |
| 7 #include "cc/test/skia_common.h" | 7 #include "cc/test/skia_common.h" |
| 8 #include "skia/ext/refptr.h" | 8 #include "skia/ext/refptr.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkPixelRef.h" | 10 #include "third_party/skia/include/core/SkPixelRef.h" |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 EXPECT_TRUE(iterator); | 627 EXPECT_TRUE(iterator); |
| 628 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); | 628 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 629 EXPECT_TRUE(++iterator); | 629 EXPECT_TRUE(++iterator); |
| 630 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); | 630 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); |
| 631 EXPECT_TRUE(++iterator); | 631 EXPECT_TRUE(++iterator); |
| 632 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); | 632 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 633 EXPECT_FALSE(++iterator); | 633 EXPECT_FALSE(++iterator); |
| 634 } | 634 } |
| 635 } | 635 } |
| 636 | 636 |
| 637 class FullContentsTest : public ::testing::TestWithParam<bool> {}; | 637 TEST(PicturePileImplTest, RasterFullContents) { |
| 638 | |
| 639 TEST_P(FullContentsTest, RasterFullContents) { | |
| 640 gfx::Size tile_size(1000, 1000); | 638 gfx::Size tile_size(1000, 1000); |
| 641 gfx::Size layer_bounds(3, 5); | 639 gfx::Size layer_bounds(3, 5); |
| 642 float contents_scale = 1.5f; | 640 float contents_scale = 1.5f; |
| 643 float raster_divisions = 2.f; | 641 float raster_divisions = 2.f; |
| 644 // Param in this case is whether the content is fully opaque | |
| 645 // or just filled completely. For this test they should behave the same. | |
| 646 bool contents_opaque = GetParam(); | |
| 647 bool fills_content = !GetParam(); | |
| 648 | 642 |
| 649 scoped_refptr<FakePicturePileImpl> pile = | 643 scoped_refptr<FakePicturePileImpl> pile = |
| 650 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 644 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 651 // Because the caller sets content opaque, it also promises that it | 645 // Because the caller sets content opaque, it also promises that it |
| 652 // has at least filled in layer_bounds opaquely. | 646 // has at least filled in layer_bounds opaquely. |
| 653 SkPaint white_paint; | 647 SkPaint white_paint; |
| 654 white_paint.setColor(SK_ColorWHITE); | 648 white_paint.setColor(SK_ColorWHITE); |
| 655 pile->add_draw_rect_with_paint(gfx::Rect(layer_bounds), white_paint); | 649 pile->add_draw_rect_with_paint(gfx::Rect(layer_bounds), white_paint); |
| 656 | 650 |
| 657 pile->SetMinContentsScale(contents_scale); | 651 pile->SetMinContentsScale(contents_scale); |
| 658 pile->set_background_color(SK_ColorBLACK); | 652 pile->set_background_color(SK_ColorBLACK); |
| 659 pile->set_contents_opaque(contents_opaque); | 653 pile->SetRequiresClear(false); |
| 660 pile->set_contents_fill_bounds_completely(fills_content); | |
| 661 pile->set_clear_canvas_with_debug_color(false); | 654 pile->set_clear_canvas_with_debug_color(false); |
| 662 pile->RerecordPile(); | 655 pile->RerecordPile(); |
| 663 | 656 |
| 664 gfx::Size content_bounds( | 657 gfx::Size content_bounds( |
| 665 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 658 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
| 666 | 659 |
| 667 // Simulate drawing into different tiles at different offsets. | 660 // Simulate drawing into different tiles at different offsets. |
| 668 int step_x = std::ceil(content_bounds.width() / raster_divisions); | 661 int step_x = std::ceil(content_bounds.width() / raster_divisions); |
| 669 int step_y = std::ceil(content_bounds.height() / raster_divisions); | 662 int step_y = std::ceil(content_bounds.height() / raster_divisions); |
| 670 for (int offset_x = 0; offset_x < content_bounds.width(); | 663 for (int offset_x = 0; offset_x < content_bounds.width(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 698 } | 691 } |
| 699 | 692 |
| 700 // If the canvas doesn't extend past the edge of the content, | 693 // If the canvas doesn't extend past the edge of the content, |
| 701 // it should be entirely white. Otherwise, the edge of the content | 694 // it should be entirely white. Otherwise, the edge of the content |
| 702 // will be non-white. | 695 // will be non-white. |
| 703 EXPECT_EQ(all_white, gfx::Rect(content_bounds).Contains(canvas_rect)); | 696 EXPECT_EQ(all_white, gfx::Rect(content_bounds).Contains(canvas_rect)); |
| 704 } | 697 } |
| 705 } | 698 } |
| 706 } | 699 } |
| 707 | 700 |
| 708 INSTANTIATE_TEST_CASE_P(PicturePileImpl, | |
| 709 FullContentsTest, | |
| 710 ::testing::Values(false, true)); | |
| 711 | |
| 712 TEST(PicturePileImpl, RasterContentsTransparent) { | 701 TEST(PicturePileImpl, RasterContentsTransparent) { |
| 713 gfx::Size tile_size(1000, 1000); | 702 gfx::Size tile_size(1000, 1000); |
| 714 gfx::Size layer_bounds(5, 3); | 703 gfx::Size layer_bounds(5, 3); |
| 715 float contents_scale = 0.5f; | 704 float contents_scale = 0.5f; |
| 716 | 705 |
| 717 scoped_refptr<FakePicturePileImpl> pile = | 706 scoped_refptr<FakePicturePileImpl> pile = |
| 718 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 707 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 719 pile->set_background_color(SK_ColorTRANSPARENT); | 708 pile->set_background_color(SK_ColorTRANSPARENT); |
| 720 pile->set_contents_opaque(false); | 709 pile->SetRequiresClear(true); |
| 721 pile->SetMinContentsScale(contents_scale); | 710 pile->SetMinContentsScale(contents_scale); |
| 722 pile->set_clear_canvas_with_debug_color(false); | 711 pile->set_clear_canvas_with_debug_color(false); |
| 723 pile->RerecordPile(); | 712 pile->RerecordPile(); |
| 724 | 713 |
| 725 gfx::Size content_bounds( | 714 gfx::Size content_bounds( |
| 726 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 715 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
| 727 | 716 |
| 728 gfx::Rect canvas_rect(content_bounds); | 717 gfx::Rect canvas_rect(content_bounds); |
| 729 canvas_rect.Inset(0, 0, -1, -1); | 718 canvas_rect.Inset(0, 0, -1, -1); |
| 730 | 719 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 750 gfx::Size tile_size(10, 10); | 739 gfx::Size tile_size(10, 10); |
| 751 gfx::Size layer_bounds(30, 30); | 740 gfx::Size layer_bounds(30, 30); |
| 752 gfx::Size bigger_than_layer_bounds(300, 300); | 741 gfx::Size bigger_than_layer_bounds(300, 300); |
| 753 float contents_scale = GetParam(); | 742 float contents_scale = GetParam(); |
| 754 // Pick an opaque color to not have to deal with premultiplication off-by-one. | 743 // Pick an opaque color to not have to deal with premultiplication off-by-one. |
| 755 SkColor test_color = SkColorSetARGB(255, 45, 56, 67); | 744 SkColor test_color = SkColorSetARGB(255, 45, 56, 67); |
| 756 | 745 |
| 757 scoped_refptr<FakePicturePileImpl> pile = | 746 scoped_refptr<FakePicturePileImpl> pile = |
| 758 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 747 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 759 pile->set_background_color(SK_ColorTRANSPARENT); | 748 pile->set_background_color(SK_ColorTRANSPARENT); |
| 760 pile->set_contents_opaque(false); | 749 pile->SetRequiresClear(true); |
| 761 pile->SetMinContentsScale(MinContentsScale()); | 750 pile->SetMinContentsScale(MinContentsScale()); |
| 762 pile->set_clear_canvas_with_debug_color(true); | 751 pile->set_clear_canvas_with_debug_color(true); |
| 763 SkPaint color_paint; | 752 SkPaint color_paint; |
| 764 color_paint.setColor(test_color); | 753 color_paint.setColor(test_color); |
| 765 // Additive paint, so that if two paints overlap, the color will change. | 754 // Additive paint, so that if two paints overlap, the color will change. |
| 766 color_paint.setXfermodeMode(SkXfermode::kPlus_Mode); | 755 color_paint.setXfermodeMode(SkXfermode::kPlus_Mode); |
| 767 // Paint outside the layer to make sure that blending works. | 756 // Paint outside the layer to make sure that blending works. |
| 768 pile->add_draw_rect_with_paint(gfx::RectF(bigger_than_layer_bounds), | 757 pile->add_draw_rect_with_paint(gfx::RectF(bigger_than_layer_bounds), |
| 769 color_paint); | 758 color_paint); |
| 770 pile->RerecordPile(); | 759 pile->RerecordPile(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 EXPECT_TRUE(iterator); | 861 EXPECT_TRUE(iterator); |
| 873 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); | 862 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); |
| 874 EXPECT_TRUE(++iterator); | 863 EXPECT_TRUE(++iterator); |
| 875 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); | 864 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); |
| 876 EXPECT_FALSE(++iterator); | 865 EXPECT_FALSE(++iterator); |
| 877 } | 866 } |
| 878 } | 867 } |
| 879 | 868 |
| 880 } // namespace | 869 } // namespace |
| 881 } // namespace cc | 870 } // namespace cc |
| OLD | NEW |