mac: Add the flag "-gline-tables-only" to reduce dSYM size. (attempt #2)
[chromium-blink-merge.git] / ui / compositor / layer_animator_collection.cc
blobbabdcb6f6b2bb0b2ba8f7992f2aebdaa96009d76
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
3 // found in the LICENSE file.
5 #include "ui/compositor/layer_animator_collection.h"
7 #include <set>
9 #include "base/time/time.h"
10 #include "ui/compositor/compositor.h"
11 #include "ui/compositor/layer_animator.h"
12 #include "ui/gfx/frame_time.h"
14 namespace ui {
16 LayerAnimatorCollection::LayerAnimatorCollection(Compositor* compositor)
17 : compositor_(compositor), last_tick_time_(gfx::FrameTime::Now()) {
20 LayerAnimatorCollection::~LayerAnimatorCollection() {
21 if (compositor_ && compositor_->HasAnimationObserver(this))
22 compositor_->RemoveAnimationObserver(this);
25 void LayerAnimatorCollection::StartAnimator(
26 scoped_refptr<LayerAnimator> animator) {
27 DCHECK_EQ(0U, animators_.count(animator));
28 if (!animators_.size())
29 last_tick_time_ = gfx::FrameTime::Now();
30 animators_.insert(animator);
31 if (animators_.size() == 1U && compositor_)
32 compositor_->AddAnimationObserver(this);
35 void LayerAnimatorCollection::StopAnimator(
36 scoped_refptr<LayerAnimator> animator) {
37 DCHECK_GT(animators_.count(animator), 0U);
38 animators_.erase(animator);
39 if (animators_.empty() && compositor_)
40 compositor_->RemoveAnimationObserver(this);
43 bool LayerAnimatorCollection::HasActiveAnimators() const {
44 return !animators_.empty();
47 void LayerAnimatorCollection::OnAnimationStep(base::TimeTicks now) {
48 last_tick_time_ = now;
49 std::set<scoped_refptr<LayerAnimator> > list = animators_;
50 for (std::set<scoped_refptr<LayerAnimator> >::iterator iter = list.begin();
51 iter != list.end();
52 ++iter) {
53 // Make sure the animator is still valid.
54 if (animators_.count(*iter) > 0)
55 (*iter)->Step(now);
57 if (!HasActiveAnimators() && compositor_)
58 compositor_->RemoveAnimationObserver(this);
61 } // namespace ui