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

Side by Side Diff: cc/layers/layer_position_constraint_unittest.cc

Issue 1783613004: CC Animation: Erase cc::LayerSettings everywhere. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@eraseandroid
Patch Set: Rebase. Created 4 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/layers/layer_position_constraint.h" 5 #include "cc/layers/layer_position_constraint.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "cc/layers/layer.h" 9 #include "cc/layers/layer.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
11 #include "cc/layers/layer_settings.h"
12 #include "cc/proto/layer_position_constraint.pb.h" 11 #include "cc/proto/layer_position_constraint.pb.h"
13 #include "cc/test/fake_layer_tree_host.h" 12 #include "cc/test/fake_layer_tree_host.h"
14 #include "cc/test/fake_proxy.h" 13 #include "cc/test/fake_proxy.h"
15 #include "cc/test/geometry_test_utils.h" 14 #include "cc/test/geometry_test_utils.h"
16 #include "cc/test/test_task_graph_runner.h" 15 #include "cc/test/test_task_graph_runner.h"
17 #include "cc/trees/layer_tree_host_common.h" 16 #include "cc/trees/layer_tree_host_common.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 namespace cc { 19 namespace cc {
21 namespace { 20 namespace {
22 21
23 class LayerWithForcedDrawsContent : public Layer { 22 class LayerWithForcedDrawsContent : public Layer {
24 public: 23 public:
25 explicit LayerWithForcedDrawsContent(const LayerSettings& settings) 24 LayerWithForcedDrawsContent() : Layer() {}
26 : Layer(settings) {}
27 25
28 bool DrawsContent() const override; 26 bool DrawsContent() const override;
29 27
30 private: 28 private:
31 ~LayerWithForcedDrawsContent() override {} 29 ~LayerWithForcedDrawsContent() override {}
32 }; 30 };
33 31
34 bool LayerWithForcedDrawsContent::DrawsContent() const { 32 bool LayerWithForcedDrawsContent::DrawsContent() const {
35 return true; 33 return true;
36 } 34 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 CreateTreeForTest(); 79 CreateTreeForTest();
82 fixed_to_top_left_.set_is_fixed_position(true); 80 fixed_to_top_left_.set_is_fixed_position(true);
83 fixed_to_bottom_right_.set_is_fixed_position(true); 81 fixed_to_bottom_right_.set_is_fixed_position(true);
84 fixed_to_bottom_right_.set_is_fixed_to_right_edge(true); 82 fixed_to_bottom_right_.set_is_fixed_to_right_edge(true);
85 fixed_to_bottom_right_.set_is_fixed_to_bottom_edge(true); 83 fixed_to_bottom_right_.set_is_fixed_to_bottom_edge(true);
86 } 84 }
87 85
88 void CreateTreeForTest() { 86 void CreateTreeForTest() {
89 // scroll_layer_ is the inner viewport scroll layer and child_ is the outer 87 // scroll_layer_ is the inner viewport scroll layer and child_ is the outer
90 // viewport scroll layer. 88 // viewport scroll layer.
91 root_ = Layer::Create(layer_settings_); 89 root_ = Layer::Create();
92 inner_viewport_container_layer_ = Layer::Create(layer_settings_); 90 inner_viewport_container_layer_ = Layer::Create();
93 scroll_layer_ = Layer::Create(layer_settings_); 91 scroll_layer_ = Layer::Create();
94 outer_viewport_container_layer_ = Layer::Create(layer_settings_); 92 outer_viewport_container_layer_ = Layer::Create();
95 child_transform_layer_ = Layer::Create(layer_settings_); 93 child_transform_layer_ = Layer::Create();
96 child_ = Layer::Create(layer_settings_); 94 child_ = Layer::Create();
97 grand_child_ = 95 grand_child_ = make_scoped_refptr(new LayerWithForcedDrawsContent());
98 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings_)); 96 great_grand_child_ = make_scoped_refptr(new LayerWithForcedDrawsContent());
99 great_grand_child_ =
100 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings_));
101 97
102 gfx::Transform IdentityMatrix; 98 gfx::Transform IdentityMatrix;
103 gfx::Point3F transform_origin; 99 gfx::Point3F transform_origin;
104 gfx::PointF position; 100 gfx::PointF position;
105 gfx::Size bounds(200, 200); 101 gfx::Size bounds(200, 200);
106 gfx::Size clip_bounds(100, 100); 102 gfx::Size clip_bounds(100, 100);
107 SetLayerPropertiesForTesting(inner_viewport_container_layer_.get(), 103 SetLayerPropertiesForTesting(inner_viewport_container_layer_.get(),
108 IdentityMatrix, transform_origin, position, 104 IdentityMatrix, transform_origin, position,
109 clip_bounds, true); 105 clip_bounds, true);
110 SetLayerPropertiesForTesting(scroll_layer_.get(), IdentityMatrix, 106 SetLayerPropertiesForTesting(scroll_layer_.get(), IdentityMatrix,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 outer_viewport_container_layer_impl_->children()[0].get(); 164 outer_viewport_container_layer_impl_->children()[0].get();
169 child_impl_ = child_transform_layer_impl_->children()[0].get(); 165 child_impl_ = child_transform_layer_impl_->children()[0].get();
170 grand_child_impl_ = child_impl_->children()[0].get(); 166 grand_child_impl_ = child_impl_->children()[0].get();
171 great_grand_child_impl_ = grand_child_impl_->children()[0].get(); 167 great_grand_child_impl_ = grand_child_impl_->children()[0].get();
172 } 168 }
173 169
174 protected: 170 protected:
175 FakeLayerTreeHostClient fake_client_; 171 FakeLayerTreeHostClient fake_client_;
176 TestTaskGraphRunner task_graph_runner_; 172 TestTaskGraphRunner task_graph_runner_;
177 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; 173 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
178 LayerSettings layer_settings_;
179 scoped_refptr<Layer> root_; 174 scoped_refptr<Layer> root_;
180 scoped_refptr<Layer> inner_viewport_container_layer_; 175 scoped_refptr<Layer> inner_viewport_container_layer_;
181 scoped_refptr<Layer> scroll_layer_; 176 scoped_refptr<Layer> scroll_layer_;
182 scoped_refptr<Layer> outer_viewport_container_layer_; 177 scoped_refptr<Layer> outer_viewport_container_layer_;
183 scoped_refptr<Layer> child_transform_layer_; 178 scoped_refptr<Layer> child_transform_layer_;
184 scoped_refptr<Layer> child_; 179 scoped_refptr<Layer> child_;
185 scoped_refptr<Layer> grand_child_; 180 scoped_refptr<Layer> grand_child_;
186 scoped_refptr<Layer> great_grand_child_; 181 scoped_refptr<Layer> great_grand_child_;
187 LayerImpl* root_impl_; 182 LayerImpl* root_impl_;
188 LayerImpl* inner_viewport_container_layer_impl_; 183 LayerImpl* inner_viewport_container_layer_impl_;
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 TEST_F(LayerPositionConstraintTest, 542 TEST_F(LayerPositionConstraintTest,
548 ScrollCompensationForFixedPositionLayerWithMultipleIntermediateSurfaces) { 543 ScrollCompensationForFixedPositionLayerWithMultipleIntermediateSurfaces) {
549 // This test checks for correct scroll compensation when the fixed-position 544 // This test checks for correct scroll compensation when the fixed-position
550 // container contributes to a different render surface than the fixed-position 545 // container contributes to a different render surface than the fixed-position
551 // layer, with additional render surfaces in-between. This checks that the 546 // layer, with additional render surfaces in-between. This checks that the
552 // conversion to ancestor surfaces is accumulated properly in the final matrix 547 // conversion to ancestor surfaces is accumulated properly in the final matrix
553 // transform. 548 // transform.
554 549
555 // Add one more layer to the test tree for this scenario. 550 // Add one more layer to the test tree for this scenario.
556 scoped_refptr<Layer> fixed_position_child = 551 scoped_refptr<Layer> fixed_position_child =
557 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings_)); 552 make_scoped_refptr(new LayerWithForcedDrawsContent());
558 SetLayerPropertiesForTesting(fixed_position_child.get(), gfx::Transform(), 553 SetLayerPropertiesForTesting(fixed_position_child.get(), gfx::Transform(),
559 gfx::Point3F(), gfx::PointF(), 554 gfx::Point3F(), gfx::PointF(),
560 gfx::Size(100, 100), true); 555 gfx::Size(100, 100), true);
561 great_grand_child_->AddChild(fixed_position_child); 556 great_grand_child_->AddChild(fixed_position_child);
562 557
563 // Actually set up the scenario here. 558 // Actually set up the scenario here.
564 child_->SetIsContainerForFixedPositionLayers(true); 559 child_->SetIsContainerForFixedPositionLayers(true);
565 grand_child_->SetPosition(gfx::PointF(8.f, 6.f)); 560 grand_child_->SetPosition(gfx::PointF(8.f, 6.f));
566 grand_child_->SetForceRenderSurface(true); 561 grand_child_->SetForceRenderSurface(true);
567 great_grand_child_->SetPosition(gfx::PointF(40.f, 60.f)); 562 great_grand_child_->SetPosition(gfx::PointF(40.f, 60.f));
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 LayerPositionConstraintTest, 699 LayerPositionConstraintTest,
705 ScrollCompensationForFixedPositionLayerWithMultipleSurfacesAndTransforms) { 700 ScrollCompensationForFixedPositionLayerWithMultipleSurfacesAndTransforms) {
706 // This test checks for correct scroll compensation when the fixed-position 701 // This test checks for correct scroll compensation when the fixed-position
707 // container contributes to a different render surface than the fixed-position 702 // container contributes to a different render surface than the fixed-position
708 // layer, with additional render surfaces in-between, and the fixed-position 703 // layer, with additional render surfaces in-between, and the fixed-position
709 // container is transformed. This checks that the conversion to ancestor 704 // container is transformed. This checks that the conversion to ancestor
710 // surfaces is accumulated properly in the final matrix transform. 705 // surfaces is accumulated properly in the final matrix transform.
711 706
712 // Add one more layer to the test tree for this scenario. 707 // Add one more layer to the test tree for this scenario.
713 scoped_refptr<Layer> fixed_position_child = 708 scoped_refptr<Layer> fixed_position_child =
714 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings_)); 709 make_scoped_refptr(new LayerWithForcedDrawsContent());
715 SetLayerPropertiesForTesting(fixed_position_child.get(), gfx::Transform(), 710 SetLayerPropertiesForTesting(fixed_position_child.get(), gfx::Transform(),
716 gfx::Point3F(), gfx::PointF(), 711 gfx::Point3F(), gfx::PointF(),
717 gfx::Size(100, 100), true); 712 gfx::Size(100, 100), true);
718 great_grand_child_->AddChild(fixed_position_child); 713 great_grand_child_->AddChild(fixed_position_child);
719 714
720 // Actually set up the scenario here. 715 // Actually set up the scenario here.
721 child_transform_layer_->SetIsContainerForFixedPositionLayers(true); 716 child_transform_layer_->SetIsContainerForFixedPositionLayers(true);
722 grand_child_->SetPosition(gfx::PointF(8.f, 6.f)); 717 grand_child_->SetPosition(gfx::PointF(8.f, 6.f));
723 grand_child_->SetForceRenderSurface(true); 718 grand_child_->SetForceRenderSurface(true);
724 great_grand_child_->SetPosition(gfx::PointF(40.f, 60.f)); 719 great_grand_child_->SetPosition(gfx::PointF(40.f, 60.f));
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 1031
1037 TEST_F(LayerPositionConstraintTest, 1032 TEST_F(LayerPositionConstraintTest,
1038 ScrollCompensationForFixedWithinFixedWithInterveningContainer) { 1033 ScrollCompensationForFixedWithinFixedWithInterveningContainer) {
1039 // This test checks scroll compensation for a fixed-position layer that is 1034 // This test checks scroll compensation for a fixed-position layer that is
1040 // inside of another fixed-position layer, but they have different fixed 1035 // inside of another fixed-position layer, but they have different fixed
1041 // position containers. In this situation, the child fixed-position element 1036 // position containers. In this situation, the child fixed-position element
1042 // would still have to compensate with respect to its container. 1037 // would still have to compensate with respect to its container.
1043 1038
1044 // Add one more layer to the hierarchy for this test. 1039 // Add one more layer to the hierarchy for this test.
1045 scoped_refptr<Layer> great_great_grand_child = 1040 scoped_refptr<Layer> great_great_grand_child =
1046 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings_)); 1041 make_scoped_refptr(new LayerWithForcedDrawsContent());
1047 great_grand_child_->AddChild(great_great_grand_child); 1042 great_grand_child_->AddChild(great_great_grand_child);
1048 1043
1049 child_->SetIsContainerForFixedPositionLayers(true); 1044 child_->SetIsContainerForFixedPositionLayers(true);
1050 grand_child_->SetPositionConstraint(fixed_to_top_left_); 1045 grand_child_->SetPositionConstraint(fixed_to_top_left_);
1051 great_grand_child_->SetIsContainerForFixedPositionLayers(true); 1046 great_grand_child_->SetIsContainerForFixedPositionLayers(true);
1052 great_grand_child_->SetScrollClipLayerId(root_->id()); 1047 great_grand_child_->SetScrollClipLayerId(root_->id());
1053 great_great_grand_child->SetPositionConstraint(fixed_to_top_left_); 1048 great_great_grand_child->SetPositionConstraint(fixed_to_top_left_);
1054 1049
1055 CommitAndUpdateImplPointers(); 1050 CommitAndUpdateImplPointers();
1056 1051
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 1084
1090 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_to_container2_transform, 1085 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_to_container2_transform,
1091 fixed_to_container2->DrawTransform()); 1086 fixed_to_container2->DrawTransform());
1092 } 1087 }
1093 1088
1094 TEST_F(LayerPositionConstraintTest, 1089 TEST_F(LayerPositionConstraintTest,
1095 ScrollCompensationForInnerViewportBoundsDelta) { 1090 ScrollCompensationForInnerViewportBoundsDelta) {
1096 // This test checks for correct scroll compensation when the fixed-position 1091 // This test checks for correct scroll compensation when the fixed-position
1097 // container is the inner viewport scroll layer and has non-zero bounds delta. 1092 // container is the inner viewport scroll layer and has non-zero bounds delta.
1098 scoped_refptr<Layer> fixed_child = 1093 scoped_refptr<Layer> fixed_child =
1099 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings_)); 1094 make_scoped_refptr(new LayerWithForcedDrawsContent());
1100 fixed_child->SetBounds(gfx::Size(300, 300)); 1095 fixed_child->SetBounds(gfx::Size(300, 300));
1101 scroll_layer_->AddChild(fixed_child); 1096 scroll_layer_->AddChild(fixed_child);
1102 fixed_child->SetPositionConstraint(fixed_to_top_left_); 1097 fixed_child->SetPositionConstraint(fixed_to_top_left_);
1103 1098
1104 CommitAndUpdateImplPointers(); 1099 CommitAndUpdateImplPointers();
1105 1100
1106 LayerImpl* fixed_child_impl = 1101 LayerImpl* fixed_child_impl =
1107 root_impl_->layer_tree_impl()->FindActiveTreeLayerById(fixed_child->id()); 1102 root_impl_->layer_tree_impl()->FindActiveTreeLayerById(fixed_child->id());
1108 1103
1109 // Case 1: fixed-container size delta of 20, 20 1104 // Case 1: fixed-container size delta of 20, 20
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 VerifySerializeAndDeserializeProto(true, false, true); 1159 VerifySerializeAndDeserializeProto(true, false, true);
1165 VerifySerializeAndDeserializeProto(true, false, false); 1160 VerifySerializeAndDeserializeProto(true, false, false);
1166 VerifySerializeAndDeserializeProto(false, true, true); 1161 VerifySerializeAndDeserializeProto(false, true, true);
1167 VerifySerializeAndDeserializeProto(false, true, false); 1162 VerifySerializeAndDeserializeProto(false, true, false);
1168 VerifySerializeAndDeserializeProto(false, false, true); 1163 VerifySerializeAndDeserializeProto(false, false, true);
1169 VerifySerializeAndDeserializeProto(false, false, false); 1164 VerifySerializeAndDeserializeProto(false, false, false);
1170 } 1165 }
1171 1166
1172 } // namespace 1167 } // namespace
1173 } // namespace cc 1168 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698