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

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, 2 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/layer_tree_host_common.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"
(...skipping 2875 matching lines...) Expand 10 before | Expand all | Expand 10 after
2886 true, 2886 true,
2887 false); 2887 false);
2888 SetLayerPropertiesForTesting(child.get(), 2888 SetLayerPropertiesForTesting(child.get(),
2889 identity_matrix, 2889 identity_matrix,
2890 gfx::Point3F(), 2890 gfx::Point3F(),
2891 gfx::PointF(5.f, 5.f), 2891 gfx::PointF(5.f, 5.f),
2892 gfx::Size(50, 50), 2892 gfx::Size(50, 50),
2893 true, 2893 true,
2894 false); 2894 false);
2895 2895
2896 child->draw_properties().sorted_for_recursion = true; 2896 int initial_sequence_number = child->draw_properties().sequence_number;
2897 2897
2898 TransformOperations start_transform_operations; 2898 TransformOperations start_transform_operations;
2899 start_transform_operations.AppendScale(1.f, 0.f, 0.f); 2899 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
2900 2900
2901 TransformOperations end_transform_operations; 2901 TransformOperations end_transform_operations;
2902 end_transform_operations.AppendScale(1.f, 1.f, 0.f); 2902 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
2903 2903
2904 AddAnimatedTransformToLayer( 2904 AddAnimatedTransformToLayer(
2905 root.get(), 10.0, start_transform_operations, end_transform_operations); 2905 root.get(), 10.0, start_transform_operations, end_transform_operations);
2906 2906
2907 EXPECT_TRUE(root->TransformIsAnimating()); 2907 EXPECT_TRUE(root->TransformIsAnimating());
2908 2908
2909 ExecuteCalculateDrawProperties(root.get()); 2909 ExecuteCalculateDrawProperties(root.get());
2910 2910
2911 EXPECT_FALSE(child->draw_properties().sorted_for_recursion); 2911 EXPECT_NE(initial_sequence_number, child->draw_properties().sequence_number);
2912 } 2912 }
2913 2913
2914 TEST_F(LayerTreeHostCommonTest, 2914 TEST_F(LayerTreeHostCommonTest,
2915 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { 2915 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
2916 scoped_refptr<Layer> root = Layer::Create(); 2916 scoped_refptr<Layer> root = Layer::Create();
2917 2917
2918 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); 2918 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
2919 host->SetRootLayer(root); 2919 host->SetRootLayer(root);
2920 2920
2921 gfx::Transform identity_matrix; 2921 gfx::Transform identity_matrix;
2922 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 2922 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2923 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); 2923 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2924 2924
2925 SetLayerPropertiesForTesting(root.get(), 2925 SetLayerPropertiesForTesting(root.get(),
2926 uninvertible_matrix, 2926 uninvertible_matrix,
2927 gfx::Point3F(), 2927 gfx::Point3F(),
2928 gfx::PointF(), 2928 gfx::PointF(),
2929 gfx::Size(100, 100), 2929 gfx::Size(100, 100),
2930 true, 2930 true,
2931 false); 2931 false);
2932 2932
2933 root->draw_properties().sorted_for_recursion = true; 2933 int initial_sequence_number = root->draw_properties().sequence_number;
2934 2934
2935 EXPECT_FALSE(root->TransformIsAnimating()); 2935 EXPECT_FALSE(root->TransformIsAnimating());
2936 2936
2937 ExecuteCalculateDrawProperties(root.get()); 2937 ExecuteCalculateDrawProperties(root.get());
2938 2938
2939 EXPECT_FALSE(root->draw_properties().sorted_for_recursion); 2939 EXPECT_NE(initial_sequence_number, root->draw_properties().sequence_number);
2940 } 2940 }
2941 2941
2942 TEST_F(LayerTreeHostCommonTest, 2942 TEST_F(LayerTreeHostCommonTest,
2943 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { 2943 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
2944 scoped_refptr<Layer> root = Layer::Create(); 2944 scoped_refptr<Layer> root = Layer::Create();
2945 scoped_refptr<Layer> render_surface1 = Layer::Create(); 2945 scoped_refptr<Layer> render_surface1 = Layer::Create();
2946 scoped_refptr<LayerWithForcedDrawsContent> child1 = 2946 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2947 make_scoped_refptr(new LayerWithForcedDrawsContent()); 2947 make_scoped_refptr(new LayerWithForcedDrawsContent());
2948 scoped_refptr<LayerWithForcedDrawsContent> child2 = 2948 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2949 make_scoped_refptr(new LayerWithForcedDrawsContent()); 2949 make_scoped_refptr(new LayerWithForcedDrawsContent());
(...skipping 3675 matching lines...) Expand 10 before | Expand all | Expand 10 after
6625 // The clip child should have inherited the clip parent's clip (projected to 6625 // The clip child should have inherited the clip parent's clip (projected to
6626 // the right space, of course), and should have the correctly sized visible 6626 // the right space, of course), and should have the correctly sized visible
6627 // content rect. 6627 // content rect.
6628 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), 6628 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6629 clip_child->clip_rect().ToString()); 6629 clip_child->clip_rect().ToString());
6630 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), 6630 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6631 clip_child->visible_content_rect().ToString()); 6631 clip_child->visible_content_rect().ToString());
6632 EXPECT_TRUE(clip_child->is_clipped()); 6632 EXPECT_TRUE(clip_child->is_clipped());
6633 } 6633 }
6634 6634
6635 TEST_F(LayerTreeHostCommonTest, ClipParentIsNotAnAncestor) {
6636 // We can get into a situation where a clip parent is not an ancestor if the
6637 // clip parent is also a scroll parent. Here's an example.
6638 //
6639 // + root
6640 // + scroll_parent_border
6641 // | + scroll_parent_clip
6642 // | + scroll_parent
6643 // + scroll_child
6644 // + intervening clip
6645 // + clip_child (clip_parent is the scroll parent).
6646 //
6647 // Gross, right?
6648
6649 scoped_refptr<Layer> root = Layer::Create();
6650 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
6651 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
6652 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
6653 make_scoped_refptr(new LayerWithForcedDrawsContent);
6654 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
6655 make_scoped_refptr(new LayerWithForcedDrawsContent);
6656 scoped_refptr<Layer> intervening = Layer::Create();
6657 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6658 make_scoped_refptr(new LayerWithForcedDrawsContent);
6659
6660 root->AddChild(scroll_child);
6661
6662 root->AddChild(scroll_parent_border);
6663 scroll_parent_border->AddChild(scroll_parent_clip);
6664 scroll_parent_clip->AddChild(scroll_parent);
6665
6666 scroll_parent_clip->SetMasksToBounds(true);
6667 intervening->SetMasksToBounds(true);
6668
6669 scroll_child->SetScrollParent(scroll_parent.get());
6670 scroll_child->AddChild(intervening);
6671 intervening->AddChild(clip_child);
6672
6673 clip_child->SetClipParent(scroll_parent.get());
6674
6675 gfx::Transform identity_transform;
6676 SetLayerPropertiesForTesting(root.get(),
6677 identity_transform,
6678 gfx::Point3F(),
6679 gfx::PointF(),
6680 gfx::Size(50, 50),
6681 true,
6682 false);
6683 SetLayerPropertiesForTesting(scroll_parent_border.get(),
6684 identity_transform,
6685 gfx::Point3F(),
6686 gfx::PointF(),
6687 gfx::Size(40, 40),
6688 true,
6689 false);
6690 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
6691 identity_transform,
6692 gfx::Point3F(),
6693 gfx::PointF(),
6694 gfx::Size(30, 30),
6695 true,
6696 false);
6697 SetLayerPropertiesForTesting(scroll_parent.get(),
6698 identity_transform,
6699 gfx::Point3F(),
6700 gfx::PointF(),
6701 gfx::Size(50, 50),
6702 true,
6703 false);
6704 SetLayerPropertiesForTesting(scroll_child.get(),
6705 identity_transform,
6706 gfx::Point3F(),
6707 gfx::PointF(),
6708 gfx::Size(50, 50),
6709 true,
6710 false);
6711 SetLayerPropertiesForTesting(intervening.get(),
6712 identity_transform,
6713 gfx::Point3F(),
6714 gfx::PointF(),
6715 gfx::Size(5, 5),
6716 true,
6717 false);
6718 SetLayerPropertiesForTesting(clip_child.get(),
6719 identity_transform,
6720 gfx::Point3F(),
6721 gfx::PointF(),
6722 gfx::Size(60, 60),
6723 true,
6724 false);
6725
6726 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
6727 host->SetRootLayer(root);
6728
6729 ExecuteCalculateDrawProperties(root.get());
6730
6731 EXPECT_TRUE(root->render_surface());
6732
6733 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6734 scroll_child->clip_rect().ToString());
6735 EXPECT_TRUE(scroll_child->is_clipped());
6736
6737 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6738 clip_child->clip_rect().ToString());
6739 EXPECT_TRUE(clip_child->is_clipped());
6740 }
6741
6635 TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { 6742 TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
6636 // Ensures that descendants of the clip child inherit the correct clip. 6743 // Ensures that descendants of the clip child inherit the correct clip.
6637 // 6744 //
6638 // root (a render surface) 6745 // root (a render surface)
6639 // + clip_parent (masks to bounds) 6746 // + clip_parent (masks to bounds)
6640 // + intervening (masks to bounds) 6747 // + intervening (masks to bounds)
6641 // + clip_child 6748 // + clip_child
6642 // + child 6749 // + child
6643 // 6750 //
6644 scoped_refptr<Layer> root = Layer::Create(); 6751 scoped_refptr<Layer> root = Layer::Create();
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
7044 7151
7045 ExecuteCalculateDrawProperties(root.get()); 7152 ExecuteCalculateDrawProperties(root.get());
7046 7153
7047 EXPECT_TRUE(root->render_surface()); 7154 EXPECT_TRUE(root->render_surface());
7048 7155
7049 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), 7156 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7050 scroll_child->clip_rect().ToString()); 7157 scroll_child->clip_rect().ToString());
7051 EXPECT_TRUE(scroll_child->is_clipped()); 7158 EXPECT_TRUE(scroll_child->is_clipped());
7052 } 7159 }
7053 7160
7161 TEST_F(LayerTreeHostCommonTest, ScrollParentIsNotAxisAlignedToTarget) {
7162 // It can be the case (depressingly) that a scroll parent is not axis aligned
7163 // with respect to its target. This is rare, though. Usually when a scroller
7164 // is transformed, it becomes a stacking context, and when an ancestor is
7165 // transformed, it usually takes its descendant scroller along with it. The
7166 // rules for 3d rendering contexts can bite us, however.
7167 //
7168 // It can be the case that the ancestor is transformed, but lies at the
7169 // boundary of a 3d rendering context, meaning that the matrix it passes to
7170 // its descendants is "flattened". Flattening is wonky it replaces the 3rd row
7171 // and column of the matrix with 0's and 1's as follows.
7172 //
7173 // # # 0 #
7174 // # # 0 #
7175 // 0 0 1 0
7176 // # # 0 #
7177 //
7178 // The # entries are unaffected by the flattening process. Flattening can
7179 // break axis alignment. This tests creates a scenario where flattening
7180 // becomes problematic:
7181 //
7182 // + root (transformed, should-flatten-transform)
7183 // + scroll_parent_border
7184 // | + scroll_parent_clip
7185 // | + scroll_parent
7186 // + scroll_child
7187 //
7188 scoped_refptr<Layer> root = Layer::Create();
7189 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7190 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7191 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7192 make_scoped_refptr(new LayerWithForcedDrawsContent);
7193 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7194 make_scoped_refptr(new LayerWithForcedDrawsContent);
7195
7196 root->AddChild(scroll_child);
7197
7198 root->AddChild(scroll_parent_border);
7199 scroll_parent_border->AddChild(scroll_parent_clip);
7200 scroll_parent_clip->AddChild(scroll_parent);
7201
7202 scroll_parent_clip->SetMasksToBounds(true);
7203
7204 scroll_child->SetScrollParent(scroll_parent.get());
7205
7206 gfx::Transform root_transform(0.7f,
7207 -0.7f,
7208 0.8f,
7209 10.f,
7210 0.7f,
7211 0.7f,
7212 1.3f,
7213 10.f,
7214 0.f,
7215 0.f,
7216 1.f,
7217 0.f,
7218 0.f,
7219 0.f,
7220 -.3f,
7221 1.f);
7222
7223 gfx::Transform identity_transform;
7224 SetLayerPropertiesForTesting(root.get(),
7225 root_transform,
7226 gfx::Point3F(),
7227 gfx::PointF(),
7228 gfx::Size(50, 50),
7229 true,
7230 false);
7231 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7232 identity_transform,
7233 gfx::Point3F(),
7234 gfx::PointF(),
7235 gfx::Size(40, 40),
7236 true,
7237 false);
7238 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7239 identity_transform,
7240 gfx::Point3F(),
7241 gfx::PointF(),
7242 gfx::Size(30, 30),
7243 true,
7244 false);
7245 SetLayerPropertiesForTesting(scroll_parent.get(),
7246 identity_transform,
7247 gfx::Point3F(),
7248 gfx::PointF(),
7249 gfx::Size(50, 50),
7250 true,
7251 false);
7252 SetLayerPropertiesForTesting(scroll_child.get(),
7253 identity_transform,
7254 gfx::Point3F(),
7255 gfx::PointF(),
7256 gfx::Size(50, 50),
7257 true,
7258 false);
7259
7260 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
7261 host->SetRootLayer(root);
7262
7263 ExecuteCalculateDrawProperties(root.get());
7264
7265 EXPECT_TRUE(root->render_surface());
7266
7267 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7268 scroll_child->clip_rect().ToString());
7269 EXPECT_TRUE(scroll_child->is_clipped());
7270 }
7271
7054 TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { 7272 TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
7055 scoped_refptr<LayerWithForcedDrawsContent> root = 7273 scoped_refptr<LayerWithForcedDrawsContent> root =
7056 make_scoped_refptr(new LayerWithForcedDrawsContent); 7274 make_scoped_refptr(new LayerWithForcedDrawsContent);
7057 scoped_refptr<LayerWithForcedDrawsContent> parent = 7275 scoped_refptr<LayerWithForcedDrawsContent> parent =
7058 make_scoped_refptr(new LayerWithForcedDrawsContent); 7276 make_scoped_refptr(new LayerWithForcedDrawsContent);
7059 scoped_refptr<LayerWithForcedDrawsContent> child = 7277 scoped_refptr<LayerWithForcedDrawsContent> child =
7060 make_scoped_refptr(new LayerWithForcedDrawsContent); 7278 make_scoped_refptr(new LayerWithForcedDrawsContent);
7061 7279
7062 root->AddChild(parent); 7280 root->AddChild(parent);
7063 parent->AddChild(child); 7281 parent->AddChild(child);
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
7464 // right clip, our render_surface_layer_list's order should be unaffected. 7682 // right clip, our render_surface_layer_list's order should be unaffected.
7465 EXPECT_EQ(3u, render_surface_layer_list.size()); 7683 EXPECT_EQ(3u, render_surface_layer_list.size());
7466 EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); 7684 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
7467 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); 7685 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
7468 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); 7686 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
7469 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); 7687 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
7470 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); 7688 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
7471 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); 7689 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
7472 } 7690 }
7473 7691
7692 TEST_F(LayerTreeHostCommonTest, ScrollChildIsGrandchildOfLCA) {
7693 // A previously unhandled case for layer sorting was when the scroll child was
7694 // a grand child of the lowest common ancestor of the scroll child and parent.
7695 // For example,
7696 //
7697 // + root
7698 // + top_content
7699 // + scroll_child
7700 // + bottom_content
7701 // + scroll_parent_border
7702 // + scroll_parent_clip
7703 // + scroll_parent
7704 //
7705 FakeImplProxy proxy;
7706 TestSharedBitmapManager shared_bitmap_manager;
7707 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7708 host_impl.CreatePendingTree();
7709 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7710 scoped_ptr<LayerImpl> scroll_parent_border =
7711 LayerImpl::Create(host_impl.active_tree(), 2);
7712 scoped_ptr<LayerImpl> scroll_parent_clip =
7713 LayerImpl::Create(host_impl.active_tree(), 3);
7714 scoped_ptr<LayerImpl> scroll_parent =
7715 LayerImpl::Create(host_impl.active_tree(), 4);
7716 scoped_ptr<LayerImpl> scroll_child =
7717 LayerImpl::Create(host_impl.active_tree(), 5);
7718 scoped_ptr<LayerImpl> bottom_content =
7719 LayerImpl::Create(host_impl.active_tree(), 6);
7720 scoped_ptr<LayerImpl> top_content =
7721 LayerImpl::Create(host_impl.active_tree(), 7);
7722
7723 scroll_parent_clip->SetMasksToBounds(true);
7724
7725 scroll_child->SetScrollParent(scroll_parent.get());
7726 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
7727 scroll_children->insert(scroll_child.get());
7728 scroll_parent->SetScrollChildren(scroll_children.release());
7729
7730 scroll_child->SetDrawsContent(true);
7731 scroll_parent->SetDrawsContent(true);
7732 top_content->SetDrawsContent(true);
7733 bottom_content->SetDrawsContent(true);
7734
7735 gfx::Transform identity_transform;
7736 gfx::Transform top_transform;
7737 top_transform.Translate3d(0.0, 0.0, 5.0);
7738 gfx::Transform bottom_transform;
7739 bottom_transform.Translate3d(0.0, 0.0, 3.0);
7740
7741 SetLayerPropertiesForTesting(root.get(),
7742 identity_transform,
7743 gfx::Point3F(),
7744 gfx::PointF(),
7745 gfx::Size(50, 50),
7746 true,
7747 false);
7748 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7749 identity_transform,
7750 gfx::Point3F(),
7751 gfx::PointF(),
7752 gfx::Size(40, 40),
7753 true,
7754 false);
7755 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7756 identity_transform,
7757 gfx::Point3F(),
7758 gfx::PointF(),
7759 gfx::Size(30, 30),
7760 true,
7761 false);
7762 SetLayerPropertiesForTesting(scroll_parent.get(),
7763 identity_transform,
7764 gfx::Point3F(),
7765 gfx::PointF(),
7766 gfx::Size(50, 50),
7767 true,
7768 false);
7769 SetLayerPropertiesForTesting(scroll_child.get(),
7770 identity_transform,
7771 gfx::Point3F(),
7772 gfx::PointF(),
7773 gfx::Size(50, 50),
7774 true,
7775 false);
7776 SetLayerPropertiesForTesting(top_content.get(),
7777 top_transform,
7778 gfx::Point3F(),
7779 gfx::PointF(),
7780 gfx::Size(50, 50),
7781 false,
7782 true);
7783 SetLayerPropertiesForTesting(bottom_content.get(),
7784 bottom_transform,
7785 gfx::Point3F(),
7786 gfx::PointF(),
7787 gfx::Size(50, 50),
7788 false,
7789 true);
7790
7791 scroll_child->SetShouldFlattenTransform(false);
7792 scroll_child->Set3dSortingContextId(1);
7793
7794 scroll_child->AddChild(bottom_content.Pass());
7795
7796 top_content->AddChild(scroll_child.Pass());
7797 root->AddChild(top_content.Pass());
7798
7799 scroll_parent_clip->AddChild(scroll_parent.Pass());
7800 scroll_parent_border->AddChild(scroll_parent_clip.Pass());
7801 root->AddChild(scroll_parent_border.Pass());
7802
7803 LayerImplList render_surface_layer_list;
7804 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7805 root.get(), root->bounds(), &render_surface_layer_list);
7806
7807 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7808
7809 EXPECT_TRUE(root->render_surface());
7810
7811 EXPECT_EQ(4u, root->render_surface()->layer_list().size());
7812 EXPECT_EQ(7, root->render_surface()->layer_list().at(0)->id());
7813 EXPECT_EQ(5, root->render_surface()->layer_list().at(1)->id());
7814 EXPECT_EQ(6, root->render_surface()->layer_list().at(2)->id());
7815 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
7816
7817 // Explicitly check that the sort weights of the two descendancs of the lowest
7818 // common ancestor of the scroll parent and child are ordered correctly.
7819 EXPECT_EQ(7, root->child_at(0)->id());
7820 EXPECT_EQ(2, root->child_at(1)->id());
7821 EXPECT_LT(root->child_at(1)->draw_properties().sort_weight,
7822 root->child_at(0)->draw_properties().sort_weight);
7823 }
7824
7825 TEST_F(LayerTreeHostCommonTest, ScrollWeightSetMultipleTimes) {
7826 // This is a case where we have to reset a previously set weight.
7827 // scroll_parent_1_border will get a negative weight because the child is
7828 // visited first. When we reach scroll child 2, we'll have to go back and
7829 // "fix" the weight for scroll_parent_2_border so that it sorts before
7830 // scroll_parent_1_border.
7831 //
7832 // + root
7833 // + scroll_parent_2_border
7834 // | + scroll_parent_2_clip
7835 // | + scroll_parent_2
7836 // |
7837 // + top_content
7838 // | + scroll_child_1
7839 // | + bottom_content
7840 // |
7841 // + scroll_parent_1_border
7842 // + scroll_parent_1_clip
7843 // + scroll_child_2
7844 // + scroll_parent_1
7845 //
7846 FakeImplProxy proxy;
7847 TestSharedBitmapManager shared_bitmap_manager;
7848 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7849 host_impl.CreatePendingTree();
7850 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7851
7852 scoped_ptr<LayerImpl> scroll_parent_1_border =
7853 LayerImpl::Create(host_impl.active_tree(), 2);
7854 scoped_ptr<LayerImpl> scroll_parent_1_clip =
7855 LayerImpl::Create(host_impl.active_tree(), 3);
7856 scoped_ptr<LayerImpl> scroll_parent_1 =
7857 LayerImpl::Create(host_impl.active_tree(), 4);
7858
7859 scoped_ptr<LayerImpl> scroll_child_1 =
7860 LayerImpl::Create(host_impl.active_tree(), 5);
7861
7862 scoped_ptr<LayerImpl> scroll_parent_2_border =
7863 LayerImpl::Create(host_impl.active_tree(), 6);
7864 scoped_ptr<LayerImpl> scroll_parent_2_clip =
7865 LayerImpl::Create(host_impl.active_tree(), 7);
7866 scoped_ptr<LayerImpl> scroll_parent_2 =
7867 LayerImpl::Create(host_impl.active_tree(), 8);
7868
7869 scoped_ptr<LayerImpl> scroll_child_2 =
7870 LayerImpl::Create(host_impl.active_tree(), 9);
7871
7872 scoped_ptr<LayerImpl> bottom_content =
7873 LayerImpl::Create(host_impl.active_tree(), 10);
7874 scoped_ptr<LayerImpl> top_content =
7875 LayerImpl::Create(host_impl.active_tree(), 11);
7876
7877 scroll_parent_1_clip->SetMasksToBounds(true);
7878 scroll_parent_2_clip->SetMasksToBounds(true);
7879
7880 scroll_child_1->SetScrollParent(scroll_parent_1.get());
7881 scroll_child_2->SetScrollParent(scroll_parent_2.get());
7882
7883 scoped_ptr<std::set<LayerImpl*>> scroll_children_1(new std::set<LayerImpl*>);
7884 scroll_children_1->insert(scroll_child_1.get());
7885 scroll_parent_1->SetScrollChildren(scroll_children_1.release());
7886
7887 scoped_ptr<std::set<LayerImpl*>> scroll_children_2(new std::set<LayerImpl*>);
7888 scroll_children_2->insert(scroll_child_2.get());
7889 scroll_parent_2->SetScrollChildren(scroll_children_2.release());
7890
7891 scroll_child_1->SetDrawsContent(true);
7892 scroll_child_2->SetDrawsContent(true);
7893 scroll_parent_1->SetDrawsContent(true);
7894 scroll_parent_2->SetDrawsContent(true);
7895
7896 top_content->SetDrawsContent(true);
7897 bottom_content->SetDrawsContent(true);
7898
7899 gfx::Transform identity_transform;
7900 gfx::Transform top_transform;
7901 top_transform.Translate3d(0.0, 0.0, 5.0);
7902 gfx::Transform bottom_transform;
7903 bottom_transform.Translate3d(0.0, 0.0, 3.0);
7904
7905 SetLayerPropertiesForTesting(root.get(),
7906 identity_transform,
7907 gfx::Point3F(),
7908 gfx::PointF(),
7909 gfx::Size(50, 50),
7910 true,
7911 false);
7912 SetLayerPropertiesForTesting(scroll_parent_1_border.get(),
7913 identity_transform,
7914 gfx::Point3F(),
7915 gfx::PointF(),
7916 gfx::Size(40, 40),
7917 true,
7918 false);
7919 SetLayerPropertiesForTesting(scroll_parent_1_clip.get(),
7920 identity_transform,
7921 gfx::Point3F(),
7922 gfx::PointF(),
7923 gfx::Size(30, 30),
7924 true,
7925 false);
7926 SetLayerPropertiesForTesting(scroll_parent_1.get(),
7927 identity_transform,
7928 gfx::Point3F(),
7929 gfx::PointF(),
7930 gfx::Size(50, 50),
7931 true,
7932 false);
7933 SetLayerPropertiesForTesting(scroll_parent_2_border.get(),
7934 identity_transform,
7935 gfx::Point3F(),
7936 gfx::PointF(),
7937 gfx::Size(40, 40),
7938 true,
7939 false);
7940 SetLayerPropertiesForTesting(scroll_parent_2_clip.get(),
7941 identity_transform,
7942 gfx::Point3F(),
7943 gfx::PointF(),
7944 gfx::Size(30, 30),
7945 true,
7946 false);
7947 SetLayerPropertiesForTesting(scroll_parent_2.get(),
7948 identity_transform,
7949 gfx::Point3F(),
7950 gfx::PointF(),
7951 gfx::Size(50, 50),
7952 true,
7953 false);
7954 SetLayerPropertiesForTesting(scroll_child_1.get(),
7955 identity_transform,
7956 gfx::Point3F(),
7957 gfx::PointF(),
7958 gfx::Size(50, 50),
7959 true,
7960 false);
7961 SetLayerPropertiesForTesting(scroll_child_2.get(),
7962 identity_transform,
7963 gfx::Point3F(),
7964 gfx::PointF(),
7965 gfx::Size(50, 50),
7966 true,
7967 false);
7968 SetLayerPropertiesForTesting(top_content.get(),
7969 top_transform,
7970 gfx::Point3F(),
7971 gfx::PointF(),
7972 gfx::Size(50, 50),
7973 false,
7974 true);
7975 SetLayerPropertiesForTesting(bottom_content.get(),
7976 bottom_transform,
7977 gfx::Point3F(),
7978 gfx::PointF(),
7979 gfx::Size(50, 50),
7980 false,
7981 true);
7982
7983 scroll_child_1->SetShouldFlattenTransform(false);
7984 scroll_child_1->Set3dSortingContextId(1);
7985
7986 scroll_child_2->SetShouldFlattenTransform(false);
7987 scroll_child_2->Set3dSortingContextId(1);
7988
7989 scroll_parent_2_clip->AddChild(scroll_parent_2.Pass());
7990 scroll_parent_2_border->AddChild(scroll_parent_2_clip.Pass());
7991 root->AddChild(scroll_parent_2_border.Pass());
7992
7993 scroll_child_1->AddChild(bottom_content.Pass());
7994 top_content->AddChild(scroll_child_1.Pass());
7995 root->AddChild(top_content.Pass());
7996
7997 scroll_parent_1_clip->AddChild(scroll_child_2.Pass());
7998 scroll_parent_1_clip->AddChild(scroll_parent_1.Pass());
7999 scroll_parent_1_border->AddChild(scroll_parent_1_clip.Pass());
8000 root->AddChild(scroll_parent_1_border.Pass());
8001
8002 LayerImplList render_surface_layer_list;
8003 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8004 root.get(), root->bounds(), &render_surface_layer_list);
8005
8006 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8007
8008 EXPECT_TRUE(root->render_surface());
8009
8010 EXPECT_GT(0, root->child_at(0)->draw_properties().sort_weight);
8011 EXPECT_GT(0, root->child_at(2)->draw_properties().sort_weight);
8012 EXPECT_LT(root->child_at(0)->draw_properties().sort_weight,
8013 root->child_at(2)->draw_properties().sort_weight);
8014 EXPECT_TRUE(root->draw_properties().children_need_sorting);
8015 }
8016
7474 TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) { 8017 TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) {
7475 // We rearrange layer list contributions if we have to visit children out of 8018 // We rearrange layer list contributions if we have to visit children out of
7476 // order, but it should be a 'stable' rearrangement. That is, the layer list 8019 // order, but it should be a 'stable' rearrangement. That is, the layer list
7477 // additions for a single layer should not be reordered, though their position 8020 // additions for a single layer should not be reordered, though their position
7478 // wrt to the contributions due to a sibling may vary. 8021 // wrt to the contributions due to a sibling may vary.
7479 // 8022 //
7480 // + root 8023 // + root
7481 // + scroll_child 8024 // + scroll_child
7482 // + top_content 8025 // + top_content
7483 // + bottom_content 8026 // + bottom_content
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after
8557 // by the viewport. 9100 // by the viewport.
8558 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); 9101 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect());
8559 9102
8560 // Layers drawing to a child render surface should still have their visible 9103 // Layers drawing to a child render surface should still have their visible
8561 // content rect clipped by the viewport. 9104 // content rect clipped by the viewport.
8562 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); 9105 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect());
8563 } 9106 }
8564 9107
8565 } // namespace 9108 } // namespace
8566 } // namespace cc 9109 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_common.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698