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

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

Issue 1778213003: UI Compositor: Fix threaded animation survival if layer removed and added. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 9 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
« no previous file with comments | « ui/compositor/layer_animator.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.h" 5 #include "ui/compositor/layer_animator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "cc/animation/animation_events.h" 12 #include "cc/animation/animation_events.h"
13 #include "cc/animation/animation_host.h"
13 #include "cc/animation/animation_id_provider.h" 14 #include "cc/animation/animation_id_provider.h"
14 #include "cc/animation/animation_player.h" 15 #include "cc/animation/animation_player.h"
16 #include "cc/animation/animation_registrar.h"
15 #include "cc/animation/animation_timeline.h" 17 #include "cc/animation/animation_timeline.h"
16 #include "cc/animation/element_animations.h" 18 #include "cc/animation/element_animations.h"
19 #include "cc/animation/layer_animation_controller.h"
17 #include "cc/layers/layer_settings.h" 20 #include "cc/layers/layer_settings.h"
18 #include "cc/output/begin_frame_args.h" 21 #include "cc/output/begin_frame_args.h"
19 #include "ui/compositor/compositor.h" 22 #include "ui/compositor/compositor.h"
20 #include "ui/compositor/layer.h" 23 #include "ui/compositor/layer.h"
21 #include "ui/compositor/layer_animation_delegate.h" 24 #include "ui/compositor/layer_animation_delegate.h"
22 #include "ui/compositor/layer_animation_observer.h" 25 #include "ui/compositor/layer_animation_observer.h"
23 #include "ui/compositor/layer_animation_sequence.h" 26 #include "ui/compositor/layer_animation_sequence.h"
24 #include "ui/compositor/layer_animator_collection.h" 27 #include "ui/compositor/layer_animator_collection.h"
25 28
26 #define SAFE_INVOKE_VOID(function, running_anim, ...) \ 29 #define SAFE_INVOKE_VOID(function, running_anim, ...) \
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr); 133 SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr);
131 delegate_ = delegate; 134 delegate_ = delegate;
132 if (delegate_ && is_started_) { 135 if (delegate_ && is_started_) {
133 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); 136 LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
134 if (collection) 137 if (collection)
135 collection->StartAnimator(this); 138 collection->StartAnimator(this);
136 } 139 }
137 } 140 }
138 141
139 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { 142 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
143 // Release LAC state for old layer.
144 animation_controller_state_ = nullptr;
145
140 if (delegate_) { 146 if (delegate_) {
141 if (animation_player_) 147 if (animation_player_)
142 DetachLayerFromAnimationPlayer(); 148 DetachLayerFromAnimationPlayer();
143 else 149 else
144 delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this); 150 delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this);
145 } 151 }
146 if (new_layer) { 152 if (new_layer) {
147 if (animation_player_) 153 if (animation_player_)
148 AttachLayerToAnimationPlayer(new_layer->id()); 154 AttachLayerToAnimationPlayer(new_layer->id());
149 else 155 else
150 new_layer->AddLayerAnimationEventObserver(this); 156 new_layer->AddLayerAnimationEventObserver(this);
151 } 157 }
152 } 158 }
153 159
154 void LayerAnimator::SetCompositor(Compositor* compositor) { 160 void LayerAnimator::SetCompositor(Compositor* compositor) {
155 DCHECK(compositor); 161 DCHECK(compositor);
156 if (animation_player_) { 162 if (animation_player_) {
157 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); 163 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline();
158 DCHECK(timeline); 164 DCHECK(timeline);
165
166 DCHECK(delegate_->GetCcLayer());
167
168 // Register LAC so ElementAnimations picks it up via
169 // AnimationRegistrar::GetAnimationControllerForId.
170 if (animation_controller_state_) {
171 DCHECK_EQ(animation_controller_state_->id(),
172 delegate_->GetCcLayer()->id());
173 timeline->animation_host()
174 ->animation_registrar()
175 ->RegisterAnimationController(animation_controller_state_.get());
176 }
177
159 timeline->AttachPlayer(animation_player_); 178 timeline->AttachPlayer(animation_player_);
160 179
161 DCHECK(delegate_->GetCcLayer());
162 AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); 180 AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id());
181
182 // Release LAC (it is referenced in ElementAnimations).
183 animation_controller_state_ = nullptr;
163 } 184 }
164 } 185 }
165 186
166 void LayerAnimator::ResetCompositor(Compositor* compositor) { 187 void LayerAnimator::ResetCompositor(Compositor* compositor) {
167 DCHECK(compositor); 188 DCHECK(compositor);
168 if (animation_player_) { 189 if (animation_player_) {
190 // Store a reference to LAC if any so it may be picked up in SetCompositor.
191 if (animation_player_->element_animations()) {
192 animation_controller_state_ =
193 animation_player_->element_animations()->layer_animation_controller();
194 }
195
169 DetachLayerFromAnimationPlayer(); 196 DetachLayerFromAnimationPlayer();
170 197
171 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); 198 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline();
172 DCHECK(timeline); 199 DCHECK(timeline);
173 timeline->DetachPlayer(animation_player_); 200 timeline->DetachPlayer(animation_player_);
174 } 201 }
175 } 202 }
176 203
177 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { 204 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) {
178 DCHECK(animation_player_); 205 DCHECK(animation_player_);
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 const base::WeakPtr<LayerAnimationSequence>& sequence) 983 const base::WeakPtr<LayerAnimationSequence>& sequence)
957 : sequence_(sequence) { 984 : sequence_(sequence) {
958 } 985 }
959 986
960 LayerAnimator::RunningAnimation::RunningAnimation( 987 LayerAnimator::RunningAnimation::RunningAnimation(
961 const RunningAnimation& other) = default; 988 const RunningAnimation& other) = default;
962 989
963 LayerAnimator::RunningAnimation::~RunningAnimation() { } 990 LayerAnimator::RunningAnimation::~RunningAnimation() { }
964 991
965 } // namespace ui 992 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_animator.h ('k') | ui/compositor/layer_animator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698