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

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

Issue 14230007: cc: Do GatherPixelRefs from skia at record time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unittests + enne's review Created 7 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
OLDNEW
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 "cc/test/fake_picture_pile_impl.h" 6 #include "cc/test/fake_picture_pile_impl.h"
7 #include "skia/ext/lazy_pixel_ref.h"
6 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/skia/include/core/SkPixelRef.h"
10 #include "third_party/skia/include/core/SkShader.h"
7 #include "ui/gfx/rect.h" 11 #include "ui/gfx/rect.h"
8 12
9 namespace cc { 13 namespace cc {
10 namespace { 14 namespace {
11 15
16 class TestPixelRef : public SkPixelRef {
17 public:
18 // Pure virtual implementation.
19 TestPixelRef(int width, int height)
20 : pixels_(new char[4 * width * height]) {}
21 virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; }
22 virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE {
23 return pixels_.get();
24 }
25 virtual void onUnlockPixels() OVERRIDE {}
26 virtual SkPixelRef* deepCopy(
27 SkBitmap::Config config,
28 const SkIRect* subset) OVERRIDE {
29 this->ref();
30 return this;
31 }
32 private:
33 scoped_ptr<char[]> pixels_;
34 };
35
36 class TestLazyPixelRef : public skia::LazyPixelRef {
37 public:
38 // Pure virtual implementation.
39 TestLazyPixelRef(int width, int height)
40 : pixels_(new char[4 * width * height]) {}
41 virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; }
42 virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE {
43 return pixels_.get();
44 }
45 virtual void onUnlockPixels() OVERRIDE {}
46 virtual bool PrepareToDecode(const PrepareParams& params) OVERRIDE {
47 return true;
48 }
49 virtual SkPixelRef* deepCopy(
50 SkBitmap::Config config,
51 const SkIRect* subset) OVERRIDE {
52 this->ref();
53 return this;
54 }
55 virtual void Decode() OVERRIDE {}
56 private:
57 scoped_ptr<char[]> pixels_;
58 };
59
12 void RerecordPile(scoped_refptr<FakePicturePileImpl> pile) { 60 void RerecordPile(scoped_refptr<FakePicturePileImpl> pile) {
13 for (int y = 0; y < pile->num_tiles_y(); ++y) { 61 for (int y = 0; y < pile->num_tiles_y(); ++y) {
14 for (int x = 0; x < pile->num_tiles_x(); ++x) { 62 for (int x = 0; x < pile->num_tiles_x(); ++x) {
15 pile->RemoveRecordingAt(x, y); 63 pile->RemoveRecordingAt(x, y);
16 pile->AddRecordingAt(x, y); 64 pile->AddRecordingAt(x, y);
17 } 65 }
18 } 66 }
19 } 67 }
20 68
21 TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) { 69 TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 pile->AnalyzeInRect(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis); 175 pile->AnalyzeInRect(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis);
128 EXPECT_TRUE(analysis.is_solid_color); 176 EXPECT_TRUE(analysis.is_solid_color);
129 EXPECT_EQ(analysis.solid_color, solid_color); 177 EXPECT_EQ(analysis.solid_color, solid_color);
130 178
131 analysis.is_solid_color = false; 179 analysis.is_solid_color = false;
132 pile->AnalyzeInRect(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis); 180 pile->AnalyzeInRect(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis);
133 EXPECT_TRUE(analysis.is_solid_color); 181 EXPECT_TRUE(analysis.is_solid_color);
134 EXPECT_EQ(analysis.solid_color, solid_color); 182 EXPECT_EQ(analysis.solid_color, solid_color);
135 } 183 }
136 184
185 TEST(PicturePileImplTest, LazyPixelRefIteratorEmpty) {
186 gfx::Size tile_size(128, 128);
187 gfx::Size layer_bounds(256, 256);
188
189 // Create a filled pile with no recording.
190 scoped_refptr<FakePicturePileImpl> pile =
191 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
192
193 // Tile sized iterators.
194 {
195 PicturePileImpl::LazyPixelRefIterator iterator(
196 gfx::Rect(0, 0, 128, 128),
197 1.0,
198 pile);
199 EXPECT_FALSE(iterator);
200 }
201 {
202 PicturePileImpl::LazyPixelRefIterator iterator(
203 gfx::Rect(0, 0, 256, 256),
204 2.0,
205 pile);
206 EXPECT_FALSE(iterator);
207 }
208 {
209 PicturePileImpl::LazyPixelRefIterator iterator(
210 gfx::Rect(0, 0, 64, 64),
211 0.5,
212 pile);
213 EXPECT_FALSE(iterator);
214 }
215 // Shifted tile sized iterators.
216 {
217 PicturePileImpl::LazyPixelRefIterator iterator(
218 gfx::Rect(140, 140, 128, 128),
219 1.0,
220 pile);
221 EXPECT_FALSE(iterator);
222 }
223 {
224 PicturePileImpl::LazyPixelRefIterator iterator(
225 gfx::Rect(280, 280, 256, 256),
226 2.0,
227 pile);
228 EXPECT_FALSE(iterator);
229 }
230 {
231 PicturePileImpl::LazyPixelRefIterator iterator(
232 gfx::Rect(70, 70, 64, 64),
233 0.5,
234 pile);
235 EXPECT_FALSE(iterator);
236 }
237 // Layer sized iterators.
238 {
239 PicturePileImpl::LazyPixelRefIterator iterator(
240 gfx::Rect(0, 0, 256, 256),
241 1.0,
242 pile);
243 EXPECT_FALSE(iterator);
244 }
245 {
246 PicturePileImpl::LazyPixelRefIterator iterator(
247 gfx::Rect(0, 0, 512, 512),
248 2.0,
249 pile);
250 EXPECT_FALSE(iterator);
251 }
252 {
253 PicturePileImpl::LazyPixelRefIterator iterator(
254 gfx::Rect(0, 0, 128, 128),
255 0.5,
256 pile);
257 EXPECT_FALSE(iterator);
258 }
259 }
260
261 TEST(PicturePileImplTest, LazyPixelRefIteratorNoLazyRefs) {
262 gfx::Size tile_size(128, 128);
263 gfx::Size layer_bounds(256, 256);
264
265 scoped_refptr<FakePicturePileImpl> pile =
266 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
267
268 SkPaint simple_paint;
269 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34));
270
271 SkAutoTUnref<TestPixelRef> non_lazy_pixel_ref;
272 non_lazy_pixel_ref.reset(new TestPixelRef(128, 128));
273 non_lazy_pixel_ref->setURI("notlazy");
274
275 SkBitmap non_lazy_bitmap;
276 non_lazy_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 128, 128);
277 non_lazy_bitmap.setPixelRef(non_lazy_pixel_ref);
278
279 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), simple_paint);
280 pile->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512), simple_paint);
281 pile->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256), simple_paint);
282 pile->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256), simple_paint);
283 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(128, 0));
284 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 128));
285 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(150, 150));
286
287 RerecordPile(pile);
288
289 // Tile sized iterators.
290 {
291 PicturePileImpl::LazyPixelRefIterator iterator(
292 gfx::Rect(0, 0, 128, 128),
293 1.0,
294 pile);
295 EXPECT_FALSE(iterator);
296 }
297 {
298 PicturePileImpl::LazyPixelRefIterator iterator(
299 gfx::Rect(0, 0, 256, 256),
300 2.0,
301 pile);
302 EXPECT_FALSE(iterator);
303 }
304 {
305 PicturePileImpl::LazyPixelRefIterator iterator(
306 gfx::Rect(0, 0, 64, 64),
307 0.5,
308 pile);
309 EXPECT_FALSE(iterator);
310 }
311 // Shifted tile sized iterators.
312 {
313 PicturePileImpl::LazyPixelRefIterator iterator(
314 gfx::Rect(140, 140, 128, 128),
315 1.0,
316 pile);
317 EXPECT_FALSE(iterator);
318 }
319 {
320 PicturePileImpl::LazyPixelRefIterator iterator(
321 gfx::Rect(280, 280, 256, 256),
322 2.0,
323 pile);
324 EXPECT_FALSE(iterator);
325 }
326 {
327 PicturePileImpl::LazyPixelRefIterator iterator(
328 gfx::Rect(70, 70, 64, 64),
329 0.5,
330 pile);
331 EXPECT_FALSE(iterator);
332 }
333 // Layer sized iterators.
334 {
335 PicturePileImpl::LazyPixelRefIterator iterator(
336 gfx::Rect(0, 0, 256, 256),
337 1.0,
338 pile);
339 EXPECT_FALSE(iterator);
340 }
341 {
342 PicturePileImpl::LazyPixelRefIterator iterator(
343 gfx::Rect(0, 0, 512, 512),
344 2.0,
345 pile);
346 EXPECT_FALSE(iterator);
347 }
348 {
349 PicturePileImpl::LazyPixelRefIterator iterator(
350 gfx::Rect(0, 0, 128, 128),
351 0.5,
352 pile);
353 EXPECT_FALSE(iterator);
354 }
355 }
356
357 TEST(PicturePileImplTest, LazyPixelRefIteratorLazyRefs) {
358 gfx::Size tile_size(128, 128);
359 gfx::Size layer_bounds(256, 256);
360
361 scoped_refptr<FakePicturePileImpl> pile =
362 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
363
364 SkAutoTUnref<TestLazyPixelRef> lazy_pixel_ref;
365 lazy_pixel_ref.reset(new TestLazyPixelRef(32, 32));
366 lazy_pixel_ref->setURI("lazy");
367
368 SkBitmap lazy_bitmap;
369 lazy_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 32, 32);
370 lazy_bitmap.setPixelRef(lazy_pixel_ref);
371
372 // Lazy pixel refs are found in the following cells:
enne (OOO) 2013/04/22 19:10:56 Can you use different bitmaps per cell?
vmpstr 2013/04/22 22:38:16 Done.
373 // |---|---|
374 // | x | |
375 // |---|---|
376 // | x | x |
377 // |---|---|
378 pile->add_draw_bitmap(lazy_bitmap, gfx::Point(140, 140));
379 pile->add_draw_bitmap(lazy_bitmap, gfx::Point(0, 0));
380 pile->add_draw_bitmap(lazy_bitmap, gfx::Point(0, 130));
381
382 RerecordPile(pile);
383
384 // Tile sized iterators. These should find only one pixel ref.
385 {
386 PicturePileImpl::LazyPixelRefIterator iterator(
387 gfx::Rect(0, 0, 128, 128),
388 1.0,
389 pile);
390 EXPECT_TRUE(iterator);
391 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
392 EXPECT_FALSE(++iterator);
393 }
394 {
395 PicturePileImpl::LazyPixelRefIterator iterator(
396 gfx::Rect(0, 0, 256, 256),
397 2.0,
398 pile);
399 EXPECT_TRUE(iterator);
400 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
401 EXPECT_FALSE(++iterator);
402 }
403 {
404 PicturePileImpl::LazyPixelRefIterator iterator(
405 gfx::Rect(0, 0, 64, 64),
406 0.5,
407 pile);
408 EXPECT_TRUE(iterator);
409 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
410 EXPECT_FALSE(++iterator);
411 }
412 // Shifted tile sized iterators. These should find only one pixel ref.
413 {
414 PicturePileImpl::LazyPixelRefIterator iterator(
415 gfx::Rect(140, 140, 128, 128),
416 1.0,
417 pile);
418 EXPECT_TRUE(iterator);
419 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
420 EXPECT_FALSE(++iterator);
421 }
422 {
423 PicturePileImpl::LazyPixelRefIterator iterator(
424 gfx::Rect(280, 280, 256, 256),
425 2.0,
426 pile);
427 EXPECT_TRUE(iterator);
428 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
429 EXPECT_FALSE(++iterator);
430 }
431 {
432 PicturePileImpl::LazyPixelRefIterator iterator(
433 gfx::Rect(70, 70, 64, 64),
434 0.5,
435 pile);
436 EXPECT_TRUE(iterator);
437 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
438 EXPECT_FALSE(++iterator);
439 }
440 // Ensure there's no lazy pixel refs in the empty cell
441 {
442 PicturePileImpl::LazyPixelRefIterator iterator(
443 gfx::Rect(140, 0, 128, 128),
444 1.0,
445 pile);
446 EXPECT_FALSE(iterator);
447 // Ensure we can increment the iterator with no change
448 EXPECT_FALSE(++iterator);
449 EXPECT_FALSE(++iterator);
450 EXPECT_FALSE(++iterator);
451 EXPECT_FALSE(++iterator);
452 }
453 // Layer sized iterators. These should find all 3 pixel refs.
454 {
455 PicturePileImpl::LazyPixelRefIterator iterator(
456 gfx::Rect(0, 0, 256, 256),
457 1.0,
458 pile);
459 EXPECT_TRUE(iterator);
460 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
461 EXPECT_TRUE(++iterator);
462 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
463 EXPECT_TRUE(++iterator);
464 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
465 EXPECT_FALSE(++iterator);
466 }
467 {
468 PicturePileImpl::LazyPixelRefIterator iterator(
469 gfx::Rect(0, 0, 512, 512),
470 2.0,
471 pile);
472 EXPECT_TRUE(iterator);
473 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
474 EXPECT_TRUE(++iterator);
475 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
476 EXPECT_TRUE(++iterator);
477 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
478 EXPECT_FALSE(++iterator);
479 }
480 {
481 PicturePileImpl::LazyPixelRefIterator iterator(
482 gfx::Rect(0, 0, 128, 128),
483 0.5,
484 pile);
485 EXPECT_TRUE(iterator);
486 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
487 EXPECT_TRUE(++iterator);
488 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
489 EXPECT_TRUE(++iterator);
490 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
491 EXPECT_FALSE(++iterator);
492 }
493 }
494
495 TEST(PicturePileImplTest, LazyPixelRefIteratorLazyRefsOneTile) {
496 gfx::Size tile_size(512, 512);
497 gfx::Size layer_bounds(1024, 1024);
498
499 scoped_refptr<FakePicturePileImpl> pile =
500 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
501
502 SkAutoTUnref<TestLazyPixelRef> lazy_pixel_ref;
503 lazy_pixel_ref.reset(new TestLazyPixelRef(256, 256));
504 lazy_pixel_ref->setURI("lazy");
505
506 SkBitmap lazy_bitmap;
enne (OOO) 2013/04/22 19:10:56 You do this a bunch. Maybe you could wrap the boi
vmpstr 2013/04/22 22:38:16 Done.
507 lazy_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 256);
508 lazy_bitmap.setPixelRef(lazy_pixel_ref);
509
510 // Lazy pixel refs are found in the following cells:
511 // |---|---|
512 // | x | x |
513 // |---|---|
514 // | | x |
515 // |---|---|
516 pile->add_draw_bitmap(lazy_bitmap, gfx::Point(0, 0));
517 pile->add_draw_bitmap(lazy_bitmap, gfx::Point(520, 520));
518 pile->add_draw_bitmap(lazy_bitmap, gfx::Point(520, 0));
519
520 RerecordPile(pile);
521
522 // Tile sized iterators. These should find only one pixel ref.
523 {
524 PicturePileImpl::LazyPixelRefIterator iterator(
525 gfx::Rect(0, 0, 512, 512),
526 1.0,
527 pile);
528 EXPECT_TRUE(iterator);
529 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
530 EXPECT_FALSE(++iterator);
531 }
532 {
533 PicturePileImpl::LazyPixelRefIterator iterator(
534 gfx::Rect(0, 0, 1024, 1024),
535 2.0,
536 pile);
537 EXPECT_TRUE(iterator);
538 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
539 EXPECT_FALSE(++iterator);
540 }
541 {
542 PicturePileImpl::LazyPixelRefIterator iterator(
543 gfx::Rect(0, 0, 256, 256),
544 0.5,
545 pile);
546 EXPECT_TRUE(iterator);
547 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
548 EXPECT_FALSE(++iterator);
549 }
550 // Shifted tile sized iterators. These should find only one pixel ref.
551 {
552 PicturePileImpl::LazyPixelRefIterator iterator(
553 gfx::Rect(530, 530, 512, 512),
554 1.0,
555 pile);
556 EXPECT_TRUE(iterator);
557 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
558 EXPECT_FALSE(++iterator);
559 }
560 {
561 PicturePileImpl::LazyPixelRefIterator iterator(
562 gfx::Rect(1060, 1060, 1024, 1024),
563 2.0,
564 pile);
565 EXPECT_TRUE(iterator);
566 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
567 EXPECT_FALSE(++iterator);
568 }
569 {
570 PicturePileImpl::LazyPixelRefIterator iterator(
571 gfx::Rect(275, 275, 256, 256),
572 0.5,
573 pile);
574 EXPECT_TRUE(iterator);
575 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
576 EXPECT_FALSE(++iterator);
577 }
578 // Ensure there's no lazy pixel refs in the empty cell
579 {
580 PicturePileImpl::LazyPixelRefIterator iterator(
581 gfx::Rect(0, 512, 512, 512),
582 1.0,
583 pile);
584 EXPECT_FALSE(iterator);
585 // Ensure we can increment the iterator with no change
586 EXPECT_FALSE(++iterator);
587 EXPECT_FALSE(++iterator);
588 EXPECT_FALSE(++iterator);
589 EXPECT_FALSE(++iterator);
590 }
591 // Tile sized iterators. These should find only one pixel ref.
592 {
593 PicturePileImpl::LazyPixelRefIterator iterator(
594 gfx::Rect(0, 0, 1024, 1024),
595 1.0,
596 pile);
597 EXPECT_TRUE(iterator);
598 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
599 EXPECT_TRUE(++iterator);
600 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
601 EXPECT_TRUE(++iterator);
602 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
603 EXPECT_FALSE(++iterator);
604 }
605 {
606 PicturePileImpl::LazyPixelRefIterator iterator(
607 gfx::Rect(0, 0, 2048, 2048),
608 2.0,
609 pile);
610 EXPECT_TRUE(iterator);
611 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
612 EXPECT_TRUE(++iterator);
613 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
614 EXPECT_TRUE(++iterator);
615 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
616 EXPECT_FALSE(++iterator);
617 }
618 {
619 PicturePileImpl::LazyPixelRefIterator iterator(
620 gfx::Rect(0, 0, 512, 512),
621 0.5,
622 pile);
623 EXPECT_TRUE(iterator);
624 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
625 EXPECT_TRUE(++iterator);
626 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
627 EXPECT_TRUE(++iterator);
628 EXPECT_TRUE(*iterator == lazy_pixel_ref.get());
629 EXPECT_FALSE(++iterator);
630 }
631
632 // Copy test.
633 PicturePileImpl::LazyPixelRefIterator iterator(
634 gfx::Rect(0, 0, 1024, 1024),
635 1.0,
636 pile);
637 EXPECT_TRUE(iterator);
638 EXPECT_TRUE(++iterator);
639
640 // copy now points to the same spot as iterator,
641 // but both can be incremented independently.
642 PicturePileImpl::LazyPixelRefIterator copy = iterator;
643 EXPECT_TRUE(++iterator);
644 EXPECT_FALSE(++iterator);
645
646 EXPECT_TRUE(copy);
647 EXPECT_TRUE(++copy);
648 EXPECT_FALSE(++copy);
649 }
137 650
138 } // namespace 651 } // namespace
139 } // namespace cc 652 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698