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 "cc/base/math_util.h" | 7 #include "cc/base/math_util.h" |
8 #include "cc/layers/layer_impl.h" | 8 #include "cc/layers/layer_impl.h" |
9 #include "cc/output/filter_operation.h" | 9 #include "cc/output/filter_operation.h" |
10 #include "cc/output/filter_operations.h" | 10 #include "cc/output/filter_operations.h" |
11 #include "cc/test/fake_impl_proxy.h" | 11 #include "cc/test/fake_impl_proxy.h" |
12 #include "cc/test/fake_layer_tree_host_impl.h" | 12 #include "cc/test/fake_layer_tree_host_impl.h" |
13 #include "cc/test/geometry_test_utils.h" | 13 #include "cc/test/geometry_test_utils.h" |
14 #include "cc/test/test_shared_bitmap_manager.h" | 14 #include "cc/test/test_shared_bitmap_manager.h" |
15 #include "cc/trees/layer_tree_host_common.h" | 15 #include "cc/trees/layer_tree_host_common.h" |
16 #include "cc/trees/single_thread_proxy.h" | 16 #include "cc/trees/single_thread_proxy.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 18 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
19 #include "ui/gfx/geometry/quad_f.h" | 19 #include "ui/gfx/geometry/quad_f.h" |
20 #include "ui/gfx/geometry/rect_conversions.h" | 20 #include "ui/gfx/geometry/rect_conversions.h" |
21 | 21 |
22 namespace cc { | 22 namespace cc { |
23 namespace { | 23 namespace { |
24 | 24 |
25 void ExecuteCalculateDrawProperties(LayerImpl* root, | 25 void ExecuteCalculateDrawProperties(LayerImpl* root, |
26 LayerImplList& render_surface_layer_list) { | 26 LayerImplList* render_surface_layer_list) { |
27 // Sanity check: The test itself should create the root layer's render | 27 // Sanity check: The test itself should create the root layer's render |
28 // surface, so that the surface (and its damage tracker) can | 28 // surface, so that the surface (and its damage tracker) can |
29 // persist across multiple calls to this function. | 29 // persist across multiple calls to this function. |
30 ASSERT_TRUE(root->render_surface()); | 30 ASSERT_TRUE(root->render_surface()); |
31 ASSERT_FALSE(render_surface_layer_list.size()); | 31 ASSERT_FALSE(render_surface_layer_list->size()); |
32 | 32 |
33 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 33 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
34 root, root->bounds(), &render_surface_layer_list); | 34 root, root->bounds(), render_surface_layer_list); |
35 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 35 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
36 } | 36 } |
37 | 37 |
38 void ClearDamageForAllSurfaces(LayerImpl* layer) { | 38 void ClearDamageForAllSurfaces(LayerImpl* layer) { |
39 if (layer->render_surface()) | 39 if (layer->render_surface()) |
40 layer->render_surface()->damage_tracker()->DidDrawDamagedArea(); | 40 layer->render_surface()->damage_tracker()->DidDrawDamagedArea(); |
41 | 41 |
42 // Recursively clear damage for any existing surface. | 42 // Recursively clear damage for any existing surface. |
43 for (size_t i = 0; i < layer->children().size(); ++i) | 43 for (size_t i = 0; i < layer->children().size(); ++i) |
44 ClearDamageForAllSurfaces(layer->children()[i]); | 44 ClearDamageForAllSurfaces(layer->children()[i]); |
45 } | 45 } |
46 | 46 |
47 void EmulateDrawingOneFrame(LayerImpl* root) { | 47 void EmulateDrawingOneFrame(LayerImpl* root) { |
48 // This emulates only steps that are relevant to testing the damage tracker: | 48 // This emulates only steps that are relevant to testing the damage tracker: |
49 // 1. computing the render passes and layerlists | 49 // 1. computing the render passes and layerlists |
50 // 2. updating all damage trackers in the correct order | 50 // 2. updating all damage trackers in the correct order |
51 // 3. resetting all update_rects and property_changed flags for all layers | 51 // 3. resetting all update_rects and property_changed flags for all layers |
52 // and surfaces. | 52 // and surfaces. |
53 | 53 |
54 LayerImplList render_surface_layer_list; | 54 LayerImplList render_surface_layer_list; |
55 ExecuteCalculateDrawProperties(root, render_surface_layer_list); | 55 ExecuteCalculateDrawProperties(root, &render_surface_layer_list); |
56 | 56 |
57 // Iterate back-to-front, so that damage correctly propagates from descendant | 57 // Iterate back-to-front, so that damage correctly propagates from descendant |
58 // surfaces to ancestors. | 58 // surfaces to ancestors. |
59 for (int i = render_surface_layer_list.size() - 1; i >= 0; --i) { | 59 for (int i = render_surface_layer_list.size() - 1; i >= 0; --i) { |
60 RenderSurfaceImpl* target_surface = | 60 RenderSurfaceImpl* target_surface = |
61 render_surface_layer_list[i]->render_surface(); | 61 render_surface_layer_list[i]->render_surface(); |
62 target_surface->damage_tracker()->UpdateDamageTrackingState( | 62 target_surface->damage_tracker()->UpdateDamageTrackingState( |
63 target_surface->layer_list(), | 63 target_surface->layer_list(), |
64 target_surface->OwningLayerId(), | 64 target_surface->OwningLayerId(), |
65 target_surface->SurfacePropertyChangedOnlyFromDescendant(), | 65 target_surface->SurfacePropertyChangedOnlyFromDescendant(), |
66 target_surface->content_rect(), | 66 target_surface->content_rect(), |
67 render_surface_layer_list[i]->mask_layer(), | 67 render_surface_layer_list[i]->mask_layer(), |
68 render_surface_layer_list[i]->filters()); | 68 render_surface_layer_list[i]->filters()); |
69 } | 69 } |
70 | 70 |
71 root->ResetAllChangeTrackingForSubtree(); | 71 root->ResetAllChangeTrackingForSubtree(); |
72 } | 72 } |
73 | 73 |
74 class DamageTrackerTest : public testing::Test { | 74 class DamageTrackerTest : public testing::Test { |
75 public: | 75 public: |
76 DamageTrackerTest() : host_impl_(&proxy_, &shared_bitmap_manager_) {} | 76 DamageTrackerTest() : host_impl_(&proxy_, &shared_bitmap_manager_) {} |
77 | 77 |
78 scoped_ptr<LayerImpl> CreateTestTreeWithOneSurface() { | 78 scoped_ptr<LayerImpl> CreateTestTreeWithOneSurface() { |
79 scoped_ptr<LayerImpl> root = | 79 scoped_ptr<LayerImpl> root = |
80 LayerImpl::Create(host_impl_.active_tree(), 1); | 80 LayerImpl::Create(host_impl_.active_tree(), 1); |
81 scoped_ptr<LayerImpl> child = | 81 scoped_ptr<LayerImpl> child = |
82 LayerImpl::Create(host_impl_.active_tree(), 2); | 82 LayerImpl::Create(host_impl_.active_tree(), 2); |
83 | 83 |
84 root->SetPosition(gfx::PointF()); | 84 root->SetPosition(gfx::PointF()); |
85 root->SetAnchorPoint(gfx::PointF()); | 85 root->SetTransformOrigin(gfx::Point3F()); |
86 root->SetBounds(gfx::Size(500, 500)); | 86 root->SetBounds(gfx::Size(500, 500)); |
87 root->SetContentBounds(gfx::Size(500, 500)); | 87 root->SetContentBounds(gfx::Size(500, 500)); |
88 root->SetDrawsContent(true); | 88 root->SetDrawsContent(true); |
89 root->CreateRenderSurface(); | 89 root->CreateRenderSurface(); |
90 root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500)); | 90 root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500)); |
91 | 91 |
92 child->SetPosition(gfx::PointF(100.f, 100.f)); | 92 child->SetPosition(gfx::PointF(100.f, 100.f)); |
93 child->SetAnchorPoint(gfx::PointF()); | 93 child->SetTransformOrigin(gfx::Point3F()); |
94 child->SetBounds(gfx::Size(30, 30)); | 94 child->SetBounds(gfx::Size(30, 30)); |
95 child->SetContentBounds(gfx::Size(30, 30)); | 95 child->SetContentBounds(gfx::Size(30, 30)); |
96 child->SetDrawsContent(true); | 96 child->SetDrawsContent(true); |
97 root->AddChild(child.Pass()); | 97 root->AddChild(child.Pass()); |
98 | 98 |
99 return root.Pass(); | 99 return root.Pass(); |
100 } | 100 } |
101 | 101 |
102 scoped_ptr<LayerImpl> CreateTestTreeWithTwoSurfaces() { | 102 scoped_ptr<LayerImpl> CreateTestTreeWithTwoSurfaces() { |
103 // This test tree has two render surfaces: one for the root, and one for | 103 // This test tree has two render surfaces: one for the root, and one for |
104 // child1. Additionally, the root has a second child layer, and child1 has | 104 // child1. Additionally, the root has a second child layer, and child1 has |
105 // two children of its own. | 105 // two children of its own. |
106 | 106 |
107 scoped_ptr<LayerImpl> root = | 107 scoped_ptr<LayerImpl> root = |
108 LayerImpl::Create(host_impl_.active_tree(), 1); | 108 LayerImpl::Create(host_impl_.active_tree(), 1); |
109 scoped_ptr<LayerImpl> child1 = | 109 scoped_ptr<LayerImpl> child1 = |
110 LayerImpl::Create(host_impl_.active_tree(), 2); | 110 LayerImpl::Create(host_impl_.active_tree(), 2); |
111 scoped_ptr<LayerImpl> child2 = | 111 scoped_ptr<LayerImpl> child2 = |
112 LayerImpl::Create(host_impl_.active_tree(), 3); | 112 LayerImpl::Create(host_impl_.active_tree(), 3); |
113 scoped_ptr<LayerImpl> grand_child1 = | 113 scoped_ptr<LayerImpl> grand_child1 = |
114 LayerImpl::Create(host_impl_.active_tree(), 4); | 114 LayerImpl::Create(host_impl_.active_tree(), 4); |
115 scoped_ptr<LayerImpl> grand_child2 = | 115 scoped_ptr<LayerImpl> grand_child2 = |
116 LayerImpl::Create(host_impl_.active_tree(), 5); | 116 LayerImpl::Create(host_impl_.active_tree(), 5); |
117 | 117 |
118 root->SetPosition(gfx::PointF()); | 118 root->SetPosition(gfx::PointF()); |
119 root->SetAnchorPoint(gfx::PointF()); | 119 root->SetTransformOrigin(gfx::Point3F()); |
120 root->SetBounds(gfx::Size(500, 500)); | 120 root->SetBounds(gfx::Size(500, 500)); |
121 root->SetContentBounds(gfx::Size(500, 500)); | 121 root->SetContentBounds(gfx::Size(500, 500)); |
122 root->SetDrawsContent(true); | 122 root->SetDrawsContent(true); |
123 root->CreateRenderSurface(); | 123 root->CreateRenderSurface(); |
124 root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500)); | 124 root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500)); |
125 | 125 |
126 child1->SetPosition(gfx::PointF(100.f, 100.f)); | 126 child1->SetPosition(gfx::PointF(100.f, 100.f)); |
127 child1->SetAnchorPoint(gfx::PointF()); | 127 child1->SetTransformOrigin(gfx::Point3F()); |
128 child1->SetBounds(gfx::Size(30, 30)); | 128 child1->SetBounds(gfx::Size(30, 30)); |
129 child1->SetContentBounds(gfx::Size(30, 30)); | 129 child1->SetContentBounds(gfx::Size(30, 30)); |
130 // With a child that draws_content, opacity will cause the layer to create | 130 // With a child that draws_content, opacity will cause the layer to create |
131 // its own RenderSurface. This layer does not draw, but is intended to | 131 // its own RenderSurface. This layer does not draw, but is intended to |
132 // create its own RenderSurface. TODO: setting opacity and | 132 // create its own RenderSurface. TODO: setting opacity and |
133 // ForceRenderSurface may be redundant here. | 133 // ForceRenderSurface may be redundant here. |
134 child1->SetOpacity(0.5f); | 134 child1->SetOpacity(0.5f); |
135 child1->SetDrawsContent(false); | 135 child1->SetDrawsContent(false); |
136 child1->SetForceRenderSurface(true); | 136 child1->SetForceRenderSurface(true); |
137 | 137 |
138 child2->SetPosition(gfx::PointF(11.f, 11.f)); | 138 child2->SetPosition(gfx::PointF(11.f, 11.f)); |
139 child2->SetAnchorPoint(gfx::PointF()); | 139 child2->SetTransformOrigin(gfx::Point3F()); |
140 child2->SetBounds(gfx::Size(18, 18)); | 140 child2->SetBounds(gfx::Size(18, 18)); |
141 child2->SetContentBounds(gfx::Size(18, 18)); | 141 child2->SetContentBounds(gfx::Size(18, 18)); |
142 child2->SetDrawsContent(true); | 142 child2->SetDrawsContent(true); |
143 | 143 |
144 grand_child1->SetPosition(gfx::PointF(200.f, 200.f)); | 144 grand_child1->SetPosition(gfx::PointF(200.f, 200.f)); |
145 grand_child1->SetAnchorPoint(gfx::PointF()); | 145 grand_child1->SetTransformOrigin(gfx::Point3F()); |
146 grand_child1->SetBounds(gfx::Size(6, 8)); | 146 grand_child1->SetBounds(gfx::Size(6, 8)); |
147 grand_child1->SetContentBounds(gfx::Size(6, 8)); | 147 grand_child1->SetContentBounds(gfx::Size(6, 8)); |
148 grand_child1->SetDrawsContent(true); | 148 grand_child1->SetDrawsContent(true); |
149 | 149 |
150 grand_child2->SetPosition(gfx::PointF(190.f, 190.f)); | 150 grand_child2->SetPosition(gfx::PointF(190.f, 190.f)); |
151 grand_child2->SetAnchorPoint(gfx::PointF()); | 151 grand_child2->SetTransformOrigin(gfx::Point3F()); |
152 grand_child2->SetBounds(gfx::Size(6, 8)); | 152 grand_child2->SetBounds(gfx::Size(6, 8)); |
153 grand_child2->SetContentBounds(gfx::Size(6, 8)); | 153 grand_child2->SetContentBounds(gfx::Size(6, 8)); |
154 grand_child2->SetDrawsContent(true); | 154 grand_child2->SetDrawsContent(true); |
155 | 155 |
156 child1->AddChild(grand_child1.Pass()); | 156 child1->AddChild(grand_child1.Pass()); |
157 child1->AddChild(grand_child2.Pass()); | 157 child1->AddChild(grand_child2.Pass()); |
158 root->AddChild(child1.Pass()); | 158 root->AddChild(child1.Pass()); |
159 root->AddChild(child2.Pass()); | 159 root->AddChild(child2.Pass()); |
160 | 160 |
161 return root.Pass(); | 161 return root.Pass(); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 // If a layer is transformed, the damage rect should still enclose the entire | 412 // If a layer is transformed, the damage rect should still enclose the entire |
413 // transformed layer. | 413 // transformed layer. |
414 | 414 |
415 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 415 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
416 LayerImpl* child = root->children()[0]; | 416 LayerImpl* child = root->children()[0]; |
417 | 417 |
418 gfx::Transform rotation; | 418 gfx::Transform rotation; |
419 rotation.Rotate(45.0); | 419 rotation.Rotate(45.0); |
420 | 420 |
421 ClearDamageForAllSurfaces(root.get()); | 421 ClearDamageForAllSurfaces(root.get()); |
422 child->SetAnchorPoint(gfx::PointF(0.5f, 0.5f)); | 422 child->SetTransformOrigin(gfx::Point3F( |
| 423 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f)); |
423 child->SetPosition(gfx::PointF(85.f, 85.f)); | 424 child->SetPosition(gfx::PointF(85.f, 85.f)); |
424 EmulateDrawingOneFrame(root.get()); | 425 EmulateDrawingOneFrame(root.get()); |
425 | 426 |
426 // Sanity check that the layer actually moved to (85, 85), damaging its old | 427 // Sanity check that the layer actually moved to (85, 85), damaging its old |
427 // location and new location. | 428 // location and new location. |
428 gfx::Rect root_damage_rect = | 429 gfx::Rect root_damage_rect = |
429 root->render_surface()->damage_tracker()->current_damage_rect(); | 430 root->render_surface()->damage_tracker()->current_damage_rect(); |
430 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString()); | 431 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString()); |
431 | 432 |
432 // With the anchor on the layer's center, now we can test the rotation more | 433 // With the anchor on the layer's center, now we can test the rotation more |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 703 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
703 LayerImpl* child1 = root->children()[0]; | 704 LayerImpl* child1 = root->children()[0]; |
704 | 705 |
705 // CASE 1: Adding a new layer should cause the appropriate damage. | 706 // CASE 1: Adding a new layer should cause the appropriate damage. |
706 // | 707 // |
707 ClearDamageForAllSurfaces(root.get()); | 708 ClearDamageForAllSurfaces(root.get()); |
708 { | 709 { |
709 scoped_ptr<LayerImpl> child2 = | 710 scoped_ptr<LayerImpl> child2 = |
710 LayerImpl::Create(host_impl_.active_tree(), 3); | 711 LayerImpl::Create(host_impl_.active_tree(), 3); |
711 child2->SetPosition(gfx::PointF(400.f, 380.f)); | 712 child2->SetPosition(gfx::PointF(400.f, 380.f)); |
712 child2->SetAnchorPoint(gfx::PointF()); | 713 child2->SetTransformOrigin(gfx::Point3F()); |
713 child2->SetBounds(gfx::Size(6, 8)); | 714 child2->SetBounds(gfx::Size(6, 8)); |
714 child2->SetContentBounds(gfx::Size(6, 8)); | 715 child2->SetContentBounds(gfx::Size(6, 8)); |
715 child2->SetDrawsContent(true); | 716 child2->SetDrawsContent(true); |
716 root->AddChild(child2.Pass()); | 717 root->AddChild(child2.Pass()); |
717 } | 718 } |
718 EmulateDrawingOneFrame(root.get()); | 719 EmulateDrawingOneFrame(root.get()); |
719 | 720 |
720 // Sanity check - all 3 layers should be on the same render surface; render | 721 // Sanity check - all 3 layers should be on the same render surface; render |
721 // surfaces are tested elsewhere. | 722 // surfaces are tested elsewhere. |
722 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); | 723 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
(...skipping 29 matching lines...) Expand all Loading... |
752 // If child2 is added to the layer tree, but it doesn't have any explicit | 753 // If child2 is added to the layer tree, but it doesn't have any explicit |
753 // damage of its own, it should still indeed damage the target surface. | 754 // damage of its own, it should still indeed damage the target surface. |
754 | 755 |
755 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 756 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
756 | 757 |
757 ClearDamageForAllSurfaces(root.get()); | 758 ClearDamageForAllSurfaces(root.get()); |
758 { | 759 { |
759 scoped_ptr<LayerImpl> child2 = | 760 scoped_ptr<LayerImpl> child2 = |
760 LayerImpl::Create(host_impl_.active_tree(), 3); | 761 LayerImpl::Create(host_impl_.active_tree(), 3); |
761 child2->SetPosition(gfx::PointF(400.f, 380.f)); | 762 child2->SetPosition(gfx::PointF(400.f, 380.f)); |
762 child2->SetAnchorPoint(gfx::PointF()); | 763 child2->SetTransformOrigin(gfx::Point3F()); |
763 child2->SetBounds(gfx::Size(6, 8)); | 764 child2->SetBounds(gfx::Size(6, 8)); |
764 child2->SetContentBounds(gfx::Size(6, 8)); | 765 child2->SetContentBounds(gfx::Size(6, 8)); |
765 child2->SetDrawsContent(true); | 766 child2->SetDrawsContent(true); |
766 child2->ResetAllChangeTrackingForSubtree(); | 767 child2->ResetAllChangeTrackingForSubtree(); |
767 // Sanity check the initial conditions of the test, if these asserts | 768 // Sanity check the initial conditions of the test, if these asserts |
768 // trigger, it means the test no longer actually covers the intended | 769 // trigger, it means the test no longer actually covers the intended |
769 // scenario. | 770 // scenario. |
770 ASSERT_FALSE(child2->LayerPropertyChanged()); | 771 ASSERT_FALSE(child2->LayerPropertyChanged()); |
771 ASSERT_TRUE(child2->update_rect().IsEmpty()); | 772 ASSERT_TRUE(child2->update_rect().IsEmpty()); |
772 root->AddChild(child2.Pass()); | 773 root->AddChild(child2.Pass()); |
(...skipping 13 matching lines...) Expand all Loading... |
786 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 787 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
787 LayerImpl* child1 = root->children()[0]; | 788 LayerImpl* child1 = root->children()[0]; |
788 | 789 |
789 // In this test we don't want the above tree manipulation to be considered | 790 // In this test we don't want the above tree manipulation to be considered |
790 // part of the same frame. | 791 // part of the same frame. |
791 ClearDamageForAllSurfaces(root.get()); | 792 ClearDamageForAllSurfaces(root.get()); |
792 { | 793 { |
793 scoped_ptr<LayerImpl> child2 = | 794 scoped_ptr<LayerImpl> child2 = |
794 LayerImpl::Create(host_impl_.active_tree(), 3); | 795 LayerImpl::Create(host_impl_.active_tree(), 3); |
795 child2->SetPosition(gfx::PointF(400.f, 380.f)); | 796 child2->SetPosition(gfx::PointF(400.f, 380.f)); |
796 child2->SetAnchorPoint(gfx::PointF()); | 797 child2->SetTransformOrigin(gfx::Point3F()); |
797 child2->SetBounds(gfx::Size(6, 8)); | 798 child2->SetBounds(gfx::Size(6, 8)); |
798 child2->SetContentBounds(gfx::Size(6, 8)); | 799 child2->SetContentBounds(gfx::Size(6, 8)); |
799 child2->SetDrawsContent(true); | 800 child2->SetDrawsContent(true); |
800 root->AddChild(child2.Pass()); | 801 root->AddChild(child2.Pass()); |
801 } | 802 } |
802 LayerImpl* child2 = root->children()[1]; | 803 LayerImpl* child2 = root->children()[1]; |
803 EmulateDrawingOneFrame(root.get()); | 804 EmulateDrawingOneFrame(root.get()); |
804 | 805 |
805 // Damaging two layers simultaneously should cause combined damage. | 806 // Damaging two layers simultaneously should cause combined damage. |
806 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); | 807 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 // to receive the surface's damage and the surface's reflected damage. | 1039 // to receive the surface's damage and the surface's reflected damage. |
1039 | 1040 |
1040 // For this test case, we modify grand_child2, and add grand_child3 to extend | 1041 // For this test case, we modify grand_child2, and add grand_child3 to extend |
1041 // the bounds of child1's surface. This way, we can test reflection changes | 1042 // the bounds of child1's surface. This way, we can test reflection changes |
1042 // without changing content_bounds of the surface. | 1043 // without changing content_bounds of the surface. |
1043 grand_child2->SetPosition(gfx::PointF(180.f, 180.f)); | 1044 grand_child2->SetPosition(gfx::PointF(180.f, 180.f)); |
1044 { | 1045 { |
1045 scoped_ptr<LayerImpl> grand_child3 = | 1046 scoped_ptr<LayerImpl> grand_child3 = |
1046 LayerImpl::Create(host_impl_.active_tree(), 6); | 1047 LayerImpl::Create(host_impl_.active_tree(), 6); |
1047 grand_child3->SetPosition(gfx::PointF(240.f, 240.f)); | 1048 grand_child3->SetPosition(gfx::PointF(240.f, 240.f)); |
1048 grand_child3->SetAnchorPoint(gfx::PointF()); | 1049 grand_child3->SetTransformOrigin(gfx::Point3F()); |
1049 grand_child3->SetBounds(gfx::Size(10, 10)); | 1050 grand_child3->SetBounds(gfx::Size(10, 10)); |
1050 grand_child3->SetContentBounds(gfx::Size(10, 10)); | 1051 grand_child3->SetContentBounds(gfx::Size(10, 10)); |
1051 grand_child3->SetDrawsContent(true); | 1052 grand_child3->SetDrawsContent(true); |
1052 child1->AddChild(grand_child3.Pass()); | 1053 child1->AddChild(grand_child3.Pass()); |
1053 } | 1054 } |
1054 child1->SetOpacity(0.5f); | 1055 child1->SetOpacity(0.5f); |
1055 EmulateDrawingOneFrame(root.get()); | 1056 EmulateDrawingOneFrame(root.get()); |
1056 | 1057 |
1057 // CASE 1: adding a reflection about the left edge of grand_child1. | 1058 // CASE 1: adding a reflection about the left edge of grand_child1. |
1058 // | 1059 // |
1059 ClearDamageForAllSurfaces(root.get()); | 1060 ClearDamageForAllSurfaces(root.get()); |
1060 { | 1061 { |
1061 scoped_ptr<LayerImpl> grand_child1_replica = | 1062 scoped_ptr<LayerImpl> grand_child1_replica = |
1062 LayerImpl::Create(host_impl_.active_tree(), 7); | 1063 LayerImpl::Create(host_impl_.active_tree(), 7); |
1063 grand_child1_replica->SetPosition(gfx::PointF()); | 1064 grand_child1_replica->SetPosition(gfx::PointF()); |
1064 grand_child1_replica->SetAnchorPoint(gfx::PointF()); | 1065 grand_child1_replica->SetTransformOrigin(gfx::Point3F()); |
1065 gfx::Transform reflection; | 1066 gfx::Transform reflection; |
1066 reflection.Scale3d(-1.0, 1.0, 1.0); | 1067 reflection.Scale3d(-1.0, 1.0, 1.0); |
1067 grand_child1_replica->SetTransform(reflection); | 1068 grand_child1_replica->SetTransform(reflection); |
1068 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); | 1069 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); |
1069 } | 1070 } |
1070 EmulateDrawingOneFrame(root.get()); | 1071 EmulateDrawingOneFrame(root.get()); |
1071 | 1072 |
1072 gfx::Rect grand_child_damage_rect = | 1073 gfx::Rect grand_child_damage_rect = |
1073 grand_child1->render_surface()->damage_tracker()->current_damage_rect(); | 1074 grand_child1->render_surface()->damage_tracker()->current_damage_rect(); |
1074 gfx::Rect child_damage_rect = | 1075 gfx::Rect child_damage_rect = |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 // In the current implementation of the damage tracker, changes to mask | 1141 // In the current implementation of the damage tracker, changes to mask |
1141 // layers should damage the entire corresponding surface. | 1142 // layers should damage the entire corresponding surface. |
1142 | 1143 |
1143 ClearDamageForAllSurfaces(root.get()); | 1144 ClearDamageForAllSurfaces(root.get()); |
1144 | 1145 |
1145 // Set up the mask layer. | 1146 // Set up the mask layer. |
1146 { | 1147 { |
1147 scoped_ptr<LayerImpl> mask_layer = | 1148 scoped_ptr<LayerImpl> mask_layer = |
1148 LayerImpl::Create(host_impl_.active_tree(), 3); | 1149 LayerImpl::Create(host_impl_.active_tree(), 3); |
1149 mask_layer->SetPosition(child->position()); | 1150 mask_layer->SetPosition(child->position()); |
1150 mask_layer->SetAnchorPoint(gfx::PointF()); | 1151 mask_layer->SetTransformOrigin(gfx::Point3F()); |
1151 mask_layer->SetBounds(child->bounds()); | 1152 mask_layer->SetBounds(child->bounds()); |
1152 mask_layer->SetContentBounds(child->bounds()); | 1153 mask_layer->SetContentBounds(child->bounds()); |
1153 child->SetMaskLayer(mask_layer.Pass()); | 1154 child->SetMaskLayer(mask_layer.Pass()); |
1154 } | 1155 } |
1155 LayerImpl* mask_layer = child->mask_layer(); | 1156 LayerImpl* mask_layer = child->mask_layer(); |
1156 | 1157 |
1157 // Add opacity and a grand_child so that the render surface persists even | 1158 // Add opacity and a grand_child so that the render surface persists even |
1158 // after we remove the mask. | 1159 // after we remove the mask. |
1159 child->SetOpacity(0.5f); | 1160 child->SetOpacity(0.5f); |
1160 { | 1161 { |
1161 scoped_ptr<LayerImpl> grand_child = | 1162 scoped_ptr<LayerImpl> grand_child = |
1162 LayerImpl::Create(host_impl_.active_tree(), 4); | 1163 LayerImpl::Create(host_impl_.active_tree(), 4); |
1163 grand_child->SetPosition(gfx::PointF(2.f, 2.f)); | 1164 grand_child->SetPosition(gfx::PointF(2.f, 2.f)); |
1164 grand_child->SetAnchorPoint(gfx::PointF()); | 1165 grand_child->SetTransformOrigin(gfx::Point3F()); |
1165 grand_child->SetBounds(gfx::Size(2, 2)); | 1166 grand_child->SetBounds(gfx::Size(2, 2)); |
1166 grand_child->SetContentBounds(gfx::Size(2, 2)); | 1167 grand_child->SetContentBounds(gfx::Size(2, 2)); |
1167 grand_child->SetDrawsContent(true); | 1168 grand_child->SetDrawsContent(true); |
1168 child->AddChild(grand_child.Pass()); | 1169 child->AddChild(grand_child.Pass()); |
1169 } | 1170 } |
1170 EmulateDrawingOneFrame(root.get()); | 1171 EmulateDrawingOneFrame(root.get()); |
1171 | 1172 |
1172 // Sanity check that a new surface was created for the child. | 1173 // Sanity check that a new surface was created for the child. |
1173 ASSERT_TRUE(child->render_surface()); | 1174 ASSERT_TRUE(child->render_surface()); |
1174 | 1175 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 // Changes to a replica's mask should not damage the original surface, | 1235 // Changes to a replica's mask should not damage the original surface, |
1235 // because it is not masked. But it does damage the ancestor target surface. | 1236 // because it is not masked. But it does damage the ancestor target surface. |
1236 | 1237 |
1237 ClearDamageForAllSurfaces(root.get()); | 1238 ClearDamageForAllSurfaces(root.get()); |
1238 | 1239 |
1239 // Create a reflection about the left edge of grand_child1. | 1240 // Create a reflection about the left edge of grand_child1. |
1240 { | 1241 { |
1241 scoped_ptr<LayerImpl> grand_child1_replica = | 1242 scoped_ptr<LayerImpl> grand_child1_replica = |
1242 LayerImpl::Create(host_impl_.active_tree(), 6); | 1243 LayerImpl::Create(host_impl_.active_tree(), 6); |
1243 grand_child1_replica->SetPosition(gfx::PointF()); | 1244 grand_child1_replica->SetPosition(gfx::PointF()); |
1244 grand_child1_replica->SetAnchorPoint(gfx::PointF()); | 1245 grand_child1_replica->SetTransformOrigin(gfx::Point3F()); |
1245 gfx::Transform reflection; | 1246 gfx::Transform reflection; |
1246 reflection.Scale3d(-1.0, 1.0, 1.0); | 1247 reflection.Scale3d(-1.0, 1.0, 1.0); |
1247 grand_child1_replica->SetTransform(reflection); | 1248 grand_child1_replica->SetTransform(reflection); |
1248 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); | 1249 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); |
1249 } | 1250 } |
1250 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); | 1251 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); |
1251 | 1252 |
1252 // Set up the mask layer on the replica layer | 1253 // Set up the mask layer on the replica layer |
1253 { | 1254 { |
1254 scoped_ptr<LayerImpl> replica_mask_layer = | 1255 scoped_ptr<LayerImpl> replica_mask_layer = |
1255 LayerImpl::Create(host_impl_.active_tree(), 7); | 1256 LayerImpl::Create(host_impl_.active_tree(), 7); |
1256 replica_mask_layer->SetPosition(gfx::PointF()); | 1257 replica_mask_layer->SetPosition(gfx::PointF()); |
1257 replica_mask_layer->SetAnchorPoint(gfx::PointF()); | 1258 replica_mask_layer->SetTransformOrigin(gfx::Point3F()); |
1258 replica_mask_layer->SetBounds(grand_child1->bounds()); | 1259 replica_mask_layer->SetBounds(grand_child1->bounds()); |
1259 replica_mask_layer->SetContentBounds(grand_child1->bounds()); | 1260 replica_mask_layer->SetContentBounds(grand_child1->bounds()); |
1260 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass()); | 1261 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass()); |
1261 } | 1262 } |
1262 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); | 1263 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); |
1263 | 1264 |
1264 EmulateDrawingOneFrame(root.get()); | 1265 EmulateDrawingOneFrame(root.get()); |
1265 | 1266 |
1266 // Sanity check that the appropriate render surfaces were created | 1267 // Sanity check that the appropriate render surfaces were created |
1267 ASSERT_TRUE(grand_child1->render_surface()); | 1268 ASSERT_TRUE(grand_child1->render_surface()); |
(...skipping 22 matching lines...) Expand all Loading... |
1290 grand_child_damage_rect = | 1291 grand_child_damage_rect = |
1291 grand_child1->render_surface()->damage_tracker()-> | 1292 grand_child1->render_surface()->damage_tracker()-> |
1292 current_damage_rect(); | 1293 current_damage_rect(); |
1293 child_damage_rect = | 1294 child_damage_rect = |
1294 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1295 child1->render_surface()->damage_tracker()->current_damage_rect(); |
1295 | 1296 |
1296 EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); | 1297 EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); |
1297 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1298 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
1298 } | 1299 } |
1299 | 1300 |
1300 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithAnchor) { | 1301 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithTransformOrigin) { |
1301 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1302 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1302 LayerImpl* child1 = root->children()[0]; | 1303 LayerImpl* child1 = root->children()[0]; |
1303 LayerImpl* grand_child1 = child1->children()[0]; | 1304 LayerImpl* grand_child1 = child1->children()[0]; |
1304 | 1305 |
1305 // Verify that the correct replica_origin_transform is used for the | 1306 // Verify that the correct replica_origin_transform is used for the |
1306 // replica_mask. | 1307 // replica_mask. |
1307 ClearDamageForAllSurfaces(root.get()); | 1308 ClearDamageForAllSurfaces(root.get()); |
1308 | 1309 |
1309 // This is not actually the anchor point being tested, but by convention its | 1310 // This is not actually the transform origin point being tested, but by |
| 1311 // convention its |
1310 // expected to be the same as the replica's anchor point. | 1312 // expected to be the same as the replica's anchor point. |
1311 grand_child1->SetAnchorPoint(gfx::PointF(1.f, 0.f)); | 1313 grand_child1->SetTransformOrigin( |
| 1314 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f)); |
1312 | 1315 |
1313 { | 1316 { |
1314 scoped_ptr<LayerImpl> grand_child1_replica = | 1317 scoped_ptr<LayerImpl> grand_child1_replica = |
1315 LayerImpl::Create(host_impl_.active_tree(), 6); | 1318 LayerImpl::Create(host_impl_.active_tree(), 6); |
1316 grand_child1_replica->SetPosition(gfx::PointF()); | 1319 grand_child1_replica->SetPosition(gfx::PointF()); |
1317 | 1320 |
1318 // This is the anchor being tested. | 1321 // This is the anchor being tested. |
1319 grand_child1_replica->SetAnchorPoint(gfx::PointF(1.f, 0.f)); | 1322 grand_child1_replica->SetTransformOrigin( |
| 1323 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f)); |
1320 gfx::Transform reflection; | 1324 gfx::Transform reflection; |
1321 reflection.Scale3d(-1.0, 1.0, 1.0); | 1325 reflection.Scale3d(-1.0, 1.0, 1.0); |
1322 grand_child1_replica->SetTransform(reflection); | 1326 grand_child1_replica->SetTransform(reflection); |
1323 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); | 1327 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); |
1324 } | 1328 } |
1325 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); | 1329 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); |
1326 | 1330 |
1327 // Set up the mask layer on the replica layer | 1331 // Set up the mask layer on the replica layer |
1328 { | 1332 { |
1329 scoped_ptr<LayerImpl> replica_mask_layer = | 1333 scoped_ptr<LayerImpl> replica_mask_layer = |
1330 LayerImpl::Create(host_impl_.active_tree(), 7); | 1334 LayerImpl::Create(host_impl_.active_tree(), 7); |
1331 replica_mask_layer->SetPosition(gfx::PointF()); | 1335 replica_mask_layer->SetPosition(gfx::PointF()); |
1332 // Note: this is not the anchor being tested. | 1336 // Note: this is not the transform origin being tested. |
1333 replica_mask_layer->SetAnchorPoint(gfx::PointF()); | 1337 replica_mask_layer->SetTransformOrigin(gfx::Point3F()); |
1334 replica_mask_layer->SetBounds(grand_child1->bounds()); | 1338 replica_mask_layer->SetBounds(grand_child1->bounds()); |
1335 replica_mask_layer->SetContentBounds(grand_child1->bounds()); | 1339 replica_mask_layer->SetContentBounds(grand_child1->bounds()); |
1336 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass()); | 1340 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass()); |
1337 } | 1341 } |
1338 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); | 1342 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); |
1339 | 1343 |
1340 EmulateDrawingOneFrame(root.get()); | 1344 EmulateDrawingOneFrame(root.get()); |
1341 | 1345 |
1342 // Sanity check that the appropriate render surfaces were created | 1346 // Sanity check that the appropriate render surfaces were created |
1343 ASSERT_TRUE(grand_child1->render_surface()); | 1347 ASSERT_TRUE(grand_child1->render_surface()); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 gfx::Rect root_damage_rect = | 1478 gfx::Rect root_damage_rect = |
1475 root->render_surface()->damage_tracker()->current_damage_rect(); | 1479 root->render_surface()->damage_tracker()->current_damage_rect(); |
1476 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1480 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
1477 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1481 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
1478 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1482 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
1479 } | 1483 } |
1480 } | 1484 } |
1481 | 1485 |
1482 } // namespace | 1486 } // namespace |
1483 } // namespace cc | 1487 } // namespace cc |
OLD | NEW |