diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 03:11:47 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 03:11:47 +0000 |
commit | 9034a2852384f40f23305e108ee7f23ab5dc7ff3 (patch) | |
tree | 5b2e6a7e049b39227168cbc1f2e90104897f7439 | |
parent | 71a04b9c149ecbbf096bf651f03c4803860f8334 (diff) | |
download | chromium_src-9034a2852384f40f23305e108ee7f23ab5dc7ff3.zip chromium_src-9034a2852384f40f23305e108ee7f23ab5dc7ff3.tar.gz chromium_src-9034a2852384f40f23305e108ee7f23ab5dc7ff3.tar.bz2 |
compositor: Tick the UI animations from cc, instead of from timer callbacks.
Update the animations in the UI in response to the animation step in the compositor,
instead of from a timer callback. This should make it more difficult for rogue UI
animations to negatively impact the system too much.
BUG=371071
R=ajuma@chromium.org, sky@chromium.org
Review URL: https://codereview.chromium.org/291843012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274988 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 658 insertions, 192 deletions
diff --git a/ash/desktop_background/desktop_background_controller_unittest.cc b/ash/desktop_background/desktop_background_controller_unittest.cc index 4e87be6..609ea14 100644 --- a/ash/desktop_background/desktop_background_controller_unittest.cc +++ b/ash/desktop_background/desktop_background_controller_unittest.cc @@ -53,13 +53,13 @@ void RunAnimationForWidget(views::Widget* widget) { ui::Layer* layer = widget->GetNativeView()->layer(); ui::LayerAnimatorTestController controller(layer->GetAnimator()); - gfx::AnimationContainerElement* element = layer->GetAnimator(); // Multiple steps are required to complete complex animations. // TODO(vollick): This should not be necessary. crbug.com/154017 while (controller.animator()->is_animating()) { controller.StartThreadedAnimationsIfNeeded(); base::TimeTicks step_time = controller.animator()->last_step_time(); - element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); + layer->GetAnimator()->Step(step_time + + base::TimeDelta::FromMilliseconds(1000)); } } diff --git a/ash/shelf/shelf_layout_manager_unittest.cc b/ash/shelf/shelf_layout_manager_unittest.cc index 3a38fc0..dd5a35d 100644 --- a/ash/shelf/shelf_layout_manager_unittest.cc +++ b/ash/shelf/shelf_layout_manager_unittest.cc @@ -34,7 +34,6 @@ #include "ui/compositor/layer_animator.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/events/gestures/gesture_configuration.h" -#include "ui/gfx/animation/animation_container_element.h" #include "ui/gfx/display.h" #include "ui/gfx/screen.h" #include "ui/views/controls/label.h" @@ -50,10 +49,8 @@ namespace ash { namespace { void StepWidgetLayerAnimatorToEnd(views::Widget* widget) { - gfx::AnimationContainerElement* element = - static_cast<gfx::AnimationContainerElement*>( - widget->GetNativeView()->layer()->GetAnimator()); - element->Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); + widget->GetNativeView()->layer()->GetAnimator()->Step( + base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); } ShelfWidget* GetShelfWidget() { diff --git a/ash/wm/window_animations_unittest.cc b/ash/wm/window_animations_unittest.cc index 7df1c49..0e1a4d8 100644 --- a/ash/wm/window_animations_unittest.cc +++ b/ash/wm/window_animations_unittest.cc @@ -16,7 +16,6 @@ #include "ui/compositor/layer_animator.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/compositor/scoped_layer_animation_settings.h" -#include "ui/gfx/animation/animation_container_element.h" using aura::Window; using ui::Layer; @@ -89,11 +88,8 @@ TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { EXPECT_TRUE(window->layer()->visible()); // Stays shown. - gfx::AnimationContainerElement* element = - static_cast<gfx::AnimationContainerElement*>( - window->layer()->GetAnimator()); - element->Step(base::TimeTicks::Now() + - base::TimeDelta::FromSeconds(5)); + window->layer()->GetAnimator()->Step(base::TimeTicks::Now() + + base::TimeDelta::FromSeconds(5)); EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness()); EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale()); EXPECT_TRUE(window->layer()->visible()); @@ -141,10 +137,10 @@ TEST_F(WindowAnimationsTest, CrossFadeToBounds) { EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); // Run the animations to completion. - static_cast<gfx::AnimationContainerElement*>(old_layer->GetAnimator())->Step( - base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); - static_cast<gfx::AnimationContainerElement*>(window->layer()->GetAnimator())-> - Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); + old_layer->GetAnimator()->Step(base::TimeTicks::Now() + + base::TimeDelta::FromSeconds(1)); + window->layer()->GetAnimator()->Step(base::TimeTicks::Now() + + base::TimeDelta::FromSeconds(1)); // Cross fade to a smaller size, as in a restore animation. old_layer = window->layer(); @@ -163,10 +159,10 @@ TEST_F(WindowAnimationsTest, CrossFadeToBounds) { EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); - static_cast<gfx::AnimationContainerElement*>(old_layer->GetAnimator())->Step( - base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); - static_cast<gfx::AnimationContainerElement*>(window->layer()->GetAnimator())-> - Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); + old_layer->GetAnimator()->Step(base::TimeTicks::Now() + + base::TimeDelta::FromSeconds(1)); + window->layer()->GetAnimator()->Step(base::TimeTicks::Now() + + base::TimeDelta::FromSeconds(1)); } } // namespace wm diff --git a/content/browser/web_contents/aura/window_slider_unittest.cc b/content/browser/web_contents/aura/window_slider_unittest.cc index 2ad69c2..4a2d0a5 100644 --- a/content/browser/web_contents/aura/window_slider_unittest.cc +++ b/content/browser/web_contents/aura/window_slider_unittest.cc @@ -341,7 +341,6 @@ TEST_F(WindowSliderTest, WindowSlideInterruptedThenContinues) { ui::ScopedAnimationDurationScaleMode normal_duration_( ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); ui::LayerAnimator* animator = window->layer()->GetAnimator(); - gfx::AnimationContainerElement* element = animator; animator->set_disable_timer_for_test(true); ui::LayerAnimatorTestController test_controller(animator); @@ -428,7 +427,7 @@ TEST_F(WindowSliderTest, WindowSlideInterruptedThenContinues) { ui::ScopedLayerAnimationSettings settings(animator); base::TimeDelta duration = settings.GetTransitionDuration(); test_controller.StartThreadedAnimationsIfNeeded(); - element->Step(gfx::FrameTime::Now() + duration); + animator->Step(gfx::FrameTime::Now() + duration); EXPECT_TRUE(slider_delegate.slide_completed()); EXPECT_FALSE(slider_delegate.slider_destroyed()); @@ -596,7 +595,6 @@ TEST_F(WindowSliderTest, SwipeDuringSwipeAnimation) { ui::ScopedAnimationDurationScaleMode normal_duration_( ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); ui::LayerAnimator* animator = window->layer()->GetAnimator(); - gfx::AnimationContainerElement* element = animator; animator->set_disable_timer_for_test(true); ui::LayerAnimatorTestController test_controller(animator); @@ -619,7 +617,7 @@ TEST_F(WindowSliderTest, SwipeDuringSwipeAnimation) { test_controller.StartThreadedAnimationsIfNeeded(); base::TimeTicks start_time1 = gfx::FrameTime::Now(); - element->Step(start_time1 + duration/2); + animator->Step(start_time1 + duration / 2); EXPECT_FALSE(slider_delegate.slide_completed()); slider_delegate.Reset(); // Generate another horizontal swipe while the animation from the previous @@ -640,7 +638,7 @@ TEST_F(WindowSliderTest, SwipeDuringSwipeAnimation) { test_controller.StartThreadedAnimationsIfNeeded(); base::TimeTicks start_time2 = gfx::FrameTime::Now(); slider_delegate.Reset(); - element->Step(start_time2 + duration); + animator->Step(start_time2 + duration); // The animation for the second slide should now be completed. EXPECT_TRUE(slider_delegate.slide_completed()); slider_delegate.Reset(); diff --git a/ui/aura/window.cc b/ui/aura/window.cc index b1e95c3..22262d0 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -217,8 +217,11 @@ Window::Window(WindowDelegate* delegate) Window::~Window() { // |layer()| can be NULL during tests, or if this Window is layerless. - if (layer()) + if (layer()) { + if (layer()->owner() == this) + layer()->CompleteAllAnimations(); layer()->SuppressPaint(); + } // Let the delegate know we're in the processing of destroying. if (delegate_) diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index add99d4..37cf5ed 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -31,6 +31,7 @@ #include "ui/aura/window_tree_host.h" #include "ui/base/hit_test.h" #include "ui/compositor/layer.h" +#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/test/test_layers.h" @@ -1625,7 +1626,7 @@ TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { EXPECT_FALSE(!w1->layer()); w1->layer()->GetAnimator()->set_disable_timer_for_test(true); - gfx::AnimationContainerElement* element = w1->layer()->GetAnimator(); + ui::LayerAnimator* animator = w1->layer()->GetAnimator(); EXPECT_EQ("0,0 100x100", w1->bounds().ToString()); EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString()); @@ -1655,7 +1656,7 @@ TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { base::TimeTicks start_time = w1->layer()->GetAnimator()->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_EQ("0,0 100x100", w1->bounds().ToString()); } @@ -2374,8 +2375,8 @@ TEST_F(WindowTest, DelegateNotifiedAsBoundsChange) { // Animate to the end, which should notify of the change. base::TimeTicks start_time = window->layer()->GetAnimator()->last_step_time(); - gfx::AnimationContainerElement* element = window->layer()->GetAnimator(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + ui::LayerAnimator* animator = window->layer()->GetAnimator(); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(delegate.bounds_changed()); EXPECT_NE("0,0 100x100", window->bounds().ToString()); } @@ -2416,8 +2417,8 @@ TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) { // Animate to the end: will *not* notify of the change since we are hidden. base::TimeTicks start_time = window->layer()->GetAnimator()->last_step_time(); - gfx::AnimationContainerElement* element = window->layer()->GetAnimator(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + ui::LayerAnimator* animator = window->layer()->GetAnimator(); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); // No bounds changed notification at the end of animation since layer // delegate is NULL. @@ -3347,5 +3348,95 @@ TEST_F(WindowTest, StackChildAtLayerless) { } } +namespace { + +class TestLayerAnimationObserver : public ui::LayerAnimationObserver { + public: + TestLayerAnimationObserver() + : animation_completed_(false), + animation_aborted_(false) {} + virtual ~TestLayerAnimationObserver() {} + + bool animation_completed() const { return animation_completed_; } + bool animation_aborted() const { return animation_aborted_; } + + void Reset() { + animation_completed_ = false; + animation_aborted_ = false; + } + + private: + // ui::LayerAnimationObserver: + virtual void OnLayerAnimationEnded( + ui::LayerAnimationSequence* sequence) OVERRIDE { + animation_completed_ = true; + } + + virtual void OnLayerAnimationAborted( + ui::LayerAnimationSequence* sequence) OVERRIDE { + animation_aborted_ = true; + } + + virtual void OnLayerAnimationScheduled( + ui::LayerAnimationSequence* sequence) OVERRIDE { + } + + bool animation_completed_; + bool animation_aborted_; + + DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationObserver); +}; + +} + +TEST_F(WindowTest, WindowDestroyCompletesAnimations) { + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); + scoped_refptr<ui::LayerAnimator> animator = + ui::LayerAnimator::CreateImplicitAnimator(); + TestLayerAnimationObserver observer; + animator->AddObserver(&observer); + // Make sure destroying a Window completes the animation. + { + scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window())); + window->layer()->SetAnimator(animator); + + gfx::Transform transform; + transform.Scale(0.5f, 0.5f); + window->SetTransform(transform); + + EXPECT_TRUE(animator->is_animating()); + EXPECT_FALSE(observer.animation_completed()); + } + EXPECT_TRUE(animator); + EXPECT_FALSE(animator->is_animating()); + EXPECT_TRUE(observer.animation_completed()); + EXPECT_FALSE(observer.animation_aborted()); + animator->RemoveObserver(&observer); + observer.Reset(); + + animator = ui::LayerAnimator::CreateImplicitAnimator(); + animator->AddObserver(&observer); + ui::Layer layer; + layer.SetAnimator(animator); + { + scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window())); + window->layer()->Add(&layer); + + gfx::Transform transform; + transform.Scale(0.5f, 0.5f); + layer.SetTransform(transform); + + EXPECT_TRUE(animator->is_animating()); + EXPECT_FALSE(observer.animation_completed()); + } + + EXPECT_TRUE(animator); + EXPECT_FALSE(animator->is_animating()); + EXPECT_TRUE(observer.animation_completed()); + EXPECT_FALSE(observer.animation_aborted()); + animator->RemoveObserver(&observer); +} + } // namespace test } // namespace aura diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc index 325425c..b511e6d 100644 --- a/ui/compositor/compositor.cc +++ b/ui/compositor/compositor.cc @@ -26,6 +26,7 @@ #include "ui/compositor/compositor_vsync_manager.h" #include "ui/compositor/dip_util.h" #include "ui/compositor/layer.h" +#include "ui/compositor/layer_animator_collection.h" #include "ui/gfx/frame_time.h" #include "ui/gl/gl_context.h" #include "ui/gl/gl_switches.h" @@ -84,6 +85,7 @@ Compositor::Compositor(gfx::AcceleratedWidget widget, waiting_on_compositing_end_(false), draw_on_compositing_end_(false), swap_state_(SWAP_NONE), + layer_animator_collection_(this), schedule_draw_factory_(this) { root_web_layer_ = cc::Layer::Create(); root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); @@ -217,8 +219,10 @@ void Compositor::Draw() { if (!IsLocked()) { // TODO(nduca): Temporary while compositor calls // compositeImmediately() directly. + base::TimeTicks now = gfx::FrameTime::Now(); + Animate(now); Layout(); - host_->Composite(gfx::FrameTime::Now()); + host_->Composite(now); } if (swap_state_ == SWAP_NONE) NotifyEnd(); @@ -278,6 +282,12 @@ bool Compositor::HasObserver(CompositorObserver* observer) { return observer_list_.HasObserver(observer); } +void Compositor::Animate(base::TimeTicks frame_begin_time) { + layer_animator_collection_.Progress(frame_begin_time); + if (layer_animator_collection_.HasActiveAnimators()) + host_->SetNeedsAnimate(); +} + void Compositor::Layout() { // We're sending damage that will be addressed during this composite // cycle, so we don't need to schedule another composite to address it. @@ -343,6 +353,10 @@ void Compositor::DidAbortSwapBuffers() { OnCompositingAborted(this)); } +void Compositor::ScheduleAnimationForLayerCollection() { + host_->SetNeedsAnimate(); +} + const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { return host_->debug_state(); } diff --git a/ui/compositor/compositor.gyp b/ui/compositor/compositor.gyp index e242dce..9b19e60 100644 --- a/ui/compositor/compositor.gyp +++ b/ui/compositor/compositor.gyp @@ -49,6 +49,8 @@ 'layer_animation_sequence.h', 'layer_animator.cc', 'layer_animator.h', + 'layer_animator_collection.cc', + 'layer_animator_collection.h', 'layer_delegate.h', 'layer_owner.cc', 'layer_owner.h', diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h index e0606c1..79bf691 100644 --- a/ui/compositor/compositor.h +++ b/ui/compositor/compositor.h @@ -17,6 +17,7 @@ #include "third_party/skia/include/core/SkColor.h" #include "ui/compositor/compositor_export.h" #include "ui/compositor/compositor_observer.h" +#include "ui/compositor/layer_animator_collection.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/size.h" #include "ui/gfx/vector2d.h" @@ -126,7 +127,8 @@ class COMPOSITOR_EXPORT CompositorLock // view hierarchy. class COMPOSITOR_EXPORT Compositor : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), - NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { + NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient), + NON_EXPORTED_BASE(public LayerAnimatorCollectionDelegate) { public: Compositor(gfx::AcceleratedWidget widget, ui::ContextFactory* context_factory); @@ -213,7 +215,7 @@ class COMPOSITOR_EXPORT Compositor // LayerTreeHostClient implementation. virtual void WillBeginMainFrame(int frame_id) OVERRIDE {} virtual void DidBeginMainFrame() OVERRIDE {} - virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE {} + virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE; virtual void Layout() OVERRIDE; virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, float page_scale) OVERRIDE {} @@ -231,6 +233,9 @@ class COMPOSITOR_EXPORT Compositor virtual void DidPostSwapBuffers() OVERRIDE; virtual void DidAbortSwapBuffers() OVERRIDE; + // LayerAnimatorCollectionDelegate implementation. + virtual void ScheduleAnimationForLayerCollection() OVERRIDE; + int last_started_frame() { return last_started_frame_; } int last_ended_frame() { return last_ended_frame_; } @@ -239,6 +244,10 @@ class COMPOSITOR_EXPORT Compositor const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); + LayerAnimatorCollection* layer_animator_collection() { + return &layer_animator_collection_; + } + private: friend class base::RefCounted<Compositor>; friend class CompositorLock; @@ -289,6 +298,8 @@ class COMPOSITOR_EXPORT Compositor enum SwapState { SWAP_NONE, SWAP_POSTED, SWAP_COMPLETED }; SwapState swap_state_; + LayerAnimatorCollection layer_animator_collection_; + base::WeakPtrFactory<Compositor> schedule_draw_factory_; DISALLOW_COPY_AND_ASSIGN(Compositor); diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc index ca3ff28..d57cc3b 100644 --- a/ui/compositor/layer.cc +++ b/ui/compositor/layer.cc @@ -142,10 +142,15 @@ void Layer::SetCompositor(Compositor* compositor) { DCHECK(!compositor || !compositor_); DCHECK(!compositor || compositor->root_layer() == this); DCHECK(!parent_); + if (compositor_) { + RemoveAnimatorsInTreeFromCollection( + compositor_->layer_animator_collection()); + } compositor_ = compositor; if (compositor) { OnDeviceScaleFactorChanged(compositor->device_scale_factor()); SendPendingThreadedAnimations(); + AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection()); } } @@ -159,15 +164,21 @@ void Layer::Add(Layer* child) { child->OnDeviceScaleFactorChanged(device_scale_factor_); if (GetCompositor()) child->SendPendingThreadedAnimations(); + LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); + if (collection) + child->AddAnimatorsInTreeToCollection(collection); } void Layer::Remove(Layer* child) { // Current bounds are used to calculate offsets when layers are reparented. // Stop (and complete) an ongoing animation to update the bounds immediately. - if (child->GetAnimator()) { - child->GetAnimator()->StopAnimatingProperty( - ui::LayerAnimationElement::BOUNDS); - } + LayerAnimator* child_animator = child->animator_; + if (child_animator) + child_animator->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS); + LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); + if (collection) + child->RemoveAnimatorsInTreeFromCollection(collection); + std::vector<Layer*>::iterator i = std::find(children_.begin(), children_.end(), child); DCHECK(i != children_.end()); @@ -605,6 +616,13 @@ void Layer::SendDamagedRects() { children_[i]->SendDamagedRects(); } +void Layer::CompleteAllAnimations() { + std::vector<scoped_refptr<LayerAnimator> > animators; + CollectAnimators(&animators); + std::for_each(animators.begin(), animators.end(), + std::mem_fun(&LayerAnimator::StopAnimating)); +} + void Layer::SuppressPaint() { if (!delegate_) return; @@ -689,6 +707,15 @@ void Layer::OnAnimationStarted(const cc::AnimationEvent& event) { animator_->OnThreadedAnimationStarted(event); } +void Layer::CollectAnimators( + std::vector<scoped_refptr<LayerAnimator> >* animators) { + if (IsAnimating()) + animators->push_back(animator_); + std::for_each(children_.begin(), children_.end(), + std::bind2nd(std::mem_fun(&Layer::CollectAnimators), + animators)); +} + void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { DCHECK_NE(child, other); DCHECK_EQ(this, child->parent()); @@ -873,6 +900,11 @@ void Layer::RemoveThreadedAnimation(int animation_id) { pending_threaded_animations_.end()); } +LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() { + Compositor* compositor = GetCompositor(); + return compositor ? compositor->layer_animator_collection() : NULL; +} + void Layer::SendPendingThreadedAnimations() { for (cc::ScopedPtrVector<cc::Animation>::iterator it = pending_threaded_animations_.begin(); @@ -930,4 +962,32 @@ void Layer::RecomputePosition() { cc_layer_->SetPosition(gfx::PointF(bounds_.x(), bounds_.y())); } +void Layer::AddAnimatorsInTreeToCollection( + LayerAnimatorCollection* collection) { + DCHECK(collection); + if (IsAnimating()) + animator_->AddToCollection(collection); + std::for_each( + children_.begin(), + children_.end(), + std::bind2nd(std::mem_fun(&Layer::AddAnimatorsInTreeToCollection), + collection)); +} + +void Layer::RemoveAnimatorsInTreeFromCollection( + LayerAnimatorCollection* collection) { + DCHECK(collection); + if (IsAnimating()) + animator_->RemoveFromCollection(collection); + std::for_each( + children_.begin(), + children_.end(), + std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), + collection)); +} + +bool Layer::IsAnimating() const { + return animator_ && animator_->is_animating(); +} + } // namespace ui diff --git a/ui/compositor/layer.h b/ui/compositor/layer.h index 2b0d913..069f167 100644 --- a/ui/compositor/layer.h +++ b/ui/compositor/layer.h @@ -287,6 +287,8 @@ class COMPOSITOR_EXPORT Layer const SkRegion& damaged_region() const { return damaged_region_; } + void CompleteAllAnimations(); + // Suppresses painting the content by disconnecting |delegate_|. void SuppressPaint(); @@ -338,6 +340,8 @@ class COMPOSITOR_EXPORT Layer private: friend class LayerOwner; + void CollectAnimators(std::vector<scoped_refptr<LayerAnimator> >* animators); + // Stacks |child| above or below |other|. Helper method for StackAbove() and // StackBelow(). void StackRelativeTo(Layer* child, Layer* other, bool above); @@ -366,6 +370,7 @@ class COMPOSITOR_EXPORT Layer virtual void AddThreadedAnimation( scoped_ptr<cc::Animation> animation) OVERRIDE; virtual void RemoveThreadedAnimation(int animation_id) OVERRIDE; + virtual LayerAnimatorCollection* GetLayerAnimatorCollection() OVERRIDE; // Creates a corresponding composited layer for |type_|. void CreateWebLayer(); @@ -389,6 +394,12 @@ class COMPOSITOR_EXPORT Layer // be called once we have been added to a tree. void SendPendingThreadedAnimations(); + void AddAnimatorsInTreeToCollection(LayerAnimatorCollection* collection); + void RemoveAnimatorsInTreeFromCollection(LayerAnimatorCollection* collection); + + // Returns whether the layer has an animating LayerAnimator. + bool IsAnimating() const; + const LayerType type_; Compositor* compositor_; diff --git a/ui/compositor/layer_animation_delegate.h b/ui/compositor/layer_animation_delegate.h index 1d57c71..2f38d54 100644 --- a/ui/compositor/layer_animation_delegate.h +++ b/ui/compositor/layer_animation_delegate.h @@ -14,6 +14,8 @@ namespace ui { +class LayerAnimatorCollection; + // Layer animations interact with the layers using this interface. class COMPOSITOR_EXPORT LayerAnimationDelegate { public: @@ -35,6 +37,7 @@ class COMPOSITOR_EXPORT LayerAnimationDelegate { virtual float GetDeviceScaleFactor() const = 0; virtual void AddThreadedAnimation(scoped_ptr<cc::Animation> animation) = 0; virtual void RemoveThreadedAnimation(int animation_id) = 0; + virtual LayerAnimatorCollection* GetLayerAnimatorCollection() = 0; protected: virtual ~LayerAnimationDelegate() {} diff --git a/ui/compositor/layer_animator.cc b/ui/compositor/layer_animator.cc index ce2b0ff..39585a7 100644 --- a/ui/compositor/layer_animator.cc +++ b/ui/compositor/layer_animator.cc @@ -14,7 +14,7 @@ #include "ui/compositor/layer_animation_delegate.h" #include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_sequence.h" -#include "ui/gfx/animation/animation_container.h" +#include "ui/compositor/layer_animator_collection.h" #include "ui/gfx/frame_time.h" #define SAFE_INVOKE_VOID(function, running_anim, ...) \ @@ -31,22 +31,9 @@ namespace ui { -class LayerAnimator; - namespace { const int kDefaultTransitionDurationMs = 120; -const int kTimerIntervalMs = 10; - -// Returns the AnimationContainer we're added to. -gfx::AnimationContainer* GetAnimationContainer() { - static gfx::AnimationContainer* container = NULL; - if (!container) { - container = new gfx::AnimationContainer(); - container->AddRef(); - } - return container; -} } // namespace @@ -124,7 +111,17 @@ base::TimeDelta LayerAnimator::GetTransitionDuration() const { } void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { + if (delegate_ && is_started_) { + LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); + if (collection) + collection->StopAnimator(this); + } delegate_ = delegate; + if (delegate_ && is_started_) { + LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); + if (collection) + collection->StartAnimator(this); + } } void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { @@ -181,8 +178,9 @@ void LayerAnimator::StartTogether( adding_animations_ = true; if (!is_animating()) { - if (GetAnimationContainer()->is_running()) - last_step_time_ = GetAnimationContainer()->last_tick_time(); + LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); + if (collection && collection->HasActiveAnimators()) + last_step_time_ = collection->last_tick_time(); else last_step_time_ = gfx::FrameTime::Now(); } @@ -343,6 +341,20 @@ void LayerAnimator::OnThreadedAnimationStarted( } } +void LayerAnimator::AddToCollection(LayerAnimatorCollection* collection) { + if (is_animating() && !is_started_) { + collection->StartAnimator(this); + is_started_ = true; + } +} + +void LayerAnimator::RemoveFromCollection(LayerAnimatorCollection* collection) { + if (is_animating() && is_started_) { + collection->StopAnimator(this); + is_started_ = false; + } +} + // LayerAnimator protected ----------------------------------------------------- void LayerAnimator::ProgressAnimation(LayerAnimationSequence* sequence, @@ -395,14 +407,6 @@ void LayerAnimator::Step(base::TimeTicks now) { } } -void LayerAnimator::SetStartTime(base::TimeTicks start_time) { - // Do nothing. -} - -base::TimeDelta LayerAnimator::GetTimerInterval() const { - return base::TimeDelta::FromMilliseconds(kTimerIntervalMs); -} - void LayerAnimator::StopAnimatingInternal(bool abort) { scoped_refptr<LayerAnimator> retain(this); while (is_animating()) { @@ -431,12 +435,16 @@ void LayerAnimator::UpdateAnimationState() { return; const bool should_start = is_animating(); - if (should_start && !is_started_) - GetAnimationContainer()->Start(this); - else if (!should_start && is_started_) - GetAnimationContainer()->Stop(this); - - is_started_ = should_start; + LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); + if (collection) { + if (should_start && !is_started_) + collection->StartAnimator(this); + else if (!should_start && is_started_) + collection->StopAnimator(this); + is_started_ = should_start; + } else { + is_started_ = false; + } } LayerAnimationSequence* LayerAnimator::RemoveAnimation( @@ -753,14 +761,15 @@ bool LayerAnimator::StartSequenceImmediately(LayerAnimationSequence* sequence) { // a resolution that can be as bad as 15ms. If this causes glitches in the // animations, this can be switched to HighResNow() (animation uses Now() // internally). - // All LayerAnimators share the same AnimationContainer. Use the + // All LayerAnimators share the same LayerAnimatorCollection. Use the // last_tick_time() from there to ensure animations started during the same // event complete at the same time. base::TimeTicks start_time; + LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); if (is_animating() || adding_animations_) start_time = last_step_time_; - else if (GetAnimationContainer()->is_running()) - start_time = GetAnimationContainer()->last_tick_time(); + else if (collection && collection->HasActiveAnimators()) + start_time = collection->last_tick_time(); else start_time = gfx::FrameTime::Now(); @@ -839,6 +848,10 @@ void LayerAnimator::PurgeDeletedAnimations() { } } +LayerAnimatorCollection* LayerAnimator::GetLayerAnimatorCollection() { + return delegate_ ? delegate_->GetLayerAnimatorCollection() : NULL; +} + LayerAnimator::RunningAnimation::RunningAnimation( const base::WeakPtr<LayerAnimationSequence>& sequence) : sequence_(sequence) { diff --git a/ui/compositor/layer_animator.h b/ui/compositor/layer_animator.h index a1e0ad2..69744f8 100644 --- a/ui/compositor/layer_animator.h +++ b/ui/compositor/layer_animator.h @@ -9,13 +9,13 @@ #include <vector> #include "base/compiler_specific.h" +#include "base/gtest_prod_util.h" #include "base/memory/linked_ptr.h" #include "base/memory/ref_counted.h" #include "base/observer_list.h" #include "base/time/time.h" #include "ui/compositor/compositor_export.h" #include "ui/compositor/layer_animation_element.h" -#include "ui/gfx/animation/animation_container_element.h" #include "ui/gfx/animation/tween.h" namespace gfx { @@ -29,6 +29,7 @@ class Layer; class LayerAnimationSequence; class LayerAnimationDelegate; class LayerAnimationObserver; +class LayerAnimatorCollection; class ScopedLayerAnimationSettings; // When a property of layer needs to be changed it is set by way of @@ -40,9 +41,7 @@ class ScopedLayerAnimationSettings; // ensure that it is not disposed of until it finishes executing. It does this // by holding a reference to itself for the duration of methods for which it // must guarantee that |this| is valid. -class COMPOSITOR_EXPORT LayerAnimator - : public gfx::AnimationContainerElement, - public base::RefCounted<LayerAnimator> { +class COMPOSITOR_EXPORT LayerAnimator : public base::RefCounted<LayerAnimator> { public: enum PreemptionStrategy { IMMEDIATELY_SET_NEW_TARGET, @@ -188,6 +187,11 @@ class COMPOSITOR_EXPORT LayerAnimator } base::TimeTicks last_step_time() const { return last_step_time_; } + void Step(base::TimeTicks time_now); + + void AddToCollection(LayerAnimatorCollection* collection); + void RemoveFromCollection(LayerAnimatorCollection* collection); + protected: virtual ~LayerAnimator(); @@ -207,6 +211,9 @@ class COMPOSITOR_EXPORT LayerAnimator friend class base::RefCounted<LayerAnimator>; friend class ScopedLayerAnimationSettings; friend class LayerAnimatorTestController; + FRIEND_TEST_ALL_PREFIXES(LayerAnimatorTest, AnimatorStartedCorrectly); + FRIEND_TEST_ALL_PREFIXES(LayerAnimatorTest, + AnimatorRemovedFromCollectionWhenLayerIsDestroyed); class RunningAnimation { public: @@ -225,11 +232,6 @@ class COMPOSITOR_EXPORT LayerAnimator typedef std::vector<RunningAnimation> RunningAnimations; typedef std::deque<linked_ptr<LayerAnimationSequence> > AnimationQueue; - // Implementation of AnimationContainerElement - virtual void SetStartTime(base::TimeTicks start_time) OVERRIDE; - virtual void Step(base::TimeTicks time_now) OVERRIDE; - virtual base::TimeDelta GetTimerInterval() const OVERRIDE; - // Finishes all animations by either advancing them to their final state or by // aborting them. void StopAnimatingInternal(bool abort); @@ -307,6 +309,8 @@ class COMPOSITOR_EXPORT LayerAnimator // Cleans up any running animations that may have been deleted. void PurgeDeletedAnimations(); + LayerAnimatorCollection* GetLayerAnimatorCollection(); + // This is the queue of animations to run. AnimationQueue animation_queue_; diff --git a/ui/compositor/layer_animator_collection.cc b/ui/compositor/layer_animator_collection.cc new file mode 100644 index 0000000..12142d8 --- /dev/null +++ b/ui/compositor/layer_animator_collection.cc @@ -0,0 +1,56 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/compositor/layer_animator_collection.h" + +#include <set> + +#include "base/time/time.h" +#include "ui/compositor/layer_animator.h" +#include "ui/gfx/frame_time.h" + +namespace ui { + +LayerAnimatorCollection::LayerAnimatorCollection( + LayerAnimatorCollectionDelegate* delegate) + : delegate_(delegate), + last_tick_time_(gfx::FrameTime::Now()) { +} + +LayerAnimatorCollection::~LayerAnimatorCollection() { +} + +void LayerAnimatorCollection::StartAnimator( + scoped_refptr<LayerAnimator> animator) { + DCHECK_EQ(0U, animators_.count(animator)); + if (!animators_.size()) + last_tick_time_ = gfx::FrameTime::Now(); + animators_.insert(animator); + if (delegate_) + delegate_->ScheduleAnimationForLayerCollection(); +} + +void LayerAnimatorCollection::StopAnimator( + scoped_refptr<LayerAnimator> animator) { + DCHECK_GT(animators_.count(animator), 0U); + animators_.erase(animator); +} + +bool LayerAnimatorCollection::HasActiveAnimators() const { + return !animators_.empty(); +} + +void LayerAnimatorCollection::Progress(base::TimeTicks now) { + last_tick_time_ = now; + std::set<scoped_refptr<LayerAnimator> > list = animators_; + for (std::set<scoped_refptr<LayerAnimator> >::iterator iter = list.begin(); + iter != list.end(); + ++iter) { + // Make sure the animator is still valid. + if (animators_.count(*iter) > 0) + (*iter)->Step(now); + } +} + +} // namespace ui diff --git a/ui/compositor/layer_animator_collection.h b/ui/compositor/layer_animator_collection.h new file mode 100644 index 0000000..2789eda --- /dev/null +++ b/ui/compositor/layer_animator_collection.h @@ -0,0 +1,56 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_COMPOSITOR_LAYER_ANIMATOR_COLLECTION_H_ +#define UI_COMPOSITOR_LAYER_ANIMATOR_COLLECTION_H_ + +#include <set> + +#include "base/callback.h" +#include "base/memory/ref_counted.h" +#include "base/time/time.h" +#include "ui/compositor/compositor_export.h" + +namespace base { +class TimeTicks; +} + +namespace ui { + +class LayerAnimator; + +class COMPOSITOR_EXPORT LayerAnimatorCollectionDelegate { + public: + virtual ~LayerAnimatorCollectionDelegate() {} + + virtual void ScheduleAnimationForLayerCollection() = 0; +}; + +// A collection of LayerAnimators that should be updated at each animation step +// in the compositor. +class COMPOSITOR_EXPORT LayerAnimatorCollection { + public: + explicit LayerAnimatorCollection(LayerAnimatorCollectionDelegate* delegate); + ~LayerAnimatorCollection(); + + void StartAnimator(scoped_refptr<LayerAnimator> animator); + void StopAnimator(scoped_refptr<LayerAnimator> animator); + + bool HasActiveAnimators() const; + + void Progress(base::TimeTicks now); + + base::TimeTicks last_tick_time() const { return last_tick_time_; } + + private: + LayerAnimatorCollectionDelegate* delegate_; + base::TimeTicks last_tick_time_; + std::set<scoped_refptr<LayerAnimator> > animators_; + + DISALLOW_COPY_AND_ASSIGN(LayerAnimatorCollection); +}; + +} // namespace ui + +#endif // UI_COMPOSITOR_LAYER_ANIMATOR_COLLECTION_H_ diff --git a/ui/compositor/layer_animator_unittest.cc b/ui/compositor/layer_animator_unittest.cc index 66efca7..3ae8c2b 100644 --- a/ui/compositor/layer_animator_unittest.cc +++ b/ui/compositor/layer_animator_unittest.cc @@ -14,9 +14,12 @@ #include "ui/compositor/layer_animation_delegate.h" #include "ui/compositor/layer_animation_element.h" #include "ui/compositor/layer_animation_sequence.h" +#include "ui/compositor/layer_animator_collection.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/compositor/scoped_layer_animation_settings.h" +#include "ui/compositor/test/context_factories_for_test.h" #include "ui/compositor/test/layer_animator_test_controller.h" +#include "ui/compositor/test/test_compositor_host.h" #include "ui/compositor/test/test_layer_animation_delegate.h" #include "ui/compositor/test/test_layer_animation_observer.h" #include "ui/compositor/test/test_utils.h" @@ -24,8 +27,6 @@ #include "ui/gfx/rect.h" #include "ui/gfx/transform.h" -using gfx::AnimationContainerElement; - namespace ui { namespace { @@ -196,14 +197,13 @@ class TestLayerAnimationSequence : public LayerAnimationSequence { TEST(LayerAnimatorTest, ImplicitAnimation) { scoped_refptr<LayerAnimator> animator( LayerAnimator::CreateImplicitAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); base::TimeTicks now = gfx::FrameTime::Now(); animator->SetBrightness(0.5); EXPECT_TRUE(animator->is_animating()); - element->Step(now + base::TimeDelta::FromSeconds(1)); + animator->Step(now + base::TimeDelta::FromSeconds(1)); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); } @@ -285,7 +285,6 @@ TEST(LayerAnimatorTest, AbortAllAnimations) { // trivial case and should result in the animation being started immediately. TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -308,12 +307,12 @@ TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); @@ -324,7 +323,7 @@ TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) { double epsilon = 0.00001; LayerAnimatorTestController test_controller( LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = test_controller.animator(); + LayerAnimator* animator = test_controller.animator(); test_controller.animator()->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; test_controller.animator()->SetDelegate(&delegate); @@ -354,7 +353,7 @@ TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) { cc::Animation::Opacity, effective_start)); - element->Step(effective_start + delta/2); + animator->Step(effective_start + delta / 2); EXPECT_TRUE(test_controller.animator()->is_animating()); EXPECT_NEAR( @@ -363,7 +362,7 @@ TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) { last_progressed_fraction(), epsilon); - element->Step(effective_start + delta); + animator->Step(effective_start + delta); EXPECT_FALSE(test_controller.animator()->is_animating()); EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); @@ -373,7 +372,6 @@ TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) { // should start immediately and should progress in lock step. TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -407,13 +405,13 @@ TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); @@ -426,7 +424,7 @@ TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) { double epsilon = 0.00001; LayerAnimatorTestController test_controller( LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = test_controller.animator(); + LayerAnimator* animator = test_controller.animator(); test_controller.animator()->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; test_controller.animator()->SetDelegate(&delegate); @@ -470,7 +468,7 @@ TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) { cc::Animation::Opacity, effective_start)); - element->Step(effective_start + delta/2); + animator->Step(effective_start + delta / 2); EXPECT_TRUE(test_controller.animator()->is_animating()); EXPECT_NEAR( @@ -480,7 +478,7 @@ TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) { epsilon); CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); - element->Step(effective_start + delta); + animator->Step(effective_start + delta); EXPECT_FALSE(test_controller.animator()->is_animating()); EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); @@ -491,7 +489,6 @@ TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) { // animations should run one after another. TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -519,22 +516,22 @@ TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); @@ -545,7 +542,6 @@ TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { // order. TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -589,31 +585,31 @@ TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); - element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); - element->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); - element->Step(start_time + base::TimeDelta::FromMilliseconds(4000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(4000)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); @@ -625,7 +621,6 @@ TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { // the second grayscale animation starts. TEST(LayerAnimatorTest, ScheduleTogether) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -662,13 +657,13 @@ TEST(LayerAnimatorTest, ScheduleTogether) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); - element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); @@ -679,7 +674,6 @@ TEST(LayerAnimatorTest, ScheduleTogether) { // case (see the trival case for ScheduleAnimation). TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -702,12 +696,12 @@ TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); @@ -718,7 +712,7 @@ TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) { double epsilon = 0.00001; LayerAnimatorTestController test_controller( LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = test_controller.animator(); + LayerAnimator* animator = test_controller.animator(); test_controller.animator()->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; test_controller.animator()->SetDelegate(&delegate); @@ -748,7 +742,7 @@ TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) { cc::Animation::Opacity, effective_start)); - element->Step(effective_start + delta/2); + animator->Step(effective_start + delta / 2); EXPECT_TRUE(test_controller.animator()->is_animating()); EXPECT_NEAR( @@ -757,7 +751,7 @@ TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) { last_progressed_fraction(), epsilon); - element->Step(effective_start + delta); + animator->Step(effective_start + delta); EXPECT_FALSE(test_controller.animator()->is_animating()); EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); } @@ -793,7 +787,6 @@ TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { // Preempt by animating to new target, with a non-threaded animation. TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -816,7 +809,7 @@ TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); animator->StartAnimation( new LayerAnimationSequence( @@ -833,13 +826,13 @@ TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { EXPECT_TRUE(animator->is_animating()); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5 * (start_brightness + middle_brightness)); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); @@ -850,7 +843,7 @@ TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) { double epsilon = 0.00001; LayerAnimatorTestController test_controller( LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = test_controller.animator(); + LayerAnimator* animator = test_controller.animator(); test_controller.animator()->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; test_controller.animator()->SetDelegate(&delegate); @@ -881,7 +874,7 @@ TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) { cc::Animation::Opacity, effective_start)); - element->Step(effective_start + delta/2); + animator->Step(effective_start + delta / 2); test_controller.animator()->StartAnimation( new LayerAnimationSequence( @@ -906,7 +899,7 @@ TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) { cc::Animation::Opacity, second_effective_start)); - element->Step(second_effective_start + delta/2); + animator->Step(second_effective_start + delta / 2); EXPECT_TRUE(test_controller.animator()->is_animating()); EXPECT_NEAR( @@ -915,7 +908,7 @@ TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) { last_progressed_fraction(), epsilon); - element->Step(second_effective_start + delta); + animator->Step(second_effective_start + delta); EXPECT_FALSE(test_controller.animator()->is_animating()); EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); @@ -924,7 +917,6 @@ TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) { // Preempt by enqueuing the new animation. TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -946,7 +938,7 @@ TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); animator->StartAnimation( new LayerAnimationSequence( @@ -958,17 +950,17 @@ TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { EXPECT_TRUE(animator->is_animating()); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); @@ -979,7 +971,6 @@ TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { // animation started. TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -1001,7 +992,7 @@ TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); animator->StartAnimation( new LayerAnimationSequence( @@ -1018,17 +1009,17 @@ TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); @@ -1113,7 +1104,6 @@ TEST(LayerAnimatorTest, MultiPreemptBySettingNewTarget) { // Preempt by animating to new target. TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -1144,7 +1134,7 @@ TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); animator->StartTogether( CreateMultiSequence( @@ -1164,7 +1154,7 @@ TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) { EXPECT_TRUE(animator->is_animating()); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), @@ -1172,7 +1162,7 @@ TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) { EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5 * (start_brightness + middle_brightness)); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); @@ -1184,7 +1174,7 @@ TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) { double epsilon = 0.00001; LayerAnimatorTestController test_controller( LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = test_controller.animator(); + LayerAnimator* animator = test_controller.animator(); test_controller.animator()->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; test_controller.animator()->SetDelegate(&delegate); @@ -1223,7 +1213,7 @@ TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) { cc::Animation::Opacity, effective_start)); - element->Step(effective_start + delta/2); + animator->Step(effective_start + delta / 2); test_controller.animator()->StartTogether( CreateMultiSequence( @@ -1253,7 +1243,7 @@ TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) { cc::Animation::Opacity, second_effective_start)); - element->Step(second_effective_start + delta/2); + animator->Step(second_effective_start + delta / 2); EXPECT_TRUE(test_controller.animator()->is_animating()); EXPECT_NEAR( @@ -1265,7 +1255,7 @@ TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) { 0.5 * (start_brightness + middle_brightness), epsilon); - element->Step(second_effective_start + delta); + animator->Step(second_effective_start + delta); EXPECT_FALSE(test_controller.animator()->is_animating()); EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); @@ -1275,7 +1265,6 @@ TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) { // Preempt by enqueuing the new animation. TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -1304,7 +1293,7 @@ TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); animator->StartTogether( CreateMultiSequence( @@ -1318,19 +1307,19 @@ TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) { EXPECT_TRUE(animator->is_animating()); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); @@ -1342,7 +1331,6 @@ TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) { // animation started. TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -1371,7 +1359,7 @@ TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); animator->StartTogether( CreateMultiSequence( @@ -1392,19 +1380,19 @@ TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) { EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); EXPECT_FALSE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); @@ -1414,7 +1402,6 @@ TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) { // Test that non-threaded cyclic sequences continue to animate. TEST(LayerAnimatorTest, CyclicSequences) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -1440,29 +1427,29 @@ TEST(LayerAnimatorTest, CyclicSequences) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); - element->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); // Skip ahead by a lot. - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000000000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000000000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); // Skip ahead by a lot. - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000001000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000001000)); EXPECT_TRUE(animator->is_animating()); EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); @@ -1476,7 +1463,7 @@ TEST(LayerAnimatorTest, CyclicSequences) { TEST(LayerAnimatorTest, ThreadedCyclicSequences) { LayerAnimatorTestController test_controller( LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = test_controller.animator(); + LayerAnimator* animator = test_controller.animator(); test_controller.animator()->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; test_controller.animator()->SetDelegate(&delegate); @@ -1510,7 +1497,7 @@ TEST(LayerAnimatorTest, ThreadedCyclicSequences) { cc::Animation::Opacity, effective_start)); - element->Step(effective_start + delta); + animator->Step(effective_start + delta); EXPECT_TRUE(test_controller.animator()->is_animating()); EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); @@ -1523,7 +1510,7 @@ TEST(LayerAnimatorTest, ThreadedCyclicSequences) { cc::Animation::Opacity, second_effective_start)); - element->Step(second_effective_start + delta); + animator->Step(second_effective_start + delta); EXPECT_TRUE(test_controller.animator()->is_animating()); EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); @@ -1537,7 +1524,7 @@ TEST(LayerAnimatorTest, ThreadedCyclicSequences) { cc::Animation::Opacity, third_effective_start)); - element->Step(third_effective_start + delta); + animator->Step(third_effective_start + delta); EXPECT_TRUE(test_controller.animator()->is_animating()); EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); @@ -1551,7 +1538,7 @@ TEST(LayerAnimatorTest, ThreadedCyclicSequences) { fourth_effective_start)); // Skip ahead by a lot. - element->Step(fourth_effective_start + 1000 * delta); + animator->Step(fourth_effective_start + 1000 * delta); EXPECT_TRUE(test_controller.animator()->is_animating()); EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); @@ -1566,7 +1553,7 @@ TEST(LayerAnimatorTest, ThreadedCyclicSequences) { fifth_effective_start)); // Skip ahead by a lot. - element->Step(fifth_effective_start + 999 * delta); + animator->Step(fifth_effective_start + 999 * delta); EXPECT_TRUE(test_controller.animator()->is_animating()); EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); @@ -1579,7 +1566,6 @@ TEST(LayerAnimatorTest, ThreadedCyclicSequences) { TEST(LayerAnimatorTest, AddObserverExplicit) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationObserver observer; TestLayerAnimationDelegate delegate; @@ -1602,7 +1588,7 @@ TEST(LayerAnimatorTest, AddObserverExplicit) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_EQ(observer.last_ended_sequence(), sequence); @@ -1621,7 +1607,6 @@ TEST(LayerAnimatorTest, AddObserverExplicit) { // when the object goes out of scope. TEST(LayerAnimatorTest, ImplicitAnimationObservers) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestImplicitAnimationObserver observer(false); TestLayerAnimationDelegate delegate; @@ -1638,7 +1623,7 @@ TEST(LayerAnimatorTest, ImplicitAnimationObservers) { EXPECT_FALSE(observer.animations_completed()); base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_TRUE(observer.animations_completed()); EXPECT_TRUE(observer.WasAnimationCompletedForProperty( LayerAnimationElement::BRIGHTNESS)); @@ -1680,7 +1665,6 @@ TEST(LayerAnimatorTest, AnimatorKeptAliveBySettings) { TestLayerAnimator* animator = new TestLayerAnimator(); LayerAnimatorDestructionObserver destruction_observer; animator->SetDestructionObserver(&destruction_observer); - AnimationContainerElement* element = animator; animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -1690,7 +1674,7 @@ TEST(LayerAnimatorTest, AnimatorKeptAliveBySettings) { ScopedLayerAnimationSettings settings(animator); base::TimeTicks now = gfx::FrameTime::Now(); animator->SetBrightness(0.5); - element->Step(now + base::TimeDelta::FromSeconds(1)); + animator->Step(now + base::TimeDelta::FromSeconds(1)); EXPECT_FALSE(destruction_observer.IsAnimatorDeleted()); } // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted. @@ -1770,7 +1754,6 @@ TEST(LayerAnimatorTest, AbortedAnimationStatusInImplicitObservers) { TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationObserver observer; TestLayerAnimationObserver removed_observer; @@ -1797,7 +1780,7 @@ TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_EQ(observer.last_ended_sequence(), sequence); EXPECT_TRUE(!removed_observer.last_ended_sequence()); @@ -1833,7 +1816,6 @@ TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestImplicitAnimationObserver observer(false); @@ -1851,14 +1833,14 @@ TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { animator->StartAnimation(sequence); base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); setter.AddObserver(&observer); // Start observing an in-flight animation. sequence->AddObserver(&observer); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); } EXPECT_TRUE(observer.animations_completed()); @@ -1868,7 +1850,6 @@ TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestImplicitAnimationObserver observer(false); @@ -1886,7 +1867,7 @@ TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { animator->StartAnimation(sequence); base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); } EXPECT_FALSE(observer.animations_completed()); @@ -1912,7 +1893,6 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnEnd) { ScopedAnimationDurationScaleMode normal_duration_mode( ScopedAnimationDurationScaleMode::NORMAL_DURATION); scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -1946,7 +1926,7 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnEnd) { ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + halfway_delta); + animator->Step(start_time + halfway_delta); // Completing the brightness animation should have stopped the bounds // animation. @@ -1982,7 +1962,6 @@ TEST(LayerAnimatorTest, CallbackDeletesAnimationInProgress) { ScopedAnimationDurationScaleMode normal_duration_mode( ScopedAnimationDurationScaleMode::NORMAL_DURATION); scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDeletingDelegate delegate(animator.get(), 30); animator->SetDelegate(&delegate); @@ -2003,14 +1982,14 @@ TEST(LayerAnimatorTest, CallbackDeletesAnimationInProgress) { ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); base::TimeTicks start_time = animator->last_step_time(); - ASSERT_NO_FATAL_FAILURE(element->Step(start_time + bounds_delta1)); + ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + bounds_delta1)); ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); // The next step should change the animated bounds past the threshold and // cause the animaton to stop. - ASSERT_NO_FATAL_FAILURE(element->Step(start_time + bounds_delta2)); + ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + bounds_delta2)); ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); - ASSERT_NO_FATAL_FAILURE(element->Step(start_time + final_delta)); + ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + final_delta)); // Completing the animation should have stopped the bounds // animation. @@ -2200,7 +2179,6 @@ TEST(LayerAnimatorTest, GetTargetGrayscale) { // Verifies color property is modified appropriately. TEST(LayerAnimatorTest, Color) { scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); - AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -2223,13 +2201,13 @@ TEST(LayerAnimatorTest, Color) { base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); EXPECT_TRUE(animator->is_animating()); EXPECT_EQ(ColorToString(middle_color), ColorToString(delegate.GetColorForAnimation())); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); EXPECT_FALSE(animator->is_animating()); EXPECT_EQ(ColorToString(target_color), @@ -2337,7 +2315,6 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) { observer->set_delete_on_animation_ended(true); observer->set_delete_on_animation_aborted(true); LayerAnimator* animator = observer->animator(); - AnimationContainerElement* element = observer->animator(); animator->set_disable_timer_for_test(true); TestLayerAnimationDelegate delegate; animator->SetDelegate(&delegate); @@ -2360,7 +2337,7 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) { animator->StartAnimation(bounds_sequence); base::TimeTicks start_time = animator->last_step_time(); - element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); + animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); EXPECT_TRUE(observer_was_deleted); } @@ -2525,4 +2502,122 @@ TEST(LayerAnimatorTest, TestScopedCounterAnimation) { } +class CollectionLayerAnimationDelegate : public TestLayerAnimationDelegate { + public: + CollectionLayerAnimationDelegate() : collection(NULL) {} + virtual ~CollectionLayerAnimationDelegate() {} + + // LayerAnimationDelegate: + virtual LayerAnimatorCollection* GetLayerAnimatorCollection() OVERRIDE { + return &collection; + } + + private: + LayerAnimatorCollection collection; +}; + +TEST(LayerAnimatorTest, LayerAnimatorCollectionTickTime) { + Layer layer; + LayerAnimator* animator = layer.GetAnimator(); + CollectionLayerAnimationDelegate delegate; + animator->SetDelegate(&delegate); + + LayerAnimatorCollection* collection = delegate.GetLayerAnimatorCollection(); + base::TimeTicks null; + collection->Progress(null); + EXPECT_TRUE(collection->last_tick_time().is_null()); + + // Adding an animator to the collection should update the last tick time. + collection->StartAnimator(layer.GetAnimator()); + EXPECT_TRUE(collection->HasActiveAnimators()); + EXPECT_FALSE(collection->last_tick_time().is_null()); + + collection->StopAnimator(layer.GetAnimator()); + EXPECT_FALSE(collection->HasActiveAnimators()); +} + +TEST(LayerAnimatorTest, AnimatorStartedCorrectly) { + Layer layer; + LayerAnimatorTestController test_controller(layer.GetAnimator()); + LayerAnimator* animator = test_controller.animator(); + ASSERT_FALSE(animator->is_started_); + + TestLayerAnimationDelegate test_delegate; + animator->SetDelegate(&test_delegate); + double target_opacity = 1.0; + base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); + animator->ScheduleAnimation(new LayerAnimationSequence( + LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta))); + EXPECT_FALSE(animator->is_started_); + + CollectionLayerAnimationDelegate collection_delegate; + animator->SetDelegate(&collection_delegate); + animator->UpdateAnimationState(); + EXPECT_TRUE(animator->is_started_); + animator->SetDelegate(NULL); +} + +TEST(LayerAnimatorTest, AnimatorRemovedFromCollectionWhenLayerIsDestroyed) { + scoped_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); + LayerAnimatorTestController test_controller(layer->GetAnimator()); + scoped_refptr<LayerAnimator> animator = test_controller.animator(); + CollectionLayerAnimationDelegate collection_delegate; + animator->SetDelegate(&collection_delegate); + + double target_opacity = 1.0; + base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); + animator->ScheduleAnimation(new LayerAnimationSequence( + LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta))); + + EXPECT_TRUE( + collection_delegate.GetLayerAnimatorCollection()->HasActiveAnimators()); + + layer.reset(); + EXPECT_EQ(NULL, animator->delegate()); + EXPECT_FALSE( + collection_delegate.GetLayerAnimatorCollection()->HasActiveAnimators()); +} + +TEST(LayerAnimatorTest, LayerMovedBetweenCompositorsDuringAnimation) { + bool enable_pixel_output = false; + ui::ContextFactory* context_factory = + InitializeContextFactoryForTests(enable_pixel_output); + const gfx::Rect bounds(10, 10, 100, 100); + scoped_ptr<TestCompositorHost> host_1( + TestCompositorHost::Create(bounds, context_factory)); + scoped_ptr<TestCompositorHost> host_2( + TestCompositorHost::Create(bounds, context_factory)); + host_1->Show(); + host_2->Show(); + + Compositor* compositor_1 = host_1->GetCompositor(); + Layer root_1; + compositor_1->SetRootLayer(&root_1); + + Compositor* compositor_2 = host_2->GetCompositor(); + Layer root_2; + compositor_2->SetRootLayer(&root_2); + + // Verify that neither compositor has active animators. + EXPECT_FALSE(compositor_1->layer_animator_collection()->HasActiveAnimators()); + EXPECT_FALSE(compositor_2->layer_animator_collection()->HasActiveAnimators()); + + Layer layer; + root_1.Add(&layer); + LayerAnimator* animator = layer.GetAnimator(); + double target_opacity = 1.0; + base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); + animator->ScheduleAnimation(new LayerAnimationSequence( + LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta))); + EXPECT_TRUE(compositor_1->layer_animator_collection()->HasActiveAnimators()); + EXPECT_FALSE(compositor_2->layer_animator_collection()->HasActiveAnimators()); + + root_2.Add(&layer); + EXPECT_FALSE(compositor_1->layer_animator_collection()->HasActiveAnimators()); + EXPECT_TRUE(compositor_2->layer_animator_collection()->HasActiveAnimators()); + host_2.reset(); + host_1.reset(); + TerminateContextFactoryForTests(); +} + } // namespace ui diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc index f216af3..9c4b8a0 100644 --- a/ui/compositor/layer_unittest.cc +++ b/ui/compositor/layer_unittest.cc @@ -1507,4 +1507,54 @@ TEST_F(LayerWithRealCompositorTest, SwitchCCLayerAnimations) { EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); } +// Tests that the animators in the layer tree is added to the +// animator-collection when the root-layer is set to the compositor. +TEST_F(LayerWithDelegateTest, RootLayerAnimatorsInCompositor) { + scoped_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); + scoped_ptr<Layer> child(CreateColorLayer(SK_ColorRED, gfx::Rect(10, 10))); + child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); + child->SetOpacity(0.5f); + root->Add(child.get()); + + EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); + compositor()->SetRootLayer(root.get()); + EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); +} + +// Tests that adding/removing a layer adds/removes the animator from its entire +// subtree from the compositor's animator-collection. +TEST_F(LayerWithDelegateTest, AddRemoveLayerUpdatesAnimatorsFromSubtree) { + scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); + scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); + scoped_ptr<Layer> grandchild(CreateColorLayer(SK_ColorRED, + gfx::Rect(10, 10))); + root->Add(child.get()); + child->Add(grandchild.get()); + compositor()->SetRootLayer(root.get()); + + grandchild->SetAnimator(LayerAnimator::CreateImplicitAnimator()); + grandchild->SetOpacity(0.5f); + EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); + + root->Remove(child.get()); + EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); + + root->Add(child.get()); + EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); +} + +TEST_F(LayerWithDelegateTest, DestroyingLayerRemovesTheAnimatorFromCollection) { + scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); + scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); + root->Add(child.get()); + compositor()->SetRootLayer(root.get()); + + child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); + child->SetOpacity(0.5f); + EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); + + child.reset(); + EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); +} + } // namespace ui diff --git a/ui/compositor/test/test_layer_animation_delegate.cc b/ui/compositor/test/test_layer_animation_delegate.cc index ce875e6..e6053d6 100644 --- a/ui/compositor/test/test_layer_animation_delegate.cc +++ b/ui/compositor/test/test_layer_animation_delegate.cc @@ -98,4 +98,9 @@ void TestLayerAnimationDelegate::AddThreadedAnimation( void TestLayerAnimationDelegate::RemoveThreadedAnimation(int animation_id) { } +LayerAnimatorCollection* +TestLayerAnimationDelegate::GetLayerAnimatorCollection() { + return NULL; +} + } // namespace ui diff --git a/ui/compositor/test/test_layer_animation_delegate.h b/ui/compositor/test/test_layer_animation_delegate.h index 014ed3a..0732c99 100644 --- a/ui/compositor/test/test_layer_animation_delegate.h +++ b/ui/compositor/test/test_layer_animation_delegate.h @@ -39,6 +39,7 @@ class TestLayerAnimationDelegate : public LayerAnimationDelegate { virtual void AddThreadedAnimation( scoped_ptr<cc::Animation> animation) OVERRIDE; virtual void RemoveThreadedAnimation(int animation_id) OVERRIDE; + virtual LayerAnimatorCollection* GetLayerAnimatorCollection() OVERRIDE; private: gfx::Rect bounds_; diff --git a/ui/keyboard/keyboard_controller_unittest.cc b/ui/keyboard/keyboard_controller_unittest.cc index f264493..52a98bd 100644 --- a/ui/keyboard/keyboard_controller_unittest.cc +++ b/ui/keyboard/keyboard_controller_unittest.cc @@ -41,13 +41,13 @@ void RunAnimationForLayer(ui::Layer* layer) { ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); ui::LayerAnimatorTestController controller(layer->GetAnimator()); - gfx::AnimationContainerElement* element = layer->GetAnimator(); // Multiple steps are required to complete complex animations. // TODO(vollick): This should not be necessary. crbug.com/154017 while (controller.animator()->is_animating()) { controller.StartThreadedAnimationsIfNeeded(); base::TimeTicks step_time = controller.animator()->last_step_time(); - element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); + controller.animator()->Step(step_time + + base::TimeDelta::FromMilliseconds(1000)); } } |