| 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 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 | 1395 |
| 1396 TransformOperations operations2; | 1396 TransformOperations operations2; |
| 1397 operations2.AppendIdentity(); | 1397 operations2.AppendIdentity(); |
| 1398 operations2.AppendTranslate(3.f, 2.f, 1.f); | 1398 operations2.AppendTranslate(3.f, 2.f, 1.f); |
| 1399 gfx::Transform translation_transform; | 1399 gfx::Transform translation_transform; |
| 1400 translation_transform.Translate3d(1.f, 2.f, 3.f); | 1400 translation_transform.Translate3d(1.f, 2.f, 3.f); |
| 1401 operations2.AppendMatrix(translation_transform); | 1401 operations2.AppendMatrix(translation_transform); |
| 1402 EXPECT_TRUE(operations2.IsTranslation()); | 1402 EXPECT_TRUE(operations2.IsTranslation()); |
| 1403 } | 1403 } |
| 1404 | 1404 |
| 1405 TEST(TransformOperationTest, MaximumScale) { | 1405 TEST(TransformOperationTest, ScaleComponent) { |
| 1406 gfx::Vector3dF scale; |
| 1407 |
| 1408 // Scale. |
| 1406 TransformOperations operations1; | 1409 TransformOperations operations1; |
| 1407 operations1.AppendScale(3.f, 2.f, 5.f); | 1410 operations1.AppendScale(-3.f, 2.f, 5.f); |
| 1408 TransformOperations operations2; | 1411 EXPECT_TRUE(operations1.ScaleComponent(&scale)); |
| 1409 operations2.AppendScale(6.f, 5.f, 2.f); | 1412 EXPECT_EQ(gfx::Vector3dF(-3.f, 2.f, 5.f), scale); |
| 1410 | 1413 |
| 1411 float max_scale = 0.f; | 1414 // Translate + Scale. |
| 1412 EXPECT_TRUE(operations2.MaximumScale(operations1, 0.f, 1.f, &max_scale)); | |
| 1413 // x at progress 1.f | |
| 1414 EXPECT_EQ(6.f, max_scale); | |
| 1415 | |
| 1416 EXPECT_TRUE(operations2.MaximumScale(operations1, -1.f, 1.f, &max_scale)); | |
| 1417 // z at progress -1.f | |
| 1418 EXPECT_EQ(8.f, max_scale); | |
| 1419 | |
| 1420 EXPECT_TRUE(operations2.MaximumScale(operations1, 0.f, 2.f, &max_scale)); | |
| 1421 // x at progress 2.f | |
| 1422 EXPECT_EQ(9.f, max_scale); | |
| 1423 | |
| 1424 TransformOperations operations3; | |
| 1425 operations3.AppendScale(1.f, 4.f, 1.f); | |
| 1426 TransformOperations operations4; | |
| 1427 | |
| 1428 EXPECT_TRUE(operations4.MaximumScale(operations3, 0.f, 1.f, &max_scale)); | |
| 1429 // y at progress 0.f | |
| 1430 EXPECT_EQ(4.f, max_scale); | |
| 1431 | |
| 1432 EXPECT_TRUE(operations4.MaximumScale(operations3, -1.f, 1.f, &max_scale)); | |
| 1433 // y at progress -1.f | |
| 1434 EXPECT_EQ(7.f, max_scale); | |
| 1435 | |
| 1436 EXPECT_TRUE(operations4.MaximumScale(operations3, 0.f, 2.f, &max_scale)); | |
| 1437 // y at progress 0.f | |
| 1438 EXPECT_EQ(4.f, max_scale); | |
| 1439 | |
| 1440 TransformOperations operations5; | 1415 TransformOperations operations5; |
| 1441 operations5.AppendTranslate(1.f, 2.f, 3.f); | 1416 operations5.AppendTranslate(1.f, 2.f, 3.f); |
| 1442 operations5.AppendScale(1.f, 1.f, 4.f); | 1417 operations5.AppendScale(2.f, 5.f, 4.f); |
| 1418 EXPECT_TRUE(operations5.ScaleComponent(&scale)); |
| 1419 EXPECT_EQ(gfx::Vector3dF(2.f, 5.f, 4.f), scale); |
| 1420 |
| 1421 // Translate + Scale + Matrix with translate. |
| 1443 gfx::Transform translation_transform; | 1422 gfx::Transform translation_transform; |
| 1444 translation_transform.Translate3d(1.f, 2.f, 3.f); | 1423 translation_transform.Translate3d(1.f, 2.f, 3.f); |
| 1445 operations5.AppendMatrix(translation_transform); | 1424 operations5.AppendMatrix(translation_transform); |
| 1446 TransformOperations operations6; | 1425 EXPECT_TRUE(operations5.ScaleComponent(&scale)); |
| 1447 operations6.AppendTranslate(2.f, 3.f, 4.f); | 1426 EXPECT_EQ(gfx::Vector3dF(2.f, 5.f, 4.f), scale); |
| 1448 operations6.AppendScale(2.f, 5.f, 1.f); | |
| 1449 operations6.AppendMatrix(translation_transform); | |
| 1450 | |
| 1451 EXPECT_TRUE(operations6.MaximumScale(operations5, 0.f, 1.f, &max_scale)); | |
| 1452 // y at progress 1.f | |
| 1453 EXPECT_EQ(5.f, max_scale); | |
| 1454 | |
| 1455 EXPECT_TRUE(operations6.MaximumScale(operations5, -1.f, 1.f, &max_scale)); | |
| 1456 // z at progress -1.f | |
| 1457 EXPECT_EQ(7.f, max_scale); | |
| 1458 | |
| 1459 EXPECT_TRUE(operations6.MaximumScale(operations5, 0.f, 2.f, &max_scale)); | |
| 1460 // y at progress 2.f | |
| 1461 EXPECT_EQ(9.f, max_scale); | |
| 1462 } | 1427 } |
| 1463 | 1428 |
| 1464 TEST(TransformOperationTest, MaximumScaleCannotBeComputed) { | 1429 TEST(TransformOperationTest, ScaleComponentCannotBeComputed) { |
| 1430 gfx::Vector3dF scale; |
| 1431 |
| 1432 // Scale can. |
| 1465 TransformOperations operations1; | 1433 TransformOperations operations1; |
| 1466 operations1.AppendScale(2.f, 2.f, 2.f); | 1434 operations1.AppendScale(2.f, 2.f, 2.f); |
| 1435 EXPECT_TRUE(operations1.ScaleComponent(&scale)); |
| 1436 EXPECT_EQ(gfx::Vector3dF(2.f, 2.f, 2.f), scale); |
| 1437 |
| 1438 // Translate can. |
| 1467 TransformOperations operations2; | 1439 TransformOperations operations2; |
| 1468 operations2.AppendTranslate(1.f, 2.f, 3.f); | 1440 operations2.AppendTranslate(1.f, 2.f, 3.f); |
| 1441 EXPECT_TRUE(operations2.ScaleComponent(&scale)); |
| 1442 EXPECT_EQ(gfx::Vector3dF(1.f, 1.f, 1.f), scale); |
| 1469 | 1443 |
| 1470 float max_scale = 0.f; | 1444 // Scale + translate can. |
| 1445 TransformOperations operations3; |
| 1446 operations3.AppendScale(2.f, 3.f, 2.f); |
| 1447 operations3.AppendTranslate(1.f, 2.f, 3.f); |
| 1448 EXPECT_TRUE(operations3.ScaleComponent(&scale)); |
| 1449 EXPECT_EQ(gfx::Vector3dF(2.f, 3.f, 2.f), scale); |
| 1471 | 1450 |
| 1472 // Non-matching operations. | 1451 // Two Scales can't. |
| 1473 EXPECT_FALSE(operations2.MaximumScale(operations1, 0.f, 1.f, &max_scale)); | 1452 TransformOperations operations4; |
| 1453 operations4.AppendScale(2.f, 3.f, 2.f); |
| 1454 operations4.AppendScale(3.f, 2.f, 3.f); |
| 1455 EXPECT_FALSE(operations4.ScaleComponent(&scale)); |
| 1474 | 1456 |
| 1475 TransformOperations operations3; | 1457 // Matrix can't. |
| 1476 operations3.AppendScale(2.f, 2.f, 2.f); | |
| 1477 operations3.AppendTranslate(1.f, 2.f, 3.f); | |
| 1478 operations3.AppendScale(3.f, 3.f, 3.f); | |
| 1479 TransformOperations operations4; | |
| 1480 operations4.AppendScale(4.f, 4.f, 4.f); | |
| 1481 operations4.AppendTranslate(2.f, 3.f, 4.f); | |
| 1482 operations4.AppendScale(5.f, 5.f, 5.f); | |
| 1483 | |
| 1484 // More that one scale operation in a sequence. | |
| 1485 EXPECT_FALSE(operations4.MaximumScale(operations3, 0.f, 1.f, &max_scale)); | |
| 1486 | |
| 1487 TransformOperations operations5; | 1458 TransformOperations operations5; |
| 1488 operations5.AppendScale(2.f, 2.f, 2.f); | 1459 operations5.AppendScale(2.f, 2.f, 2.f); |
| 1489 gfx::Transform scaling_transform; | 1460 gfx::Transform scaling_transform; |
| 1490 scaling_transform.Scale(2.f, 2.f); | 1461 scaling_transform.Scale(2.f, 2.f); |
| 1491 operations5.AppendMatrix(scaling_transform); | 1462 operations5.AppendMatrix(scaling_transform); |
| 1492 TransformOperations operations6; | 1463 EXPECT_FALSE(operations5.ScaleComponent(&scale)); |
| 1493 operations6.AppendScale(3.f, 3.f, 3.f); | |
| 1494 gfx::Transform translation_transform; | |
| 1495 translation_transform.Translate3d(1.f, 2.f, 3.f); | |
| 1496 operations6.AppendMatrix(translation_transform); | |
| 1497 | 1464 |
| 1498 // Non-translation matrix operation. | 1465 // Scale + Rotate can't. |
| 1499 EXPECT_FALSE(operations6.MaximumScale(operations5, 0.f, 1.f, &max_scale)); | |
| 1500 | |
| 1501 TransformOperations operations7; | 1466 TransformOperations operations7; |
| 1502 operations7.AppendScale(2.f, 2.f, 2.f); | 1467 operations7.AppendScale(2.f, 2.f, 2.f); |
| 1503 operations7.AppendRotate(1.f, 2.f, 3.f, 4.f); | 1468 operations7.AppendRotate(1.f, 2.f, 3.f, 4.f); |
| 1504 TransformOperations operations8; | 1469 EXPECT_FALSE(operations7.ScaleComponent(&scale)); |
| 1505 operations8.AppendScale(3.f, 3.f, 3.f); | |
| 1506 operations8.AppendRotate(3.f, 4.f, 5.f, 6.f); | |
| 1507 | 1470 |
| 1508 // Rotation operation. | 1471 // Scale + Skew can't. |
| 1509 EXPECT_FALSE(operations8.MaximumScale(operations7, 0.f, 1.f, &max_scale)); | |
| 1510 | |
| 1511 TransformOperations operations9; | 1472 TransformOperations operations9; |
| 1512 operations9.AppendScale(2.f, 2.f, 2.f); | 1473 operations9.AppendScale(2.f, 2.f, 2.f); |
| 1513 operations9.AppendSkew(1.f, 2.f); | 1474 operations9.AppendSkew(1.f, 2.f); |
| 1514 TransformOperations operations10; | 1475 EXPECT_FALSE(operations9.ScaleComponent(&scale)); |
| 1515 operations10.AppendScale(3.f, 3.f, 3.f); | |
| 1516 operations10.AppendSkew(3.f, 4.f); | |
| 1517 | 1476 |
| 1518 // Skew operation. | 1477 // Scale + Perspective can't. |
| 1519 EXPECT_FALSE(operations10.MaximumScale(operations9, 0.f, 1.f, &max_scale)); | |
| 1520 | |
| 1521 TransformOperations operations11; | 1478 TransformOperations operations11; |
| 1522 operations11.AppendScale(2.f, 2.f, 2.f); | 1479 operations11.AppendScale(2.f, 2.f, 2.f); |
| 1523 operations11.AppendPerspective(1.f); | 1480 operations11.AppendPerspective(1.f); |
| 1524 TransformOperations operations12; | 1481 EXPECT_FALSE(operations11.ScaleComponent(&scale)); |
| 1525 operations12.AppendScale(3.f, 3.f, 3.f); | |
| 1526 operations12.AppendPerspective(3.f); | |
| 1527 | |
| 1528 // Perspective operation. | |
| 1529 EXPECT_FALSE(operations12.MaximumScale(operations11, 0.f, 1.f, &max_scale)); | |
| 1530 } | 1482 } |
| 1531 | 1483 |
| 1532 } // namespace | 1484 } // namespace |
| 1533 } // namespace cc | 1485 } // namespace cc |
| OLD | NEW |