Chromium Code Reviews| 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 <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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 // not because of the old damage state. | 407 // not because of the old damage state. |
| 408 ClearDamageForAllSurfaces(root); | 408 ClearDamageForAllSurfaces(root); |
| 409 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 409 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 410 EmulateDrawingOneFrame(root); | 410 EmulateDrawingOneFrame(root); |
| 411 root_damage_rect = | 411 root_damage_rect = |
| 412 root->render_surface()->damage_tracker()->current_damage_rect(); | 412 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 413 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 413 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 414 | 414 |
| 415 // Then, test the actual layer movement. | 415 // Then, test the actual layer movement. |
| 416 ClearDamageForAllSurfaces(root); | 416 ClearDamageForAllSurfaces(root); |
| 417 child->SetPosition(gfx::PointF(200.f, 230.f)); | 417 gfx::Transform translation; |
| 418 child->NoteLayerPropertyChanged(); | 418 translation.Translate(100.f, 130.f); |
| 419 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 419 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 420 translation, child->transform_tree_index(), root->layer_tree_impl()); | |
|
ajuma
2016/09/23 14:10:58
The layer's original position is (100, 100). Movin
| |
| 420 EmulateDrawingOneFrame(root); | 421 EmulateDrawingOneFrame(root); |
| 421 | 422 |
| 422 // Expect damage to be the combination of the previous one and the new one. | 423 // Expect damage to be the combination of the previous one and the new one. |
| 423 expected_rect.Union(gfx::Rect(200, 230, 30, 30)); | 424 expected_rect.Union(gfx::Rect(200, 230, 30, 30)); |
| 424 root_damage_rect = | 425 root_damage_rect = |
| 425 root->render_surface()->damage_tracker()->current_damage_rect(); | 426 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 426 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); | 427 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); |
| 427 } | 428 } |
| 428 | 429 |
| 429 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) { | 430 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) { |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1067 // the entire child1 surface, but the damage tracker still needs the correct | 1068 // the entire child1 surface, but the damage tracker still needs the correct |
| 1068 // logic to compute the exposed region on the root surface. | 1069 // logic to compute the exposed region on the root surface. |
| 1069 | 1070 |
| 1070 // TODO(shawnsingh): the expectations of this test case should change when we | 1071 // TODO(shawnsingh): the expectations of this test case should change when we |
| 1071 // add support for a unique scissor_rect per RenderSurface. In that case, the | 1072 // add support for a unique scissor_rect per RenderSurface. In that case, the |
| 1072 // child1 surface should be completely unchanged, since we are only | 1073 // child1 surface should be completely unchanged, since we are only |
| 1073 // transforming it, while the root surface would be damaged appropriately. | 1074 // transforming it, while the root surface would be damaged appropriately. |
| 1074 | 1075 |
| 1075 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1076 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1076 LayerImpl* child1 = root->test_properties()->children[0]; | 1077 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1077 LayerImpl* grand_child1 = child1->test_properties()->children[0]; | |
| 1078 LayerImpl* grand_child2 = child1->test_properties()->children[1]; | |
| 1079 gfx::Rect child_damage_rect; | 1078 gfx::Rect child_damage_rect; |
| 1080 gfx::Rect root_damage_rect; | 1079 gfx::Rect root_damage_rect; |
| 1081 | 1080 |
| 1082 ClearDamageForAllSurfaces(root); | 1081 ClearDamageForAllSurfaces(root); |
| 1083 child1->SetPosition(gfx::PointF(50.f, 50.f)); | 1082 gfx::Transform translation; |
| 1084 child1->NoteLayerPropertyChanged(); | 1083 translation.Translate(-50.f, -50.f); |
| 1085 grand_child1->NoteLayerPropertyChanged(); | 1084 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 1086 grand_child2->NoteLayerPropertyChanged(); | 1085 translation, child1->transform_tree_index(), root->layer_tree_impl()); |
| 1087 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | |
| 1088 EmulateDrawingOneFrame(root); | 1086 EmulateDrawingOneFrame(root); |
| 1089 child_damage_rect = | 1087 child_damage_rect = |
| 1090 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1088 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 1091 root_damage_rect = | 1089 root_damage_rect = |
| 1092 root->render_surface()->damage_tracker()->current_damage_rect(); | 1090 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1093 | 1091 |
| 1094 // The new surface bounds should be damaged entirely. | 1092 // The new surface bounds should be damaged entirely. |
| 1095 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1093 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 1096 child_damage_rect.ToString()); | 1094 child_damage_rect.ToString()); |
| 1097 | 1095 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1265 // child surface damage should include the normal and replica surfaces. | 1263 // child surface damage should include the normal and replica surfaces. |
| 1266 EXPECT_EQ(gfx::Rect(6, 8).ToString(), grand_child_damage_rect.ToString()); | 1264 EXPECT_EQ(gfx::Rect(6, 8).ToString(), grand_child_damage_rect.ToString()); |
| 1267 EXPECT_EQ(gfx::Rect(194, 200, 12, 8).ToString(), | 1265 EXPECT_EQ(gfx::Rect(194, 200, 12, 8).ToString(), |
| 1268 child_damage_rect.ToString()); | 1266 child_damage_rect.ToString()); |
| 1269 EXPECT_EQ(gfx::Rect(294, 300, 12, 8).ToString(), root_damage_rect.ToString()); | 1267 EXPECT_EQ(gfx::Rect(294, 300, 12, 8).ToString(), root_damage_rect.ToString()); |
| 1270 | 1268 |
| 1271 // CASE 2: moving the descendant surface should cause both the original and | 1269 // CASE 2: moving the descendant surface should cause both the original and |
| 1272 // reflected areas to be damaged on the target. | 1270 // reflected areas to be damaged on the target. |
| 1273 ClearDamageForAllSurfaces(root); | 1271 ClearDamageForAllSurfaces(root); |
| 1274 gfx::Rect old_content_rect = child1->render_surface()->content_rect(); | 1272 gfx::Rect old_content_rect = child1->render_surface()->content_rect(); |
| 1275 grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); | 1273 gfx::Transform translation; |
| 1276 grand_child1->NoteLayerPropertyChanged(); | 1274 translation.Translate(-5.f, 5.f); |
| 1277 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1275 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 1276 translation, grand_child1->transform_tree_index(), | |
| 1277 root->layer_tree_impl()); | |
| 1278 grand_child1->test_properties()->transform = translation; | |
| 1278 EmulateDrawingOneFrame(root); | 1279 EmulateDrawingOneFrame(root); |
| 1279 ASSERT_EQ(old_content_rect.width(), | 1280 ASSERT_EQ(old_content_rect.width(), |
| 1280 child1->render_surface()->content_rect().width()); | 1281 child1->render_surface()->content_rect().width()); |
| 1281 ASSERT_EQ(old_content_rect.height(), | 1282 ASSERT_EQ(old_content_rect.height(), |
| 1282 child1->render_surface()->content_rect().height()); | 1283 child1->render_surface()->content_rect().height()); |
| 1283 | |
| 1284 grand_child_damage_rect = | 1284 grand_child_damage_rect = |
| 1285 grand_child1->render_surface()-> | 1285 grand_child1->render_surface()-> |
| 1286 damage_tracker()->current_damage_rect(); | 1286 damage_tracker()->current_damage_rect(); |
| 1287 child_damage_rect = | 1287 child_damage_rect = |
| 1288 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1288 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 1289 root_damage_rect = | 1289 root_damage_rect = |
| 1290 root->render_surface()->damage_tracker()->current_damage_rect(); | 1290 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1291 | 1291 |
| 1292 // The child surface damage should include normal and replica surfaces for | 1292 // The child surface damage should include normal and replica surfaces for |
| 1293 // both old and new locations. | 1293 // both old and new locations. |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1658 } | 1658 } |
| 1659 | 1659 |
| 1660 TEST_F(DamageTrackerTest, HugeDamageRect) { | 1660 TEST_F(DamageTrackerTest, HugeDamageRect) { |
| 1661 // This number is so large that we start losting floating point accuracy. | 1661 // This number is so large that we start losting floating point accuracy. |
| 1662 const int kBigNumber = 900000000; | 1662 const int kBigNumber = 900000000; |
| 1663 // Walk over a range to find floating point inaccuracy boundaries that move | 1663 // Walk over a range to find floating point inaccuracy boundaries that move |
| 1664 // toward the wrong direction. | 1664 // toward the wrong direction. |
| 1665 const int kRange = 5000; | 1665 const int kRange = 5000; |
| 1666 | 1666 |
| 1667 for (int i = 0; i < kRange; ++i) { | 1667 for (int i = 0; i < kRange; ++i) { |
| 1668 LayerImpl* root = CreateTestTreeWithOneSurface(); | 1668 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1669 LayerImpl* child = root->test_properties()->children[0]; | 1669 LayerImpl* child = root->test_properties()->children[0]; |
| 1670 | 1670 |
| 1671 gfx::Transform transform; | 1671 gfx::Transform transform; |
| 1672 transform.Translate(-kBigNumber, -kBigNumber); | 1672 transform.Translate(-kBigNumber, -kBigNumber); |
| 1673 | 1673 |
| 1674 // The child layer covers (0, 0, i, i) of the viewport, | 1674 // The child layer covers (0, 0, i, i) of the viewport, |
| 1675 // but has a huge negative position. | 1675 // but has a huge negative position. |
| 1676 child->SetPosition(gfx::PointF()); | 1676 child->SetPosition(gfx::PointF()); |
| 1677 child->SetBounds(gfx::Size(kBigNumber + i, kBigNumber + i)); | 1677 child->SetBounds(gfx::Size(kBigNumber + i, kBigNumber + i)); |
| 1678 child->test_properties()->transform = transform; | 1678 child->test_properties()->transform = transform; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1690 gfx::Rect root_damage_rect = | 1690 gfx::Rect root_damage_rect = |
| 1691 root->render_surface()->damage_tracker()->current_damage_rect(); | 1691 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1692 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1692 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
| 1693 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1693 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
| 1694 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1694 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
| 1695 } | 1695 } |
| 1696 } | 1696 } |
| 1697 | 1697 |
| 1698 } // namespace | 1698 } // namespace |
| 1699 } // namespace cc | 1699 } // namespace cc |
| OLD | NEW |