summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-04 01:29:58 +0000
committervollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-04 01:29:58 +0000
commit22a0fbd00117465e9d451cc4d1758e8050052661 (patch)
tree1125760f2c0cf4839239399f9757a5a6d8231e1b
parentfeacc37d3da5fdf5eec6d616835e2ede92d1bf13 (diff)
downloadchromium_src-22a0fbd00117465e9d451cc4d1758e8050052661.zip
chromium_src-22a0fbd00117465e9d451cc4d1758e8050052661.tar.gz
chromium_src-22a0fbd00117465e9d451cc4d1758e8050052661.tar.bz2
After http://crrev.com/202755, timing functions can now produce values outside the range [0, 1]. Unfortunately, these values are getting clamped when they are used for blending. This CL removes that extra clamping and adds unit tests for this extrapolation.
BUG=178299 R=ajuma@chromium.org Review URL: https://codereview.chromium.org/15972006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203808 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--cc/animation/transform_operation.cc6
-rw-r--r--cc/animation/transform_operations.cc10
-rw-r--r--cc/animation/transform_operations_unittest.cc106
-rw-r--r--ui/gfx/transform.cc8
-rw-r--r--ui/gfx/transform_unittest.cc29
5 files changed, 128 insertions, 31 deletions
diff --git a/cc/animation/transform_operation.cc b/cc/animation/transform_operation.cc
index e1468bf..854901d 100644
--- a/cc/animation/transform_operation.cc
+++ b/cc/animation/transform_operation.cc
@@ -74,12 +74,6 @@ static bool ShareSameAxis(const TransformOperation* from,
}
static double BlendDoubles(double from, double to, double progress) {
- if (progress <= 0.0)
- return from;
-
- if (progress >= 1.0)
- return to;
-
return from * (1 - progress) + to * progress;
}
diff --git a/cc/animation/transform_operations.cc b/cc/animation/transform_operations.cc
index 8826d29..d74f1a5 100644
--- a/cc/animation/transform_operations.cc
+++ b/cc/animation/transform_operations.cc
@@ -164,16 +164,6 @@ bool TransformOperations::BlendInternal(const TransformOperations& from,
return true;
}
- if (progress <= 0.0) {
- *result = from.Apply();
- return true;
- }
-
- if (progress >= 1.0) {
- *result = Apply();
- return true;
- }
-
if (!ComputeDecomposedTransform() || !from.ComputeDecomposedTransform())
return false;
diff --git a/cc/animation/transform_operations_unittest.cc b/cc/animation/transform_operations_unittest.cc
index 7e344c7..8fc9b94 100644
--- a/cc/animation/transform_operations_unittest.cc
+++ b/cc/animation/transform_operations_unittest.cc
@@ -432,6 +432,22 @@ TEST(TransformOperationTest, BlendRotationFromIdentity) {
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected, operations.Blend(*identity_operations[i], progress));
+
+ progress = -0.5;
+
+ expected.MakeIdentity();
+ expected.RotateAbout(gfx::Vector3dF(0, 0, 1), -180);
+
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations.Blend(*identity_operations[i], progress));
+
+ progress = 1.5;
+
+ expected.MakeIdentity();
+ expected.RotateAbout(gfx::Vector3dF(0, 0, 1), 540);
+
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations.Blend(*identity_operations[i], progress));
}
}
@@ -450,6 +466,22 @@ TEST(TransformOperationTest, BlendTranslationFromIdentity) {
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected, operations.Blend(*identity_operations[i], progress));
+
+ progress = -0.5;
+
+ expected.MakeIdentity();
+ expected.Translate3d(-1, -1, -1);
+
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations.Blend(*identity_operations[i], progress));
+
+ progress = 1.5;
+
+ expected.MakeIdentity();
+ expected.Translate3d(3, 3, 3);
+
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations.Blend(*identity_operations[i], progress));
}
}
@@ -468,6 +500,22 @@ TEST(TransformOperationTest, BlendScaleFromIdentity) {
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected, operations.Blend(*identity_operations[i], progress));
+
+ progress = -0.5;
+
+ expected.MakeIdentity();
+ expected.Scale3d(0, 0, 0);
+
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations.Blend(*identity_operations[i], progress));
+
+ progress = 1.5;
+
+ expected.MakeIdentity();
+ expected.Scale3d(4, 4, 4);
+
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations.Blend(*identity_operations[i], progress));
}
}
@@ -487,6 +535,24 @@ TEST(TransformOperationTest, BlendSkewFromIdentity) {
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected, operations.Blend(*identity_operations[i], progress));
+
+ progress = -0.5;
+
+ expected.MakeIdentity();
+ expected.SkewX(-1);
+ expected.SkewY(-1);
+
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations.Blend(*identity_operations[i], progress));
+
+ progress = 1.5;
+
+ expected.MakeIdentity();
+ expected.SkewX(3);
+ expected.SkewY(3);
+
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations.Blend(*identity_operations[i], progress));
}
}
@@ -601,5 +667,45 @@ TEST(TransformOperationTest, BlendPerspectiveToIdentity) {
}
}
+TEST(TransformOperationTest, ExtrapolatePerspectiveBlending) {
+ TransformOperations operations1;
+ operations1.AppendPerspective(1000);
+
+ TransformOperations operations2;
+ operations2.AppendPerspective(500);
+
+ gfx::Transform expected;
+ expected.ApplyPerspectiveDepth(250);
+
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations1.Blend(operations2, -0.5));
+
+ expected.MakeIdentity();
+ expected.ApplyPerspectiveDepth(1250);
+
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations1.Blend(operations2, 1.5));
+}
+
+TEST(TransformOperationTest, ExtrapolateMatrixBlending) {
+ gfx::Transform transform1;
+ transform1.Translate3d(1, 1, 1);
+ TransformOperations operations1;
+ operations1.AppendMatrix(transform1);
+
+ gfx::Transform transform2;
+ transform2.Translate3d(3, 3, 3);
+ TransformOperations operations2;
+ operations2.AppendMatrix(transform2);
+
+ gfx::Transform expected;
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations1.Blend(operations2, 1.5));
+
+ expected.Translate3d(4, 4, 4);
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, operations1.Blend(operations2, -0.5));
+}
+
} // namespace
} // namespace cc
diff --git a/ui/gfx/transform.cc b/ui/gfx/transform.cc
index 5e87998..09a213e 100644
--- a/ui/gfx/transform.cc
+++ b/ui/gfx/transform.cc
@@ -365,14 +365,6 @@ bool Transform::TransformRectReverse(RectF* rect) const {
}
bool Transform::Blend(const Transform& from, double progress) {
- if (progress <= 0.0) {
- *this = from;
- return true;
- }
-
- if (progress >= 1.0)
- return true;
-
DecomposedTransform to_decomp;
DecomposedTransform from_decomp;
if (!DecomposeTransform(&to_decomp, *this) ||
diff --git a/ui/gfx/transform_unittest.cc b/ui/gfx/transform_unittest.cc
index 72abeef..7ccde8c 100644
--- a/ui/gfx/transform_unittest.cc
+++ b/ui/gfx/transform_unittest.cc
@@ -12,6 +12,7 @@
#include <limits>
#include "base/basictypes.h"
+#include "base/logging.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/point.h"
#include "ui/gfx/point3_f.h"
@@ -654,7 +655,7 @@ TEST(XFormTest, SetRotate2D) {
TEST(XFormTest, BlendTranslate) {
Transform from;
- for (int i = 0; i < 10; ++i) {
+ for (int i = -5; i < 15; ++i) {
Transform to;
to.Translate3d(1, 1, 1);
double t = i / 9.0;
@@ -674,7 +675,7 @@ TEST(XFormTest, BlendRotate) {
};
Transform from;
for (size_t index = 0; index < ARRAYSIZE_UNSAFE(axes); ++index) {
- for (int i = 0; i < 10; ++i) {
+ for (int i = -5; i < 15; ++i) {
Transform to;
to.RotateAbout(axes[index], 90);
double t = i / 9.0;
@@ -698,7 +699,7 @@ TEST(XFormTest, BlendRotateFollowsShortestPath) {
Vector3dF(1, 1, 1)
};
for (size_t index = 0; index < ARRAYSIZE_UNSAFE(axes); ++index) {
- for (int i = 0; i < 10; ++i) {
+ for (int i = -5; i < 15; ++i) {
Transform from1;
from1.RotateAbout(axes[index], 130.0);
Transform to1;
@@ -734,7 +735,7 @@ TEST(XFormTest, CanBlend180DegreeRotation) {
};
Transform from;
for (size_t index = 0; index < ARRAYSIZE_UNSAFE(axes); ++index) {
- for (int i = 0; i < 10; ++i) {
+ for (int i = -5; i < 15; ++i) {
Transform to;
to.RotateAbout(axes[index], 180);
double t = i / 9.0;
@@ -750,7 +751,7 @@ TEST(XFormTest, CanBlend180DegreeRotation) {
TEST(XFormTest, BlendScale) {
Transform from;
- for (int i = 0; i < 10; ++i) {
+ for (int i = -5; i < 15; ++i) {
Transform to;
to.Scale3d(5, 4, 3);
double t = i / 9.0;
@@ -776,15 +777,29 @@ TEST(XFormTest, BlendSkew) {
}
}
+TEST(XFormTest, ExtrapolateSkew) {
+ Transform from;
+ for (int i = -1; i < 2; ++i) {
+ Transform to;
+ to.SkewX(20);
+ double t = i;
+ Transform expected;
+ expected.SkewX(t * 20);
+ EXPECT_TRUE(to.Blend(from, t));
+ EXPECT_TRUE(MatricesAreNearlyEqual(expected, to));
+ }
+}
+
TEST(XFormTest, BlendPerspective) {
Transform from;
from.ApplyPerspectiveDepth(200);
- for (int i = 0; i < 2; ++i) {
+ for (int i = -1; i < 3; ++i) {
Transform to;
to.ApplyPerspectiveDepth(800);
double t = i;
+ double depth = 1.0 / ((1.0 / 200) * (1.0 - t) + (1.0 / 800) * t);
Transform expected;
- expected.ApplyPerspectiveDepth(t * 600 + 200);
+ expected.ApplyPerspectiveDepth(depth);
EXPECT_TRUE(to.Blend(from, t));
EXPECT_TRUE(MatricesAreNearlyEqual(expected, to));
}