OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_utils.h" | 5 #include "cc/layers/layer_utils.h" |
6 | 6 |
7 #include "cc/animation/transform_operations.h" | 7 #include "cc/animation/transform_operations.h" |
8 #include "cc/layers/layer_impl.h" | 8 #include "cc/layers/layer_impl.h" |
9 #include "cc/test/animation_test_common.h" | 9 #include "cc/test/animation_test_common.h" |
10 #include "cc/test/fake_impl_proxy.h" | 10 #include "cc/test/fake_impl_proxy.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 end.AppendRotate(1.f, 0.f, 0.f, 90.f); | 158 end.AppendRotate(1.f, 0.f, 0.f, 90.f); |
159 AddAnimatedTransformToLayer(child(), duration, start, end); | 159 AddAnimatedTransformToLayer(child(), duration, start, end); |
160 | 160 |
161 parent()->SetBounds(gfx::Size(350, 200)); | 161 parent()->SetBounds(gfx::Size(350, 200)); |
162 | 162 |
163 gfx::Size bounds(100, 100); | 163 gfx::Size bounds(100, 100); |
164 child()->SetDrawsContent(true); | 164 child()->SetDrawsContent(true); |
165 child()->draw_properties().screen_space_transform_is_animating = true; | 165 child()->draw_properties().screen_space_transform_is_animating = true; |
166 child()->SetPosition(gfx::PointF(150.f, 50.f)); | 166 child()->SetPosition(gfx::PointF(150.f, 50.f)); |
167 child()->SetBounds(bounds); | 167 child()->SetBounds(bounds); |
| 168 child()->SetTransformOrigin( |
| 169 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); |
168 | 170 |
169 gfx::BoxF box; | 171 gfx::BoxF box; |
170 bool success = LayerUtils::GetAnimationBounds(*child(), &box); | 172 bool success = LayerUtils::GetAnimationBounds(*child(), &box); |
171 EXPECT_TRUE(success); | 173 EXPECT_TRUE(success); |
172 gfx::BoxF expected(150.f, 50.f, -50.f, 100.f, 100.f, 100.f); | 174 gfx::BoxF expected(150.f, 50.f, -50.f, 100.f, 100.f, 100.f); |
173 EXPECT_BOXF_EQ(expected, box); | 175 EXPECT_BOXF_EQ(expected, box); |
174 } | 176 } |
175 | 177 |
176 TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXWithPerspective) { | 178 TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXWithPerspective) { |
177 double duration = 1.0; | 179 double duration = 1.0; |
178 | 180 |
179 TransformOperations start; | 181 TransformOperations start; |
180 start.AppendRotate(1.f, 0.f, 0.f, 0.f); | 182 start.AppendRotate(1.f, 0.f, 0.f, 0.f); |
181 TransformOperations end; | 183 TransformOperations end; |
182 end.AppendRotate(1.f, 0.f, 0.f, 90.f); | 184 end.AppendRotate(1.f, 0.f, 0.f, 90.f); |
183 AddAnimatedTransformToLayer(child(), duration, start, end); | 185 AddAnimatedTransformToLayer(child(), duration, start, end); |
184 | 186 |
185 // Make the anchor point not the default 0.5 value and line up with the | 187 // Make the anchor point not the default 0.5 value and line up with the |
186 // child center to make the math easier. | 188 // child center to make the math easier. |
187 parent()->SetAnchorPoint(gfx::PointF(0.375f, 0.375f)); | 189 parent()->SetTransformOrigin( |
| 190 gfx::Point3F(0.375f * 400.f, 0.375f * 400.f, 0.f)); |
188 parent()->SetBounds(gfx::Size(400, 400)); | 191 parent()->SetBounds(gfx::Size(400, 400)); |
189 | 192 |
190 gfx::Transform perspective; | 193 gfx::Transform perspective; |
191 perspective.ApplyPerspectiveDepth(100.f); | 194 perspective.ApplyPerspectiveDepth(100.f); |
192 parent()->SetTransform(perspective); | 195 parent()->SetTransform(perspective); |
193 | 196 |
194 gfx::Size bounds(100, 100); | 197 gfx::Size bounds(100, 100); |
195 child()->SetDrawsContent(true); | 198 child()->SetDrawsContent(true); |
196 child()->draw_properties().screen_space_transform_is_animating = true; | 199 child()->draw_properties().screen_space_transform_is_animating = true; |
197 child()->SetPosition(gfx::PointF(100.f, 100.f)); | 200 child()->SetPosition(gfx::PointF(100.f, 100.f)); |
198 child()->SetBounds(bounds); | 201 child()->SetBounds(bounds); |
| 202 child()->SetTransformOrigin( |
| 203 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); |
199 | 204 |
200 gfx::BoxF box; | 205 gfx::BoxF box; |
201 bool success = LayerUtils::GetAnimationBounds(*child(), &box); | 206 bool success = LayerUtils::GetAnimationBounds(*child(), &box); |
202 EXPECT_TRUE(success); | 207 EXPECT_TRUE(success); |
203 gfx::BoxF expected(50.f, 50.f, -33.333336f, 200.f, 200.f, 133.333344f); | 208 gfx::BoxF expected(50.f, 50.f, -33.333336f, 200.f, 200.f, 133.333344f); |
204 EXPECT_BOXF_EQ(expected, box); | 209 EXPECT_BOXF_EQ(expected, box); |
205 } | 210 } |
206 | 211 |
207 TEST_F(LayerUtilsGetAnimationBoundsTest, RotateZ) { | 212 TEST_F(LayerUtilsGetAnimationBoundsTest, RotateZ) { |
208 double duration = 1.0; | 213 double duration = 1.0; |
209 | 214 |
210 TransformOperations start; | 215 TransformOperations start; |
211 start.AppendRotate(0.f, 0.f, 1.f, 0.f); | 216 start.AppendRotate(0.f, 0.f, 1.f, 0.f); |
212 TransformOperations end; | 217 TransformOperations end; |
213 end.AppendRotate(0.f, 0.f, 1.f, 90.f); | 218 end.AppendRotate(0.f, 0.f, 1.f, 90.f); |
214 AddAnimatedTransformToLayer(child(), duration, start, end); | 219 AddAnimatedTransformToLayer(child(), duration, start, end); |
215 | 220 |
216 parent()->SetBounds(gfx::Size(350, 200)); | 221 parent()->SetBounds(gfx::Size(350, 200)); |
217 | 222 |
218 gfx::Size bounds(100, 100); | 223 gfx::Size bounds(100, 100); |
219 child()->SetDrawsContent(true); | 224 child()->SetDrawsContent(true); |
220 child()->draw_properties().screen_space_transform_is_animating = true; | 225 child()->draw_properties().screen_space_transform_is_animating = true; |
221 child()->SetPosition(gfx::PointF(150.f, 50.f)); | 226 child()->SetPosition(gfx::PointF(150.f, 50.f)); |
222 child()->SetBounds(bounds); | 227 child()->SetBounds(bounds); |
| 228 child()->SetTransformOrigin( |
| 229 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); |
223 | 230 |
224 gfx::BoxF box; | 231 gfx::BoxF box; |
225 bool success = LayerUtils::GetAnimationBounds(*child(), &box); | 232 bool success = LayerUtils::GetAnimationBounds(*child(), &box); |
226 EXPECT_TRUE(success); | 233 EXPECT_TRUE(success); |
227 float diag = diagonal(bounds.width(), bounds.height()); | 234 float diag = diagonal(bounds.width(), bounds.height()); |
228 gfx::BoxF expected(150.f + 0.5f * (bounds.width() - diag), | 235 gfx::BoxF expected(150.f + 0.5f * (bounds.width() - diag), |
229 50.f + 0.5f * (bounds.height() - diag), | 236 50.f + 0.5f * (bounds.height() - diag), |
230 0.f, | 237 0.f, |
231 diag, | 238 diag, |
232 diag, | 239 diag, |
(...skipping 18 matching lines...) Expand all Loading... |
251 child()->SetPosition(gfx::PointF(150.f, 50.f)); | 258 child()->SetPosition(gfx::PointF(150.f, 50.f)); |
252 child()->SetBounds(bounds); | 259 child()->SetBounds(bounds); |
253 | 260 |
254 gfx::BoxF box; | 261 gfx::BoxF box; |
255 bool success = LayerUtils::GetAnimationBounds(*child(), &box); | 262 bool success = LayerUtils::GetAnimationBounds(*child(), &box); |
256 EXPECT_FALSE(success); | 263 EXPECT_FALSE(success); |
257 } | 264 } |
258 | 265 |
259 } // namespace | 266 } // namespace |
260 } // namespace cc | 267 } // namespace cc |
OLD | NEW |