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/layer_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "cc/animation/layer_animation_controller.h" | 10 #include "cc/animation/layer_animation_controller.h" |
| 11 #include "cc/animation/transform_operations.h" | 11 #include "cc/animation/transform_operations.h" |
| 12 #include "cc/base/math_util.h" | 12 #include "cc/base/math_util.h" |
| 13 #include "cc/layers/content_layer.h" | 13 #include "cc/layers/content_layer.h" |
| 14 #include "cc/layers/content_layer_client.h" | 14 #include "cc/layers/content_layer_client.h" |
| 15 #include "cc/layers/layer.h" | 15 #include "cc/layers/layer.h" |
| 16 #include "cc/layers/layer_client.h" | 16 #include "cc/layers/layer_client.h" |
| 17 #include "cc/layers/layer_impl.h" | 17 #include "cc/layers/layer_impl.h" |
| 18 #include "cc/layers/layer_iterator.h" | 18 #include "cc/layers/layer_iterator.h" |
| 19 #include "cc/layers/render_surface.h" | 19 #include "cc/layers/render_surface.h" |
| 20 #include "cc/layers/render_surface_impl.h" | 20 #include "cc/layers/render_surface_impl.h" |
| 21 #include "cc/output/copy_output_request.h" | 21 #include "cc/output/copy_output_request.h" |
| 22 #include "cc/output/copy_output_result.h" | 22 #include "cc/output/copy_output_result.h" |
| 23 #include "cc/test/animation_test_common.h" | 23 #include "cc/test/animation_test_common.h" |
| 24 #include "cc/test/fake_content_layer.h" | |
| 25 #include "cc/test/fake_content_layer_client.h" | |
| 26 #include "cc/test/fake_content_layer_impl.h" | |
| 24 #include "cc/test/fake_impl_proxy.h" | 27 #include "cc/test/fake_impl_proxy.h" |
| 25 #include "cc/test/fake_layer_tree_host.h" | 28 #include "cc/test/fake_layer_tree_host.h" |
| 26 #include "cc/test/fake_layer_tree_host_impl.h" | 29 #include "cc/test/fake_layer_tree_host_impl.h" |
| 27 #include "cc/test/fake_picture_layer.h" | 30 #include "cc/test/fake_picture_layer.h" |
| 28 #include "cc/test/fake_picture_layer_impl.h" | 31 #include "cc/test/fake_picture_layer_impl.h" |
| 29 #include "cc/test/geometry_test_utils.h" | 32 #include "cc/test/geometry_test_utils.h" |
| 30 #include "cc/test/layer_tree_host_common_test.h" | 33 #include "cc/test/layer_tree_host_common_test.h" |
| 31 #include "cc/test/test_task_graph_runner.h" | 34 #include "cc/test/test_task_graph_runner.h" |
| 32 #include "cc/trees/layer_tree_impl.h" | 35 #include "cc/trees/layer_tree_impl.h" |
| 33 #include "cc/trees/proxy.h" | 36 #include "cc/trees/proxy.h" |
| (...skipping 9217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9251 EXPECT_EQ(gfx::Rect(25, 25), | 9254 EXPECT_EQ(gfx::Rect(25, 25), |
| 9252 scroll_child->visible_rect_from_property_trees()); | 9255 scroll_child->visible_rect_from_property_trees()); |
| 9253 | 9256 |
| 9254 scroll_child->SetPosition(gfx::PointF(0, -10.f)); | 9257 scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
| 9255 scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f)); | 9258 scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
| 9256 ExecuteCalculateDrawProperties(root.get()); | 9259 ExecuteCalculateDrawProperties(root.get()); |
| 9257 EXPECT_EQ(gfx::Rect(0, 5, 25, 25), | 9260 EXPECT_EQ(gfx::Rect(0, 5, 25, 25), |
| 9258 scroll_child->visible_rect_from_property_trees()); | 9261 scroll_child->visible_rect_from_property_trees()); |
| 9259 } | 9262 } |
| 9260 | 9263 |
| 9264 static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | |
| 9265 } | |
| 9266 | |
| 9267 TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { | |
| 9268 gfx::Transform identity; | |
| 9269 FakeContentLayerClient client; | |
| 9270 scoped_refptr<Layer> root = Layer::Create(); | |
| 9271 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 9272 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 9273 scoped_refptr<LayerWithForcedDrawsContent> grandchild = | |
| 9274 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 9275 scoped_refptr<FakeContentLayer> greatgrandchild( | |
| 9276 FakeContentLayer::Create(&client)); | |
| 9277 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), | |
| 9278 gfx::PointF(), gfx::Size(100, 100), true, false); | |
| 9279 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), | |
| 9280 gfx::PointF(), gfx::Size(10, 10), true, false); | |
| 9281 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), | |
| 9282 gfx::PointF(), gfx::Size(10, 10), true, false); | |
| 9283 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(), | |
| 9284 gfx::PointF(), gfx::Size(10, 10), true, false); | |
| 9285 | |
| 9286 root->AddChild(child); | |
| 9287 child->AddChild(grandchild); | |
| 9288 grandchild->AddChild(greatgrandchild); | |
| 9289 | |
| 9290 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 9291 host->SetRootLayer(root); | |
| 9292 | |
| 9293 // Check the non-skipped case. | |
| 9294 ExecuteCalculateDrawProperties(root.get()); | |
| 9295 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees()); | |
| 9296 | |
| 9297 // Now we will reset the visible rect from property trees for the grandchild, | |
| 9298 // and we will configure |child| in several ways that should force the subtree | |
| 9299 // to be skipped. The visible content rect for |grandchild| should, therefore, | |
| 9300 // remain empty. | |
| 9301 grandchild->set_visible_rect_from_property_trees(gfx::Rect()); | |
| 9302 gfx::Transform singular; | |
| 9303 singular.matrix().set(0, 0, 0); | |
| 9304 | |
| 9305 child->SetTransform(singular); | |
| 9306 ExecuteCalculateDrawProperties(root.get()); | |
| 9307 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees()); | |
| 9308 child->SetTransform(identity); | |
| 9309 | |
| 9310 child->SetHideLayerAndSubtree(true); | |
| 9311 ExecuteCalculateDrawProperties(root.get()); | |
| 9312 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees()); | |
| 9313 child->SetHideLayerAndSubtree(false); | |
| 9314 | |
| 9315 child->SetOpacity(0.f); | |
| 9316 ExecuteCalculateDrawProperties(root.get()); | |
| 9317 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees()); | |
| 9318 | |
| 9319 // Now, even though child has zero opacity, we will configure _grandchild_ in | |
|
ajuma
2015/04/27 19:54:22
s/_grandchild_/|grandchild| (also below in the imp
Ian Vollick
2015/04/27 20:13:05
Done.
| |
| 9320 // several ways that should force the subtree to be processed anyhow. | |
| 9321 grandchild->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10))); | |
| 9322 ExecuteCalculateDrawProperties(root.get()); | |
| 9323 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees()); | |
| 9324 grandchild->set_visible_rect_from_property_trees(gfx::Rect()); | |
| 9325 grandchild->SetTouchEventHandlerRegion(Region()); | |
| 9326 ExecuteCalculateDrawProperties(root.get()); | |
| 9327 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees()); | |
| 9328 grandchild->set_visible_rect_from_property_trees(gfx::Rect()); | |
| 9329 | |
| 9330 greatgrandchild->RequestCopyOfOutput( | |
| 9331 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); | |
| 9332 ExecuteCalculateDrawProperties(root.get()); | |
| 9333 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees()); | |
| 9334 } | |
| 9335 | |
| 9336 TEST_F(LayerTreeHostCommonTest, SkippingSubtreeImpl) { | |
| 9337 FakeImplProxy proxy; | |
| 9338 TestSharedBitmapManager shared_bitmap_manager; | |
| 9339 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 9340 | |
| 9341 gfx::Transform identity; | |
| 9342 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); | |
| 9343 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2); | |
| 9344 scoped_ptr<LayerImpl> grandchild = | |
| 9345 LayerImpl::Create(host_impl.active_tree(), 3); | |
| 9346 | |
| 9347 scoped_ptr<FakeContentLayerImpl> greatgrandchild( | |
| 9348 FakeContentLayerImpl::Create(host_impl.active_tree(), 4)); | |
| 9349 | |
| 9350 child->SetDrawsContent(true); | |
| 9351 grandchild->SetDrawsContent(true); | |
| 9352 greatgrandchild->SetDrawsContent(true); | |
| 9353 | |
| 9354 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), | |
| 9355 gfx::PointF(), gfx::Size(100, 100), true, false, | |
| 9356 true); | |
| 9357 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), | |
| 9358 gfx::PointF(), gfx::Size(10, 10), true, false, | |
| 9359 false); | |
| 9360 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), | |
| 9361 gfx::PointF(), gfx::Size(10, 10), true, false, | |
| 9362 false); | |
| 9363 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(), | |
| 9364 gfx::PointF(), gfx::Size(10, 10), true, false, | |
| 9365 true); | |
| 9366 | |
| 9367 LayerImpl* child_ptr = child.get(); | |
| 9368 LayerImpl* grandchild_ptr = grandchild.get(); | |
| 9369 LayerImpl* greatgrandchild_ptr = greatgrandchild.get(); | |
| 9370 | |
| 9371 grandchild->AddChild(greatgrandchild.Pass()); | |
| 9372 child->AddChild(grandchild.Pass()); | |
| 9373 root->AddChild(child.Pass()); | |
| 9374 | |
| 9375 // Check the non-skipped case. | |
| 9376 ExecuteCalculateDrawProperties(root.get()); | |
| 9377 EXPECT_EQ(gfx::Rect(10, 10), | |
| 9378 grandchild_ptr->visible_rect_from_property_trees()); | |
| 9379 | |
| 9380 // Now we will reset the visible rect from property trees for the grandchild, | |
| 9381 // and we will configure |child| in several ways that should force the subtree | |
| 9382 // to be skipped. The visible content rect for |grandchild| should, therefore, | |
| 9383 // remain empty. | |
| 9384 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect()); | |
| 9385 gfx::Transform singular; | |
| 9386 singular.matrix().set(0, 0, 0); | |
| 9387 | |
| 9388 child_ptr->SetTransform(singular); | |
| 9389 ExecuteCalculateDrawProperties(root.get()); | |
| 9390 EXPECT_EQ(gfx::Rect(0, 0), | |
| 9391 grandchild_ptr->visible_rect_from_property_trees()); | |
| 9392 child_ptr->SetTransform(identity); | |
| 9393 | |
| 9394 child_ptr->SetHideLayerAndSubtree(true); | |
| 9395 ExecuteCalculateDrawProperties(root.get()); | |
| 9396 EXPECT_EQ(gfx::Rect(0, 0), | |
| 9397 grandchild_ptr->visible_rect_from_property_trees()); | |
| 9398 child_ptr->SetHideLayerAndSubtree(false); | |
| 9399 | |
| 9400 child_ptr->SetOpacity(0.f); | |
| 9401 ExecuteCalculateDrawProperties(root.get()); | |
| 9402 EXPECT_EQ(gfx::Rect(0, 0), | |
| 9403 grandchild_ptr->visible_rect_from_property_trees()); | |
| 9404 | |
| 9405 // Now, even though child has zero opacity, we will configure _grandchild_ in | |
| 9406 // several ways that should force the subtree to be processed anyhow. | |
| 9407 grandchild_ptr->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10))); | |
| 9408 ExecuteCalculateDrawProperties(root.get()); | |
| 9409 EXPECT_EQ(gfx::Rect(10, 10), | |
| 9410 grandchild_ptr->visible_rect_from_property_trees()); | |
| 9411 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect()); | |
| 9412 grandchild_ptr->SetTouchEventHandlerRegion(Region()); | |
| 9413 ExecuteCalculateDrawProperties(root.get()); | |
| 9414 EXPECT_EQ(gfx::Rect(0, 0), | |
| 9415 grandchild_ptr->visible_rect_from_property_trees()); | |
| 9416 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect()); | |
| 9417 | |
| 9418 ScopedPtrVector<CopyOutputRequest> requests; | |
| 9419 requests.push_back(CopyOutputRequest::CreateEmptyRequest()); | |
| 9420 | |
| 9421 greatgrandchild_ptr->PassCopyRequests(&requests); | |
| 9422 ExecuteCalculateDrawProperties(root.get()); | |
| 9423 EXPECT_EQ(gfx::Rect(10, 10), | |
| 9424 grandchild_ptr->visible_rect_from_property_trees()); | |
| 9425 } | |
| 9426 | |
| 9427 TEST_F(LayerTreeHostCommonTest, SkippingLayer) { | |
| 9428 gfx::Transform identity; | |
| 9429 FakeContentLayerClient client; | |
| 9430 scoped_refptr<Layer> root = Layer::Create(); | |
| 9431 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 9432 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 9433 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), | |
| 9434 gfx::PointF(), gfx::Size(100, 100), true, false); | |
| 9435 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), | |
| 9436 gfx::PointF(), gfx::Size(10, 10), true, false); | |
| 9437 root->AddChild(child); | |
| 9438 | |
| 9439 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 9440 host->SetRootLayer(root); | |
| 9441 | |
| 9442 ExecuteCalculateDrawProperties(root.get()); | |
| 9443 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees()); | |
| 9444 child->set_visible_rect_from_property_trees(gfx::Rect()); | |
| 9445 | |
| 9446 child->SetHideLayerAndSubtree(true); | |
| 9447 ExecuteCalculateDrawProperties(root.get()); | |
| 9448 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); | |
| 9449 child->SetHideLayerAndSubtree(false); | |
| 9450 | |
| 9451 child->SetBounds(gfx::Size()); | |
| 9452 ExecuteCalculateDrawProperties(root.get()); | |
| 9453 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); | |
| 9454 child->SetBounds(gfx::Size(10, 10)); | |
| 9455 | |
| 9456 gfx::Transform rotate; | |
| 9457 child->SetDoubleSided(false); | |
| 9458 rotate.RotateAboutXAxis(180.f); | |
| 9459 child->SetTransform(rotate); | |
| 9460 ExecuteCalculateDrawProperties(root.get()); | |
| 9461 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); | |
| 9462 child->SetDoubleSided(true); | |
| 9463 child->SetTransform(identity); | |
| 9464 | |
| 9465 child->SetOpacity(0.f); | |
| 9466 ExecuteCalculateDrawProperties(root.get()); | |
| 9467 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); | |
| 9468 } | |
| 9469 | |
| 9261 } // namespace | 9470 } // namespace |
| 9262 } // namespace cc | 9471 } // namespace cc |
| OLD | NEW |