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

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

Issue 1057283003: Remove parts of //cc we aren't using (Closed) Base URL: git@github.com:domokit/mojo.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/picture_pile_impl_perftest.cc ('k') | cc/resources/picture_pile_unittest.cc » ('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 2013 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 "base/memory/scoped_ptr.h"
6 #include "cc/test/fake_picture_pile_impl.h"
7 #include "cc/test/skia_common.h"
8 #include "skia/ext/refptr.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkPixelRef.h"
11 #include "third_party/skia/include/core/SkShader.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/geometry/size_conversions.h"
14
15 namespace cc {
16 namespace {
17
18 TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) {
19 gfx::Size tile_size(100, 100);
20 gfx::Size layer_bounds(400, 400);
21
22 scoped_ptr<FakePicturePile> recording_source =
23 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
24
25 SkPaint solid_paint;
26 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
27 solid_paint.setColor(solid_color);
28
29 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
30 SkPaint non_solid_paint;
31 non_solid_paint.setColor(non_solid_color);
32
33 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400),
34 solid_paint);
35 recording_source->RerecordPile();
36
37 scoped_refptr<FakePicturePileImpl> pile =
38 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
39
40 // Ensure everything is solid.
41 for (int y = 0; y <= 300; y += 100) {
42 for (int x = 0; x <= 300; x += 100) {
43 RasterSource::SolidColorAnalysis analysis;
44 gfx::Rect rect(x, y, 100, 100);
45 pile->PerformSolidColorAnalysis(rect, 1.0, &analysis);
46 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString();
47 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString();
48 }
49 }
50
51 // Add one non-solid pixel and recreate the raster source.
52 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1),
53 non_solid_paint);
54 recording_source->RerecordPile();
55 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
56
57 RasterSource::SolidColorAnalysis analysis;
58 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis);
59 EXPECT_FALSE(analysis.is_solid_color);
60
61 pile->PerformSolidColorAnalysis(gfx::Rect(100, 0, 100, 100), 1.0, &analysis);
62 EXPECT_TRUE(analysis.is_solid_color);
63 EXPECT_EQ(analysis.solid_color, solid_color);
64
65 // Boundaries should be clipped.
66 analysis.is_solid_color = false;
67 pile->PerformSolidColorAnalysis(gfx::Rect(350, 0, 100, 100), 1.0, &analysis);
68 EXPECT_TRUE(analysis.is_solid_color);
69 EXPECT_EQ(analysis.solid_color, solid_color);
70
71 analysis.is_solid_color = false;
72 pile->PerformSolidColorAnalysis(gfx::Rect(0, 350, 100, 100), 1.0, &analysis);
73 EXPECT_TRUE(analysis.is_solid_color);
74 EXPECT_EQ(analysis.solid_color, solid_color);
75
76 analysis.is_solid_color = false;
77 pile->PerformSolidColorAnalysis(gfx::Rect(350, 350, 100, 100), 1.0,
78 &analysis);
79 EXPECT_TRUE(analysis.is_solid_color);
80 EXPECT_EQ(analysis.solid_color, solid_color);
81 }
82
83 TEST(PicturePileImplTest, AnalyzeIsSolidScaled) {
84 gfx::Size tile_size(100, 100);
85 gfx::Size layer_bounds(400, 400);
86
87 scoped_ptr<FakePicturePile> recording_source =
88 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
89
90 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
91 SkPaint solid_paint;
92 solid_paint.setColor(solid_color);
93
94 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
95 SkPaint non_solid_paint;
96 non_solid_paint.setColor(non_solid_color);
97
98 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400),
99 solid_paint);
100 recording_source->RerecordPile();
101
102 scoped_refptr<FakePicturePileImpl> pile =
103 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
104
105 // Ensure everything is solid.
106 for (int y = 0; y <= 30; y += 10) {
107 for (int x = 0; x <= 30; x += 10) {
108 RasterSource::SolidColorAnalysis analysis;
109 gfx::Rect rect(x, y, 10, 10);
110 pile->PerformSolidColorAnalysis(rect, 0.1f, &analysis);
111 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString();
112 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString();
113 }
114 }
115
116 // Add one non-solid pixel and recreate the raster source.
117 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1),
118 non_solid_paint);
119 recording_source->RerecordPile();
120 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
121
122 RasterSource::SolidColorAnalysis analysis;
123 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis);
124 EXPECT_FALSE(analysis.is_solid_color);
125
126 pile->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis);
127 EXPECT_TRUE(analysis.is_solid_color);
128 EXPECT_EQ(analysis.solid_color, solid_color);
129
130 // Boundaries should be clipped.
131 analysis.is_solid_color = false;
132 pile->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f, &analysis);
133 EXPECT_TRUE(analysis.is_solid_color);
134 EXPECT_EQ(analysis.solid_color, solid_color);
135
136 analysis.is_solid_color = false;
137 pile->PerformSolidColorAnalysis(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis);
138 EXPECT_TRUE(analysis.is_solid_color);
139 EXPECT_EQ(analysis.solid_color, solid_color);
140
141 analysis.is_solid_color = false;
142 pile->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis);
143 EXPECT_TRUE(analysis.is_solid_color);
144 EXPECT_EQ(analysis.solid_color, solid_color);
145 }
146
147 TEST(PicturePileImplTest, AnalyzeIsSolidEmpty) {
148 gfx::Size tile_size(100, 100);
149 gfx::Size layer_bounds(400, 400);
150
151 scoped_refptr<FakePicturePileImpl> pile =
152 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
153 RasterSource::SolidColorAnalysis analysis;
154 EXPECT_FALSE(analysis.is_solid_color);
155
156 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &analysis);
157
158 EXPECT_TRUE(analysis.is_solid_color);
159 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0));
160 }
161
162 TEST(PicturePileImplTest, PixelRefIteratorEmpty) {
163 gfx::Size tile_size(128, 128);
164 gfx::Size layer_bounds(256, 256);
165
166 // Create a filled pile with no recording.
167 scoped_refptr<FakePicturePileImpl> pile =
168 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
169
170 // Tile sized iterators.
171 {
172 PicturePileImpl::PixelRefIterator iterator(
173 gfx::Rect(0, 0, 128, 128), 1.0, pile.get());
174 EXPECT_FALSE(iterator);
175 }
176 {
177 PicturePileImpl::PixelRefIterator iterator(
178 gfx::Rect(0, 0, 256, 256), 2.0, pile.get());
179 EXPECT_FALSE(iterator);
180 }
181 {
182 PicturePileImpl::PixelRefIterator iterator(
183 gfx::Rect(0, 0, 64, 64), 0.5, pile.get());
184 EXPECT_FALSE(iterator);
185 }
186 // Shifted tile sized iterators.
187 {
188 PicturePileImpl::PixelRefIterator iterator(
189 gfx::Rect(140, 140, 128, 128), 1.0, pile.get());
190 EXPECT_FALSE(iterator);
191 }
192 {
193 PicturePileImpl::PixelRefIterator iterator(
194 gfx::Rect(280, 280, 256, 256), 2.0, pile.get());
195 EXPECT_FALSE(iterator);
196 }
197 {
198 PicturePileImpl::PixelRefIterator iterator(
199 gfx::Rect(70, 70, 64, 64), 0.5, pile.get());
200 EXPECT_FALSE(iterator);
201 }
202 // Layer sized iterators.
203 {
204 PicturePileImpl::PixelRefIterator iterator(
205 gfx::Rect(0, 0, 256, 256), 1.0, pile.get());
206 EXPECT_FALSE(iterator);
207 }
208 {
209 PicturePileImpl::PixelRefIterator iterator(
210 gfx::Rect(0, 0, 512, 512), 2.0, pile.get());
211 EXPECT_FALSE(iterator);
212 }
213 {
214 PicturePileImpl::PixelRefIterator iterator(
215 gfx::Rect(0, 0, 128, 128), 0.5, pile.get());
216 EXPECT_FALSE(iterator);
217 }
218 }
219
220 TEST(PicturePileImplTest, PixelRefIteratorNoDiscardableRefs) {
221 gfx::Size tile_size(128, 128);
222 gfx::Size layer_bounds(256, 256);
223
224 scoped_ptr<FakePicturePile> recording_source =
225 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
226 SkPaint simple_paint;
227 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34));
228
229 SkBitmap non_discardable_bitmap;
230 CreateBitmap(gfx::Size(128, 128), "notdiscardable", &non_discardable_bitmap);
231
232 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256),
233 simple_paint);
234 recording_source->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512),
235 simple_paint);
236 recording_source->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256),
237 simple_paint);
238 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256),
239 simple_paint);
240 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(128, 0));
241 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 128));
242 recording_source->add_draw_bitmap(non_discardable_bitmap,
243 gfx::Point(150, 150));
244 recording_source->RerecordPile();
245
246 scoped_refptr<FakePicturePileImpl> pile =
247 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
248
249 // Tile sized iterators.
250 {
251 PicturePileImpl::PixelRefIterator iterator(
252 gfx::Rect(0, 0, 128, 128), 1.0, pile.get());
253 EXPECT_FALSE(iterator);
254 }
255 {
256 PicturePileImpl::PixelRefIterator iterator(
257 gfx::Rect(0, 0, 256, 256), 2.0, pile.get());
258 EXPECT_FALSE(iterator);
259 }
260 {
261 PicturePileImpl::PixelRefIterator iterator(
262 gfx::Rect(0, 0, 64, 64), 0.5, pile.get());
263 EXPECT_FALSE(iterator);
264 }
265 // Shifted tile sized iterators.
266 {
267 PicturePileImpl::PixelRefIterator iterator(
268 gfx::Rect(140, 140, 128, 128), 1.0, pile.get());
269 EXPECT_FALSE(iterator);
270 }
271 {
272 PicturePileImpl::PixelRefIterator iterator(
273 gfx::Rect(280, 280, 256, 256), 2.0, pile.get());
274 EXPECT_FALSE(iterator);
275 }
276 {
277 PicturePileImpl::PixelRefIterator iterator(
278 gfx::Rect(70, 70, 64, 64), 0.5, pile.get());
279 EXPECT_FALSE(iterator);
280 }
281 // Layer sized iterators.
282 {
283 PicturePileImpl::PixelRefIterator iterator(
284 gfx::Rect(0, 0, 256, 256), 1.0, pile.get());
285 EXPECT_FALSE(iterator);
286 }
287 {
288 PicturePileImpl::PixelRefIterator iterator(
289 gfx::Rect(0, 0, 512, 512), 2.0, pile.get());
290 EXPECT_FALSE(iterator);
291 }
292 {
293 PicturePileImpl::PixelRefIterator iterator(
294 gfx::Rect(0, 0, 128, 128), 0.5, pile.get());
295 EXPECT_FALSE(iterator);
296 }
297 }
298
299 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefs) {
300 gfx::Size tile_size(128, 128);
301 gfx::Size layer_bounds(256, 256);
302
303 scoped_ptr<FakePicturePile> recording_source =
304 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
305
306 SkBitmap discardable_bitmap[2][2];
307 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]);
308 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][0]);
309 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]);
310
311 // Discardable pixel refs are found in the following cells:
312 // |---|---|
313 // | x | |
314 // |---|---|
315 // | x | x |
316 // |---|---|
317 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0));
318 recording_source->add_draw_bitmap(discardable_bitmap[1][0],
319 gfx::Point(0, 130));
320 recording_source->add_draw_bitmap(discardable_bitmap[1][1],
321 gfx::Point(140, 140));
322 recording_source->RerecordPile();
323
324 scoped_refptr<FakePicturePileImpl> pile =
325 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
326
327 // Tile sized iterators. These should find only one pixel ref.
328 {
329 PicturePileImpl::PixelRefIterator iterator(
330 gfx::Rect(0, 0, 128, 128), 1.0, pile.get());
331 EXPECT_TRUE(iterator);
332 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
333 EXPECT_FALSE(++iterator);
334 }
335 {
336 PicturePileImpl::PixelRefIterator iterator(
337 gfx::Rect(0, 0, 256, 256), 2.0, pile.get());
338 EXPECT_TRUE(iterator);
339 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
340 EXPECT_FALSE(++iterator);
341 }
342 {
343 PicturePileImpl::PixelRefIterator iterator(
344 gfx::Rect(0, 0, 64, 64), 0.5, pile.get());
345 EXPECT_TRUE(iterator);
346 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
347 EXPECT_FALSE(++iterator);
348 }
349 // Shifted tile sized iterators. These should find only one pixel ref.
350 {
351 PicturePileImpl::PixelRefIterator iterator(
352 gfx::Rect(140, 140, 128, 128), 1.0, pile.get());
353 EXPECT_TRUE(iterator);
354 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
355 EXPECT_FALSE(++iterator);
356 }
357 {
358 PicturePileImpl::PixelRefIterator iterator(
359 gfx::Rect(280, 280, 256, 256), 2.0, pile.get());
360 EXPECT_TRUE(iterator);
361 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
362 EXPECT_FALSE(++iterator);
363 }
364 {
365 PicturePileImpl::PixelRefIterator iterator(
366 gfx::Rect(70, 70, 64, 64), 0.5, pile.get());
367 EXPECT_TRUE(iterator);
368 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
369 EXPECT_FALSE(++iterator);
370 }
371 // Ensure there's no discardable pixel refs in the empty cell
372 {
373 PicturePileImpl::PixelRefIterator iterator(
374 gfx::Rect(140, 0, 128, 128), 1.0, pile.get());
375 EXPECT_FALSE(iterator);
376 }
377 // Layer sized iterators. These should find all 3 pixel refs.
378 {
379 PicturePileImpl::PixelRefIterator iterator(
380 gfx::Rect(0, 0, 256, 256), 1.0, pile.get());
381 EXPECT_TRUE(iterator);
382 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
383 EXPECT_TRUE(++iterator);
384 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef());
385 EXPECT_TRUE(++iterator);
386 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
387 EXPECT_FALSE(++iterator);
388 }
389 {
390 PicturePileImpl::PixelRefIterator iterator(
391 gfx::Rect(0, 0, 512, 512), 2.0, pile.get());
392 EXPECT_TRUE(iterator);
393 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
394 EXPECT_TRUE(++iterator);
395 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef());
396 EXPECT_TRUE(++iterator);
397 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
398 EXPECT_FALSE(++iterator);
399 }
400 {
401 PicturePileImpl::PixelRefIterator iterator(
402 gfx::Rect(0, 0, 128, 128), 0.5, pile.get());
403 EXPECT_TRUE(iterator);
404 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
405 EXPECT_TRUE(++iterator);
406 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef());
407 EXPECT_TRUE(++iterator);
408 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
409 EXPECT_FALSE(++iterator);
410 }
411 }
412
413 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) {
414 gfx::Size tile_size(256, 256);
415 gfx::Size layer_bounds(512, 512);
416
417 scoped_ptr<FakePicturePile> recording_source =
418 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
419
420 SkBitmap discardable_bitmap[2][2];
421 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]);
422 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][1]);
423 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]);
424
425 // Discardable pixel refs are found in the following cells:
426 // |---|---|
427 // | x | x |
428 // |---|---|
429 // | | x |
430 // |---|---|
431 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0));
432 recording_source->add_draw_bitmap(discardable_bitmap[0][1],
433 gfx::Point(260, 0));
434 recording_source->add_draw_bitmap(discardable_bitmap[1][1],
435 gfx::Point(260, 260));
436 recording_source->RerecordPile();
437
438 scoped_refptr<FakePicturePileImpl> pile =
439 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
440
441 // Tile sized iterators. These should find only one pixel ref.
442 {
443 PicturePileImpl::PixelRefIterator iterator(
444 gfx::Rect(0, 0, 256, 256), 1.0, pile.get());
445 EXPECT_TRUE(iterator);
446 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
447 EXPECT_FALSE(++iterator);
448 }
449 {
450 PicturePileImpl::PixelRefIterator iterator(
451 gfx::Rect(0, 0, 512, 512), 2.0, pile.get());
452 EXPECT_TRUE(iterator);
453 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
454 EXPECT_FALSE(++iterator);
455 }
456 {
457 PicturePileImpl::PixelRefIterator iterator(
458 gfx::Rect(0, 0, 128, 128), 0.5, pile.get());
459 EXPECT_TRUE(iterator);
460 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
461 EXPECT_FALSE(++iterator);
462 }
463 // Shifted tile sized iterators. These should find only one pixel ref.
464 {
465 PicturePileImpl::PixelRefIterator iterator(
466 gfx::Rect(260, 260, 256, 256), 1.0, pile.get());
467 EXPECT_TRUE(iterator);
468 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
469 EXPECT_FALSE(++iterator);
470 }
471 {
472 PicturePileImpl::PixelRefIterator iterator(
473 gfx::Rect(520, 520, 512, 512), 2.0, pile.get());
474 EXPECT_TRUE(iterator);
475 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
476 EXPECT_FALSE(++iterator);
477 }
478 {
479 PicturePileImpl::PixelRefIterator iterator(
480 gfx::Rect(130, 130, 128, 128), 0.5, pile.get());
481 EXPECT_TRUE(iterator);
482 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
483 EXPECT_FALSE(++iterator);
484 }
485 // Ensure there's no discardable pixel refs in the empty cell
486 {
487 PicturePileImpl::PixelRefIterator iterator(
488 gfx::Rect(0, 256, 256, 256), 1.0, pile.get());
489 EXPECT_FALSE(iterator);
490 }
491 // Layer sized iterators. These should find three pixel ref.
492 {
493 PicturePileImpl::PixelRefIterator iterator(
494 gfx::Rect(0, 0, 512, 512), 1.0, pile.get());
495 EXPECT_TRUE(iterator);
496 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
497 EXPECT_TRUE(++iterator);
498 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef());
499 EXPECT_TRUE(++iterator);
500 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
501 EXPECT_FALSE(++iterator);
502 }
503 {
504 PicturePileImpl::PixelRefIterator iterator(
505 gfx::Rect(0, 0, 1024, 1024), 2.0, pile.get());
506 EXPECT_TRUE(iterator);
507 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
508 EXPECT_TRUE(++iterator);
509 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef());
510 EXPECT_TRUE(++iterator);
511 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
512 EXPECT_FALSE(++iterator);
513 }
514 {
515 PicturePileImpl::PixelRefIterator iterator(
516 gfx::Rect(0, 0, 256, 256), 0.5, pile.get());
517 EXPECT_TRUE(iterator);
518 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
519 EXPECT_TRUE(++iterator);
520 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef());
521 EXPECT_TRUE(++iterator);
522 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
523 EXPECT_FALSE(++iterator);
524 }
525
526 // Copy test.
527 PicturePileImpl::PixelRefIterator iterator(
528 gfx::Rect(0, 0, 512, 512), 1.0, pile.get());
529 EXPECT_TRUE(iterator);
530 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
531 EXPECT_TRUE(++iterator);
532 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef());
533
534 // copy now points to the same spot as iterator,
535 // but both can be incremented independently.
536 PicturePileImpl::PixelRefIterator copy = iterator;
537 EXPECT_TRUE(++iterator);
538 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
539 EXPECT_FALSE(++iterator);
540
541 EXPECT_TRUE(copy);
542 EXPECT_TRUE(*copy == discardable_bitmap[0][1].pixelRef());
543 EXPECT_TRUE(++copy);
544 EXPECT_TRUE(*copy == discardable_bitmap[1][1].pixelRef());
545 EXPECT_FALSE(++copy);
546 }
547
548 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsBaseNonDiscardable) {
549 gfx::Size tile_size(256, 256);
550 gfx::Size layer_bounds(512, 512);
551
552 scoped_ptr<FakePicturePile> recording_source =
553 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
554
555 SkBitmap non_discardable_bitmap;
556 CreateBitmap(gfx::Size(512, 512), "notdiscardable", &non_discardable_bitmap);
557
558 SkBitmap discardable_bitmap[2][2];
559 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][0]);
560 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][1]);
561 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[1][1]);
562
563 // One large non-discardable bitmap covers the whole grid.
564 // Discardable pixel refs are found in the following cells:
565 // |---|---|
566 // | x | x |
567 // |---|---|
568 // | | x |
569 // |---|---|
570 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 0));
571 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0));
572 recording_source->add_draw_bitmap(discardable_bitmap[0][1],
573 gfx::Point(260, 0));
574 recording_source->add_draw_bitmap(discardable_bitmap[1][1],
575 gfx::Point(260, 260));
576 recording_source->RerecordPile();
577
578 scoped_refptr<FakePicturePileImpl> pile =
579 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
580
581 // Tile sized iterators. These should find only one pixel ref.
582 {
583 PicturePileImpl::PixelRefIterator iterator(
584 gfx::Rect(0, 0, 256, 256), 1.0, pile.get());
585 EXPECT_TRUE(iterator);
586 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
587 EXPECT_FALSE(++iterator);
588 }
589 {
590 PicturePileImpl::PixelRefIterator iterator(
591 gfx::Rect(0, 0, 512, 512), 2.0, pile.get());
592 EXPECT_TRUE(iterator);
593 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
594 EXPECT_FALSE(++iterator);
595 }
596 {
597 PicturePileImpl::PixelRefIterator iterator(
598 gfx::Rect(0, 0, 128, 128), 0.5, pile.get());
599 EXPECT_TRUE(iterator);
600 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
601 EXPECT_FALSE(++iterator);
602 }
603 // Shifted tile sized iterators. These should find only one pixel ref.
604 {
605 PicturePileImpl::PixelRefIterator iterator(
606 gfx::Rect(260, 260, 256, 256), 1.0, pile.get());
607 EXPECT_TRUE(iterator);
608 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
609 EXPECT_FALSE(++iterator);
610 }
611 {
612 PicturePileImpl::PixelRefIterator iterator(
613 gfx::Rect(520, 520, 512, 512), 2.0, pile.get());
614 EXPECT_TRUE(iterator);
615 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
616 EXPECT_FALSE(++iterator);
617 }
618 {
619 PicturePileImpl::PixelRefIterator iterator(
620 gfx::Rect(130, 130, 128, 128), 0.5, pile.get());
621 EXPECT_TRUE(iterator);
622 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
623 EXPECT_FALSE(++iterator);
624 }
625 // Ensure there's no discardable pixel refs in the empty cell
626 {
627 PicturePileImpl::PixelRefIterator iterator(
628 gfx::Rect(0, 256, 256, 256), 1.0, pile.get());
629 EXPECT_FALSE(iterator);
630 }
631 // Layer sized iterators. These should find three pixel ref.
632 {
633 PicturePileImpl::PixelRefIterator iterator(
634 gfx::Rect(0, 0, 512, 512), 1.0, pile.get());
635 EXPECT_TRUE(iterator);
636 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
637 EXPECT_TRUE(++iterator);
638 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef());
639 EXPECT_TRUE(++iterator);
640 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
641 EXPECT_FALSE(++iterator);
642 }
643 {
644 PicturePileImpl::PixelRefIterator iterator(
645 gfx::Rect(0, 0, 1024, 1024), 2.0, pile.get());
646 EXPECT_TRUE(iterator);
647 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
648 EXPECT_TRUE(++iterator);
649 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef());
650 EXPECT_TRUE(++iterator);
651 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
652 EXPECT_FALSE(++iterator);
653 }
654 {
655 PicturePileImpl::PixelRefIterator iterator(
656 gfx::Rect(0, 0, 256, 256), 0.5, pile.get());
657 EXPECT_TRUE(iterator);
658 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
659 EXPECT_TRUE(++iterator);
660 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef());
661 EXPECT_TRUE(++iterator);
662 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
663 EXPECT_FALSE(++iterator);
664 }
665 }
666
667 TEST(PicturePileImplTest, RasterFullContents) {
668 gfx::Size tile_size(1000, 1000);
669 gfx::Size layer_bounds(3, 5);
670 float contents_scale = 1.5f;
671 float raster_divisions = 2.f;
672
673 scoped_ptr<FakePicturePile> recording_source =
674 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
675 recording_source->SetBackgroundColor(SK_ColorBLACK);
676 recording_source->SetIsSolidColor(false);
677 recording_source->SetRequiresClear(false);
678 recording_source->SetClearCanvasWithDebugColor(false);
679
680 // Because the caller sets content opaque, it also promises that it
681 // has at least filled in layer_bounds opaquely.
682 SkPaint white_paint;
683 white_paint.setColor(SK_ColorWHITE);
684 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
685 white_paint);
686
687 recording_source->SetMinContentsScale(contents_scale);
688 recording_source->RerecordPile();
689
690 scoped_refptr<FakePicturePileImpl> pile =
691 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
692
693 gfx::Size content_bounds(
694 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
695
696 // Simulate drawing into different tiles at different offsets.
697 int step_x = std::ceil(content_bounds.width() / raster_divisions);
698 int step_y = std::ceil(content_bounds.height() / raster_divisions);
699 for (int offset_x = 0; offset_x < content_bounds.width();
700 offset_x += step_x) {
701 for (int offset_y = 0; offset_y < content_bounds.height();
702 offset_y += step_y) {
703 gfx::Rect content_rect(offset_x, offset_y, step_x, step_y);
704 content_rect.Intersect(gfx::Rect(content_bounds));
705
706 // Simulate a canvas rect larger than the content rect. Every pixel
707 // up to one pixel outside the content rect is guaranteed to be opaque.
708 // Outside of that is undefined.
709 gfx::Rect canvas_rect(content_rect);
710 canvas_rect.Inset(0, 0, -1, -1);
711
712 SkBitmap bitmap;
713 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height());
714 SkCanvas canvas(bitmap);
715 canvas.clear(SK_ColorTRANSPARENT);
716
717 pile->PlaybackToCanvas(&canvas, canvas_rect, contents_scale);
718
719 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
720 int num_pixels = bitmap.width() * bitmap.height();
721 bool all_white = true;
722 for (int i = 0; i < num_pixels; ++i) {
723 EXPECT_EQ(SkColorGetA(pixels[i]), 255u);
724 all_white &= (SkColorGetR(pixels[i]) == 255);
725 all_white &= (SkColorGetG(pixels[i]) == 255);
726 all_white &= (SkColorGetB(pixels[i]) == 255);
727 }
728
729 // If the canvas doesn't extend past the edge of the content,
730 // it should be entirely white. Otherwise, the edge of the content
731 // will be non-white.
732 EXPECT_EQ(all_white, gfx::Rect(content_bounds).Contains(canvas_rect));
733 }
734 }
735 }
736
737 TEST(PicturePileImpl, RasterContentsTransparent) {
738 gfx::Size tile_size(1000, 1000);
739 gfx::Size layer_bounds(5, 3);
740 float contents_scale = 0.5f;
741
742 scoped_ptr<FakePicturePile> recording_source =
743 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
744 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT);
745 recording_source->SetRequiresClear(true);
746 recording_source->SetMinContentsScale(contents_scale);
747 recording_source->SetClearCanvasWithDebugColor(false);
748 recording_source->RerecordPile();
749
750 scoped_refptr<FakePicturePileImpl> pile =
751 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
752 gfx::Size content_bounds(
753 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
754
755 gfx::Rect canvas_rect(content_bounds);
756 canvas_rect.Inset(0, 0, -1, -1);
757
758 SkBitmap bitmap;
759 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height());
760 SkCanvas canvas(bitmap);
761
762 pile->PlaybackToCanvas(&canvas, canvas_rect, contents_scale);
763
764 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
765 int num_pixels = bitmap.width() * bitmap.height();
766 for (int i = 0; i < num_pixels; ++i) {
767 EXPECT_EQ(SkColorGetA(pixels[i]), 0u);
768 }
769 }
770
771 class OverlapTest : public ::testing::TestWithParam<float> {
772 public:
773 static float MinContentsScale() { return 1.f / 4.f; }
774 };
775
776 TEST_P(OverlapTest, NoOverlap) {
777 gfx::Size tile_size(10, 10);
778 gfx::Size layer_bounds(30, 30);
779 gfx::Size bigger_than_layer_bounds(300, 300);
780 float contents_scale = GetParam();
781 // Pick an opaque color to not have to deal with premultiplication off-by-one.
782 SkColor test_color = SkColorSetARGB(255, 45, 56, 67);
783
784 scoped_ptr<FakePicturePile> recording_source =
785 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
786 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT);
787 recording_source->SetRequiresClear(true);
788 recording_source->SetMinContentsScale(MinContentsScale());
789 recording_source->SetClearCanvasWithDebugColor(true);
790
791 SkPaint color_paint;
792 color_paint.setColor(test_color);
793 // Additive paint, so that if two paints overlap, the color will change.
794 color_paint.setXfermodeMode(SkXfermode::kPlus_Mode);
795 // Paint outside the layer to make sure that blending works.
796 recording_source->add_draw_rect_with_paint(
797 gfx::RectF(bigger_than_layer_bounds), color_paint);
798 recording_source->RerecordPile();
799
800 scoped_refptr<FakePicturePileImpl> pile =
801 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
802 gfx::Size content_bounds(
803 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
804
805 SkBitmap bitmap;
806 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height());
807 SkCanvas canvas(bitmap);
808
809 pile->PlaybackToCanvas(&canvas, gfx::Rect(content_bounds), contents_scale);
810
811 for (int y = 0; y < bitmap.height(); y++) {
812 for (int x = 0; x < bitmap.width(); x++) {
813 SkColor color = bitmap.getColor(x, y);
814 EXPECT_EQ(SkColorGetR(test_color), SkColorGetR(color)) << "x: " << x
815 << ", y: " << y;
816 EXPECT_EQ(SkColorGetG(test_color), SkColorGetG(color)) << "x: " << x
817 << ", y: " << y;
818 EXPECT_EQ(SkColorGetB(test_color), SkColorGetB(color)) << "x: " << x
819 << ", y: " << y;
820 EXPECT_EQ(SkColorGetA(test_color), SkColorGetA(color)) << "x: " << x
821 << ", y: " << y;
822 if (test_color != color)
823 break;
824 }
825 }
826 }
827
828 INSTANTIATE_TEST_CASE_P(PicturePileImpl,
829 OverlapTest,
830 ::testing::Values(1.f, 0.873f, 1.f / 4.f, 4.f));
831
832 TEST(PicturePileImplTest, PixelRefIteratorBorders) {
833 // 3 tile width / 1 tile height pile
834 gfx::Size tile_size(128, 128);
835 gfx::Size layer_bounds(320, 128);
836
837 // Fake picture pile uses a tile grid the size of the tile. So,
838 // any iteration that intersects with a tile will return all pixel refs
839 // inside of it.
840 scoped_ptr<FakePicturePile> recording_source =
841 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
842 recording_source->SetMinContentsScale(0.5f);
843
844 // Bitmaps 0-2 are exactly on tiles 0-2, so that they overlap the borders
845 // of adjacent tiles.
846 gfx::Rect bitmap_rects[] = {
847 recording_source->tiling().TileBounds(0, 0),
848 recording_source->tiling().TileBounds(1, 0),
849 recording_source->tiling().TileBounds(2, 0),
850 };
851 SkBitmap discardable_bitmap[arraysize(bitmap_rects)];
852
853 for (size_t i = 0; i < arraysize(bitmap_rects); ++i) {
854 CreateBitmap(bitmap_rects[i].size(), "discardable", &discardable_bitmap[i]);
855 recording_source->add_draw_bitmap(discardable_bitmap[i],
856 bitmap_rects[i].origin());
857 }
858
859 recording_source->RerecordPile();
860
861 scoped_refptr<FakePicturePileImpl> pile =
862 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
863
864 // Sanity check that bitmaps 0-2 intersect the borders of their adjacent
865 // tiles, but not the actual tiles.
866 EXPECT_TRUE(
867 bitmap_rects[0].Intersects(pile->tiling().TileBoundsWithBorder(1, 0)));
868 EXPECT_FALSE(bitmap_rects[0].Intersects(pile->tiling().TileBounds(1, 0)));
869 EXPECT_TRUE(
870 bitmap_rects[1].Intersects(pile->tiling().TileBoundsWithBorder(0, 0)));
871 EXPECT_FALSE(bitmap_rects[1].Intersects(pile->tiling().TileBounds(0, 0)));
872 EXPECT_TRUE(
873 bitmap_rects[1].Intersects(pile->tiling().TileBoundsWithBorder(2, 0)));
874 EXPECT_FALSE(bitmap_rects[1].Intersects(pile->tiling().TileBounds(2, 0)));
875 EXPECT_TRUE(
876 bitmap_rects[2].Intersects(pile->tiling().TileBoundsWithBorder(1, 0)));
877 EXPECT_FALSE(bitmap_rects[2].Intersects(pile->tiling().TileBounds(1, 0)));
878
879 // Tile-sized iterators.
880 {
881 // Because tile 0's borders extend onto tile 1, it will include both
882 // bitmap 0 and 1. However, it should *not* include bitmap 2.
883 PicturePileImpl::PixelRefIterator iterator(
884 pile->tiling().TileBounds(0, 0), 1.f, pile.get());
885 EXPECT_TRUE(iterator);
886 EXPECT_TRUE(*iterator == discardable_bitmap[0].pixelRef());
887 EXPECT_TRUE(++iterator);
888 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef());
889 EXPECT_FALSE(++iterator);
890 }
891 {
892 // Tile 1 + borders hits all bitmaps.
893 PicturePileImpl::PixelRefIterator iterator(
894 pile->tiling().TileBounds(1, 0), 1.f, pile.get());
895 EXPECT_TRUE(iterator);
896 EXPECT_TRUE(*iterator == discardable_bitmap[0].pixelRef());
897 EXPECT_TRUE(++iterator);
898 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef());
899 EXPECT_TRUE(++iterator);
900 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef());
901 EXPECT_FALSE(++iterator);
902 }
903 {
904 // Tile 2 should not include bitmap 0, which is only on tile 0 and the
905 // borders of tile 1.
906 PicturePileImpl::PixelRefIterator iterator(
907 pile->tiling().TileBounds(2, 0), 1.f, pile.get());
908 EXPECT_TRUE(iterator);
909 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef());
910 EXPECT_TRUE(++iterator);
911 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef());
912 EXPECT_FALSE(++iterator);
913 }
914 }
915
916 } // namespace
917 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture_pile_impl_perftest.cc ('k') | cc/resources/picture_pile_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698