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

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

Issue 1056793009: Reconcile property tree and CDP layer skipping logic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 8 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/draw_property_utils.cc ('k') | no next file » | 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/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
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| and
9320 // |greatgrandchild| in several ways that should force the subtree to be
9321 // processed anyhow.
9322 grandchild->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
9323 ExecuteCalculateDrawProperties(root.get());
9324 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
9325 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
9326 grandchild->SetTouchEventHandlerRegion(Region());
9327 ExecuteCalculateDrawProperties(root.get());
9328 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
9329 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
9330
9331 greatgrandchild->RequestCopyOfOutput(
9332 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
9333 ExecuteCalculateDrawProperties(root.get());
9334 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
9335 }
9336
9337 TEST_F(LayerTreeHostCommonTest, SkippingSubtreeImpl) {
9338 FakeImplProxy proxy;
9339 TestSharedBitmapManager shared_bitmap_manager;
9340 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
9341
9342 gfx::Transform identity;
9343 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9344 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
9345 scoped_ptr<LayerImpl> grandchild =
9346 LayerImpl::Create(host_impl.active_tree(), 3);
9347
9348 scoped_ptr<FakeContentLayerImpl> greatgrandchild(
9349 FakeContentLayerImpl::Create(host_impl.active_tree(), 4));
9350
9351 child->SetDrawsContent(true);
9352 grandchild->SetDrawsContent(true);
9353 greatgrandchild->SetDrawsContent(true);
9354
9355 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9356 gfx::PointF(), gfx::Size(100, 100), true, false,
9357 true);
9358 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9359 gfx::PointF(), gfx::Size(10, 10), true, false,
9360 false);
9361 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
9362 gfx::PointF(), gfx::Size(10, 10), true, false,
9363 false);
9364 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
9365 gfx::PointF(), gfx::Size(10, 10), true, false,
9366 true);
9367
9368 LayerImpl* child_ptr = child.get();
9369 LayerImpl* grandchild_ptr = grandchild.get();
9370 LayerImpl* greatgrandchild_ptr = greatgrandchild.get();
9371
9372 grandchild->AddChild(greatgrandchild.Pass());
9373 child->AddChild(grandchild.Pass());
9374 root->AddChild(child.Pass());
9375
9376 // Check the non-skipped case.
9377 ExecuteCalculateDrawProperties(root.get());
9378 EXPECT_EQ(gfx::Rect(10, 10),
9379 grandchild_ptr->visible_rect_from_property_trees());
9380
9381 // Now we will reset the visible rect from property trees for the grandchild,
9382 // and we will configure |child| in several ways that should force the subtree
9383 // to be skipped. The visible content rect for |grandchild| should, therefore,
9384 // remain empty.
9385 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
9386 gfx::Transform singular;
9387 singular.matrix().set(0, 0, 0);
9388
9389 child_ptr->SetTransform(singular);
9390 ExecuteCalculateDrawProperties(root.get());
9391 EXPECT_EQ(gfx::Rect(0, 0),
9392 grandchild_ptr->visible_rect_from_property_trees());
9393 child_ptr->SetTransform(identity);
9394
9395 child_ptr->SetHideLayerAndSubtree(true);
9396 ExecuteCalculateDrawProperties(root.get());
9397 EXPECT_EQ(gfx::Rect(0, 0),
9398 grandchild_ptr->visible_rect_from_property_trees());
9399 child_ptr->SetHideLayerAndSubtree(false);
9400
9401 child_ptr->SetOpacity(0.f);
9402 ExecuteCalculateDrawProperties(root.get());
9403 EXPECT_EQ(gfx::Rect(0, 0),
9404 grandchild_ptr->visible_rect_from_property_trees());
9405
9406 // Now, even though child has zero opacity, we will configure |grandchild| and
9407 // |greatgrandchild| in several ways that should force the subtree to be
9408 // processed anyhow.
9409 grandchild_ptr->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
9410 ExecuteCalculateDrawProperties(root.get());
9411 EXPECT_EQ(gfx::Rect(10, 10),
9412 grandchild_ptr->visible_rect_from_property_trees());
9413 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
9414 grandchild_ptr->SetTouchEventHandlerRegion(Region());
9415 ExecuteCalculateDrawProperties(root.get());
9416 EXPECT_EQ(gfx::Rect(0, 0),
9417 grandchild_ptr->visible_rect_from_property_trees());
9418 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
9419
9420 ScopedPtrVector<CopyOutputRequest> requests;
9421 requests.push_back(CopyOutputRequest::CreateEmptyRequest());
9422
9423 greatgrandchild_ptr->PassCopyRequests(&requests);
9424 ExecuteCalculateDrawProperties(root.get());
9425 EXPECT_EQ(gfx::Rect(10, 10),
9426 grandchild_ptr->visible_rect_from_property_trees());
9427 }
9428
9429 TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
9430 gfx::Transform identity;
9431 FakeContentLayerClient client;
9432 scoped_refptr<Layer> root = Layer::Create();
9433 scoped_refptr<LayerWithForcedDrawsContent> child =
9434 make_scoped_refptr(new LayerWithForcedDrawsContent());
9435 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9436 gfx::PointF(), gfx::Size(100, 100), true, false);
9437 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9438 gfx::PointF(), gfx::Size(10, 10), true, false);
9439 root->AddChild(child);
9440
9441 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9442 host->SetRootLayer(root);
9443
9444 ExecuteCalculateDrawProperties(root.get());
9445 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
9446 child->set_visible_rect_from_property_trees(gfx::Rect());
9447
9448 child->SetHideLayerAndSubtree(true);
9449 ExecuteCalculateDrawProperties(root.get());
9450 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9451 child->SetHideLayerAndSubtree(false);
9452
9453 child->SetBounds(gfx::Size());
9454 ExecuteCalculateDrawProperties(root.get());
9455 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9456 child->SetBounds(gfx::Size(10, 10));
9457
9458 gfx::Transform rotate;
9459 child->SetDoubleSided(false);
9460 rotate.RotateAboutXAxis(180.f);
9461 child->SetTransform(rotate);
9462 ExecuteCalculateDrawProperties(root.get());
9463 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9464 child->SetDoubleSided(true);
9465 child->SetTransform(identity);
9466
9467 child->SetOpacity(0.f);
9468 ExecuteCalculateDrawProperties(root.get());
9469 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9470 }
9471
9261 } // namespace 9472 } // namespace
9262 } // namespace cc 9473 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/draw_property_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698