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

Side by Side Diff: cc/trees/damage_tracker_unittest.cc

Issue 2124983003: cc: Remove uses of FilterOperations::GetOutsets in unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | cc/trees/occlusion_tracker_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
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/trees/damage_tracker.h" 5 #include "cc/trees/damage_tracker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "cc/base/math_util.h" 9 #include "cc/base/math_util.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); 532 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about));
533 } 533 }
534 534
535 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { 535 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) {
536 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 536 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
537 LayerImpl* surface = root->test_properties()->children[0]; 537 LayerImpl* surface = root->test_properties()->children[0];
538 LayerImpl* child = surface->test_properties()->children[0]; 538 LayerImpl* child = surface->test_properties()->children[0];
539 539
540 FilterOperations filters; 540 FilterOperations filters;
541 filters.Append(FilterOperation::CreateBlurFilter(5.f)); 541 filters.Append(FilterOperation::CreateBlurFilter(5.f));
542 int outset_top, outset_right, outset_bottom, outset_left;
543 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
544 542
545 // Setting the filter will damage the whole surface. 543 // Setting the filter will damage the whole surface.
546 ClearDamageForAllSurfaces(root); 544 ClearDamageForAllSurfaces(root);
547 surface->SetFilters(filters); 545 surface->SetFilters(filters);
548 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 546 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
549 EmulateDrawingOneFrame(root); 547 EmulateDrawingOneFrame(root);
550 548
551 // Setting the update rect should cause the corresponding damage to the 549 // Setting the update rect should cause the corresponding damage to the
552 // surface, blurred based on the size of the blur filter. 550 // surface, blurred based on the size of the blur filter.
553 ClearDamageForAllSurfaces(root); 551 ClearDamageForAllSurfaces(root);
554 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); 552 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4));
555 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 553 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
556 EmulateDrawingOneFrame(root); 554 EmulateDrawingOneFrame(root);
557 555
558 // Damage position on the surface should be: position of update_rect (1, 2) 556 // Damage position on the surface should be: position of update_rect (1, 2)
559 // relative to the child (300, 300), but expanded by the blur outsets. 557 // relative to the child (300, 300), but expanded by the blur outsets
558 // (15, since the blur radius is 5).
560 gfx::Rect root_damage_rect = 559 gfx::Rect root_damage_rect =
561 root->render_surface()->damage_tracker()->current_damage_rect(); 560 root->render_surface()->damage_tracker()->current_damage_rect();
562 gfx::Rect expected_damage_rect = gfx::Rect(301, 302, 3, 4); 561 EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect);
563
564 expected_damage_rect.Inset(-outset_left,
565 -outset_top,
566 -outset_right,
567 -outset_bottom);
568 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
569 } 562 }
570 563
571 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { 564 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) {
572 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 565 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
573 LayerImpl* child = root->test_properties()->children[0]; 566 LayerImpl* child = root->test_properties()->children[0];
574 gfx::Rect root_damage_rect, child_damage_rect; 567 gfx::Rect root_damage_rect, child_damage_rect;
575 568
576 // Allow us to set damage on child too. 569 // Allow us to set damage on child too.
577 child->SetDrawsContent(true); 570 child->SetDrawsContent(true);
578 571
579 FilterOperations filters; 572 FilterOperations filters;
580 filters.Append(FilterOperation::CreateReferenceFilter( 573 filters.Append(FilterOperation::CreateReferenceFilter(
581 SkBlurImageFilter::Make(2, 2, nullptr))); 574 SkBlurImageFilter::Make(2, 2, nullptr)));
582 int outset_top, outset_right, outset_bottom, outset_left;
583 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
584 575
585 // Setting the filter will damage the whole surface. 576 // Setting the filter will damage the whole surface.
586 ClearDamageForAllSurfaces(root); 577 ClearDamageForAllSurfaces(root);
587 child->test_properties()->force_render_surface = true; 578 child->test_properties()->force_render_surface = true;
588 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 579 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
589 EmulateDrawingOneFrame(root); 580 EmulateDrawingOneFrame(root);
590 child->OnFilterAnimated(filters); 581 child->OnFilterAnimated(filters);
591 EmulateDrawingOneFrame(root); 582 EmulateDrawingOneFrame(root);
592 root_damage_rect = 583 root_damage_rect =
593 root->render_surface()->damage_tracker()->current_damage_rect(); 584 root->render_surface()->damage_tracker()->current_damage_rect();
594 child_damage_rect = 585 child_damage_rect =
595 child->render_surface()->damage_tracker()->current_damage_rect(); 586 child->render_surface()->damage_tracker()->current_damage_rect();
596 EXPECT_EQ(gfx::Rect(100 - outset_left, 100 - outset_top, 587
597 30 + outset_left + outset_right, 588 // gfx::Rect(100, 100, 30, 30), expanded by 6px for the 2px blur filter.
598 30 + outset_top + outset_bottom), 589 EXPECT_EQ(gfx::Rect(94, 94, 42, 42), root_damage_rect);
599 root_damage_rect); 590
600 EXPECT_EQ( 591 // gfx::Rect(0, 0, 30, 30), expanded by 6px for the 2px blur filter.
601 gfx::Rect(-outset_left, -outset_top, 30 + (outset_left + outset_right), 592 EXPECT_EQ(gfx::Rect(-6, -6, 42, 42), child_damage_rect);
602 30 + (outset_top + outset_bottom)),
603 child_damage_rect);
604 593
605 // CASE 1: Setting the update rect should damage the whole surface (for now) 594 // CASE 1: Setting the update rect should damage the whole surface (for now)
606 ClearDamageForAllSurfaces(root); 595 ClearDamageForAllSurfaces(root);
607 child->SetUpdateRect(gfx::Rect(1, 1)); 596 child->SetUpdateRect(gfx::Rect(1, 1));
608 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 597 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
609 EmulateDrawingOneFrame(root); 598 EmulateDrawingOneFrame(root);
610 599
611 root_damage_rect = 600 root_damage_rect =
612 root->render_surface()->damage_tracker()->current_damage_rect(); 601 root->render_surface()->damage_tracker()->current_damage_rect();
613 child_damage_rect = 602 child_damage_rect =
614 child->render_surface()->damage_tracker()->current_damage_rect(); 603 child->render_surface()->damage_tracker()->current_damage_rect();
615 604
616 int expect_width = 1 + outset_left + outset_right; 605 // gfx::Rect(100, 100, 1, 1), expanded by 6px for the 2px blur filter.
617 int expect_height = 1 + outset_top + outset_bottom; 606 EXPECT_EQ(gfx::Rect(94, 94, 13, 13), root_damage_rect);
618 EXPECT_EQ(gfx::Rect(100 - outset_left, 100 - outset_top, expect_width, 607
619 expect_height), 608 // gfx::Rect(0, 0, 1, 1), expanded by 6px for the 2px blur filter.
620 root_damage_rect); 609 EXPECT_EQ(gfx::Rect(-6, -6, 13, 13), child_damage_rect);
621 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height),
622 child_damage_rect);
623 } 610 }
624 611
625 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { 612 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) {
626 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 613 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
627 LayerImpl* child = root->test_properties()->children[0]; 614 LayerImpl* child = root->test_properties()->children[0];
628 gfx::Rect root_damage_rect, child_damage_rect; 615 gfx::Rect root_damage_rect, child_damage_rect;
629 616
630 // Allow us to set damage on child too. 617 // Allow us to set damage on child too.
631 child->SetDrawsContent(true); 618 child->SetDrawsContent(true);
632 619
633 FilterOperations filters; 620 FilterOperations filters;
634 filters.Append(FilterOperation::CreateReferenceFilter( 621 filters.Append(FilterOperation::CreateReferenceFilter(
635 SkBlurImageFilter::Make(2, 2, nullptr))); 622 SkBlurImageFilter::Make(2, 2, nullptr)));
636 int outset_top, outset_right, outset_bottom, outset_left;
637 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
638 623
639 // Setting the filter will damage the whole surface. 624 // Setting the filter will damage the whole surface.
640 gfx::Transform transform; 625 gfx::Transform transform;
641 transform.RotateAboutYAxis(60); 626 transform.RotateAboutYAxis(60);
642 ClearDamageForAllSurfaces(root); 627 ClearDamageForAllSurfaces(root);
643 child->test_properties()->force_render_surface = true; 628 child->test_properties()->force_render_surface = true;
644 child->SetTransform(transform); 629 child->SetTransform(transform);
645 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 630 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
646 EmulateDrawingOneFrame(root); 631 EmulateDrawingOneFrame(root);
647 child->OnFilterAnimated(filters); 632 child->OnFilterAnimated(filters);
648 EmulateDrawingOneFrame(root); 633 EmulateDrawingOneFrame(root);
649 root_damage_rect = 634 root_damage_rect =
650 root->render_surface()->damage_tracker()->current_damage_rect(); 635 root->render_surface()->damage_tracker()->current_damage_rect();
651 child_damage_rect = 636 child_damage_rect =
652 child->render_surface()->damage_tracker()->current_damage_rect(); 637 child->render_surface()->damage_tracker()->current_damage_rect();
653 int rotated_outset_left = outset_left / 2; 638
654 int expected_rotated_width = (30 + outset_left + outset_right) / 2; 639 // Blur outset is 6px for a 2px blur.
655 gfx::Rect expected_root_damage(100 - rotated_outset_left, 100 - outset_top, 640 int blur_outset = 6;
656 expected_rotated_width, 641 int rotated_outset_left = blur_outset / 2;
657 30 + outset_top + outset_bottom); 642 int expected_rotated_width = (30 + 2 * blur_outset) / 2;
643 gfx::Rect expected_root_damage(100 - rotated_outset_left, 100 - blur_outset,
644 expected_rotated_width, 30 + 2 * blur_outset);
658 expected_root_damage.Union(gfx::Rect(100, 100, 30, 30)); 645 expected_root_damage.Union(gfx::Rect(100, 100, 30, 30));
659 EXPECT_EQ(expected_root_damage, root_damage_rect); 646 EXPECT_EQ(expected_root_damage, root_damage_rect);
660 EXPECT_EQ( 647 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, 30 + 2 * blur_outset,
661 gfx::Rect(-outset_left, -outset_top, 30 + (outset_left + outset_right), 648 30 + 2 * blur_outset),
662 30 + (outset_top + outset_bottom)), 649 child_damage_rect);
663 child_damage_rect);
664 650
665 // Setting the update rect should damage the whole surface (for now) 651 // Setting the update rect should damage the whole surface (for now)
666 ClearDamageForAllSurfaces(root); 652 ClearDamageForAllSurfaces(root);
667 child->SetUpdateRect(gfx::Rect(30, 30)); 653 child->SetUpdateRect(gfx::Rect(30, 30));
668 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 654 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
669 EmulateDrawingOneFrame(root); 655 EmulateDrawingOneFrame(root);
670 656
671 root_damage_rect = 657 root_damage_rect =
672 root->render_surface()->damage_tracker()->current_damage_rect(); 658 root->render_surface()->damage_tracker()->current_damage_rect();
673 child_damage_rect = 659 child_damage_rect =
674 child->render_surface()->damage_tracker()->current_damage_rect(); 660 child->render_surface()->damage_tracker()->current_damage_rect();
675 661
676 int expect_width = 30 + outset_left + outset_right; 662 int expect_width = 30 + 2 * blur_outset;
677 int expect_height = 30 + outset_top + outset_bottom; 663 int expect_height = 30 + 2 * blur_outset;
678 EXPECT_EQ(gfx::Rect(100 - outset_left / 2, 100 - outset_top, expect_width / 2, 664 EXPECT_EQ(gfx::Rect(100 - blur_outset / 2, 100 - blur_outset,
679 expect_height), 665 expect_width / 2, expect_height),
680 root_damage_rect); 666 root_damage_rect);
681 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height), 667 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, expect_width, expect_height),
682 child_damage_rect); 668 child_damage_rect);
683 } 669 }
684 670
685 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { 671 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) {
686 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 672 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
687 LayerImpl* child1 = root->test_properties()->children[0]; 673 LayerImpl* child1 = root->test_properties()->children[0];
688 LayerImpl* child2 = root->test_properties()->children[1]; 674 LayerImpl* child2 = root->test_properties()->children[1];
689 675
690 // Allow us to set damage on child1 too. 676 // Allow us to set damage on child1 too.
691 child1->SetDrawsContent(true); 677 child1->SetDrawsContent(true);
692 678
693 FilterOperations filters; 679 FilterOperations filters;
694 filters.Append(FilterOperation::CreateBlurFilter(2.f)); 680 filters.Append(FilterOperation::CreateBlurFilter(2.f));
695 int outset_top, outset_right, outset_bottom, outset_left;
696 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
697 681
698 // Setting the filter will damage the whole surface. 682 // Setting the filter will damage the whole surface.
699 ClearDamageForAllSurfaces(root); 683 ClearDamageForAllSurfaces(root);
700 child1->test_properties()->background_filters = filters; 684 child1->test_properties()->background_filters = filters;
701 child1->NoteLayerPropertyChanged(); 685 child1->NoteLayerPropertyChanged();
702 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 686 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
703 EmulateDrawingOneFrame(root); 687 EmulateDrawingOneFrame(root);
704 688
705 // CASE 1: Setting the update rect should cause the corresponding damage to 689 // CASE 1: Setting the update rect should cause the corresponding damage to
706 // the surface, blurred based on the size of the child's background 690 // the surface, blurred based on the size of the child's background
707 // blur filter. Note that child1's render surface has a size of 691 // blur filter. Note that child1's render surface has a size of
708 // 206x208 due to contributions from grand_child1 and grand_child2. 692 // 206x208 due to contributions from grand_child1 and grand_child2.
709 ClearDamageForAllSurfaces(root); 693 ClearDamageForAllSurfaces(root);
710 root->SetUpdateRect(gfx::Rect(297, 297, 2, 2)); 694 root->SetUpdateRect(gfx::Rect(297, 297, 2, 2));
711 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 695 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
712 EmulateDrawingOneFrame(root); 696 EmulateDrawingOneFrame(root);
713 697
714 gfx::Rect root_damage_rect = 698 gfx::Rect root_damage_rect =
715 root->render_surface()->damage_tracker()->current_damage_rect(); 699 root->render_surface()->damage_tracker()->current_damage_rect();
716 // Damage position on the surface should be a composition of the damage on 700 // Damage position on the surface should be a composition of the damage on
717 // the root and on child2. Damage on the root should be: position of 701 // the root and on child2. Damage on the root should be: position of
718 // update_rect (297, 297), but expanded by the blur outsets. 702 // update_rect (297, 297), but expanded by the blur outsets.
719 gfx::Rect expected_damage_rect = gfx::Rect(297, 297, 2, 2); 703 gfx::Rect expected_damage_rect = gfx::Rect(297, 297, 2, 2);
720 704
721 expected_damage_rect.Inset(-outset_left, 705 // 6px spread for a 2px blur.
722 -outset_top, 706 expected_damage_rect.Inset(-6, -6, -6, -6);
723 -outset_right,
724 -outset_bottom);
725 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); 707 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
726 708
727 // CASE 2: Setting the update rect should cause the corresponding damage to 709 // CASE 2: Setting the update rect should cause the corresponding damage to
728 // the surface, blurred based on the size of the child's background 710 // the surface, blurred based on the size of the child's background
729 // blur filter. Since the damage extends to the right/bottom outside 711 // blur filter. Since the damage extends to the right/bottom outside
730 // of the blurred layer, only the left/top should end up expanded. 712 // of the blurred layer, only the left/top should end up expanded.
731 ClearDamageForAllSurfaces(root); 713 ClearDamageForAllSurfaces(root);
732 root->SetUpdateRect(gfx::Rect(297, 297, 30, 30)); 714 root->SetUpdateRect(gfx::Rect(297, 297, 30, 30));
733 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 715 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
734 EmulateDrawingOneFrame(root); 716 EmulateDrawingOneFrame(root);
735 717
736 root_damage_rect = 718 root_damage_rect =
737 root->render_surface()->damage_tracker()->current_damage_rect(); 719 root->render_surface()->damage_tracker()->current_damage_rect();
738 // Damage position on the surface should be a composition of the damage on 720 // Damage position on the surface should be a composition of the damage on
739 // the root and on child2. Damage on the root should be: position of 721 // the root and on child2. Damage on the root should be: position of
740 // update_rect (297, 297), but expanded on the left/top by the blur outsets. 722 // update_rect (297, 297), but expanded on the left/top by the blur outsets.
741 expected_damage_rect = gfx::Rect(297, 297, 30, 30); 723 expected_damage_rect = gfx::Rect(297, 297, 30, 30);
742 724
743 expected_damage_rect.Inset(-outset_left, 725 // 6px spread for a 2px blur.
744 -outset_top, 726 expected_damage_rect.Inset(-6, -6, 0, 0);
745 0,
746 0);
747 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); 727 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
748 728
749 // CASE 3: Setting this update rect outside the blurred content_bounds of the 729 // CASE 3: Setting this update rect outside the blurred content_bounds of the
750 // blurred child1 will not cause it to be expanded. 730 // blurred child1 will not cause it to be expanded.
751 ClearDamageForAllSurfaces(root); 731 ClearDamageForAllSurfaces(root);
752 root->SetUpdateRect(gfx::Rect(30, 30, 2, 2)); 732 root->SetUpdateRect(gfx::Rect(30, 30, 2, 2));
753 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 733 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
754 EmulateDrawingOneFrame(root); 734 EmulateDrawingOneFrame(root);
755 735
756 root_damage_rect = 736 root_damage_rect =
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 gfx::Rect root_damage_rect = 1618 gfx::Rect root_damage_rect =
1639 root->render_surface()->damage_tracker()->current_damage_rect(); 1619 root->render_surface()->damage_tracker()->current_damage_rect();
1640 gfx::Rect damage_we_care_about = gfx::Rect(i, i); 1620 gfx::Rect damage_we_care_about = gfx::Rect(i, i);
1641 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); 1621 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right());
1642 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); 1622 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom());
1643 } 1623 }
1644 } 1624 }
1645 1625
1646 } // namespace 1626 } // namespace
1647 } // namespace cc 1627 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/trees/occlusion_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698