| OLD | NEW |
| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 if (thread_instance == ThreadInstance::IMPL) | 36 if (thread_instance == ThreadInstance::IMPL) |
| 37 animation_host->SetSupportsScrollAnimations(true); | 37 animation_host->SetSupportsScrollAnimations(true); |
| 38 | 38 |
| 39 return animation_host; | 39 return animation_host; |
| 40 } | 40 } |
| 41 | 41 |
| 42 AnimationHost::AnimationHost(ThreadInstance thread_instance) | 42 AnimationHost::AnimationHost(ThreadInstance thread_instance) |
| 43 : mutator_host_client_(nullptr), | 43 : mutator_host_client_(nullptr), |
| 44 thread_instance_(thread_instance), | 44 thread_instance_(thread_instance), |
| 45 supports_scroll_animations_(false), | 45 supports_scroll_animations_(false), |
| 46 animation_waiting_for_deletion_(false) { | 46 needs_push_properties_(false) { |
| 47 if (thread_instance_ == ThreadInstance::IMPL) { | 47 if (thread_instance_ == ThreadInstance::IMPL) { |
| 48 scroll_offset_animations_impl_ = | 48 scroll_offset_animations_impl_ = |
| 49 base::WrapUnique(new ScrollOffsetAnimationsImpl(this)); | 49 base::WrapUnique(new ScrollOffsetAnimationsImpl(this)); |
| 50 } else { | 50 } else { |
| 51 scroll_offset_animations_ = | 51 scroll_offset_animations_ = |
| 52 base::WrapUnique(new ScrollOffsetAnimations(this)); | 52 base::WrapUnique(new ScrollOffsetAnimations(this)); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 AnimationHost::~AnimationHost() { | 56 AnimationHost::~AnimationHost() { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 85 timeline->ClearPlayers(); | 85 timeline->ClearPlayers(); |
| 86 timeline->SetAnimationHost(nullptr); | 86 timeline->SetAnimationHost(nullptr); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void AnimationHost::AddAnimationTimeline( | 89 void AnimationHost::AddAnimationTimeline( |
| 90 scoped_refptr<AnimationTimeline> timeline) { | 90 scoped_refptr<AnimationTimeline> timeline) { |
| 91 DCHECK(timeline->id()); | 91 DCHECK(timeline->id()); |
| 92 timeline->SetAnimationHost(this); | 92 timeline->SetAnimationHost(this); |
| 93 id_to_timeline_map_.insert( | 93 id_to_timeline_map_.insert( |
| 94 std::make_pair(timeline->id(), std::move(timeline))); | 94 std::make_pair(timeline->id(), std::move(timeline))); |
| 95 SetNeedsPushProperties(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void AnimationHost::RemoveAnimationTimeline( | 98 void AnimationHost::RemoveAnimationTimeline( |
| 98 scoped_refptr<AnimationTimeline> timeline) { | 99 scoped_refptr<AnimationTimeline> timeline) { |
| 99 DCHECK(timeline->id()); | 100 DCHECK(timeline->id()); |
| 100 EraseTimeline(timeline); | 101 EraseTimeline(timeline); |
| 101 id_to_timeline_map_.erase(timeline->id()); | 102 id_to_timeline_map_.erase(timeline->id()); |
| 103 SetNeedsPushProperties(); |
| 102 } | 104 } |
| 103 | 105 |
| 104 void AnimationHost::RegisterElement(ElementId element_id, | 106 void AnimationHost::RegisterElement(ElementId element_id, |
| 105 ElementListType list_type) { | 107 ElementListType list_type) { |
| 106 scoped_refptr<ElementAnimations> element_animations = | 108 scoped_refptr<ElementAnimations> element_animations = |
| 107 GetElementAnimationsForElementId(element_id); | 109 GetElementAnimationsForElementId(element_id); |
| 108 if (element_animations) | 110 if (element_animations) |
| 109 element_animations->ElementRegistered(element_id, list_type); | 111 element_animations->ElementRegistered(element_id, list_type); |
| 110 } | 112 } |
| 111 | 113 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 UnregisterElementAnimations(element_animations.get()); | 155 UnregisterElementAnimations(element_animations.get()); |
| 154 element_animations->SetAnimationHost(nullptr); | 156 element_animations->SetAnimationHost(nullptr); |
| 155 } | 157 } |
| 156 } | 158 } |
| 157 | 159 |
| 158 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) { | 160 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) { |
| 159 if (mutator_host_client_ == client) | 161 if (mutator_host_client_ == client) |
| 160 return; | 162 return; |
| 161 | 163 |
| 162 mutator_host_client_ = client; | 164 mutator_host_client_ = client; |
| 165 |
| 166 if (needs_push_properties() && mutator_host_client()) |
| 167 SetNeedsPushProperties(); |
| 163 } | 168 } |
| 164 | 169 |
| 165 void AnimationHost::SetNeedsCommit() { | 170 void AnimationHost::SetNeedsPushProperties() { |
| 166 DCHECK(mutator_host_client_); | 171 if (mutator_host_client_) { |
| 167 mutator_host_client_->SetMutatorsNeedCommit(); | 172 mutator_host_client_->SetMutatorsNeedCommit(); |
| 168 } | 173 // TODO(loyso): Invalidate property trees only if really needed. |
| 169 | 174 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees(); |
| 170 void AnimationHost::SetNeedsRebuildPropertyTrees() { | 175 } |
| 171 DCHECK(mutator_host_client_); | 176 needs_push_properties_ = true; |
| 172 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees(); | |
| 173 } | 177 } |
| 174 | 178 |
| 175 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) { | 179 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) { |
| 176 PushTimelinesToImplThread(host_impl); | 180 if (needs_push_properties_) { |
| 177 RemoveTimelinesFromImplThread(host_impl); | 181 needs_push_properties_ = false; |
| 178 PushPropertiesToImplThread(host_impl); | 182 PushTimelinesToImplThread(host_impl); |
| 179 animation_waiting_for_deletion_ = false; | 183 RemoveTimelinesFromImplThread(host_impl); |
| 184 PushPropertiesToImplThread(host_impl); |
| 185 // This is redundant but used in tests. |
| 186 host_impl->needs_push_properties_ = false; |
| 187 } |
| 180 } | 188 } |
| 181 | 189 |
| 182 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { | 190 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { |
| 183 for (auto& kv : id_to_timeline_map_) { | 191 for (auto& kv : id_to_timeline_map_) { |
| 184 auto& timeline = kv.second; | 192 auto& timeline = kv.second; |
| 185 AnimationTimeline* timeline_impl = | 193 AnimationTimeline* timeline_impl = |
| 186 host_impl->GetTimelineById(timeline->id()); | 194 host_impl->GetTimelineById(timeline->id()); |
| 187 if (timeline_impl) | 195 if (timeline_impl) |
| 188 continue; | 196 continue; |
| 189 | 197 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 206 it = timelines_impl.erase(it); | 214 it = timelines_impl.erase(it); |
| 207 } | 215 } |
| 208 } | 216 } |
| 209 } | 217 } |
| 210 | 218 |
| 211 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) { | 219 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) { |
| 212 // Sync all players with impl thread to create ElementAnimations. This needs | 220 // Sync all players with impl thread to create ElementAnimations. This needs |
| 213 // to happen before the element animations are synced below. | 221 // to happen before the element animations are synced below. |
| 214 for (auto& kv : id_to_timeline_map_) { | 222 for (auto& kv : id_to_timeline_map_) { |
| 215 AnimationTimeline* timeline = kv.second.get(); | 223 AnimationTimeline* timeline = kv.second.get(); |
| 216 AnimationTimeline* timeline_impl = | 224 if (timeline->needs_push_properties()) { |
| 217 host_impl->GetTimelineById(timeline->id()); | 225 AnimationTimeline* timeline_impl = |
| 218 if (timeline_impl) | 226 host_impl->GetTimelineById(timeline->id()); |
| 219 timeline->PushPropertiesTo(timeline_impl); | 227 if (timeline_impl) |
| 228 timeline->PushPropertiesTo(timeline_impl); |
| 229 } |
| 220 } | 230 } |
| 221 | 231 |
| 222 // Sync properties for created ElementAnimations. | 232 // Sync properties for created ElementAnimations. |
| 223 for (auto& kv : element_to_animations_map_) { | 233 for (auto& kv : element_to_animations_map_) { |
| 224 const auto& element_animations = kv.second; | 234 const auto& element_animations = kv.second; |
| 225 auto element_animations_impl = | 235 if (element_animations->needs_push_properties()) { |
| 226 host_impl->GetElementAnimationsForElementId(kv.first); | 236 auto element_animations_impl = |
| 227 if (element_animations_impl) | 237 host_impl->GetElementAnimationsForElementId(kv.first); |
| 228 element_animations->PushPropertiesTo(std::move(element_animations_impl)); | 238 if (element_animations_impl) |
| 239 element_animations->PushPropertiesTo( |
| 240 std::move(element_animations_impl)); |
| 241 } |
| 229 } | 242 } |
| 230 | 243 |
| 231 // Update the impl-only scroll offset animations. | 244 // Update the impl-only scroll offset animations. |
| 232 scroll_offset_animations_->PushPropertiesTo( | 245 scroll_offset_animations_->PushPropertiesTo( |
| 233 host_impl->scroll_offset_animations_impl_.get()); | 246 host_impl->scroll_offset_animations_impl_.get()); |
| 234 } | 247 } |
| 235 | 248 |
| 236 scoped_refptr<ElementAnimations> | 249 scoped_refptr<ElementAnimations> |
| 237 AnimationHost::GetElementAnimationsForElementId(ElementId element_id) const { | 250 AnimationHost::GetElementAnimationsForElementId(ElementId element_id) const { |
| 238 if (!element_id) | 251 if (!element_id) |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 const AnimationHost::ElementToAnimationsMap& | 575 const AnimationHost::ElementToAnimationsMap& |
| 563 AnimationHost::active_element_animations_for_testing() const { | 576 AnimationHost::active_element_animations_for_testing() const { |
| 564 return active_element_to_animations_map_; | 577 return active_element_to_animations_map_; |
| 565 } | 578 } |
| 566 | 579 |
| 567 const AnimationHost::ElementToAnimationsMap& | 580 const AnimationHost::ElementToAnimationsMap& |
| 568 AnimationHost::all_element_animations_for_testing() const { | 581 AnimationHost::all_element_animations_for_testing() const { |
| 569 return element_to_animations_map_; | 582 return element_to_animations_map_; |
| 570 } | 583 } |
| 571 | 584 |
| 572 void AnimationHost::OnAnimationWaitingForDeletion() { | |
| 573 animation_waiting_for_deletion_ = true; | |
| 574 } | |
| 575 | |
| 576 } // namespace cc | 585 } // namespace cc |
| OLD | NEW |