OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/animation/animation_player.h" | 5 #include "cc/animation/animation_player.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "cc/animation/animation_delegate.h" | 9 #include "cc/animation/animation_delegate.h" |
10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
11 #include "cc/animation/animation_timeline.h" | 11 #include "cc/animation/animation_timeline.h" |
12 #include "cc/animation/element_animations.h" | 12 #include "cc/animation/element_animations.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) { | 16 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) { |
17 return make_scoped_refptr(new AnimationPlayer(id)); | 17 return make_scoped_refptr(new AnimationPlayer(id)); |
18 } | 18 } |
19 | 19 |
20 AnimationPlayer::AnimationPlayer(int id) | 20 AnimationPlayer::AnimationPlayer(int id) |
21 : animation_host_(), | 21 : animation_host_(), |
22 animation_timeline_(), | 22 animation_timeline_(), |
23 element_animations_(), | 23 element_animations_(), |
24 animation_delegate_(), | 24 animation_delegate_(), |
25 id_(id), | 25 id_(id) { |
26 element_id_(0) { | |
27 DCHECK(id_); | 26 DCHECK(id_); |
28 } | 27 } |
29 | 28 |
30 AnimationPlayer::~AnimationPlayer() { | 29 AnimationPlayer::~AnimationPlayer() { |
31 DCHECK(!animation_timeline_); | 30 DCHECK(!animation_timeline_); |
32 DCHECK(!element_animations_); | 31 DCHECK(!element_animations_); |
33 } | 32 } |
34 | 33 |
35 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const { | 34 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const { |
36 scoped_refptr<AnimationPlayer> player = AnimationPlayer::Create(id()); | 35 scoped_refptr<AnimationPlayer> player = AnimationPlayer::Create(id()); |
(...skipping 14 matching lines...) Expand all Loading... |
51 UnregisterPlayer(); | 50 UnregisterPlayer(); |
52 | 51 |
53 animation_timeline_ = timeline; | 52 animation_timeline_ = timeline; |
54 | 53 |
55 // Register player only if layer AND host attached. | 54 // Register player only if layer AND host attached. |
56 if (element_id_ && animation_host_) | 55 if (element_id_ && animation_host_) |
57 RegisterPlayer(); | 56 RegisterPlayer(); |
58 } | 57 } |
59 | 58 |
60 void AnimationPlayer::AttachElement(ElementId element_id) { | 59 void AnimationPlayer::AttachElement(ElementId element_id) { |
61 DCHECK_EQ(element_id_, 0); | 60 DCHECK(!element_id_); |
62 DCHECK(element_id); | 61 DCHECK(element_id); |
63 | 62 |
64 element_id_ = element_id; | 63 element_id_ = element_id; |
65 | 64 |
66 // Register player only if layer AND host attached. | 65 // Register player only if layer AND host attached. |
67 if (animation_host_) | 66 if (animation_host_) |
68 RegisterPlayer(); | 67 RegisterPlayer(); |
69 } | 68 } |
70 | 69 |
71 void AnimationPlayer::DetachElement() { | 70 void AnimationPlayer::DetachElement() { |
72 DCHECK(element_id_); | 71 DCHECK(element_id_); |
73 | 72 |
74 if (animation_host_) | 73 if (animation_host_) |
75 UnregisterPlayer(); | 74 UnregisterPlayer(); |
76 | 75 |
77 element_id_ = 0; | 76 element_id_ = ElementId(); |
78 } | 77 } |
79 | 78 |
80 void AnimationPlayer::RegisterPlayer() { | 79 void AnimationPlayer::RegisterPlayer() { |
81 DCHECK(element_id_); | 80 DCHECK(element_id_); |
82 DCHECK(animation_host_); | 81 DCHECK(animation_host_); |
83 DCHECK(!element_animations_); | 82 DCHECK(!element_animations_); |
84 | 83 |
85 // Create ElementAnimations or re-use existing. | 84 // Create ElementAnimations or re-use existing. |
86 animation_host_->RegisterPlayerForElement(element_id_, this); | 85 animation_host_->RegisterPlayerForElement(element_id_, this); |
87 // Get local reference to shared ElementAnimations. | 86 // Get local reference to shared ElementAnimations. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 220 } |
222 } | 221 } |
223 | 222 |
224 void AnimationPlayer::SetNeedsCommit() { | 223 void AnimationPlayer::SetNeedsCommit() { |
225 DCHECK(animation_host_); | 224 DCHECK(animation_host_); |
226 animation_host_->SetNeedsCommit(); | 225 animation_host_->SetNeedsCommit(); |
227 animation_host_->SetNeedsRebuildPropertyTrees(); | 226 animation_host_->SetNeedsRebuildPropertyTrees(); |
228 } | 227 } |
229 | 228 |
230 } // namespace cc | 229 } // namespace cc |
OLD | NEW |