roll libyuv to r1437 to resolve msan overread on odd width ARGBToYUY2.
[chromium-blink-merge.git] / cc / playback / recording_source_unittest.cc
blobf1506e32ec83aee50c7923603875218a249de0ca
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <vector>
7 #include "cc/playback/display_list_raster_source.h"
8 #include "cc/test/fake_display_list_recording_source.h"
9 #include "cc/test/fake_picture_pile.h"
10 #include "cc/test/fake_picture_pile_impl.h"
11 #include "cc/test/skia_common.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace cc {
15 namespace {
17 template <class T>
18 scoped_ptr<T> CreateRecordingSource(const gfx::Rect& viewport,
19 const gfx::Size& grid_cell_size);
21 template <>
22 scoped_ptr<FakePicturePile> CreateRecordingSource<FakePicturePile>(
23 const gfx::Rect& viewport,
24 const gfx::Size& grid_cell_size) {
25 return FakePicturePile::CreateFilledPile(grid_cell_size, viewport.size());
28 template <>
29 scoped_ptr<FakeDisplayListRecordingSource> CreateRecordingSource<
30 FakeDisplayListRecordingSource>(const gfx::Rect& viewport,
31 const gfx::Size& grid_cell_size) {
32 gfx::Rect layer_rect(viewport.right(), viewport.bottom());
33 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
34 FakeDisplayListRecordingSource::CreateRecordingSource(viewport,
35 layer_rect.size());
36 recording_source->SetGridCellSize(grid_cell_size);
38 return recording_source.Pass();
41 template <class T>
42 scoped_refptr<RasterSource> CreateRasterSource(T* recording_source);
44 template <>
45 scoped_refptr<RasterSource> CreateRasterSource(
46 FakePicturePile* recording_source) {
47 return FakePicturePileImpl::CreateFromPile(recording_source, nullptr);
50 template <>
51 scoped_refptr<RasterSource> CreateRasterSource(
52 FakeDisplayListRecordingSource* recording_source) {
53 bool can_use_lcd_text = true;
54 return DisplayListRasterSource::CreateFromDisplayListRecordingSource(
55 recording_source, can_use_lcd_text);
58 template <typename T>
59 class RecordingSourceTest : public testing::Test {};
61 using testing::Types;
63 typedef Types<FakePicturePile, FakeDisplayListRecordingSource>
64 RecordingSourceImplementations;
66 TYPED_TEST_CASE(RecordingSourceTest, RecordingSourceImplementations);
68 TYPED_TEST(RecordingSourceTest, NoGatherPixelRefEmptyPixelRefs) {
69 gfx::Size grid_cell_size(128, 128);
70 gfx::Rect recorded_viewport(0, 0, 256, 256);
72 scoped_ptr<TypeParam> recording_source =
73 CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size);
74 recording_source->SetGatherPixelRefs(false);
75 recording_source->Rerecord();
77 scoped_refptr<RasterSource> raster_source =
78 CreateRasterSource<TypeParam>(recording_source.get());
80 // If recording source do not gather pixel ref, raster source is not going to
81 // get pixel refs.
83 std::vector<SkPixelRef*> pixel_refs;
84 raster_source->GatherPixelRefs(recorded_viewport, 1.0, &pixel_refs);
85 EXPECT_TRUE(pixel_refs.empty());
89 TYPED_TEST(RecordingSourceTest, EmptyPixelRefs) {
90 gfx::Size grid_cell_size(128, 128);
91 gfx::Rect recorded_viewport(0, 0, 256, 256);
93 scoped_ptr<TypeParam> recording_source =
94 CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size);
95 recording_source->SetGatherPixelRefs(true);
96 recording_source->Rerecord();
98 scoped_refptr<RasterSource> raster_source =
99 CreateRasterSource<TypeParam>(recording_source.get());
101 // Tile sized iterators.
103 std::vector<SkPixelRef*> pixel_refs;
104 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 1.0, &pixel_refs);
105 EXPECT_TRUE(pixel_refs.empty());
108 std::vector<SkPixelRef*> pixel_refs;
109 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 2.0, &pixel_refs);
110 EXPECT_TRUE(pixel_refs.empty());
113 std::vector<SkPixelRef*> pixel_refs;
114 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 64, 64), 0.5, &pixel_refs);
115 EXPECT_TRUE(pixel_refs.empty());
117 // Shifted tile sized iterators.
119 std::vector<SkPixelRef*> pixel_refs;
120 raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), 1.0,
121 &pixel_refs);
122 EXPECT_TRUE(pixel_refs.empty());
125 std::vector<SkPixelRef*> pixel_refs;
126 raster_source->GatherPixelRefs(gfx::Rect(280, 280, 256, 256), 2.0,
127 &pixel_refs);
128 EXPECT_TRUE(pixel_refs.empty());
131 std::vector<SkPixelRef*> pixel_refs;
132 raster_source->GatherPixelRefs(gfx::Rect(70, 70, 64, 64), 0.5, &pixel_refs);
133 EXPECT_TRUE(pixel_refs.empty());
135 // Layer sized iterators.
137 std::vector<SkPixelRef*> pixel_refs;
138 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs);
139 EXPECT_TRUE(pixel_refs.empty());
142 std::vector<SkPixelRef*> pixel_refs;
143 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs);
144 EXPECT_TRUE(pixel_refs.empty());
147 std::vector<SkPixelRef*> pixel_refs;
148 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs);
149 EXPECT_TRUE(pixel_refs.empty());
153 TYPED_TEST(RecordingSourceTest, NoDiscardablePixelRefs) {
154 gfx::Size grid_cell_size(128, 128);
155 gfx::Rect recorded_viewport(0, 0, 256, 256);
157 scoped_ptr<TypeParam> recording_source =
158 CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size);
160 SkPaint simple_paint;
161 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34));
163 SkBitmap non_discardable_bitmap;
164 CreateBitmap(gfx::Size(128, 128), "notdiscardable", &non_discardable_bitmap);
166 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256),
167 simple_paint);
168 recording_source->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512),
169 simple_paint);
170 recording_source->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256),
171 simple_paint);
172 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256),
173 simple_paint);
174 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(128, 0));
175 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 128));
176 recording_source->add_draw_bitmap(non_discardable_bitmap,
177 gfx::Point(150, 150));
178 recording_source->SetGatherPixelRefs(true);
179 recording_source->Rerecord();
181 scoped_refptr<RasterSource> raster_source =
182 CreateRasterSource<TypeParam>(recording_source.get());
184 // Tile sized iterators.
186 std::vector<SkPixelRef*> pixel_refs;
187 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 1.0, &pixel_refs);
188 EXPECT_TRUE(pixel_refs.empty());
191 std::vector<SkPixelRef*> pixel_refs;
192 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 2.0, &pixel_refs);
193 EXPECT_TRUE(pixel_refs.empty());
196 std::vector<SkPixelRef*> pixel_refs;
197 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 64, 64), 0.5, &pixel_refs);
198 EXPECT_TRUE(pixel_refs.empty());
200 // Shifted tile sized iterators.
202 std::vector<SkPixelRef*> pixel_refs;
203 raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), 1.0,
204 &pixel_refs);
205 EXPECT_TRUE(pixel_refs.empty());
208 std::vector<SkPixelRef*> pixel_refs;
209 raster_source->GatherPixelRefs(gfx::Rect(280, 280, 256, 256), 2.0,
210 &pixel_refs);
211 EXPECT_TRUE(pixel_refs.empty());
214 std::vector<SkPixelRef*> pixel_refs;
215 raster_source->GatherPixelRefs(gfx::Rect(70, 70, 64, 64), 0.5, &pixel_refs);
216 EXPECT_TRUE(pixel_refs.empty());
218 // Layer sized iterators.
220 std::vector<SkPixelRef*> pixel_refs;
221 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs);
222 EXPECT_TRUE(pixel_refs.empty());
225 std::vector<SkPixelRef*> pixel_refs;
226 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs);
227 EXPECT_TRUE(pixel_refs.empty());
230 std::vector<SkPixelRef*> pixel_refs;
231 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs);
232 EXPECT_TRUE(pixel_refs.empty());
236 TYPED_TEST(RecordingSourceTest, DiscardablePixelRefs) {
237 gfx::Size grid_cell_size(128, 128);
238 gfx::Rect recorded_viewport(0, 0, 256, 256);
240 scoped_ptr<TypeParam> recording_source =
241 CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size);
243 SkBitmap discardable_bitmap[2][2];
244 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]);
245 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][0]);
246 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]);
248 // Discardable pixel refs are found in the following cells:
249 // |---|---|
250 // | x | |
251 // |---|---|
252 // | x | x |
253 // |---|---|
254 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0));
255 recording_source->add_draw_bitmap(discardable_bitmap[1][0],
256 gfx::Point(0, 130));
257 recording_source->add_draw_bitmap(discardable_bitmap[1][1],
258 gfx::Point(140, 140));
259 recording_source->SetGatherPixelRefs(true);
260 recording_source->Rerecord();
262 scoped_refptr<RasterSource> raster_source =
263 CreateRasterSource<TypeParam>(recording_source.get());
265 // Tile sized iterators. These should find only one pixel ref.
267 std::vector<SkPixelRef*> pixel_refs;
268 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 1.0, &pixel_refs);
269 EXPECT_FALSE(pixel_refs.empty());
270 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
271 EXPECT_EQ(1u, pixel_refs.size());
274 std::vector<SkPixelRef*> pixel_refs;
275 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 2.0, &pixel_refs);
276 EXPECT_FALSE(pixel_refs.empty());
277 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
278 EXPECT_EQ(1u, pixel_refs.size());
281 std::vector<SkPixelRef*> pixel_refs;
282 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 64, 64), 0.5, &pixel_refs);
283 EXPECT_FALSE(pixel_refs.empty());
284 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
285 EXPECT_EQ(1u, pixel_refs.size());
288 // Shifted tile sized iterators. These should find only one pixel ref.
290 std::vector<SkPixelRef*> pixel_refs;
291 raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), 1.0,
292 &pixel_refs);
293 EXPECT_FALSE(pixel_refs.empty());
294 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
295 EXPECT_EQ(1u, pixel_refs.size());
298 std::vector<SkPixelRef*> pixel_refs;
299 raster_source->GatherPixelRefs(gfx::Rect(280, 280, 256, 256), 2.0,
300 &pixel_refs);
301 EXPECT_FALSE(pixel_refs.empty());
302 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
303 EXPECT_EQ(1u, pixel_refs.size());
306 std::vector<SkPixelRef*> pixel_refs;
307 raster_source->GatherPixelRefs(gfx::Rect(70, 70, 64, 64), 0.5, &pixel_refs);
308 EXPECT_FALSE(pixel_refs.empty());
309 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
310 EXPECT_EQ(1u, pixel_refs.size());
313 // Ensure there's no discardable pixel refs in the empty cell
315 std::vector<SkPixelRef*> pixel_refs;
316 raster_source->GatherPixelRefs(gfx::Rect(140, 0, 128, 128), 1.0,
317 &pixel_refs);
318 EXPECT_TRUE(pixel_refs.empty());
321 // Layer sized iterators. These should find all 3 pixel refs.
323 std::vector<SkPixelRef*> pixel_refs;
324 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs);
325 EXPECT_FALSE(pixel_refs.empty());
326 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
327 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][0].pixelRef());
328 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
329 EXPECT_EQ(3u, pixel_refs.size());
332 std::vector<SkPixelRef*> pixel_refs;
333 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs);
334 EXPECT_FALSE(pixel_refs.empty());
335 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
336 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][0].pixelRef());
337 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
338 EXPECT_EQ(3u, pixel_refs.size());
341 std::vector<SkPixelRef*> pixel_refs;
342 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs);
343 EXPECT_FALSE(pixel_refs.empty());
344 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
345 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][0].pixelRef());
346 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
347 EXPECT_EQ(3u, pixel_refs.size());
351 TYPED_TEST(RecordingSourceTest, DiscardablePixelRefsBaseNonDiscardable) {
352 gfx::Size grid_cell_size(256, 256);
353 gfx::Rect recorded_viewport(0, 0, 512, 512);
355 scoped_ptr<TypeParam> recording_source =
356 CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size);
358 SkBitmap non_discardable_bitmap;
359 CreateBitmap(gfx::Size(512, 512), "notdiscardable", &non_discardable_bitmap);
361 SkBitmap discardable_bitmap[2][2];
362 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][0]);
363 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][1]);
364 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[1][1]);
366 // One large non-discardable bitmap covers the whole grid.
367 // Discardable pixel refs are found in the following cells:
368 // |---|---|
369 // | x | x |
370 // |---|---|
371 // | | x |
372 // |---|---|
373 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 0));
374 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0));
375 recording_source->add_draw_bitmap(discardable_bitmap[0][1],
376 gfx::Point(260, 0));
377 recording_source->add_draw_bitmap(discardable_bitmap[1][1],
378 gfx::Point(260, 260));
379 recording_source->SetGatherPixelRefs(true);
380 recording_source->Rerecord();
382 scoped_refptr<RasterSource> raster_source =
383 CreateRasterSource<TypeParam>(recording_source.get());
385 // Tile sized iterators. These should find only one pixel ref.
387 std::vector<SkPixelRef*> pixel_refs;
388 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs);
389 EXPECT_FALSE(pixel_refs.empty());
390 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
391 EXPECT_EQ(1u, pixel_refs.size());
394 std::vector<SkPixelRef*> pixel_refs;
395 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs);
396 EXPECT_FALSE(pixel_refs.empty());
397 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
398 EXPECT_EQ(1u, pixel_refs.size());
401 std::vector<SkPixelRef*> pixel_refs;
402 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs);
403 EXPECT_FALSE(pixel_refs.empty());
404 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
405 EXPECT_EQ(1u, pixel_refs.size());
407 // Shifted tile sized iterators. These should find only one pixel ref.
409 std::vector<SkPixelRef*> pixel_refs;
410 raster_source->GatherPixelRefs(gfx::Rect(260, 260, 256, 256), 1.0,
411 &pixel_refs);
412 EXPECT_FALSE(pixel_refs.empty());
413 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
414 EXPECT_EQ(1u, pixel_refs.size());
417 std::vector<SkPixelRef*> pixel_refs;
418 raster_source->GatherPixelRefs(gfx::Rect(520, 520, 512, 512), 2.0,
419 &pixel_refs);
420 EXPECT_FALSE(pixel_refs.empty());
421 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
422 EXPECT_EQ(1u, pixel_refs.size());
425 std::vector<SkPixelRef*> pixel_refs;
426 raster_source->GatherPixelRefs(gfx::Rect(130, 130, 128, 128), 0.5,
427 &pixel_refs);
428 EXPECT_FALSE(pixel_refs.empty());
429 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
430 EXPECT_EQ(1u, pixel_refs.size());
432 // Ensure there's no discardable pixel refs in the empty cell
434 std::vector<SkPixelRef*> pixel_refs;
435 raster_source->GatherPixelRefs(gfx::Rect(0, 256, 256, 256), 1.0,
436 &pixel_refs);
437 EXPECT_TRUE(pixel_refs.empty());
439 // Layer sized iterators. These should find three pixel ref.
441 std::vector<SkPixelRef*> pixel_refs;
442 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 1.0, &pixel_refs);
443 EXPECT_FALSE(pixel_refs.empty());
444 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
445 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[0][1].pixelRef());
446 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
447 EXPECT_EQ(3u, pixel_refs.size());
450 std::vector<SkPixelRef*> pixel_refs;
451 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 1024, 1024), 2.0,
452 &pixel_refs);
453 EXPECT_FALSE(pixel_refs.empty());
454 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
455 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[0][1].pixelRef());
456 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
457 EXPECT_EQ(3u, pixel_refs.size());
460 std::vector<SkPixelRef*> pixel_refs;
461 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 0.5, &pixel_refs);
462 EXPECT_FALSE(pixel_refs.empty());
463 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
464 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[0][1].pixelRef());
465 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
466 EXPECT_EQ(3u, pixel_refs.size());
470 } // namespace
471 } // namespace cc