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

Side by Side Diff: cc/animation/layer_animation_controller_unittest.cc

Issue 642983003: cc: Make PictureLayerImpl use a better choice for animated raster scale. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: animationscale: fixtest Created 6 years, 2 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/animation/layer_animation_controller.cc ('k') | cc/animation/transform_operations.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/layer_animation_controller.h" 5 #include "cc/animation/layer_animation_controller.h"
6 6
7 #include "cc/animation/animation.h" 7 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_curve.h" 8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/animation_delegate.h" 9 #include "cc/animation/animation_delegate.h"
10 #include "cc/animation/animation_registrar.h" 10 #include "cc/animation/animation_registrar.h"
(...skipping 1872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms()); 1883 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms());
1884 1884
1885 controller_impl->GetAnimation(3, Animation::Transform) 1885 controller_impl->GetAnimation(3, Animation::Transform)
1886 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); 1886 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
1887 1887
1888 // Only unfinished animations should be considered by 1888 // Only unfinished animations should be considered by
1889 // HasOnlyTranslationTransforms. 1889 // HasOnlyTranslationTransforms.
1890 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); 1890 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms());
1891 } 1891 }
1892 1892
1893 TEST(LayerAnimationControllerTest, MaximumScale) { 1893 TEST(LayerAnimationControllerTest, MaximumTargetScale) {
1894 scoped_refptr<LayerAnimationController> controller_impl( 1894 scoped_refptr<LayerAnimationController> controller_impl(
1895 LayerAnimationController::Create(0)); 1895 LayerAnimationController::Create(0));
1896 1896
1897 float max_scale = 0.f; 1897 float max_scale = 0.f;
1898 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale)); 1898 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
1899 EXPECT_EQ(0.f, max_scale); 1899 EXPECT_EQ(0.f, max_scale);
1900 1900
1901 scoped_ptr<KeyframedTransformAnimationCurve> curve1( 1901 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
1902 KeyframedTransformAnimationCurve::Create()); 1902 KeyframedTransformAnimationCurve::Create());
1903 1903
1904 TransformOperations operations1; 1904 TransformOperations operations1;
1905 curve1->AddKeyframe(TransformKeyframe::Create( 1905 curve1->AddKeyframe(TransformKeyframe::Create(
1906 0.0, operations1, scoped_ptr<TimingFunction>())); 1906 0.0, operations1, scoped_ptr<TimingFunction>()));
1907 operations1.AppendScale(2.0, 3.0, 4.0); 1907 operations1.AppendScale(2.0, 3.0, 4.0);
1908 curve1->AddKeyframe(TransformKeyframe::Create( 1908 curve1->AddKeyframe(TransformKeyframe::Create(
1909 1.0, operations1, scoped_ptr<TimingFunction>())); 1909 1.0, operations1, scoped_ptr<TimingFunction>()));
1910 1910
1911 scoped_ptr<Animation> animation( 1911 scoped_ptr<Animation> animation(
1912 Animation::Create(curve1.Pass(), 1, 1, Animation::Transform)); 1912 Animation::Create(curve1.Pass(), 1, 1, Animation::Transform));
1913 controller_impl->AddAnimation(animation.Pass()); 1913 controller_impl->AddAnimation(animation.Pass());
1914 1914
1915 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale)); 1915 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
1916 EXPECT_EQ(4.f, max_scale); 1916 EXPECT_EQ(4.f, max_scale);
1917 1917
1918 scoped_ptr<KeyframedTransformAnimationCurve> curve2( 1918 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
1919 KeyframedTransformAnimationCurve::Create()); 1919 KeyframedTransformAnimationCurve::Create());
1920 1920
1921 TransformOperations operations2; 1921 TransformOperations operations2;
1922 curve2->AddKeyframe(TransformKeyframe::Create( 1922 curve2->AddKeyframe(TransformKeyframe::Create(
1923 0.0, operations2, scoped_ptr<TimingFunction>())); 1923 0.0, operations2, scoped_ptr<TimingFunction>()));
1924 operations2.AppendScale(6.0, 5.0, 4.0); 1924 operations2.AppendScale(6.0, 5.0, 4.0);
1925 curve2->AddKeyframe(TransformKeyframe::Create( 1925 curve2->AddKeyframe(TransformKeyframe::Create(
1926 1.0, operations2, scoped_ptr<TimingFunction>())); 1926 1.0, operations2, scoped_ptr<TimingFunction>()));
1927 1927
1928 animation = Animation::Create(curve2.Pass(), 2, 2, Animation::Transform); 1928 animation = Animation::Create(curve2.Pass(), 2, 2, Animation::Transform);
1929 controller_impl->AddAnimation(animation.Pass()); 1929 controller_impl->AddAnimation(animation.Pass());
1930 1930
1931 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale)); 1931 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
1932 EXPECT_EQ(6.f, max_scale); 1932 EXPECT_EQ(6.f, max_scale);
1933 1933
1934 scoped_ptr<KeyframedTransformAnimationCurve> curve3( 1934 scoped_ptr<KeyframedTransformAnimationCurve> curve3(
1935 KeyframedTransformAnimationCurve::Create()); 1935 KeyframedTransformAnimationCurve::Create());
1936 1936
1937 TransformOperations operations3; 1937 TransformOperations operations3;
1938 curve3->AddKeyframe(TransformKeyframe::Create( 1938 curve3->AddKeyframe(TransformKeyframe::Create(
1939 0.0, operations3, scoped_ptr<TimingFunction>())); 1939 0.0, operations3, scoped_ptr<TimingFunction>()));
1940 operations3.AppendPerspective(6.0); 1940 operations3.AppendPerspective(6.0);
1941 curve3->AddKeyframe(TransformKeyframe::Create( 1941 curve3->AddKeyframe(TransformKeyframe::Create(
1942 1.0, operations3, scoped_ptr<TimingFunction>())); 1942 1.0, operations3, scoped_ptr<TimingFunction>()));
1943 1943
1944 animation = Animation::Create(curve3.Pass(), 3, 3, Animation::Transform); 1944 animation = Animation::Create(curve3.Pass(), 3, 3, Animation::Transform);
1945 controller_impl->AddAnimation(animation.Pass()); 1945 controller_impl->AddAnimation(animation.Pass());
1946 1946
1947 EXPECT_FALSE(controller_impl->MaximumScale(&max_scale)); 1947 EXPECT_FALSE(controller_impl->MaximumTargetScale(&max_scale));
1948 1948
1949 controller_impl->GetAnimation(3, Animation::Transform) 1949 controller_impl->GetAnimation(3, Animation::Transform)
1950 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); 1950 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
1951 controller_impl->GetAnimation(2, Animation::Transform) 1951 controller_impl->GetAnimation(2, Animation::Transform)
1952 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); 1952 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
1953 1953
1954 // Only unfinished animations should be considered by 1954 // Only unfinished animations should be considered by
1955 // MaximumScale. 1955 // MaximumTargetScale.
1956 EXPECT_TRUE(controller_impl->MaximumScale(&max_scale)); 1956 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
1957 EXPECT_EQ(4.f, max_scale); 1957 EXPECT_EQ(4.f, max_scale);
1958 } 1958 }
1959 1959
1960 TEST(LayerAnimationControllerTest, MaximumTargetScaleWithDirection) {
1961 scoped_refptr<LayerAnimationController> controller_impl(
1962 LayerAnimationController::Create(0));
1963
1964 scoped_ptr<KeyframedTransformAnimationCurve> curve1(
1965 KeyframedTransformAnimationCurve::Create());
1966 TransformOperations operations1;
1967 operations1.AppendScale(1.0, 2.0, 3.0);
1968 curve1->AddKeyframe(TransformKeyframe::Create(
1969 0.0, operations1, scoped_ptr<TimingFunction>()));
1970 TransformOperations operations2;
1971 operations2.AppendScale(4.0, 5.0, 6.0);
1972 curve1->AddKeyframe(TransformKeyframe::Create(
1973 1.0, operations2, scoped_ptr<TimingFunction>()));
1974
1975 scoped_ptr<Animation> animation_owned(
1976 Animation::Create(curve1.Pass(), 1, 1, Animation::Transform));
1977 Animation* animation = animation_owned.get();
1978 controller_impl->AddAnimation(animation_owned.Pass());
1979
1980 float max_scale = 0.f;
1981
1982 EXPECT_GT(animation->playback_rate(), 0.0);
1983
1984 // Normal direction with positive playback rate.
1985 animation->set_direction(Animation::Normal);
1986 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
1987 EXPECT_EQ(6.f, max_scale);
1988
1989 // Alternate direction with positive playback rate.
1990 animation->set_direction(Animation::Alternate);
1991 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
1992 EXPECT_EQ(6.f, max_scale);
1993
1994 // Reverse direction with positive playback rate.
1995 animation->set_direction(Animation::Reverse);
1996 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
1997 EXPECT_EQ(3.f, max_scale);
1998
1999 // Alternate reverse direction.
2000 animation->set_direction(Animation::Reverse);
2001 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
2002 EXPECT_EQ(3.f, max_scale);
2003
2004 animation->set_playback_rate(-1.0);
2005
2006 // Normal direction with negative playback rate.
2007 animation->set_direction(Animation::Normal);
2008 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
2009 EXPECT_EQ(3.f, max_scale);
2010
2011 // Alternate direction with negative playback rate.
2012 animation->set_direction(Animation::Alternate);
2013 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
2014 EXPECT_EQ(3.f, max_scale);
2015
2016 // Reverse direction with negative playback rate.
2017 animation->set_direction(Animation::Reverse);
2018 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
2019 EXPECT_EQ(6.f, max_scale);
2020
2021 // Alternate reverse direction with negative playback rate.
2022 animation->set_direction(Animation::Reverse);
2023 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
2024 EXPECT_EQ(6.f, max_scale);
2025 }
2026
1960 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) { 2027 TEST(LayerAnimationControllerTest, NewlyPushedAnimationWaitsForActivation) {
1961 scoped_ptr<AnimationEventsVector> events( 2028 scoped_ptr<AnimationEventsVector> events(
1962 make_scoped_ptr(new AnimationEventsVector)); 2029 make_scoped_ptr(new AnimationEventsVector));
1963 FakeLayerAnimationValueObserver dummy_impl; 2030 FakeLayerAnimationValueObserver dummy_impl;
1964 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; 2031 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
1965 scoped_refptr<LayerAnimationController> controller_impl( 2032 scoped_refptr<LayerAnimationController> controller_impl(
1966 LayerAnimationController::Create(0)); 2033 LayerAnimationController::Create(0));
1967 controller_impl->AddValueObserver(&dummy_impl); 2034 controller_impl->AddValueObserver(&dummy_impl);
1968 controller_impl->AddValueObserver(&pending_dummy_impl); 2035 controller_impl->AddValueObserver(&pending_dummy_impl);
1969 FakeLayerAnimationValueObserver dummy; 2036 FakeLayerAnimationValueObserver dummy;
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 // been ticked at the new animation's starting point. 2321 // been ticked at the new animation's starting point.
2255 EXPECT_EQ(Animation::Running, 2322 EXPECT_EQ(Animation::Running,
2256 controller_impl->GetAnimation(second_animation_group_id, 2323 controller_impl->GetAnimation(second_animation_group_id,
2257 Animation::Opacity)->run_state()); 2324 Animation::Opacity)->run_state());
2258 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); 2325 EXPECT_EQ(1.f, pending_dummy_impl.opacity());
2259 EXPECT_EQ(1.f, dummy_impl.opacity()); 2326 EXPECT_EQ(1.f, dummy_impl.opacity());
2260 } 2327 }
2261 2328
2262 } // namespace 2329 } // namespace
2263 } // namespace cc 2330 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/animation/transform_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698