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