| 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/fake_rendering_stats_instrumentation.h" | |
| 8 #include "cc/test/skia_common.h" | 7 #include "cc/test/skia_common.h" |
| 9 #include "skia/ext/refptr.h" | 8 #include "skia/ext/refptr.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/skia/include/core/SkPixelRef.h" | 10 #include "third_party/skia/include/core/SkPixelRef.h" |
| 12 #include "third_party/skia/include/core/SkShader.h" | 11 #include "third_party/skia/include/core/SkShader.h" |
| 13 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 14 #include "ui/gfx/geometry/size_conversions.h" | 13 #include "ui/gfx/geometry/size_conversions.h" |
| 15 | 14 |
| 16 namespace cc { | 15 namespace cc { |
| 17 namespace { | 16 namespace { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 32 non_solid_paint.setColor(non_solid_color); | 31 non_solid_paint.setColor(non_solid_color); |
| 33 | 32 |
| 34 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); | 33 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); |
| 35 pile->RerecordPile(); | 34 pile->RerecordPile(); |
| 36 | 35 |
| 37 // Ensure everything is solid | 36 // Ensure everything is solid |
| 38 for (int y = 0; y <= 300; y += 100) { | 37 for (int y = 0; y <= 300; y += 100) { |
| 39 for (int x = 0; x <= 300; x += 100) { | 38 for (int x = 0; x <= 300; x += 100) { |
| 40 RasterSource::SolidColorAnalysis analysis; | 39 RasterSource::SolidColorAnalysis analysis; |
| 41 gfx::Rect rect(x, y, 100, 100); | 40 gfx::Rect rect(x, y, 100, 100); |
| 42 pile->PerformSolidColorAnalysis(rect, 1.0, &analysis, nullptr); | 41 pile->PerformSolidColorAnalysis(rect, 1.0, &analysis); |
| 43 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); | 42 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); |
| 44 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); | 43 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); |
| 45 } | 44 } |
| 46 } | 45 } |
| 47 | 46 |
| 48 // One pixel non solid | 47 // One pixel non solid |
| 49 pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); | 48 pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); |
| 50 pile->RerecordPile(); | 49 pile->RerecordPile(); |
| 51 | 50 |
| 52 RasterSource::SolidColorAnalysis analysis; | 51 RasterSource::SolidColorAnalysis analysis; |
| 53 pile->PerformSolidColorAnalysis( | 52 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); |
| 54 gfx::Rect(0, 0, 100, 100), 1.0, &analysis, nullptr); | |
| 55 EXPECT_FALSE(analysis.is_solid_color); | 53 EXPECT_FALSE(analysis.is_solid_color); |
| 56 | 54 |
| 57 pile->PerformSolidColorAnalysis( | 55 pile->PerformSolidColorAnalysis(gfx::Rect(100, 0, 100, 100), 1.0, &analysis); |
| 58 gfx::Rect(100, 0, 100, 100), 1.0, &analysis, nullptr); | |
| 59 EXPECT_TRUE(analysis.is_solid_color); | 56 EXPECT_TRUE(analysis.is_solid_color); |
| 60 EXPECT_EQ(analysis.solid_color, solid_color); | 57 EXPECT_EQ(analysis.solid_color, solid_color); |
| 61 | 58 |
| 62 // Boundaries should be clipped | 59 // Boundaries should be clipped |
| 63 analysis.is_solid_color = false; | 60 analysis.is_solid_color = false; |
| 64 pile->PerformSolidColorAnalysis( | 61 pile->PerformSolidColorAnalysis(gfx::Rect(350, 0, 100, 100), 1.0, &analysis); |
| 65 gfx::Rect(350, 0, 100, 100), 1.0, &analysis, nullptr); | |
| 66 EXPECT_TRUE(analysis.is_solid_color); | 62 EXPECT_TRUE(analysis.is_solid_color); |
| 67 EXPECT_EQ(analysis.solid_color, solid_color); | 63 EXPECT_EQ(analysis.solid_color, solid_color); |
| 68 | 64 |
| 69 analysis.is_solid_color = false; | 65 analysis.is_solid_color = false; |
| 70 pile->PerformSolidColorAnalysis( | 66 pile->PerformSolidColorAnalysis(gfx::Rect(0, 350, 100, 100), 1.0, &analysis); |
| 71 gfx::Rect(0, 350, 100, 100), 1.0, &analysis, nullptr); | |
| 72 EXPECT_TRUE(analysis.is_solid_color); | 67 EXPECT_TRUE(analysis.is_solid_color); |
| 73 EXPECT_EQ(analysis.solid_color, solid_color); | 68 EXPECT_EQ(analysis.solid_color, solid_color); |
| 74 | 69 |
| 75 analysis.is_solid_color = false; | 70 analysis.is_solid_color = false; |
| 76 pile->PerformSolidColorAnalysis( | 71 pile->PerformSolidColorAnalysis(gfx::Rect(350, 350, 100, 100), 1.0, |
| 77 gfx::Rect(350, 350, 100, 100), 1.0, &analysis, nullptr); | 72 &analysis); |
| 78 EXPECT_TRUE(analysis.is_solid_color); | 73 EXPECT_TRUE(analysis.is_solid_color); |
| 79 EXPECT_EQ(analysis.solid_color, solid_color); | 74 EXPECT_EQ(analysis.solid_color, solid_color); |
| 80 } | 75 } |
| 81 | 76 |
| 82 TEST(PicturePileImplTest, AnalyzeIsSolidScaled) { | 77 TEST(PicturePileImplTest, AnalyzeIsSolidScaled) { |
| 83 gfx::Size tile_size(100, 100); | 78 gfx::Size tile_size(100, 100); |
| 84 gfx::Size layer_bounds(400, 400); | 79 gfx::Size layer_bounds(400, 400); |
| 85 | 80 |
| 86 scoped_refptr<FakePicturePileImpl> pile = | 81 scoped_refptr<FakePicturePileImpl> pile = |
| 87 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 82 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 88 | 83 |
| 89 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | 84 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
| 90 SkPaint solid_paint; | 85 SkPaint solid_paint; |
| 91 solid_paint.setColor(solid_color); | 86 solid_paint.setColor(solid_color); |
| 92 | 87 |
| 93 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | 88 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
| 94 SkPaint non_solid_paint; | 89 SkPaint non_solid_paint; |
| 95 non_solid_paint.setColor(non_solid_color); | 90 non_solid_paint.setColor(non_solid_color); |
| 96 | 91 |
| 97 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); | 92 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); |
| 98 pile->RerecordPile(); | 93 pile->RerecordPile(); |
| 99 | 94 |
| 100 // Ensure everything is solid | 95 // Ensure everything is solid |
| 101 for (int y = 0; y <= 30; y += 10) { | 96 for (int y = 0; y <= 30; y += 10) { |
| 102 for (int x = 0; x <= 30; x += 10) { | 97 for (int x = 0; x <= 30; x += 10) { |
| 103 RasterSource::SolidColorAnalysis analysis; | 98 RasterSource::SolidColorAnalysis analysis; |
| 104 gfx::Rect rect(x, y, 10, 10); | 99 gfx::Rect rect(x, y, 10, 10); |
| 105 pile->PerformSolidColorAnalysis(rect, 0.1f, &analysis, nullptr); | 100 pile->PerformSolidColorAnalysis(rect, 0.1f, &analysis); |
| 106 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); | 101 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); |
| 107 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); | 102 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); |
| 108 } | 103 } |
| 109 } | 104 } |
| 110 | 105 |
| 111 // One pixel non solid | 106 // One pixel non solid |
| 112 pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); | 107 pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); |
| 113 pile->RerecordPile(); | 108 pile->RerecordPile(); |
| 114 | 109 |
| 115 RasterSource::SolidColorAnalysis analysis; | 110 RasterSource::SolidColorAnalysis analysis; |
| 116 pile->PerformSolidColorAnalysis( | 111 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); |
| 117 gfx::Rect(0, 0, 10, 10), 0.1f, &analysis, nullptr); | |
| 118 EXPECT_FALSE(analysis.is_solid_color); | 112 EXPECT_FALSE(analysis.is_solid_color); |
| 119 | 113 |
| 120 pile->PerformSolidColorAnalysis( | 114 pile->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); |
| 121 gfx::Rect(10, 0, 10, 10), 0.1f, &analysis, nullptr); | |
| 122 EXPECT_TRUE(analysis.is_solid_color); | 115 EXPECT_TRUE(analysis.is_solid_color); |
| 123 EXPECT_EQ(analysis.solid_color, solid_color); | 116 EXPECT_EQ(analysis.solid_color, solid_color); |
| 124 | 117 |
| 125 // Boundaries should be clipped | 118 // Boundaries should be clipped |
| 126 analysis.is_solid_color = false; | 119 analysis.is_solid_color = false; |
| 127 pile->PerformSolidColorAnalysis( | 120 pile->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f, &analysis); |
| 128 gfx::Rect(35, 0, 10, 10), 0.1f, &analysis, nullptr); | |
| 129 EXPECT_TRUE(analysis.is_solid_color); | 121 EXPECT_TRUE(analysis.is_solid_color); |
| 130 EXPECT_EQ(analysis.solid_color, solid_color); | 122 EXPECT_EQ(analysis.solid_color, solid_color); |
| 131 | 123 |
| 132 analysis.is_solid_color = false; | 124 analysis.is_solid_color = false; |
| 133 pile->PerformSolidColorAnalysis( | 125 pile->PerformSolidColorAnalysis(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis); |
| 134 gfx::Rect(0, 35, 10, 10), 0.1f, &analysis, nullptr); | |
| 135 EXPECT_TRUE(analysis.is_solid_color); | 126 EXPECT_TRUE(analysis.is_solid_color); |
| 136 EXPECT_EQ(analysis.solid_color, solid_color); | 127 EXPECT_EQ(analysis.solid_color, solid_color); |
| 137 | 128 |
| 138 analysis.is_solid_color = false; | 129 analysis.is_solid_color = false; |
| 139 pile->PerformSolidColorAnalysis( | 130 pile->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis); |
| 140 gfx::Rect(35, 35, 10, 10), 0.1f, &analysis, nullptr); | |
| 141 EXPECT_TRUE(analysis.is_solid_color); | 131 EXPECT_TRUE(analysis.is_solid_color); |
| 142 EXPECT_EQ(analysis.solid_color, solid_color); | 132 EXPECT_EQ(analysis.solid_color, solid_color); |
| 143 } | 133 } |
| 144 | 134 |
| 145 TEST(PicturePileImplTest, AnalyzeIsSolidEmpty) { | 135 TEST(PicturePileImplTest, AnalyzeIsSolidEmpty) { |
| 146 gfx::Size tile_size(100, 100); | 136 gfx::Size tile_size(100, 100); |
| 147 gfx::Size layer_bounds(400, 400); | 137 gfx::Size layer_bounds(400, 400); |
| 148 | 138 |
| 149 scoped_refptr<FakePicturePileImpl> pile = | 139 scoped_refptr<FakePicturePileImpl> pile = |
| 150 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 140 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 151 RasterSource::SolidColorAnalysis analysis; | 141 RasterSource::SolidColorAnalysis analysis; |
| 152 EXPECT_FALSE(analysis.is_solid_color); | 142 EXPECT_FALSE(analysis.is_solid_color); |
| 153 | 143 |
| 154 pile->PerformSolidColorAnalysis( | 144 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &analysis); |
| 155 gfx::Rect(0, 0, 400, 400), 1.f, &analysis, nullptr); | |
| 156 | 145 |
| 157 EXPECT_TRUE(analysis.is_solid_color); | 146 EXPECT_TRUE(analysis.is_solid_color); |
| 158 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0)); | 147 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0)); |
| 159 } | 148 } |
| 160 | 149 |
| 161 TEST(PicturePileImplTest, PixelRefIteratorEmpty) { | 150 TEST(PicturePileImplTest, PixelRefIteratorEmpty) { |
| 162 gfx::Size tile_size(128, 128); | 151 gfx::Size tile_size(128, 128); |
| 163 gfx::Size layer_bounds(256, 256); | 152 gfx::Size layer_bounds(256, 256); |
| 164 | 153 |
| 165 // Create a filled pile with no recording. | 154 // Create a filled pile with no recording. |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 // up to one pixel outside the content rect is guaranteed to be opaque. | 678 // up to one pixel outside the content rect is guaranteed to be opaque. |
| 690 // Outside of that is undefined. | 679 // Outside of that is undefined. |
| 691 gfx::Rect canvas_rect(content_rect); | 680 gfx::Rect canvas_rect(content_rect); |
| 692 canvas_rect.Inset(0, 0, -1, -1); | 681 canvas_rect.Inset(0, 0, -1, -1); |
| 693 | 682 |
| 694 SkBitmap bitmap; | 683 SkBitmap bitmap; |
| 695 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | 684 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); |
| 696 SkCanvas canvas(bitmap); | 685 SkCanvas canvas(bitmap); |
| 697 canvas.clear(SK_ColorTRANSPARENT); | 686 canvas.clear(SK_ColorTRANSPARENT); |
| 698 | 687 |
| 699 FakeRenderingStatsInstrumentation rendering_stats_instrumentation; | 688 pile->PlaybackToCanvas(&canvas, canvas_rect, contents_scale); |
| 700 | |
| 701 pile->PlaybackToCanvas(&canvas, | |
| 702 canvas_rect, | |
| 703 contents_scale, | |
| 704 &rendering_stats_instrumentation); | |
| 705 | 689 |
| 706 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 690 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
| 707 int num_pixels = bitmap.width() * bitmap.height(); | 691 int num_pixels = bitmap.width() * bitmap.height(); |
| 708 bool all_white = true; | 692 bool all_white = true; |
| 709 for (int i = 0; i < num_pixels; ++i) { | 693 for (int i = 0; i < num_pixels; ++i) { |
| 710 EXPECT_EQ(SkColorGetA(pixels[i]), 255u); | 694 EXPECT_EQ(SkColorGetA(pixels[i]), 255u); |
| 711 all_white &= (SkColorGetR(pixels[i]) == 255); | 695 all_white &= (SkColorGetR(pixels[i]) == 255); |
| 712 all_white &= (SkColorGetG(pixels[i]) == 255); | 696 all_white &= (SkColorGetG(pixels[i]) == 255); |
| 713 all_white &= (SkColorGetB(pixels[i]) == 255); | 697 all_white &= (SkColorGetB(pixels[i]) == 255); |
| 714 } | 698 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 741 gfx::Size content_bounds( | 725 gfx::Size content_bounds( |
| 742 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 726 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
| 743 | 727 |
| 744 gfx::Rect canvas_rect(content_bounds); | 728 gfx::Rect canvas_rect(content_bounds); |
| 745 canvas_rect.Inset(0, 0, -1, -1); | 729 canvas_rect.Inset(0, 0, -1, -1); |
| 746 | 730 |
| 747 SkBitmap bitmap; | 731 SkBitmap bitmap; |
| 748 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | 732 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); |
| 749 SkCanvas canvas(bitmap); | 733 SkCanvas canvas(bitmap); |
| 750 | 734 |
| 751 FakeRenderingStatsInstrumentation rendering_stats_instrumentation; | 735 pile->PlaybackToCanvas(&canvas, canvas_rect, contents_scale); |
| 752 pile->PlaybackToCanvas( | |
| 753 &canvas, canvas_rect, contents_scale, &rendering_stats_instrumentation); | |
| 754 | 736 |
| 755 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 737 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
| 756 int num_pixels = bitmap.width() * bitmap.height(); | 738 int num_pixels = bitmap.width() * bitmap.height(); |
| 757 for (int i = 0; i < num_pixels; ++i) { | 739 for (int i = 0; i < num_pixels; ++i) { |
| 758 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); | 740 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); |
| 759 } | 741 } |
| 760 } | 742 } |
| 761 | 743 |
| 762 class OverlapTest : public ::testing::TestWithParam<float> { | 744 class OverlapTest : public ::testing::TestWithParam<float> { |
| 763 public: | 745 public: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 787 color_paint); | 769 color_paint); |
| 788 pile->RerecordPile(); | 770 pile->RerecordPile(); |
| 789 | 771 |
| 790 gfx::Size content_bounds( | 772 gfx::Size content_bounds( |
| 791 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 773 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
| 792 | 774 |
| 793 SkBitmap bitmap; | 775 SkBitmap bitmap; |
| 794 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | 776 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); |
| 795 SkCanvas canvas(bitmap); | 777 SkCanvas canvas(bitmap); |
| 796 | 778 |
| 797 FakeRenderingStatsInstrumentation rendering_stats_instrumentation; | 779 pile->PlaybackToCanvas(&canvas, gfx::Rect(content_bounds), contents_scale); |
| 798 pile->PlaybackToCanvas(&canvas, | |
| 799 gfx::Rect(content_bounds), | |
| 800 contents_scale, | |
| 801 &rendering_stats_instrumentation); | |
| 802 | 780 |
| 803 for (int y = 0; y < bitmap.height(); y++) { | 781 for (int y = 0; y < bitmap.height(); y++) { |
| 804 for (int x = 0; x < bitmap.width(); x++) { | 782 for (int x = 0; x < bitmap.width(); x++) { |
| 805 SkColor color = bitmap.getColor(x, y); | 783 SkColor color = bitmap.getColor(x, y); |
| 806 EXPECT_EQ(SkColorGetR(test_color), SkColorGetR(color)) << "x: " << x | 784 EXPECT_EQ(SkColorGetR(test_color), SkColorGetR(color)) << "x: " << x |
| 807 << ", y: " << y; | 785 << ", y: " << y; |
| 808 EXPECT_EQ(SkColorGetG(test_color), SkColorGetG(color)) << "x: " << x | 786 EXPECT_EQ(SkColorGetG(test_color), SkColorGetG(color)) << "x: " << x |
| 809 << ", y: " << y; | 787 << ", y: " << y; |
| 810 EXPECT_EQ(SkColorGetB(test_color), SkColorGetB(color)) << "x: " << x | 788 EXPECT_EQ(SkColorGetB(test_color), SkColorGetB(color)) << "x: " << x |
| 811 << ", y: " << y; | 789 << ", y: " << y; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 EXPECT_TRUE(iterator); | 872 EXPECT_TRUE(iterator); |
| 895 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); | 873 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); |
| 896 EXPECT_TRUE(++iterator); | 874 EXPECT_TRUE(++iterator); |
| 897 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); | 875 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); |
| 898 EXPECT_FALSE(++iterator); | 876 EXPECT_FALSE(++iterator); |
| 899 } | 877 } |
| 900 } | 878 } |
| 901 | 879 |
| 902 } // namespace | 880 } // namespace |
| 903 } // namespace cc | 881 } // namespace cc |
| OLD | NEW |