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

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

Issue 1050103003: Revert of Revert of Implement DisplayList GatherPixelRefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months 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
« no previous file with comments | « cc/resources/pixel_ref_map.cc ('k') | cc/test/fake_content_layer_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include <vector>
6
7 #include "cc/resources/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/impl_side_painting_settings.h"
12 #include "cc/test/skia_common.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace cc {
16 namespace {
17
18 template <class T>
19 scoped_ptr<T> CreateRecordingSource(const gfx::Rect& viewport,
20 const gfx::Size& grid_cell_size);
21
22 template <>
23 scoped_ptr<FakePicturePile> CreateRecordingSource<FakePicturePile>(
24 const gfx::Rect& viewport,
25 const gfx::Size& grid_cell_size) {
26 return FakePicturePile::CreateFilledPile(grid_cell_size, viewport.size());
27 }
28
29 template <>
30 scoped_ptr<FakeDisplayListRecordingSource> CreateRecordingSource<
31 FakeDisplayListRecordingSource>(const gfx::Rect& viewport,
32 const gfx::Size& grid_cell_size) {
33 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
34 FakeDisplayListRecordingSource::CreateRecordingSource(viewport);
35 recording_source->SetGridCellSize(grid_cell_size);
36
37 return recording_source.Pass();
38 }
39
40 template <class T>
41 scoped_refptr<RasterSource> CreateRasterSource(T* recording_source);
42
43 template <>
44 scoped_refptr<RasterSource> CreateRasterSource(
45 FakePicturePile* recording_source) {
46 return FakePicturePileImpl::CreateFromPile(recording_source, nullptr);
47 }
48
49 template <>
50 scoped_refptr<RasterSource> CreateRasterSource(
51 FakeDisplayListRecordingSource* recording_source) {
52 bool can_use_lcd_text = true;
53 return DisplayListRasterSource::CreateFromDisplayListRecordingSource(
54 recording_source, can_use_lcd_text);
55 }
56
57 template <typename T>
58 class RecordingSourceTest : public testing::Test {};
59
60 using testing::Types;
61
62 typedef Types<FakePicturePile, FakeDisplayListRecordingSource>
63 RecordingSourceImplementations;
64
65 TYPED_TEST_CASE(RecordingSourceTest, RecordingSourceImplementations);
66
67 TYPED_TEST(RecordingSourceTest, EmptyPixelRefs) {
68 gfx::Size grid_cell_size(128, 128);
69 gfx::Rect recorded_viewport(0, 0, 256, 256);
70
71 scoped_ptr<TypeParam> recording_source =
72 CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size);
73 recording_source->Rerecord();
74
75 scoped_refptr<RasterSource> raster_source =
76 CreateRasterSource<TypeParam>(recording_source.get());
77
78 // Tile sized iterators.
79 {
80 std::vector<SkPixelRef*> pixel_refs;
81 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 1.0, &pixel_refs);
82 EXPECT_TRUE(pixel_refs.empty());
83 }
84 {
85 std::vector<SkPixelRef*> pixel_refs;
86 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 2.0, &pixel_refs);
87 EXPECT_TRUE(pixel_refs.empty());
88 }
89 {
90 std::vector<SkPixelRef*> pixel_refs;
91 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 64, 64), 0.5, &pixel_refs);
92 EXPECT_TRUE(pixel_refs.empty());
93 }
94 // Shifted tile sized iterators.
95 {
96 std::vector<SkPixelRef*> pixel_refs;
97 raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), 1.0,
98 &pixel_refs);
99 EXPECT_TRUE(pixel_refs.empty());
100 }
101 {
102 std::vector<SkPixelRef*> pixel_refs;
103 raster_source->GatherPixelRefs(gfx::Rect(280, 280, 256, 256), 2.0,
104 &pixel_refs);
105 EXPECT_TRUE(pixel_refs.empty());
106 }
107 {
108 std::vector<SkPixelRef*> pixel_refs;
109 raster_source->GatherPixelRefs(gfx::Rect(70, 70, 64, 64), 0.5, &pixel_refs);
110 EXPECT_TRUE(pixel_refs.empty());
111 }
112 // Layer sized iterators.
113 {
114 std::vector<SkPixelRef*> pixel_refs;
115 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs);
116 EXPECT_TRUE(pixel_refs.empty());
117 }
118 {
119 std::vector<SkPixelRef*> pixel_refs;
120 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs);
121 EXPECT_TRUE(pixel_refs.empty());
122 }
123 {
124 std::vector<SkPixelRef*> pixel_refs;
125 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs);
126 EXPECT_TRUE(pixel_refs.empty());
127 }
128 }
129
130 TYPED_TEST(RecordingSourceTest, NoDiscardablePixelRefs) {
131 gfx::Size grid_cell_size(128, 128);
132 gfx::Rect recorded_viewport(0, 0, 256, 256);
133
134 scoped_ptr<TypeParam> recording_source =
135 CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size);
136
137 SkPaint simple_paint;
138 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34));
139
140 SkBitmap non_discardable_bitmap;
141 CreateBitmap(gfx::Size(128, 128), "notdiscardable", &non_discardable_bitmap);
142
143 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256),
144 simple_paint);
145 recording_source->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512),
146 simple_paint);
147 recording_source->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256),
148 simple_paint);
149 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256),
150 simple_paint);
151 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(128, 0));
152 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 128));
153 recording_source->add_draw_bitmap(non_discardable_bitmap,
154 gfx::Point(150, 150));
155 recording_source->Rerecord();
156
157 scoped_refptr<RasterSource> raster_source =
158 CreateRasterSource<TypeParam>(recording_source.get());
159
160 // Tile sized iterators.
161 {
162 std::vector<SkPixelRef*> pixel_refs;
163 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 1.0, &pixel_refs);
164 EXPECT_TRUE(pixel_refs.empty());
165 }
166 {
167 std::vector<SkPixelRef*> pixel_refs;
168 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 2.0, &pixel_refs);
169 EXPECT_TRUE(pixel_refs.empty());
170 }
171 {
172 std::vector<SkPixelRef*> pixel_refs;
173 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 64, 64), 0.5, &pixel_refs);
174 EXPECT_TRUE(pixel_refs.empty());
175 }
176 // Shifted tile sized iterators.
177 {
178 std::vector<SkPixelRef*> pixel_refs;
179 raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), 1.0,
180 &pixel_refs);
181 EXPECT_TRUE(pixel_refs.empty());
182 }
183 {
184 std::vector<SkPixelRef*> pixel_refs;
185 raster_source->GatherPixelRefs(gfx::Rect(280, 280, 256, 256), 2.0,
186 &pixel_refs);
187 EXPECT_TRUE(pixel_refs.empty());
188 }
189 {
190 std::vector<SkPixelRef*> pixel_refs;
191 raster_source->GatherPixelRefs(gfx::Rect(70, 70, 64, 64), 0.5, &pixel_refs);
192 EXPECT_TRUE(pixel_refs.empty());
193 }
194 // Layer sized iterators.
195 {
196 std::vector<SkPixelRef*> pixel_refs;
197 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs);
198 EXPECT_TRUE(pixel_refs.empty());
199 }
200 {
201 std::vector<SkPixelRef*> pixel_refs;
202 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs);
203 EXPECT_TRUE(pixel_refs.empty());
204 }
205 {
206 std::vector<SkPixelRef*> pixel_refs;
207 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs);
208 EXPECT_TRUE(pixel_refs.empty());
209 }
210 }
211
212 TYPED_TEST(RecordingSourceTest, DiscardablePixelRefs) {
213 gfx::Size grid_cell_size(128, 128);
214 gfx::Rect recorded_viewport(0, 0, 256, 256);
215
216 scoped_ptr<TypeParam> recording_source =
217 CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size);
218
219 SkBitmap discardable_bitmap[2][2];
220 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]);
221 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][0]);
222 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]);
223
224 // Discardable pixel refs are found in the following cells:
225 // |---|---|
226 // | x | |
227 // |---|---|
228 // | x | x |
229 // |---|---|
230 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0));
231 recording_source->add_draw_bitmap(discardable_bitmap[1][0],
232 gfx::Point(0, 130));
233 recording_source->add_draw_bitmap(discardable_bitmap[1][1],
234 gfx::Point(140, 140));
235 recording_source->Rerecord();
236
237 scoped_refptr<RasterSource> raster_source =
238 CreateRasterSource<TypeParam>(recording_source.get());
239
240 // Tile sized iterators. These should find only one pixel ref.
241 {
242 std::vector<SkPixelRef*> pixel_refs;
243 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 1.0, &pixel_refs);
244 EXPECT_FALSE(pixel_refs.empty());
245 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
246 EXPECT_EQ(1u, pixel_refs.size());
247 }
248 {
249 std::vector<SkPixelRef*> pixel_refs;
250 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 2.0, &pixel_refs);
251 EXPECT_FALSE(pixel_refs.empty());
252 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
253 EXPECT_EQ(1u, pixel_refs.size());
254 }
255 {
256 std::vector<SkPixelRef*> pixel_refs;
257 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 64, 64), 0.5, &pixel_refs);
258 EXPECT_FALSE(pixel_refs.empty());
259 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
260 EXPECT_EQ(1u, pixel_refs.size());
261 }
262
263 // Shifted tile sized iterators. These should find only one pixel ref.
264 {
265 std::vector<SkPixelRef*> pixel_refs;
266 raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), 1.0,
267 &pixel_refs);
268 EXPECT_FALSE(pixel_refs.empty());
269 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
270 EXPECT_EQ(1u, pixel_refs.size());
271 }
272 {
273 std::vector<SkPixelRef*> pixel_refs;
274 raster_source->GatherPixelRefs(gfx::Rect(280, 280, 256, 256), 2.0,
275 &pixel_refs);
276 EXPECT_FALSE(pixel_refs.empty());
277 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
278 EXPECT_EQ(1u, pixel_refs.size());
279 }
280 {
281 std::vector<SkPixelRef*> pixel_refs;
282 raster_source->GatherPixelRefs(gfx::Rect(70, 70, 64, 64), 0.5, &pixel_refs);
283 EXPECT_FALSE(pixel_refs.empty());
284 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
285 EXPECT_EQ(1u, pixel_refs.size());
286 }
287
288 // Ensure there's no discardable pixel refs in the empty cell
289 {
290 std::vector<SkPixelRef*> pixel_refs;
291 raster_source->GatherPixelRefs(gfx::Rect(140, 0, 128, 128), 1.0,
292 &pixel_refs);
293 EXPECT_TRUE(pixel_refs.empty());
294 }
295
296 // Layer sized iterators. These should find all 3 pixel refs.
297 {
298 std::vector<SkPixelRef*> pixel_refs;
299 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs);
300 EXPECT_FALSE(pixel_refs.empty());
301 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
302 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][0].pixelRef());
303 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
304 EXPECT_EQ(3u, pixel_refs.size());
305 }
306 {
307 std::vector<SkPixelRef*> pixel_refs;
308 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs);
309 EXPECT_FALSE(pixel_refs.empty());
310 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
311 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][0].pixelRef());
312 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
313 EXPECT_EQ(3u, pixel_refs.size());
314 }
315 {
316 std::vector<SkPixelRef*> pixel_refs;
317 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs);
318 EXPECT_FALSE(pixel_refs.empty());
319 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
320 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[1][0].pixelRef());
321 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
322 EXPECT_EQ(3u, pixel_refs.size());
323 }
324 }
325
326 TYPED_TEST(RecordingSourceTest, DiscardablePixelRefsBaseNonDiscardable) {
327 gfx::Size grid_cell_size(256, 256);
328 gfx::Rect recorded_viewport(0, 0, 512, 512);
329
330 scoped_ptr<TypeParam> recording_source =
331 CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size);
332
333 SkBitmap non_discardable_bitmap;
334 CreateBitmap(gfx::Size(512, 512), "notdiscardable", &non_discardable_bitmap);
335
336 SkBitmap discardable_bitmap[2][2];
337 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][0]);
338 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][1]);
339 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[1][1]);
340
341 // One large non-discardable bitmap covers the whole grid.
342 // Discardable pixel refs are found in the following cells:
343 // |---|---|
344 // | x | x |
345 // |---|---|
346 // | | x |
347 // |---|---|
348 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 0));
349 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0));
350 recording_source->add_draw_bitmap(discardable_bitmap[0][1],
351 gfx::Point(260, 0));
352 recording_source->add_draw_bitmap(discardable_bitmap[1][1],
353 gfx::Point(260, 260));
354 recording_source->Rerecord();
355
356 scoped_refptr<RasterSource> raster_source =
357 CreateRasterSource<TypeParam>(recording_source.get());
358
359 // Tile sized iterators. These should find only one pixel ref.
360 {
361 std::vector<SkPixelRef*> pixel_refs;
362 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs);
363 EXPECT_FALSE(pixel_refs.empty());
364 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
365 EXPECT_EQ(1u, pixel_refs.size());
366 }
367 {
368 std::vector<SkPixelRef*> pixel_refs;
369 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs);
370 EXPECT_FALSE(pixel_refs.empty());
371 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
372 EXPECT_EQ(1u, pixel_refs.size());
373 }
374 {
375 std::vector<SkPixelRef*> pixel_refs;
376 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs);
377 EXPECT_FALSE(pixel_refs.empty());
378 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
379 EXPECT_EQ(1u, pixel_refs.size());
380 }
381 // Shifted tile sized iterators. These should find only one pixel ref.
382 {
383 std::vector<SkPixelRef*> pixel_refs;
384 raster_source->GatherPixelRefs(gfx::Rect(260, 260, 256, 256), 1.0,
385 &pixel_refs);
386 EXPECT_FALSE(pixel_refs.empty());
387 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
388 EXPECT_EQ(1u, pixel_refs.size());
389 }
390 {
391 std::vector<SkPixelRef*> pixel_refs;
392 raster_source->GatherPixelRefs(gfx::Rect(520, 520, 512, 512), 2.0,
393 &pixel_refs);
394 EXPECT_FALSE(pixel_refs.empty());
395 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
396 EXPECT_EQ(1u, pixel_refs.size());
397 }
398 {
399 std::vector<SkPixelRef*> pixel_refs;
400 raster_source->GatherPixelRefs(gfx::Rect(130, 130, 128, 128), 0.5,
401 &pixel_refs);
402 EXPECT_FALSE(pixel_refs.empty());
403 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[1][1].pixelRef());
404 EXPECT_EQ(1u, pixel_refs.size());
405 }
406 // Ensure there's no discardable pixel refs in the empty cell
407 {
408 std::vector<SkPixelRef*> pixel_refs;
409 raster_source->GatherPixelRefs(gfx::Rect(0, 256, 256, 256), 1.0,
410 &pixel_refs);
411 EXPECT_TRUE(pixel_refs.empty());
412 }
413 // Layer sized iterators. These should find three pixel ref.
414 {
415 std::vector<SkPixelRef*> pixel_refs;
416 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 1.0, &pixel_refs);
417 EXPECT_FALSE(pixel_refs.empty());
418 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
419 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[0][1].pixelRef());
420 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
421 EXPECT_EQ(3u, pixel_refs.size());
422 }
423 {
424 std::vector<SkPixelRef*> pixel_refs;
425 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 1024, 1024), 2.0,
426 &pixel_refs);
427 EXPECT_FALSE(pixel_refs.empty());
428 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
429 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[0][1].pixelRef());
430 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
431 EXPECT_EQ(3u, pixel_refs.size());
432 }
433 {
434 std::vector<SkPixelRef*> pixel_refs;
435 raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 0.5, &pixel_refs);
436 EXPECT_FALSE(pixel_refs.empty());
437 EXPECT_TRUE(pixel_refs[0] == discardable_bitmap[0][0].pixelRef());
438 EXPECT_TRUE(pixel_refs[1] == discardable_bitmap[0][1].pixelRef());
439 EXPECT_TRUE(pixel_refs[2] == discardable_bitmap[1][1].pixelRef());
440 EXPECT_EQ(3u, pixel_refs.size());
441 }
442 }
443
444 } // namespace
445 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/pixel_ref_map.cc ('k') | cc/test/fake_content_layer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698