| OLD | NEW |
| 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/layer_animation_controller.h" | 5 #include "cc/layer_animation_controller.h" |
| 6 | 6 |
| 7 #include "cc/animation.h" | 7 #include "cc/animation.h" |
| 8 #include "cc/animation_curve.h" | 8 #include "cc/animation_curve.h" |
| 9 #include "cc/keyframed_animation_curve.h" |
| 9 #include "cc/test/animation_test_common.h" | 10 #include "cc/test/animation_test_common.h" |
| 11 #include "cc/transform_operations.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gfx/transform.h" | 14 #include "ui/gfx/transform.h" |
| 13 | 15 |
| 14 namespace cc { | 16 namespace cc { |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 void expectTranslateX(double translateX, const gfx::Transform& matrix) | 19 void expectTranslateX(double translateX, const gfx::Transform& matrix) |
| 18 { | 20 { |
| 19 EXPECT_FLOAT_EQ(translateX, matrix.matrix().getDouble(0, 3)); | 21 EXPECT_FLOAT_EQ(translateX, matrix.matrix().getDouble(0, 3)); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 151 |
| 150 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); | 152 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); |
| 151 | 153 |
| 152 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 154 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
| 153 | 155 |
| 154 // Even though the main thread has a 'new' animation, it should not be pushe
d because the animation has already completed on the impl thread. | 156 // Even though the main thread has a 'new' animation, it should not be pushe
d because the animation has already completed on the impl thread. |
| 155 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); | 157 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); |
| 156 } | 158 } |
| 157 | 159 |
| 158 // Tests that transitioning opacity from 0 to 1 works as expected. | 160 // Tests that transitioning opacity from 0 to 1 works as expected. |
| 161 |
| 162 static const AnimationEvent* getMostRecentPropertyUpdateEvent(const AnimationEve
ntsVector* events) |
| 163 { |
| 164 const AnimationEvent* event = 0; |
| 165 for (size_t i = 0; i < events->size(); ++i) |
| 166 if ((*events)[i].type == AnimationEvent::PropertyUpdate) |
| 167 event = &(*events)[i]; |
| 168 |
| 169 return event; |
| 170 } |
| 171 |
| 159 TEST(LayerAnimationControllerTest, TrivialTransition) | 172 TEST(LayerAnimationControllerTest, TrivialTransition) |
| 160 { | 173 { |
| 161 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 174 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 162 FakeLayerAnimationValueObserver dummy; | 175 FakeLayerAnimationValueObserver dummy; |
| 163 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 176 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 164 controller->addObserver(&dummy); | 177 controller->addObserver(&dummy); |
| 165 | 178 |
| 166 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 179 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
| 167 | 180 |
| 168 controller->addAnimation(toAdd.Pass()); | 181 controller->addAnimation(toAdd.Pass()); |
| 169 controller->animate(0); | 182 controller->animate(0); |
| 170 controller->updateState(events.get()); | 183 controller->updateState(events.get()); |
| 171 EXPECT_TRUE(controller->hasActiveAnimation()); | 184 EXPECT_TRUE(controller->hasActiveAnimation()); |
| 172 EXPECT_EQ(0, dummy.opacity()); | 185 EXPECT_EQ(0, dummy.opacity()); |
| 186 // A non-implOnly animation should not generate property updates. |
| 187 const AnimationEvent* event = getMostRecentPropertyUpdateEvent(events.get())
; |
| 188 EXPECT_FALSE(event); |
| 173 controller->animate(1); | 189 controller->animate(1); |
| 174 controller->updateState(events.get()); | 190 controller->updateState(events.get()); |
| 175 EXPECT_EQ(1, dummy.opacity()); | 191 EXPECT_EQ(1, dummy.opacity()); |
| 176 EXPECT_FALSE(controller->hasActiveAnimation()); | 192 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 193 event = getMostRecentPropertyUpdateEvent(events.get()); |
| 194 EXPECT_FALSE(event); |
| 195 } |
| 196 |
| 197 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) |
| 198 { |
| 199 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 200 FakeLayerAnimationValueObserver dummyImpl; |
| 201 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
| 202 controllerImpl->addObserver(&dummyImpl); |
| 203 |
| 204 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
| 205 toAdd->setIsImplOnly(true); |
| 206 |
| 207 controllerImpl->addAnimation(toAdd.Pass()); |
| 208 controllerImpl->animate(0); |
| 209 controllerImpl->updateState(events.get()); |
| 210 EXPECT_TRUE(controllerImpl->hasActiveAnimation()); |
| 211 EXPECT_EQ(0, dummyImpl.opacity()); |
| 212 EXPECT_EQ(2, events->size()); |
| 213 const AnimationEvent* startOpacityEvent = getMostRecentPropertyUpdateEvent(e
vents.get()); |
| 214 EXPECT_EQ(0, startOpacityEvent->opacity); |
| 215 |
| 216 controllerImpl->animate(1); |
| 217 controllerImpl->updateState(events.get()); |
| 218 EXPECT_EQ(1, dummyImpl.opacity()); |
| 219 EXPECT_FALSE(controllerImpl->hasActiveAnimation()); |
| 220 EXPECT_EQ(4, events->size()); |
| 221 const AnimationEvent* endOpacityEvent = getMostRecentPropertyUpdateEvent(eve
nts.get()); |
| 222 EXPECT_EQ(1, endOpacityEvent->opacity); |
| 223 } |
| 224 |
| 225 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) |
| 226 { |
| 227 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 228 FakeLayerAnimationValueObserver dummyImpl; |
| 229 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
| 230 controllerImpl->addObserver(&dummyImpl); |
| 231 |
| 232 // Choose different values for x and y to avoid coincidental values in the |
| 233 // observed transforms. |
| 234 const float deltaX = 3; |
| 235 const float deltaY = 4; |
| 236 |
| 237 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati
onCurve::create()); |
| 238 |
| 239 // Create simple Transform animation. |
| 240 TransformOperations operations; |
| 241 curve->addKeyframe(TransformKeyframe::create(0, operations, scoped_ptr<cc::T
imingFunction>())); |
| 242 operations.AppendTranslate(deltaX, deltaY, 0); |
| 243 curve->addKeyframe(TransformKeyframe::create(1, operations, scoped_ptr<cc::T
imingFunction>())); |
| 244 |
| 245 scoped_ptr<Animation> animation(Animation::create(curve.PassAs<AnimationCurv
e>(), 1, 0, Animation::Transform)); |
| 246 animation->setIsImplOnly(true); |
| 247 controllerImpl->addAnimation(animation.Pass()); |
| 248 |
| 249 // Run animation. |
| 250 controllerImpl->animate(0); |
| 251 controllerImpl->updateState(events.get()); |
| 252 EXPECT_TRUE(controllerImpl->hasActiveAnimation()); |
| 253 EXPECT_EQ(gfx::Transform(), dummyImpl.transform()); |
| 254 EXPECT_EQ(2, events->size()); |
| 255 const AnimationEvent* startTransformEvent = getMostRecentPropertyUpdateEvent
(events.get()); |
| 256 ASSERT_TRUE(startTransformEvent); |
| 257 EXPECT_EQ(gfx::Transform(), startTransformEvent->transform); |
| 258 |
| 259 gfx::Transform expectedTransform; |
| 260 expectedTransform.Translate(deltaX, deltaY); |
| 261 |
| 262 controllerImpl->animate(1); |
| 263 controllerImpl->updateState(events.get()); |
| 264 EXPECT_EQ(expectedTransform, dummyImpl.transform()); |
| 265 EXPECT_FALSE(controllerImpl->hasActiveAnimation()); |
| 266 EXPECT_EQ(4, events->size()); |
| 267 const AnimationEvent* endTransformEvent = getMostRecentPropertyUpdateEvent(e
vents.get()); |
| 268 EXPECT_EQ(expectedTransform, endTransformEvent->transform); |
| 177 } | 269 } |
| 178 | 270 |
| 179 // Tests animations that are waiting for a synchronized start time do not finish
. | 271 // Tests animations that are waiting for a synchronized start time do not finish
. |
| 180 TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe
yWaitLongerToStartThanTheirDuration) | 272 TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe
yWaitLongerToStartThanTheirDuration) |
| 181 { | 273 { |
| 182 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 274 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
| 183 FakeLayerAnimationValueObserver dummy; | 275 FakeLayerAnimationValueObserver dummy; |
| 184 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 276 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
| 185 controller->addObserver(&dummy); | 277 controller->addObserver(&dummy); |
| 186 | 278 |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 controller->animate(3); | 743 controller->animate(3); |
| 652 controller->updateState(events.get()); | 744 controller->updateState(events.get()); |
| 653 | 745 |
| 654 // The float tranisition should now be done. | 746 // The float tranisition should now be done. |
| 655 EXPECT_EQ(1, dummy.opacity()); | 747 EXPECT_EQ(1, dummy.opacity()); |
| 656 EXPECT_FALSE(controller->hasActiveAnimation()); | 748 EXPECT_FALSE(controller->hasActiveAnimation()); |
| 657 } | 749 } |
| 658 | 750 |
| 659 } // namespace | 751 } // namespace |
| 660 } // namespace cc | 752 } // namespace cc |
| OLD | NEW |