OLD | NEW |
---|---|
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 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 LayerImpl* child = root->children()[0]; | 627 LayerImpl* child = root->children()[0]; |
628 gfx::Rect root_damage_rect, child_damage_rect; | 628 gfx::Rect root_damage_rect, child_damage_rect; |
629 | 629 |
630 // Allow us to set damage on child too. | 630 // Allow us to set damage on child too. |
631 child->SetDrawsContent(true); | 631 child->SetDrawsContent(true); |
632 | 632 |
633 FilterOperations filters; | 633 FilterOperations filters; |
634 filters.Append(FilterOperation::CreateReferenceFilter( | 634 filters.Append(FilterOperation::CreateReferenceFilter( |
635 SkBlurImageFilter::Make(2, 2, nullptr))); | 635 SkBlurImageFilter::Make(2, 2, nullptr))); |
636 int outset_top, outset_right, outset_bottom, outset_left; | 636 int outset_top, outset_right, outset_bottom, outset_left; |
637 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); | 637 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); |
Stephen White
2016/06/01 15:50:00
Out of curiosity, why are we still using outsets h
jbroman
2016/06/01 15:53:37
They're used to constructed expected values, presu
| |
638 | 638 |
639 // Setting the filter will damage the whole surface. | 639 // Setting the filter will damage the whole surface. |
640 gfx::Transform transform; | 640 gfx::Transform transform; |
641 transform.RotateAboutYAxis(60); | 641 transform.RotateAboutYAxis(60); |
642 ClearDamageForAllSurfaces(root); | 642 ClearDamageForAllSurfaces(root); |
643 child->test_properties()->force_render_surface = true; | 643 child->test_properties()->force_render_surface = true; |
644 child->SetTransform(transform); | 644 child->SetTransform(transform); |
645 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 645 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
646 EmulateDrawingOneFrame(root); | 646 EmulateDrawingOneFrame(root); |
647 child->OnFilterAnimated(filters); | 647 child->OnFilterAnimated(filters); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); | 696 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); |
697 | 697 |
698 // Setting the filter will damage the whole surface. | 698 // Setting the filter will damage the whole surface. |
699 ClearDamageForAllSurfaces(root); | 699 ClearDamageForAllSurfaces(root); |
700 child1->SetBackgroundFilters(filters); | 700 child1->SetBackgroundFilters(filters); |
701 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 701 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
702 EmulateDrawingOneFrame(root); | 702 EmulateDrawingOneFrame(root); |
703 | 703 |
704 // CASE 1: Setting the update rect should cause the corresponding damage to | 704 // CASE 1: Setting the update rect should cause the corresponding damage to |
705 // the surface, blurred based on the size of the child's background | 705 // the surface, blurred based on the size of the child's background |
706 // blur filter. | 706 // blur filter. Note that child1's render surface has a size of |
707 // 206x208 due to contributions from grand_child1 and grand_child2. | |
jbroman
2016/06/01 14:32:28
I was confused until I realized why the surface wa
| |
707 ClearDamageForAllSurfaces(root); | 708 ClearDamageForAllSurfaces(root); |
708 root->SetUpdateRect(gfx::Rect(297, 297, 2, 2)); | 709 root->SetUpdateRect(gfx::Rect(297, 297, 2, 2)); |
709 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 710 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
710 EmulateDrawingOneFrame(root); | 711 EmulateDrawingOneFrame(root); |
711 | 712 |
712 gfx::Rect root_damage_rect = | 713 gfx::Rect root_damage_rect = |
713 root->render_surface()->damage_tracker()->current_damage_rect(); | 714 root->render_surface()->damage_tracker()->current_damage_rect(); |
714 // Damage position on the surface should be a composition of the damage on | 715 // Damage position on the surface should be a composition of the damage on |
715 // the root and on child2. Damage on the root should be: position of | 716 // the root and on child2. Damage on the root should be: position of |
716 // update_rect (297, 297), but expanded by the blur outsets. | 717 // update_rect (297, 297), but expanded by the blur outsets. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 // CASE 4: Setting this update rect inside the blurred content_bounds but | 763 // CASE 4: Setting this update rect inside the blurred content_bounds but |
763 // outside the original content_bounds of the blurred child1 will | 764 // outside the original content_bounds of the blurred child1 will |
764 // cause it to be expanded. | 765 // cause it to be expanded. |
765 ClearDamageForAllSurfaces(root); | 766 ClearDamageForAllSurfaces(root); |
766 root->SetUpdateRect(gfx::Rect(99, 99, 1, 1)); | 767 root->SetUpdateRect(gfx::Rect(99, 99, 1, 1)); |
767 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 768 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
768 EmulateDrawingOneFrame(root); | 769 EmulateDrawingOneFrame(root); |
769 | 770 |
770 root_damage_rect = | 771 root_damage_rect = |
771 root->render_surface()->damage_tracker()->current_damage_rect(); | 772 root->render_surface()->damage_tracker()->current_damage_rect(); |
772 // Damage on the root should be: position of update_rect (99, 99), expanded by | 773 // Damage on the root should be: the originally damaged rect (99,99 1x1) |
773 // the blurring on child1, but since it is 1 pixel outside the layer, the | 774 // plus the rect that can influence with a 2px blur (93,93 13x13) intersected |
774 // expanding should be reduced by 1. | 775 // with the surface rect (100,100 206x208). So no additional damage occurs |
775 expected_damage_rect = gfx::Rect(99, 99, 1, 1); | 776 // above or to the left, but there is additional damage within the blurred |
776 | 777 // area. |
777 expected_damage_rect.Inset(-outset_left + 1, | 778 expected_damage_rect = gfx::Rect(99, 99, 7, 7); |
778 -outset_top + 1, | |
779 -outset_right, | |
780 -outset_bottom); | |
781 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 779 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
782 | 780 |
783 // CASE 5: Setting the update rect on child2, which is above child1, will | 781 // CASE 5: Setting the update rect on child2, which is above child1, will |
784 // not get blurred by child1, so it does not need to get expanded. | 782 // not get blurred by child1, so it does not need to get expanded. |
785 ClearDamageForAllSurfaces(root); | 783 ClearDamageForAllSurfaces(root); |
786 child2->SetUpdateRect(gfx::Rect(1, 1)); | 784 child2->SetUpdateRect(gfx::Rect(1, 1)); |
787 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 785 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
788 EmulateDrawingOneFrame(root); | 786 EmulateDrawingOneFrame(root); |
789 | 787 |
790 root_damage_rect = | 788 root_damage_rect = |
791 root->render_surface()->damage_tracker()->current_damage_rect(); | 789 root->render_surface()->damage_tracker()->current_damage_rect(); |
792 // Damage on child2 should be: position of update_rect offset by the child's | 790 // Damage on child2 should be: position of update_rect offset by the child's |
793 // position (11, 11), and not expanded by anything. | 791 // position (11, 11), and not expanded by anything. |
794 expected_damage_rect = gfx::Rect(11, 11, 1, 1); | 792 expected_damage_rect = gfx::Rect(11, 11, 1, 1); |
795 | 793 |
796 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 794 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
797 | 795 |
798 // CASE 6: Setting the update rect on child1 will also blur the damage, so | 796 // CASE 6: Setting the update rect on child1 will also blur the damage, so |
799 // that any pixels needed for the blur are redrawn in the current | 797 // that any pixels needed for the blur are redrawn in the current |
800 // frame. | 798 // frame. |
801 ClearDamageForAllSurfaces(root); | 799 ClearDamageForAllSurfaces(root); |
802 child1->SetUpdateRect(gfx::Rect(1, 1)); | 800 child1->SetUpdateRect(gfx::Rect(1, 1)); |
803 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 801 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
804 EmulateDrawingOneFrame(root); | 802 EmulateDrawingOneFrame(root); |
805 | 803 |
806 root_damage_rect = | 804 root_damage_rect = |
807 root->render_surface()->damage_tracker()->current_damage_rect(); | 805 root->render_surface()->damage_tracker()->current_damage_rect(); |
808 // Damage on child1 should be: position of update_rect offset by the child's | 806 // Damage on child1 should be: position of update_rect offset by the child's |
809 // position (100, 100), and expanded by the damage. | 807 // position (100, 100), and expanded by the damage. |
810 expected_damage_rect = gfx::Rect(100, 100, 1, 1); | |
811 | 808 |
812 expected_damage_rect.Inset(-outset_left, | 809 // Damage should be (0,0 1x1), offset by the 100,100 offset of child1 in |
813 -outset_top, | 810 // root, and expanded 6px for the 2px blur (i.e., 94,94 13x13), but there |
814 -outset_right, | 811 // should be no damage outside child1 (i.e. none above or to the left of |
815 -outset_bottom); | 812 // 100,100. |
813 expected_damage_rect = gfx::Rect(100, 100, 7, 7); | |
816 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 814 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
817 } | 815 } |
818 | 816 |
819 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingLayer) { | 817 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingLayer) { |
820 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 818 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
821 LayerImpl* child1 = root->children()[0]; | 819 LayerImpl* child1 = root->children()[0]; |
822 | 820 |
823 // CASE 1: Adding a new layer should cause the appropriate damage. | 821 // CASE 1: Adding a new layer should cause the appropriate damage. |
824 // | 822 // |
825 ClearDamageForAllSurfaces(root); | 823 ClearDamageForAllSurfaces(root); |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1627 gfx::Rect root_damage_rect = | 1625 gfx::Rect root_damage_rect = |
1628 root->render_surface()->damage_tracker()->current_damage_rect(); | 1626 root->render_surface()->damage_tracker()->current_damage_rect(); |
1629 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1627 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
1630 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1628 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
1631 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1629 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
1632 } | 1630 } |
1633 } | 1631 } |
1634 | 1632 |
1635 } // namespace | 1633 } // namespace |
1636 } // namespace cc | 1634 } // namespace cc |
OLD | NEW |