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/layer_sorter.h" | 5 #include "cc/layer_sorter.h" |
6 | 6 |
7 #include "cc/layer_impl.h" | 7 #include "cc/layer_impl.h" |
8 #include "cc/math_util.h" | 8 #include "cc/math_util.h" |
9 #include "cc/single_thread_proxy.h" | 9 #include "cc/single_thread_proxy.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 LayerSorter::ABCompareResult overlapResult; | 57 LayerSorter::ABCompareResult overlapResult; |
58 const float zThreshold = 0.1f; | 58 const float zThreshold = 0.1f; |
59 float weight = 0; | 59 float weight = 0; |
60 | 60 |
61 gfx::Transform perspectiveMatrix; | 61 gfx::Transform perspectiveMatrix; |
62 perspectiveMatrix.ApplyPerspectiveDepth(1000); | 62 perspectiveMatrix.ApplyPerspectiveDepth(1000); |
63 | 63 |
64 // Two layers forming a right angle with a perspective viewing transform. | 64 // Two layers forming a right angle with a perspective viewing transform. |
65 gfx::Transform leftFaceMatrix; | 65 gfx::Transform leftFaceMatrix; |
66 leftFaceMatrix.Translate3d(-1, 0, -5); | 66 leftFaceMatrix.Translate3d(-1, 0, -5); |
67 MathUtil::rotateAxisAngle(&leftFaceMatrix, 0, 1, 0, -90); | 67 leftFaceMatrix.RotateAboutYAxis(-90); |
68 leftFaceMatrix.Translate(-1, -1); | 68 leftFaceMatrix.Translate(-1, -1); |
69 LayerShape leftFace(2, 2, perspectiveMatrix * leftFaceMatrix); | 69 LayerShape leftFace(2, 2, perspectiveMatrix * leftFaceMatrix); |
70 gfx::Transform frontFaceMatrix; | 70 gfx::Transform frontFaceMatrix; |
71 frontFaceMatrix.Translate3d(0, 0, -4); | 71 frontFaceMatrix.Translate3d(0, 0, -4); |
72 frontFaceMatrix.Translate(-1, -1); | 72 frontFaceMatrix.Translate(-1, -1); |
73 LayerShape frontFace(2, 2, perspectiveMatrix * frontFaceMatrix); | 73 LayerShape frontFace(2, 2, perspectiveMatrix * frontFaceMatrix); |
74 | 74 |
75 overlapResult = LayerSorter::checkOverlap(&frontFace, &leftFace, zThreshold,
weight); | 75 overlapResult = LayerSorter::checkOverlap(&frontFace, &leftFace, zThreshold,
weight); |
76 EXPECT_EQ(LayerSorter::BBeforeA, overlapResult); | 76 EXPECT_EQ(LayerSorter::BBeforeA, overlapResult); |
77 } | 77 } |
78 | 78 |
79 TEST(LayerSorterTest, IntersectingLayerOverlap) | 79 TEST(LayerSorterTest, IntersectingLayerOverlap) |
80 { | 80 { |
81 LayerSorter::ABCompareResult overlapResult; | 81 LayerSorter::ABCompareResult overlapResult; |
82 const float zThreshold = 0.1f; | 82 const float zThreshold = 0.1f; |
83 float weight = 0; | 83 float weight = 0; |
84 | 84 |
85 gfx::Transform perspectiveMatrix; | 85 gfx::Transform perspectiveMatrix; |
86 perspectiveMatrix.ApplyPerspectiveDepth(1000); | 86 perspectiveMatrix.ApplyPerspectiveDepth(1000); |
87 | 87 |
88 // Intersecting layers. An explicit order will be returned based on relative
z | 88 // Intersecting layers. An explicit order will be returned based on relative
z |
89 // values at the overlapping features but the weight returned should be zero
. | 89 // values at the overlapping features but the weight returned should be zero
. |
90 gfx::Transform frontFaceMatrix; | 90 gfx::Transform frontFaceMatrix; |
91 frontFaceMatrix.Translate3d(0, 0, -4); | 91 frontFaceMatrix.Translate3d(0, 0, -4); |
92 frontFaceMatrix.Translate(-1, -1); | 92 frontFaceMatrix.Translate(-1, -1); |
93 LayerShape frontFace(2, 2, perspectiveMatrix * frontFaceMatrix); | 93 LayerShape frontFace(2, 2, perspectiveMatrix * frontFaceMatrix); |
94 | 94 |
95 gfx::Transform throughMatrix; | 95 gfx::Transform throughMatrix; |
96 throughMatrix.Translate3d(0, 0, -4); | 96 throughMatrix.Translate3d(0, 0, -4); |
97 MathUtil::rotateAxisAngle(&throughMatrix, 0, 1, 0, 45); | 97 throughMatrix.RotateAboutYAxis(45); |
98 throughMatrix.Translate(-1, -1); | 98 throughMatrix.Translate(-1, -1); |
99 LayerShape rotatedFace(2, 2, perspectiveMatrix * throughMatrix); | 99 LayerShape rotatedFace(2, 2, perspectiveMatrix * throughMatrix); |
100 overlapResult = LayerSorter::checkOverlap(&frontFace, &rotatedFace, zThresho
ld, weight); | 100 overlapResult = LayerSorter::checkOverlap(&frontFace, &rotatedFace, zThresho
ld, weight); |
101 EXPECT_NE(LayerSorter::None, overlapResult); | 101 EXPECT_NE(LayerSorter::None, overlapResult); |
102 EXPECT_EQ(0, weight); | 102 EXPECT_EQ(0, weight); |
103 } | 103 } |
104 | 104 |
105 TEST(LayerSorterTest, LayersAtAngleOverlap) | 105 TEST(LayerSorterTest, LayersAtAngleOverlap) |
106 { | 106 { |
107 LayerSorter::ABCompareResult overlapResult; | 107 LayerSorter::ABCompareResult overlapResult; |
(...skipping 16 matching lines...) Expand all Loading... |
124 transformA.Translate3d(-6, 0, 1); | 124 transformA.Translate3d(-6, 0, 1); |
125 transformA.Translate(-4, -10); | 125 transformA.Translate(-4, -10); |
126 LayerShape layerA(8, 20, transformA); | 126 LayerShape layerA(8, 20, transformA); |
127 | 127 |
128 gfx::Transform transformB; | 128 gfx::Transform transformB; |
129 transformB.Translate3d(6, 0, -1); | 129 transformB.Translate3d(6, 0, -1); |
130 transformB.Translate(-4, -10); | 130 transformB.Translate(-4, -10); |
131 LayerShape layerB(8, 20, transformB); | 131 LayerShape layerB(8, 20, transformB); |
132 | 132 |
133 gfx::Transform transformC; | 133 gfx::Transform transformC; |
134 MathUtil::rotateAxisAngle(&transformC, 0, 1, 0, 40); | 134 transformC.RotateAboutYAxis(40); |
135 transformC.Translate(-4, -10); | 135 transformC.Translate(-4, -10); |
136 LayerShape layerC(8, 20, transformC); | 136 LayerShape layerC(8, 20, transformC); |
137 | 137 |
138 overlapResult = LayerSorter::checkOverlap(&layerA, &layerC, zThreshold, weig
ht); | 138 overlapResult = LayerSorter::checkOverlap(&layerA, &layerC, zThreshold, weig
ht); |
139 EXPECT_EQ(LayerSorter::ABeforeB, overlapResult); | 139 EXPECT_EQ(LayerSorter::ABeforeB, overlapResult); |
140 overlapResult = LayerSorter::checkOverlap(&layerC, &layerB, zThreshold, weig
ht); | 140 overlapResult = LayerSorter::checkOverlap(&layerC, &layerB, zThreshold, weig
ht); |
141 EXPECT_EQ(LayerSorter::ABeforeB, overlapResult); | 141 EXPECT_EQ(LayerSorter::ABeforeB, overlapResult); |
142 overlapResult = LayerSorter::checkOverlap(&layerA, &layerB, zThreshold, weig
ht); | 142 overlapResult = LayerSorter::checkOverlap(&layerA, &layerB, zThreshold, weig
ht); |
143 EXPECT_EQ(LayerSorter::None, overlapResult); | 143 EXPECT_EQ(LayerSorter::None, overlapResult); |
144 } | 144 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 ASSERT_EQ(static_cast<size_t>(5), layerList.size()); | 253 ASSERT_EQ(static_cast<size_t>(5), layerList.size()); |
254 EXPECT_EQ(3, layerList[0]->id()); | 254 EXPECT_EQ(3, layerList[0]->id()); |
255 EXPECT_EQ(4, layerList[1]->id()); | 255 EXPECT_EQ(4, layerList[1]->id()); |
256 EXPECT_EQ(1, layerList[2]->id()); | 256 EXPECT_EQ(1, layerList[2]->id()); |
257 EXPECT_EQ(2, layerList[3]->id()); | 257 EXPECT_EQ(2, layerList[3]->id()); |
258 EXPECT_EQ(5, layerList[4]->id()); | 258 EXPECT_EQ(5, layerList[4]->id()); |
259 } | 259 } |
260 | 260 |
261 } // namespace | 261 } // namespace |
262 } // namespace cc | 262 } // namespace cc |
OLD | NEW |