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

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

Issue 295193002: Get rid of graphics layer anchor points, and replace with transform origin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nit. Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « cc/test/layer_tree_test.cc ('k') | cc/trees/layer_tree_host_common.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 "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());
86 root->SetBounds(gfx::Size(500, 500)); 85 root->SetBounds(gfx::Size(500, 500));
87 root->SetContentBounds(gfx::Size(500, 500)); 86 root->SetContentBounds(gfx::Size(500, 500));
88 root->SetDrawsContent(true); 87 root->SetDrawsContent(true);
89 root->CreateRenderSurface(); 88 root->CreateRenderSurface();
90 root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500)); 89 root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500));
91 90
92 child->SetPosition(gfx::PointF(100.f, 100.f)); 91 child->SetPosition(gfx::PointF(100.f, 100.f));
93 child->SetAnchorPoint(gfx::PointF());
94 child->SetBounds(gfx::Size(30, 30)); 92 child->SetBounds(gfx::Size(30, 30));
95 child->SetContentBounds(gfx::Size(30, 30)); 93 child->SetContentBounds(gfx::Size(30, 30));
96 child->SetDrawsContent(true); 94 child->SetDrawsContent(true);
97 root->AddChild(child.Pass()); 95 root->AddChild(child.Pass());
98 96
99 return root.Pass(); 97 return root.Pass();
100 } 98 }
101 99
102 scoped_ptr<LayerImpl> CreateTestTreeWithTwoSurfaces() { 100 scoped_ptr<LayerImpl> CreateTestTreeWithTwoSurfaces() {
103 // This test tree has two render surfaces: one for the root, and one for 101 // 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 102 // child1. Additionally, the root has a second child layer, and child1 has
105 // two children of its own. 103 // two children of its own.
106 104
107 scoped_ptr<LayerImpl> root = 105 scoped_ptr<LayerImpl> root =
108 LayerImpl::Create(host_impl_.active_tree(), 1); 106 LayerImpl::Create(host_impl_.active_tree(), 1);
109 scoped_ptr<LayerImpl> child1 = 107 scoped_ptr<LayerImpl> child1 =
110 LayerImpl::Create(host_impl_.active_tree(), 2); 108 LayerImpl::Create(host_impl_.active_tree(), 2);
111 scoped_ptr<LayerImpl> child2 = 109 scoped_ptr<LayerImpl> child2 =
112 LayerImpl::Create(host_impl_.active_tree(), 3); 110 LayerImpl::Create(host_impl_.active_tree(), 3);
113 scoped_ptr<LayerImpl> grand_child1 = 111 scoped_ptr<LayerImpl> grand_child1 =
114 LayerImpl::Create(host_impl_.active_tree(), 4); 112 LayerImpl::Create(host_impl_.active_tree(), 4);
115 scoped_ptr<LayerImpl> grand_child2 = 113 scoped_ptr<LayerImpl> grand_child2 =
116 LayerImpl::Create(host_impl_.active_tree(), 5); 114 LayerImpl::Create(host_impl_.active_tree(), 5);
117 115
118 root->SetPosition(gfx::PointF()); 116 root->SetPosition(gfx::PointF());
119 root->SetAnchorPoint(gfx::PointF());
120 root->SetBounds(gfx::Size(500, 500)); 117 root->SetBounds(gfx::Size(500, 500));
121 root->SetContentBounds(gfx::Size(500, 500)); 118 root->SetContentBounds(gfx::Size(500, 500));
122 root->SetDrawsContent(true); 119 root->SetDrawsContent(true);
123 root->CreateRenderSurface(); 120 root->CreateRenderSurface();
124 root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500)); 121 root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500));
125 122
126 child1->SetPosition(gfx::PointF(100.f, 100.f)); 123 child1->SetPosition(gfx::PointF(100.f, 100.f));
127 child1->SetAnchorPoint(gfx::PointF());
128 child1->SetBounds(gfx::Size(30, 30)); 124 child1->SetBounds(gfx::Size(30, 30));
129 child1->SetContentBounds(gfx::Size(30, 30)); 125 child1->SetContentBounds(gfx::Size(30, 30));
130 // With a child that draws_content, opacity will cause the layer to create 126 // 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 127 // its own RenderSurface. This layer does not draw, but is intended to
132 // create its own RenderSurface. TODO: setting opacity and 128 // create its own RenderSurface. TODO: setting opacity and
133 // ForceRenderSurface may be redundant here. 129 // ForceRenderSurface may be redundant here.
134 child1->SetOpacity(0.5f); 130 child1->SetOpacity(0.5f);
135 child1->SetDrawsContent(false); 131 child1->SetDrawsContent(false);
136 child1->SetForceRenderSurface(true); 132 child1->SetForceRenderSurface(true);
137 133
138 child2->SetPosition(gfx::PointF(11.f, 11.f)); 134 child2->SetPosition(gfx::PointF(11.f, 11.f));
139 child2->SetAnchorPoint(gfx::PointF());
140 child2->SetBounds(gfx::Size(18, 18)); 135 child2->SetBounds(gfx::Size(18, 18));
141 child2->SetContentBounds(gfx::Size(18, 18)); 136 child2->SetContentBounds(gfx::Size(18, 18));
142 child2->SetDrawsContent(true); 137 child2->SetDrawsContent(true);
143 138
144 grand_child1->SetPosition(gfx::PointF(200.f, 200.f)); 139 grand_child1->SetPosition(gfx::PointF(200.f, 200.f));
145 grand_child1->SetAnchorPoint(gfx::PointF());
146 grand_child1->SetBounds(gfx::Size(6, 8)); 140 grand_child1->SetBounds(gfx::Size(6, 8));
147 grand_child1->SetContentBounds(gfx::Size(6, 8)); 141 grand_child1->SetContentBounds(gfx::Size(6, 8));
148 grand_child1->SetDrawsContent(true); 142 grand_child1->SetDrawsContent(true);
149 143
150 grand_child2->SetPosition(gfx::PointF(190.f, 190.f)); 144 grand_child2->SetPosition(gfx::PointF(190.f, 190.f));
151 grand_child2->SetAnchorPoint(gfx::PointF());
152 grand_child2->SetBounds(gfx::Size(6, 8)); 145 grand_child2->SetBounds(gfx::Size(6, 8));
153 grand_child2->SetContentBounds(gfx::Size(6, 8)); 146 grand_child2->SetContentBounds(gfx::Size(6, 8));
154 grand_child2->SetDrawsContent(true); 147 grand_child2->SetDrawsContent(true);
155 148
156 child1->AddChild(grand_child1.Pass()); 149 child1->AddChild(grand_child1.Pass());
157 child1->AddChild(grand_child2.Pass()); 150 child1->AddChild(grand_child2.Pass());
158 root->AddChild(child1.Pass()); 151 root->AddChild(child1.Pass());
159 root->AddChild(child2.Pass()); 152 root->AddChild(child2.Pass());
160 153
161 return root.Pass(); 154 return root.Pass();
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 // If a layer is transformed, the damage rect should still enclose the entire 405 // If a layer is transformed, the damage rect should still enclose the entire
413 // transformed layer. 406 // transformed layer.
414 407
415 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); 408 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
416 LayerImpl* child = root->children()[0]; 409 LayerImpl* child = root->children()[0];
417 410
418 gfx::Transform rotation; 411 gfx::Transform rotation;
419 rotation.Rotate(45.0); 412 rotation.Rotate(45.0);
420 413
421 ClearDamageForAllSurfaces(root.get()); 414 ClearDamageForAllSurfaces(root.get());
422 child->SetAnchorPoint(gfx::PointF(0.5f, 0.5f)); 415 child->SetTransformOrigin(gfx::Point3F(
416 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f));
423 child->SetPosition(gfx::PointF(85.f, 85.f)); 417 child->SetPosition(gfx::PointF(85.f, 85.f));
424 EmulateDrawingOneFrame(root.get()); 418 EmulateDrawingOneFrame(root.get());
425 419
426 // Sanity check that the layer actually moved to (85, 85), damaging its old 420 // Sanity check that the layer actually moved to (85, 85), damaging its old
427 // location and new location. 421 // location and new location.
428 gfx::Rect root_damage_rect = 422 gfx::Rect root_damage_rect =
429 root->render_surface()->damage_tracker()->current_damage_rect(); 423 root->render_surface()->damage_tracker()->current_damage_rect();
430 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString()); 424 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString());
431 425
432 // With the anchor on the layer's center, now we can test the rotation more 426 // 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
702 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); 696 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
703 LayerImpl* child1 = root->children()[0]; 697 LayerImpl* child1 = root->children()[0];
704 698
705 // CASE 1: Adding a new layer should cause the appropriate damage. 699 // CASE 1: Adding a new layer should cause the appropriate damage.
706 // 700 //
707 ClearDamageForAllSurfaces(root.get()); 701 ClearDamageForAllSurfaces(root.get());
708 { 702 {
709 scoped_ptr<LayerImpl> child2 = 703 scoped_ptr<LayerImpl> child2 =
710 LayerImpl::Create(host_impl_.active_tree(), 3); 704 LayerImpl::Create(host_impl_.active_tree(), 3);
711 child2->SetPosition(gfx::PointF(400.f, 380.f)); 705 child2->SetPosition(gfx::PointF(400.f, 380.f));
712 child2->SetAnchorPoint(gfx::PointF());
713 child2->SetBounds(gfx::Size(6, 8)); 706 child2->SetBounds(gfx::Size(6, 8));
714 child2->SetContentBounds(gfx::Size(6, 8)); 707 child2->SetContentBounds(gfx::Size(6, 8));
715 child2->SetDrawsContent(true); 708 child2->SetDrawsContent(true);
716 root->AddChild(child2.Pass()); 709 root->AddChild(child2.Pass());
717 } 710 }
718 EmulateDrawingOneFrame(root.get()); 711 EmulateDrawingOneFrame(root.get());
719 712
720 // Sanity check - all 3 layers should be on the same render surface; render 713 // Sanity check - all 3 layers should be on the same render surface; render
721 // surfaces are tested elsewhere. 714 // surfaces are tested elsewhere.
722 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); 715 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
(...skipping 29 matching lines...) Expand all
752 // If child2 is added to the layer tree, but it doesn't have any explicit 745 // 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. 746 // damage of its own, it should still indeed damage the target surface.
754 747
755 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); 748 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
756 749
757 ClearDamageForAllSurfaces(root.get()); 750 ClearDamageForAllSurfaces(root.get());
758 { 751 {
759 scoped_ptr<LayerImpl> child2 = 752 scoped_ptr<LayerImpl> child2 =
760 LayerImpl::Create(host_impl_.active_tree(), 3); 753 LayerImpl::Create(host_impl_.active_tree(), 3);
761 child2->SetPosition(gfx::PointF(400.f, 380.f)); 754 child2->SetPosition(gfx::PointF(400.f, 380.f));
762 child2->SetAnchorPoint(gfx::PointF());
763 child2->SetBounds(gfx::Size(6, 8)); 755 child2->SetBounds(gfx::Size(6, 8));
764 child2->SetContentBounds(gfx::Size(6, 8)); 756 child2->SetContentBounds(gfx::Size(6, 8));
765 child2->SetDrawsContent(true); 757 child2->SetDrawsContent(true);
766 child2->ResetAllChangeTrackingForSubtree(); 758 child2->ResetAllChangeTrackingForSubtree();
767 // Sanity check the initial conditions of the test, if these asserts 759 // Sanity check the initial conditions of the test, if these asserts
768 // trigger, it means the test no longer actually covers the intended 760 // trigger, it means the test no longer actually covers the intended
769 // scenario. 761 // scenario.
770 ASSERT_FALSE(child2->LayerPropertyChanged()); 762 ASSERT_FALSE(child2->LayerPropertyChanged());
771 ASSERT_TRUE(child2->update_rect().IsEmpty()); 763 ASSERT_TRUE(child2->update_rect().IsEmpty());
772 root->AddChild(child2.Pass()); 764 root->AddChild(child2.Pass());
(...skipping 13 matching lines...) Expand all
786 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); 778 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
787 LayerImpl* child1 = root->children()[0]; 779 LayerImpl* child1 = root->children()[0];
788 780
789 // In this test we don't want the above tree manipulation to be considered 781 // In this test we don't want the above tree manipulation to be considered
790 // part of the same frame. 782 // part of the same frame.
791 ClearDamageForAllSurfaces(root.get()); 783 ClearDamageForAllSurfaces(root.get());
792 { 784 {
793 scoped_ptr<LayerImpl> child2 = 785 scoped_ptr<LayerImpl> child2 =
794 LayerImpl::Create(host_impl_.active_tree(), 3); 786 LayerImpl::Create(host_impl_.active_tree(), 3);
795 child2->SetPosition(gfx::PointF(400.f, 380.f)); 787 child2->SetPosition(gfx::PointF(400.f, 380.f));
796 child2->SetAnchorPoint(gfx::PointF());
797 child2->SetBounds(gfx::Size(6, 8)); 788 child2->SetBounds(gfx::Size(6, 8));
798 child2->SetContentBounds(gfx::Size(6, 8)); 789 child2->SetContentBounds(gfx::Size(6, 8));
799 child2->SetDrawsContent(true); 790 child2->SetDrawsContent(true);
800 root->AddChild(child2.Pass()); 791 root->AddChild(child2.Pass());
801 } 792 }
802 LayerImpl* child2 = root->children()[1]; 793 LayerImpl* child2 = root->children()[1];
803 EmulateDrawingOneFrame(root.get()); 794 EmulateDrawingOneFrame(root.get());
804 795
805 // Damaging two layers simultaneously should cause combined damage. 796 // Damaging two layers simultaneously should cause combined damage.
806 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); 797 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 // to receive the surface's damage and the surface's reflected damage. 1029 // to receive the surface's damage and the surface's reflected damage.
1039 1030
1040 // For this test case, we modify grand_child2, and add grand_child3 to extend 1031 // 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 1032 // the bounds of child1's surface. This way, we can test reflection changes
1042 // without changing content_bounds of the surface. 1033 // without changing content_bounds of the surface.
1043 grand_child2->SetPosition(gfx::PointF(180.f, 180.f)); 1034 grand_child2->SetPosition(gfx::PointF(180.f, 180.f));
1044 { 1035 {
1045 scoped_ptr<LayerImpl> grand_child3 = 1036 scoped_ptr<LayerImpl> grand_child3 =
1046 LayerImpl::Create(host_impl_.active_tree(), 6); 1037 LayerImpl::Create(host_impl_.active_tree(), 6);
1047 grand_child3->SetPosition(gfx::PointF(240.f, 240.f)); 1038 grand_child3->SetPosition(gfx::PointF(240.f, 240.f));
1048 grand_child3->SetAnchorPoint(gfx::PointF());
1049 grand_child3->SetBounds(gfx::Size(10, 10)); 1039 grand_child3->SetBounds(gfx::Size(10, 10));
1050 grand_child3->SetContentBounds(gfx::Size(10, 10)); 1040 grand_child3->SetContentBounds(gfx::Size(10, 10));
1051 grand_child3->SetDrawsContent(true); 1041 grand_child3->SetDrawsContent(true);
1052 child1->AddChild(grand_child3.Pass()); 1042 child1->AddChild(grand_child3.Pass());
1053 } 1043 }
1054 child1->SetOpacity(0.5f); 1044 child1->SetOpacity(0.5f);
1055 EmulateDrawingOneFrame(root.get()); 1045 EmulateDrawingOneFrame(root.get());
1056 1046
1057 // CASE 1: adding a reflection about the left edge of grand_child1. 1047 // CASE 1: adding a reflection about the left edge of grand_child1.
1058 // 1048 //
1059 ClearDamageForAllSurfaces(root.get()); 1049 ClearDamageForAllSurfaces(root.get());
1060 { 1050 {
1061 scoped_ptr<LayerImpl> grand_child1_replica = 1051 scoped_ptr<LayerImpl> grand_child1_replica =
1062 LayerImpl::Create(host_impl_.active_tree(), 7); 1052 LayerImpl::Create(host_impl_.active_tree(), 7);
1063 grand_child1_replica->SetPosition(gfx::PointF()); 1053 grand_child1_replica->SetPosition(gfx::PointF());
1064 grand_child1_replica->SetAnchorPoint(gfx::PointF());
1065 gfx::Transform reflection; 1054 gfx::Transform reflection;
1066 reflection.Scale3d(-1.0, 1.0, 1.0); 1055 reflection.Scale3d(-1.0, 1.0, 1.0);
1067 grand_child1_replica->SetTransform(reflection); 1056 grand_child1_replica->SetTransform(reflection);
1068 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); 1057 grand_child1->SetReplicaLayer(grand_child1_replica.Pass());
1069 } 1058 }
1070 EmulateDrawingOneFrame(root.get()); 1059 EmulateDrawingOneFrame(root.get());
1071 1060
1072 gfx::Rect grand_child_damage_rect = 1061 gfx::Rect grand_child_damage_rect =
1073 grand_child1->render_surface()->damage_tracker()->current_damage_rect(); 1062 grand_child1->render_surface()->damage_tracker()->current_damage_rect();
1074 gfx::Rect child_damage_rect = 1063 gfx::Rect child_damage_rect =
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 // In the current implementation of the damage tracker, changes to mask 1129 // In the current implementation of the damage tracker, changes to mask
1141 // layers should damage the entire corresponding surface. 1130 // layers should damage the entire corresponding surface.
1142 1131
1143 ClearDamageForAllSurfaces(root.get()); 1132 ClearDamageForAllSurfaces(root.get());
1144 1133
1145 // Set up the mask layer. 1134 // Set up the mask layer.
1146 { 1135 {
1147 scoped_ptr<LayerImpl> mask_layer = 1136 scoped_ptr<LayerImpl> mask_layer =
1148 LayerImpl::Create(host_impl_.active_tree(), 3); 1137 LayerImpl::Create(host_impl_.active_tree(), 3);
1149 mask_layer->SetPosition(child->position()); 1138 mask_layer->SetPosition(child->position());
1150 mask_layer->SetAnchorPoint(gfx::PointF());
1151 mask_layer->SetBounds(child->bounds()); 1139 mask_layer->SetBounds(child->bounds());
1152 mask_layer->SetContentBounds(child->bounds()); 1140 mask_layer->SetContentBounds(child->bounds());
1153 child->SetMaskLayer(mask_layer.Pass()); 1141 child->SetMaskLayer(mask_layer.Pass());
1154 } 1142 }
1155 LayerImpl* mask_layer = child->mask_layer(); 1143 LayerImpl* mask_layer = child->mask_layer();
1156 1144
1157 // Add opacity and a grand_child so that the render surface persists even 1145 // Add opacity and a grand_child so that the render surface persists even
1158 // after we remove the mask. 1146 // after we remove the mask.
1159 child->SetOpacity(0.5f); 1147 child->SetOpacity(0.5f);
1160 { 1148 {
1161 scoped_ptr<LayerImpl> grand_child = 1149 scoped_ptr<LayerImpl> grand_child =
1162 LayerImpl::Create(host_impl_.active_tree(), 4); 1150 LayerImpl::Create(host_impl_.active_tree(), 4);
1163 grand_child->SetPosition(gfx::PointF(2.f, 2.f)); 1151 grand_child->SetPosition(gfx::PointF(2.f, 2.f));
1164 grand_child->SetAnchorPoint(gfx::PointF());
1165 grand_child->SetBounds(gfx::Size(2, 2)); 1152 grand_child->SetBounds(gfx::Size(2, 2));
1166 grand_child->SetContentBounds(gfx::Size(2, 2)); 1153 grand_child->SetContentBounds(gfx::Size(2, 2));
1167 grand_child->SetDrawsContent(true); 1154 grand_child->SetDrawsContent(true);
1168 child->AddChild(grand_child.Pass()); 1155 child->AddChild(grand_child.Pass());
1169 } 1156 }
1170 EmulateDrawingOneFrame(root.get()); 1157 EmulateDrawingOneFrame(root.get());
1171 1158
1172 // Sanity check that a new surface was created for the child. 1159 // Sanity check that a new surface was created for the child.
1173 ASSERT_TRUE(child->render_surface()); 1160 ASSERT_TRUE(child->render_surface());
1174 1161
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 // Changes to a replica's mask should not damage the original surface, 1221 // 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. 1222 // because it is not masked. But it does damage the ancestor target surface.
1236 1223
1237 ClearDamageForAllSurfaces(root.get()); 1224 ClearDamageForAllSurfaces(root.get());
1238 1225
1239 // Create a reflection about the left edge of grand_child1. 1226 // Create a reflection about the left edge of grand_child1.
1240 { 1227 {
1241 scoped_ptr<LayerImpl> grand_child1_replica = 1228 scoped_ptr<LayerImpl> grand_child1_replica =
1242 LayerImpl::Create(host_impl_.active_tree(), 6); 1229 LayerImpl::Create(host_impl_.active_tree(), 6);
1243 grand_child1_replica->SetPosition(gfx::PointF()); 1230 grand_child1_replica->SetPosition(gfx::PointF());
1244 grand_child1_replica->SetAnchorPoint(gfx::PointF());
1245 gfx::Transform reflection; 1231 gfx::Transform reflection;
1246 reflection.Scale3d(-1.0, 1.0, 1.0); 1232 reflection.Scale3d(-1.0, 1.0, 1.0);
1247 grand_child1_replica->SetTransform(reflection); 1233 grand_child1_replica->SetTransform(reflection);
1248 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); 1234 grand_child1->SetReplicaLayer(grand_child1_replica.Pass());
1249 } 1235 }
1250 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); 1236 LayerImpl* grand_child1_replica = grand_child1->replica_layer();
1251 1237
1252 // Set up the mask layer on the replica layer 1238 // Set up the mask layer on the replica layer
1253 { 1239 {
1254 scoped_ptr<LayerImpl> replica_mask_layer = 1240 scoped_ptr<LayerImpl> replica_mask_layer =
1255 LayerImpl::Create(host_impl_.active_tree(), 7); 1241 LayerImpl::Create(host_impl_.active_tree(), 7);
1256 replica_mask_layer->SetPosition(gfx::PointF()); 1242 replica_mask_layer->SetPosition(gfx::PointF());
1257 replica_mask_layer->SetAnchorPoint(gfx::PointF());
1258 replica_mask_layer->SetBounds(grand_child1->bounds()); 1243 replica_mask_layer->SetBounds(grand_child1->bounds());
1259 replica_mask_layer->SetContentBounds(grand_child1->bounds()); 1244 replica_mask_layer->SetContentBounds(grand_child1->bounds());
1260 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass()); 1245 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass());
1261 } 1246 }
1262 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); 1247 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer();
1263 1248
1264 EmulateDrawingOneFrame(root.get()); 1249 EmulateDrawingOneFrame(root.get());
1265 1250
1266 // Sanity check that the appropriate render surfaces were created 1251 // Sanity check that the appropriate render surfaces were created
1267 ASSERT_TRUE(grand_child1->render_surface()); 1252 ASSERT_TRUE(grand_child1->render_surface());
(...skipping 22 matching lines...) Expand all
1290 grand_child_damage_rect = 1275 grand_child_damage_rect =
1291 grand_child1->render_surface()->damage_tracker()-> 1276 grand_child1->render_surface()->damage_tracker()->
1292 current_damage_rect(); 1277 current_damage_rect();
1293 child_damage_rect = 1278 child_damage_rect =
1294 child1->render_surface()->damage_tracker()->current_damage_rect(); 1279 child1->render_surface()->damage_tracker()->current_damage_rect();
1295 1280
1296 EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); 1281 EXPECT_TRUE(grand_child_damage_rect.IsEmpty());
1297 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString()); 1282 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString());
1298 } 1283 }
1299 1284
1300 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithAnchor) { 1285 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithTransformOrigin) {
1301 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1286 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
1302 LayerImpl* child1 = root->children()[0]; 1287 LayerImpl* child1 = root->children()[0];
1303 LayerImpl* grand_child1 = child1->children()[0]; 1288 LayerImpl* grand_child1 = child1->children()[0];
1304 1289
1305 // Verify that the correct replica_origin_transform is used for the 1290 // Verify that the correct replica_origin_transform is used for the
1306 // replica_mask. 1291 // replica_mask.
1307 ClearDamageForAllSurfaces(root.get()); 1292 ClearDamageForAllSurfaces(root.get());
1308 1293
1309 // This is not actually the anchor point being tested, but by convention its 1294 // This is not actually the transform origin point being tested, but by
1295 // convention its
1310 // expected to be the same as the replica's anchor point. 1296 // expected to be the same as the replica's anchor point.
1311 grand_child1->SetAnchorPoint(gfx::PointF(1.f, 0.f)); 1297 grand_child1->SetTransformOrigin(
1298 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f));
1312 1299
1313 { 1300 {
1314 scoped_ptr<LayerImpl> grand_child1_replica = 1301 scoped_ptr<LayerImpl> grand_child1_replica =
1315 LayerImpl::Create(host_impl_.active_tree(), 6); 1302 LayerImpl::Create(host_impl_.active_tree(), 6);
1316 grand_child1_replica->SetPosition(gfx::PointF()); 1303 grand_child1_replica->SetPosition(gfx::PointF());
1317 1304
1318 // This is the anchor being tested. 1305 // This is the anchor being tested.
1319 grand_child1_replica->SetAnchorPoint(gfx::PointF(1.f, 0.f)); 1306 grand_child1_replica->SetTransformOrigin(
1307 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f));
1320 gfx::Transform reflection; 1308 gfx::Transform reflection;
1321 reflection.Scale3d(-1.0, 1.0, 1.0); 1309 reflection.Scale3d(-1.0, 1.0, 1.0);
1322 grand_child1_replica->SetTransform(reflection); 1310 grand_child1_replica->SetTransform(reflection);
1323 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); 1311 grand_child1->SetReplicaLayer(grand_child1_replica.Pass());
1324 } 1312 }
1325 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); 1313 LayerImpl* grand_child1_replica = grand_child1->replica_layer();
1326 1314
1327 // Set up the mask layer on the replica layer 1315 // Set up the mask layer on the replica layer
1328 { 1316 {
1329 scoped_ptr<LayerImpl> replica_mask_layer = 1317 scoped_ptr<LayerImpl> replica_mask_layer =
1330 LayerImpl::Create(host_impl_.active_tree(), 7); 1318 LayerImpl::Create(host_impl_.active_tree(), 7);
1331 replica_mask_layer->SetPosition(gfx::PointF()); 1319 replica_mask_layer->SetPosition(gfx::PointF());
1332 // Note: this is not the anchor being tested. 1320 // Note: this is not the transform origin being tested.
1333 replica_mask_layer->SetAnchorPoint(gfx::PointF());
1334 replica_mask_layer->SetBounds(grand_child1->bounds()); 1321 replica_mask_layer->SetBounds(grand_child1->bounds());
1335 replica_mask_layer->SetContentBounds(grand_child1->bounds()); 1322 replica_mask_layer->SetContentBounds(grand_child1->bounds());
1336 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass()); 1323 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass());
1337 } 1324 }
1338 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); 1325 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer();
1339 1326
1340 EmulateDrawingOneFrame(root.get()); 1327 EmulateDrawingOneFrame(root.get());
1341 1328
1342 // Sanity check that the appropriate render surfaces were created 1329 // Sanity check that the appropriate render surfaces were created
1343 ASSERT_TRUE(grand_child1->render_surface()); 1330 ASSERT_TRUE(grand_child1->render_surface());
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 gfx::Rect root_damage_rect = 1461 gfx::Rect root_damage_rect =
1475 root->render_surface()->damage_tracker()->current_damage_rect(); 1462 root->render_surface()->damage_tracker()->current_damage_rect();
1476 gfx::Rect damage_we_care_about = gfx::Rect(i, i); 1463 gfx::Rect damage_we_care_about = gfx::Rect(i, i);
1477 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); 1464 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right());
1478 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); 1465 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom());
1479 } 1466 }
1480 } 1467 }
1481 1468
1482 } // namespace 1469 } // namespace
1483 } // namespace cc 1470 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/layer_tree_test.cc ('k') | cc/trees/layer_tree_host_common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698