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

Side by Side Diff: cc/animation/animation_player.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_player.h ('k') | cc/animation/animation_player_unittest.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_player.h" 5 #include "cc/animation/animation_player.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "cc/animation/animation_delegate.h" 9 #include "cc/animation/animation_delegate.h"
10 #include "cc/animation/animation_host.h" 10 #include "cc/animation/animation_host.h"
11 #include "cc/animation/animation_timeline.h" 11 #include "cc/animation/animation_timeline.h"
12 #include "cc/animation/element_animations.h" 12 #include "cc/animation/element_animations.h"
13 13
14 namespace cc { 14 namespace cc {
15 15
16 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) { 16 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) {
17 return make_scoped_refptr(new AnimationPlayer(id)); 17 return make_scoped_refptr(new AnimationPlayer(id));
18 } 18 }
19 19
20 AnimationPlayer::AnimationPlayer(int id) 20 AnimationPlayer::AnimationPlayer(int id)
21 : animation_host_(), 21 : animation_host_(),
22 animation_timeline_(), 22 animation_timeline_(),
23 element_animations_(), 23 element_animations_(),
24 animation_delegate_(), 24 animation_delegate_(),
25 id_(id), 25 id_(id) {
26 needs_push_properties_(false) {
27 DCHECK(id_); 26 DCHECK(id_);
28 } 27 }
29 28
30 AnimationPlayer::~AnimationPlayer() { 29 AnimationPlayer::~AnimationPlayer() {
31 DCHECK(!animation_timeline_); 30 DCHECK(!animation_timeline_);
32 DCHECK(!element_animations_); 31 DCHECK(!element_animations_);
33 } 32 }
34 33
35 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const { 34 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const {
36 scoped_refptr<AnimationPlayer> player = AnimationPlayer::Create(id()); 35 scoped_refptr<AnimationPlayer> player = AnimationPlayer::Create(id());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 animation_host_->UnregisterPlayerForElement(element_id_, this); 97 animation_host_->UnregisterPlayerForElement(element_id_, this);
99 } 98 }
100 99
101 void AnimationPlayer::BindElementAnimations() { 100 void AnimationPlayer::BindElementAnimations() {
102 DCHECK(!element_animations_); 101 DCHECK(!element_animations_);
103 element_animations_ = 102 element_animations_ =
104 animation_host_->GetElementAnimationsForElementId(element_id_); 103 animation_host_->GetElementAnimationsForElementId(element_id_);
105 DCHECK(element_animations_); 104 DCHECK(element_animations_);
106 105
107 // Pass all accumulated animations to ElementAnimations. 106 // Pass all accumulated animations to ElementAnimations.
108 for (auto& animation : animations_) 107 for (auto& animation : animations_) {
109 element_animations_->AddAnimation(std::move(animation)); 108 element_animations_->AddAnimation(std::move(animation));
109 }
110 if (!animations_.empty())
111 SetNeedsCommit();
110 animations_.clear(); 112 animations_.clear();
111
112 SetNeedsPushProperties();
113 } 113 }
114 114
115 void AnimationPlayer::UnbindElementAnimations() { 115 void AnimationPlayer::UnbindElementAnimations() {
116 SetNeedsPushProperties();
117
118 element_animations_ = nullptr; 116 element_animations_ = nullptr;
119 DCHECK(animations_.empty()); 117 DCHECK(animations_.empty());
120 } 118 }
121 119
122 void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) { 120 void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) {
123 DCHECK(animation->target_property() != TargetProperty::SCROLL_OFFSET || 121 DCHECK(animation->target_property() != TargetProperty::SCROLL_OFFSET ||
124 (animation_host_ && animation_host_->SupportsScrollAnimations())); 122 (animation_host_ && animation_host_->SupportsScrollAnimations()));
125 123
126 if (element_animations_) { 124 if (element_animations_) {
127 element_animations_->AddAnimation(std::move(animation)); 125 element_animations_->AddAnimation(std::move(animation));
128 SetNeedsPushProperties(); 126 SetNeedsCommit();
129 } else { 127 } else {
130 animations_.push_back(std::move(animation)); 128 animations_.push_back(std::move(animation));
131 } 129 }
132 } 130 }
133 131
134 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) { 132 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) {
135 DCHECK(element_animations_); 133 DCHECK(element_animations_);
136 element_animations_->PauseAnimation( 134 element_animations_->PauseAnimation(
137 animation_id, base::TimeDelta::FromSecondsD(time_offset)); 135 animation_id, base::TimeDelta::FromSecondsD(time_offset));
138 SetNeedsPushProperties(); 136 SetNeedsCommit();
139 } 137 }
140 138
141 void AnimationPlayer::RemoveAnimation(int animation_id) { 139 void AnimationPlayer::RemoveAnimation(int animation_id) {
142 if (element_animations_) { 140 if (element_animations_) {
143 element_animations_->RemoveAnimation(animation_id); 141 element_animations_->RemoveAnimation(animation_id);
144 SetNeedsPushProperties(); 142 SetNeedsCommit();
145 } else { 143 } else {
146 auto animations_to_remove = std::remove_if( 144 auto animations_to_remove = std::remove_if(
147 animations_.begin(), animations_.end(), 145 animations_.begin(), animations_.end(),
148 [animation_id](const std::unique_ptr<Animation>& animation) { 146 [animation_id](const std::unique_ptr<Animation>& animation) {
149 return animation->id() == animation_id; 147 return animation->id() == animation_id;
150 }); 148 });
151 animations_.erase(animations_to_remove, animations_.end()); 149 animations_.erase(animations_to_remove, animations_.end());
152 } 150 }
153 } 151 }
154 152
155 void AnimationPlayer::AbortAnimation(int animation_id) { 153 void AnimationPlayer::AbortAnimation(int animation_id) {
156 DCHECK(element_animations_); 154 DCHECK(element_animations_);
157 element_animations_->AbortAnimation(animation_id); 155 element_animations_->AbortAnimation(animation_id);
158 SetNeedsPushProperties(); 156 SetNeedsCommit();
159 } 157 }
160 158
161 void AnimationPlayer::AbortAnimations(TargetProperty::Type target_property, 159 void AnimationPlayer::AbortAnimations(TargetProperty::Type target_property,
162 bool needs_completion) { 160 bool needs_completion) {
163 if (element_animations_) { 161 if (element_animations_) {
164 element_animations_->AbortAnimations(target_property, needs_completion); 162 element_animations_->AbortAnimations(target_property, needs_completion);
165 SetNeedsPushProperties(); 163 SetNeedsCommit();
166 } else { 164 } else {
167 auto animations_to_remove = std::remove_if( 165 auto animations_to_remove = std::remove_if(
168 animations_.begin(), animations_.end(), 166 animations_.begin(), animations_.end(),
169 [target_property](const std::unique_ptr<Animation>& animation) { 167 [target_property](const std::unique_ptr<Animation>& animation) {
170 return animation->target_property() == target_property; 168 return animation->target_property() == target_property;
171 }); 169 });
172 animations_.erase(animations_to_remove, animations_.end()); 170 animations_.erase(animations_to_remove, animations_.end());
173 } 171 }
174 } 172 }
175 173
176 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { 174 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) {
177 if (!needs_push_properties_)
178 return;
179 needs_push_properties_ = false;
180
181 if (element_id_ != player_impl->element_id()) { 175 if (element_id_ != player_impl->element_id()) {
182 if (player_impl->element_id()) 176 if (player_impl->element_id())
183 player_impl->DetachElement(); 177 player_impl->DetachElement();
184 if (element_id_) 178 if (element_id_)
185 player_impl->AttachElement(element_id_); 179 player_impl->AttachElement(element_id_);
186 } 180 }
187 } 181 }
188 182
189 void AnimationPlayer::NotifyAnimationStarted( 183 void AnimationPlayer::NotifyAnimationStarted(
190 base::TimeTicks monotonic_time, 184 base::TimeTicks monotonic_time,
(...skipping 15 matching lines...) Expand all
206 200
207 void AnimationPlayer::NotifyAnimationAborted( 201 void AnimationPlayer::NotifyAnimationAborted(
208 base::TimeTicks monotonic_time, 202 base::TimeTicks monotonic_time,
209 TargetProperty::Type target_property, 203 TargetProperty::Type target_property,
210 int group) { 204 int group) {
211 if (animation_delegate_) 205 if (animation_delegate_)
212 animation_delegate_->NotifyAnimationAborted(monotonic_time, target_property, 206 animation_delegate_->NotifyAnimationAborted(monotonic_time, target_property,
213 group); 207 group);
214 } 208 }
215 209
216 void AnimationPlayer::NotifyAnimationWaitingForDeletion() {
217 // We need to purge animations marked for deletion.
218 SetNeedsPushProperties();
219 }
220
221 void AnimationPlayer::NotifyAnimationTakeover( 210 void AnimationPlayer::NotifyAnimationTakeover(
222 base::TimeTicks monotonic_time, 211 base::TimeTicks monotonic_time,
223 TargetProperty::Type target_property, 212 TargetProperty::Type target_property,
224 double animation_start_time, 213 double animation_start_time,
225 std::unique_ptr<AnimationCurve> curve) { 214 std::unique_ptr<AnimationCurve> curve) {
226 // We need to purge animations marked for deletion on CT.
227 SetNeedsPushProperties();
228
229 if (animation_delegate_) { 215 if (animation_delegate_) {
230 DCHECK(curve); 216 DCHECK(curve);
231 animation_delegate_->NotifyAnimationTakeover( 217 animation_delegate_->NotifyAnimationTakeover(
232 monotonic_time, target_property, animation_start_time, 218 monotonic_time, target_property, animation_start_time,
233 std::move(curve)); 219 std::move(curve));
234 } 220 }
235 } 221 }
236 222
237 void AnimationPlayer::SetNeedsPushProperties() { 223 void AnimationPlayer::SetNeedsCommit() {
238 needs_push_properties_ = true; 224 DCHECK(animation_host_);
239 225 animation_host_->SetNeedsCommit();
240 DCHECK(animation_timeline_); 226 animation_host_->SetNeedsRebuildPropertyTrees();
241 animation_timeline_->SetNeedsPushProperties();
242
243 DCHECK(element_animations_);
244 element_animations_->SetNeedsPushProperties();
245 } 227 }
246 228
247 } // namespace cc 229 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_player.h ('k') | cc/animation/animation_player_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698