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_sorter.h" | 5 #include "cc/trees/layer_sorter.h" |
6 | 6 |
7 #include "cc/base/math_util.h" | 7 #include "cc/base/math_util.h" |
8 #include "cc/layers/layer_impl.h" | 8 #include "cc/layers/layer_impl.h" |
9 #include "cc/test/fake_impl_proxy.h" | 9 #include "cc/test/fake_impl_proxy.h" |
10 #include "cc/test/fake_layer_tree_host_impl.h" | 10 #include "cc/test/fake_layer_tree_host_impl.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 gfx::Transform neg4_translate; | 30 gfx::Transform neg4_translate; |
31 neg4_translate.Translate3d(0.0, 0.0, -4.0); | 31 neg4_translate.Translate3d(0.0, 0.0, -4.0); |
32 LayerShape front(2.f, 2.f, neg4_translate); | 32 LayerShape front(2.f, 2.f, neg4_translate); |
33 | 33 |
34 gfx::Transform neg5_translate; | 34 gfx::Transform neg5_translate; |
35 neg5_translate.Translate3d(0.0, 0.0, -5.0); | 35 neg5_translate.Translate3d(0.0, 0.0, -5.0); |
36 LayerShape back(2.f, 2.f, neg5_translate); | 36 LayerShape back(2.f, 2.f, neg5_translate); |
37 | 37 |
38 overlap_result = | 38 overlap_result = |
39 LayerSorter::CheckOverlap(&front, &back, z_threshold, &weight); | 39 LayerSorter::CheckOverlap(&front, &back, z_threshold, &weight); |
40 EXPECT_EQ(LayerSorter::B_BEFORE_A, overlap_result); | 40 EXPECT_EQ(LayerSorter::BBeforeA, overlap_result); |
41 EXPECT_EQ(1.f, weight); | 41 EXPECT_EQ(1.f, weight); |
42 | 42 |
43 overlap_result = | 43 overlap_result = |
44 LayerSorter::CheckOverlap(&back, &front, z_threshold, &weight); | 44 LayerSorter::CheckOverlap(&back, &front, z_threshold, &weight); |
45 EXPECT_EQ(LayerSorter::A_BEFORE_B, overlap_result); | 45 EXPECT_EQ(LayerSorter::ABeforeB, overlap_result); |
46 EXPECT_EQ(1.f, weight); | 46 EXPECT_EQ(1.f, weight); |
47 | 47 |
48 // One layer translated off to the right. No overlap should be detected. | 48 // One layer translated off to the right. No overlap should be detected. |
49 gfx::Transform right_translate; | 49 gfx::Transform right_translate; |
50 right_translate.Translate3d(10.0, 0.0, -5.0); | 50 right_translate.Translate3d(10.0, 0.0, -5.0); |
51 LayerShape back_right(2.f, 2.f, right_translate); | 51 LayerShape back_right(2.f, 2.f, right_translate); |
52 overlap_result = | 52 overlap_result = |
53 LayerSorter::CheckOverlap(&front, &back_right, z_threshold, &weight); | 53 LayerSorter::CheckOverlap(&front, &back_right, z_threshold, &weight); |
54 EXPECT_EQ(LayerSorter::NONE, overlap_result); | 54 EXPECT_EQ(LayerSorter::None, overlap_result); |
55 | 55 |
56 // When comparing a layer with itself, z difference is always 0. | 56 // When comparing a layer with itself, z difference is always 0. |
57 overlap_result = | 57 overlap_result = |
58 LayerSorter::CheckOverlap(&front, &front, z_threshold, &weight); | 58 LayerSorter::CheckOverlap(&front, &front, z_threshold, &weight); |
59 EXPECT_EQ(0.f, weight); | 59 EXPECT_EQ(0.f, weight); |
60 } | 60 } |
61 | 61 |
62 TEST(LayerSorterTest, RightAngleOverlap) { | 62 TEST(LayerSorterTest, RightAngleOverlap) { |
63 LayerSorter::ABCompareResult overlap_result; | 63 LayerSorter::ABCompareResult overlap_result; |
64 const float z_threshold = 0.1f; | 64 const float z_threshold = 0.1f; |
65 float weight = 0.f; | 65 float weight = 0.f; |
66 | 66 |
67 gfx::Transform perspective_matrix; | 67 gfx::Transform perspective_matrix; |
68 perspective_matrix.ApplyPerspectiveDepth(1000.0); | 68 perspective_matrix.ApplyPerspectiveDepth(1000.0); |
69 | 69 |
70 // Two layers forming a right angle with a perspective viewing transform. | 70 // Two layers forming a right angle with a perspective viewing transform. |
71 gfx::Transform left_face_matrix; | 71 gfx::Transform left_face_matrix; |
72 left_face_matrix.Translate3d(-1.0, 0.0, -5.0); | 72 left_face_matrix.Translate3d(-1.0, 0.0, -5.0); |
73 left_face_matrix.RotateAboutYAxis(-90.0); | 73 left_face_matrix.RotateAboutYAxis(-90.0); |
74 left_face_matrix.Translate(-1.0, -1.0); | 74 left_face_matrix.Translate(-1.0, -1.0); |
75 LayerShape left_face(2.f, 2.f, perspective_matrix * left_face_matrix); | 75 LayerShape left_face(2.f, 2.f, perspective_matrix * left_face_matrix); |
76 gfx::Transform front_face_matrix; | 76 gfx::Transform front_face_matrix; |
77 front_face_matrix.Translate3d(0.0, 0.0, -4.0); | 77 front_face_matrix.Translate3d(0.0, 0.0, -4.0); |
78 front_face_matrix.Translate(-1.0, -1.0); | 78 front_face_matrix.Translate(-1.0, -1.0); |
79 LayerShape front_face(2.f, 2.f, perspective_matrix * front_face_matrix); | 79 LayerShape front_face(2.f, 2.f, perspective_matrix * front_face_matrix); |
80 | 80 |
81 overlap_result = | 81 overlap_result = |
82 LayerSorter::CheckOverlap(&front_face, &left_face, z_threshold, &weight); | 82 LayerSorter::CheckOverlap(&front_face, &left_face, z_threshold, &weight); |
83 EXPECT_EQ(LayerSorter::B_BEFORE_A, overlap_result); | 83 EXPECT_EQ(LayerSorter::BBeforeA, overlap_result); |
84 } | 84 } |
85 | 85 |
86 TEST(LayerSorterTest, IntersectingLayerOverlap) { | 86 TEST(LayerSorterTest, IntersectingLayerOverlap) { |
87 LayerSorter::ABCompareResult overlap_result; | 87 LayerSorter::ABCompareResult overlap_result; |
88 const float z_threshold = 0.1f; | 88 const float z_threshold = 0.1f; |
89 float weight = 0.f; | 89 float weight = 0.f; |
90 | 90 |
91 gfx::Transform perspective_matrix; | 91 gfx::Transform perspective_matrix; |
92 perspective_matrix.ApplyPerspectiveDepth(1000.0); | 92 perspective_matrix.ApplyPerspectiveDepth(1000.0); |
93 | 93 |
94 // Intersecting layers. An explicit order will be returned based on relative z | 94 // Intersecting layers. An explicit order will be returned based on relative z |
95 // values at the overlapping features but the weight returned should be zero. | 95 // values at the overlapping features but the weight returned should be zero. |
96 gfx::Transform front_face_matrix; | 96 gfx::Transform front_face_matrix; |
97 front_face_matrix.Translate3d(0.0, 0.0, -4.0); | 97 front_face_matrix.Translate3d(0.0, 0.0, -4.0); |
98 front_face_matrix.Translate(-1.0, -1.0); | 98 front_face_matrix.Translate(-1.0, -1.0); |
99 LayerShape front_face(2.f, 2.f, perspective_matrix * front_face_matrix); | 99 LayerShape front_face(2.f, 2.f, perspective_matrix * front_face_matrix); |
100 | 100 |
101 gfx::Transform through_matrix; | 101 gfx::Transform through_matrix; |
102 through_matrix.Translate3d(0.0, 0.0, -4.0); | 102 through_matrix.Translate3d(0.0, 0.0, -4.0); |
103 through_matrix.RotateAboutYAxis(45.0); | 103 through_matrix.RotateAboutYAxis(45.0); |
104 through_matrix.Translate(-1.0, -1.0); | 104 through_matrix.Translate(-1.0, -1.0); |
105 LayerShape rotated_face(2.f, 2.f, perspective_matrix * through_matrix); | 105 LayerShape rotated_face(2.f, 2.f, perspective_matrix * through_matrix); |
106 overlap_result = LayerSorter::CheckOverlap(&front_face, | 106 overlap_result = LayerSorter::CheckOverlap(&front_face, |
107 &rotated_face, | 107 &rotated_face, |
108 z_threshold, | 108 z_threshold, |
109 &weight); | 109 &weight); |
110 EXPECT_NE(LayerSorter::NONE, overlap_result); | 110 EXPECT_NE(LayerSorter::None, overlap_result); |
111 EXPECT_EQ(0.f, weight); | 111 EXPECT_EQ(0.f, weight); |
112 } | 112 } |
113 | 113 |
114 TEST(LayerSorterTest, LayersAtAngleOverlap) { | 114 TEST(LayerSorterTest, LayersAtAngleOverlap) { |
115 LayerSorter::ABCompareResult overlap_result; | 115 LayerSorter::ABCompareResult overlap_result; |
116 const float z_threshold = 0.1f; | 116 const float z_threshold = 0.1f; |
117 float weight = 0.f; | 117 float weight = 0.f; |
118 | 118 |
119 // Trickier test with layers at an angle. | 119 // Trickier test with layers at an angle. |
120 // | 120 // |
(...skipping 17 matching lines...) Expand all Loading... |
138 transform_b.Translate(-4.0, -10.0); | 138 transform_b.Translate(-4.0, -10.0); |
139 LayerShape layer_b(8.f, 20.f, transform_b); | 139 LayerShape layer_b(8.f, 20.f, transform_b); |
140 | 140 |
141 gfx::Transform transform_c; | 141 gfx::Transform transform_c; |
142 transform_c.RotateAboutYAxis(40.0); | 142 transform_c.RotateAboutYAxis(40.0); |
143 transform_c.Translate(-4.0, -10.0); | 143 transform_c.Translate(-4.0, -10.0); |
144 LayerShape layer_c(8.f, 20.f, transform_c); | 144 LayerShape layer_c(8.f, 20.f, transform_c); |
145 | 145 |
146 overlap_result = | 146 overlap_result = |
147 LayerSorter::CheckOverlap(&layer_a, &layer_c, z_threshold, &weight); | 147 LayerSorter::CheckOverlap(&layer_a, &layer_c, z_threshold, &weight); |
148 EXPECT_EQ(LayerSorter::A_BEFORE_B, overlap_result); | 148 EXPECT_EQ(LayerSorter::ABeforeB, overlap_result); |
149 overlap_result = | 149 overlap_result = |
150 LayerSorter::CheckOverlap(&layer_c, &layer_b, z_threshold, &weight); | 150 LayerSorter::CheckOverlap(&layer_c, &layer_b, z_threshold, &weight); |
151 EXPECT_EQ(LayerSorter::A_BEFORE_B, overlap_result); | 151 EXPECT_EQ(LayerSorter::ABeforeB, overlap_result); |
152 overlap_result = | 152 overlap_result = |
153 LayerSorter::CheckOverlap(&layer_a, &layer_b, z_threshold, &weight); | 153 LayerSorter::CheckOverlap(&layer_a, &layer_b, z_threshold, &weight); |
154 EXPECT_EQ(LayerSorter::NONE, overlap_result); | 154 EXPECT_EQ(LayerSorter::None, overlap_result); |
155 } | 155 } |
156 | 156 |
157 TEST(LayerSorterTest, LayersUnderPathologicalPerspectiveTransform) { | 157 TEST(LayerSorterTest, LayersUnderPathologicalPerspectiveTransform) { |
158 LayerSorter::ABCompareResult overlap_result; | 158 LayerSorter::ABCompareResult overlap_result; |
159 const float z_threshold = 0.1f; | 159 const float z_threshold = 0.1f; |
160 float weight = 0.f; | 160 float weight = 0.f; |
161 | 161 |
162 // On perspective projection, if w becomes negative, the re-projected point | 162 // On perspective projection, if w becomes negative, the re-projected point |
163 // will be invalid and un-usable. Correct code needs to clip away portions of | 163 // will be invalid and un-usable. Correct code needs to clip away portions of |
164 // the geometry where w < 0. If the code uses the invalid value, it will think | 164 // the geometry where w < 0. If the code uses the invalid value, it will think |
(...skipping 20 matching lines...) Expand all Loading... |
185 | 185 |
186 // Sanity check that the test case actually covers the intended scenario, | 186 // Sanity check that the test case actually covers the intended scenario, |
187 // where part of layer B go behind the w = 0 plane. | 187 // where part of layer B go behind the w = 0 plane. |
188 gfx::QuadF test_quad = gfx::QuadF(gfx::RectF(-0.5f, -0.5f, 1.f, 1.f)); | 188 gfx::QuadF test_quad = gfx::QuadF(gfx::RectF(-0.5f, -0.5f, 1.f, 1.f)); |
189 bool clipped = false; | 189 bool clipped = false; |
190 MathUtil::MapQuad(perspective_matrix * transform_b, test_quad, &clipped); | 190 MathUtil::MapQuad(perspective_matrix * transform_b, test_quad, &clipped); |
191 ASSERT_TRUE(clipped); | 191 ASSERT_TRUE(clipped); |
192 | 192 |
193 overlap_result = | 193 overlap_result = |
194 LayerSorter::CheckOverlap(&layer_a, &layer_b, z_threshold, &weight); | 194 LayerSorter::CheckOverlap(&layer_a, &layer_b, z_threshold, &weight); |
195 EXPECT_EQ(LayerSorter::A_BEFORE_B, overlap_result); | 195 EXPECT_EQ(LayerSorter::ABeforeB, overlap_result); |
196 } | 196 } |
197 | 197 |
198 TEST(LayerSorterTest, VerifyExistingOrderingPreservedWhenNoZDiff) { | 198 TEST(LayerSorterTest, VerifyExistingOrderingPreservedWhenNoZDiff) { |
199 // If there is no reason to re-sort the layers (i.e. no 3d z difference), then | 199 // If there is no reason to re-sort the layers (i.e. no 3d z difference), then |
200 // the existing ordering provided on input should be retained. This test | 200 // the existing ordering provided on input should be retained. This test |
201 // covers the fix in https://bugs.webkit.org/show_bug.cgi?id=75046. Before | 201 // covers the fix in https://bugs.webkit.org/show_bug.cgi?id=75046. Before |
202 // this fix, ordering was accidentally reversed, causing bugs in z-index | 202 // this fix, ordering was accidentally reversed, causing bugs in z-index |
203 // ordering on websites when preserves3D triggered the LayerSorter. | 203 // ordering on websites when preserves3D triggered the LayerSorter. |
204 | 204 |
205 // Input list of layers: [1, 2, 3, 4, 5]. | 205 // Input list of layers: [1, 2, 3, 4, 5]. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 layer_sorter.Sort(layer_list.begin(), layer_list.end()); | 320 layer_sorter.Sort(layer_list.begin(), layer_list.end()); |
321 | 321 |
322 ASSERT_EQ(2u, layer_list.size()); | 322 ASSERT_EQ(2u, layer_list.size()); |
323 EXPECT_EQ(1, layer_list[0]->id()); | 323 EXPECT_EQ(1, layer_list[0]->id()); |
324 EXPECT_EQ(2, layer_list[1]->id()); | 324 EXPECT_EQ(2, layer_list[1]->id()); |
325 } | 325 } |
326 | 326 |
327 } // namespace | 327 } // namespace |
328 } // namespace cc | 328 } // namespace cc |
329 | 329 |
OLD | NEW |