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

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

Issue 2035863003: cc: Add mask and replica layer ids to the effect tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 4 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
« no previous file with comments | « cc/trees/damage_tracker.cc ('k') | cc/trees/draw_property_utils.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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "cc/base/math_util.h" 9 #include "cc/base/math_util.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 // surfaces to ancestors. 61 // surfaces to ancestors.
62 size_t render_surface_layer_list_size = render_surface_layer_list.size(); 62 size_t render_surface_layer_list_size = render_surface_layer_list.size();
63 for (size_t i = 0; i < render_surface_layer_list_size; ++i) { 63 for (size_t i = 0; i < render_surface_layer_list_size; ++i) {
64 size_t index = render_surface_layer_list_size - 1 - i; 64 size_t index = render_surface_layer_list_size - 1 - i;
65 RenderSurfaceImpl* target_surface = 65 RenderSurfaceImpl* target_surface =
66 render_surface_layer_list[index]->render_surface(); 66 render_surface_layer_list[index]->render_surface();
67 target_surface->damage_tracker()->UpdateDamageTrackingState( 67 target_surface->damage_tracker()->UpdateDamageTrackingState(
68 target_surface->layer_list(), target_surface, 68 target_surface->layer_list(), target_surface,
69 target_surface->SurfacePropertyChangedOnlyFromDescendant(), 69 target_surface->SurfacePropertyChangedOnlyFromDescendant(),
70 target_surface->content_rect(), 70 target_surface->content_rect(),
71 render_surface_layer_list[index]->mask_layer(), 71 render_surface_layer_list[index]->render_surface()->MaskLayer(),
72 render_surface_layer_list[index]->filters()); 72 render_surface_layer_list[index]->filters());
73 } 73 }
74 74
75 root->layer_tree_impl()->ResetAllChangeTracking(); 75 root->layer_tree_impl()->ResetAllChangeTracking();
76 } 76 }
77 77
78 class DamageTrackerTest : public testing::Test { 78 class DamageTrackerTest : public testing::Test {
79 public: 79 public:
80 DamageTrackerTest() 80 DamageTrackerTest()
81 : host_impl_(&task_runner_provider_, 81 : host_impl_(&task_runner_provider_,
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 // CASE 1: adding a reflection about the left edge of grand_child1. 1192 // CASE 1: adding a reflection about the left edge of grand_child1.
1193 // 1193 //
1194 ClearDamageForAllSurfaces(root); 1194 ClearDamageForAllSurfaces(root);
1195 { 1195 {
1196 std::unique_ptr<LayerImpl> grand_child1_replica = 1196 std::unique_ptr<LayerImpl> grand_child1_replica =
1197 LayerImpl::Create(host_impl_.active_tree(), 7); 1197 LayerImpl::Create(host_impl_.active_tree(), 7);
1198 grand_child1_replica->SetPosition(gfx::PointF()); 1198 grand_child1_replica->SetPosition(gfx::PointF());
1199 gfx::Transform reflection; 1199 gfx::Transform reflection;
1200 reflection.Scale3d(-1.0, 1.0, 1.0); 1200 reflection.Scale3d(-1.0, 1.0, 1.0);
1201 grand_child1_replica->SetTransform(reflection); 1201 grand_child1_replica->SetTransform(reflection);
1202 grand_child1->SetReplicaLayer(std::move(grand_child1_replica)); 1202 grand_child1->test_properties()->SetReplicaLayer(
1203 std::move(grand_child1_replica));
1203 grand_child1->test_properties()->force_render_surface = true; 1204 grand_child1->test_properties()->force_render_surface = true;
1204 grand_child1->NoteLayerPropertyChanged(); 1205 grand_child1->NoteLayerPropertyChanged();
1205 } 1206 }
1206 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1207 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1207 EmulateDrawingOneFrame(root); 1208 EmulateDrawingOneFrame(root);
1208 1209
1209 gfx::Rect grand_child_damage_rect = 1210 gfx::Rect grand_child_damage_rect =
1210 grand_child1->render_surface()->damage_tracker()->current_damage_rect(); 1211 grand_child1->render_surface()->damage_tracker()->current_damage_rect();
1211 gfx::Rect child_damage_rect = 1212 gfx::Rect child_damage_rect =
1212 child1->render_surface()->damage_tracker()->current_damage_rect(); 1213 child1->render_surface()->damage_tracker()->current_damage_rect();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 // - new location in target space: gfx::Rect(189, 205, 12, 8) 1248 // - new location in target space: gfx::Rect(189, 205, 12, 8)
1248 EXPECT_EQ(gfx::Rect(6, 8).ToString(), grand_child_damage_rect.ToString()); 1249 EXPECT_EQ(gfx::Rect(6, 8).ToString(), grand_child_damage_rect.ToString());
1249 EXPECT_EQ(gfx::Rect(189, 200, 17, 13).ToString(), 1250 EXPECT_EQ(gfx::Rect(189, 200, 17, 13).ToString(),
1250 child_damage_rect.ToString()); 1251 child_damage_rect.ToString());
1251 EXPECT_EQ(gfx::Rect(289, 300, 17, 13).ToString(), 1252 EXPECT_EQ(gfx::Rect(289, 300, 17, 13).ToString(),
1252 root_damage_rect.ToString()); 1253 root_damage_rect.ToString());
1253 1254
1254 // CASE 3: removing the reflection should cause the entire region including 1255 // CASE 3: removing the reflection should cause the entire region including
1255 // reflection to damage the target surface. 1256 // reflection to damage the target surface.
1256 ClearDamageForAllSurfaces(root); 1257 ClearDamageForAllSurfaces(root);
1257 grand_child1->SetReplicaLayer(nullptr); 1258 grand_child1->test_properties()->SetReplicaLayer(nullptr);
1258 grand_child1->test_properties()->force_render_surface = false; 1259 grand_child1->test_properties()->force_render_surface = false;
1259 grand_child1->NoteLayerPropertyChanged(); 1260 grand_child1->NoteLayerPropertyChanged();
1260 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1261 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1261 EmulateDrawingOneFrame(root); 1262 EmulateDrawingOneFrame(root);
1262 ASSERT_EQ(old_content_rect.width(), 1263 ASSERT_EQ(old_content_rect.width(),
1263 child1->render_surface()->content_rect().width()); 1264 child1->render_surface()->content_rect().width());
1264 ASSERT_EQ(old_content_rect.height(), 1265 ASSERT_EQ(old_content_rect.height(),
1265 child1->render_surface()->content_rect().height()); 1266 child1->render_surface()->content_rect().height());
1266 1267
1267 EXPECT_FALSE(grand_child1->render_surface()); 1268 EXPECT_FALSE(grand_child1->render_surface());
(...skipping 15 matching lines...) Expand all
1283 // layers should damage the entire corresponding surface. 1284 // layers should damage the entire corresponding surface.
1284 1285
1285 ClearDamageForAllSurfaces(root); 1286 ClearDamageForAllSurfaces(root);
1286 1287
1287 // Set up the mask layer. 1288 // Set up the mask layer.
1288 { 1289 {
1289 std::unique_ptr<LayerImpl> mask_layer = 1290 std::unique_ptr<LayerImpl> mask_layer =
1290 LayerImpl::Create(host_impl_.active_tree(), 3); 1291 LayerImpl::Create(host_impl_.active_tree(), 3);
1291 mask_layer->SetPosition(child->position()); 1292 mask_layer->SetPosition(child->position());
1292 mask_layer->SetBounds(child->bounds()); 1293 mask_layer->SetBounds(child->bounds());
1293 child->SetMaskLayer(std::move(mask_layer)); 1294 child->test_properties()->SetMaskLayer(std::move(mask_layer));
1294 child->test_properties()->force_render_surface = true; 1295 child->test_properties()->force_render_surface = true;
1295 } 1296 }
1296 LayerImpl* mask_layer = child->mask_layer(); 1297 LayerImpl* mask_layer = child->test_properties()->mask_layer;
1297 1298
1298 // Add opacity and a grand_child so that the render surface persists even 1299 // Add opacity and a grand_child so that the render surface persists even
1299 // after we remove the mask. 1300 // after we remove the mask.
1300 { 1301 {
1301 std::unique_ptr<LayerImpl> grand_child = 1302 std::unique_ptr<LayerImpl> grand_child =
1302 LayerImpl::Create(host_impl_.active_tree(), 4); 1303 LayerImpl::Create(host_impl_.active_tree(), 4);
1303 grand_child->SetPosition(gfx::PointF(2.f, 2.f)); 1304 grand_child->SetPosition(gfx::PointF(2.f, 2.f));
1304 grand_child->SetBounds(gfx::Size(2, 2)); 1305 grand_child->SetBounds(gfx::Size(2, 2));
1305 grand_child->SetDrawsContent(true); 1306 grand_child->SetDrawsContent(true);
1306 child->AddChild(std::move(grand_child)); 1307 child->AddChild(std::move(grand_child));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 // leftover from the previous case. 1348 // leftover from the previous case.
1348 ClearDamageForAllSurfaces(root); 1349 ClearDamageForAllSurfaces(root);
1349 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1350 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1350 EmulateDrawingOneFrame(root); 1351 EmulateDrawingOneFrame(root);
1351 child_damage_rect = 1352 child_damage_rect =
1352 child->render_surface()->damage_tracker()->current_damage_rect(); 1353 child->render_surface()->damage_tracker()->current_damage_rect();
1353 EXPECT_TRUE(child_damage_rect.IsEmpty()); 1354 EXPECT_TRUE(child_damage_rect.IsEmpty());
1354 1355
1355 // Then test mask removal. 1356 // Then test mask removal.
1356 ClearDamageForAllSurfaces(root); 1357 ClearDamageForAllSurfaces(root);
1357 child->SetMaskLayer(nullptr); 1358 child->test_properties()->SetMaskLayer(nullptr);
1358 child->NoteLayerPropertyChanged(); 1359 child->NoteLayerPropertyChanged();
1359 ASSERT_TRUE(child->LayerPropertyChanged()); 1360 ASSERT_TRUE(child->LayerPropertyChanged());
1360 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1361 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1361 EmulateDrawingOneFrame(root); 1362 EmulateDrawingOneFrame(root);
1362 1363
1363 // Sanity check that a render surface still exists. 1364 // Sanity check that a render surface still exists.
1364 ASSERT_TRUE(child->render_surface()); 1365 ASSERT_TRUE(child->render_surface());
1365 1366
1366 child_damage_rect = 1367 child_damage_rect =
1367 child->render_surface()->damage_tracker()->current_damage_rect(); 1368 child->render_surface()->damage_tracker()->current_damage_rect();
(...skipping 11 matching lines...) Expand all
1379 ClearDamageForAllSurfaces(root); 1380 ClearDamageForAllSurfaces(root);
1380 1381
1381 // Create a reflection about the left edge of grand_child1. 1382 // Create a reflection about the left edge of grand_child1.
1382 { 1383 {
1383 std::unique_ptr<LayerImpl> grand_child1_replica = 1384 std::unique_ptr<LayerImpl> grand_child1_replica =
1384 LayerImpl::Create(host_impl_.active_tree(), 6); 1385 LayerImpl::Create(host_impl_.active_tree(), 6);
1385 grand_child1_replica->SetPosition(gfx::PointF()); 1386 grand_child1_replica->SetPosition(gfx::PointF());
1386 gfx::Transform reflection; 1387 gfx::Transform reflection;
1387 reflection.Scale3d(-1.0, 1.0, 1.0); 1388 reflection.Scale3d(-1.0, 1.0, 1.0);
1388 grand_child1_replica->SetTransform(reflection); 1389 grand_child1_replica->SetTransform(reflection);
1389 grand_child1->SetReplicaLayer(std::move(grand_child1_replica)); 1390 grand_child1->test_properties()->SetReplicaLayer(
1391 std::move(grand_child1_replica));
1390 grand_child1->test_properties()->force_render_surface = true; 1392 grand_child1->test_properties()->force_render_surface = true;
1391 } 1393 }
1392 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); 1394 LayerImpl* grand_child1_replica =
1395 grand_child1->test_properties()->replica_layer;
1393 1396
1394 // Set up the mask layer on the replica layer 1397 // Set up the mask layer on the replica layer
1395 { 1398 {
1396 std::unique_ptr<LayerImpl> replica_mask_layer = 1399 std::unique_ptr<LayerImpl> replica_mask_layer =
1397 LayerImpl::Create(host_impl_.active_tree(), 7); 1400 LayerImpl::Create(host_impl_.active_tree(), 7);
1398 replica_mask_layer->SetPosition(gfx::PointF()); 1401 replica_mask_layer->SetPosition(gfx::PointF());
1399 replica_mask_layer->SetBounds(grand_child1->bounds()); 1402 replica_mask_layer->SetBounds(grand_child1->bounds());
1400 grand_child1_replica->SetMaskLayer(std::move(replica_mask_layer)); 1403 grand_child1_replica->test_properties()->SetMaskLayer(
1404 std::move(replica_mask_layer));
1401 } 1405 }
1402 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); 1406 LayerImpl* replica_mask_layer =
1407 grand_child1_replica->test_properties()->mask_layer;
1403 1408
1404 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1409 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1405 EmulateDrawingOneFrame(root); 1410 EmulateDrawingOneFrame(root);
1406 1411
1407 // Sanity check that the appropriate render surfaces were created 1412 // Sanity check that the appropriate render surfaces were created
1408 ASSERT_TRUE(grand_child1->render_surface()); 1413 ASSERT_TRUE(grand_child1->render_surface());
1409 1414
1410 // CASE 1: a property change on the mask should damage only the reflected 1415 // CASE 1: a property change on the mask should damage only the reflected
1411 // region on the target surface. 1416 // region on the target surface.
1412 ClearDamageForAllSurfaces(root); 1417 ClearDamageForAllSurfaces(root);
1413 replica_mask_layer->NoteLayerPropertyChanged(); 1418 replica_mask_layer->NoteLayerPropertyChanged();
1414 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1419 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1415 EmulateDrawingOneFrame(root); 1420 EmulateDrawingOneFrame(root);
1416 1421
1417 gfx::Rect grand_child_damage_rect = 1422 gfx::Rect grand_child_damage_rect =
1418 grand_child1->render_surface()->damage_tracker()->current_damage_rect(); 1423 grand_child1->render_surface()->damage_tracker()->current_damage_rect();
1419 gfx::Rect child_damage_rect = 1424 gfx::Rect child_damage_rect =
1420 child1->render_surface()->damage_tracker()->current_damage_rect(); 1425 child1->render_surface()->damage_tracker()->current_damage_rect();
1421 1426
1422 EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); 1427 EXPECT_TRUE(grand_child_damage_rect.IsEmpty());
1423 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString()); 1428 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString());
1424 1429
1425 // CASE 2: removing the replica mask damages only the reflected region on the 1430 // CASE 2: removing the replica mask damages only the reflected region on the
1426 // target surface. 1431 // target surface.
1427 // 1432 //
1428 ClearDamageForAllSurfaces(root); 1433 ClearDamageForAllSurfaces(root);
1429 grand_child1_replica->SetMaskLayer(nullptr); 1434 grand_child1_replica->test_properties()->SetMaskLayer(nullptr);
1430 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1435 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1431 EmulateDrawingOneFrame(root); 1436 EmulateDrawingOneFrame(root);
1432 1437
1433 grand_child_damage_rect = 1438 grand_child_damage_rect =
1434 grand_child1->render_surface()->damage_tracker()-> 1439 grand_child1->render_surface()->damage_tracker()->
1435 current_damage_rect(); 1440 current_damage_rect();
1436 child_damage_rect = 1441 child_damage_rect =
1437 child1->render_surface()->damage_tracker()->current_damage_rect(); 1442 child1->render_surface()->damage_tracker()->current_damage_rect();
1438 1443
1439 EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); 1444 EXPECT_TRUE(grand_child_damage_rect.IsEmpty());
(...skipping 21 matching lines...) Expand all
1461 grand_child1_replica->SetPosition(gfx::PointF()); 1466 grand_child1_replica->SetPosition(gfx::PointF());
1462 1467
1463 // This is the anchor being tested. 1468 // This is the anchor being tested.
1464 grand_child1_replica->test_properties()->transform_origin = 1469 grand_child1_replica->test_properties()->transform_origin =
1465 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f); 1470 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f);
1466 gfx::Transform reflection; 1471 gfx::Transform reflection;
1467 reflection.Scale3d(-1.0, 1.0, 1.0); 1472 reflection.Scale3d(-1.0, 1.0, 1.0);
1468 grand_child1_replica->SetTransform(reflection); 1473 grand_child1_replica->SetTransform(reflection);
1469 // We need to set parent on replica layer for property tree building. 1474 // We need to set parent on replica layer for property tree building.
1470 grand_child1_replica->SetParent(grand_child1); 1475 grand_child1_replica->SetParent(grand_child1);
1471 grand_child1->SetReplicaLayer(std::move(grand_child1_replica)); 1476 grand_child1->test_properties()->SetReplicaLayer(
1477 std::move(grand_child1_replica));
1472 grand_child1->test_properties()->force_render_surface = true; 1478 grand_child1->test_properties()->force_render_surface = true;
1473 } 1479 }
1474 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); 1480 LayerImpl* grand_child1_replica =
1481 grand_child1->test_properties()->replica_layer;
1475 1482
1476 // Set up the mask layer on the replica layer 1483 // Set up the mask layer on the replica layer
1477 { 1484 {
1478 std::unique_ptr<LayerImpl> replica_mask_layer = 1485 std::unique_ptr<LayerImpl> replica_mask_layer =
1479 LayerImpl::Create(host_impl_.active_tree(), 7); 1486 LayerImpl::Create(host_impl_.active_tree(), 7);
1480 replica_mask_layer->SetPosition(gfx::PointF()); 1487 replica_mask_layer->SetPosition(gfx::PointF());
1481 // Note: this is not the transform origin being tested. 1488 // Note: this is not the transform origin being tested.
1482 replica_mask_layer->SetBounds(grand_child1->bounds()); 1489 replica_mask_layer->SetBounds(grand_child1->bounds());
1483 grand_child1_replica->SetMaskLayer(std::move(replica_mask_layer)); 1490 grand_child1_replica->test_properties()->SetMaskLayer(
1491 std::move(replica_mask_layer));
1484 } 1492 }
1485 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); 1493 LayerImpl* replica_mask_layer =
1494 grand_child1_replica->test_properties()->mask_layer;
1486 1495
1487 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1496 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1488 EmulateDrawingOneFrame(root); 1497 EmulateDrawingOneFrame(root);
1489 1498
1490 // Sanity check that the appropriate render surfaces were created 1499 // Sanity check that the appropriate render surfaces were created
1491 ASSERT_TRUE(grand_child1->render_surface()); 1500 ASSERT_TRUE(grand_child1->render_surface());
1492 1501
1493 // A property change on the replica_mask should damage the reflected region on 1502 // A property change on the replica_mask should damage the reflected region on
1494 // the target surface. 1503 // the target surface.
1495 ClearDamageForAllSurfaces(root); 1504 ClearDamageForAllSurfaces(root);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 gfx::Rect root_damage_rect = 1637 gfx::Rect root_damage_rect =
1629 root->render_surface()->damage_tracker()->current_damage_rect(); 1638 root->render_surface()->damage_tracker()->current_damage_rect();
1630 gfx::Rect damage_we_care_about = gfx::Rect(i, i); 1639 gfx::Rect damage_we_care_about = gfx::Rect(i, i);
1631 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); 1640 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right());
1632 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); 1641 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom());
1633 } 1642 }
1634 } 1643 }
1635 1644
1636 } // namespace 1645 } // namespace
1637 } // namespace cc 1646 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/damage_tracker.cc ('k') | cc/trees/draw_property_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698