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

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

Powered by Google App Engine
This is Rietveld 408576698