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

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

Issue 1908593002: cc : Stop pushing transform origin from Layer and LayerImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/layers/layer_impl_unittest.cc ('k') | cc/test/layer_tree_host_common_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/animation_host.h" 7 #include "cc/animation/animation_host.h"
8 #include "cc/animation/animation_id_provider.h" 8 #include "cc/animation/animation_id_provider.h"
9 #include "cc/animation/transform_operations.h" 9 #include "cc/animation/transform_operations.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration, 204 AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration,
205 start, end); 205 start, end);
206 206
207 parent1()->SetBounds(gfx::Size(350, 200)); 207 parent1()->SetBounds(gfx::Size(350, 200));
208 208
209 gfx::Size bounds(100, 100); 209 gfx::Size bounds(100, 100);
210 child1()->SetDrawsContent(true); 210 child1()->SetDrawsContent(true);
211 child1()->SetPosition(gfx::PointF(150.f, 50.f)); 211 child1()->SetPosition(gfx::PointF(150.f, 50.f));
212 child1()->SetBounds(bounds); 212 child1()->SetBounds(bounds);
213 child1()->SetTransformOrigin( 213 child1()->test_properties()->transform_origin =
214 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); 214 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
215 215
216 host_impl().active_tree()->BuildPropertyTreesForTesting(); 216 host_impl().active_tree()->BuildPropertyTreesForTesting();
217 217
218 gfx::BoxF box; 218 gfx::BoxF box;
219 bool success = LayerUtils::GetAnimationBounds(*child1(), &box); 219 bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
220 EXPECT_TRUE(success); 220 EXPECT_TRUE(success);
221 gfx::BoxF expected(150.f, 50.f, -50.f, 100.f, 100.f, 100.f); 221 gfx::BoxF expected(150.f, 50.f, -50.f, 100.f, 100.f, 100.f);
222 EXPECT_BOXF_EQ(expected, box); 222 EXPECT_BOXF_EQ(expected, box);
223 } 223 }
224 224
225 TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXWithPerspective) { 225 TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXWithPerspective) {
226 double duration = 1.0; 226 double duration = 1.0;
227 227
228 TransformOperations start; 228 TransformOperations start;
229 start.AppendRotate(1.f, 0.f, 0.f, 0.f); 229 start.AppendRotate(1.f, 0.f, 0.f, 0.f);
230 TransformOperations end; 230 TransformOperations end;
231 end.AppendRotate(1.f, 0.f, 0.f, 90.f); 231 end.AppendRotate(1.f, 0.f, 0.f, 90.f);
232 232
233 AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration, 233 AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration,
234 start, end); 234 start, end);
235 235
236 // Make the anchor point not the default 0.5 value and line up with the 236 // Make the anchor point not the default 0.5 value and line up with the
237 // child center to make the math easier. 237 // child center to make the math easier.
238 parent1()->SetTransformOrigin( 238 parent1()->test_properties()->transform_origin =
239 gfx::Point3F(0.375f * 400.f, 0.375f * 400.f, 0.f)); 239 gfx::Point3F(0.375f * 400.f, 0.375f * 400.f, 0.f);
240 parent1()->SetBounds(gfx::Size(400, 400)); 240 parent1()->SetBounds(gfx::Size(400, 400));
241 241
242 gfx::Transform perspective; 242 gfx::Transform perspective;
243 perspective.ApplyPerspectiveDepth(100.f); 243 perspective.ApplyPerspectiveDepth(100.f);
244 parent1()->SetTransform(perspective); 244 parent1()->SetTransform(perspective);
245 245
246 gfx::Size bounds(100, 100); 246 gfx::Size bounds(100, 100);
247 child1()->SetDrawsContent(true); 247 child1()->SetDrawsContent(true);
248 child1()->SetPosition(gfx::PointF(100.f, 100.f)); 248 child1()->SetPosition(gfx::PointF(100.f, 100.f));
249 child1()->SetBounds(bounds); 249 child1()->SetBounds(bounds);
250 child1()->SetTransformOrigin( 250 child1()->test_properties()->transform_origin =
251 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); 251 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
252 252
253 host_impl().active_tree()->BuildPropertyTreesForTesting(); 253 host_impl().active_tree()->BuildPropertyTreesForTesting();
254 254
255 gfx::BoxF box; 255 gfx::BoxF box;
256 bool success = LayerUtils::GetAnimationBounds(*child1(), &box); 256 bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
257 EXPECT_TRUE(success); 257 EXPECT_TRUE(success);
258 gfx::BoxF expected(50.f, 50.f, -33.333336f, 200.f, 200.f, 133.333344f); 258 gfx::BoxF expected(50.f, 50.f, -33.333336f, 200.f, 200.f, 133.333344f);
259 EXPECT_BOXF_EQ(expected, box); 259 EXPECT_BOXF_EQ(expected, box);
260 } 260 }
261 261
262 TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXWithPerspectiveOnSameLayer) { 262 TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXWithPerspectiveOnSameLayer) {
263 // This test is used to check whether GetAnimationBounds correctly ignores the 263 // This test is used to check whether GetAnimationBounds correctly ignores the
264 // local transform when there is an animation applied to the layer / node. 264 // local transform when there is an animation applied to the layer / node.
265 // The intended behavior is that the animation should overwrite the transform. 265 // The intended behavior is that the animation should overwrite the transform.
266 266
267 double duration = 1.0; 267 double duration = 1.0;
268 268
269 TransformOperations start; 269 TransformOperations start;
270 start.AppendRotate(1.f, 0.f, 0.f, 0.f); 270 start.AppendRotate(1.f, 0.f, 0.f, 0.f);
271 TransformOperations end; 271 TransformOperations end;
272 end.AppendRotate(1.f, 0.f, 0.f, 90.f); 272 end.AppendRotate(1.f, 0.f, 0.f, 90.f);
273 273
274 AddAnimatedTransformToLayerWithPlayer(parent1()->id(), timeline(), duration, 274 AddAnimatedTransformToLayerWithPlayer(parent1()->id(), timeline(), duration,
275 start, end); 275 start, end);
276 276
277 // Make the anchor point not the default 0.5 value and line up 277 // Make the anchor point not the default 0.5 value and line up
278 // with the child center to make the math easier. 278 // with the child center to make the math easier.
279 parent1()->SetTransformOrigin( 279 parent1()->test_properties()->transform_origin =
280 gfx::Point3F(0.375f * 400.f, 0.375f * 400.f, 0.f)); 280 gfx::Point3F(0.375f * 400.f, 0.375f * 400.f, 0.f);
281 parent1()->SetBounds(gfx::Size(400, 400)); 281 parent1()->SetBounds(gfx::Size(400, 400));
282 282
283 gfx::Transform perspective; 283 gfx::Transform perspective;
284 perspective.ApplyPerspectiveDepth(100.f); 284 perspective.ApplyPerspectiveDepth(100.f);
285 parent1()->SetTransform(perspective); 285 parent1()->SetTransform(perspective);
286 286
287 gfx::Size bounds(100, 100); 287 gfx::Size bounds(100, 100);
288 child1()->SetDrawsContent(true); 288 child1()->SetDrawsContent(true);
289 child1()->SetPosition(gfx::PointF(100.f, 100.f)); 289 child1()->SetPosition(gfx::PointF(100.f, 100.f));
290 child1()->SetBounds(bounds); 290 child1()->SetBounds(bounds);
291 child1()->SetTransformOrigin( 291 child1()->test_properties()->transform_origin =
292 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); 292 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
293 293
294 host_impl().active_tree()->BuildPropertyTreesForTesting(); 294 host_impl().active_tree()->BuildPropertyTreesForTesting();
295 295
296 gfx::BoxF box; 296 gfx::BoxF box;
297 bool success = LayerUtils::GetAnimationBounds(*child1(), &box); 297 bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
298 EXPECT_TRUE(success); 298 EXPECT_TRUE(success);
299 gfx::BoxF expected(100.f, 100.f, -50.f, 100.f, 100.f, 100.f); 299 gfx::BoxF expected(100.f, 100.f, -50.f, 100.f, 100.f, 100.f);
300 EXPECT_BOXF_EQ(expected, box); 300 EXPECT_BOXF_EQ(expected, box);
301 } 301 }
302 302
303 TEST_F(LayerUtilsGetAnimationBoundsTest, RotateZ) { 303 TEST_F(LayerUtilsGetAnimationBoundsTest, RotateZ) {
304 double duration = 1.0; 304 double duration = 1.0;
305 305
306 TransformOperations start; 306 TransformOperations start;
307 start.AppendRotate(0.f, 0.f, 1.f, 0.f); 307 start.AppendRotate(0.f, 0.f, 1.f, 0.f);
308 TransformOperations end; 308 TransformOperations end;
309 end.AppendRotate(0.f, 0.f, 1.f, 90.f); 309 end.AppendRotate(0.f, 0.f, 1.f, 90.f);
310 AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration, 310 AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration,
311 start, end); 311 start, end);
312 312
313 parent1()->SetBounds(gfx::Size(350, 200)); 313 parent1()->SetBounds(gfx::Size(350, 200));
314 314
315 gfx::Size bounds(100, 100); 315 gfx::Size bounds(100, 100);
316 child1()->SetDrawsContent(true); 316 child1()->SetDrawsContent(true);
317 child1()->SetPosition(gfx::PointF(150.f, 50.f)); 317 child1()->SetPosition(gfx::PointF(150.f, 50.f));
318 child1()->SetBounds(bounds); 318 child1()->SetBounds(bounds);
319 child1()->SetTransformOrigin( 319 child1()->test_properties()->transform_origin =
320 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); 320 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
321 321
322 host_impl().active_tree()->BuildPropertyTreesForTesting(); 322 host_impl().active_tree()->BuildPropertyTreesForTesting();
323 323
324 gfx::BoxF box; 324 gfx::BoxF box;
325 bool success = LayerUtils::GetAnimationBounds(*child1(), &box); 325 bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
326 EXPECT_TRUE(success); 326 EXPECT_TRUE(success);
327 float diag = diagonal(bounds.width(), bounds.height()); 327 float diag = diagonal(bounds.width(), bounds.height());
328 gfx::BoxF expected(150.f + 0.5f * (bounds.width() - diag), 328 gfx::BoxF expected(150.f + 0.5f * (bounds.width() - diag),
329 50.f + 0.5f * (bounds.height() - diag), 329 50.f + 0.5f * (bounds.height() - diag),
330 0.f, 330 0.f,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 409
410 gfx::Transform translate_2d_transform; 410 gfx::Transform translate_2d_transform;
411 translate_2d_transform.Translate(80.f, 60.f); 411 translate_2d_transform.Translate(80.f, 60.f);
412 root()->SetBounds(gfx::Size(350, 200)); 412 root()->SetBounds(gfx::Size(350, 200));
413 parent2()->SetPosition(gfx::PointF(40.f, 45.f)); 413 parent2()->SetPosition(gfx::PointF(40.f, 45.f));
414 child2()->SetTransform(translate_2d_transform); 414 child2()->SetTransform(translate_2d_transform);
415 415
416 gfx::Size bounds(100, 100); 416 gfx::Size bounds(100, 100);
417 grand_child()->SetPosition(gfx::PointF(150.f, 50.f)); 417 grand_child()->SetPosition(gfx::PointF(150.f, 50.f));
418 grand_child()->SetBounds(bounds); 418 grand_child()->SetBounds(bounds);
419 grand_child()->SetTransformOrigin( 419 grand_child()->test_properties()->transform_origin =
420 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); 420 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
421 421
422 great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f)); 422 great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f));
423 great_grand_child()->SetBounds(gfx::Size(50.f, 50.f)); 423 great_grand_child()->SetBounds(gfx::Size(50.f, 50.f));
424 great_grand_child()->SetDrawsContent(true); 424 great_grand_child()->SetDrawsContent(true);
425 425
426 host_impl().active_tree()->BuildPropertyTreesForTesting(); 426 host_impl().active_tree()->BuildPropertyTreesForTesting();
427 427
428 gfx::BoxF box; 428 gfx::BoxF box;
429 bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box); 429 bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box);
430 EXPECT_TRUE(success); 430 EXPECT_TRUE(success);
(...skipping 30 matching lines...) Expand all
461 parent2()->SetPosition(gfx::PointF(40.f, 45.f)); 461 parent2()->SetPosition(gfx::PointF(40.f, 45.f));
462 child2()->SetTransform(translate_2d_transform); 462 child2()->SetTransform(translate_2d_transform);
463 463
464 gfx::Transform perspective; 464 gfx::Transform perspective;
465 perspective.ApplyPerspectiveDepth(100.f); 465 perspective.ApplyPerspectiveDepth(100.f);
466 466
467 gfx::Size bounds(100.f, 100.f); 467 gfx::Size bounds(100.f, 100.f);
468 grand_child()->SetPosition(gfx::PointF(150.f, 50.f)); 468 grand_child()->SetPosition(gfx::PointF(150.f, 50.f));
469 grand_child()->SetBounds(bounds); 469 grand_child()->SetBounds(bounds);
470 grand_child()->SetTransform(perspective); 470 grand_child()->SetTransform(perspective);
471 grand_child()->SetTransformOrigin( 471 grand_child()->test_properties()->transform_origin =
472 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); 472 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
473 473
474 great_grand_child()->SetTransformOrigin( 474 great_grand_child()->test_properties()->transform_origin =
475 gfx::Point3F(bounds.width() * 0.25f, bounds.height() * 0.25f, 0)); 475 gfx::Point3F(bounds.width() * 0.25f, bounds.height() * 0.25f, 0);
476 great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f)); 476 great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f));
477 great_grand_child()->SetBounds(gfx::Size(50.f, 50.f)); 477 great_grand_child()->SetBounds(gfx::Size(50.f, 50.f));
478 great_grand_child()->SetDrawsContent(true); 478 great_grand_child()->SetDrawsContent(true);
479 479
480 host_impl().active_tree()->BuildPropertyTreesForTesting(); 480 host_impl().active_tree()->BuildPropertyTreesForTesting();
481 481
482 gfx::BoxF box; 482 gfx::BoxF box;
483 bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box); 483 bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box);
484 EXPECT_TRUE(success); 484 EXPECT_TRUE(success);
485 485
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 translate_2d_transform.Translate(80.f, 60.f); 539 translate_2d_transform.Translate(80.f, 60.f);
540 540
541 root()->SetBounds(gfx::Size(350, 200)); 541 root()->SetBounds(gfx::Size(350, 200));
542 parent2()->SetPosition(gfx::PointF(40.f, 45.f)); 542 parent2()->SetPosition(gfx::PointF(40.f, 45.f));
543 child2()->SetTransform(translate_2d_transform); 543 child2()->SetTransform(translate_2d_transform);
544 544
545 gfx::Size bounds(100.f, 100.f); 545 gfx::Size bounds(100.f, 100.f);
546 grand_child()->SetPosition(gfx::PointF(150.f, 50.f)); 546 grand_child()->SetPosition(gfx::PointF(150.f, 50.f));
547 grand_child()->SetBounds(bounds); 547 grand_child()->SetBounds(bounds);
548 548
549 great_grand_child()->SetTransformOrigin( 549 great_grand_child()->test_properties()->transform_origin =
550 gfx::Point3F(bounds.width() * 0.25f, bounds.height() * 0.25f, 0)); 550 gfx::Point3F(bounds.width() * 0.25f, bounds.height() * 0.25f, 0);
551 great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f)); 551 great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f));
552 great_grand_child()->SetBounds( 552 great_grand_child()->SetBounds(
553 gfx::Size(bounds.width() * 0.5f, bounds.height() * 0.5f)); 553 gfx::Size(bounds.width() * 0.5f, bounds.height() * 0.5f));
554 great_grand_child()->SetDrawsContent(true); 554 great_grand_child()->SetDrawsContent(true);
555 555
556 host_impl().active_tree()->BuildPropertyTreesForTesting(); 556 host_impl().active_tree()->BuildPropertyTreesForTesting();
557 557
558 gfx::BoxF box; 558 gfx::BoxF box;
559 bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box); 559 bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box);
560 EXPECT_TRUE(success); 560 EXPECT_TRUE(success);
561 561
562 // Same as RotateXWithPerspectiveUnderAncestorsWithPositionOr2DTransform test, 562 // Same as RotateXWithPerspectiveUnderAncestorsWithPositionOr2DTransform test,
563 // except for the perspective calculations. 563 // except for the perspective calculations.
564 564
565 gfx::BoxF expected(295.f, 180.f, -25.f, 50.f, 50.f, 50.f); 565 gfx::BoxF expected(295.f, 180.f, -25.f, 50.f, 50.f, 50.f);
566 EXPECT_BOXF_EQ(expected, box); 566 EXPECT_BOXF_EQ(expected, box);
567 } 567 }
568 568
569 } // namespace 569 } // namespace
570 570
571 } // namespace cc 571 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_impl_unittest.cc ('k') | cc/test/layer_tree_host_common_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698