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

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

Issue 465853004: Moving RenderSurface creation outside of CalcDrawProps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 scoped_ptr<LayerImpl> CreateTestTreeWithOneSurface() { 79 scoped_ptr<LayerImpl> CreateTestTreeWithOneSurface() {
80 scoped_ptr<LayerImpl> root = 80 scoped_ptr<LayerImpl> root =
81 LayerImpl::Create(host_impl_.active_tree(), 1); 81 LayerImpl::Create(host_impl_.active_tree(), 1);
82 scoped_ptr<LayerImpl> child = 82 scoped_ptr<LayerImpl> child =
83 LayerImpl::Create(host_impl_.active_tree(), 2); 83 LayerImpl::Create(host_impl_.active_tree(), 2);
84 84
85 root->SetPosition(gfx::PointF()); 85 root->SetPosition(gfx::PointF());
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->SetHasRenderSurface(true);
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->SetBounds(gfx::Size(30, 30)); 93 child->SetBounds(gfx::Size(30, 30));
94 child->SetContentBounds(gfx::Size(30, 30)); 94 child->SetContentBounds(gfx::Size(30, 30));
95 child->SetDrawsContent(true); 95 child->SetDrawsContent(true);
96 root->AddChild(child.Pass()); 96 root->AddChild(child.Pass());
97 97
98 return root.Pass(); 98 return root.Pass();
99 } 99 }
(...skipping 11 matching lines...) Expand all
111 LayerImpl::Create(host_impl_.active_tree(), 3); 111 LayerImpl::Create(host_impl_.active_tree(), 3);
112 scoped_ptr<LayerImpl> grand_child1 = 112 scoped_ptr<LayerImpl> grand_child1 =
113 LayerImpl::Create(host_impl_.active_tree(), 4); 113 LayerImpl::Create(host_impl_.active_tree(), 4);
114 scoped_ptr<LayerImpl> grand_child2 = 114 scoped_ptr<LayerImpl> grand_child2 =
115 LayerImpl::Create(host_impl_.active_tree(), 5); 115 LayerImpl::Create(host_impl_.active_tree(), 5);
116 116
117 root->SetPosition(gfx::PointF()); 117 root->SetPosition(gfx::PointF());
118 root->SetBounds(gfx::Size(500, 500)); 118 root->SetBounds(gfx::Size(500, 500));
119 root->SetContentBounds(gfx::Size(500, 500)); 119 root->SetContentBounds(gfx::Size(500, 500));
120 root->SetDrawsContent(true); 120 root->SetDrawsContent(true);
121 root->CreateRenderSurface(); 121 root->SetHasRenderSurface(true);
122 root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500)); 122 root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500));
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);
danakj 2014/09/03 19:30:33 does the opacity really matter anymore? do we need
awoloszyn 2014/09/09 15:31:36 Done.
132 child1->SetDrawsContent(false); 132 child1->SetDrawsContent(false);
133 child1->SetForceRenderSurface(true); 133 child1->SetHasRenderSurface(true);
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->SetHasRenderSurface(true);
danakj 2014/09/03 19:30:34 The comment at the top of this method suggests thi
awoloszyn 2014/09/09 15:31:36 This was an over-eager fix to some other tests. I
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
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->SetHasRenderSurface(true);
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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 921
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);
danakj 2014/09/03 19:30:33 do we need to do this anymore?
awoloszyn 2014/09/09 15:31:36 Have removed the SetOpacity, but we must keep the
930 child1->SetForceRenderSurface(false); 932 child1->SetHasRenderSurface(false);
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);
danakj 2014/09/03 19:30:34 and this?
awoloszyn 2014/09/09 15:31:36 Same as above, SetOpacity removed.
956 child1->SetForceRenderSurface(true); 958 child1->SetHasRenderSurface(true);
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
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());
danakj 2014/09/03 19:30:33 this seems like it should be there and we shouldn'
awoloszyn 2014/09/09 15:31:36 Done.
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
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->SetHasRenderSurface(true);
danakj 2014/09/03 19:30:33 move this up to the SetMaskLayer() call on L1144?
awoloszyn 2014/09/09 15:31:36 Done. And correct, we no longer need the opacity c
1156 child->AddChild(grand_child.Pass()); 1159 child->AddChild(grand_child.Pass());
1157 } 1160 }
1158 EmulateDrawingOneFrame(root.get()); 1161 EmulateDrawingOneFrame(root.get());
1159 1162
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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 root_damage_rect = 1370 root_damage_rect =
1371 root->render_surface()->damage_tracker()->current_damage_rect(); 1371 root->render_surface()->damage_tracker()->current_damage_rect();
1372 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString()); 1372 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString());
1373 } 1373 }
1374 1374
1375 TEST_F(DamageTrackerTest, VerifyDamageForEmptyLayerList) { 1375 TEST_F(DamageTrackerTest, VerifyDamageForEmptyLayerList) {
1376 // Though it should never happen, its a good idea to verify that the damage 1376 // Though it should never happen, its a good idea to verify that the damage
1377 // tracker does not crash when it receives an empty layer_list. 1377 // tracker does not crash when it receives an empty layer_list.
1378 1378
1379 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_.active_tree(), 1); 1379 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_.active_tree(), 1);
1380 root->CreateRenderSurface(); 1380 root->SetHasRenderSurface(true);
1381
1382 {
1383 LayerImplList render_surface_layer_list;
1384 ExecuteCalculateDrawProperties(root.get(), &render_surface_layer_list);
danakj 2014/09/03 19:30:33 why is this needed?
awoloszyn 2014/09/09 15:31:36 Since we now only set render_targets during CDP we
1385 }
1381 1386
1382 ASSERT_TRUE(root == root->render_target()); 1387 ASSERT_TRUE(root == root->render_target());
1383 RenderSurfaceImpl* target_surface = root->render_surface(); 1388 RenderSurfaceImpl* target_surface = root->render_surface();
1384 1389
1385 LayerImplList empty_list; 1390 LayerImplList empty_list;
1386 target_surface->damage_tracker()->UpdateDamageTrackingState( 1391 target_surface->damage_tracker()->UpdateDamageTrackingState(
1387 empty_list, 1392 empty_list,
1388 target_surface->OwningLayerId(), 1393 target_surface->OwningLayerId(),
1389 false, 1394 false,
1390 gfx::Rect(), 1395 gfx::Rect(),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 gfx::Rect root_damage_rect = 1467 gfx::Rect root_damage_rect =
1463 root->render_surface()->damage_tracker()->current_damage_rect(); 1468 root->render_surface()->damage_tracker()->current_damage_rect();
1464 gfx::Rect damage_we_care_about = gfx::Rect(i, i); 1469 gfx::Rect damage_we_care_about = gfx::Rect(i, i);
1465 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); 1470 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right());
1466 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); 1471 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom());
1467 } 1472 }
1468 } 1473 }
1469 1474
1470 } // namespace 1475 } // namespace
1471 } // namespace cc 1476 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698