Chromium Code Reviews| 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 "cc/animation/transform_operations.h" | 5 #include "cc/animation/transform_operations.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 expected_scale_matrix.Scale3d(sx, sy, sz); | 258 expected_scale_matrix.Scale3d(sx, sy, sz); |
| 259 | 259 |
| 260 gfx::Transform expected_translate_matrix; | 260 gfx::Transform expected_translate_matrix; |
| 261 expected_translate_matrix.Translate3d(dx, dy, dz); | 261 expected_translate_matrix.Translate3d(dx, dy, dz); |
| 262 | 262 |
| 263 gfx::Transform expected_combined_matrix = expected_scale_matrix; | 263 gfx::Transform expected_combined_matrix = expected_scale_matrix; |
| 264 expected_combined_matrix.PreconcatTransform(expected_translate_matrix); | 264 expected_combined_matrix.PreconcatTransform(expected_translate_matrix); |
| 265 | 265 |
| 266 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_combined_matrix, operations.Apply()); | 266 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_combined_matrix, operations.Apply()); |
| 267 } | 267 } |
| 268 | 268 |
|
ajuma
2017/07/04 14:50:56
Please add a couple tests to verify
the unbaked Tr
Ian Vollick
2017/07/04 16:15:17
Done.
| |
| 269 TEST(TransformOperationTest, BlendOrder) { | 269 TEST(TransformOperationTest, BlendOrder) { |
| 270 SkMScalar sx1 = 2; | 270 SkMScalar sx1 = 2; |
| 271 SkMScalar sy1 = 4; | 271 SkMScalar sy1 = 4; |
| 272 SkMScalar sz1 = 8; | 272 SkMScalar sz1 = 8; |
| 273 | 273 |
| 274 SkMScalar dx1 = 1; | 274 SkMScalar dx1 = 1; |
| 275 SkMScalar dy1 = 2; | 275 SkMScalar dy1 = 2; |
| 276 SkMScalar dz1 = 3; | 276 SkMScalar dz1 = 3; |
| 277 | 277 |
| 278 SkMScalar sx2 = 4; | 278 SkMScalar sx2 = 4; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 306 gfx::Transform blended_scale = scale_to; | 306 gfx::Transform blended_scale = scale_to; |
| 307 blended_scale.Blend(scale_from, progress); | 307 blended_scale.Blend(scale_from, progress); |
| 308 | 308 |
| 309 gfx::Transform blended_translate = translate_to; | 309 gfx::Transform blended_translate = translate_to; |
| 310 blended_translate.Blend(translate_from, progress); | 310 blended_translate.Blend(translate_from, progress); |
| 311 | 311 |
| 312 gfx::Transform expected = blended_scale; | 312 gfx::Transform expected = blended_scale; |
| 313 expected.PreconcatTransform(blended_translate); | 313 expected.PreconcatTransform(blended_translate); |
| 314 | 314 |
| 315 EXPECT_TRANSFORMATION_MATRIX_EQ( | 315 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 316 expected, operations_to.Blend(operations_from, progress)); | 316 expected, operations_to.Blend(operations_from, progress).Apply()); |
| 317 } | 317 } |
| 318 | 318 |
| 319 static void CheckProgress(SkMScalar progress, | 319 static void CheckProgress(SkMScalar progress, |
| 320 const gfx::Transform& from_matrix, | 320 const gfx::Transform& from_matrix, |
| 321 const gfx::Transform& to_matrix, | 321 const gfx::Transform& to_matrix, |
| 322 const TransformOperations& from_transform, | 322 const TransformOperations& from_transform, |
| 323 const TransformOperations& to_transform) { | 323 const TransformOperations& to_transform) { |
| 324 gfx::Transform expected_matrix = to_matrix; | 324 gfx::Transform expected_matrix = to_matrix; |
| 325 expected_matrix.Blend(from_matrix, progress); | 325 expected_matrix.Blend(from_matrix, progress); |
| 326 EXPECT_TRANSFORMATION_MATRIX_EQ( | 326 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 327 expected_matrix, to_transform.Blend(from_transform, progress)); | 327 expected_matrix, to_transform.Blend(from_transform, progress).Apply()); |
| 328 } | 328 } |
| 329 | 329 |
| 330 TEST(TransformOperationTest, BlendProgress) { | 330 TEST(TransformOperationTest, BlendProgress) { |
| 331 SkMScalar sx = 2; | 331 SkMScalar sx = 2; |
| 332 SkMScalar sy = 4; | 332 SkMScalar sy = 4; |
| 333 SkMScalar sz = 8; | 333 SkMScalar sz = 8; |
| 334 TransformOperations operations_from; | 334 TransformOperations operations_from; |
| 335 operations_from.AppendScale(sx, sy, sz); | 335 operations_from.AppendScale(sx, sy, sz); |
| 336 | 336 |
| 337 gfx::Transform matrix_from; | 337 gfx::Transform matrix_from; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 gfx::Transform to; | 386 gfx::Transform to; |
| 387 to.Translate3d(dx2, dy2, dz2); | 387 to.Translate3d(dx2, dy2, dz2); |
| 388 to.Scale3d(sx2, sy2, sz2); | 388 to.Scale3d(sx2, sy2, sz2); |
| 389 | 389 |
| 390 SkMScalar progress = 0.25f; | 390 SkMScalar progress = 0.25f; |
| 391 | 391 |
| 392 gfx::Transform expected = to; | 392 gfx::Transform expected = to; |
| 393 expected.Blend(from, progress); | 393 expected.Blend(from, progress); |
| 394 | 394 |
| 395 EXPECT_TRANSFORMATION_MATRIX_EQ( | 395 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 396 expected, operations_to.Blend(operations_from, progress)); | 396 expected, operations_to.Blend(operations_from, progress).Apply()); |
| 397 } | 397 } |
| 398 | 398 |
| 399 TEST(TransformOperationTest, LargeRotationsWithSameAxis) { | 399 TEST(TransformOperationTest, LargeRotationsWithSameAxis) { |
| 400 TransformOperations operations_from; | 400 TransformOperations operations_from; |
| 401 operations_from.AppendRotate(0, 0, 1, 0); | 401 operations_from.AppendRotate(0, 0, 1, 0); |
| 402 | 402 |
| 403 TransformOperations operations_to; | 403 TransformOperations operations_to; |
| 404 operations_to.AppendRotate(0, 0, 2, 360); | 404 operations_to.AppendRotate(0, 0, 2, 360); |
| 405 | 405 |
| 406 SkMScalar progress = 0.5f; | 406 SkMScalar progress = 0.5f; |
| 407 | 407 |
| 408 gfx::Transform expected; | 408 gfx::Transform expected; |
| 409 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 180); | 409 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 180); |
| 410 | 410 |
| 411 EXPECT_TRANSFORMATION_MATRIX_EQ( | 411 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 412 expected, operations_to.Blend(operations_from, progress)); | 412 expected, operations_to.Blend(operations_from, progress).Apply()); |
| 413 } | 413 } |
| 414 | 414 |
| 415 TEST(TransformOperationTest, LargeRotationsWithSameAxisInDifferentDirection) { | 415 TEST(TransformOperationTest, LargeRotationsWithSameAxisInDifferentDirection) { |
| 416 TransformOperations operations_from; | 416 TransformOperations operations_from; |
| 417 operations_from.AppendRotate(0, 0, 1, 180); | 417 operations_from.AppendRotate(0, 0, 1, 180); |
| 418 | 418 |
| 419 TransformOperations operations_to; | 419 TransformOperations operations_to; |
| 420 operations_to.AppendRotate(0, 0, -1, 180); | 420 operations_to.AppendRotate(0, 0, -1, 180); |
| 421 | 421 |
| 422 SkMScalar progress = 0.5f; | 422 SkMScalar progress = 0.5f; |
| 423 | 423 |
| 424 gfx::Transform expected; | 424 gfx::Transform expected; |
| 425 | 425 |
| 426 EXPECT_TRANSFORMATION_MATRIX_EQ( | 426 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 427 expected, operations_to.Blend(operations_from, progress)); | 427 expected, operations_to.Blend(operations_from, progress).Apply()); |
| 428 } | 428 } |
| 429 | 429 |
| 430 TEST(TransformOperationTest, LargeRotationsWithDifferentAxes) { | 430 TEST(TransformOperationTest, LargeRotationsWithDifferentAxes) { |
| 431 TransformOperations operations_from; | 431 TransformOperations operations_from; |
| 432 operations_from.AppendRotate(0, 0, 1, 175); | 432 operations_from.AppendRotate(0, 0, 1, 175); |
| 433 | 433 |
| 434 TransformOperations operations_to; | 434 TransformOperations operations_to; |
| 435 operations_to.AppendRotate(0, 1, 0, 175); | 435 operations_to.AppendRotate(0, 1, 0, 175); |
| 436 | 436 |
| 437 SkMScalar progress = 0.5f; | 437 SkMScalar progress = 0.5f; |
| 438 gfx::Transform matrix_from; | 438 gfx::Transform matrix_from; |
| 439 matrix_from.RotateAbout(gfx::Vector3dF(0, 0, 1), 175); | 439 matrix_from.RotateAbout(gfx::Vector3dF(0, 0, 1), 175); |
| 440 | 440 |
| 441 gfx::Transform matrix_to; | 441 gfx::Transform matrix_to; |
| 442 matrix_to.RotateAbout(gfx::Vector3dF(0, 1, 0), 175); | 442 matrix_to.RotateAbout(gfx::Vector3dF(0, 1, 0), 175); |
| 443 | 443 |
| 444 gfx::Transform expected = matrix_to; | 444 gfx::Transform expected = matrix_to; |
| 445 expected.Blend(matrix_from, progress); | 445 expected.Blend(matrix_from, progress); |
| 446 | 446 |
| 447 EXPECT_TRANSFORMATION_MATRIX_EQ( | 447 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 448 expected, operations_to.Blend(operations_from, progress)); | 448 expected, operations_to.Blend(operations_from, progress).Apply()); |
| 449 } | 449 } |
| 450 | 450 |
| 451 TEST(TransformOperationTest, RotationFromZeroDegDifferentAxes) { | 451 TEST(TransformOperationTest, RotationFromZeroDegDifferentAxes) { |
| 452 TransformOperations operations_from; | 452 TransformOperations operations_from; |
| 453 operations_from.AppendRotate(0, 0, 1, 0); | 453 operations_from.AppendRotate(0, 0, 1, 0); |
| 454 | 454 |
| 455 TransformOperations operations_to; | 455 TransformOperations operations_to; |
| 456 operations_to.AppendRotate(0, 1, 0, 450); | 456 operations_to.AppendRotate(0, 1, 0, 450); |
| 457 | 457 |
| 458 SkMScalar progress = 0.5f; | 458 SkMScalar progress = 0.5f; |
| 459 gfx::Transform expected; | 459 gfx::Transform expected; |
| 460 expected.RotateAbout(gfx::Vector3dF(0, 1, 0), 225); | 460 expected.RotateAbout(gfx::Vector3dF(0, 1, 0), 225); |
| 461 EXPECT_TRANSFORMATION_MATRIX_EQ( | 461 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 462 expected, operations_to.Blend(operations_from, progress)); | 462 expected, operations_to.Blend(operations_from, progress).Apply()); |
| 463 } | 463 } |
| 464 | 464 |
| 465 TEST(TransformOperationTest, RotationFromZeroDegSameAxes) { | 465 TEST(TransformOperationTest, RotationFromZeroDegSameAxes) { |
| 466 TransformOperations operations_from; | 466 TransformOperations operations_from; |
| 467 operations_from.AppendRotate(0, 0, 1, 0); | 467 operations_from.AppendRotate(0, 0, 1, 0); |
| 468 | 468 |
| 469 TransformOperations operations_to; | 469 TransformOperations operations_to; |
| 470 operations_to.AppendRotate(0, 0, 1, 450); | 470 operations_to.AppendRotate(0, 0, 1, 450); |
| 471 | 471 |
| 472 SkMScalar progress = 0.5f; | 472 SkMScalar progress = 0.5f; |
| 473 gfx::Transform expected; | 473 gfx::Transform expected; |
| 474 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 225); | 474 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 225); |
| 475 EXPECT_TRANSFORMATION_MATRIX_EQ( | 475 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 476 expected, operations_to.Blend(operations_from, progress)); | 476 expected, operations_to.Blend(operations_from, progress).Apply()); |
| 477 } | 477 } |
| 478 | 478 |
| 479 TEST(TransformOperationTest, RotationToZeroDegDifferentAxes) { | 479 TEST(TransformOperationTest, RotationToZeroDegDifferentAxes) { |
| 480 TransformOperations operations_from; | 480 TransformOperations operations_from; |
| 481 operations_from.AppendRotate(0, 1, 0, 450); | 481 operations_from.AppendRotate(0, 1, 0, 450); |
| 482 | 482 |
| 483 TransformOperations operations_to; | 483 TransformOperations operations_to; |
| 484 operations_to.AppendRotate(0, 0, 1, 0); | 484 operations_to.AppendRotate(0, 0, 1, 0); |
| 485 | 485 |
| 486 SkMScalar progress = 0.5f; | 486 SkMScalar progress = 0.5f; |
| 487 gfx::Transform expected; | 487 gfx::Transform expected; |
| 488 expected.RotateAbout(gfx::Vector3dF(0, 1, 0), 225); | 488 expected.RotateAbout(gfx::Vector3dF(0, 1, 0), 225); |
| 489 EXPECT_TRANSFORMATION_MATRIX_EQ( | 489 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 490 expected, operations_to.Blend(operations_from, progress)); | 490 expected, operations_to.Blend(operations_from, progress).Apply()); |
| 491 } | 491 } |
| 492 | 492 |
| 493 TEST(TransformOperationTest, RotationToZeroDegSameAxes) { | 493 TEST(TransformOperationTest, RotationToZeroDegSameAxes) { |
| 494 TransformOperations operations_from; | 494 TransformOperations operations_from; |
| 495 operations_from.AppendRotate(0, 0, 1, 450); | 495 operations_from.AppendRotate(0, 0, 1, 450); |
| 496 | 496 |
| 497 TransformOperations operations_to; | 497 TransformOperations operations_to; |
| 498 operations_to.AppendRotate(0, 0, 1, 0); | 498 operations_to.AppendRotate(0, 0, 1, 0); |
| 499 | 499 |
| 500 SkMScalar progress = 0.5f; | 500 SkMScalar progress = 0.5f; |
| 501 gfx::Transform expected; | 501 gfx::Transform expected; |
| 502 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 225); | 502 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 225); |
| 503 EXPECT_TRANSFORMATION_MATRIX_EQ( | 503 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 504 expected, operations_to.Blend(operations_from, progress)); | 504 expected, operations_to.Blend(operations_from, progress).Apply()); |
| 505 } | 505 } |
| 506 | 506 |
| 507 TEST(TransformOperationTest, BlendRotationFromIdentity) { | 507 TEST(TransformOperationTest, BlendRotationFromIdentity) { |
| 508 std::vector<std::unique_ptr<TransformOperations>> identity_operations = | 508 std::vector<std::unique_ptr<TransformOperations>> identity_operations = |
| 509 GetIdentityOperations(); | 509 GetIdentityOperations(); |
| 510 | 510 |
| 511 for (size_t i = 0; i < identity_operations.size(); ++i) { | 511 for (size_t i = 0; i < identity_operations.size(); ++i) { |
| 512 TransformOperations operations; | 512 TransformOperations operations; |
| 513 operations.AppendRotate(0, 0, 1, 90); | 513 operations.AppendRotate(0, 0, 1, 90); |
| 514 | 514 |
| 515 SkMScalar progress = 0.5f; | 515 SkMScalar progress = 0.5f; |
| 516 | 516 |
| 517 gfx::Transform expected; | 517 gfx::Transform expected; |
| 518 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 45); | 518 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 45); |
| 519 | 519 |
| 520 EXPECT_TRANSFORMATION_MATRIX_EQ( | 520 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 521 expected, operations.Blend(*identity_operations[i], progress)); | 521 expected, operations.Blend(*identity_operations[i], progress).Apply()); |
| 522 | 522 |
| 523 progress = -0.5f; | 523 progress = -0.5f; |
| 524 | 524 |
| 525 expected.MakeIdentity(); | 525 expected.MakeIdentity(); |
| 526 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), -45); | 526 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), -45); |
| 527 | 527 |
| 528 EXPECT_TRANSFORMATION_MATRIX_EQ( | 528 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 529 expected, operations.Blend(*identity_operations[i], progress)); | 529 expected, operations.Blend(*identity_operations[i], progress).Apply()); |
| 530 | 530 |
| 531 progress = 1.5f; | 531 progress = 1.5f; |
| 532 | 532 |
| 533 expected.MakeIdentity(); | 533 expected.MakeIdentity(); |
| 534 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 135); | 534 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 135); |
| 535 | 535 |
| 536 EXPECT_TRANSFORMATION_MATRIX_EQ( | 536 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 537 expected, operations.Blend(*identity_operations[i], progress)); | 537 expected, operations.Blend(*identity_operations[i], progress).Apply()); |
| 538 } | 538 } |
| 539 } | 539 } |
| 540 | 540 |
| 541 TEST(TransformOperationTest, BlendTranslationFromIdentity) { | 541 TEST(TransformOperationTest, BlendTranslationFromIdentity) { |
| 542 std::vector<std::unique_ptr<TransformOperations>> identity_operations = | 542 std::vector<std::unique_ptr<TransformOperations>> identity_operations = |
| 543 GetIdentityOperations(); | 543 GetIdentityOperations(); |
| 544 | 544 |
| 545 for (size_t i = 0; i < identity_operations.size(); ++i) { | 545 for (size_t i = 0; i < identity_operations.size(); ++i) { |
| 546 TransformOperations operations; | 546 TransformOperations operations; |
| 547 operations.AppendTranslate(2, 2, 2); | 547 operations.AppendTranslate(2, 2, 2); |
| 548 | 548 |
| 549 SkMScalar progress = 0.5f; | 549 SkMScalar progress = 0.5f; |
| 550 | 550 |
| 551 gfx::Transform expected; | 551 gfx::Transform expected; |
| 552 expected.Translate3d(1, 1, 1); | 552 expected.Translate3d(1, 1, 1); |
| 553 | 553 |
| 554 EXPECT_TRANSFORMATION_MATRIX_EQ( | 554 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 555 expected, operations.Blend(*identity_operations[i], progress)); | 555 expected, operations.Blend(*identity_operations[i], progress).Apply()); |
| 556 | 556 |
| 557 progress = -0.5f; | 557 progress = -0.5f; |
| 558 | 558 |
| 559 expected.MakeIdentity(); | 559 expected.MakeIdentity(); |
| 560 expected.Translate3d(-1, -1, -1); | 560 expected.Translate3d(-1, -1, -1); |
| 561 | 561 |
| 562 EXPECT_TRANSFORMATION_MATRIX_EQ( | 562 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 563 expected, operations.Blend(*identity_operations[i], progress)); | 563 expected, operations.Blend(*identity_operations[i], progress).Apply()); |
| 564 | 564 |
| 565 progress = 1.5f; | 565 progress = 1.5f; |
| 566 | 566 |
| 567 expected.MakeIdentity(); | 567 expected.MakeIdentity(); |
| 568 expected.Translate3d(3, 3, 3); | 568 expected.Translate3d(3, 3, 3); |
| 569 | 569 |
| 570 EXPECT_TRANSFORMATION_MATRIX_EQ( | 570 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 571 expected, operations.Blend(*identity_operations[i], progress)); | 571 expected, operations.Blend(*identity_operations[i], progress).Apply()); |
| 572 } | 572 } |
| 573 } | 573 } |
| 574 | 574 |
| 575 TEST(TransformOperationTest, BlendScaleFromIdentity) { | 575 TEST(TransformOperationTest, BlendScaleFromIdentity) { |
| 576 std::vector<std::unique_ptr<TransformOperations>> identity_operations = | 576 std::vector<std::unique_ptr<TransformOperations>> identity_operations = |
| 577 GetIdentityOperations(); | 577 GetIdentityOperations(); |
| 578 | 578 |
| 579 for (size_t i = 0; i < identity_operations.size(); ++i) { | 579 for (size_t i = 0; i < identity_operations.size(); ++i) { |
| 580 TransformOperations operations; | 580 TransformOperations operations; |
| 581 operations.AppendScale(3, 3, 3); | 581 operations.AppendScale(3, 3, 3); |
| 582 | 582 |
| 583 SkMScalar progress = 0.5f; | 583 SkMScalar progress = 0.5f; |
| 584 | 584 |
| 585 gfx::Transform expected; | 585 gfx::Transform expected; |
| 586 expected.Scale3d(2, 2, 2); | 586 expected.Scale3d(2, 2, 2); |
| 587 | 587 |
| 588 EXPECT_TRANSFORMATION_MATRIX_EQ( | 588 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 589 expected, operations.Blend(*identity_operations[i], progress)); | 589 expected, operations.Blend(*identity_operations[i], progress).Apply()); |
| 590 | 590 |
| 591 progress = -0.5f; | 591 progress = -0.5f; |
| 592 | 592 |
| 593 expected.MakeIdentity(); | 593 expected.MakeIdentity(); |
| 594 expected.Scale3d(0, 0, 0); | 594 expected.Scale3d(0, 0, 0); |
| 595 | 595 |
| 596 EXPECT_TRANSFORMATION_MATRIX_EQ( | 596 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 597 expected, operations.Blend(*identity_operations[i], progress)); | 597 expected, operations.Blend(*identity_operations[i], progress).Apply()); |
| 598 | 598 |
| 599 progress = 1.5f; | 599 progress = 1.5f; |
| 600 | 600 |
| 601 expected.MakeIdentity(); | 601 expected.MakeIdentity(); |
| 602 expected.Scale3d(4, 4, 4); | 602 expected.Scale3d(4, 4, 4); |
| 603 | 603 |
| 604 EXPECT_TRANSFORMATION_MATRIX_EQ( | 604 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 605 expected, operations.Blend(*identity_operations[i], progress)); | 605 expected, operations.Blend(*identity_operations[i], progress).Apply()); |
| 606 } | 606 } |
| 607 } | 607 } |
| 608 | 608 |
| 609 TEST(TransformOperationTest, BlendSkewFromEmpty) { | 609 TEST(TransformOperationTest, BlendSkewFromEmpty) { |
| 610 TransformOperations empty_operation; | 610 TransformOperations empty_operation; |
| 611 | 611 |
| 612 TransformOperations operations; | 612 TransformOperations operations; |
| 613 operations.AppendSkew(2, 2); | 613 operations.AppendSkew(2, 2); |
| 614 | 614 |
| 615 SkMScalar progress = 0.5f; | 615 SkMScalar progress = 0.5f; |
| 616 | 616 |
| 617 gfx::Transform expected; | 617 gfx::Transform expected; |
| 618 expected.Skew(1, 1); | 618 expected.Skew(1, 1); |
| 619 | 619 |
| 620 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, | 620 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 621 operations.Blend(empty_operation, progress)); | 621 expected, operations.Blend(empty_operation, progress).Apply()); |
| 622 | 622 |
| 623 progress = -0.5f; | 623 progress = -0.5f; |
| 624 | 624 |
| 625 expected.MakeIdentity(); | 625 expected.MakeIdentity(); |
| 626 expected.Skew(-1, -1); | 626 expected.Skew(-1, -1); |
| 627 | 627 |
| 628 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, | 628 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 629 operations.Blend(empty_operation, progress)); | 629 expected, operations.Blend(empty_operation, progress).Apply()); |
| 630 | 630 |
| 631 progress = 1.5f; | 631 progress = 1.5f; |
| 632 | 632 |
| 633 expected.MakeIdentity(); | 633 expected.MakeIdentity(); |
| 634 expected.Skew(3, 3); | 634 expected.Skew(3, 3); |
| 635 | 635 |
| 636 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, | 636 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 637 operations.Blend(empty_operation, progress)); | 637 expected, operations.Blend(empty_operation, progress).Apply()); |
| 638 } | 638 } |
| 639 | 639 |
| 640 TEST(TransformOperationTest, BlendPerspectiveFromIdentity) { | 640 TEST(TransformOperationTest, BlendPerspectiveFromIdentity) { |
| 641 std::vector<std::unique_ptr<TransformOperations>> identity_operations = | 641 std::vector<std::unique_ptr<TransformOperations>> identity_operations = |
| 642 GetIdentityOperations(); | 642 GetIdentityOperations(); |
| 643 | 643 |
| 644 for (size_t i = 0; i < identity_operations.size(); ++i) { | 644 for (size_t i = 0; i < identity_operations.size(); ++i) { |
| 645 TransformOperations operations; | 645 TransformOperations operations; |
| 646 operations.AppendPerspective(1000); | 646 operations.AppendPerspective(1000); |
| 647 | 647 |
| 648 SkMScalar progress = 0.5f; | 648 SkMScalar progress = 0.5f; |
| 649 | 649 |
| 650 gfx::Transform expected; | 650 gfx::Transform expected; |
| 651 expected.ApplyPerspectiveDepth(2000); | 651 expected.ApplyPerspectiveDepth(2000); |
| 652 | 652 |
| 653 EXPECT_TRANSFORMATION_MATRIX_EQ( | 653 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 654 expected, operations.Blend(*identity_operations[i], progress)); | 654 expected, operations.Blend(*identity_operations[i], progress).Apply()); |
| 655 } | 655 } |
| 656 } | 656 } |
| 657 | 657 |
| 658 TEST(TransformOperationTest, BlendRotationToIdentity) { | 658 TEST(TransformOperationTest, BlendRotationToIdentity) { |
| 659 std::vector<std::unique_ptr<TransformOperations>> identity_operations = | 659 std::vector<std::unique_ptr<TransformOperations>> identity_operations = |
| 660 GetIdentityOperations(); | 660 GetIdentityOperations(); |
| 661 | 661 |
| 662 for (size_t i = 0; i < identity_operations.size(); ++i) { | 662 for (size_t i = 0; i < identity_operations.size(); ++i) { |
| 663 TransformOperations operations; | 663 TransformOperations operations; |
| 664 operations.AppendRotate(0, 0, 1, 90); | 664 operations.AppendRotate(0, 0, 1, 90); |
| 665 | 665 |
| 666 SkMScalar progress = 0.5f; | 666 SkMScalar progress = 0.5f; |
| 667 | 667 |
| 668 gfx::Transform expected; | 668 gfx::Transform expected; |
| 669 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 45); | 669 expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 45); |
| 670 | 670 |
| 671 EXPECT_TRANSFORMATION_MATRIX_EQ( | 671 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 672 expected, identity_operations[i]->Blend(operations, progress)); | 672 expected, identity_operations[i]->Blend(operations, progress).Apply()); |
| 673 } | 673 } |
| 674 } | 674 } |
| 675 | 675 |
| 676 TEST(TransformOperationTest, BlendTranslationToIdentity) { | 676 TEST(TransformOperationTest, BlendTranslationToIdentity) { |
| 677 std::vector<std::unique_ptr<TransformOperations>> identity_operations = | 677 std::vector<std::unique_ptr<TransformOperations>> identity_operations = |
| 678 GetIdentityOperations(); | 678 GetIdentityOperations(); |
| 679 | 679 |
| 680 for (size_t i = 0; i < identity_operations.size(); ++i) { | 680 for (size_t i = 0; i < identity_operations.size(); ++i) { |
| 681 TransformOperations operations; | 681 TransformOperations operations; |
| 682 operations.AppendTranslate(2, 2, 2); | 682 operations.AppendTranslate(2, 2, 2); |
| 683 | 683 |
| 684 SkMScalar progress = 0.5f; | 684 SkMScalar progress = 0.5f; |
| 685 | 685 |
| 686 gfx::Transform expected; | 686 gfx::Transform expected; |
| 687 expected.Translate3d(1, 1, 1); | 687 expected.Translate3d(1, 1, 1); |
| 688 | 688 |
| 689 EXPECT_TRANSFORMATION_MATRIX_EQ( | 689 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 690 expected, identity_operations[i]->Blend(operations, progress)); | 690 expected, identity_operations[i]->Blend(operations, progress).Apply()); |
| 691 } | 691 } |
| 692 } | 692 } |
| 693 | 693 |
| 694 TEST(TransformOperationTest, BlendScaleToIdentity) { | 694 TEST(TransformOperationTest, BlendScaleToIdentity) { |
| 695 std::vector<std::unique_ptr<TransformOperations>> identity_operations = | 695 std::vector<std::unique_ptr<TransformOperations>> identity_operations = |
| 696 GetIdentityOperations(); | 696 GetIdentityOperations(); |
| 697 | 697 |
| 698 for (size_t i = 0; i < identity_operations.size(); ++i) { | 698 for (size_t i = 0; i < identity_operations.size(); ++i) { |
| 699 TransformOperations operations; | 699 TransformOperations operations; |
| 700 operations.AppendScale(3, 3, 3); | 700 operations.AppendScale(3, 3, 3); |
| 701 | 701 |
| 702 SkMScalar progress = 0.5f; | 702 SkMScalar progress = 0.5f; |
| 703 | 703 |
| 704 gfx::Transform expected; | 704 gfx::Transform expected; |
| 705 expected.Scale3d(2, 2, 2); | 705 expected.Scale3d(2, 2, 2); |
| 706 | 706 |
| 707 EXPECT_TRANSFORMATION_MATRIX_EQ( | 707 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 708 expected, identity_operations[i]->Blend(operations, progress)); | 708 expected, identity_operations[i]->Blend(operations, progress).Apply()); |
| 709 } | 709 } |
| 710 } | 710 } |
| 711 | 711 |
| 712 TEST(TransformOperationTest, BlendSkewToEmpty) { | 712 TEST(TransformOperationTest, BlendSkewToEmpty) { |
| 713 TransformOperations empty_operation; | 713 TransformOperations empty_operation; |
| 714 | 714 |
| 715 TransformOperations operations; | 715 TransformOperations operations; |
| 716 operations.AppendSkew(2, 2); | 716 operations.AppendSkew(2, 2); |
| 717 | 717 |
| 718 SkMScalar progress = 0.5f; | 718 SkMScalar progress = 0.5f; |
| 719 | 719 |
| 720 gfx::Transform expected; | 720 gfx::Transform expected; |
| 721 expected.Skew(1, 1); | 721 expected.Skew(1, 1); |
| 722 | 722 |
| 723 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, | 723 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 724 empty_operation.Blend(operations, progress)); | 724 expected, empty_operation.Blend(operations, progress).Apply()); |
| 725 } | 725 } |
| 726 | 726 |
| 727 TEST(TransformOperationTest, BlendPerspectiveToIdentity) { | 727 TEST(TransformOperationTest, BlendPerspectiveToIdentity) { |
| 728 std::vector<std::unique_ptr<TransformOperations>> identity_operations = | 728 std::vector<std::unique_ptr<TransformOperations>> identity_operations = |
| 729 GetIdentityOperations(); | 729 GetIdentityOperations(); |
| 730 | 730 |
| 731 for (size_t i = 0; i < identity_operations.size(); ++i) { | 731 for (size_t i = 0; i < identity_operations.size(); ++i) { |
| 732 TransformOperations operations; | 732 TransformOperations operations; |
| 733 operations.AppendPerspective(1000); | 733 operations.AppendPerspective(1000); |
| 734 | 734 |
| 735 SkMScalar progress = 0.5f; | 735 SkMScalar progress = 0.5f; |
| 736 | 736 |
| 737 gfx::Transform expected; | 737 gfx::Transform expected; |
| 738 expected.ApplyPerspectiveDepth(2000); | 738 expected.ApplyPerspectiveDepth(2000); |
| 739 | 739 |
| 740 EXPECT_TRANSFORMATION_MATRIX_EQ( | 740 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 741 expected, identity_operations[i]->Blend(operations, progress)); | 741 expected, identity_operations[i]->Blend(operations, progress).Apply()); |
| 742 } | 742 } |
| 743 } | 743 } |
| 744 | 744 |
| 745 TEST(TransformOperationTest, ExtrapolatePerspectiveBlending) { | 745 TEST(TransformOperationTest, ExtrapolatePerspectiveBlending) { |
| 746 TransformOperations operations1; | 746 TransformOperations operations1; |
| 747 operations1.AppendPerspective(1000); | 747 operations1.AppendPerspective(1000); |
| 748 | 748 |
| 749 TransformOperations operations2; | 749 TransformOperations operations2; |
| 750 operations2.AppendPerspective(500); | 750 operations2.AppendPerspective(500); |
| 751 | 751 |
| 752 gfx::Transform expected; | 752 gfx::Transform expected; |
| 753 expected.ApplyPerspectiveDepth(400); | 753 expected.ApplyPerspectiveDepth(400); |
| 754 | 754 |
| 755 EXPECT_TRANSFORMATION_MATRIX_EQ( | 755 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
| 756 expected, operations1.Blend(operations2, -0.5)); | 756 operations1.Blend(operations2, -0.5).Apply()); |
| 757 | 757 |
| 758 expected.MakeIdentity(); | 758 expected.MakeIdentity(); |
| 759 expected.ApplyPerspectiveDepth(2000); | 759 expected.ApplyPerspectiveDepth(2000); |
| 760 | 760 |
| 761 EXPECT_TRANSFORMATION_MATRIX_EQ( | 761 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
| 762 expected, operations1.Blend(operations2, 1.5)); | 762 operations1.Blend(operations2, 1.5).Apply()); |
| 763 } | 763 } |
| 764 | 764 |
| 765 TEST(TransformOperationTest, ExtrapolateMatrixBlending) { | 765 TEST(TransformOperationTest, ExtrapolateMatrixBlending) { |
| 766 gfx::Transform transform1; | 766 gfx::Transform transform1; |
| 767 transform1.Translate3d(1, 1, 1); | 767 transform1.Translate3d(1, 1, 1); |
| 768 TransformOperations operations1; | 768 TransformOperations operations1; |
| 769 operations1.AppendMatrix(transform1); | 769 operations1.AppendMatrix(transform1); |
| 770 | 770 |
| 771 gfx::Transform transform2; | 771 gfx::Transform transform2; |
| 772 transform2.Translate3d(3, 3, 3); | 772 transform2.Translate3d(3, 3, 3); |
| 773 TransformOperations operations2; | 773 TransformOperations operations2; |
| 774 operations2.AppendMatrix(transform2); | 774 operations2.AppendMatrix(transform2); |
| 775 | 775 |
| 776 gfx::Transform expected; | 776 gfx::Transform expected; |
| 777 EXPECT_TRANSFORMATION_MATRIX_EQ( | 777 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
| 778 expected, operations1.Blend(operations2, 1.5)); | 778 operations1.Blend(operations2, 1.5).Apply()); |
| 779 | 779 |
| 780 expected.Translate3d(4, 4, 4); | 780 expected.Translate3d(4, 4, 4); |
| 781 EXPECT_TRANSFORMATION_MATRIX_EQ( | 781 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
| 782 expected, operations1.Blend(operations2, -0.5)); | 782 operations1.Blend(operations2, -0.5).Apply()); |
| 783 } | 783 } |
| 784 | 784 |
| 785 TEST(TransformOperationTest, BlendedBoundsWhenTypesDoNotMatch) { | 785 TEST(TransformOperationTest, BlendedBoundsWhenTypesDoNotMatch) { |
| 786 TransformOperations operations_from; | 786 TransformOperations operations_from; |
| 787 operations_from.AppendScale(2.0, 4.0, 8.0); | 787 operations_from.AppendScale(2.0, 4.0, 8.0); |
| 788 operations_from.AppendTranslate(1.0, 2.0, 3.0); | 788 operations_from.AppendTranslate(1.0, 2.0, 3.0); |
| 789 | 789 |
| 790 TransformOperations operations_to; | 790 TransformOperations operations_to; |
| 791 operations_to.AppendTranslate(10.0, 20.0, 30.0); | 791 operations_to.AppendTranslate(10.0, 20.0, 30.0); |
| 792 operations_to.AppendScale(4.0, 8.0, 16.0); | 792 operations_to.AppendScale(4.0, 8.0, 16.0); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1060 gfx::BoxF bounds; | 1060 gfx::BoxF bounds; |
| 1061 EXPECT_TRUE( | 1061 EXPECT_TRUE( |
| 1062 to.BlendedBoundsForBox(box, from, min_progress, max_progress, &bounds)); | 1062 to.BlendedBoundsForBox(box, from, min_progress, max_progress, &bounds)); |
| 1063 | 1063 |
| 1064 bool first_time = true; | 1064 bool first_time = true; |
| 1065 gfx::BoxF empirical_bounds; | 1065 gfx::BoxF empirical_bounds; |
| 1066 static const size_t kNumSteps = 10; | 1066 static const size_t kNumSteps = 10; |
| 1067 for (size_t step = 0; step < kNumSteps; ++step) { | 1067 for (size_t step = 0; step < kNumSteps; ++step) { |
| 1068 float t = step / (kNumSteps - 1.f); | 1068 float t = step / (kNumSteps - 1.f); |
| 1069 t = gfx::Tween::FloatValueBetween(t, min_progress, max_progress); | 1069 t = gfx::Tween::FloatValueBetween(t, min_progress, max_progress); |
| 1070 gfx::Transform partial_transform = to.Blend(from, t); | 1070 gfx::Transform partial_transform = to.Blend(from, t).Apply(); |
| 1071 gfx::BoxF transformed = box; | 1071 gfx::BoxF transformed = box; |
| 1072 partial_transform.TransformBox(&transformed); | 1072 partial_transform.TransformBox(&transformed); |
| 1073 | 1073 |
| 1074 if (first_time) { | 1074 if (first_time) { |
| 1075 empirical_bounds = transformed; | 1075 empirical_bounds = transformed; |
| 1076 first_time = false; | 1076 first_time = false; |
| 1077 } else { | 1077 } else { |
| 1078 empirical_bounds.Union(transformed); | 1078 empirical_bounds.Union(transformed); |
| 1079 } | 1079 } |
| 1080 } | 1080 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1195 to_transform.ApplyPerspectiveDepth(1000); | 1195 to_transform.ApplyPerspectiveDepth(1000); |
| 1196 | 1196 |
| 1197 static const int steps = 20; | 1197 static const int steps = 20; |
| 1198 for (int i = 0; i < steps; ++i) { | 1198 for (int i = 0; i < steps; ++i) { |
| 1199 double progress = static_cast<double>(i) / (steps - 1); | 1199 double progress = static_cast<double>(i) / (steps - 1); |
| 1200 | 1200 |
| 1201 gfx::Transform blended_matrix = to_transform; | 1201 gfx::Transform blended_matrix = to_transform; |
| 1202 EXPECT_TRUE(blended_matrix.Blend(from_transform, progress)); | 1202 EXPECT_TRUE(blended_matrix.Blend(from_transform, progress)); |
| 1203 | 1203 |
| 1204 gfx::Transform blended_transform = | 1204 gfx::Transform blended_transform = |
| 1205 to_operations.Blend(from_operations, progress); | 1205 to_operations.Blend(from_operations, progress).Apply(); |
| 1206 | 1206 |
| 1207 EXPECT_TRANSFORMATION_MATRIX_EQ(blended_matrix, blended_transform); | 1207 EXPECT_TRANSFORMATION_MATRIX_EQ(blended_matrix, blended_transform); |
| 1208 } | 1208 } |
| 1209 } | 1209 } |
| 1210 | 1210 |
| 1211 TEST(TransformOperationTest, BlendedBoundsForPerspective) { | 1211 TEST(TransformOperationTest, BlendedBoundsForPerspective) { |
| 1212 struct { | 1212 struct { |
| 1213 float from_depth; | 1213 float from_depth; |
| 1214 float to_depth; | 1214 float to_depth; |
| 1215 } perspective_depths[] = { | 1215 } perspective_depths[] = { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1279 operations_to.AppendRotate(0.0, 1.0, 0.0, 135.0); | 1279 operations_to.AppendRotate(0.0, 1.0, 0.0, 135.0); |
| 1280 | 1280 |
| 1281 gfx::BoxF box(0, 0, 0, 1, 1, 1); | 1281 gfx::BoxF box(0, 0, 0, 1, 1, 1); |
| 1282 gfx::BoxF bounds; | 1282 gfx::BoxF bounds; |
| 1283 | 1283 |
| 1284 SkMScalar min_progress = 0.0f; | 1284 SkMScalar min_progress = 0.0f; |
| 1285 SkMScalar max_progress = 1.0f; | 1285 SkMScalar max_progress = 1.0f; |
| 1286 EXPECT_TRUE(operations_to.BlendedBoundsForBox( | 1286 EXPECT_TRUE(operations_to.BlendedBoundsForBox( |
| 1287 box, operations_from, min_progress, max_progress, &bounds)); | 1287 box, operations_from, min_progress, max_progress, &bounds)); |
| 1288 gfx::Transform blended_transform = | 1288 gfx::Transform blended_transform = |
| 1289 operations_to.Blend(operations_from, max_progress); | 1289 operations_to.Blend(operations_from, max_progress).Apply(); |
| 1290 gfx::Point3F blended_point(0.9f, 0.9f, 0.0f); | 1290 gfx::Point3F blended_point(0.9f, 0.9f, 0.0f); |
| 1291 blended_transform.TransformPoint(&blended_point); | 1291 blended_transform.TransformPoint(&blended_point); |
| 1292 gfx::BoxF expanded_bounds = bounds; | 1292 gfx::BoxF expanded_bounds = bounds; |
| 1293 expanded_bounds.ExpandTo(blended_point); | 1293 expanded_bounds.ExpandTo(blended_point); |
| 1294 EXPECT_EQ(bounds.ToString(), expanded_bounds.ToString()); | 1294 EXPECT_EQ(bounds.ToString(), expanded_bounds.ToString()); |
| 1295 } | 1295 } |
| 1296 | 1296 |
| 1297 TEST(TransformOperationTest, BlendedBoundsForSequence) { | 1297 TEST(TransformOperationTest, BlendedBoundsForSequence) { |
| 1298 TransformOperations operations_from; | 1298 TransformOperations operations_from; |
| 1299 operations_from.AppendTranslate(1.0, -5.0, 1.0); | 1299 operations_from.AppendTranslate(1.0, -5.0, 1.0); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1509 TransformOperations operations16; | 1509 TransformOperations operations16; |
| 1510 gfx::Transform skew_transform; | 1510 gfx::Transform skew_transform; |
| 1511 skew_transform.Skew(50.f, 60.f); | 1511 skew_transform.Skew(50.f, 60.f); |
| 1512 operations16.AppendMatrix(skew_transform); | 1512 operations16.AppendMatrix(skew_transform); |
| 1513 EXPECT_TRUE(operations16.ScaleComponent(&scale)); | 1513 EXPECT_TRUE(operations16.ScaleComponent(&scale)); |
| 1514 EXPECT_EQ(2.f, scale); | 1514 EXPECT_EQ(2.f, scale); |
| 1515 } | 1515 } |
| 1516 | 1516 |
| 1517 } // namespace | 1517 } // namespace |
| 1518 } // namespace cc | 1518 } // namespace cc |
| OLD | NEW |