OLD | NEW |
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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "cc/animation/transform_operations.h" | 9 #include "cc/animation/transform_operations.h" |
10 #include "cc/test/geometry_test_utils.h" | 10 #include "cc/test/geometry_test_utils.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 to_add = new TransformOperations(); | 132 to_add = new TransformOperations(); |
133 to_add->AppendMatrix(gfx::Transform()); | 133 to_add->AppendMatrix(gfx::Transform()); |
134 operations->push_back(to_add); | 134 operations->push_back(to_add); |
135 | 135 |
136 to_add = new TransformOperations(); | 136 to_add = new TransformOperations(); |
137 to_add->AppendMatrix(gfx::Transform()); | 137 to_add->AppendMatrix(gfx::Transform()); |
138 to_add->AppendMatrix(gfx::Transform()); | 138 to_add->AppendMatrix(gfx::Transform()); |
139 operations->push_back(to_add); | 139 operations->push_back(to_add); |
140 } | 140 } |
141 | 141 |
142 TEST(TransformOperationTest, IdentityAlwaysMatches) { | 142 TEST(TransformOperationTest, MatchTypesOrder) { |
| 143 TransformOperations mix_order_identity; |
| 144 mix_order_identity.AppendTranslate(0, 0, 0); |
| 145 mix_order_identity.AppendScale(1, 1, 1); |
| 146 mix_order_identity.AppendTranslate(0, 0, 0); |
| 147 |
| 148 TransformOperations mix_order_one; |
| 149 mix_order_one.AppendTranslate(0, 1, 0); |
| 150 mix_order_one.AppendScale(2, 1, 3); |
| 151 mix_order_one.AppendTranslate(1, 0, 0); |
| 152 |
| 153 TransformOperations mix_order_two; |
| 154 mix_order_two.AppendTranslate(0, 1, 0); |
| 155 mix_order_two.AppendTranslate(1, 0, 0); |
| 156 mix_order_two.AppendScale(2, 1, 3); |
| 157 |
| 158 EXPECT_TRUE(mix_order_identity.MatchesTypes(mix_order_one)); |
| 159 EXPECT_FALSE(mix_order_identity.MatchesTypes(mix_order_two)); |
| 160 EXPECT_FALSE(mix_order_one.MatchesTypes(mix_order_two)); |
| 161 } |
| 162 |
| 163 TEST(TransformOperationTest, NoneAlwaysMatches) { |
143 ScopedVector<TransformOperations> operations; | 164 ScopedVector<TransformOperations> operations; |
144 GetIdentityOperations(&operations); | 165 GetIdentityOperations(&operations); |
145 | 166 |
146 for (size_t i = 0; i < operations.size(); ++i) { | 167 TransformOperations none_operation; |
147 for (size_t j = 0; j < operations.size(); ++j) | 168 for (size_t i = 0; i < operations.size(); ++i) |
148 EXPECT_TRUE(operations[i]->MatchesTypes(*operations[j])); | 169 EXPECT_TRUE(operations[i]->MatchesTypes(none_operation)); |
149 } | |
150 } | 170 } |
151 | 171 |
152 TEST(TransformOperationTest, ApplyTranslate) { | 172 TEST(TransformOperationTest, ApplyTranslate) { |
153 SkMScalar x = 1; | 173 SkMScalar x = 1; |
154 SkMScalar y = 2; | 174 SkMScalar y = 2; |
155 SkMScalar z = 3; | 175 SkMScalar z = 3; |
156 TransformOperations operations; | 176 TransformOperations operations; |
157 operations.AppendTranslate(x, y, z); | 177 operations.AppendTranslate(x, y, z); |
158 gfx::Transform expected; | 178 gfx::Transform expected; |
159 expected.Translate3d(x, y, z); | 179 expected.Translate3d(x, y, z); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 EXPECT_TRANSFORMATION_MATRIX_EQ( | 440 EXPECT_TRANSFORMATION_MATRIX_EQ( |
421 expected, operations_to.Blend(operations_from, progress)); | 441 expected, operations_to.Blend(operations_from, progress)); |
422 } | 442 } |
423 | 443 |
424 TEST(TransformOperationTest, BlendRotationFromIdentity) { | 444 TEST(TransformOperationTest, BlendRotationFromIdentity) { |
425 ScopedVector<TransformOperations> identity_operations; | 445 ScopedVector<TransformOperations> identity_operations; |
426 GetIdentityOperations(&identity_operations); | 446 GetIdentityOperations(&identity_operations); |
427 | 447 |
428 for (size_t i = 0; i < identity_operations.size(); ++i) { | 448 for (size_t i = 0; i < identity_operations.size(); ++i) { |
429 TransformOperations operations; | 449 TransformOperations operations; |
430 operations.AppendRotate(0, 0, 1, 360); | 450 operations.AppendRotate(0, 0, 1, 90); |
431 | 451 |
432 SkMScalar progress = 0.5f; | 452 SkMScalar progress = 0.5f; |
433 | 453 |
434 gfx::Transform expected; | 454 gfx::Transform expected; |
435 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 180); | 455 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 45); |
436 | 456 |
437 EXPECT_TRANSFORMATION_MATRIX_EQ( | 457 EXPECT_TRANSFORMATION_MATRIX_EQ( |
438 expected, operations.Blend(*identity_operations[i], progress)); | 458 expected, operations.Blend(*identity_operations[i], progress)); |
439 | 459 |
440 progress = -0.5f; | 460 progress = -0.5f; |
441 | 461 |
442 expected.MakeIdentity(); | 462 expected.MakeIdentity(); |
443 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), -180); | 463 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), -45); |
444 | 464 |
445 EXPECT_TRANSFORMATION_MATRIX_EQ( | 465 EXPECT_TRANSFORMATION_MATRIX_EQ( |
446 expected, operations.Blend(*identity_operations[i], progress)); | 466 expected, operations.Blend(*identity_operations[i], progress)); |
447 | 467 |
448 progress = 1.5f; | 468 progress = 1.5f; |
449 | 469 |
450 expected.MakeIdentity(); | 470 expected.MakeIdentity(); |
451 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 540); | 471 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 135); |
452 | 472 |
453 EXPECT_TRANSFORMATION_MATRIX_EQ( | 473 EXPECT_TRANSFORMATION_MATRIX_EQ( |
454 expected, operations.Blend(*identity_operations[i], progress)); | 474 expected, operations.Blend(*identity_operations[i], progress)); |
455 } | 475 } |
456 } | 476 } |
457 | 477 |
458 TEST(TransformOperationTest, BlendTranslationFromIdentity) { | 478 TEST(TransformOperationTest, BlendTranslationFromIdentity) { |
459 ScopedVector<TransformOperations> identity_operations; | 479 ScopedVector<TransformOperations> identity_operations; |
460 GetIdentityOperations(&identity_operations); | 480 GetIdentityOperations(&identity_operations); |
461 | 481 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 progress = 1.5f; | 536 progress = 1.5f; |
517 | 537 |
518 expected.MakeIdentity(); | 538 expected.MakeIdentity(); |
519 expected.Scale3d(4, 4, 4); | 539 expected.Scale3d(4, 4, 4); |
520 | 540 |
521 EXPECT_TRANSFORMATION_MATRIX_EQ( | 541 EXPECT_TRANSFORMATION_MATRIX_EQ( |
522 expected, operations.Blend(*identity_operations[i], progress)); | 542 expected, operations.Blend(*identity_operations[i], progress)); |
523 } | 543 } |
524 } | 544 } |
525 | 545 |
526 TEST(TransformOperationTest, BlendSkewFromIdentity) { | 546 TEST(TransformOperationTest, BlendSkewFromEmpty) { |
527 ScopedVector<TransformOperations> identity_operations; | 547 TransformOperations empty_operation; |
528 GetIdentityOperations(&identity_operations); | |
529 | 548 |
530 for (size_t i = 0; i < identity_operations.size(); ++i) { | 549 TransformOperations operations; |
531 TransformOperations operations; | 550 operations.AppendSkew(2, 2); |
532 operations.AppendSkew(2, 2); | |
533 | 551 |
534 SkMScalar progress = 0.5f; | 552 SkMScalar progress = 0.5f; |
535 | 553 |
536 gfx::Transform expected; | 554 gfx::Transform expected; |
537 expected.SkewX(1); | 555 expected.SkewX(1); |
538 expected.SkewY(1); | 556 expected.SkewY(1); |
539 | 557 |
540 EXPECT_TRANSFORMATION_MATRIX_EQ( | 558 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
541 expected, operations.Blend(*identity_operations[i], progress)); | 559 operations.Blend(empty_operation, progress)); |
542 | 560 |
543 progress = -0.5f; | 561 progress = -0.5f; |
544 | 562 |
545 expected.MakeIdentity(); | 563 expected.MakeIdentity(); |
546 expected.SkewX(-1); | 564 expected.SkewX(-1); |
547 expected.SkewY(-1); | 565 expected.SkewY(-1); |
548 | 566 |
549 EXPECT_TRANSFORMATION_MATRIX_EQ( | 567 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
550 expected, operations.Blend(*identity_operations[i], progress)); | 568 operations.Blend(empty_operation, progress)); |
551 | 569 |
552 progress = 1.5f; | 570 progress = 1.5f; |
553 | 571 |
554 expected.MakeIdentity(); | 572 expected.MakeIdentity(); |
555 expected.SkewX(3); | 573 expected.SkewX(3); |
556 expected.SkewY(3); | 574 expected.SkewY(3); |
557 | 575 |
558 EXPECT_TRANSFORMATION_MATRIX_EQ( | 576 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
559 expected, operations.Blend(*identity_operations[i], progress)); | 577 operations.Blend(empty_operation, progress)); |
560 } | |
561 } | 578 } |
562 | 579 |
563 TEST(TransformOperationTest, BlendPerspectiveFromIdentity) { | 580 TEST(TransformOperationTest, BlendPerspectiveFromIdentity) { |
564 ScopedVector<TransformOperations> identity_operations; | 581 ScopedVector<TransformOperations> identity_operations; |
565 GetIdentityOperations(&identity_operations); | 582 GetIdentityOperations(&identity_operations); |
566 | 583 |
567 for (size_t i = 0; i < identity_operations.size(); ++i) { | 584 for (size_t i = 0; i < identity_operations.size(); ++i) { |
568 TransformOperations operations; | 585 TransformOperations operations; |
569 operations.AppendPerspective(1000); | 586 operations.AppendPerspective(1000); |
570 | 587 |
571 SkMScalar progress = 0.5f; | 588 SkMScalar progress = 0.5f; |
572 | 589 |
573 gfx::Transform expected; | 590 gfx::Transform expected; |
574 expected.ApplyPerspectiveDepth(2000); | 591 expected.ApplyPerspectiveDepth(2000); |
575 | 592 |
576 EXPECT_TRANSFORMATION_MATRIX_EQ( | 593 EXPECT_TRANSFORMATION_MATRIX_EQ( |
577 expected, operations.Blend(*identity_operations[i], progress)); | 594 expected, operations.Blend(*identity_operations[i], progress)); |
578 } | 595 } |
579 } | 596 } |
580 | 597 |
581 TEST(TransformOperationTest, BlendRotationToIdentity) { | 598 TEST(TransformOperationTest, BlendRotationToIdentity) { |
582 ScopedVector<TransformOperations> identity_operations; | 599 ScopedVector<TransformOperations> identity_operations; |
583 GetIdentityOperations(&identity_operations); | 600 GetIdentityOperations(&identity_operations); |
584 | 601 |
585 for (size_t i = 0; i < identity_operations.size(); ++i) { | 602 for (size_t i = 0; i < identity_operations.size(); ++i) { |
586 TransformOperations operations; | 603 TransformOperations operations; |
587 operations.AppendRotate(0, 0, 1, 360); | 604 operations.AppendRotate(0, 0, 1, 90); |
588 | 605 |
589 SkMScalar progress = 0.5f; | 606 SkMScalar progress = 0.5f; |
590 | 607 |
591 gfx::Transform expected; | 608 gfx::Transform expected; |
592 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 180); | 609 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 45); |
593 | 610 |
594 EXPECT_TRANSFORMATION_MATRIX_EQ( | 611 EXPECT_TRANSFORMATION_MATRIX_EQ( |
595 expected, identity_operations[i]->Blend(operations, progress)); | 612 expected, identity_operations[i]->Blend(operations, progress)); |
596 } | 613 } |
597 } | 614 } |
598 | 615 |
599 TEST(TransformOperationTest, BlendTranslationToIdentity) { | 616 TEST(TransformOperationTest, BlendTranslationToIdentity) { |
600 ScopedVector<TransformOperations> identity_operations; | 617 ScopedVector<TransformOperations> identity_operations; |
601 GetIdentityOperations(&identity_operations); | 618 GetIdentityOperations(&identity_operations); |
602 | 619 |
(...skipping 22 matching lines...) Expand all Loading... |
625 SkMScalar progress = 0.5f; | 642 SkMScalar progress = 0.5f; |
626 | 643 |
627 gfx::Transform expected; | 644 gfx::Transform expected; |
628 expected.Scale3d(2, 2, 2); | 645 expected.Scale3d(2, 2, 2); |
629 | 646 |
630 EXPECT_TRANSFORMATION_MATRIX_EQ( | 647 EXPECT_TRANSFORMATION_MATRIX_EQ( |
631 expected, identity_operations[i]->Blend(operations, progress)); | 648 expected, identity_operations[i]->Blend(operations, progress)); |
632 } | 649 } |
633 } | 650 } |
634 | 651 |
635 TEST(TransformOperationTest, BlendSkewToIdentity) { | 652 TEST(TransformOperationTest, BlendSkewToEmpty) { |
636 ScopedVector<TransformOperations> identity_operations; | 653 TransformOperations empty_operation; |
637 GetIdentityOperations(&identity_operations); | |
638 | 654 |
639 for (size_t i = 0; i < identity_operations.size(); ++i) { | 655 TransformOperations operations; |
640 TransformOperations operations; | 656 operations.AppendSkew(2, 2); |
641 operations.AppendSkew(2, 2); | |
642 | 657 |
643 SkMScalar progress = 0.5f; | 658 SkMScalar progress = 0.5f; |
644 | 659 |
645 gfx::Transform expected; | 660 gfx::Transform expected; |
646 expected.SkewX(1); | 661 expected.SkewX(1); |
647 expected.SkewY(1); | 662 expected.SkewY(1); |
648 | 663 |
649 EXPECT_TRANSFORMATION_MATRIX_EQ( | 664 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
650 expected, identity_operations[i]->Blend(operations, progress)); | 665 empty_operation.Blend(operations, progress)); |
651 } | |
652 } | 666 } |
653 | 667 |
654 TEST(TransformOperationTest, BlendPerspectiveToIdentity) { | 668 TEST(TransformOperationTest, BlendPerspectiveToIdentity) { |
655 ScopedVector<TransformOperations> identity_operations; | 669 ScopedVector<TransformOperations> identity_operations; |
656 GetIdentityOperations(&identity_operations); | 670 GetIdentityOperations(&identity_operations); |
657 | 671 |
658 for (size_t i = 0; i < identity_operations.size(); ++i) { | 672 for (size_t i = 0; i < identity_operations.size(); ++i) { |
659 TransformOperations operations; | 673 TransformOperations operations; |
660 operations.AppendPerspective(1000); | 674 operations.AppendPerspective(1000); |
661 | 675 |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 | 1468 |
1455 // Scale + Perspective can't. | 1469 // Scale + Perspective can't. |
1456 TransformOperations operations11; | 1470 TransformOperations operations11; |
1457 operations11.AppendScale(2.f, 2.f, 2.f); | 1471 operations11.AppendScale(2.f, 2.f, 2.f); |
1458 operations11.AppendPerspective(1.f); | 1472 operations11.AppendPerspective(1.f); |
1459 EXPECT_FALSE(operations11.ScaleComponent(&scale)); | 1473 EXPECT_FALSE(operations11.ScaleComponent(&scale)); |
1460 } | 1474 } |
1461 | 1475 |
1462 } // namespace | 1476 } // namespace |
1463 } // namespace cc | 1477 } // namespace cc |
OLD | NEW |