Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/animation/animation_player.h" | |
| 6 | |
| 7 #include "cc/animation/animation_host.h" | |
| 8 #include "cc/animation/animation_registrar.h" | |
| 9 #include "cc/animation/animation_timeline.h" | |
| 10 #include "cc/layers/layer.h" | |
| 11 #include "cc/trees/layer_tree_mutators_client.h" | |
| 12 | |
| 13 namespace cc { | |
| 14 | |
| 15 class AnimationPlayer::ValueObserver : public LayerAnimationValueObserver { | |
| 16 public: | |
| 17 ValueObserver(AnimationPlayer* player, bool is_active) | |
| 18 : player_(player), is_active_(is_active) { | |
|
Ian Vollick
2015/05/05 03:52:06
Just to make sure I'm understanding this correctly
loyso (OOO)
2015/05/05 06:51:18
Yes, that's absolutely correct.
| |
| 19 DCHECK(player_); | |
| 20 } | |
| 21 | |
| 22 // LayerAnimationValueObserver implementation. | |
| 23 void OnFilterAnimated(const FilterOperations& filters) override { | |
| 24 player_->SetFilterMutated(is_active_, filters); | |
| 25 } | |
| 26 | |
| 27 void OnOpacityAnimated(float opacity) override { | |
| 28 player_->SetOpacityMutated(is_active_, opacity); | |
| 29 } | |
| 30 | |
| 31 void OnTransformAnimated(const gfx::Transform& transform) override { | |
| 32 player_->SetTransformMutated(is_active_, transform); | |
| 33 } | |
| 34 | |
| 35 void OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) override { | |
| 36 player_->SetScrollOffsetMutated(is_active_, scroll_offset); | |
| 37 } | |
| 38 | |
| 39 void OnAnimationWaitingForDeletion() override { | |
| 40 // TODO(loyso): implement it. | |
|
Ian Vollick
2015/05/05 03:52:06
Why's it ok to put this off?
loyso (OOO)
2015/05/05 06:51:18
It's in separate CL for scroll offset. https://cod
Ian Vollick
2015/05/07 13:58:42
My questions is more about staging. Will the code
loyso (OOO)
2015/05/08 01:04:34
We don't run this code path w/o --enable_composito
Ian Vollick
2015/05/08 14:58:22
K, great.
| |
| 41 } | |
| 42 | |
| 43 bool IsActive() const override { return is_active_; } | |
| 44 | |
| 45 private: | |
| 46 AnimationPlayer* player_; | |
| 47 bool is_active_; | |
| 48 | |
| 49 DISALLOW_COPY_AND_ASSIGN(ValueObserver); | |
| 50 }; | |
| 51 | |
| 52 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) { | |
| 53 return make_scoped_refptr(new AnimationPlayer(id)); | |
| 54 } | |
| 55 | |
| 56 AnimationPlayer::AnimationPlayer(int id) | |
| 57 : animation_host_(), | |
| 58 animation_timeline_(), | |
| 59 layer_animation_delegate_(), | |
| 60 id_(id), | |
| 61 layer_id_(0) { | |
| 62 DCHECK(id_); | |
| 63 } | |
| 64 | |
| 65 AnimationPlayer::~AnimationPlayer() { | |
| 66 DCHECK(!animation_timeline_); | |
| 67 DCHECK(!layer_animation_controller_); | |
| 68 DCHECK(!layer_id_); | |
| 69 } | |
| 70 | |
| 71 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const { | |
| 72 scoped_refptr<AnimationPlayer> to_return = AnimationPlayer::Create(id()); | |
| 73 return to_return; | |
| 74 } | |
| 75 | |
| 76 void AnimationPlayer::SetAnimationHost(AnimationHost* animation_host) { | |
| 77 animation_host_ = animation_host; | |
| 78 } | |
| 79 | |
| 80 void AnimationPlayer::SetAnimationTimeline(AnimationTimeline* timeline) { | |
| 81 if (animation_timeline_ == timeline) | |
| 82 return; | |
| 83 | |
| 84 if (layer_id_ && animation_timeline_) | |
| 85 RemoveControllerFromTimeline(); | |
|
Ian Vollick
2015/05/05 03:52:06
Can you add a comment explaining why you need to r
loyso (OOO)
2015/05/05 06:51:18
Acknowledged.
loyso (OOO)
2015/06/22 07:48:51
Done.
| |
| 86 | |
| 87 animation_timeline_ = timeline; | |
| 88 | |
| 89 if (layer_id_ && animation_timeline_) | |
| 90 AddControllerToTimeline(); | |
| 91 } | |
| 92 | |
| 93 void AnimationPlayer::set_layer_animation_delegate( | |
| 94 AnimationDelegate* delegate) { | |
| 95 layer_animation_delegate_ = delegate; | |
| 96 if (layer_animation_controller_) | |
| 97 layer_animation_controller_->set_layer_animation_delegate(delegate); | |
| 98 } | |
| 99 | |
| 100 void AnimationPlayer::AttachLayer(int layer_id) { | |
| 101 DCHECK_EQ(layer_id_, 0); | |
| 102 DCHECK_NE(layer_id, 0); | |
| 103 DCHECK(!layer_animation_controller_); | |
| 104 | |
| 105 layer_id_ = layer_id; | |
| 106 | |
| 107 if (animation_timeline_) | |
| 108 AddControllerToTimeline(); | |
| 109 } | |
| 110 | |
| 111 void AnimationPlayer::DetachLayer() { | |
| 112 DCHECK_NE(layer_id_, 0); | |
| 113 | |
| 114 if (animation_timeline_) | |
| 115 RemoveControllerFromTimeline(); | |
| 116 | |
| 117 layer_animation_controller_ = nullptr; | |
| 118 layer_id_ = 0; | |
| 119 } | |
| 120 | |
| 121 void AnimationPlayer::AddControllerToTimeline() { | |
| 122 DCHECK(layer_id_); | |
| 123 DCHECK(animation_host_); | |
| 124 | |
| 125 AnimationRegistrar* registrar = animation_host_->animation_registrar(); | |
| 126 DCHECK(registrar); | |
| 127 | |
| 128 layer_animation_controller_ = | |
| 129 registrar->GetAnimationControllerForId(layer_id_); | |
| 130 layer_animation_controller_->SetAnimationRegistrar(registrar); | |
| 131 | |
| 132 DCHECK(animation_host_->layer_tree_mutators_client()); | |
| 133 if (animation_host_->layer_tree_mutators_client()->IsLayerInActiveTree( | |
| 134 layer_id_)) | |
| 135 CreateActiveValueObserver(); | |
| 136 if (animation_host_->layer_tree_mutators_client()->IsLayerInPendingTree( | |
| 137 layer_id_)) | |
| 138 CreatePendingValueObserver(); | |
| 139 | |
| 140 animation_host_->RegisterPlayerForLayer(layer_id_, this); | |
| 141 } | |
| 142 | |
| 143 void AnimationPlayer::RemoveControllerFromTimeline() { | |
| 144 DCHECK(layer_id_); | |
| 145 DCHECK(animation_host_); | |
| 146 animation_host_->UnregisterPlayerForLayer(layer_id_, this); | |
| 147 | |
| 148 DestroyPendingValueObserver(); | |
| 149 DestroyActiveValueObserver(); | |
| 150 if (layer_animation_controller_) | |
| 151 layer_animation_controller_->SetAnimationRegistrar(nullptr); | |
| 152 layer_animation_controller_ = nullptr; | |
| 153 } | |
| 154 | |
| 155 void AnimationPlayer::LayerRegistered(int layer_id, bool is_active_tree) { | |
| 156 DCHECK_EQ(layer_id_, layer_id); | |
| 157 if (is_active_tree && layer_animation_controller_) { | |
| 158 if (!active_value_observer_) | |
| 159 CreateActiveValueObserver(); | |
| 160 } else { | |
| 161 if (!pending_value_observer_) | |
| 162 CreatePendingValueObserver(); | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 void AnimationPlayer::LayerUnregistered(int layer_id, bool is_active_tree) { | |
| 167 DCHECK_EQ(layer_id_, layer_id); | |
| 168 is_active_tree ? DestroyActiveValueObserver() : DestroyPendingValueObserver(); | |
| 169 } | |
| 170 | |
| 171 void AnimationPlayer::AddAnimation(scoped_ptr<Animation> animation) { | |
| 172 DCHECK(layer_animation_controller_); | |
| 173 layer_animation_controller_->AddAnimation(animation.Pass()); | |
| 174 SetNeedsCommit(); | |
| 175 } | |
| 176 | |
| 177 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) { | |
| 178 DCHECK(layer_animation_controller_); | |
| 179 layer_animation_controller_->PauseAnimation( | |
| 180 animation_id, base::TimeDelta::FromSecondsD(time_offset)); | |
| 181 SetNeedsCommit(); | |
| 182 } | |
| 183 | |
| 184 void AnimationPlayer::RemoveAnimation(int animation_id) { | |
| 185 if (layer_animation_controller_) { | |
| 186 layer_animation_controller_->RemoveAnimation(animation_id); | |
| 187 SetNeedsCommit(); | |
| 188 } | |
| 189 } | |
| 190 | |
| 191 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { | |
| 192 if (!layer_animation_controller()) { | |
| 193 if (player_impl->layer_animation_controller()) | |
| 194 player_impl->DetachLayer(); | |
| 195 return; | |
| 196 } | |
| 197 | |
| 198 DCHECK_NE(layer_id_, 0); | |
| 199 if (!player_impl->layer_animation_controller()) | |
| 200 player_impl->AttachLayer(layer_id_); | |
| 201 | |
| 202 DCHECK(player_impl->layer_animation_controller()); | |
| 203 layer_animation_controller_->PushAnimationUpdatesTo( | |
| 204 player_impl->layer_animation_controller()); | |
| 205 } | |
| 206 | |
| 207 void AnimationPlayer::SetNeedsCommit() { | |
| 208 DCHECK(animation_host_); | |
| 209 animation_host_->SetNeedsCommit(); | |
| 210 } | |
| 211 | |
| 212 void AnimationPlayer::SetFilterMutated(bool active_tree, | |
| 213 const FilterOperations& filters) { | |
| 214 DCHECK(layer_id_); | |
| 215 if (animation_host()) { | |
| 216 DCHECK(animation_host()->layer_tree_mutators_client()); | |
| 217 animation_host()->layer_tree_mutators_client()->SetLayerFilterMutated( | |
| 218 layer_id_, active_tree, filters); | |
| 219 } | |
| 220 } | |
| 221 | |
| 222 void AnimationPlayer::SetOpacityMutated(bool active_tree, float opacity) { | |
| 223 DCHECK(layer_id_); | |
| 224 if (animation_host()) { | |
| 225 DCHECK(animation_host()->layer_tree_mutators_client()); | |
| 226 animation_host()->layer_tree_mutators_client()->SetLayerOpacityMutated( | |
| 227 layer_id_, active_tree, opacity); | |
| 228 } | |
| 229 } | |
| 230 | |
| 231 void AnimationPlayer::SetTransformMutated(bool active_tree, | |
| 232 const gfx::Transform& transform) { | |
| 233 DCHECK(layer_id_); | |
| 234 if (animation_host()) { | |
| 235 DCHECK(animation_host()->layer_tree_mutators_client()); | |
| 236 animation_host()->layer_tree_mutators_client()->SetLayerTransformMutated( | |
|
Ian Vollick
2015/05/05 03:52:06
If I understand correctly, this will cause us to f
loyso (OOO)
2015/05/05 06:51:18
Yes, that's a hash_map look up. We discussed that
Ian Vollick
2015/05/07 13:58:42
I think you're right that we won't have that many
loyso (OOO)
2015/05/08 01:04:34
May I set this as a separate perf and optimization
Ian Vollick
2015/05/08 14:58:22
Since these results could affect the design of thi
loyso (OOO)
2015/06/22 07:48:51
Done. https://codereview.chromium.org/1172583003/
| |
| 237 layer_id_, active_tree, transform); | |
| 238 } | |
| 239 } | |
| 240 | |
| 241 void AnimationPlayer::SetScrollOffsetMutated( | |
| 242 bool active_tree, | |
| 243 const gfx::ScrollOffset& scroll_offset) { | |
| 244 DCHECK(layer_id_); | |
| 245 if (animation_host()) { | |
| 246 DCHECK(animation_host()->layer_tree_mutators_client()); | |
| 247 animation_host()->layer_tree_mutators_client()->SetLayerScrollOffsetMutated( | |
| 248 layer_id_, active_tree, scroll_offset); | |
| 249 } | |
| 250 } | |
| 251 | |
| 252 void AnimationPlayer::CreateActiveValueObserver() { | |
| 253 DCHECK(layer_animation_controller_); | |
| 254 DCHECK(!active_value_observer_); | |
| 255 active_value_observer_ = make_scoped_ptr(new ValueObserver(this, true)); | |
| 256 layer_animation_controller_->AddValueObserver(active_value_observer_.get()); | |
| 257 | |
| 258 layer_animation_controller_->set_value_provider(this); | |
| 259 layer_animation_controller_->set_layer_animation_delegate( | |
| 260 layer_animation_delegate_); | |
| 261 } | |
| 262 | |
| 263 void AnimationPlayer::DestroyActiveValueObserver() { | |
| 264 if (layer_animation_controller_ && active_value_observer_) | |
| 265 layer_animation_controller_->RemoveValueObserver( | |
| 266 active_value_observer_.get()); | |
| 267 active_value_observer_ = nullptr; | |
| 268 | |
| 269 if (layer_animation_controller_) { | |
| 270 layer_animation_controller_->remove_value_provider(this); | |
| 271 layer_animation_controller_->remove_layer_animation_delegate( | |
| 272 layer_animation_delegate_); | |
| 273 } | |
| 274 } | |
| 275 | |
| 276 void AnimationPlayer::CreatePendingValueObserver() { | |
| 277 DCHECK(layer_animation_controller_); | |
| 278 DCHECK(!pending_value_observer_); | |
| 279 pending_value_observer_ = make_scoped_ptr(new ValueObserver(this, false)); | |
| 280 layer_animation_controller_->AddValueObserver(pending_value_observer_.get()); | |
| 281 } | |
| 282 | |
| 283 void AnimationPlayer::DestroyPendingValueObserver() { | |
| 284 if (layer_animation_controller_ && pending_value_observer_) | |
| 285 layer_animation_controller_->RemoveValueObserver( | |
| 286 pending_value_observer_.get()); | |
| 287 pending_value_observer_ = nullptr; | |
| 288 } | |
| 289 | |
| 290 gfx::ScrollOffset AnimationPlayer::ScrollOffsetForAnimation() const { | |
| 291 // TODO(loyso): implement it. | |
| 292 return gfx::ScrollOffset(); | |
| 293 } | |
| 294 | |
| 295 } // namespace cc | |
| OLD | NEW |