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

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

Issue 361143002: Impl thread smooth scrolling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/input/input_handler.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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 469 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
470 1, 470 1,
471 Animation::Opacity)); 471 Animation::Opacity));
472 to_add->set_is_impl_only(true); 472 to_add->set_is_impl_only(true);
473 473
474 controller_impl->AddAnimation(to_add.Pass()); 474 controller_impl->AddAnimation(to_add.Pass());
475 controller_impl->Animate(kInitialTickTime); 475 controller_impl->Animate(kInitialTickTime);
476 controller_impl->UpdateState(true, events.get()); 476 controller_impl->UpdateState(true, events.get());
477 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 477 EXPECT_TRUE(controller_impl->HasActiveAnimation());
478 EXPECT_EQ(0.f, dummy_impl.opacity()); 478 EXPECT_EQ(0.f, dummy_impl.opacity());
479 EXPECT_EQ(2u, events->size()); 479 EXPECT_EQ(1u, events->size());
480 const AnimationEvent* start_opacity_event = 480 const AnimationEvent* start_opacity_event =
481 GetMostRecentPropertyUpdateEvent(events.get()); 481 GetMostRecentPropertyUpdateEvent(events.get());
482 EXPECT_EQ(0.f, start_opacity_event->opacity); 482 EXPECT_EQ(0.f, start_opacity_event->opacity);
483 483
484 controller_impl->Animate(kInitialTickTime + 484 controller_impl->Animate(kInitialTickTime +
485 TimeDelta::FromMilliseconds(1000)); 485 TimeDelta::FromMilliseconds(1000));
486 controller_impl->UpdateState(true, events.get()); 486 controller_impl->UpdateState(true, events.get());
487 EXPECT_EQ(1.f, dummy_impl.opacity()); 487 EXPECT_EQ(1.f, dummy_impl.opacity());
488 EXPECT_FALSE(controller_impl->HasActiveAnimation()); 488 EXPECT_FALSE(controller_impl->HasActiveAnimation());
489 EXPECT_EQ(4u, events->size()); 489 EXPECT_EQ(2u, events->size());
490 const AnimationEvent* end_opacity_event = 490 const AnimationEvent* end_opacity_event =
491 GetMostRecentPropertyUpdateEvent(events.get()); 491 GetMostRecentPropertyUpdateEvent(events.get());
492 EXPECT_EQ(1.f, end_opacity_event->opacity); 492 EXPECT_EQ(1.f, end_opacity_event->opacity);
493 } 493 }
494 494
495 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { 495 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) {
496 scoped_ptr<AnimationEventsVector> events( 496 scoped_ptr<AnimationEventsVector> events(
497 make_scoped_ptr(new AnimationEventsVector)); 497 make_scoped_ptr(new AnimationEventsVector));
498 FakeLayerAnimationValueObserver dummy_impl; 498 FakeLayerAnimationValueObserver dummy_impl;
499 scoped_refptr<LayerAnimationController> controller_impl( 499 scoped_refptr<LayerAnimationController> controller_impl(
(...skipping 19 matching lines...) Expand all
519 scoped_ptr<Animation> animation(Animation::Create( 519 scoped_ptr<Animation> animation(Animation::Create(
520 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Transform)); 520 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Transform));
521 animation->set_is_impl_only(true); 521 animation->set_is_impl_only(true);
522 controller_impl->AddAnimation(animation.Pass()); 522 controller_impl->AddAnimation(animation.Pass());
523 523
524 // Run animation. 524 // Run animation.
525 controller_impl->Animate(kInitialTickTime); 525 controller_impl->Animate(kInitialTickTime);
526 controller_impl->UpdateState(true, events.get()); 526 controller_impl->UpdateState(true, events.get());
527 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 527 EXPECT_TRUE(controller_impl->HasActiveAnimation());
528 EXPECT_EQ(gfx::Transform(), dummy_impl.transform()); 528 EXPECT_EQ(gfx::Transform(), dummy_impl.transform());
529 EXPECT_EQ(2u, events->size()); 529 EXPECT_EQ(1u, events->size());
530 const AnimationEvent* start_transform_event = 530 const AnimationEvent* start_transform_event =
531 GetMostRecentPropertyUpdateEvent(events.get()); 531 GetMostRecentPropertyUpdateEvent(events.get());
532 ASSERT_TRUE(start_transform_event); 532 ASSERT_TRUE(start_transform_event);
533 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); 533 EXPECT_EQ(gfx::Transform(), start_transform_event->transform);
534 EXPECT_TRUE(start_transform_event->is_impl_only); 534 EXPECT_TRUE(start_transform_event->is_impl_only);
535 535
536 gfx::Transform expected_transform; 536 gfx::Transform expected_transform;
537 expected_transform.Translate(delta_x, delta_y); 537 expected_transform.Translate(delta_x, delta_y);
538 538
539 controller_impl->Animate(kInitialTickTime + 539 controller_impl->Animate(kInitialTickTime +
540 TimeDelta::FromMilliseconds(1000)); 540 TimeDelta::FromMilliseconds(1000));
541 controller_impl->UpdateState(true, events.get()); 541 controller_impl->UpdateState(true, events.get());
542 EXPECT_EQ(expected_transform, dummy_impl.transform()); 542 EXPECT_EQ(expected_transform, dummy_impl.transform());
543 EXPECT_FALSE(controller_impl->HasActiveAnimation()); 543 EXPECT_FALSE(controller_impl->HasActiveAnimation());
544 EXPECT_EQ(4u, events->size()); 544 EXPECT_EQ(2u, events->size());
545 const AnimationEvent* end_transform_event = 545 const AnimationEvent* end_transform_event =
546 GetMostRecentPropertyUpdateEvent(events.get()); 546 GetMostRecentPropertyUpdateEvent(events.get());
547 EXPECT_EQ(expected_transform, end_transform_event->transform); 547 EXPECT_EQ(expected_transform, end_transform_event->transform);
548 EXPECT_TRUE(end_transform_event->is_impl_only); 548 EXPECT_TRUE(end_transform_event->is_impl_only);
549 } 549 }
550 550
551 TEST(LayerAnimationControllerTest, FilterTransition) { 551 TEST(LayerAnimationControllerTest, FilterTransition) {
552 scoped_ptr<AnimationEventsVector> events( 552 scoped_ptr<AnimationEventsVector> events(
553 make_scoped_ptr(new AnimationEventsVector)); 553 make_scoped_ptr(new AnimationEventsVector));
554 FakeLayerAnimationValueObserver dummy; 554 FakeLayerAnimationValueObserver dummy;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 scoped_ptr<Animation> animation(Animation::Create( 620 scoped_ptr<Animation> animation(Animation::Create(
621 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Filter)); 621 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Filter));
622 animation->set_is_impl_only(true); 622 animation->set_is_impl_only(true);
623 controller_impl->AddAnimation(animation.Pass()); 623 controller_impl->AddAnimation(animation.Pass());
624 624
625 // Run animation. 625 // Run animation.
626 controller_impl->Animate(kInitialTickTime); 626 controller_impl->Animate(kInitialTickTime);
627 controller_impl->UpdateState(true, events.get()); 627 controller_impl->UpdateState(true, events.get());
628 EXPECT_TRUE(controller_impl->HasActiveAnimation()); 628 EXPECT_TRUE(controller_impl->HasActiveAnimation());
629 EXPECT_EQ(start_filters, dummy_impl.filters()); 629 EXPECT_EQ(start_filters, dummy_impl.filters());
630 EXPECT_EQ(2u, events->size()); 630 EXPECT_EQ(1u, events->size());
631 const AnimationEvent* start_filter_event = 631 const AnimationEvent* start_filter_event =
632 GetMostRecentPropertyUpdateEvent(events.get()); 632 GetMostRecentPropertyUpdateEvent(events.get());
633 EXPECT_TRUE(start_filter_event); 633 EXPECT_TRUE(start_filter_event);
634 EXPECT_EQ(start_filters, start_filter_event->filters); 634 EXPECT_EQ(start_filters, start_filter_event->filters);
635 EXPECT_TRUE(start_filter_event->is_impl_only); 635 EXPECT_TRUE(start_filter_event->is_impl_only);
636 636
637 controller_impl->Animate(kInitialTickTime + 637 controller_impl->Animate(kInitialTickTime +
638 TimeDelta::FromMilliseconds(1000)); 638 TimeDelta::FromMilliseconds(1000));
639 controller_impl->UpdateState(true, events.get()); 639 controller_impl->UpdateState(true, events.get());
640 EXPECT_EQ(end_filters, dummy_impl.filters()); 640 EXPECT_EQ(end_filters, dummy_impl.filters());
641 EXPECT_FALSE(controller_impl->HasActiveAnimation()); 641 EXPECT_FALSE(controller_impl->HasActiveAnimation());
642 EXPECT_EQ(4u, events->size()); 642 EXPECT_EQ(2u, events->size());
643 const AnimationEvent* end_filter_event = 643 const AnimationEvent* end_filter_event =
644 GetMostRecentPropertyUpdateEvent(events.get()); 644 GetMostRecentPropertyUpdateEvent(events.get());
645 EXPECT_TRUE(end_filter_event); 645 EXPECT_TRUE(end_filter_event);
646 EXPECT_EQ(end_filters, end_filter_event->filters); 646 EXPECT_EQ(end_filters, end_filter_event->filters);
647 EXPECT_TRUE(end_filter_event->is_impl_only); 647 EXPECT_TRUE(end_filter_event->is_impl_only);
648 } 648 }
649 649
650 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) { 650 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) {
651 FakeLayerAnimationValueObserver dummy_impl; 651 FakeLayerAnimationValueObserver dummy_impl;
652 FakeLayerAnimationValueProvider dummy_provider_impl; 652 FakeLayerAnimationValueProvider dummy_provider_impl;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 bool started() { return started_; } 880 bool started() { return started_; }
881 881
882 bool finished() { return finished_; } 882 bool finished() { return finished_; }
883 883
884 private: 884 private:
885 bool started_; 885 bool started_;
886 bool finished_; 886 bool finished_;
887 }; 887 };
888 888
889 // Tests that impl-only animations lead to start and finished notifications 889 // Tests that impl-only animations lead to start and finished notifications
890 // being sent to the main thread controller's animation delegate. 890 // on the impl thread controller's animation delegate.
891 TEST(LayerAnimationControllerTest, 891 TEST(LayerAnimationControllerTest,
892 NotificationsForImplOnlyAnimationsAreSentToMainThreadDelegate) { 892 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) {
893 FakeLayerAnimationValueObserver dummy_impl; 893 FakeLayerAnimationValueObserver dummy_impl;
894 scoped_refptr<LayerAnimationController> controller_impl( 894 scoped_refptr<LayerAnimationController> controller_impl(
895 LayerAnimationController::Create(0)); 895 LayerAnimationController::Create(0));
896 controller_impl->AddValueObserver(&dummy_impl); 896 controller_impl->AddValueObserver(&dummy_impl);
897 scoped_ptr<AnimationEventsVector> events( 897 scoped_ptr<AnimationEventsVector> events(
898 make_scoped_ptr(new AnimationEventsVector)); 898 make_scoped_ptr(new AnimationEventsVector));
899 FakeLayerAnimationValueObserver dummy;
900 scoped_refptr<LayerAnimationController> controller(
901 LayerAnimationController::Create(0));
902 controller->AddValueObserver(&dummy);
903 FakeAnimationDelegate delegate; 899 FakeAnimationDelegate delegate;
904 controller->set_layer_animation_delegate(&delegate); 900 controller_impl->set_layer_animation_delegate(&delegate);
905 901
906 scoped_ptr<Animation> to_add(CreateAnimation( 902 scoped_ptr<Animation> to_add(CreateAnimation(
907 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 903 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
908 1, 904 1,
909 Animation::Opacity)); 905 Animation::Opacity));
910 to_add->set_is_impl_only(true); 906 to_add->set_is_impl_only(true);
911 controller_impl->AddAnimation(to_add.Pass()); 907 controller_impl->AddAnimation(to_add.Pass());
912 908
909 EXPECT_FALSE(delegate.started());
910 EXPECT_FALSE(delegate.finished());
911
913 controller_impl->Animate(kInitialTickTime); 912 controller_impl->Animate(kInitialTickTime);
914 controller_impl->UpdateState(true, events.get()); 913 controller_impl->UpdateState(true, events.get());
915 914
916 // We should receive 2 events (a started notification and a property update).
917 EXPECT_EQ(2u, events->size());
918 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
919 EXPECT_TRUE((*events)[0].is_impl_only);
920 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type);
921 EXPECT_TRUE((*events)[1].is_impl_only);
922
923 // Passing on the start event to the main thread controller should cause the
924 // delegate to get notified.
925 EXPECT_FALSE(delegate.started());
926 controller->NotifyAnimationStarted((*events)[0]);
927 EXPECT_TRUE(delegate.started()); 915 EXPECT_TRUE(delegate.started());
916 EXPECT_FALSE(delegate.finished());
928 917
929 events.reset(new AnimationEventsVector); 918 events.reset(new AnimationEventsVector);
930 controller_impl->Animate(kInitialTickTime + 919 controller_impl->Animate(kInitialTickTime +
931 TimeDelta::FromMilliseconds(1000)); 920 TimeDelta::FromMilliseconds(1000));
932 controller_impl->UpdateState(true, events.get()); 921 controller_impl->UpdateState(true, events.get());
933 922
934 // We should receive 2 events (a finished notification and a property update). 923 EXPECT_TRUE(delegate.started());
935 EXPECT_EQ(2u, events->size());
936 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
937 EXPECT_TRUE((*events)[0].is_impl_only);
938 EXPECT_EQ(AnimationEvent::PropertyUpdate, (*events)[1].type);
939 EXPECT_TRUE((*events)[1].is_impl_only);
940
941 // Passing on the finished event to the main thread controller should cause
942 // the delegate to get notified.
943 EXPECT_FALSE(delegate.finished());
944 controller->NotifyAnimationFinished((*events)[0]);
945 EXPECT_TRUE(delegate.finished()); 924 EXPECT_TRUE(delegate.finished());
946 } 925 }
947 926
948 // Tests animations that are waiting for a synchronized start time do not 927 // Tests animations that are waiting for a synchronized start time do not
949 // finish. 928 // finish.
950 TEST(LayerAnimationControllerTest, 929 TEST(LayerAnimationControllerTest,
951 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { 930 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) {
952 scoped_ptr<AnimationEventsVector> events( 931 scoped_ptr<AnimationEventsVector> events(
953 make_scoped_ptr(new AnimationEventsVector)); 932 make_scoped_ptr(new AnimationEventsVector));
954 FakeLayerAnimationValueObserver dummy; 933 FakeLayerAnimationValueObserver dummy;
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2249 // been ticked at the new animation's starting point. 2228 // been ticked at the new animation's starting point.
2250 EXPECT_EQ(Animation::Running, 2229 EXPECT_EQ(Animation::Running,
2251 controller_impl->GetAnimation(second_animation_group_id, 2230 controller_impl->GetAnimation(second_animation_group_id,
2252 Animation::Opacity)->run_state()); 2231 Animation::Opacity)->run_state());
2253 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); 2232 EXPECT_EQ(1.f, pending_dummy_impl.opacity());
2254 EXPECT_EQ(1.f, dummy_impl.opacity()); 2233 EXPECT_EQ(1.f, dummy_impl.opacity());
2255 } 2234 }
2256 2235
2257 } // namespace 2236 } // namespace
2258 } // namespace cc 2237 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/input/input_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698