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