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" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 | 123 |
124 child1->SetPosition(gfx::PointF(100.f, 100.f)); | 124 child1->SetPosition(gfx::PointF(100.f, 100.f)); |
125 child1->SetBounds(gfx::Size(30, 30)); | 125 child1->SetBounds(gfx::Size(30, 30)); |
126 child1->SetContentBounds(gfx::Size(30, 30)); | 126 child1->SetContentBounds(gfx::Size(30, 30)); |
127 // With a child that draws_content, opacity will cause the layer to create | 127 // With a child that draws_content, opacity will cause the layer to create |
128 // its own RenderSurface. This layer does not draw, but is intended to | 128 // its own RenderSurface. This layer does not draw, but is intended to |
129 // create its own RenderSurface. TODO: setting opacity and | 129 // create its own RenderSurface. TODO: setting opacity and |
130 // ForceRenderSurface may be redundant here. | 130 // ForceRenderSurface may be redundant here. |
131 child1->SetOpacity(0.5f); | 131 child1->SetOpacity(0.5f); |
132 child1->SetDrawsContent(false); | 132 child1->SetDrawsContent(false); |
133 child1->SetForceRenderSurface(true); | 133 child1->CreateRenderSurface(); |
134 | 134 |
135 child2->SetPosition(gfx::PointF(11.f, 11.f)); | 135 child2->SetPosition(gfx::PointF(11.f, 11.f)); |
136 child2->SetBounds(gfx::Size(18, 18)); | 136 child2->SetBounds(gfx::Size(18, 18)); |
137 child2->SetContentBounds(gfx::Size(18, 18)); | 137 child2->SetContentBounds(gfx::Size(18, 18)); |
138 child2->SetDrawsContent(true); | 138 child2->SetDrawsContent(true); |
139 | 139 |
140 grand_child1->SetPosition(gfx::PointF(200.f, 200.f)); | 140 grand_child1->SetPosition(gfx::PointF(200.f, 200.f)); |
141 grand_child1->SetBounds(gfx::Size(6, 8)); | 141 grand_child1->SetBounds(gfx::Size(6, 8)); |
142 grand_child1->SetContentBounds(gfx::Size(6, 8)); | 142 grand_child1->SetContentBounds(gfx::Size(6, 8)); |
143 grand_child1->SetDrawsContent(true); | 143 grand_child1->SetDrawsContent(true); |
144 grand_child1->CreateRenderSurface(); | |
144 | 145 |
145 grand_child2->SetPosition(gfx::PointF(190.f, 190.f)); | 146 grand_child2->SetPosition(gfx::PointF(190.f, 190.f)); |
146 grand_child2->SetBounds(gfx::Size(6, 8)); | 147 grand_child2->SetBounds(gfx::Size(6, 8)); |
147 grand_child2->SetContentBounds(gfx::Size(6, 8)); | 148 grand_child2->SetContentBounds(gfx::Size(6, 8)); |
148 grand_child2->SetDrawsContent(true); | 149 grand_child2->SetDrawsContent(true); |
149 | 150 |
150 child1->AddChild(grand_child1.Pass()); | 151 child1->AddChild(grand_child1.Pass()); |
151 child1->AddChild(grand_child2.Pass()); | 152 child1->AddChild(grand_child2.Pass()); |
152 root->AddChild(child1.Pass()); | 153 root->AddChild(child1.Pass()); |
153 root->AddChild(child2.Pass()); | 154 root->AddChild(child2.Pass()); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 child->SetDrawsContent(true); | 537 child->SetDrawsContent(true); |
537 | 538 |
538 skia::RefPtr<SkImageFilter> filter = skia::AdoptRef( | 539 skia::RefPtr<SkImageFilter> filter = skia::AdoptRef( |
539 SkBlurImageFilter::Create(SkIntToScalar(2), SkIntToScalar(2))); | 540 SkBlurImageFilter::Create(SkIntToScalar(2), SkIntToScalar(2))); |
540 FilterOperations filters; | 541 FilterOperations filters; |
541 filters.Append(FilterOperation::CreateReferenceFilter(filter)); | 542 filters.Append(FilterOperation::CreateReferenceFilter(filter)); |
542 | 543 |
543 // Setting the filter will damage the whole surface. | 544 // Setting the filter will damage the whole surface. |
544 ClearDamageForAllSurfaces(root.get()); | 545 ClearDamageForAllSurfaces(root.get()); |
545 child->SetFilters(filters); | 546 child->SetFilters(filters); |
547 child->CreateRenderSurface(); | |
546 EmulateDrawingOneFrame(root.get()); | 548 EmulateDrawingOneFrame(root.get()); |
547 root_damage_rect = | 549 root_damage_rect = |
548 root->render_surface()->damage_tracker()->current_damage_rect(); | 550 root->render_surface()->damage_tracker()->current_damage_rect(); |
549 child_damage_rect = | 551 child_damage_rect = |
550 child->render_surface()->damage_tracker()->current_damage_rect(); | 552 child->render_surface()->damage_tracker()->current_damage_rect(); |
551 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), | 553 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), |
552 root_damage_rect.ToString()); | 554 root_damage_rect.ToString()); |
553 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 555 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
554 | 556 |
555 // CASE 1: Setting the update rect should damage the whole surface (for now) | 557 // CASE 1: Setting the update rect should damage the whole surface (for now) |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
920 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { | 922 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { |
921 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 923 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
922 LayerImpl* child1 = root->children()[0]; | 924 LayerImpl* child1 = root->children()[0]; |
923 gfx::Rect child_damage_rect; | 925 gfx::Rect child_damage_rect; |
924 gfx::Rect root_damage_rect; | 926 gfx::Rect root_damage_rect; |
925 | 927 |
926 // CASE 1: If a descendant surface disappears, its entire old area becomes | 928 // CASE 1: If a descendant surface disappears, its entire old area becomes |
927 // exposed. | 929 // exposed. |
928 ClearDamageForAllSurfaces(root.get()); | 930 ClearDamageForAllSurfaces(root.get()); |
929 child1->SetOpacity(1.f); | 931 child1->SetOpacity(1.f); |
930 child1->SetForceRenderSurface(false); | 932 child1->ClearRenderSurface(); |
931 EmulateDrawingOneFrame(root.get()); | 933 EmulateDrawingOneFrame(root.get()); |
932 | 934 |
933 // Sanity check that there is only one surface now. | 935 // Sanity check that there is only one surface now. |
934 ASSERT_FALSE(child1->render_surface()); | 936 ASSERT_FALSE(child1->render_surface()); |
935 ASSERT_EQ(4u, root->render_surface()->layer_list().size()); | 937 ASSERT_EQ(4u, root->render_surface()->layer_list().size()); |
936 | 938 |
937 root_damage_rect = | 939 root_damage_rect = |
938 root->render_surface()->damage_tracker()->current_damage_rect(); | 940 root->render_surface()->damage_tracker()->current_damage_rect(); |
939 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 941 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
940 root_damage_rect.ToString()); | 942 root_damage_rect.ToString()); |
941 | 943 |
942 // CASE 2: If a descendant surface appears, its entire old area becomes | 944 // CASE 2: If a descendant surface appears, its entire old area becomes |
943 // exposed. | 945 // exposed. |
944 | 946 |
945 // Cycle one frame of no change, just to sanity check that the next rect is | 947 // Cycle one frame of no change, just to sanity check that the next rect is |
946 // not because of the old damage state. | 948 // not because of the old damage state. |
947 ClearDamageForAllSurfaces(root.get()); | 949 ClearDamageForAllSurfaces(root.get()); |
948 EmulateDrawingOneFrame(root.get()); | 950 EmulateDrawingOneFrame(root.get()); |
949 root_damage_rect = | 951 root_damage_rect = |
950 root->render_surface()->damage_tracker()->current_damage_rect(); | 952 root->render_surface()->damage_tracker()->current_damage_rect(); |
951 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 953 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
952 | 954 |
953 // Then change the tree so that the render surface is added back. | 955 // Then change the tree so that the render surface is added back. |
954 ClearDamageForAllSurfaces(root.get()); | 956 ClearDamageForAllSurfaces(root.get()); |
955 child1->SetOpacity(0.5f); | 957 child1->SetOpacity(0.5f); |
956 child1->SetForceRenderSurface(true); | 958 child1->CreateRenderSurface(); |
959 | |
957 EmulateDrawingOneFrame(root.get()); | 960 EmulateDrawingOneFrame(root.get()); |
958 | 961 |
959 // Sanity check that there is a new surface now. | 962 // Sanity check that there is a new surface now. |
960 ASSERT_TRUE(child1->render_surface()); | 963 ASSERT_TRUE(child1->render_surface()); |
961 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); | 964 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
962 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); | 965 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); |
963 | 966 |
964 child_damage_rect = | 967 child_damage_rect = |
965 child1->render_surface()->damage_tracker()->current_damage_rect(); | 968 child1->render_surface()->damage_tracker()->current_damage_rect(); |
966 root_damage_rect = | 969 root_damage_rect = |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1105 // CASE 3: removing the reflection should cause the entire region including | 1108 // CASE 3: removing the reflection should cause the entire region including |
1106 // reflection to damage the target surface. | 1109 // reflection to damage the target surface. |
1107 ClearDamageForAllSurfaces(root.get()); | 1110 ClearDamageForAllSurfaces(root.get()); |
1108 grand_child1->SetReplicaLayer(scoped_ptr<LayerImpl>()); | 1111 grand_child1->SetReplicaLayer(scoped_ptr<LayerImpl>()); |
1109 EmulateDrawingOneFrame(root.get()); | 1112 EmulateDrawingOneFrame(root.get()); |
1110 ASSERT_EQ(old_content_rect.width(), | 1113 ASSERT_EQ(old_content_rect.width(), |
1111 child1->render_surface()->content_rect().width()); | 1114 child1->render_surface()->content_rect().width()); |
1112 ASSERT_EQ(old_content_rect.height(), | 1115 ASSERT_EQ(old_content_rect.height(), |
1113 child1->render_surface()->content_rect().height()); | 1116 child1->render_surface()->content_rect().height()); |
1114 | 1117 |
1115 EXPECT_FALSE(grand_child1->render_surface()); | |
1116 child_damage_rect = | 1118 child_damage_rect = |
1117 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1119 child1->render_surface()->damage_tracker()->current_damage_rect(); |
1118 root_damage_rect = | 1120 root_damage_rect = |
1119 root->render_surface()->damage_tracker()->current_damage_rect(); | 1121 root->render_surface()->damage_tracker()->current_damage_rect(); |
1120 | 1122 |
1121 EXPECT_EQ(gfx::Rect(189, 205, 12, 8).ToString(), | 1123 EXPECT_EQ(gfx::Rect(189, 205, 12, 8).ToString(), |
1122 child_damage_rect.ToString()); | 1124 child_damage_rect.ToString()); |
1123 EXPECT_EQ(gfx::Rect(289, 305, 12, 8).ToString(), root_damage_rect.ToString()); | 1125 EXPECT_EQ(gfx::Rect(289, 305, 12, 8).ToString(), root_damage_rect.ToString()); |
1124 } | 1126 } |
1125 | 1127 |
(...skipping 20 matching lines...) Expand all Loading... | |
1146 // Add opacity and a grand_child so that the render surface persists even | 1148 // Add opacity and a grand_child so that the render surface persists even |
1147 // after we remove the mask. | 1149 // after we remove the mask. |
1148 child->SetOpacity(0.5f); | 1150 child->SetOpacity(0.5f); |
1149 { | 1151 { |
1150 scoped_ptr<LayerImpl> grand_child = | 1152 scoped_ptr<LayerImpl> grand_child = |
1151 LayerImpl::Create(host_impl_.active_tree(), 4); | 1153 LayerImpl::Create(host_impl_.active_tree(), 4); |
1152 grand_child->SetPosition(gfx::PointF(2.f, 2.f)); | 1154 grand_child->SetPosition(gfx::PointF(2.f, 2.f)); |
1153 grand_child->SetBounds(gfx::Size(2, 2)); | 1155 grand_child->SetBounds(gfx::Size(2, 2)); |
1154 grand_child->SetContentBounds(gfx::Size(2, 2)); | 1156 grand_child->SetContentBounds(gfx::Size(2, 2)); |
1155 grand_child->SetDrawsContent(true); | 1157 grand_child->SetDrawsContent(true); |
1158 child->CreateRenderSurface(); | |
1156 child->AddChild(grand_child.Pass()); | 1159 child->AddChild(grand_child.Pass()); |
1157 } | 1160 } |
1158 EmulateDrawingOneFrame(root.get()); | 1161 EmulateDrawingOneFrame(root.get()); |
1159 | 1162 |
awoloszyn
2014/08/25 21:03:44
This test will be subsumed by the main-thread Rend
| |
1160 // Sanity check that a new surface was created for the child. | |
1161 ASSERT_TRUE(child->render_surface()); | |
1162 | |
1163 // CASE 1: the update_rect on a mask layer should damage the entire target | 1163 // CASE 1: the update_rect on a mask layer should damage the entire target |
1164 // surface. | 1164 // surface. |
1165 ClearDamageForAllSurfaces(root.get()); | 1165 ClearDamageForAllSurfaces(root.get()); |
1166 mask_layer->SetUpdateRect(gfx::RectF(1.f, 2.f, 3.f, 4.f)); | 1166 mask_layer->SetUpdateRect(gfx::RectF(1.f, 2.f, 3.f, 4.f)); |
1167 EmulateDrawingOneFrame(root.get()); | 1167 EmulateDrawingOneFrame(root.get()); |
1168 gfx::Rect child_damage_rect = | 1168 gfx::Rect child_damage_rect = |
1169 child->render_surface()->damage_tracker()->current_damage_rect(); | 1169 child->render_surface()->damage_tracker()->current_damage_rect(); |
1170 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1170 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
1171 | 1171 |
1172 // CASE 2: a property change on the mask layer should damage the entire | 1172 // CASE 2: a property change on the mask layer should damage the entire |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1462 gfx::Rect root_damage_rect = | 1462 gfx::Rect root_damage_rect = |
1463 root->render_surface()->damage_tracker()->current_damage_rect(); | 1463 root->render_surface()->damage_tracker()->current_damage_rect(); |
1464 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1464 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
1465 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1465 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
1466 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1466 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
1467 } | 1467 } |
1468 } | 1468 } |
1469 | 1469 |
1470 } // namespace | 1470 } // namespace |
1471 } // namespace cc | 1471 } // namespace cc |
OLD | NEW |