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 "cc/resources/picture.h" | 5 #include "cc/resources/picture.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "cc/test/fake_content_layer_client.h" | 10 #include "cc/test/fake_content_layer_client.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // Check for equivalence. | 78 // Check for equivalence. |
79 unsigned char two_rect_buffer[4 * 100 * 100] = {0}; | 79 unsigned char two_rect_buffer[4 * 100 * 100] = {0}; |
80 DrawPicture(two_rect_buffer, layer_rect, two_rect_picture); | 80 DrawPicture(two_rect_buffer, layer_rect, two_rect_picture); |
81 unsigned char two_rect_buffer_check[4 * 100 * 100] = {0}; | 81 unsigned char two_rect_buffer_check[4 * 100 * 100] = {0}; |
82 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check); | 82 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check); |
83 | 83 |
84 EXPECT_EQ(two_rect_picture->LayerRect(), two_rect_picture_check->LayerRect()); | 84 EXPECT_EQ(two_rect_picture->LayerRect(), two_rect_picture_check->LayerRect()); |
85 EXPECT_EQ(0, memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100)); | 85 EXPECT_EQ(0, memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100)); |
86 } | 86 } |
87 | 87 |
88 TEST(PictureTest, PixelRefIterator) { | |
89 gfx::Rect layer_rect(2048, 2048); | |
90 | |
91 gfx::Size tile_grid_size(512, 512); | |
92 | |
93 FakeContentLayerClient content_layer_client; | |
94 | |
95 // Discardable pixel refs are found in the following grids: | |
96 // |---|---|---|---| | |
97 // | | x | | x | | |
98 // |---|---|---|---| | |
99 // | x | | x | | | |
100 // |---|---|---|---| | |
101 // | | x | | x | | |
102 // |---|---|---|---| | |
103 // | x | | x | | | |
104 // |---|---|---|---| | |
105 SkBitmap discardable_bitmap[4][4]; | |
106 for (int y = 0; y < 4; ++y) { | |
107 for (int x = 0; x < 4; ++x) { | |
108 if ((x + y) & 1) { | |
109 CreateBitmap( | |
110 gfx::Size(500, 500), "discardable", &discardable_bitmap[y][x]); | |
111 SkPaint paint; | |
112 content_layer_client.add_draw_bitmap( | |
113 discardable_bitmap[y][x], | |
114 gfx::Point(x * 512 + 6, y * 512 + 6), paint); | |
115 } | |
116 } | |
117 } | |
118 | |
119 scoped_refptr<Picture> picture = | |
120 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, | |
121 RecordingSource::RECORD_NORMALLY); | |
122 | |
123 // Default iterator does not have any pixel refs | |
124 { | |
125 Picture::PixelRefIterator iterator; | |
126 EXPECT_FALSE(iterator); | |
127 } | |
128 for (int y = 0; y < 4; ++y) { | |
129 for (int x = 0; x < 4; ++x) { | |
130 Picture::PixelRefIterator iterator(gfx::Rect(x * 512, y * 512, 500, 500), | |
131 picture.get()); | |
132 if ((x + y) & 1) { | |
133 EXPECT_TRUE(iterator) << x << " " << y; | |
134 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef()) << x << | |
135 " " << y; | |
136 EXPECT_FALSE(++iterator) << x << " " << y; | |
137 } else { | |
138 EXPECT_FALSE(iterator) << x << " " << y; | |
139 } | |
140 } | |
141 } | |
142 // Capture 4 pixel refs. | |
143 { | |
144 Picture::PixelRefIterator iterator(gfx::Rect(512, 512, 2048, 2048), | |
145 picture.get()); | |
146 EXPECT_TRUE(iterator); | |
147 EXPECT_TRUE(*iterator == discardable_bitmap[1][2].pixelRef()); | |
148 EXPECT_TRUE(++iterator); | |
149 EXPECT_TRUE(*iterator == discardable_bitmap[2][1].pixelRef()); | |
150 EXPECT_TRUE(++iterator); | |
151 EXPECT_TRUE(*iterator == discardable_bitmap[2][3].pixelRef()); | |
152 EXPECT_TRUE(++iterator); | |
153 EXPECT_TRUE(*iterator == discardable_bitmap[3][2].pixelRef()); | |
154 EXPECT_FALSE(++iterator); | |
155 } | |
156 | |
157 // Copy test. | |
158 Picture::PixelRefIterator iterator(gfx::Rect(512, 512, 2048, 2048), | |
159 picture.get()); | |
160 EXPECT_TRUE(iterator); | |
161 EXPECT_TRUE(*iterator == discardable_bitmap[1][2].pixelRef()); | |
162 EXPECT_TRUE(++iterator); | |
163 EXPECT_TRUE(*iterator == discardable_bitmap[2][1].pixelRef()); | |
164 | |
165 // copy now points to the same spot as iterator, | |
166 // but both can be incremented independently. | |
167 Picture::PixelRefIterator copy = iterator; | |
168 EXPECT_TRUE(++iterator); | |
169 EXPECT_TRUE(*iterator == discardable_bitmap[2][3].pixelRef()); | |
170 EXPECT_TRUE(++iterator); | |
171 EXPECT_TRUE(*iterator == discardable_bitmap[3][2].pixelRef()); | |
172 EXPECT_FALSE(++iterator); | |
173 | |
174 EXPECT_TRUE(copy); | |
175 EXPECT_TRUE(*copy == discardable_bitmap[2][1].pixelRef()); | |
176 EXPECT_TRUE(++copy); | |
177 EXPECT_TRUE(*copy == discardable_bitmap[2][3].pixelRef()); | |
178 EXPECT_TRUE(++copy); | |
179 EXPECT_TRUE(*copy == discardable_bitmap[3][2].pixelRef()); | |
180 EXPECT_FALSE(++copy); | |
181 } | |
182 | |
183 TEST(PictureTest, PixelRefIteratorNonZeroLayer) { | |
184 gfx::Rect layer_rect(1024, 0, 2048, 2048); | |
185 | |
186 gfx::Size tile_grid_size(512, 512); | |
187 | |
188 FakeContentLayerClient content_layer_client; | |
189 | |
190 // Discardable pixel refs are found in the following grids: | |
191 // |---|---|---|---| | |
192 // | | x | | x | | |
193 // |---|---|---|---| | |
194 // | x | | x | | | |
195 // |---|---|---|---| | |
196 // | | x | | x | | |
197 // |---|---|---|---| | |
198 // | x | | x | | | |
199 // |---|---|---|---| | |
200 SkBitmap discardable_bitmap[4][4]; | |
201 for (int y = 0; y < 4; ++y) { | |
202 for (int x = 0; x < 4; ++x) { | |
203 if ((x + y) & 1) { | |
204 CreateBitmap( | |
205 gfx::Size(500, 500), "discardable", &discardable_bitmap[y][x]); | |
206 SkPaint paint; | |
207 content_layer_client.add_draw_bitmap( | |
208 discardable_bitmap[y][x], | |
209 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); | |
210 } | |
211 } | |
212 } | |
213 | |
214 scoped_refptr<Picture> picture = | |
215 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, | |
216 RecordingSource::RECORD_NORMALLY); | |
217 | |
218 // Default iterator does not have any pixel refs | |
219 { | |
220 Picture::PixelRefIterator iterator; | |
221 EXPECT_FALSE(iterator); | |
222 } | |
223 for (int y = 0; y < 4; ++y) { | |
224 for (int x = 0; x < 4; ++x) { | |
225 Picture::PixelRefIterator iterator( | |
226 gfx::Rect(1024 + x * 512, y * 512, 500, 500), picture.get()); | |
227 if ((x + y) & 1) { | |
228 EXPECT_TRUE(iterator) << x << " " << y; | |
229 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef()); | |
230 EXPECT_FALSE(++iterator) << x << " " << y; | |
231 } else { | |
232 EXPECT_FALSE(iterator) << x << " " << y; | |
233 } | |
234 } | |
235 } | |
236 // Capture 4 pixel refs. | |
237 { | |
238 Picture::PixelRefIterator iterator(gfx::Rect(1024 + 512, 512, 2048, 2048), | |
239 picture.get()); | |
240 EXPECT_TRUE(iterator); | |
241 EXPECT_TRUE(*iterator == discardable_bitmap[1][2].pixelRef()); | |
242 EXPECT_TRUE(++iterator); | |
243 EXPECT_TRUE(*iterator == discardable_bitmap[2][1].pixelRef()); | |
244 EXPECT_TRUE(++iterator); | |
245 EXPECT_TRUE(*iterator == discardable_bitmap[2][3].pixelRef()); | |
246 EXPECT_TRUE(++iterator); | |
247 EXPECT_TRUE(*iterator == discardable_bitmap[3][2].pixelRef()); | |
248 EXPECT_FALSE(++iterator); | |
249 } | |
250 | |
251 // Copy test. | |
252 { | |
253 Picture::PixelRefIterator iterator(gfx::Rect(1024 + 512, 512, 2048, 2048), | |
254 picture.get()); | |
255 EXPECT_TRUE(iterator); | |
256 EXPECT_TRUE(*iterator == discardable_bitmap[1][2].pixelRef()); | |
257 EXPECT_TRUE(++iterator); | |
258 EXPECT_TRUE(*iterator == discardable_bitmap[2][1].pixelRef()); | |
259 | |
260 // copy now points to the same spot as iterator, | |
261 // but both can be incremented independently. | |
262 Picture::PixelRefIterator copy = iterator; | |
263 EXPECT_TRUE(++iterator); | |
264 EXPECT_TRUE(*iterator == discardable_bitmap[2][3].pixelRef()); | |
265 EXPECT_TRUE(++iterator); | |
266 EXPECT_TRUE(*iterator == discardable_bitmap[3][2].pixelRef()); | |
267 EXPECT_FALSE(++iterator); | |
268 | |
269 EXPECT_TRUE(copy); | |
270 EXPECT_TRUE(*copy == discardable_bitmap[2][1].pixelRef()); | |
271 EXPECT_TRUE(++copy); | |
272 EXPECT_TRUE(*copy == discardable_bitmap[2][3].pixelRef()); | |
273 EXPECT_TRUE(++copy); | |
274 EXPECT_TRUE(*copy == discardable_bitmap[3][2].pixelRef()); | |
275 EXPECT_FALSE(++copy); | |
276 } | |
277 | |
278 // Non intersecting rects | |
279 { | |
280 Picture::PixelRefIterator iterator(gfx::Rect(0, 0, 1000, 1000), | |
281 picture.get()); | |
282 EXPECT_FALSE(iterator); | |
283 } | |
284 { | |
285 Picture::PixelRefIterator iterator(gfx::Rect(3500, 0, 1000, 1000), | |
286 picture.get()); | |
287 EXPECT_FALSE(iterator); | |
288 } | |
289 { | |
290 Picture::PixelRefIterator iterator(gfx::Rect(0, 1100, 1000, 1000), | |
291 picture.get()); | |
292 EXPECT_FALSE(iterator); | |
293 } | |
294 { | |
295 Picture::PixelRefIterator iterator(gfx::Rect(3500, 1100, 1000, 1000), | |
296 picture.get()); | |
297 EXPECT_FALSE(iterator); | |
298 } | |
299 } | |
300 | |
301 TEST(PictureTest, PixelRefIteratorOnePixelQuery) { | |
302 gfx::Rect layer_rect(2048, 2048); | |
303 | |
304 gfx::Size tile_grid_size(512, 512); | |
305 | |
306 FakeContentLayerClient content_layer_client; | |
307 | |
308 // Discardable pixel refs are found in the following grids: | |
309 // |---|---|---|---| | |
310 // | | x | | x | | |
311 // |---|---|---|---| | |
312 // | x | | x | | | |
313 // |---|---|---|---| | |
314 // | | x | | x | | |
315 // |---|---|---|---| | |
316 // | x | | x | | | |
317 // |---|---|---|---| | |
318 SkBitmap discardable_bitmap[4][4]; | |
319 for (int y = 0; y < 4; ++y) { | |
320 for (int x = 0; x < 4; ++x) { | |
321 if ((x + y) & 1) { | |
322 CreateBitmap( | |
323 gfx::Size(500, 500), "discardable", &discardable_bitmap[y][x]); | |
324 SkPaint paint; | |
325 content_layer_client.add_draw_bitmap( | |
326 discardable_bitmap[y][x], | |
327 gfx::Point(x * 512 + 6, y * 512 + 6), paint); | |
328 } | |
329 } | |
330 } | |
331 | |
332 scoped_refptr<Picture> picture = | |
333 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, | |
334 RecordingSource::RECORD_NORMALLY); | |
335 | |
336 for (int y = 0; y < 4; ++y) { | |
337 for (int x = 0; x < 4; ++x) { | |
338 Picture::PixelRefIterator iterator( | |
339 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); | |
340 if ((x + y) & 1) { | |
341 EXPECT_TRUE(iterator) << x << " " << y; | |
342 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef()); | |
343 EXPECT_FALSE(++iterator) << x << " " << y; | |
344 } else { | |
345 EXPECT_FALSE(iterator) << x << " " << y; | |
346 } | |
347 } | |
348 } | |
349 } | |
350 | |
351 TEST(PictureTest, CreateFromSkpValue) { | 88 TEST(PictureTest, CreateFromSkpValue) { |
352 SkGraphics::Init(); | 89 SkGraphics::Init(); |
353 | 90 |
354 gfx::Rect layer_rect(100, 200); | 91 gfx::Rect layer_rect(100, 200); |
355 | 92 |
356 gfx::Size tile_grid_size(100, 200); | 93 gfx::Size tile_grid_size(100, 200); |
357 | 94 |
358 FakeContentLayerClient content_layer_client; | 95 FakeContentLayerClient content_layer_client; |
359 | 96 |
360 scoped_ptr<base::Value> tmp; | 97 scoped_ptr<base::Value> tmp; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 170 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
434 EXPECT_EQ(ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED, | 171 EXPECT_EQ(ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED, |
435 content_layer_client.last_painting_control()); | 172 content_layer_client.last_painting_control()); |
436 EXPECT_TRUE(picture.get()); | 173 EXPECT_TRUE(picture.get()); |
437 | 174 |
438 EXPECT_EQ(4, RecordingSource::RECORDING_MODE_COUNT); | 175 EXPECT_EQ(4, RecordingSource::RECORDING_MODE_COUNT); |
439 } | 176 } |
440 | 177 |
441 } // namespace | 178 } // namespace |
442 } // namespace cc | 179 } // namespace cc |
OLD | NEW |