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

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

Issue 2291463003: Revert "CC Animation: Introduce some dirty flags to optimize PushProperties on commit" (Closed)
Patch Set: Created 4 years, 3 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_host_perftest.cc » ('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"
(...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 needs_push_properties_(false) { 46 animation_waiting_for_deletion_(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();
95 } 94 }
96 95
97 void AnimationHost::RemoveAnimationTimeline( 96 void AnimationHost::RemoveAnimationTimeline(
98 scoped_refptr<AnimationTimeline> timeline) { 97 scoped_refptr<AnimationTimeline> timeline) {
99 DCHECK(timeline->id()); 98 DCHECK(timeline->id());
100 EraseTimeline(timeline); 99 EraseTimeline(timeline);
101 id_to_timeline_map_.erase(timeline->id()); 100 id_to_timeline_map_.erase(timeline->id());
102 SetNeedsPushProperties();
103 } 101 }
104 102
105 void AnimationHost::RegisterElement(ElementId element_id, 103 void AnimationHost::RegisterElement(ElementId element_id,
106 ElementListType list_type) { 104 ElementListType list_type) {
107 scoped_refptr<ElementAnimations> element_animations = 105 scoped_refptr<ElementAnimations> element_animations =
108 GetElementAnimationsForElementId(element_id); 106 GetElementAnimationsForElementId(element_id);
109 if (element_animations) 107 if (element_animations)
110 element_animations->ElementRegistered(element_id, list_type); 108 element_animations->ElementRegistered(element_id, list_type);
111 } 109 }
112 110
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 UnregisterElementAnimations(element_animations.get()); 152 UnregisterElementAnimations(element_animations.get());
155 element_animations->SetAnimationHost(nullptr); 153 element_animations->SetAnimationHost(nullptr);
156 } 154 }
157 } 155 }
158 156
159 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) { 157 void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) {
160 if (mutator_host_client_ == client) 158 if (mutator_host_client_ == client)
161 return; 159 return;
162 160
163 mutator_host_client_ = client; 161 mutator_host_client_ = client;
164
165 if (needs_push_properties() && mutator_host_client())
166 SetNeedsPushProperties();
167 } 162 }
168 163
169 void AnimationHost::SetNeedsPushProperties() { 164 void AnimationHost::SetNeedsCommit() {
170 if (mutator_host_client_) { 165 DCHECK(mutator_host_client_);
171 mutator_host_client_->SetMutatorsNeedCommit(); 166 mutator_host_client_->SetMutatorsNeedCommit();
172 // TODO(loyso): Invalidate property trees only if really needed. 167 }
173 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees(); 168
174 } 169 void AnimationHost::SetNeedsRebuildPropertyTrees() {
175 needs_push_properties_ = true; 170 DCHECK(mutator_host_client_);
171 mutator_host_client_->SetMutatorsNeedRebuildPropertyTrees();
176 } 172 }
177 173
178 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) { 174 void AnimationHost::PushPropertiesTo(AnimationHost* host_impl) {
179 if (needs_push_properties_) { 175 PushTimelinesToImplThread(host_impl);
180 needs_push_properties_ = false; 176 RemoveTimelinesFromImplThread(host_impl);
181 PushTimelinesToImplThread(host_impl); 177 PushPropertiesToImplThread(host_impl);
182 RemoveTimelinesFromImplThread(host_impl); 178 animation_waiting_for_deletion_ = false;
183 PushPropertiesToImplThread(host_impl);
184 // This is redundant but used in tests.
185 host_impl->needs_push_properties_ = false;
186 }
187 } 179 }
188 180
189 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const { 181 void AnimationHost::PushTimelinesToImplThread(AnimationHost* host_impl) const {
190 for (auto& kv : id_to_timeline_map_) { 182 for (auto& kv : id_to_timeline_map_) {
191 auto& timeline = kv.second; 183 auto& timeline = kv.second;
192 AnimationTimeline* timeline_impl = 184 AnimationTimeline* timeline_impl =
193 host_impl->GetTimelineById(timeline->id()); 185 host_impl->GetTimelineById(timeline->id());
194 if (timeline_impl) 186 if (timeline_impl)
195 continue; 187 continue;
196 188
(...skipping 16 matching lines...) Expand all
213 it = timelines_impl.erase(it); 205 it = timelines_impl.erase(it);
214 } 206 }
215 } 207 }
216 } 208 }
217 209
218 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) { 210 void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) {
219 // Sync all players with impl thread to create ElementAnimations. This needs 211 // Sync all players with impl thread to create ElementAnimations. This needs
220 // to happen before the element animations are synced below. 212 // to happen before the element animations are synced below.
221 for (auto& kv : id_to_timeline_map_) { 213 for (auto& kv : id_to_timeline_map_) {
222 AnimationTimeline* timeline = kv.second.get(); 214 AnimationTimeline* timeline = kv.second.get();
223 if (timeline->needs_push_properties()) { 215 AnimationTimeline* timeline_impl =
224 AnimationTimeline* timeline_impl = 216 host_impl->GetTimelineById(timeline->id());
225 host_impl->GetTimelineById(timeline->id()); 217 if (timeline_impl)
226 if (timeline_impl) 218 timeline->PushPropertiesTo(timeline_impl);
227 timeline->PushPropertiesTo(timeline_impl);
228 }
229 } 219 }
230 220
231 // Sync properties for created ElementAnimations. 221 // Sync properties for created ElementAnimations.
232 for (auto& kv : element_to_animations_map_) { 222 for (auto& kv : element_to_animations_map_) {
233 const auto& element_animations = kv.second; 223 const auto& element_animations = kv.second;
234 if (element_animations->needs_push_properties()) { 224 auto element_animations_impl =
235 auto element_animations_impl = 225 host_impl->GetElementAnimationsForElementId(kv.first);
236 host_impl->GetElementAnimationsForElementId(kv.first); 226 if (element_animations_impl)
237 if (element_animations_impl) 227 element_animations->PushPropertiesTo(std::move(element_animations_impl));
238 element_animations->PushPropertiesTo(
239 std::move(element_animations_impl));
240 }
241 } 228 }
242 229
243 // Update the impl-only scroll offset animations. 230 // Update the impl-only scroll offset animations.
244 scroll_offset_animations_->PushPropertiesTo( 231 scroll_offset_animations_->PushPropertiesTo(
245 host_impl->scroll_offset_animations_impl_.get()); 232 host_impl->scroll_offset_animations_impl_.get());
246 } 233 }
247 234
248 scoped_refptr<ElementAnimations> 235 scoped_refptr<ElementAnimations>
249 AnimationHost::GetElementAnimationsForElementId(ElementId element_id) const { 236 AnimationHost::GetElementAnimationsForElementId(ElementId element_id) const {
250 if (!element_id) 237 if (!element_id)
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 const AnimationHost::ElementToAnimationsMap& 561 const AnimationHost::ElementToAnimationsMap&
575 AnimationHost::active_element_animations_for_testing() const { 562 AnimationHost::active_element_animations_for_testing() const {
576 return active_element_to_animations_map_; 563 return active_element_to_animations_map_;
577 } 564 }
578 565
579 const AnimationHost::ElementToAnimationsMap& 566 const AnimationHost::ElementToAnimationsMap&
580 AnimationHost::all_element_animations_for_testing() const { 567 AnimationHost::all_element_animations_for_testing() const {
581 return element_to_animations_map_; 568 return element_to_animations_map_;
582 } 569 }
583 570
571 void AnimationHost::OnAnimationWaitingForDeletion() {
572 animation_waiting_for_deletion_ = true;
573 }
574
584 } // namespace cc 575 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_host_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698