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

Side by Side Diff: ui/compositor/layer_animator_collection.cc

Issue 427103002: compositor: Add rAF-like functionality for the UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 | « ui/compositor/layer_animator_collection.h ('k') | ui/compositor/layer_animator_unittest.cc » ('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 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/compositor.h"
10 #include "ui/compositor/layer_animator.h" 11 #include "ui/compositor/layer_animator.h"
11 #include "ui/gfx/frame_time.h" 12 #include "ui/gfx/frame_time.h"
12 13
13 namespace ui { 14 namespace ui {
14 15
15 LayerAnimatorCollection::LayerAnimatorCollection( 16 LayerAnimatorCollection::LayerAnimatorCollection(Compositor* compositor)
16 LayerAnimatorCollectionDelegate* delegate) 17 : compositor_(compositor), last_tick_time_(gfx::FrameTime::Now()) {
17 : delegate_(delegate),
18 last_tick_time_(gfx::FrameTime::Now()) {
19 } 18 }
20 19
21 LayerAnimatorCollection::~LayerAnimatorCollection() { 20 LayerAnimatorCollection::~LayerAnimatorCollection() {
21 if (compositor_ && compositor_->HasAnimationObserver(this))
22 compositor_->RemoveAnimationObserver(this);
22 } 23 }
23 24
24 void LayerAnimatorCollection::StartAnimator( 25 void LayerAnimatorCollection::StartAnimator(
25 scoped_refptr<LayerAnimator> animator) { 26 scoped_refptr<LayerAnimator> animator) {
26 DCHECK_EQ(0U, animators_.count(animator)); 27 DCHECK_EQ(0U, animators_.count(animator));
27 if (!animators_.size()) 28 if (!animators_.size())
28 last_tick_time_ = gfx::FrameTime::Now(); 29 last_tick_time_ = gfx::FrameTime::Now();
29 animators_.insert(animator); 30 animators_.insert(animator);
30 if (delegate_) 31 if (animators_.size() == 1U && compositor_)
31 delegate_->ScheduleAnimationForLayerCollection(); 32 compositor_->AddAnimationObserver(this);
32 } 33 }
33 34
34 void LayerAnimatorCollection::StopAnimator( 35 void LayerAnimatorCollection::StopAnimator(
35 scoped_refptr<LayerAnimator> animator) { 36 scoped_refptr<LayerAnimator> animator) {
36 DCHECK_GT(animators_.count(animator), 0U); 37 DCHECK_GT(animators_.count(animator), 0U);
37 animators_.erase(animator); 38 animators_.erase(animator);
39 if (animators_.empty() && compositor_)
40 compositor_->RemoveAnimationObserver(this);
38 } 41 }
39 42
40 bool LayerAnimatorCollection::HasActiveAnimators() const { 43 bool LayerAnimatorCollection::HasActiveAnimators() const {
41 return !animators_.empty(); 44 return !animators_.empty();
42 } 45 }
43 46
44 void LayerAnimatorCollection::Progress(base::TimeTicks now) { 47 void LayerAnimatorCollection::OnAnimationStep(base::TimeTicks now) {
45 last_tick_time_ = now; 48 last_tick_time_ = now;
46 std::set<scoped_refptr<LayerAnimator> > list = animators_; 49 std::set<scoped_refptr<LayerAnimator> > list = animators_;
47 for (std::set<scoped_refptr<LayerAnimator> >::iterator iter = list.begin(); 50 for (std::set<scoped_refptr<LayerAnimator> >::iterator iter = list.begin();
48 iter != list.end(); 51 iter != list.end();
49 ++iter) { 52 ++iter) {
50 // Make sure the animator is still valid. 53 // Make sure the animator is still valid.
51 if (animators_.count(*iter) > 0) 54 if (animators_.count(*iter) > 0)
52 (*iter)->Step(now); 55 (*iter)->Step(now);
53 } 56 }
57 if (!HasActiveAnimators() && compositor_)
58 compositor_->RemoveAnimationObserver(this);
54 } 59 }
55 60
56 } // namespace ui 61 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_animator_collection.h ('k') | ui/compositor/layer_animator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698