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