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 21 matching lines...) Expand all Loading... |
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 PicturePileImpl::Analysis 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 PicturePileImpl::Analysis 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 PicturePileImpl::Analysis 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 PicturePileImpl::Analysis 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 PicturePileImpl::Analysis 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 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |