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

Side by Side Diff: cc/animation/animation_host.cc

Issue 1904653002: CC Animation: Merge LayerAnimationController into ElementAnimations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor optimization: Don't init value observations if same host. Created 4 years, 8 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 | « cc/animation/animation_host.h ('k') | cc/animation/animation_player.h » ('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 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_host.h" 5 #include "cc/animation/animation_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "base/trace_event/trace_event_argument.h" 12 #include "base/trace_event/trace_event_argument.h"
13 #include "cc/animation/animation_delegate.h" 13 #include "cc/animation/animation_delegate.h"
14 #include "cc/animation/animation_events.h" 14 #include "cc/animation/animation_events.h"
15 #include "cc/animation/animation_id_provider.h" 15 #include "cc/animation/animation_id_provider.h"
16 #include "cc/animation/animation_player.h" 16 #include "cc/animation/animation_player.h"
17 #include "cc/animation/animation_timeline.h" 17 #include "cc/animation/animation_timeline.h"
18 #include "cc/animation/element_animations.h" 18 #include "cc/animation/element_animations.h"
19 #include "cc/animation/layer_animation_controller.h"
20 #include "cc/animation/scroll_offset_animation_curve.h" 19 #include "cc/animation/scroll_offset_animation_curve.h"
21 #include "cc/animation/timing_function.h" 20 #include "cc/animation/timing_function.h"
22 #include "ui/gfx/geometry/box_f.h" 21 #include "ui/gfx/geometry/box_f.h"
23 #include "ui/gfx/geometry/scroll_offset.h" 22 #include "ui/gfx/geometry/scroll_offset.h"
24 23
25 namespace cc { 24 namespace cc {
26 25
27 class AnimationHost::ScrollOffsetAnimations : public AnimationDelegate { 26 class AnimationHost::ScrollOffsetAnimations : public AnimationDelegate {
28 public: 27 public:
29 explicit ScrollOffsetAnimations(AnimationHost* animation_host) 28 explicit ScrollOffsetAnimations(AnimationHost* animation_host)
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 }; 147 };
149 148
150 std::unique_ptr<AnimationHost> AnimationHost::Create( 149 std::unique_ptr<AnimationHost> AnimationHost::Create(
151 ThreadInstance thread_instance) { 150 ThreadInstance thread_instance) {
152 return base::WrapUnique(new AnimationHost(thread_instance)); 151 return base::WrapUnique(new AnimationHost(thread_instance));
153 } 152 }
154 153
155 AnimationHost::AnimationHost(ThreadInstance thread_instance) 154 AnimationHost::AnimationHost(ThreadInstance thread_instance)
156 : mutator_host_client_(nullptr), 155 : mutator_host_client_(nullptr),
157 thread_instance_(thread_instance), 156 thread_instance_(thread_instance),
158 supports_scroll_animations_(false) { 157 supports_scroll_animations_(false),
158 animation_waiting_for_deletion_(false) {
159 if (thread_instance_ == ThreadInstance::IMPL) 159 if (thread_instance_ == ThreadInstance::IMPL)
160 scroll_offset_animations_ = 160 scroll_offset_animations_ =
161 base::WrapUnique(new ScrollOffsetAnimations(this)); 161 base::WrapUnique(new ScrollOffsetAnimations(this));
162 } 162 }
163 163
164 AnimationHost::~AnimationHost() { 164 AnimationHost::~AnimationHost() {
165 scroll_offset_animations_ = nullptr; 165 scroll_offset_animations_ = nullptr;
166 166
167 ClearTimelines(); 167 ClearTimelines();
168 DCHECK(!mutator_host_client()); 168 DCHECK(!mutator_host_client());
169 DCHECK(layer_to_element_animations_map_.empty()); 169 DCHECK(layer_to_element_animations_map_.empty());
170
171 AnimationControllerMap copy = all_animation_controllers_;
172 for (AnimationControllerMap::iterator iter = copy.begin(); iter != copy.end();
173 ++iter)
174 (*iter).second->SetAnimationHost(nullptr);
175 } 170 }
176 171
177 AnimationTimeline* AnimationHost::GetTimelineById(int timeline_id) const { 172 AnimationTimeline* AnimationHost::GetTimelineById(int timeline_id) const {
178 auto f = id_to_timeline_map_.find(timeline_id); 173 auto f = id_to_timeline_map_.find(timeline_id);
179 return f == id_to_timeline_map_.end() ? nullptr : f->second.get(); 174 return f == id_to_timeline_map_.end() ? nullptr : f->second.get();
180 } 175 }
181 176
182 void AnimationHost::ClearTimelines() { 177 void AnimationHost::ClearTimelines() {
183 for (auto& kv : id_to_timeline_map_) 178 for (auto& kv : id_to_timeline_map_)
184 EraseTimeline(kv.second); 179 EraseTimeline(kv.second);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 215 }
221 216
222 void AnimationHost::RegisterPlayerForLayer(int layer_id, 217 void AnimationHost::RegisterPlayerForLayer(int layer_id,
223 AnimationPlayer* player) { 218 AnimationPlayer* player) {
224 DCHECK(layer_id); 219 DCHECK(layer_id);
225 DCHECK(player); 220 DCHECK(player);
226 221
227 scoped_refptr<ElementAnimations> element_animations = 222 scoped_refptr<ElementAnimations> element_animations =
228 GetElementAnimationsForLayerId(layer_id); 223 GetElementAnimationsForLayerId(layer_id);
229 if (!element_animations) { 224 if (!element_animations) {
230 element_animations = ElementAnimations::Create(this); 225 element_animations = ElementAnimations::Create();
231 layer_to_element_animations_map_[layer_id] = element_animations; 226 element_animations->SetLayerId(layer_id);
232 227 RegisterElementAnimations(element_animations.get());
233 element_animations->CreateLayerAnimationController(layer_id);
234 } 228 }
235 229
236 DCHECK(element_animations); 230 if (element_animations->animation_host() != this) {
231 element_animations->SetAnimationHost(this);
232 element_animations->InitValueObservations();
233 }
234
237 element_animations->AddPlayer(player); 235 element_animations->AddPlayer(player);
238 } 236 }
239 237
240 void AnimationHost::UnregisterPlayerForLayer(int layer_id, 238 void AnimationHost::UnregisterPlayerForLayer(int layer_id,
241 AnimationPlayer* player) { 239 AnimationPlayer* player) {
242 DCHECK(layer_id); 240 DCHECK(layer_id);
243 DCHECK(player); 241 DCHECK(player);
244 242
245 scoped_refptr<ElementAnimations> element_animations = 243 scoped_refptr<ElementAnimations> element_animations =
246 GetElementAnimationsForLayerId(layer_id); 244 GetElementAnimationsForLayerId(layer_id);
247 DCHECK(element_animations); 245 DCHECK(element_animations);
248 element_animations->RemovePlayer(player); 246 element_animations->RemovePlayer(player);
249 247
250 if (element_animations->IsEmpty()) { 248 if (element_animations->IsEmpty()) {
251 element_animations->DestroyLayerAnimationController(); 249 element_animations->ClearValueObservations();
252 layer_to_element_animations_map_.erase(layer_id); 250 UnregisterElementAnimations(element_animations.get());
251 element_animations->SetAnimationHost(nullptr);
253 } 252 }
254 } 253 }
255 254
256 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) { 255 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) {
257 if (mutator_host_client_ == client) 256 if (mutator_host_client_ == client)
258 return; 257 return;
259 258
260 mutator_host_client_ = client; 259 mutator_host_client_ = client;
261 } 260 }
262 261
263 void AnimationHost::SetNeedsCommit() { 262 void AnimationHost::SetNeedsCommit() {
264 DCHECK(mutator_host_client_); 263 DCHECK(mutator_host_client_);
265 mutator_host_client_->SetMutatorsNeedCommit(); 264 mutator_host_client_->SetMutatorsNeedCommit();
266 } 265 }
267 266
268 void AnimationHost::SetNeedsRebuildPropertyTrees() { 267 void AnimationHost::SetNeedsRebuildPropertyTrees() {
269 DCHECK(mutator_host_client_); 268 DCHECK(mutator_host_client_);
270 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees(); 269 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees();
271 } 270 }
272 271
273 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) { 272 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) {
274 PushTimelinesToImplThread(host_impl); 273 PushTimelinesToImplThread(host_impl);
275 RemoveTimelinesFromImplThread(host_impl); 274 RemoveTimelinesFromImplThread(host_impl);
276 PushPropertiesToImplThread(host_impl); 275 PushPropertiesToImplThread(host_impl);
276 animation_waiting_for_deletion_ = false;
277 } 277 }
278 278
279 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { 279 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const {
280 for (auto& kv : id_to_timeline_map_) { 280 for (auto& kv : id_to_timeline_map_) {
281 auto& timeline = kv.second; 281 auto& timeline = kv.second;
282 AnimationTimeline* timeline_impl = 282 AnimationTimeline* timeline_impl =
283 host_impl->GetTimelineById(timeline->id()); 283 host_impl->GetTimelineById(timeline->id());
284 if (timeline_impl) 284 if (timeline_impl)
285 continue; 285 continue;
286 286
(...skipping 12 matching lines...) Expand all
299 if (timeline_impl->is_impl_only() || GetTimelineById(timeline_impl->id())) { 299 if (timeline_impl->is_impl_only() || GetTimelineById(timeline_impl->id())) {
300 ++it; 300 ++it;
301 } else { 301 } else {
302 host_impl->EraseTimeline(it->second); 302 host_impl->EraseTimeline(it->second);
303 it = timelines_impl.erase(it); 303 it = timelines_impl.erase(it);
304 } 304 }
305 } 305 }
306 } 306 }
307 307
308 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) { 308 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) {
309 // Firstly, sync all players with impl thread to create ElementAnimations and 309 // Firstly, sync all players with impl thread to create ElementAnimations.
310 // layer animation controllers.
311 for (auto& kv : id_to_timeline_map_) { 310 for (auto& kv : id_to_timeline_map_) {
312 AnimationTimeline* timeline = kv.second.get(); 311 AnimationTimeline* timeline = kv.second.get();
313 AnimationTimeline* timeline_impl = 312 AnimationTimeline* timeline_impl =
314 host_impl->GetTimelineById(timeline->id()); 313 host_impl->GetTimelineById(timeline->id());
315 if (timeline_impl) 314 if (timeline_impl)
316 timeline->PushPropertiesTo(timeline_impl); 315 timeline->PushPropertiesTo(timeline_impl);
317 } 316 }
318 317
319 // Secondly, sync properties for created layer animation controllers. 318 // Secondly, sync properties for created ElementAnimations.
320 for (auto& kv : layer_to_element_animations_map_) { 319 for (auto& kv : layer_to_element_animations_map_) {
321 const auto& element_animations = kv.second; 320 const auto& element_animations = kv.second;
322 auto element_animations_impl = 321 auto element_animations_impl =
323 host_impl->GetElementAnimationsForLayerId(kv.first); 322 host_impl->GetElementAnimationsForLayerId(kv.first);
324 if (element_animations_impl) 323 if (element_animations_impl)
325 element_animations->PushPropertiesTo(std::move(element_animations_impl)); 324 element_animations->PushPropertiesTo(std::move(element_animations_impl));
326 } 325 }
327 } 326 }
328 327
329 LayerAnimationController* AnimationHost::GetControllerForLayerId(
330 int layer_id) const {
331 const scoped_refptr<ElementAnimations> element_animations =
332 GetElementAnimationsForLayerId(layer_id);
333 if (!element_animations)
334 return nullptr;
335
336 return element_animations->layer_animation_controller_.get();
337 }
338
339 scoped_refptr<ElementAnimations> AnimationHost::GetElementAnimationsForLayerId( 328 scoped_refptr<ElementAnimations> AnimationHost::GetElementAnimationsForLayerId(
340 int layer_id) const { 329 int layer_id) const {
341 DCHECK(layer_id); 330 DCHECK(layer_id);
342 auto iter = layer_to_element_animations_map_.find(layer_id); 331 auto iter = layer_to_element_animations_map_.find(layer_id);
343 return iter == layer_to_element_animations_map_.end() ? nullptr 332 return iter == layer_to_element_animations_map_.end() ? nullptr
344 : iter->second; 333 : iter->second;
345 } 334 }
346 335
347 void AnimationHost::SetSupportsScrollAnimations( 336 void AnimationHost::SetSupportsScrollAnimations(
348 bool supports_scroll_animations) { 337 bool supports_scroll_animations) {
349 supports_scroll_animations_ = supports_scroll_animations; 338 supports_scroll_animations_ = supports_scroll_animations;
350 } 339 }
351 340
352 bool AnimationHost::SupportsScrollAnimations() const { 341 bool AnimationHost::SupportsScrollAnimations() const {
353 return supports_scroll_animations_; 342 return supports_scroll_animations_;
354 } 343 }
355 344
356 bool AnimationHost::NeedsAnimateLayers() const { 345 bool AnimationHost::NeedsAnimateLayers() const {
357 return !active_animation_controllers_.empty(); 346 return !active_element_animations_map_.empty();
358 } 347 }
359 348
360 bool AnimationHost::ActivateAnimations() { 349 bool AnimationHost::ActivateAnimations() {
361 if (!NeedsAnimateLayers()) 350 if (!NeedsAnimateLayers())
362 return false; 351 return false;
363 352
364 TRACE_EVENT0("cc", "AnimationHost::ActivateAnimations"); 353 TRACE_EVENT0("cc", "AnimationHost::ActivateAnimations");
365 AnimationControllerMap active_controllers_copy = 354 LayerToElementAnimationsMap active_element_animations_map_copy =
366 active_animation_controllers_; 355 active_element_animations_map_;
367 for (auto& it : active_controllers_copy) 356 for (auto& it : active_element_animations_map_copy)
368 it.second->ActivateAnimations(); 357 it.second->ActivateAnimations();
369 358
370 return true; 359 return true;
371 } 360 }
372 361
373 bool AnimationHost::AnimateLayers(base::TimeTicks monotonic_time) { 362 bool AnimationHost::AnimateLayers(base::TimeTicks monotonic_time) {
374 if (!NeedsAnimateLayers()) 363 if (!NeedsAnimateLayers())
375 return false; 364 return false;
376 365
377 TRACE_EVENT0("cc", "AnimationHost::AnimateLayers"); 366 TRACE_EVENT0("cc", "AnimationHost::AnimateLayers");
378 AnimationControllerMap controllers_copy = active_animation_controllers_; 367 LayerToElementAnimationsMap active_element_animations_map_copy =
379 for (auto& it : controllers_copy) 368 active_element_animations_map_;
369 for (auto& it : active_element_animations_map_copy)
380 it.second->Animate(monotonic_time); 370 it.second->Animate(monotonic_time);
381 371
382 return true; 372 return true;
383 } 373 }
384 374
385 bool AnimationHost::UpdateAnimationState(bool start_ready_animations, 375 bool AnimationHost::UpdateAnimationState(bool start_ready_animations,
386 AnimationEvents* events) { 376 AnimationEvents* events) {
387 if (!NeedsAnimateLayers()) 377 if (!NeedsAnimateLayers())
388 return false; 378 return false;
389 379
390 TRACE_EVENT0("cc", "AnimationHost::UpdateAnimationState"); 380 TRACE_EVENT0("cc", "AnimationHost::UpdateAnimationState");
391 AnimationControllerMap active_controllers_copy = 381 LayerToElementAnimationsMap active_element_animations_map_copy =
392 active_animation_controllers_; 382 active_element_animations_map_;
393 for (auto& it : active_controllers_copy) 383 for (auto& it : active_element_animations_map_copy)
394 it.second->UpdateState(start_ready_animations, events); 384 it.second->UpdateState(start_ready_animations, events);
395 385
396 return true; 386 return true;
397 } 387 }
398 388
399 std::unique_ptr<AnimationEvents> AnimationHost::CreateEvents() { 389 std::unique_ptr<AnimationEvents> AnimationHost::CreateEvents() {
400 return base::WrapUnique(new AnimationEvents()); 390 return base::WrapUnique(new AnimationEvents());
401 } 391 }
402 392
403 void AnimationHost::SetAnimationEvents( 393 void AnimationHost::SetAnimationEvents(
404 std::unique_ptr<AnimationEvents> events) { 394 std::unique_ptr<AnimationEvents> events) {
405 for (size_t event_index = 0; event_index < events->events_.size(); 395 for (size_t event_index = 0; event_index < events->events_.size();
406 ++event_index) { 396 ++event_index) {
407 int event_layer_id = events->events_[event_index].layer_id; 397 int event_layer_id = events->events_[event_index].layer_id;
408 398
409 // Use the map of all controllers, not just active ones, since non-active 399 // Use the map of all ElementAnimations, not just active ones, since
410 // controllers may still receive events for impl-only animations. 400 // non-active ElementAnimations may still receive events for impl-only
411 const AnimationControllerMap& animation_controllers = 401 // animations.
412 all_animation_controllers_; 402 const LayerToElementAnimationsMap& all_element_animations =
413 auto iter = animation_controllers.find(event_layer_id); 403 layer_to_element_animations_map_;
414 if (iter != animation_controllers.end()) { 404 auto iter = all_element_animations.find(event_layer_id);
405 if (iter != all_element_animations.end()) {
415 switch (events->events_[event_index].type) { 406 switch (events->events_[event_index].type) {
416 case AnimationEvent::STARTED: 407 case AnimationEvent::STARTED:
417 (*iter).second->NotifyAnimationStarted(events->events_[event_index]); 408 (*iter).second->NotifyAnimationStarted(events->events_[event_index]);
418 break; 409 break;
419 410
420 case AnimationEvent::FINISHED: 411 case AnimationEvent::FINISHED:
421 (*iter).second->NotifyAnimationFinished(events->events_[event_index]); 412 (*iter).second->NotifyAnimationFinished(events->events_[event_index]);
422 break; 413 break;
423 414
424 case AnimationEvent::ABORTED: 415 case AnimationEvent::ABORTED:
425 (*iter).second->NotifyAnimationAborted(events->events_[event_index]); 416 (*iter).second->NotifyAnimationAborted(events->events_[event_index]);
426 break; 417 break;
427 418
428 case AnimationEvent::PROPERTY_UPDATE: 419 case AnimationEvent::PROPERTY_UPDATE:
429 (*iter).second->NotifyAnimationPropertyUpdate( 420 (*iter).second->NotifyAnimationPropertyUpdate(
430 events->events_[event_index]); 421 events->events_[event_index]);
431 break; 422 break;
432 423
433 case AnimationEvent::TAKEOVER: 424 case AnimationEvent::TAKEOVER:
434 (*iter).second->NotifyAnimationTakeover(events->events_[event_index]); 425 (*iter).second->NotifyAnimationTakeover(events->events_[event_index]);
435 break; 426 break;
436 } 427 }
437 } 428 }
438 } 429 }
439 } 430 }
440 431
441 bool AnimationHost::ScrollOffsetAnimationWasInterrupted(int layer_id) const { 432 bool AnimationHost::ScrollOffsetAnimationWasInterrupted(int layer_id) const {
442 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 433 auto element_animations = GetElementAnimationsForLayerId(layer_id);
443 return controller ? controller->scroll_offset_animation_was_interrupted() 434 return element_animations
444 : false; 435 ? element_animations->scroll_offset_animation_was_interrupted()
436 : false;
445 } 437 }
446 438
447 static LayerAnimationController::ObserverType ObserverTypeFromTreeType( 439 static ElementAnimations::ObserverType ObserverTypeFromTreeType(
448 LayerTreeType tree_type) { 440 LayerTreeType tree_type) {
449 return tree_type == LayerTreeType::ACTIVE 441 return tree_type == LayerTreeType::ACTIVE
450 ? LayerAnimationController::ObserverType::ACTIVE 442 ? ElementAnimations::ObserverType::ACTIVE
451 : LayerAnimationController::ObserverType::PENDING; 443 : ElementAnimations::ObserverType::PENDING;
452 } 444 }
453 445
454 bool AnimationHost::IsAnimatingFilterProperty(int layer_id, 446 bool AnimationHost::IsAnimatingFilterProperty(int layer_id,
455 LayerTreeType tree_type) const { 447 LayerTreeType tree_type) const {
456 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 448 auto element_animations = GetElementAnimationsForLayerId(layer_id);
457 return controller 449 return element_animations
458 ? controller->IsCurrentlyAnimatingProperty( 450 ? element_animations->IsCurrentlyAnimatingProperty(
459 TargetProperty::FILTER, ObserverTypeFromTreeType(tree_type)) 451 TargetProperty::FILTER, ObserverTypeFromTreeType(tree_type))
460 : false; 452 : false;
461 } 453 }
462 454
463 bool AnimationHost::IsAnimatingOpacityProperty(int layer_id, 455 bool AnimationHost::IsAnimatingOpacityProperty(int layer_id,
464 LayerTreeType tree_type) const { 456 LayerTreeType tree_type) const {
465 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 457 auto element_animations = GetElementAnimationsForLayerId(layer_id);
466 return controller 458 return element_animations
467 ? controller->IsCurrentlyAnimatingProperty( 459 ? element_animations->IsCurrentlyAnimatingProperty(
468 TargetProperty::OPACITY, ObserverTypeFromTreeType(tree_type)) 460 TargetProperty::OPACITY, ObserverTypeFromTreeType(tree_type))
469 : false; 461 : false;
470 } 462 }
471 463
472 bool AnimationHost::IsAnimatingTransformProperty( 464 bool AnimationHost::IsAnimatingTransformProperty(
473 int layer_id, 465 int layer_id,
474 LayerTreeType tree_type) const { 466 LayerTreeType tree_type) const {
475 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 467 auto element_animations = GetElementAnimationsForLayerId(layer_id);
476 return controller 468 return element_animations
477 ? controller->IsCurrentlyAnimatingProperty( 469 ? element_animations->IsCurrentlyAnimatingProperty(
478 TargetProperty::TRANSFORM, 470 TargetProperty::TRANSFORM,
479 ObserverTypeFromTreeType(tree_type)) 471 ObserverTypeFromTreeType(tree_type))
480 : false; 472 : false;
481 } 473 }
482 474
483 bool AnimationHost::HasPotentiallyRunningFilterAnimation( 475 bool AnimationHost::HasPotentiallyRunningFilterAnimation(
484 int layer_id, 476 int layer_id,
485 LayerTreeType tree_type) const { 477 LayerTreeType tree_type) const {
486 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 478 auto element_animations = GetElementAnimationsForLayerId(layer_id);
487 return controller 479 return element_animations
488 ? controller->IsPotentiallyAnimatingProperty( 480 ? element_animations->IsPotentiallyAnimatingProperty(
489 TargetProperty::FILTER, ObserverTypeFromTreeType(tree_type)) 481 TargetProperty::FILTER, ObserverTypeFromTreeType(tree_type))
490 : false; 482 : false;
491 } 483 }
492 484
493 bool AnimationHost::HasPotentiallyRunningOpacityAnimation( 485 bool AnimationHost::HasPotentiallyRunningOpacityAnimation(
494 int layer_id, 486 int layer_id,
495 LayerTreeType tree_type) const { 487 LayerTreeType tree_type) const {
496 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 488 auto element_animations = GetElementAnimationsForLayerId(layer_id);
497 return controller 489 return element_animations
498 ? controller->IsPotentiallyAnimatingProperty( 490 ? element_animations->IsPotentiallyAnimatingProperty(
499 TargetProperty::OPACITY, ObserverTypeFromTreeType(tree_type)) 491 TargetProperty::OPACITY, ObserverTypeFromTreeType(tree_type))
500 : false; 492 : false;
501 } 493 }
502 494
503 bool AnimationHost::HasPotentiallyRunningTransformAnimation( 495 bool AnimationHost::HasPotentiallyRunningTransformAnimation(
504 int layer_id, 496 int layer_id,
505 LayerTreeType tree_type) const { 497 LayerTreeType tree_type) const {
506 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 498 auto element_animations = GetElementAnimationsForLayerId(layer_id);
507 return controller 499 return element_animations
508 ? controller->IsPotentiallyAnimatingProperty( 500 ? element_animations->IsPotentiallyAnimatingProperty(
509 TargetProperty::TRANSFORM, 501 TargetProperty::TRANSFORM,
510 ObserverTypeFromTreeType(tree_type)) 502 ObserverTypeFromTreeType(tree_type))
511 : false; 503 : false;
512 } 504 }
513 505
514 bool AnimationHost::HasAnyAnimationTargetingProperty( 506 bool AnimationHost::HasAnyAnimationTargetingProperty(
515 int layer_id, 507 int layer_id,
516 TargetProperty::Type property) const { 508 TargetProperty::Type property) const {
517 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 509 auto element_animations = GetElementAnimationsForLayerId(layer_id);
518 if (!controller) 510 if (!element_animations)
519 return false; 511 return false;
520 512
521 return !!controller->GetAnimation(property); 513 return !!element_animations->GetAnimation(property);
522 } 514 }
523 515
524 bool AnimationHost::FilterIsAnimatingOnImplOnly(int layer_id) const { 516 bool AnimationHost::FilterIsAnimatingOnImplOnly(int layer_id) const {
525 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 517 auto element_animations = GetElementAnimationsForLayerId(layer_id);
526 if (!controller) 518 if (!element_animations)
527 return false; 519 return false;
528 520
529 Animation* animation = controller->GetAnimation(TargetProperty::FILTER); 521 Animation* animation =
522 element_animations->GetAnimation(TargetProperty::FILTER);
530 return animation && animation->is_impl_only(); 523 return animation && animation->is_impl_only();
531 } 524 }
532 525
533 bool AnimationHost::OpacityIsAnimatingOnImplOnly(int layer_id) const { 526 bool AnimationHost::OpacityIsAnimatingOnImplOnly(int layer_id) const {
534 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 527 auto element_animations = GetElementAnimationsForLayerId(layer_id);
535 if (!controller) 528 if (!element_animations)
536 return false; 529 return false;
537 530
538 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); 531 Animation* animation =
532 element_animations->GetAnimation(TargetProperty::OPACITY);
539 return animation && animation->is_impl_only(); 533 return animation && animation->is_impl_only();
540 } 534 }
541 535
542 bool AnimationHost::ScrollOffsetIsAnimatingOnImplOnly(int layer_id) const { 536 bool AnimationHost::ScrollOffsetIsAnimatingOnImplOnly(int layer_id) const {
543 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 537 auto element_animations = GetElementAnimationsForLayerId(layer_id);
544 if (!controller) 538 if (!element_animations)
545 return false; 539 return false;
546 540
547 Animation* animation = 541 Animation* animation =
548 controller->GetAnimation(TargetProperty::SCROLL_OFFSET); 542 element_animations->GetAnimation(TargetProperty::SCROLL_OFFSET);
549 return animation && animation->is_impl_only(); 543 return animation && animation->is_impl_only();
550 } 544 }
551 545
552 bool AnimationHost::TransformIsAnimatingOnImplOnly(int layer_id) const { 546 bool AnimationHost::TransformIsAnimatingOnImplOnly(int layer_id) const {
553 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 547 auto element_animations = GetElementAnimationsForLayerId(layer_id);
554 if (!controller) 548 if (!element_animations)
555 return false; 549 return false;
556 550
557 Animation* animation = controller->GetAnimation(TargetProperty::TRANSFORM); 551 Animation* animation =
552 element_animations->GetAnimation(TargetProperty::TRANSFORM);
558 return animation && animation->is_impl_only(); 553 return animation && animation->is_impl_only();
559 } 554 }
560 555
561 bool AnimationHost::HasFilterAnimationThatInflatesBounds(int layer_id) const { 556 bool AnimationHost::HasFilterAnimationThatInflatesBounds(int layer_id) const {
562 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 557 auto element_animations = GetElementAnimationsForLayerId(layer_id);
563 return controller ? controller->HasFilterAnimationThatInflatesBounds() 558 return element_animations
564 : false; 559 ? element_animations->HasFilterAnimationThatInflatesBounds()
560 : false;
565 } 561 }
566 562
567 bool AnimationHost::HasTransformAnimationThatInflatesBounds( 563 bool AnimationHost::HasTransformAnimationThatInflatesBounds(
568 int layer_id) const { 564 int layer_id) const {
569 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 565 auto element_animations = GetElementAnimationsForLayerId(layer_id);
570 return controller ? controller->HasTransformAnimationThatInflatesBounds() 566 return element_animations
571 : false; 567 ? element_animations->HasTransformAnimationThatInflatesBounds()
568 : false;
572 } 569 }
573 570
574 bool AnimationHost::HasAnimationThatInflatesBounds(int layer_id) const { 571 bool AnimationHost::HasAnimationThatInflatesBounds(int layer_id) const {
575 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 572 auto element_animations = GetElementAnimationsForLayerId(layer_id);
576 return controller ? controller->HasAnimationThatInflatesBounds() : false; 573 return element_animations
574 ? element_animations->HasAnimationThatInflatesBounds()
575 : false;
577 } 576 }
578 577
579 bool AnimationHost::FilterAnimationBoundsForBox(int layer_id, 578 bool AnimationHost::FilterAnimationBoundsForBox(int layer_id,
580 const gfx::BoxF& box, 579 const gfx::BoxF& box,
581 gfx::BoxF* bounds) const { 580 gfx::BoxF* bounds) const {
582 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 581 auto element_animations = GetElementAnimationsForLayerId(layer_id);
583 return controller ? controller->FilterAnimationBoundsForBox(box, bounds) 582 return element_animations
584 : false; 583 ? element_animations->FilterAnimationBoundsForBox(box, bounds)
584 : false;
585 } 585 }
586 586
587 bool AnimationHost::TransformAnimationBoundsForBox(int layer_id, 587 bool AnimationHost::TransformAnimationBoundsForBox(int layer_id,
588 const gfx::BoxF& box, 588 const gfx::BoxF& box,
589 gfx::BoxF* bounds) const { 589 gfx::BoxF* bounds) const {
590 *bounds = gfx::BoxF(); 590 *bounds = gfx::BoxF();
591 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 591 auto element_animations = GetElementAnimationsForLayerId(layer_id);
592 return controller ? controller->TransformAnimationBoundsForBox(box, bounds) 592 return element_animations
593 : true; 593 ? element_animations->TransformAnimationBoundsForBox(box, bounds)
594 : true;
594 } 595 }
595 596
596 bool AnimationHost::HasOnlyTranslationTransforms( 597 bool AnimationHost::HasOnlyTranslationTransforms(
597 int layer_id, 598 int layer_id,
598 LayerTreeType tree_type) const { 599 LayerTreeType tree_type) const {
599 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 600 auto element_animations = GetElementAnimationsForLayerId(layer_id);
600 return controller 601 return element_animations
601 ? controller->HasOnlyTranslationTransforms( 602 ? element_animations->HasOnlyTranslationTransforms(
602 ObserverTypeFromTreeType(tree_type)) 603 ObserverTypeFromTreeType(tree_type))
603 : true; 604 : true;
604 } 605 }
605 606
606 bool AnimationHost::AnimationsPreserveAxisAlignment(int layer_id) const { 607 bool AnimationHost::AnimationsPreserveAxisAlignment(int layer_id) const {
607 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 608 auto element_animations = GetElementAnimationsForLayerId(layer_id);
608 return controller ? controller->AnimationsPreserveAxisAlignment() : true; 609 return element_animations
610 ? element_animations->AnimationsPreserveAxisAlignment()
611 : true;
609 } 612 }
610 613
611 bool AnimationHost::MaximumTargetScale(int layer_id, 614 bool AnimationHost::MaximumTargetScale(int layer_id,
612 LayerTreeType tree_type, 615 LayerTreeType tree_type,
613 float* max_scale) const { 616 float* max_scale) const {
614 *max_scale = 0.f; 617 *max_scale = 0.f;
615 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 618 auto element_animations = GetElementAnimationsForLayerId(layer_id);
616 return controller 619 return element_animations
617 ? controller->MaximumTargetScale( 620 ? element_animations->MaximumTargetScale(
618 ObserverTypeFromTreeType(tree_type), max_scale) 621 ObserverTypeFromTreeType(tree_type), max_scale)
619 : true; 622 : true;
620 } 623 }
621 624
622 bool AnimationHost::AnimationStartScale(int layer_id, 625 bool AnimationHost::AnimationStartScale(int layer_id,
623 LayerTreeType tree_type, 626 LayerTreeType tree_type,
624 float* start_scale) const { 627 float* start_scale) const {
625 *start_scale = 0.f; 628 *start_scale = 0.f;
626 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 629 auto element_animations = GetElementAnimationsForLayerId(layer_id);
627 return controller 630 return element_animations
628 ? controller->AnimationStartScale( 631 ? element_animations->AnimationStartScale(
629 ObserverTypeFromTreeType(tree_type), start_scale) 632 ObserverTypeFromTreeType(tree_type), start_scale)
630 : true; 633 : true;
631 } 634 }
632 635
633 bool AnimationHost::HasAnyAnimation(int layer_id) const { 636 bool AnimationHost::HasAnyAnimation(int layer_id) const {
634 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 637 auto element_animations = GetElementAnimationsForLayerId(layer_id);
635 return controller ? controller->has_any_animation() : false; 638 return element_animations ? element_animations->has_any_animation() : false;
636 } 639 }
637 640
638 bool AnimationHost::HasActiveAnimationForTesting(int layer_id) const { 641 bool AnimationHost::HasActiveAnimationForTesting(int layer_id) const {
639 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 642 auto element_animations = GetElementAnimationsForLayerId(layer_id);
640 return controller ? controller->HasActiveAnimation() : false; 643 return element_animations ? element_animations->HasActiveAnimation() : false;
641 } 644 }
642 645
643 void AnimationHost::ImplOnlyScrollAnimationCreate( 646 void AnimationHost::ImplOnlyScrollAnimationCreate(
644 int layer_id, 647 int layer_id,
645 const gfx::ScrollOffset& target_offset, 648 const gfx::ScrollOffset& target_offset,
646 const gfx::ScrollOffset& current_offset) { 649 const gfx::ScrollOffset& current_offset) {
647 DCHECK(scroll_offset_animations_); 650 DCHECK(scroll_offset_animations_);
648 scroll_offset_animations_->ScrollAnimationCreate(layer_id, target_offset, 651 scroll_offset_animations_->ScrollAnimationCreate(layer_id, target_offset,
649 current_offset); 652 current_offset);
650 } 653 }
651 654
652 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget( 655 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget(
653 int layer_id, 656 int layer_id,
654 const gfx::Vector2dF& scroll_delta, 657 const gfx::Vector2dF& scroll_delta,
655 const gfx::ScrollOffset& max_scroll_offset, 658 const gfx::ScrollOffset& max_scroll_offset,
656 base::TimeTicks frame_monotonic_time) { 659 base::TimeTicks frame_monotonic_time) {
657 DCHECK(scroll_offset_animations_); 660 DCHECK(scroll_offset_animations_);
658 return scroll_offset_animations_->ScrollAnimationUpdateTarget( 661 return scroll_offset_animations_->ScrollAnimationUpdateTarget(
659 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time); 662 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time);
660 } 663 }
661 664
662 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { 665 void AnimationHost::ScrollAnimationAbort(bool needs_completion) {
663 DCHECK(scroll_offset_animations_); 666 DCHECK(scroll_offset_animations_);
664 return scroll_offset_animations_->ScrollAnimationAbort(needs_completion); 667 return scroll_offset_animations_->ScrollAnimationAbort(needs_completion);
665 } 668 }
666 669
667 scoped_refptr<LayerAnimationController> 670 void AnimationHost::DidActivateElementAnimations(
668 AnimationHost::GetAnimationControllerForId(int id) { 671 ElementAnimations* element_animations) {
669 scoped_refptr<LayerAnimationController> to_return; 672 DCHECK(element_animations->layer_id());
670 if (!ContainsKey(all_animation_controllers_, id)) { 673 active_element_animations_map_[element_animations->layer_id()] =
671 to_return = LayerAnimationController::Create(id); 674 element_animations;
672 to_return->SetAnimationHost(this);
673 all_animation_controllers_[id] = to_return.get();
674 } else {
675 to_return = all_animation_controllers_[id];
676 }
677 return to_return;
678 } 675 }
679 676
680 void AnimationHost::DidActivateAnimationController( 677 void AnimationHost::DidDeactivateElementAnimations(
681 LayerAnimationController* controller) { 678 ElementAnimations* element_animations) {
682 active_animation_controllers_[controller->id()] = controller; 679 DCHECK(element_animations->layer_id());
680 active_element_animations_map_.erase(element_animations->layer_id());
683 } 681 }
684 682
685 void AnimationHost::DidDeactivateAnimationController( 683 void AnimationHost::RegisterElementAnimations(
686 LayerAnimationController* controller) { 684 ElementAnimations* element_animations) {
687 if (ContainsKey(active_animation_controllers_, controller->id())) 685 DCHECK(element_animations->layer_id());
688 active_animation_controllers_.erase(controller->id()); 686 layer_to_element_animations_map_[element_animations->layer_id()] =
687 element_animations;
689 } 688 }
690 689
691 void AnimationHost::RegisterAnimationController( 690 void AnimationHost::UnregisterElementAnimations(
692 LayerAnimationController* controller) { 691 ElementAnimations* element_animations) {
693 all_animation_controllers_[controller->id()] = controller; 692 DCHECK(element_animations->layer_id());
693 layer_to_element_animations_map_.erase(element_animations->layer_id());
694 DidDeactivateElementAnimations(element_animations);
694 } 695 }
695 696
696 void AnimationHost::UnregisterAnimationController( 697 const AnimationHost::LayerToElementAnimationsMap&
697 LayerAnimationController* controller) { 698 AnimationHost::active_element_animations_for_testing() const {
698 if (ContainsKey(all_animation_controllers_, controller->id())) 699 return active_element_animations_map_;
699 all_animation_controllers_.erase(controller->id());
700 DidDeactivateAnimationController(controller);
701 } 700 }
702 701
703 const AnimationHost::AnimationControllerMap& 702 const AnimationHost::LayerToElementAnimationsMap&
704 AnimationHost::active_animation_controllers_for_testing() const { 703 AnimationHost::all_element_animations_for_testing() const {
705 return active_animation_controllers_; 704 return layer_to_element_animations_map_;
706 } 705 }
707 706
708 const AnimationHost::AnimationControllerMap& 707 void AnimationHost::OnAnimationWaitingForDeletion() {
709 AnimationHost::all_animation_controllers_for_testing() const { 708 animation_waiting_for_deletion_ = true;
710 return all_animation_controllers_;
711 } 709 }
712 710
713 } // namespace cc 711 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_player.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698