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

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

Issue 548963002: Generalize scroll parent work in CalculateDrawProperties Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 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
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 <set> 7 #include <set>
8 8
9 #include "cc/animation/layer_animation_controller.h" 9 #include "cc/animation/layer_animation_controller.h"
10 #include "cc/animation/transform_operations.h" 10 #include "cc/animation/transform_operations.h"
(...skipping 2860 matching lines...) Expand 10 before | Expand all | Expand 10 after
2871 true, 2871 true,
2872 false); 2872 false);
2873 SetLayerPropertiesForTesting(child.get(), 2873 SetLayerPropertiesForTesting(child.get(),
2874 identity_matrix, 2874 identity_matrix,
2875 gfx::Point3F(), 2875 gfx::Point3F(),
2876 gfx::PointF(5.f, 5.f), 2876 gfx::PointF(5.f, 5.f),
2877 gfx::Size(50, 50), 2877 gfx::Size(50, 50),
2878 true, 2878 true,
2879 false); 2879 false);
2880 2880
2881 child->draw_properties().sorted_for_recursion = true;
2882
2883 TransformOperations start_transform_operations; 2881 TransformOperations start_transform_operations;
2884 start_transform_operations.AppendScale(1.f, 0.f, 0.f); 2882 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
2885 2883
2886 TransformOperations end_transform_operations; 2884 TransformOperations end_transform_operations;
2887 end_transform_operations.AppendScale(1.f, 1.f, 0.f); 2885 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
2888 2886
2889 AddAnimatedTransformToLayer( 2887 AddAnimatedTransformToLayer(
2890 root.get(), 10.0, start_transform_operations, end_transform_operations); 2888 root.get(), 10.0, start_transform_operations, end_transform_operations);
2891 2889
2892 EXPECT_TRUE(root->TransformIsAnimating()); 2890 EXPECT_TRUE(root->TransformIsAnimating());
2893 2891
2894 ExecuteCalculateDrawProperties(root.get()); 2892 ExecuteCalculateDrawProperties(root.get());
2895
2896 EXPECT_FALSE(child->draw_properties().sorted_for_recursion);
2897 } 2893 }
2898 2894
2899 TEST_F(LayerTreeHostCommonTest, 2895 TEST_F(LayerTreeHostCommonTest,
2900 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { 2896 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
2901 scoped_refptr<Layer> root = Layer::Create(); 2897 scoped_refptr<Layer> root = Layer::Create();
2902 2898
2903 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 2899 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2904 host->SetRootLayer(root); 2900 host->SetRootLayer(root);
2905 2901
2906 gfx::Transform identity_matrix; 2902 gfx::Transform identity_matrix;
2907 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 2903 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2908 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); 2904 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2909 2905
2910 SetLayerPropertiesForTesting(root.get(), 2906 SetLayerPropertiesForTesting(root.get(),
2911 uninvertible_matrix, 2907 uninvertible_matrix,
2912 gfx::Point3F(), 2908 gfx::Point3F(),
2913 gfx::PointF(), 2909 gfx::PointF(),
2914 gfx::Size(100, 100), 2910 gfx::Size(100, 100),
2915 true, 2911 true,
2916 false); 2912 false);
2917 2913
2918 root->draw_properties().sorted_for_recursion = true;
2919
2920 EXPECT_FALSE(root->TransformIsAnimating()); 2914 EXPECT_FALSE(root->TransformIsAnimating());
2921 2915
2922 ExecuteCalculateDrawProperties(root.get()); 2916 ExecuteCalculateDrawProperties(root.get());
2923
2924 EXPECT_FALSE(root->draw_properties().sorted_for_recursion);
2925 } 2917 }
2926 2918
2927 TEST_F(LayerTreeHostCommonTest, 2919 TEST_F(LayerTreeHostCommonTest,
2928 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { 2920 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
2929 scoped_refptr<Layer> root = Layer::Create(); 2921 scoped_refptr<Layer> root = Layer::Create();
2930 scoped_refptr<Layer> render_surface1 = Layer::Create(); 2922 scoped_refptr<Layer> render_surface1 = Layer::Create();
2931 scoped_refptr<LayerWithForcedDrawsContent> child1 = 2923 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2932 make_scoped_refptr(new LayerWithForcedDrawsContent()); 2924 make_scoped_refptr(new LayerWithForcedDrawsContent());
2933 scoped_refptr<LayerWithForcedDrawsContent> child2 = 2925 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2934 make_scoped_refptr(new LayerWithForcedDrawsContent()); 2926 make_scoped_refptr(new LayerWithForcedDrawsContent());
(...skipping 4583 matching lines...) Expand 10 before | Expand all | Expand 10 after
7518 // right clip, our render_surface_layer_list's order should be unaffected. 7510 // right clip, our render_surface_layer_list's order should be unaffected.
7519 EXPECT_EQ(3u, render_surface_layer_list.size()); 7511 EXPECT_EQ(3u, render_surface_layer_list.size());
7520 EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); 7512 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
7521 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); 7513 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
7522 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); 7514 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
7523 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); 7515 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
7524 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); 7516 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
7525 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); 7517 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
7526 } 7518 }
7527 7519
7520 TEST_F(LayerTreeHostCommonTest, ScrollChildIsGrandchildOfLCA) {
7521 // A previously unhandled case for layer sorting was when the scroll child was
7522 // a grand child of the lowest common ancestor of the scroll child and parent.
7523 // For example,
7524 //
7525 // + root
7526 // + top_content
7527 // + scroll_child
7528 // + bottom_content
7529 // + scroll_parent_border
7530 // + scroll_parent_clip
7531 // + scroll_parent
7532 //
7533 FakeImplProxy proxy;
7534 TestSharedBitmapManager shared_bitmap_manager;
7535 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7536 host_impl.CreatePendingTree();
7537 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7538 scoped_ptr<LayerImpl> scroll_parent_border =
7539 LayerImpl::Create(host_impl.active_tree(), 2);
7540 scoped_ptr<LayerImpl> scroll_parent_clip =
7541 LayerImpl::Create(host_impl.active_tree(), 3);
7542 scoped_ptr<LayerImpl> scroll_parent =
7543 LayerImpl::Create(host_impl.active_tree(), 4);
7544 scoped_ptr<LayerImpl> scroll_child =
7545 LayerImpl::Create(host_impl.active_tree(), 5);
7546 scoped_ptr<LayerImpl> bottom_content =
7547 LayerImpl::Create(host_impl.active_tree(), 6);
7548 scoped_ptr<LayerImpl> top_content =
7549 LayerImpl::Create(host_impl.active_tree(), 7);
7550
7551 scroll_parent_clip->SetMasksToBounds(true);
7552
7553 scroll_child->SetScrollParent(scroll_parent.get());
7554 scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>);
7555 scroll_children->insert(scroll_child.get());
7556 scroll_parent->SetScrollChildren(scroll_children.release());
7557
7558 scroll_child->SetDrawsContent(true);
7559 scroll_parent->SetDrawsContent(true);
7560 top_content->SetDrawsContent(true);
7561 bottom_content->SetDrawsContent(true);
7562
7563 gfx::Transform identity_transform;
7564 gfx::Transform top_transform;
7565 top_transform.Translate3d(0.0, 0.0, 5.0);
7566 gfx::Transform bottom_transform;
7567 bottom_transform.Translate3d(0.0, 0.0, 3.0);
7568
7569 SetLayerPropertiesForTesting(root.get(),
7570 identity_transform,
7571 gfx::Point3F(),
7572 gfx::PointF(),
7573 gfx::Size(50, 50),
7574 true,
7575 false);
7576 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7577 identity_transform,
7578 gfx::Point3F(),
7579 gfx::PointF(),
7580 gfx::Size(40, 40),
7581 true,
7582 false);
7583 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7584 identity_transform,
7585 gfx::Point3F(),
7586 gfx::PointF(),
7587 gfx::Size(30, 30),
7588 true,
7589 false);
7590 SetLayerPropertiesForTesting(scroll_parent.get(),
7591 identity_transform,
7592 gfx::Point3F(),
7593 gfx::PointF(),
7594 gfx::Size(50, 50),
7595 true,
7596 false);
7597 SetLayerPropertiesForTesting(scroll_child.get(),
7598 identity_transform,
7599 gfx::Point3F(),
7600 gfx::PointF(),
7601 gfx::Size(50, 50),
7602 true,
7603 false);
7604 SetLayerPropertiesForTesting(top_content.get(),
7605 top_transform,
7606 gfx::Point3F(),
7607 gfx::PointF(),
7608 gfx::Size(50, 50),
7609 false,
7610 true);
7611 SetLayerPropertiesForTesting(bottom_content.get(),
7612 bottom_transform,
7613 gfx::Point3F(),
7614 gfx::PointF(),
7615 gfx::Size(50, 50),
7616 false,
7617 true);
7618
7619 scroll_child->SetShouldFlattenTransform(false);
7620 scroll_child->Set3dSortingContextId(1);
7621
7622 scroll_child->AddChild(bottom_content.Pass());
7623
7624 top_content->AddChild(scroll_child.Pass());
7625 root->AddChild(top_content.Pass());
7626
7627 scroll_parent_clip->AddChild(scroll_parent.Pass());
7628 scroll_parent_border->AddChild(scroll_parent_clip.Pass());
7629 root->AddChild(scroll_parent_border.Pass());
7630
7631 LayerImplList render_surface_layer_list;
7632 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7633 root.get(), root->bounds(), &render_surface_layer_list);
7634
7635 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7636
7637 EXPECT_TRUE(root->render_surface());
7638
7639 EXPECT_EQ(4u, root->render_surface()->layer_list().size());
7640 EXPECT_EQ(7, root->render_surface()->layer_list().at(0)->id());
7641 EXPECT_EQ(5, root->render_surface()->layer_list().at(1)->id());
7642 EXPECT_EQ(6, root->render_surface()->layer_list().at(2)->id());
7643 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
7644
7645 // Explicitly check that the sort weights of the two descendancs of the lowest
7646 // common ancestor of the scroll parent and child are ordered correctly.
7647 EXPECT_EQ(7, root->child_at(0)->id());
7648 EXPECT_EQ(2, root->child_at(1)->id());
7649 EXPECT_LT(root->child_at(1)->draw_properties().sort_weight,
7650 root->child_at(0)->draw_properties().sort_weight);
7651 }
7652
7653 TEST_F(LayerTreeHostCommonTest, ScrollWeightSetMultipleTimes) {
7654 // This is a case where we have to reset a previously set weight.
7655 // scroll_parent_1_border will get a negative weight because the child is
7656 // visited first. When we reach scroll child 2, we'll have to go back and
7657 // "fix" the weight for scroll_parent_2_border so that it sorts before
7658 // scroll_parent_1_border.
7659 //
7660 // + root
7661 // + scroll_parent_2_border
7662 // | + scroll_parent_2_clip
7663 // | + scroll_parent_2
7664 // |
7665 // + top_content
7666 // | + scroll_child_1
7667 // | + bottom_content
7668 // |
7669 // + scroll_parent_1_border
7670 // + scroll_parent_1_clip
7671 // + scroll_child_2
7672 // + scroll_parent_1
7673 //
7674 FakeImplProxy proxy;
7675 TestSharedBitmapManager shared_bitmap_manager;
7676 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7677 host_impl.CreatePendingTree();
7678 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7679
7680 scoped_ptr<LayerImpl> scroll_parent_1_border =
7681 LayerImpl::Create(host_impl.active_tree(), 2);
7682 scoped_ptr<LayerImpl> scroll_parent_1_clip =
7683 LayerImpl::Create(host_impl.active_tree(), 3);
7684 scoped_ptr<LayerImpl> scroll_parent_1 =
7685 LayerImpl::Create(host_impl.active_tree(), 4);
7686
7687 scoped_ptr<LayerImpl> scroll_child_1 =
7688 LayerImpl::Create(host_impl.active_tree(), 5);
7689
7690 scoped_ptr<LayerImpl> scroll_parent_2_border =
7691 LayerImpl::Create(host_impl.active_tree(), 6);
7692 scoped_ptr<LayerImpl> scroll_parent_2_clip =
7693 LayerImpl::Create(host_impl.active_tree(), 7);
7694 scoped_ptr<LayerImpl> scroll_parent_2 =
7695 LayerImpl::Create(host_impl.active_tree(), 8);
7696
7697 scoped_ptr<LayerImpl> scroll_child_2 =
7698 LayerImpl::Create(host_impl.active_tree(), 9);
7699
7700 scoped_ptr<LayerImpl> bottom_content =
7701 LayerImpl::Create(host_impl.active_tree(), 10);
7702 scoped_ptr<LayerImpl> top_content =
7703 LayerImpl::Create(host_impl.active_tree(), 11);
7704
7705 scroll_parent_1_clip->SetMasksToBounds(true);
7706 scroll_parent_2_clip->SetMasksToBounds(true);
7707
7708 scroll_child_1->SetScrollParent(scroll_parent_1.get());
7709 scroll_child_2->SetScrollParent(scroll_parent_2.get());
7710
7711 scoped_ptr<std::set<LayerImpl*> > scroll_children_1(new std::set<LayerImpl*>);
7712 scroll_children_1->insert(scroll_child_1.get());
7713 scroll_parent_1->SetScrollChildren(scroll_children_1.release());
7714
7715 scoped_ptr<std::set<LayerImpl*> > scroll_children_2(new std::set<LayerImpl*>);
7716 scroll_children_2->insert(scroll_child_2.get());
7717 scroll_parent_2->SetScrollChildren(scroll_children_2.release());
7718
7719 scroll_child_1->SetDrawsContent(true);
7720 scroll_child_2->SetDrawsContent(true);
7721 scroll_parent_1->SetDrawsContent(true);
7722 scroll_parent_2->SetDrawsContent(true);
7723
7724 top_content->SetDrawsContent(true);
7725 bottom_content->SetDrawsContent(true);
7726
7727 gfx::Transform identity_transform;
7728 gfx::Transform top_transform;
7729 top_transform.Translate3d(0.0, 0.0, 5.0);
7730 gfx::Transform bottom_transform;
7731 bottom_transform.Translate3d(0.0, 0.0, 3.0);
7732
7733 SetLayerPropertiesForTesting(root.get(),
7734 identity_transform,
7735 gfx::Point3F(),
7736 gfx::PointF(),
7737 gfx::Size(50, 50),
7738 true,
7739 false);
7740 SetLayerPropertiesForTesting(scroll_parent_1_border.get(),
7741 identity_transform,
7742 gfx::Point3F(),
7743 gfx::PointF(),
7744 gfx::Size(40, 40),
7745 true,
7746 false);
7747 SetLayerPropertiesForTesting(scroll_parent_1_clip.get(),
7748 identity_transform,
7749 gfx::Point3F(),
7750 gfx::PointF(),
7751 gfx::Size(30, 30),
7752 true,
7753 false);
7754 SetLayerPropertiesForTesting(scroll_parent_1.get(),
7755 identity_transform,
7756 gfx::Point3F(),
7757 gfx::PointF(),
7758 gfx::Size(50, 50),
7759 true,
7760 false);
7761 SetLayerPropertiesForTesting(scroll_parent_2_border.get(),
7762 identity_transform,
7763 gfx::Point3F(),
7764 gfx::PointF(),
7765 gfx::Size(40, 40),
7766 true,
7767 false);
7768 SetLayerPropertiesForTesting(scroll_parent_2_clip.get(),
7769 identity_transform,
7770 gfx::Point3F(),
7771 gfx::PointF(),
7772 gfx::Size(30, 30),
7773 true,
7774 false);
7775 SetLayerPropertiesForTesting(scroll_parent_2.get(),
7776 identity_transform,
7777 gfx::Point3F(),
7778 gfx::PointF(),
7779 gfx::Size(50, 50),
7780 true,
7781 false);
7782 SetLayerPropertiesForTesting(scroll_child_1.get(),
7783 identity_transform,
7784 gfx::Point3F(),
7785 gfx::PointF(),
7786 gfx::Size(50, 50),
7787 true,
7788 false);
7789 SetLayerPropertiesForTesting(scroll_child_2.get(),
7790 identity_transform,
7791 gfx::Point3F(),
7792 gfx::PointF(),
7793 gfx::Size(50, 50),
7794 true,
7795 false);
7796 SetLayerPropertiesForTesting(top_content.get(),
7797 top_transform,
7798 gfx::Point3F(),
7799 gfx::PointF(),
7800 gfx::Size(50, 50),
7801 false,
7802 true);
7803 SetLayerPropertiesForTesting(bottom_content.get(),
7804 bottom_transform,
7805 gfx::Point3F(),
7806 gfx::PointF(),
7807 gfx::Size(50, 50),
7808 false,
7809 true);
7810
7811 scroll_child_1->SetShouldFlattenTransform(false);
7812 scroll_child_1->Set3dSortingContextId(1);
7813
7814 scroll_child_2->SetShouldFlattenTransform(false);
7815 scroll_child_2->Set3dSortingContextId(1);
7816
7817 scroll_parent_2_clip->AddChild(scroll_parent_2.Pass());
7818 scroll_parent_2_border->AddChild(scroll_parent_2_clip.Pass());
7819 root->AddChild(scroll_parent_2_border.Pass());
7820
7821 scroll_child_1->AddChild(bottom_content.Pass());
7822 top_content->AddChild(scroll_child_1.Pass());
7823 root->AddChild(top_content.Pass());
7824
7825 scroll_parent_1_clip->AddChild(scroll_child_2.Pass());
7826 scroll_parent_1_clip->AddChild(scroll_parent_1.Pass());
7827 scroll_parent_1_border->AddChild(scroll_parent_1_clip.Pass());
7828 root->AddChild(scroll_parent_1_border.Pass());
7829
7830 LayerImplList render_surface_layer_list;
7831 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7832 root.get(), root->bounds(), &render_surface_layer_list);
7833
7834 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7835
7836 EXPECT_TRUE(root->render_surface());
7837
7838 EXPECT_GT(0, root->child_at(0)->draw_properties().sort_weight);
7839 EXPECT_GT(0, root->child_at(2)->draw_properties().sort_weight);
7840 EXPECT_LT(root->child_at(0)->draw_properties().sort_weight,
7841 root->child_at(2)->draw_properties().sort_weight);
7842 EXPECT_TRUE(root->draw_properties().children_need_sorting);
7843 }
7844
7528 TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) { 7845 TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) {
7529 // We rearrange layer list contributions if we have to visit children out of 7846 // We rearrange layer list contributions if we have to visit children out of
7530 // order, but it should be a 'stable' rearrangement. That is, the layer list 7847 // order, but it should be a 'stable' rearrangement. That is, the layer list
7531 // additions for a single layer should not be reordered, though their position 7848 // additions for a single layer should not be reordered, though their position
7532 // wrt to the contributions due to a sibling may vary. 7849 // wrt to the contributions due to a sibling may vary.
7533 // 7850 //
7534 // + root 7851 // + root
7535 // + scroll_child 7852 // + scroll_child
7536 // + top_content 7853 // + top_content
7537 // + bottom_content 7854 // + bottom_content
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
8554 EXPECT_FLOAT_EQ(4.f, 8871 EXPECT_FLOAT_EQ(4.f,
8555 child1_layer->replica_layer() 8872 child1_layer->replica_layer()
8556 ->mask_layer() 8873 ->mask_layer()
8557 ->draw_properties() 8874 ->draw_properties()
8558 .device_scale_factor); 8875 .device_scale_factor);
8559 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); 8876 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor);
8560 } 8877 }
8561 8878
8562 } // namespace 8879 } // namespace
8563 } // namespace cc 8880 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698