Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: cc/resources/picture_pile_impl_unittest.cc

Issue 666273002: cc: Added raster source. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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->AnalyzeInRect(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->AnalyzeInRect(gfx::Rect(0, 0, 100, 100), 1.0, &analysis, nullptr);
54 EXPECT_FALSE(analysis.is_solid_color); 54 EXPECT_FALSE(analysis.is_solid_color);
55 55
56 pile->AnalyzeInRect(gfx::Rect(100, 0, 100, 100), 1.0, &analysis); 56 pile->AnalyzeInRect(gfx::Rect(100, 0, 100, 100), 1.0, &analysis, nullptr);
57 EXPECT_TRUE(analysis.is_solid_color); 57 EXPECT_TRUE(analysis.is_solid_color);
58 EXPECT_EQ(analysis.solid_color, solid_color); 58 EXPECT_EQ(analysis.solid_color, solid_color);
59 59
60 // Boundaries should be clipped 60 // Boundaries should be clipped
61 analysis.is_solid_color = false; 61 analysis.is_solid_color = false;
62 pile->AnalyzeInRect(gfx::Rect(350, 0, 100, 100), 1.0, &analysis); 62 pile->AnalyzeInRect(gfx::Rect(350, 0, 100, 100), 1.0, &analysis, nullptr);
63 EXPECT_TRUE(analysis.is_solid_color); 63 EXPECT_TRUE(analysis.is_solid_color);
64 EXPECT_EQ(analysis.solid_color, solid_color); 64 EXPECT_EQ(analysis.solid_color, solid_color);
65 65
66 analysis.is_solid_color = false; 66 analysis.is_solid_color = false;
67 pile->AnalyzeInRect(gfx::Rect(0, 350, 100, 100), 1.0, &analysis); 67 pile->AnalyzeInRect(gfx::Rect(0, 350, 100, 100), 1.0, &analysis, nullptr);
68 EXPECT_TRUE(analysis.is_solid_color); 68 EXPECT_TRUE(analysis.is_solid_color);
69 EXPECT_EQ(analysis.solid_color, solid_color); 69 EXPECT_EQ(analysis.solid_color, solid_color);
70 70
71 analysis.is_solid_color = false; 71 analysis.is_solid_color = false;
72 pile->AnalyzeInRect(gfx::Rect(350, 350, 100, 100), 1.0, &analysis); 72 pile->AnalyzeInRect(gfx::Rect(350, 350, 100, 100), 1.0, &analysis, nullptr);
73 EXPECT_TRUE(analysis.is_solid_color); 73 EXPECT_TRUE(analysis.is_solid_color);
74 EXPECT_EQ(analysis.solid_color, solid_color); 74 EXPECT_EQ(analysis.solid_color, solid_color);
75 } 75 }
76 76
77 TEST(PicturePileImplTest, AnalyzeIsSolidScaled) { 77 TEST(PicturePileImplTest, AnalyzeIsSolidScaled) {
78 gfx::Size tile_size(100, 100); 78 gfx::Size tile_size(100, 100);
79 gfx::Size layer_bounds(400, 400); 79 gfx::Size layer_bounds(400, 400);
80 80
81 scoped_refptr<FakePicturePileImpl> pile = 81 scoped_refptr<FakePicturePileImpl> pile =
82 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 82 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
83 83
84 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); 84 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
85 SkPaint solid_paint; 85 SkPaint solid_paint;
86 solid_paint.setColor(solid_color); 86 solid_paint.setColor(solid_color);
87 87
88 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); 88 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
89 SkPaint non_solid_paint; 89 SkPaint non_solid_paint;
90 non_solid_paint.setColor(non_solid_color); 90 non_solid_paint.setColor(non_solid_color);
91 91
92 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);
93 pile->RerecordPile(); 93 pile->RerecordPile();
94 94
95 // Ensure everything is solid 95 // Ensure everything is solid
96 for (int y = 0; y <= 30; y += 10) { 96 for (int y = 0; y <= 30; y += 10) {
97 for (int x = 0; x <= 30; x += 10) { 97 for (int x = 0; x <= 30; x += 10) {
98 PicturePileImpl::Analysis analysis; 98 RasterSource::SolidColorAnalysis analysis;
99 gfx::Rect rect(x, y, 10, 10); 99 gfx::Rect rect(x, y, 10, 10);
100 pile->AnalyzeInRect(rect, 0.1f, &analysis); 100 pile->AnalyzeInRect(rect, 0.1f, &analysis, nullptr);
101 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); 101 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString();
102 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); 102 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString();
103 } 103 }
104 } 104 }
105 105
106 // One pixel non solid 106 // One pixel non solid
107 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);
108 pile->RerecordPile(); 108 pile->RerecordPile();
109 109
110 PicturePileImpl::Analysis analysis; 110 RasterSource::SolidColorAnalysis analysis;
111 pile->AnalyzeInRect(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); 111 pile->AnalyzeInRect(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis, nullptr);
112 EXPECT_FALSE(analysis.is_solid_color); 112 EXPECT_FALSE(analysis.is_solid_color);
113 113
114 pile->AnalyzeInRect(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); 114 pile->AnalyzeInRect(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis, nullptr);
115 EXPECT_TRUE(analysis.is_solid_color); 115 EXPECT_TRUE(analysis.is_solid_color);
116 EXPECT_EQ(analysis.solid_color, solid_color); 116 EXPECT_EQ(analysis.solid_color, solid_color);
117 117
118 // Boundaries should be clipped 118 // Boundaries should be clipped
119 analysis.is_solid_color = false; 119 analysis.is_solid_color = false;
120 pile->AnalyzeInRect(gfx::Rect(35, 0, 10, 10), 0.1f, &analysis); 120 pile->AnalyzeInRect(gfx::Rect(35, 0, 10, 10), 0.1f, &analysis, nullptr);
121 EXPECT_TRUE(analysis.is_solid_color); 121 EXPECT_TRUE(analysis.is_solid_color);
122 EXPECT_EQ(analysis.solid_color, solid_color); 122 EXPECT_EQ(analysis.solid_color, solid_color);
123 123
124 analysis.is_solid_color = false; 124 analysis.is_solid_color = false;
125 pile->AnalyzeInRect(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis); 125 pile->AnalyzeInRect(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis, nullptr);
126 EXPECT_TRUE(analysis.is_solid_color); 126 EXPECT_TRUE(analysis.is_solid_color);
127 EXPECT_EQ(analysis.solid_color, solid_color); 127 EXPECT_EQ(analysis.solid_color, solid_color);
128 128
129 analysis.is_solid_color = false; 129 analysis.is_solid_color = false;
130 pile->AnalyzeInRect(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis); 130 pile->AnalyzeInRect(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis, nullptr);
131 EXPECT_TRUE(analysis.is_solid_color); 131 EXPECT_TRUE(analysis.is_solid_color);
132 EXPECT_EQ(analysis.solid_color, solid_color); 132 EXPECT_EQ(analysis.solid_color, solid_color);
133 } 133 }
134 134
135 TEST(PicturePileImplTest, AnalyzeIsSolidEmpty) { 135 TEST(PicturePileImplTest, AnalyzeIsSolidEmpty) {
136 gfx::Size tile_size(100, 100); 136 gfx::Size tile_size(100, 100);
137 gfx::Size layer_bounds(400, 400); 137 gfx::Size layer_bounds(400, 400);
138 138
139 scoped_refptr<FakePicturePileImpl> pile = 139 scoped_refptr<FakePicturePileImpl> pile =
140 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 140 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
141 PicturePileImpl::Analysis analysis; 141 RasterSource::SolidColorAnalysis analysis;
142 EXPECT_FALSE(analysis.is_solid_color); 142 EXPECT_FALSE(analysis.is_solid_color);
143 143
144 pile->AnalyzeInRect(gfx::Rect(0, 0, 400, 400), 1.f, &analysis); 144 pile->AnalyzeInRect(gfx::Rect(0, 0, 400, 400), 1.f, &analysis, nullptr);
145 145
146 EXPECT_TRUE(analysis.is_solid_color); 146 EXPECT_TRUE(analysis.is_solid_color);
147 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0)); 147 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0));
148 } 148 }
149 149
150 TEST(PicturePileImplTest, PixelRefIteratorEmpty) { 150 TEST(PicturePileImplTest, PixelRefIteratorEmpty) {
151 gfx::Size tile_size(128, 128); 151 gfx::Size tile_size(128, 128);
152 gfx::Size layer_bounds(256, 256); 152 gfx::Size layer_bounds(256, 256);
153 153
154 // Create a filled pile with no recording. 154 // Create a filled pile with no recording.
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 gfx::Rect canvas_rect(content_rect); 680 gfx::Rect canvas_rect(content_rect);
681 canvas_rect.Inset(0, 0, -1, -1); 681 canvas_rect.Inset(0, 0, -1, -1);
682 682
683 SkBitmap bitmap; 683 SkBitmap bitmap;
684 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); 684 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height());
685 SkCanvas canvas(bitmap); 685 SkCanvas canvas(bitmap);
686 canvas.clear(SK_ColorTRANSPARENT); 686 canvas.clear(SK_ColorTRANSPARENT);
687 687
688 FakeRenderingStatsInstrumentation rendering_stats_instrumentation; 688 FakeRenderingStatsInstrumentation rendering_stats_instrumentation;
689 689
690 pile->RasterToBitmap(&canvas, 690 pile->PlaybackToCanvas(&canvas,
691 canvas_rect, 691 canvas_rect,
692 contents_scale, 692 contents_scale,
693 &rendering_stats_instrumentation); 693 &rendering_stats_instrumentation);
694 694
695 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); 695 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
696 int num_pixels = bitmap.width() * bitmap.height(); 696 int num_pixels = bitmap.width() * bitmap.height();
697 bool all_white = true; 697 bool all_white = true;
698 for (int i = 0; i < num_pixels; ++i) { 698 for (int i = 0; i < num_pixels; ++i) {
699 EXPECT_EQ(SkColorGetA(pixels[i]), 255u); 699 EXPECT_EQ(SkColorGetA(pixels[i]), 255u);
700 all_white &= (SkColorGetR(pixels[i]) == 255); 700 all_white &= (SkColorGetR(pixels[i]) == 255);
701 all_white &= (SkColorGetG(pixels[i]) == 255); 701 all_white &= (SkColorGetG(pixels[i]) == 255);
702 all_white &= (SkColorGetB(pixels[i]) == 255); 702 all_white &= (SkColorGetB(pixels[i]) == 255);
703 } 703 }
(...skipping 27 matching lines...) Expand all
731 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); 731 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
732 732
733 gfx::Rect canvas_rect(content_bounds); 733 gfx::Rect canvas_rect(content_bounds);
734 canvas_rect.Inset(0, 0, -1, -1); 734 canvas_rect.Inset(0, 0, -1, -1);
735 735
736 SkBitmap bitmap; 736 SkBitmap bitmap;
737 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); 737 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height());
738 SkCanvas canvas(bitmap); 738 SkCanvas canvas(bitmap);
739 739
740 FakeRenderingStatsInstrumentation rendering_stats_instrumentation; 740 FakeRenderingStatsInstrumentation rendering_stats_instrumentation;
741 pile->RasterToBitmap( 741 pile->PlaybackToCanvas(
742 &canvas, canvas_rect, contents_scale, &rendering_stats_instrumentation); 742 &canvas, canvas_rect, contents_scale, &rendering_stats_instrumentation);
743 743
744 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); 744 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
745 int num_pixels = bitmap.width() * bitmap.height(); 745 int num_pixels = bitmap.width() * bitmap.height();
746 for (int i = 0; i < num_pixels; ++i) { 746 for (int i = 0; i < num_pixels; ++i) {
747 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); 747 EXPECT_EQ(SkColorGetA(pixels[i]), 0u);
748 } 748 }
749 } 749 }
750 750
751 class OverlapTest : public ::testing::TestWithParam<float> { 751 class OverlapTest : public ::testing::TestWithParam<float> {
(...skipping 25 matching lines...) Expand all
777 pile->RerecordPile(); 777 pile->RerecordPile();
778 778
779 gfx::Size content_bounds( 779 gfx::Size content_bounds(
780 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); 780 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
781 781
782 SkBitmap bitmap; 782 SkBitmap bitmap;
783 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); 783 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height());
784 SkCanvas canvas(bitmap); 784 SkCanvas canvas(bitmap);
785 785
786 FakeRenderingStatsInstrumentation rendering_stats_instrumentation; 786 FakeRenderingStatsInstrumentation rendering_stats_instrumentation;
787 pile->RasterToBitmap(&canvas, 787 pile->PlaybackToCanvas(&canvas,
788 gfx::Rect(content_bounds), 788 gfx::Rect(content_bounds),
789 contents_scale, 789 contents_scale,
790 &rendering_stats_instrumentation); 790 &rendering_stats_instrumentation);
791 791
792 for (int y = 0; y < bitmap.height(); y++) { 792 for (int y = 0; y < bitmap.height(); y++) {
793 for (int x = 0; x < bitmap.width(); x++) { 793 for (int x = 0; x < bitmap.width(); x++) {
794 SkColor color = bitmap.getColor(x, y); 794 SkColor color = bitmap.getColor(x, y);
795 EXPECT_EQ(SkColorGetR(test_color), SkColorGetR(color)) << "x: " << x 795 EXPECT_EQ(SkColorGetR(test_color), SkColorGetR(color)) << "x: " << x
796 << ", y: " << y; 796 << ", y: " << y;
797 EXPECT_EQ(SkColorGetG(test_color), SkColorGetG(color)) << "x: " << x 797 EXPECT_EQ(SkColorGetG(test_color), SkColorGetG(color)) << "x: " << x
798 << ", y: " << y; 798 << ", y: " << y;
799 EXPECT_EQ(SkColorGetB(test_color), SkColorGetB(color)) << "x: " << x 799 EXPECT_EQ(SkColorGetB(test_color), SkColorGetB(color)) << "x: " << x
800 << ", y: " << y; 800 << ", y: " << y;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 EXPECT_TRUE(iterator); 883 EXPECT_TRUE(iterator);
884 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); 884 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef());
885 EXPECT_TRUE(++iterator); 885 EXPECT_TRUE(++iterator);
886 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); 886 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef());
887 EXPECT_FALSE(++iterator); 887 EXPECT_FALSE(++iterator);
888 } 888 }
889 } 889 }
890 890
891 } // namespace 891 } // namespace
892 } // namespace cc 892 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698