OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/compositor/layer_animator_collection.h" | 5 #include "ui/compositor/layer_animator_collection.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "ui/compositor/layer_animator.h" | 10 #include "ui/compositor/layer_animator.h" |
11 #include "ui/gfx/frame_time.h" | 11 #include "ui/gfx/frame_time.h" |
12 | 12 |
13 namespace ui { | 13 namespace ui { |
14 | 14 |
15 LayerAnimatorCollection::LayerAnimatorCollection( | 15 LayerAnimatorCollection::LayerAnimatorCollection( |
16 LayerAnimatorCollectionDelegate* delegate) | 16 AnimationFrameTaskProvider* provider) |
17 : delegate_(delegate), | 17 : provider_(provider), last_tick_time_(gfx::FrameTime::Now()) { |
18 last_tick_time_(gfx::FrameTime::Now()) { | |
19 } | 18 } |
20 | 19 |
21 LayerAnimatorCollection::~LayerAnimatorCollection() { | 20 LayerAnimatorCollection::~LayerAnimatorCollection() { |
22 } | 21 } |
23 | 22 |
24 void LayerAnimatorCollection::StartAnimator( | 23 void LayerAnimatorCollection::StartAnimator( |
25 scoped_refptr<LayerAnimator> animator) { | 24 scoped_refptr<LayerAnimator> animator) { |
26 DCHECK_EQ(0U, animators_.count(animator)); | 25 DCHECK_EQ(0U, animators_.count(animator)); |
27 if (!animators_.size()) | 26 if (!animators_.size()) |
28 last_tick_time_ = gfx::FrameTime::Now(); | 27 last_tick_time_ = gfx::FrameTime::Now(); |
29 animators_.insert(animator); | 28 animators_.insert(animator); |
30 if (delegate_) | 29 if (!raf_callback_ && provider_) |
31 delegate_->ScheduleAnimationForLayerCollection(); | 30 raf_callback_ = provider_->RequestAnimationFrameTask(this); |
32 } | 31 } |
33 | 32 |
34 void LayerAnimatorCollection::StopAnimator( | 33 void LayerAnimatorCollection::StopAnimator( |
35 scoped_refptr<LayerAnimator> animator) { | 34 scoped_refptr<LayerAnimator> animator) { |
36 DCHECK_GT(animators_.count(animator), 0U); | 35 DCHECK_GT(animators_.count(animator), 0U); |
37 animators_.erase(animator); | 36 animators_.erase(animator); |
| 37 if (animators_.empty() && raf_callback_) |
| 38 raf_callback_.reset(); |
38 } | 39 } |
39 | 40 |
40 bool LayerAnimatorCollection::HasActiveAnimators() const { | 41 bool LayerAnimatorCollection::HasActiveAnimators() const { |
41 return !animators_.empty(); | 42 return !animators_.empty(); |
42 } | 43 } |
43 | 44 |
44 void LayerAnimatorCollection::Progress(base::TimeTicks now) { | 45 AnimationFrameTaskStatus LayerAnimatorCollection::Progress( |
| 46 base::TimeTicks now) { |
45 last_tick_time_ = now; | 47 last_tick_time_ = now; |
46 std::set<scoped_refptr<LayerAnimator> > list = animators_; | 48 std::set<scoped_refptr<LayerAnimator> > list = animators_; |
47 for (std::set<scoped_refptr<LayerAnimator> >::iterator iter = list.begin(); | 49 for (std::set<scoped_refptr<LayerAnimator> >::iterator iter = list.begin(); |
48 iter != list.end(); | 50 iter != list.end(); |
49 ++iter) { | 51 ++iter) { |
50 // Make sure the animator is still valid. | 52 // Make sure the animator is still valid. |
51 if (animators_.count(*iter) > 0) | 53 if (animators_.count(*iter) > 0) |
52 (*iter)->Step(now); | 54 (*iter)->Step(now); |
53 } | 55 } |
| 56 return HasActiveAnimators() ? ANIMATION_FRAME_TASK_CONTINUE |
| 57 : ANIMATION_FRAME_TASK_END; |
54 } | 58 } |
55 | 59 |
56 } // namespace ui | 60 } // namespace ui |
OLD | NEW |