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" |
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 #include "ui/gfx/geometry/size_conversions.h" |
21 | 22 |
22 namespace cc { | 23 namespace cc { |
23 namespace { | 24 namespace { |
24 | 25 |
25 void ExecuteCalculateDrawProperties(LayerImpl* root, | 26 void ExecuteCalculateDrawProperties(LayerImpl* root, |
26 LayerImplList* render_surface_layer_list) { | 27 LayerImplList* render_surface_layer_list) { |
27 // Sanity check: The test itself should create the root layer's render | 28 // Sanity check: The test itself should create the root layer's render |
28 // surface, so that the surface (and its damage tracker) can | 29 // surface, so that the surface (and its damage tracker) can |
29 // persist across multiple calls to this function. | 30 // persist across multiple calls to this function. |
30 ASSERT_TRUE(root->render_surface()); | 31 ASSERT_TRUE(root->render_surface()); |
31 ASSERT_FALSE(render_surface_layer_list->size()); | 32 ASSERT_FALSE(render_surface_layer_list->size()); |
32 | 33 |
33 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root); | 34 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root); |
34 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 35 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
35 root, root->bounds(), render_surface_layer_list); | 36 root, gfx::ToCeiledSize(root->bounds()), render_surface_layer_list); |
36 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 37 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
37 } | 38 } |
38 | 39 |
39 void ClearDamageForAllSurfaces(LayerImpl* layer) { | 40 void ClearDamageForAllSurfaces(LayerImpl* layer) { |
40 if (layer->render_surface()) | 41 if (layer->render_surface()) |
41 layer->render_surface()->damage_tracker()->DidDrawDamagedArea(); | 42 layer->render_surface()->damage_tracker()->DidDrawDamagedArea(); |
42 | 43 |
43 // Recursively clear damage for any existing surface. | 44 // Recursively clear damage for any existing surface. |
44 for (size_t i = 0; i < layer->children().size(); ++i) | 45 for (size_t i = 0; i < layer->children().size(); ++i) |
45 ClearDamageForAllSurfaces(layer->children()[i]); | 46 ClearDamageForAllSurfaces(layer->children()[i]); |
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 // In the current implementation of the damage tracker, changes to mask | 1131 // In the current implementation of the damage tracker, changes to mask |
1131 // layers should damage the entire corresponding surface. | 1132 // layers should damage the entire corresponding surface. |
1132 | 1133 |
1133 ClearDamageForAllSurfaces(root.get()); | 1134 ClearDamageForAllSurfaces(root.get()); |
1134 | 1135 |
1135 // Set up the mask layer. | 1136 // Set up the mask layer. |
1136 { | 1137 { |
1137 scoped_ptr<LayerImpl> mask_layer = | 1138 scoped_ptr<LayerImpl> mask_layer = |
1138 LayerImpl::Create(host_impl_.active_tree(), 3); | 1139 LayerImpl::Create(host_impl_.active_tree(), 3); |
1139 mask_layer->SetPosition(child->position()); | 1140 mask_layer->SetPosition(child->position()); |
1140 mask_layer->SetBounds(child->bounds()); | 1141 mask_layer->SetBounds(gfx::ToCeiledSize(child->bounds())); |
1141 mask_layer->SetContentBounds(child->bounds()); | 1142 mask_layer->SetContentBounds(gfx::ToCeiledSize(child->bounds())); |
1142 child->SetMaskLayer(mask_layer.Pass()); | 1143 child->SetMaskLayer(mask_layer.Pass()); |
1143 } | 1144 } |
1144 LayerImpl* mask_layer = child->mask_layer(); | 1145 LayerImpl* mask_layer = child->mask_layer(); |
1145 | 1146 |
1146 // Add opacity and a grand_child so that the render surface persists even | 1147 // Add opacity and a grand_child so that the render surface persists even |
1147 // after we remove the mask. | 1148 // after we remove the mask. |
1148 child->SetOpacity(0.5f); | 1149 child->SetOpacity(0.5f); |
1149 { | 1150 { |
1150 scoped_ptr<LayerImpl> grand_child = | 1151 scoped_ptr<LayerImpl> grand_child = |
1151 LayerImpl::Create(host_impl_.active_tree(), 4); | 1152 LayerImpl::Create(host_impl_.active_tree(), 4); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 grand_child1_replica->SetTransform(reflection); | 1235 grand_child1_replica->SetTransform(reflection); |
1235 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); | 1236 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); |
1236 } | 1237 } |
1237 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); | 1238 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); |
1238 | 1239 |
1239 // Set up the mask layer on the replica layer | 1240 // Set up the mask layer on the replica layer |
1240 { | 1241 { |
1241 scoped_ptr<LayerImpl> replica_mask_layer = | 1242 scoped_ptr<LayerImpl> replica_mask_layer = |
1242 LayerImpl::Create(host_impl_.active_tree(), 7); | 1243 LayerImpl::Create(host_impl_.active_tree(), 7); |
1243 replica_mask_layer->SetPosition(gfx::PointF()); | 1244 replica_mask_layer->SetPosition(gfx::PointF()); |
1244 replica_mask_layer->SetBounds(grand_child1->bounds()); | 1245 replica_mask_layer->SetBounds(gfx::ToCeiledSize(grand_child1->bounds())); |
1245 replica_mask_layer->SetContentBounds(grand_child1->bounds()); | 1246 replica_mask_layer->SetContentBounds( |
| 1247 gfx::ToCeiledSize(grand_child1->bounds())); |
1246 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass()); | 1248 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass()); |
1247 } | 1249 } |
1248 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); | 1250 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); |
1249 | 1251 |
1250 EmulateDrawingOneFrame(root.get()); | 1252 EmulateDrawingOneFrame(root.get()); |
1251 | 1253 |
1252 // Sanity check that the appropriate render surfaces were created | 1254 // Sanity check that the appropriate render surfaces were created |
1253 ASSERT_TRUE(grand_child1->render_surface()); | 1255 ASSERT_TRUE(grand_child1->render_surface()); |
1254 | 1256 |
1255 // CASE 1: a property change on the mask should damage only the reflected | 1257 // CASE 1: a property change on the mask should damage only the reflected |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); | 1314 grand_child1->SetReplicaLayer(grand_child1_replica.Pass()); |
1313 } | 1315 } |
1314 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); | 1316 LayerImpl* grand_child1_replica = grand_child1->replica_layer(); |
1315 | 1317 |
1316 // Set up the mask layer on the replica layer | 1318 // Set up the mask layer on the replica layer |
1317 { | 1319 { |
1318 scoped_ptr<LayerImpl> replica_mask_layer = | 1320 scoped_ptr<LayerImpl> replica_mask_layer = |
1319 LayerImpl::Create(host_impl_.active_tree(), 7); | 1321 LayerImpl::Create(host_impl_.active_tree(), 7); |
1320 replica_mask_layer->SetPosition(gfx::PointF()); | 1322 replica_mask_layer->SetPosition(gfx::PointF()); |
1321 // Note: this is not the transform origin being tested. | 1323 // Note: this is not the transform origin being tested. |
1322 replica_mask_layer->SetBounds(grand_child1->bounds()); | 1324 replica_mask_layer->SetBounds(gfx::ToCeiledSize(grand_child1->bounds())); |
1323 replica_mask_layer->SetContentBounds(grand_child1->bounds()); | 1325 replica_mask_layer->SetContentBounds( |
| 1326 gfx::ToCeiledSize(grand_child1->bounds())); |
1324 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass()); | 1327 grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass()); |
1325 } | 1328 } |
1326 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); | 1329 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); |
1327 | 1330 |
1328 EmulateDrawingOneFrame(root.get()); | 1331 EmulateDrawingOneFrame(root.get()); |
1329 | 1332 |
1330 // Sanity check that the appropriate render surfaces were created | 1333 // Sanity check that the appropriate render surfaces were created |
1331 ASSERT_TRUE(grand_child1->render_surface()); | 1334 ASSERT_TRUE(grand_child1->render_surface()); |
1332 | 1335 |
1333 // A property change on the replica_mask should damage the reflected region on | 1336 // A property change on the replica_mask should damage the reflected region on |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 gfx::Rect root_damage_rect = | 1465 gfx::Rect root_damage_rect = |
1463 root->render_surface()->damage_tracker()->current_damage_rect(); | 1466 root->render_surface()->damage_tracker()->current_damage_rect(); |
1464 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1467 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
1465 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1468 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
1466 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1469 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
1467 } | 1470 } |
1468 } | 1471 } |
1469 | 1472 |
1470 } // namespace | 1473 } // namespace |
1471 } // namespace cc | 1474 } // namespace cc |
OLD | NEW |