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

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

Issue 2261113002: CC Animation: Introduce some dirty flags to optimize PushProperties on commit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add more tests. Created 4 years, 4 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"
(...skipping 25 matching lines...) Expand all
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
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
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::SetNeedsPushProperties() {
165 DCHECK(mutator_host_client_); 170 if (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 173 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees();
169 void AnimationHost::SetNeedsRebuildPropertyTrees() { 174 }
170 DCHECK(mutator_host_client_); 175 needs_push_properties_ = true;
171 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees();
172 } 176 }
173 177
174 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) { 178 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) {
175 PushTimelinesToImplThread(host_impl); 179 if (needs_push_properties_) {
176 RemoveTimelinesFromImplThread(host_impl); 180 needs_push_properties_ = false;
177 PushPropertiesToImplThread(host_impl); 181 PushTimelinesToImplThread(host_impl);
178 animation_waiting_for_deletion_ = false; 182 RemoveTimelinesFromImplThread(host_impl);
183 PushPropertiesToImplThread(host_impl);
184 // This is redundant but used in tests.
185 host_impl->needs_push_properties_ = false;
186 }
179 } 187 }
180 188
181 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { 189 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const {
182 for (auto& kv : id_to_timeline_map_) { 190 for (auto& kv : id_to_timeline_map_) {
183 auto& timeline = kv.second; 191 auto& timeline = kv.second;
184 AnimationTimeline* timeline_impl = 192 AnimationTimeline* timeline_impl =
185 host_impl->GetTimelineById(timeline->id()); 193 host_impl->GetTimelineById(timeline->id());
186 if (timeline_impl) 194 if (timeline_impl)
187 continue; 195 continue;
188 196
(...skipping 16 matching lines...) Expand all
205 it = timelines_impl.erase(it); 213 it = timelines_impl.erase(it);
206 } 214 }
207 } 215 }
208 } 216 }
209 217
210 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) { 218 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) {
211 // Sync all players with impl thread to create ElementAnimations. This needs 219 // Sync all players with impl thread to create ElementAnimations. This needs
212 // to happen before the element animations are synced below. 220 // to happen before the element animations are synced below.
213 for (auto& kv : id_to_timeline_map_) { 221 for (auto& kv : id_to_timeline_map_) {
214 AnimationTimeline* timeline = kv.second.get(); 222 AnimationTimeline* timeline = kv.second.get();
215 AnimationTimeline* timeline_impl = 223 if (timeline->needs_push_properties()) {
216 host_impl->GetTimelineById(timeline->id()); 224 AnimationTimeline* timeline_impl =
217 if (timeline_impl) 225 host_impl->GetTimelineById(timeline->id());
218 timeline->PushPropertiesTo(timeline_impl); 226 if (timeline_impl)
227 timeline->PushPropertiesTo(timeline_impl);
228 }
219 } 229 }
220 230
221 // Sync properties for created ElementAnimations. 231 // Sync properties for created ElementAnimations.
222 for (auto& kv : element_to_animations_map_) { 232 for (auto& kv : element_to_animations_map_) {
223 const auto& element_animations = kv.second; 233 const auto& element_animations = kv.second;
224 auto element_animations_impl = 234 if (element_animations->needs_push_properties()) {
225 host_impl->GetElementAnimationsForElementId(kv.first); 235 auto element_animations_impl =
226 if (element_animations_impl) 236 host_impl->GetElementAnimationsForElementId(kv.first);
227 element_animations->PushPropertiesTo(std::move(element_animations_impl)); 237 if (element_animations_impl)
238 element_animations->PushPropertiesTo(
239 std::move(element_animations_impl));
240 }
228 } 241 }
229 242
230 // Update the impl-only scroll offset animations. 243 // Update the impl-only scroll offset animations.
231 scroll_offset_animations_->PushPropertiesTo( 244 scroll_offset_animations_->PushPropertiesTo(
232 host_impl->scroll_offset_animations_impl_.get()); 245 host_impl->scroll_offset_animations_impl_.get());
233 } 246 }
234 247
235 scoped_refptr<ElementAnimations> 248 scoped_refptr<ElementAnimations>
236 AnimationHost::GetElementAnimationsForElementId(ElementId element_id) const { 249 AnimationHost::GetElementAnimationsForElementId(ElementId element_id) const {
237 if (!element_id) 250 if (!element_id)
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 const AnimationHost::ElementToAnimationsMap& 574 const AnimationHost::ElementToAnimationsMap&
562 AnimationHost::active_element_animations_for_testing() const { 575 AnimationHost::active_element_animations_for_testing() const {
563 return active_element_to_animations_map_; 576 return active_element_to_animations_map_;
564 } 577 }
565 578
566 const AnimationHost::ElementToAnimationsMap& 579 const AnimationHost::ElementToAnimationsMap&
567 AnimationHost::all_element_animations_for_testing() const { 580 AnimationHost::all_element_animations_for_testing() const {
568 return element_to_animations_map_; 581 return element_to_animations_map_;
569 } 582 }
570 583
571 void AnimationHost::OnAnimationWaitingForDeletion() {
572 animation_waiting_for_deletion_ = true;
573 }
574
575 } // namespace cc 584 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698