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

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

Issue 1776513002: UI Compositor: Fix threaded animation survival if layer removed and added. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Release LAC state for old layer in SwitchToLayer. 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr); 131 SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr);
129 delegate_ = delegate; 132 delegate_ = delegate;
130 if (delegate_ && is_started_) { 133 if (delegate_ && is_started_) {
131 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); 134 LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
132 if (collection) 135 if (collection)
133 collection->StartAnimator(this); 136 collection->StartAnimator(this);
134 } 137 }
135 } 138 }
136 139
137 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { 140 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
141 // Release LAC state for old layer.
142 animation_controller_state_ = nullptr;
143
138 if (delegate_) { 144 if (delegate_) {
139 if (animation_player_) 145 if (animation_player_)
140 DetachLayerFromAnimationPlayer(); 146 DetachLayerFromAnimationPlayer();
141 else 147 else
142 delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this); 148 delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this);
143 } 149 }
144 if (new_layer) { 150 if (new_layer) {
145 if (animation_player_) 151 if (animation_player_)
146 AttachLayerToAnimationPlayer(new_layer->id()); 152 AttachLayerToAnimationPlayer(new_layer->id());
147 else 153 else
148 new_layer->AddLayerAnimationEventObserver(this); 154 new_layer->AddLayerAnimationEventObserver(this);
149 } 155 }
150 } 156 }
151 157
152 void LayerAnimator::SetCompositor(Compositor* compositor) { 158 void LayerAnimator::SetCompositor(Compositor* compositor) {
153 DCHECK(compositor); 159 DCHECK(compositor);
154 if (animation_player_) { 160 if (animation_player_) {
155 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); 161 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline();
156 DCHECK(timeline); 162 DCHECK(timeline);
163
164 DCHECK(delegate_->GetCcLayer());
165
166 // Register LAC so ElementAnimations picks it up via
167 // AnimationRegistrar::GetAnimationControllerForId.
168 if (animation_controller_state_) {
169 DCHECK_EQ(animation_controller_state_->id(),
170 delegate_->GetCcLayer()->id());
171 timeline->animation_host()
172 ->animation_registrar()
173 ->RegisterAnimationController(animation_controller_state_.get());
174 }
175
157 timeline->AttachPlayer(animation_player_); 176 timeline->AttachPlayer(animation_player_);
158 177
159 DCHECK(delegate_->GetCcLayer());
160 AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id()); 178 AttachLayerToAnimationPlayer(delegate_->GetCcLayer()->id());
179
180 // Release LAC (it is referenced in ElementAnimations).
181 animation_controller_state_ = nullptr;
161 } 182 }
162 } 183 }
163 184
164 void LayerAnimator::ResetCompositor(Compositor* compositor) { 185 void LayerAnimator::ResetCompositor(Compositor* compositor) {
165 DCHECK(compositor); 186 DCHECK(compositor);
166 if (animation_player_) { 187 if (animation_player_) {
188 // Store a reference to LAC if any so it may be picked up in SetCompositor.
189 if (animation_player_->element_animations()) {
190 animation_controller_state_ =
191 animation_player_->element_animations()->layer_animation_controller();
192 }
193
167 DetachLayerFromAnimationPlayer(); 194 DetachLayerFromAnimationPlayer();
168 195
169 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline(); 196 cc::AnimationTimeline* timeline = compositor->GetAnimationTimeline();
170 DCHECK(timeline); 197 DCHECK(timeline);
171 timeline->DetachPlayer(animation_player_); 198 timeline->DetachPlayer(animation_player_);
172 } 199 }
173 } 200 }
174 201
175 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) { 202 void LayerAnimator::AttachLayerToAnimationPlayer(int layer_id) {
176 DCHECK(animation_player_); 203 DCHECK(animation_player_);
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 const base::WeakPtr<LayerAnimationSequence>& sequence) 981 const base::WeakPtr<LayerAnimationSequence>& sequence)
955 : sequence_(sequence) { 982 : sequence_(sequence) {
956 } 983 }
957 984
958 LayerAnimator::RunningAnimation::RunningAnimation( 985 LayerAnimator::RunningAnimation::RunningAnimation(
959 const RunningAnimation& other) = default; 986 const RunningAnimation& other) = default;
960 987
961 LayerAnimator::RunningAnimation::~RunningAnimation() { } 988 LayerAnimator::RunningAnimation::~RunningAnimation() { }
962 989
963 } // namespace ui 990 } // 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