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

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

Issue 951673002: Revert "Pull chromium at 2c3ffb2355a27c32f45e508ef861416b820c823b" (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/layer_animation_controller.h" 5 #include "cc/animation/layer_animation_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "cc/animation/animation.h" 10 #include "cc/animation/animation.h"
(...skipping 27 matching lines...) Expand all
38 38
39 scoped_refptr<LayerAnimationController> LayerAnimationController::Create( 39 scoped_refptr<LayerAnimationController> LayerAnimationController::Create(
40 int id) { 40 int id) {
41 return make_scoped_refptr(new LayerAnimationController(id)); 41 return make_scoped_refptr(new LayerAnimationController(id));
42 } 42 }
43 43
44 void LayerAnimationController::PauseAnimation(int animation_id, 44 void LayerAnimationController::PauseAnimation(int animation_id,
45 base::TimeDelta time_offset) { 45 base::TimeDelta time_offset) {
46 for (size_t i = 0; i < animations_.size(); ++i) { 46 for (size_t i = 0; i < animations_.size(); ++i) {
47 if (animations_[i]->id() == animation_id) { 47 if (animations_[i]->id() == animation_id) {
48 animations_[i]->SetRunState(Animation::PAUSED, 48 animations_[i]->SetRunState(Animation::Paused,
49 time_offset + animations_[i]->start_time()); 49 time_offset + animations_[i]->start_time());
50 } 50 }
51 } 51 }
52 } 52 }
53 53
54 struct HasAnimationId { 54 struct HasAnimationId {
55 explicit HasAnimationId(int id) : id_(id) {} 55 explicit HasAnimationId(int id) : id_(id) {}
56 bool operator()(Animation* animation) const { 56 bool operator()(Animation* animation) const {
57 return animation->id() == id_; 57 return animation->id() == id_;
58 } 58 }
59 59
60 private: 60 private:
61 int id_; 61 int id_;
62 }; 62 };
63 63
64 void LayerAnimationController::RemoveAnimation(int animation_id) { 64 void LayerAnimationController::RemoveAnimation(int animation_id) {
65 auto animations_to_remove = 65 auto animations_to_remove =
66 animations_.remove_if(HasAnimationId(animation_id)); 66 animations_.remove_if(HasAnimationId(animation_id));
67 for (auto it = animations_to_remove; it != animations_.end(); ++it) { 67 for (auto it = animations_to_remove; it != animations_.end(); ++it) {
68 if ((*it)->target_property() == Animation::SCROLL_OFFSET) { 68 if ((*it)->target_property() == Animation::ScrollOffset) {
69 scroll_offset_animation_was_interrupted_ = true; 69 scroll_offset_animation_was_interrupted_ = true;
70 break; 70 break;
71 } 71 }
72 } 72 }
73 animations_.erase(animations_to_remove, animations_.end()); 73 animations_.erase(animations_to_remove, animations_.end());
74 UpdateActivation(NORMAL_ACTIVATION); 74 UpdateActivation(NormalActivation);
75 } 75 }
76 76
77 struct HasAnimationIdAndProperty { 77 struct HasAnimationIdAndProperty {
78 HasAnimationIdAndProperty(int id, Animation::TargetProperty target_property) 78 HasAnimationIdAndProperty(int id, Animation::TargetProperty target_property)
79 : id_(id), target_property_(target_property) {} 79 : id_(id), target_property_(target_property) {}
80 bool operator()(Animation* animation) const { 80 bool operator()(Animation* animation) const {
81 return animation->id() == id_ && 81 return animation->id() == id_ &&
82 animation->target_property() == target_property_; 82 animation->target_property() == target_property_;
83 } 83 }
84 84
85 private: 85 private:
86 int id_; 86 int id_;
87 Animation::TargetProperty target_property_; 87 Animation::TargetProperty target_property_;
88 }; 88 };
89 89
90 void LayerAnimationController::RemoveAnimation( 90 void LayerAnimationController::RemoveAnimation(
91 int animation_id, 91 int animation_id,
92 Animation::TargetProperty target_property) { 92 Animation::TargetProperty target_property) {
93 auto animations_to_remove = animations_.remove_if( 93 auto animations_to_remove = animations_.remove_if(
94 HasAnimationIdAndProperty(animation_id, target_property)); 94 HasAnimationIdAndProperty(animation_id, target_property));
95 if (target_property == Animation::SCROLL_OFFSET && 95 if (target_property == Animation::ScrollOffset &&
96 animations_to_remove != animations_.end()) 96 animations_to_remove != animations_.end())
97 scroll_offset_animation_was_interrupted_ = true; 97 scroll_offset_animation_was_interrupted_ = true;
98 98
99 animations_.erase(animations_to_remove, animations_.end()); 99 animations_.erase(animations_to_remove, animations_.end());
100 UpdateActivation(NORMAL_ACTIVATION); 100 UpdateActivation(NormalActivation);
101 } 101 }
102 102
103 void LayerAnimationController::AbortAnimations( 103 void LayerAnimationController::AbortAnimations(
104 Animation::TargetProperty target_property) { 104 Animation::TargetProperty target_property) {
105 for (size_t i = 0; i < animations_.size(); ++i) { 105 for (size_t i = 0; i < animations_.size(); ++i) {
106 if (animations_[i]->target_property() == target_property && 106 if (animations_[i]->target_property() == target_property &&
107 !animations_[i]->is_finished()) 107 !animations_[i]->is_finished())
108 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); 108 animations_[i]->SetRunState(Animation::Aborted, last_tick_time_);
109 } 109 }
110 } 110 }
111 111
112 // Ensures that the list of active animations on the main thread and the impl 112 // Ensures that the list of active animations on the main thread and the impl
113 // thread are kept in sync. 113 // thread are kept in sync.
114 void LayerAnimationController::PushAnimationUpdatesTo( 114 void LayerAnimationController::PushAnimationUpdatesTo(
115 LayerAnimationController* controller_impl) { 115 LayerAnimationController* controller_impl) {
116 DCHECK(this != controller_impl); 116 DCHECK(this != controller_impl);
117 if (!has_any_animation() && !controller_impl->has_any_animation()) 117 if (!has_any_animation() && !controller_impl->has_any_animation())
118 return; 118 return;
119 PurgeAnimationsMarkedForDeletion(); 119 PurgeAnimationsMarkedForDeletion();
120 PushNewAnimationsToImplThread(controller_impl); 120 PushNewAnimationsToImplThread(controller_impl);
121 121
122 // Remove finished impl side animations only after pushing, 122 // Remove finished impl side animations only after pushing,
123 // and only after the animations are deleted on the main thread 123 // and only after the animations are deleted on the main thread
124 // this insures we will never push an animation twice. 124 // this insures we will never push an animation twice.
125 RemoveAnimationsCompletedOnMainThread(controller_impl); 125 RemoveAnimationsCompletedOnMainThread(controller_impl);
126 126
127 PushPropertiesToImplThread(controller_impl); 127 PushPropertiesToImplThread(controller_impl);
128 controller_impl->UpdateActivation(NORMAL_ACTIVATION); 128 controller_impl->UpdateActivation(NormalActivation);
129 UpdateActivation(NORMAL_ACTIVATION); 129 UpdateActivation(NormalActivation);
130 } 130 }
131 131
132 void LayerAnimationController::Animate(base::TimeTicks monotonic_time) { 132 void LayerAnimationController::Animate(base::TimeTicks monotonic_time) {
133 DCHECK(!monotonic_time.is_null()); 133 DCHECK(!monotonic_time.is_null());
134 if (!HasValueObserver()) 134 if (!HasValueObserver())
135 return; 135 return;
136 136
137 if (needs_to_start_animations_) 137 if (needs_to_start_animations_)
138 StartAnimations(monotonic_time); 138 StartAnimations(monotonic_time);
139 TickAnimations(monotonic_time); 139 TickAnimations(monotonic_time);
(...skipping 10 matching lines...) Expand all
150 Animation* animation = animations_[i]; 150 Animation* animation = animations_[i];
151 if (!animation->is_impl_only()) 151 if (!animation->is_impl_only())
152 continue; 152 continue;
153 153
154 if (!animation->InEffect(monotonic_time)) 154 if (!animation->InEffect(monotonic_time))
155 continue; 155 continue;
156 156
157 base::TimeDelta trimmed = 157 base::TimeDelta trimmed =
158 animation->TrimTimeToCurrentIteration(monotonic_time); 158 animation->TrimTimeToCurrentIteration(monotonic_time);
159 switch (animation->target_property()) { 159 switch (animation->target_property()) {
160 case Animation::OPACITY: { 160 case Animation::Opacity: {
161 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, 161 AnimationEvent event(AnimationEvent::PropertyUpdate,
162 animation->group(), Animation::OPACITY, 162 id_,
163 animation->group(),
164 Animation::Opacity,
163 monotonic_time); 165 monotonic_time);
164 const FloatAnimationCurve* float_animation_curve = 166 const FloatAnimationCurve* float_animation_curve =
165 animation->curve()->ToFloatAnimationCurve(); 167 animation->curve()->ToFloatAnimationCurve();
166 event.opacity = float_animation_curve->GetValue(trimmed); 168 event.opacity = float_animation_curve->GetValue(trimmed);
167 event.is_impl_only = true; 169 event.is_impl_only = true;
168 events->push_back(event); 170 events->push_back(event);
169 break; 171 break;
170 } 172 }
171 173
172 case Animation::TRANSFORM: { 174 case Animation::Transform: {
173 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, 175 AnimationEvent event(AnimationEvent::PropertyUpdate,
174 animation->group(), Animation::TRANSFORM, 176 id_,
177 animation->group(),
178 Animation::Transform,
175 monotonic_time); 179 monotonic_time);
176 const TransformAnimationCurve* transform_animation_curve = 180 const TransformAnimationCurve* transform_animation_curve =
177 animation->curve()->ToTransformAnimationCurve(); 181 animation->curve()->ToTransformAnimationCurve();
178 event.transform = transform_animation_curve->GetValue(trimmed); 182 event.transform = transform_animation_curve->GetValue(trimmed);
179 event.is_impl_only = true; 183 event.is_impl_only = true;
180 events->push_back(event); 184 events->push_back(event);
181 break; 185 break;
182 } 186 }
183 187
184 case Animation::FILTER: { 188 case Animation::Filter: {
185 AnimationEvent event(AnimationEvent::PROPERTY_UPDATE, id_, 189 AnimationEvent event(AnimationEvent::PropertyUpdate,
186 animation->group(), Animation::FILTER, 190 id_,
191 animation->group(),
192 Animation::Filter,
187 monotonic_time); 193 monotonic_time);
188 const FilterAnimationCurve* filter_animation_curve = 194 const FilterAnimationCurve* filter_animation_curve =
189 animation->curve()->ToFilterAnimationCurve(); 195 animation->curve()->ToFilterAnimationCurve();
190 event.filters = filter_animation_curve->GetValue(trimmed); 196 event.filters = filter_animation_curve->GetValue(trimmed);
191 event.is_impl_only = true; 197 event.is_impl_only = true;
192 events->push_back(event); 198 events->push_back(event);
193 break; 199 break;
194 } 200 }
195 201
196 case Animation::BACKGROUND_COLOR: { 202 case Animation::BackgroundColor: { break; }
203
204 case Animation::ScrollOffset: {
205 // Impl-side changes to scroll offset are already sent back to the
206 // main thread (e.g. for user-driven scrolling), so a PropertyUpdate
207 // isn't needed.
197 break; 208 break;
198 } 209 }
199 210
200 case Animation::SCROLL_OFFSET: { 211 case Animation::TargetPropertyEnumSize:
201 // Impl-side changes to scroll offset are already sent back to the 212 NOTREACHED();
202 // main thread (e.g. for user-driven scrolling), so a PROPERTY_UPDATE
203 // isn't needed.
204 break;
205 }
206 } 213 }
207 } 214 }
208 } 215 }
209 216
210 void LayerAnimationController::UpdateState(bool start_ready_animations, 217 void LayerAnimationController::UpdateState(bool start_ready_animations,
211 AnimationEventsVector* events) { 218 AnimationEventsVector* events) {
212 if (!HasActiveValueObserver()) 219 if (!HasActiveValueObserver())
213 return; 220 return;
214 221
215 // Animate hasn't been called, this happens if an observer has been added 222 // Animate hasn't been called, this happens if an observer has been added
216 // between the Commit and Draw phases. 223 // between the Commit and Draw phases.
217 if (last_tick_time_ == base::TimeTicks()) 224 if (last_tick_time_ == base::TimeTicks())
218 return; 225 return;
219 226
220 if (start_ready_animations) 227 if (start_ready_animations)
221 PromoteStartedAnimations(last_tick_time_, events); 228 PromoteStartedAnimations(last_tick_time_, events);
222 229
223 MarkFinishedAnimations(last_tick_time_); 230 MarkFinishedAnimations(last_tick_time_);
224 MarkAnimationsForDeletion(last_tick_time_, events); 231 MarkAnimationsForDeletion(last_tick_time_, events);
225 232
226 if (needs_to_start_animations_ && start_ready_animations) { 233 if (needs_to_start_animations_ && start_ready_animations) {
227 StartAnimations(last_tick_time_); 234 StartAnimations(last_tick_time_);
228 PromoteStartedAnimations(last_tick_time_, events); 235 PromoteStartedAnimations(last_tick_time_, events);
229 } 236 }
230 237
231 AccumulatePropertyUpdates(last_tick_time_, events); 238 AccumulatePropertyUpdates(last_tick_time_, events);
232 239
233 UpdateActivation(NORMAL_ACTIVATION); 240 UpdateActivation(NormalActivation);
234 } 241 }
235 242
236 struct AffectsNoObservers { 243 struct AffectsNoObservers {
237 bool operator()(Animation* animation) const { 244 bool operator()(Animation* animation) const {
238 return !animation->affects_active_observers() && 245 return !animation->affects_active_observers() &&
239 !animation->affects_pending_observers(); 246 !animation->affects_pending_observers();
240 } 247 }
241 }; 248 };
242 249
243 void LayerAnimationController::ActivateAnimations() { 250 void LayerAnimationController::ActivateAnimations() {
244 for (size_t i = 0; i < animations_.size(); ++i) { 251 for (size_t i = 0; i < animations_.size(); ++i) {
245 animations_[i]->set_affects_active_observers( 252 animations_[i]->set_affects_active_observers(
246 animations_[i]->affects_pending_observers()); 253 animations_[i]->affects_pending_observers());
247 } 254 }
248 animations_.erase(cc::remove_if(&animations_, 255 animations_.erase(cc::remove_if(&animations_,
249 animations_.begin(), 256 animations_.begin(),
250 animations_.end(), 257 animations_.end(),
251 AffectsNoObservers()), 258 AffectsNoObservers()),
252 animations_.end()); 259 animations_.end());
253 scroll_offset_animation_was_interrupted_ = false; 260 scroll_offset_animation_was_interrupted_ = false;
254 UpdateActivation(NORMAL_ACTIVATION); 261 UpdateActivation(NormalActivation);
255 } 262 }
256 263
257 void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) { 264 void LayerAnimationController::AddAnimation(scoped_ptr<Animation> animation) {
258 animations_.push_back(animation.Pass()); 265 animations_.push_back(animation.Pass());
259 needs_to_start_animations_ = true; 266 needs_to_start_animations_ = true;
260 UpdateActivation(NORMAL_ACTIVATION); 267 UpdateActivation(NormalActivation);
261 } 268 }
262 269
263 Animation* LayerAnimationController::GetAnimation( 270 Animation* LayerAnimationController::GetAnimation(
264 Animation::TargetProperty target_property) const { 271 Animation::TargetProperty target_property) const {
265 for (size_t i = 0; i < animations_.size(); ++i) { 272 for (size_t i = 0; i < animations_.size(); ++i) {
266 size_t index = animations_.size() - i - 1; 273 size_t index = animations_.size() - i - 1;
267 if (animations_[index]->target_property() == target_property) 274 if (animations_[index]->target_property() == target_property)
268 return animations_[index]; 275 return animations_[index];
269 } 276 }
270 return 0; 277 return 0;
(...skipping 30 matching lines...) Expand all
301 if (registrar_ == registrar) 308 if (registrar_ == registrar)
302 return; 309 return;
303 310
304 if (registrar_) 311 if (registrar_)
305 registrar_->UnregisterAnimationController(this); 312 registrar_->UnregisterAnimationController(this);
306 313
307 registrar_ = registrar; 314 registrar_ = registrar;
308 if (registrar_) 315 if (registrar_)
309 registrar_->RegisterAnimationController(this); 316 registrar_->RegisterAnimationController(this);
310 317
311 UpdateActivation(FORCE_ACTIVATION); 318 UpdateActivation(ForceActivation);
312 } 319 }
313 320
314 void LayerAnimationController::NotifyAnimationStarted( 321 void LayerAnimationController::NotifyAnimationStarted(
315 const AnimationEvent& event) { 322 const AnimationEvent& event) {
316 if (event.is_impl_only) { 323 if (event.is_impl_only) {
317 FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_, 324 FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_,
318 OnAnimationStarted(event)); 325 OnAnimationStarted(event));
319 if (layer_animation_delegate_) 326 if (layer_animation_delegate_)
320 layer_animation_delegate_->NotifyAnimationStarted( 327 layer_animation_delegate_->NotifyAnimationStarted(
321 event.monotonic_time, event.target_property, event.group_id); 328 event.monotonic_time, event.target_property, event.group_id);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 return; 368 return;
362 } 369 }
363 } 370 }
364 } 371 }
365 372
366 void LayerAnimationController::NotifyAnimationAborted( 373 void LayerAnimationController::NotifyAnimationAborted(
367 const AnimationEvent& event) { 374 const AnimationEvent& event) {
368 for (size_t i = 0; i < animations_.size(); ++i) { 375 for (size_t i = 0; i < animations_.size(); ++i) {
369 if (animations_[i]->group() == event.group_id && 376 if (animations_[i]->group() == event.group_id &&
370 animations_[i]->target_property() == event.target_property) { 377 animations_[i]->target_property() == event.target_property) {
371 animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time); 378 animations_[i]->SetRunState(Animation::Aborted, event.monotonic_time);
372 } 379 }
373 } 380 }
374 } 381 }
375 382
376 void LayerAnimationController::NotifyAnimationPropertyUpdate( 383 void LayerAnimationController::NotifyAnimationPropertyUpdate(
377 const AnimationEvent& event) { 384 const AnimationEvent& event) {
378 bool notify_active_observers = true; 385 bool notify_active_observers = true;
379 bool notify_pending_observers = true; 386 bool notify_pending_observers = true;
380 switch (event.target_property) { 387 switch (event.target_property) {
381 case Animation::OPACITY: 388 case Animation::Opacity:
382 NotifyObserversOpacityAnimated( 389 NotifyObserversOpacityAnimated(
383 event.opacity, notify_active_observers, notify_pending_observers); 390 event.opacity, notify_active_observers, notify_pending_observers);
384 break; 391 break;
385 case Animation::TRANSFORM: 392 case Animation::Transform:
386 NotifyObserversTransformAnimated( 393 NotifyObserversTransformAnimated(
387 event.transform, notify_active_observers, notify_pending_observers); 394 event.transform, notify_active_observers, notify_pending_observers);
388 break; 395 break;
389 default: 396 default:
390 NOTREACHED(); 397 NOTREACHED();
391 } 398 }
392 } 399 }
393 400
394 void LayerAnimationController::AddValueObserver( 401 void LayerAnimationController::AddValueObserver(
395 LayerAnimationValueObserver* observer) { 402 LayerAnimationValueObserver* observer) {
(...skipping 13 matching lines...) Expand all
409 } 416 }
410 417
411 void LayerAnimationController::RemoveEventObserver( 418 void LayerAnimationController::RemoveEventObserver(
412 LayerAnimationEventObserver* observer) { 419 LayerAnimationEventObserver* observer) {
413 event_observers_.RemoveObserver(observer); 420 event_observers_.RemoveObserver(observer);
414 } 421 }
415 422
416 bool LayerAnimationController::HasFilterAnimationThatInflatesBounds() const { 423 bool LayerAnimationController::HasFilterAnimationThatInflatesBounds() const {
417 for (size_t i = 0; i < animations_.size(); ++i) { 424 for (size_t i = 0; i < animations_.size(); ++i) {
418 if (!animations_[i]->is_finished() && 425 if (!animations_[i]->is_finished() &&
419 animations_[i]->target_property() == Animation::FILTER && 426 animations_[i]->target_property() == Animation::Filter &&
420 animations_[i] 427 animations_[i]
421 ->curve() 428 ->curve()
422 ->ToFilterAnimationCurve() 429 ->ToFilterAnimationCurve()
423 ->HasFilterThatMovesPixels()) 430 ->HasFilterThatMovesPixels())
424 return true; 431 return true;
425 } 432 }
426 433
427 return false; 434 return false;
428 } 435 }
429 436
430 bool LayerAnimationController::HasTransformAnimationThatInflatesBounds() const { 437 bool LayerAnimationController::HasTransformAnimationThatInflatesBounds() const {
431 return IsAnimatingProperty(Animation::TRANSFORM); 438 return IsAnimatingProperty(Animation::Transform);
432 } 439 }
433 440
434 bool LayerAnimationController::FilterAnimationBoundsForBox( 441 bool LayerAnimationController::FilterAnimationBoundsForBox(
435 const gfx::BoxF& box, gfx::BoxF* bounds) const { 442 const gfx::BoxF& box, gfx::BoxF* bounds) const {
436 // TODO(avallee): Implement. 443 // TODO(avallee): Implement.
437 return false; 444 return false;
438 } 445 }
439 446
440 bool LayerAnimationController::TransformAnimationBoundsForBox( 447 bool LayerAnimationController::TransformAnimationBoundsForBox(
441 const gfx::BoxF& box, 448 const gfx::BoxF& box,
442 gfx::BoxF* bounds) const { 449 gfx::BoxF* bounds) const {
443 DCHECK(HasTransformAnimationThatInflatesBounds()) 450 DCHECK(HasTransformAnimationThatInflatesBounds())
444 << "TransformAnimationBoundsForBox will give incorrect results if there " 451 << "TransformAnimationBoundsForBox will give incorrect results if there "
445 << "are no transform animations affecting bounds, non-animated transform " 452 << "are no transform animations affecting bounds, non-animated transform "
446 << "is not known"; 453 << "is not known";
447 454
448 // Compute bounds based on animations for which is_finished() is false. 455 // Compute bounds based on animations for which is_finished() is false.
449 // Do nothing if there are no such animations; in this case, it is assumed 456 // Do nothing if there are no such animations; in this case, it is assumed
450 // that callers will take care of computing bounds based on the owning layer's 457 // that callers will take care of computing bounds based on the owning layer's
451 // actual transform. 458 // actual transform.
452 *bounds = gfx::BoxF(); 459 *bounds = gfx::BoxF();
453 for (size_t i = 0; i < animations_.size(); ++i) { 460 for (size_t i = 0; i < animations_.size(); ++i) {
454 if (animations_[i]->is_finished() || 461 if (animations_[i]->is_finished() ||
455 animations_[i]->target_property() != Animation::TRANSFORM) 462 animations_[i]->target_property() != Animation::Transform)
456 continue; 463 continue;
457 464
458 const TransformAnimationCurve* transform_animation_curve = 465 const TransformAnimationCurve* transform_animation_curve =
459 animations_[i]->curve()->ToTransformAnimationCurve(); 466 animations_[i]->curve()->ToTransformAnimationCurve();
460 gfx::BoxF animation_bounds; 467 gfx::BoxF animation_bounds;
461 bool success = 468 bool success =
462 transform_animation_curve->AnimatedBoundsForBox(box, &animation_bounds); 469 transform_animation_curve->AnimatedBoundsForBox(box, &animation_bounds);
463 if (!success) 470 if (!success)
464 return false; 471 return false;
465 bounds->Union(animation_bounds); 472 bounds->Union(animation_bounds);
466 } 473 }
467 474
468 return true; 475 return true;
469 } 476 }
470 477
471 bool LayerAnimationController::HasAnimationThatAffectsScale() const { 478 bool LayerAnimationController::HasAnimationThatAffectsScale() const {
472 for (size_t i = 0; i < animations_.size(); ++i) { 479 for (size_t i = 0; i < animations_.size(); ++i) {
473 if (animations_[i]->is_finished() || 480 if (animations_[i]->is_finished() ||
474 animations_[i]->target_property() != Animation::TRANSFORM) 481 animations_[i]->target_property() != Animation::Transform)
475 continue; 482 continue;
476 483
477 const TransformAnimationCurve* transform_animation_curve = 484 const TransformAnimationCurve* transform_animation_curve =
478 animations_[i]->curve()->ToTransformAnimationCurve(); 485 animations_[i]->curve()->ToTransformAnimationCurve();
479 if (transform_animation_curve->AffectsScale()) 486 if (transform_animation_curve->AffectsScale())
480 return true; 487 return true;
481 } 488 }
482 489
483 return false; 490 return false;
484 } 491 }
485 492
486 bool LayerAnimationController::HasOnlyTranslationTransforms() const { 493 bool LayerAnimationController::HasOnlyTranslationTransforms() const {
487 for (size_t i = 0; i < animations_.size(); ++i) { 494 for (size_t i = 0; i < animations_.size(); ++i) {
488 if (animations_[i]->is_finished() || 495 if (animations_[i]->is_finished() ||
489 animations_[i]->target_property() != Animation::TRANSFORM) 496 animations_[i]->target_property() != Animation::Transform)
490 continue; 497 continue;
491 498
492 const TransformAnimationCurve* transform_animation_curve = 499 const TransformAnimationCurve* transform_animation_curve =
493 animations_[i]->curve()->ToTransformAnimationCurve(); 500 animations_[i]->curve()->ToTransformAnimationCurve();
494 if (!transform_animation_curve->IsTranslation()) 501 if (!transform_animation_curve->IsTranslation())
495 return false; 502 return false;
496 } 503 }
497 504
498 return true; 505 return true;
499 } 506 }
500 507
501 bool LayerAnimationController::AnimationsPreserveAxisAlignment() const { 508 bool LayerAnimationController::AnimationsPreserveAxisAlignment() const {
502 for (size_t i = 0; i < animations_.size(); ++i) { 509 for (size_t i = 0; i < animations_.size(); ++i) {
503 if (animations_[i]->is_finished() || 510 if (animations_[i]->is_finished() ||
504 animations_[i]->target_property() != Animation::TRANSFORM) 511 animations_[i]->target_property() != Animation::Transform)
505 continue; 512 continue;
506 513
507 const TransformAnimationCurve* transform_animation_curve = 514 const TransformAnimationCurve* transform_animation_curve =
508 animations_[i]->curve()->ToTransformAnimationCurve(); 515 animations_[i]->curve()->ToTransformAnimationCurve();
509 if (!transform_animation_curve->PreservesAxisAlignment()) 516 if (!transform_animation_curve->PreservesAxisAlignment())
510 return false; 517 return false;
511 } 518 }
512 519
513 return true; 520 return true;
514 } 521 }
515 522
516 bool LayerAnimationController::MaximumTargetScale(float* max_scale) const { 523 bool LayerAnimationController::MaximumTargetScale(float* max_scale) const {
517 *max_scale = 0.f; 524 *max_scale = 0.f;
518 for (size_t i = 0; i < animations_.size(); ++i) { 525 for (size_t i = 0; i < animations_.size(); ++i) {
519 if (animations_[i]->is_finished() || 526 if (animations_[i]->is_finished() ||
520 animations_[i]->target_property() != Animation::TRANSFORM) 527 animations_[i]->target_property() != Animation::Transform)
521 continue; 528 continue;
522 529
523 bool forward_direction = true; 530 bool forward_direction = true;
524 switch (animations_[i]->direction()) { 531 switch (animations_[i]->direction()) {
525 case Animation::DIRECTION_NORMAL: 532 case Animation::Normal:
526 case Animation::DIRECTION_ALTERNATE: 533 case Animation::Alternate:
527 forward_direction = animations_[i]->playback_rate() >= 0.0; 534 forward_direction = animations_[i]->playback_rate() >= 0.0;
528 break; 535 break;
529 case Animation::DIRECTION_REVERSE: 536 case Animation::Reverse:
530 case Animation::DIRECTION_ALTERNATE_REVERSE: 537 case Animation::AlternateReverse:
531 forward_direction = animations_[i]->playback_rate() < 0.0; 538 forward_direction = animations_[i]->playback_rate() < 0.0;
532 break; 539 break;
533 } 540 }
534 541
535 const TransformAnimationCurve* transform_animation_curve = 542 const TransformAnimationCurve* transform_animation_curve =
536 animations_[i]->curve()->ToTransformAnimationCurve(); 543 animations_[i]->curve()->ToTransformAnimationCurve();
537 float animation_scale = 0.f; 544 float animation_scale = 0.f;
538 if (!transform_animation_curve->MaximumTargetScale(forward_direction, 545 if (!transform_animation_curve->MaximumTargetScale(forward_direction,
539 &animation_scale)) 546 &animation_scale))
540 return false; 547 return false;
(...skipping 16 matching lines...) Expand all
557 // If the animation is not running on the impl thread, it does not 564 // If the animation is not running on the impl thread, it does not
558 // necessarily mean that it needs to be copied over and started; it may 565 // necessarily mean that it needs to be copied over and started; it may
559 // have already finished. In this case, the impl thread animation will 566 // have already finished. In this case, the impl thread animation will
560 // have already notified that it has started and the main thread animation 567 // have already notified that it has started and the main thread animation
561 // will no longer need 568 // will no longer need
562 // a synchronized start time. 569 // a synchronized start time.
563 if (!animations_[i]->needs_synchronized_start_time()) 570 if (!animations_[i]->needs_synchronized_start_time())
564 continue; 571 continue;
565 572
566 // Scroll animations always start at the current scroll offset. 573 // Scroll animations always start at the current scroll offset.
567 if (animations_[i]->target_property() == Animation::SCROLL_OFFSET) { 574 if (animations_[i]->target_property() == Animation::ScrollOffset) {
568 gfx::ScrollOffset current_scroll_offset; 575 gfx::ScrollOffset current_scroll_offset;
569 if (controller_impl->value_provider_) { 576 if (controller_impl->value_provider_) {
570 current_scroll_offset = 577 current_scroll_offset =
571 controller_impl->value_provider_->ScrollOffsetForAnimation(); 578 controller_impl->value_provider_->ScrollOffsetForAnimation();
572 } else { 579 } else {
573 // The owning layer isn't yet in the active tree, so the main thread 580 // The owning layer isn't yet in the active tree, so the main thread
574 // scroll offset will be up-to-date. 581 // scroll offset will be up-to-date.
575 current_scroll_offset = value_provider_->ScrollOffsetForAnimation(); 582 current_scroll_offset = value_provider_->ScrollOffsetForAnimation();
576 } 583 }
577 animations_[i]->curve()->ToScrollOffsetAnimationCurve()->SetInitialValue( 584 animations_[i]->curve()->ToScrollOffsetAnimationCurve()->SetInitialValue(
578 current_scroll_offset); 585 current_scroll_offset);
579 } 586 }
580 587
581 // The new animation should be set to run as soon as possible. 588 // The new animation should be set to run as soon as possible.
582 Animation::RunState initial_run_state = 589 Animation::RunState initial_run_state =
583 Animation::WAITING_FOR_TARGET_AVAILABILITY; 590 Animation::WaitingForTargetAvailability;
584 scoped_ptr<Animation> to_add( 591 scoped_ptr<Animation> to_add(
585 animations_[i]->CloneAndInitialize(initial_run_state)); 592 animations_[i]->CloneAndInitialize(initial_run_state));
586 DCHECK(!to_add->needs_synchronized_start_time()); 593 DCHECK(!to_add->needs_synchronized_start_time());
587 to_add->set_affects_active_observers(false); 594 to_add->set_affects_active_observers(false);
588 controller_impl->AddAnimation(to_add.Pass()); 595 controller_impl->AddAnimation(to_add.Pass());
589 } 596 }
590 } 597 }
591 598
592 static bool IsCompleted( 599 static bool IsCompleted(
593 Animation* animation, 600 Animation* animation,
594 const LayerAnimationController* main_thread_controller) { 601 const LayerAnimationController* main_thread_controller) {
595 if (animation->is_impl_only()) { 602 if (animation->is_impl_only()) {
596 return (animation->run_state() == Animation::WAITING_FOR_DELETION); 603 return (animation->run_state() == Animation::WaitingForDeletion);
597 } else { 604 } else {
598 return !main_thread_controller->GetAnimationById(animation->id()); 605 return !main_thread_controller->GetAnimationById(animation->id());
599 } 606 }
600 } 607 }
601 608
602 static bool AffectsActiveOnlyAndIsWaitingForDeletion(Animation* animation) { 609 static bool AffectsActiveOnlyAndIsWaitingForDeletion(Animation* animation) {
603 return animation->run_state() == Animation::WAITING_FOR_DELETION && 610 return animation->run_state() == Animation::WaitingForDeletion &&
604 !animation->affects_pending_observers(); 611 !animation->affects_pending_observers();
605 } 612 }
606 613
607 void LayerAnimationController::RemoveAnimationsCompletedOnMainThread( 614 void LayerAnimationController::RemoveAnimationsCompletedOnMainThread(
608 LayerAnimationController* controller_impl) const { 615 LayerAnimationController* controller_impl) const {
609 // Animations removed on the main thread should no longer affect pending 616 // Animations removed on the main thread should no longer affect pending
610 // observers, and should stop affecting active observers after the next call 617 // observers, and should stop affecting active observers after the next call
611 // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed 618 // to ActivateAnimations. If already WaitingForDeletion, they can be removed
612 // immediately. 619 // immediately.
613 ScopedPtrVector<Animation>& animations = controller_impl->animations_; 620 ScopedPtrVector<Animation>& animations = controller_impl->animations_;
614 for (size_t i = 0; i < animations.size(); ++i) { 621 for (size_t i = 0; i < animations.size(); ++i) {
615 if (IsCompleted(animations[i], this)) 622 if (IsCompleted(animations[i], this))
616 animations[i]->set_affects_pending_observers(false); 623 animations[i]->set_affects_pending_observers(false);
617 } 624 }
618 animations.erase(cc::remove_if(&animations, 625 animations.erase(cc::remove_if(&animations,
619 animations.begin(), 626 animations.begin(),
620 animations.end(), 627 animations.end(),
621 AffectsActiveOnlyAndIsWaitingForDeletion), 628 AffectsActiveOnlyAndIsWaitingForDeletion),
(...skipping 16 matching lines...) Expand all
638 void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { 645 void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) {
639 DCHECK(needs_to_start_animations_); 646 DCHECK(needs_to_start_animations_);
640 needs_to_start_animations_ = false; 647 needs_to_start_animations_ = false;
641 // First collect running properties affecting each type of observer. 648 // First collect running properties affecting each type of observer.
642 TargetProperties blocked_properties_for_active_observers; 649 TargetProperties blocked_properties_for_active_observers;
643 TargetProperties blocked_properties_for_pending_observers; 650 TargetProperties blocked_properties_for_pending_observers;
644 std::vector<size_t> animations_waiting_for_target; 651 std::vector<size_t> animations_waiting_for_target;
645 652
646 animations_waiting_for_target.reserve(animations_.size()); 653 animations_waiting_for_target.reserve(animations_.size());
647 for (size_t i = 0; i < animations_.size(); ++i) { 654 for (size_t i = 0; i < animations_.size(); ++i) {
648 if (animations_[i]->run_state() == Animation::STARTING || 655 if (animations_[i]->run_state() == Animation::Starting ||
649 animations_[i]->run_state() == Animation::RUNNING) { 656 animations_[i]->run_state() == Animation::Running) {
650 if (animations_[i]->affects_active_observers()) { 657 if (animations_[i]->affects_active_observers()) {
651 blocked_properties_for_active_observers.insert( 658 blocked_properties_for_active_observers.insert(
652 animations_[i]->target_property()); 659 animations_[i]->target_property());
653 } 660 }
654 if (animations_[i]->affects_pending_observers()) { 661 if (animations_[i]->affects_pending_observers()) {
655 blocked_properties_for_pending_observers.insert( 662 blocked_properties_for_pending_observers.insert(
656 animations_[i]->target_property()); 663 animations_[i]->target_property());
657 } 664 }
658 } else if (animations_[i]->run_state() == 665 } else if (animations_[i]->run_state() ==
659 Animation::WAITING_FOR_TARGET_AVAILABILITY) { 666 Animation::WaitingForTargetAvailability) {
660 animations_waiting_for_target.push_back(i); 667 animations_waiting_for_target.push_back(i);
661 } 668 }
662 } 669 }
663 670
664 for (size_t i = 0; i < animations_waiting_for_target.size(); ++i) { 671 for (size_t i = 0; i < animations_waiting_for_target.size(); ++i) {
665 // Collect all properties for animations with the same group id (they 672 // Collect all properties for animations with the same group id (they
666 // should all also be in the list of animations). 673 // should all also be in the list of animations).
667 size_t animation_index = animations_waiting_for_target[i]; 674 size_t animation_index = animations_waiting_for_target[i];
668 Animation* animation_waiting_for_target = animations_[animation_index]; 675 Animation* animation_waiting_for_target = animations_[animation_index];
669 // Check for the run state again even though the animation was waiting 676 // Check for the run state again even though the animation was waiting
670 // for target because it might have changed the run state while handling 677 // for target because it might have changed the run state while handling
671 // previous animation in this loop (if they belong to same group). 678 // previous animation in this loop (if they belong to same group).
672 if (animation_waiting_for_target->run_state() == 679 if (animation_waiting_for_target->run_state() ==
673 Animation::WAITING_FOR_TARGET_AVAILABILITY) { 680 Animation::WaitingForTargetAvailability) {
674 TargetProperties enqueued_properties; 681 TargetProperties enqueued_properties;
675 bool affects_active_observers = 682 bool affects_active_observers =
676 animation_waiting_for_target->affects_active_observers(); 683 animation_waiting_for_target->affects_active_observers();
677 bool affects_pending_observers = 684 bool affects_pending_observers =
678 animation_waiting_for_target->affects_pending_observers(); 685 animation_waiting_for_target->affects_pending_observers();
679 enqueued_properties.insert( 686 enqueued_properties.insert(
680 animation_waiting_for_target->target_property()); 687 animation_waiting_for_target->target_property());
681 for (size_t j = animation_index + 1; j < animations_.size(); ++j) { 688 for (size_t j = animation_index + 1; j < animations_.size(); ++j) {
682 if (animation_waiting_for_target->group() == animations_[j]->group()) { 689 if (animation_waiting_for_target->group() == animations_[j]->group()) {
683 enqueued_properties.insert(animations_[j]->target_property()); 690 enqueued_properties.insert(animations_[j]->target_property());
(...skipping 17 matching lines...) Expand all
701 !blocked_properties_for_active_observers.insert(*p_iter).second) 708 !blocked_properties_for_active_observers.insert(*p_iter).second)
702 null_intersection = false; 709 null_intersection = false;
703 if (affects_pending_observers && 710 if (affects_pending_observers &&
704 !blocked_properties_for_pending_observers.insert(*p_iter).second) 711 !blocked_properties_for_pending_observers.insert(*p_iter).second)
705 null_intersection = false; 712 null_intersection = false;
706 } 713 }
707 714
708 // If the intersection is null, then we are free to start the animations 715 // If the intersection is null, then we are free to start the animations
709 // in the group. 716 // in the group.
710 if (null_intersection) { 717 if (null_intersection) {
711 animation_waiting_for_target->SetRunState(Animation::STARTING, 718 animation_waiting_for_target->SetRunState(Animation::Starting,
712 monotonic_time); 719 monotonic_time);
713 for (size_t j = animation_index + 1; j < animations_.size(); ++j) { 720 for (size_t j = animation_index + 1; j < animations_.size(); ++j) {
714 if (animation_waiting_for_target->group() == 721 if (animation_waiting_for_target->group() ==
715 animations_[j]->group()) { 722 animations_[j]->group()) {
716 animations_[j]->SetRunState(Animation::STARTING, monotonic_time); 723 animations_[j]->SetRunState(Animation::Starting, monotonic_time);
717 } 724 }
718 } 725 }
719 } else { 726 } else {
720 needs_to_start_animations_ = true; 727 needs_to_start_animations_ = true;
721 } 728 }
722 } 729 }
723 } 730 }
724 } 731 }
725 732
726 void LayerAnimationController::PromoteStartedAnimations( 733 void LayerAnimationController::PromoteStartedAnimations(
727 base::TimeTicks monotonic_time, 734 base::TimeTicks monotonic_time,
728 AnimationEventsVector* events) { 735 AnimationEventsVector* events) {
729 for (size_t i = 0; i < animations_.size(); ++i) { 736 for (size_t i = 0; i < animations_.size(); ++i) {
730 if (animations_[i]->run_state() == Animation::STARTING && 737 if (animations_[i]->run_state() == Animation::Starting &&
731 animations_[i]->affects_active_observers()) { 738 animations_[i]->affects_active_observers()) {
732 animations_[i]->SetRunState(Animation::RUNNING, monotonic_time); 739 animations_[i]->SetRunState(Animation::Running, monotonic_time);
733 if (!animations_[i]->has_set_start_time() && 740 if (!animations_[i]->has_set_start_time() &&
734 !animations_[i]->needs_synchronized_start_time()) 741 !animations_[i]->needs_synchronized_start_time())
735 animations_[i]->set_start_time(monotonic_time); 742 animations_[i]->set_start_time(monotonic_time);
736 if (events) { 743 if (events) {
737 AnimationEvent started_event( 744 AnimationEvent started_event(AnimationEvent::Started,
738 AnimationEvent::STARTED, id_, animations_[i]->group(), 745 id_,
739 animations_[i]->target_property(), monotonic_time); 746 animations_[i]->group(),
747 animations_[i]->target_property(),
748 monotonic_time);
740 started_event.is_impl_only = animations_[i]->is_impl_only(); 749 started_event.is_impl_only = animations_[i]->is_impl_only();
741 if (started_event.is_impl_only) 750 if (started_event.is_impl_only)
742 NotifyAnimationStarted(started_event); 751 NotifyAnimationStarted(started_event);
743 else 752 else
744 events->push_back(started_event); 753 events->push_back(started_event);
745 } 754 }
746 } 755 }
747 } 756 }
748 } 757 }
749 758
750 void LayerAnimationController::MarkFinishedAnimations( 759 void LayerAnimationController::MarkFinishedAnimations(
751 base::TimeTicks monotonic_time) { 760 base::TimeTicks monotonic_time) {
752 for (size_t i = 0; i < animations_.size(); ++i) { 761 for (size_t i = 0; i < animations_.size(); ++i) {
753 if (animations_[i]->IsFinishedAt(monotonic_time) && 762 if (animations_[i]->IsFinishedAt(monotonic_time) &&
754 animations_[i]->run_state() != Animation::ABORTED && 763 animations_[i]->run_state() != Animation::Aborted &&
755 animations_[i]->run_state() != Animation::WAITING_FOR_DELETION) 764 animations_[i]->run_state() != Animation::WaitingForDeletion)
756 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); 765 animations_[i]->SetRunState(Animation::Finished, monotonic_time);
757 } 766 }
758 } 767 }
759 768
760 void LayerAnimationController::MarkAnimationsForDeletion( 769 void LayerAnimationController::MarkAnimationsForDeletion(
761 base::TimeTicks monotonic_time, 770 base::TimeTicks monotonic_time,
762 AnimationEventsVector* events) { 771 AnimationEventsVector* events) {
763 bool marked_animations_for_deletions = false; 772 bool marked_animations_for_deletions = false;
764 std::vector<size_t> animations_with_same_group_id; 773 std::vector<size_t> animations_with_same_group_id;
765 774
766 animations_with_same_group_id.reserve(animations_.size()); 775 animations_with_same_group_id.reserve(animations_.size());
767 // Non-aborted animations are marked for deletion after a corresponding 776 // Non-aborted animations are marked for deletion after a corresponding
768 // AnimationEvent::FINISHED event is sent or received. This means that if 777 // AnimationEvent::Finished event is sent or received. This means that if
769 // we don't have an events vector, we must ensure that non-aborted animations 778 // we don't have an events vector, we must ensure that non-aborted animations
770 // have received a finished event before marking them for deletion. 779 // have received a finished event before marking them for deletion.
771 for (size_t i = 0; i < animations_.size(); i++) { 780 for (size_t i = 0; i < animations_.size(); i++) {
772 int group_id = animations_[i]->group(); 781 int group_id = animations_[i]->group();
773 if (animations_[i]->run_state() == Animation::ABORTED) { 782 if (animations_[i]->run_state() == Animation::Aborted) {
774 if (events && !animations_[i]->is_impl_only()) { 783 if (events && !animations_[i]->is_impl_only()) {
775 AnimationEvent aborted_event(AnimationEvent::ABORTED, id_, group_id, 784 AnimationEvent aborted_event(AnimationEvent::Aborted,
785 id_,
786 group_id,
776 animations_[i]->target_property(), 787 animations_[i]->target_property(),
777 monotonic_time); 788 monotonic_time);
778 events->push_back(aborted_event); 789 events->push_back(aborted_event);
779 } 790 }
780 animations_[i]->SetRunState(Animation::WAITING_FOR_DELETION, 791 animations_[i]->SetRunState(Animation::WaitingForDeletion,
781 monotonic_time); 792 monotonic_time);
782 marked_animations_for_deletions = true; 793 marked_animations_for_deletions = true;
783 continue; 794 continue;
784 } 795 }
785 796
786 bool all_anims_with_same_id_are_finished = false; 797 bool all_anims_with_same_id_are_finished = false;
787 798
788 // Since deleting an animation on the main thread leads to its deletion 799 // Since deleting an animation on the main thread leads to its deletion
789 // on the impl thread, we only mark a FINISHED main thread animation for 800 // on the impl thread, we only mark a Finished main thread animation for
790 // deletion once it has received a FINISHED event from the impl thread. 801 // deletion once it has received a Finished event from the impl thread.
791 bool animation_i_will_send_or_has_received_finish_event = 802 bool animation_i_will_send_or_has_received_finish_event =
792 events || animations_[i]->received_finished_event(); 803 events || animations_[i]->received_finished_event();
793 // If an animation is finished, and not already marked for deletion, 804 // If an animation is finished, and not already marked for deletion,
794 // find out if all other animations in the same group are also finished. 805 // find out if all other animations in the same group are also finished.
795 if (animations_[i]->run_state() == Animation::FINISHED && 806 if (animations_[i]->run_state() == Animation::Finished &&
796 animation_i_will_send_or_has_received_finish_event) { 807 animation_i_will_send_or_has_received_finish_event) {
797 // Clear the animations_with_same_group_id if it was added for 808 // Clear the animations_with_same_group_id if it was added for
798 // the previous animation's iteration. 809 // the previous animation's iteration.
799 if (animations_with_same_group_id.size() > 0) 810 if (animations_with_same_group_id.size() > 0)
800 animations_with_same_group_id.clear(); 811 animations_with_same_group_id.clear();
801 all_anims_with_same_id_are_finished = true; 812 all_anims_with_same_id_are_finished = true;
802 for (size_t j = 0; j < animations_.size(); ++j) { 813 for (size_t j = 0; j < animations_.size(); ++j) {
803 bool animation_j_will_send_or_has_received_finish_event = 814 bool animation_j_will_send_or_has_received_finish_event =
804 events || animations_[j]->received_finished_event(); 815 events || animations_[j]->received_finished_event();
805 if (group_id == animations_[j]->group()) { 816 if (group_id == animations_[j]->group()) {
806 if (!animations_[j]->is_finished() || 817 if (!animations_[j]->is_finished() ||
807 (animations_[j]->run_state() == Animation::FINISHED && 818 (animations_[j]->run_state() == Animation::Finished &&
808 !animation_j_will_send_or_has_received_finish_event)) { 819 !animation_j_will_send_or_has_received_finish_event)) {
809 all_anims_with_same_id_are_finished = false; 820 all_anims_with_same_id_are_finished = false;
810 break; 821 break;
811 } else if (j >= i && 822 } else if (j >= i &&
812 animations_[j]->run_state() != Animation::ABORTED) { 823 animations_[j]->run_state() != Animation::Aborted) {
813 // Mark down the animations which belong to the same group 824 // Mark down the animations which belong to the same group
814 // and is not yet aborted. If this current iteration finds that all 825 // and is not yet aborted. If this current iteration finds that all
815 // animations with same ID are finished, then the marked 826 // animations with same ID are finished, then the marked
816 // animations below will be set to WAITING_FOR_DELETION in next 827 // animations below will be set to WaitingForDeletion in next
817 // iteration. 828 // iteration.
818 animations_with_same_group_id.push_back(j); 829 animations_with_same_group_id.push_back(j);
819 } 830 }
820 } 831 }
821 } 832 }
822 } 833 }
823 if (all_anims_with_same_id_are_finished) { 834 if (all_anims_with_same_id_are_finished) {
824 // We now need to remove all animations with the same group id as 835 // We now need to remove all animations with the same group id as
825 // group_id (and send along animation finished notifications, if 836 // group_id (and send along animation finished notifications, if
826 // necessary). 837 // necessary).
827 for (size_t j = 0; j < animations_with_same_group_id.size(); j++) { 838 for (size_t j = 0; j < animations_with_same_group_id.size(); j++) {
828 size_t animation_index = animations_with_same_group_id[j]; 839 size_t animation_index = animations_with_same_group_id[j];
829 if (events) { 840 if (events) {
830 AnimationEvent finished_event( 841 AnimationEvent finished_event(
831 AnimationEvent::FINISHED, id_, 842 AnimationEvent::Finished,
843 id_,
832 animations_[animation_index]->group(), 844 animations_[animation_index]->group(),
833 animations_[animation_index]->target_property(), 845 animations_[animation_index]->target_property(),
834 monotonic_time); 846 monotonic_time);
835 finished_event.is_impl_only = 847 finished_event.is_impl_only =
836 animations_[animation_index]->is_impl_only(); 848 animations_[animation_index]->is_impl_only();
837 if (finished_event.is_impl_only) 849 if (finished_event.is_impl_only)
838 NotifyAnimationFinished(finished_event); 850 NotifyAnimationFinished(finished_event);
839 else 851 else
840 events->push_back(finished_event); 852 events->push_back(finished_event);
841 } 853 }
842 animations_[animation_index]->SetRunState( 854 animations_[animation_index]->SetRunState(
843 Animation::WAITING_FOR_DELETION, monotonic_time); 855 Animation::WaitingForDeletion, monotonic_time);
844 } 856 }
845 marked_animations_for_deletions = true; 857 marked_animations_for_deletions = true;
846 } 858 }
847 } 859 }
848 if (marked_animations_for_deletions) 860 if (marked_animations_for_deletions)
849 NotifyObserversAnimationWaitingForDeletion(); 861 NotifyObserversAnimationWaitingForDeletion();
850 } 862 }
851 863
852 static bool IsWaitingForDeletion(Animation* animation) { 864 static bool IsWaitingForDeletion(Animation* animation) {
853 return animation->run_state() == Animation::WAITING_FOR_DELETION; 865 return animation->run_state() == Animation::WaitingForDeletion;
854 } 866 }
855 867
856 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() { 868 void LayerAnimationController::PurgeAnimationsMarkedForDeletion() {
857 animations_.erase(cc::remove_if(&animations_, 869 animations_.erase(cc::remove_if(&animations_,
858 animations_.begin(), 870 animations_.begin(),
859 animations_.end(), 871 animations_.end(),
860 IsWaitingForDeletion), 872 IsWaitingForDeletion),
861 animations_.end()); 873 animations_.end());
862 } 874 }
863 875
864 void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) { 876 void LayerAnimationController::TickAnimations(base::TimeTicks monotonic_time) {
865 for (size_t i = 0; i < animations_.size(); ++i) { 877 for (size_t i = 0; i < animations_.size(); ++i) {
866 if (animations_[i]->run_state() == Animation::STARTING || 878 if (animations_[i]->run_state() == Animation::Starting ||
867 animations_[i]->run_state() == Animation::RUNNING || 879 animations_[i]->run_state() == Animation::Running ||
868 animations_[i]->run_state() == Animation::PAUSED) { 880 animations_[i]->run_state() == Animation::Paused) {
869 if (!animations_[i]->InEffect(monotonic_time)) 881 if (!animations_[i]->InEffect(monotonic_time))
870 continue; 882 continue;
871 883
872 base::TimeDelta trimmed = 884 base::TimeDelta trimmed =
873 animations_[i]->TrimTimeToCurrentIteration(monotonic_time); 885 animations_[i]->TrimTimeToCurrentIteration(monotonic_time);
874 886
875 switch (animations_[i]->target_property()) { 887 switch (animations_[i]->target_property()) {
876 case Animation::TRANSFORM: { 888 case Animation::Transform: {
877 const TransformAnimationCurve* transform_animation_curve = 889 const TransformAnimationCurve* transform_animation_curve =
878 animations_[i]->curve()->ToTransformAnimationCurve(); 890 animations_[i]->curve()->ToTransformAnimationCurve();
879 const gfx::Transform transform = 891 const gfx::Transform transform =
880 transform_animation_curve->GetValue(trimmed); 892 transform_animation_curve->GetValue(trimmed);
881 NotifyObserversTransformAnimated( 893 NotifyObserversTransformAnimated(
882 transform, 894 transform,
883 animations_[i]->affects_active_observers(), 895 animations_[i]->affects_active_observers(),
884 animations_[i]->affects_pending_observers()); 896 animations_[i]->affects_pending_observers());
885 break; 897 break;
886 } 898 }
887 899
888 case Animation::OPACITY: { 900 case Animation::Opacity: {
889 const FloatAnimationCurve* float_animation_curve = 901 const FloatAnimationCurve* float_animation_curve =
890 animations_[i]->curve()->ToFloatAnimationCurve(); 902 animations_[i]->curve()->ToFloatAnimationCurve();
891 const float opacity = std::max( 903 const float opacity = std::max(
892 std::min(float_animation_curve->GetValue(trimmed), 1.0f), 0.f); 904 std::min(float_animation_curve->GetValue(trimmed), 1.0f), 0.f);
893 NotifyObserversOpacityAnimated( 905 NotifyObserversOpacityAnimated(
894 opacity, 906 opacity,
895 animations_[i]->affects_active_observers(), 907 animations_[i]->affects_active_observers(),
896 animations_[i]->affects_pending_observers()); 908 animations_[i]->affects_pending_observers());
897 break; 909 break;
898 } 910 }
899 911
900 case Animation::FILTER: { 912 case Animation::Filter: {
901 const FilterAnimationCurve* filter_animation_curve = 913 const FilterAnimationCurve* filter_animation_curve =
902 animations_[i]->curve()->ToFilterAnimationCurve(); 914 animations_[i]->curve()->ToFilterAnimationCurve();
903 const FilterOperations filter = 915 const FilterOperations filter =
904 filter_animation_curve->GetValue(trimmed); 916 filter_animation_curve->GetValue(trimmed);
905 NotifyObserversFilterAnimated( 917 NotifyObserversFilterAnimated(
906 filter, 918 filter,
907 animations_[i]->affects_active_observers(), 919 animations_[i]->affects_active_observers(),
908 animations_[i]->affects_pending_observers()); 920 animations_[i]->affects_pending_observers());
909 break; 921 break;
910 } 922 }
911 923
912 case Animation::BACKGROUND_COLOR: { 924 case Animation::BackgroundColor: {
913 // Not yet implemented. 925 // Not yet implemented.
914 break; 926 break;
915 } 927 }
916 928
917 case Animation::SCROLL_OFFSET: { 929 case Animation::ScrollOffset: {
918 const ScrollOffsetAnimationCurve* scroll_offset_animation_curve = 930 const ScrollOffsetAnimationCurve* scroll_offset_animation_curve =
919 animations_[i]->curve()->ToScrollOffsetAnimationCurve(); 931 animations_[i]->curve()->ToScrollOffsetAnimationCurve();
920 const gfx::ScrollOffset scroll_offset = 932 const gfx::ScrollOffset scroll_offset =
921 scroll_offset_animation_curve->GetValue(trimmed); 933 scroll_offset_animation_curve->GetValue(trimmed);
922 NotifyObserversScrollOffsetAnimated( 934 NotifyObserversScrollOffsetAnimated(
923 scroll_offset, 935 scroll_offset,
924 animations_[i]->affects_active_observers(), 936 animations_[i]->affects_active_observers(),
925 animations_[i]->affects_pending_observers()); 937 animations_[i]->affects_pending_observers());
926 break; 938 break;
927 } 939 }
940
941 // Do nothing for sentinel value.
942 case Animation::TargetPropertyEnumSize:
943 NOTREACHED();
928 } 944 }
929 } 945 }
930 } 946 }
931 } 947 }
932 948
933 void LayerAnimationController::UpdateActivation(UpdateActivationType type) { 949 void LayerAnimationController::UpdateActivation(UpdateActivationType type) {
934 bool force = type == FORCE_ACTIVATION; 950 bool force = type == ForceActivation;
935 if (registrar_) { 951 if (registrar_) {
936 bool was_active = is_active_; 952 bool was_active = is_active_;
937 is_active_ = false; 953 is_active_ = false;
938 for (size_t i = 0; i < animations_.size(); ++i) { 954 for (size_t i = 0; i < animations_.size(); ++i) {
939 if (animations_[i]->run_state() != Animation::WAITING_FOR_DELETION) { 955 if (animations_[i]->run_state() != Animation::WaitingForDeletion) {
940 is_active_ = true; 956 is_active_ = true;
941 break; 957 break;
942 } 958 }
943 } 959 }
944 960
945 if (is_active_ && (!was_active || force)) 961 if (is_active_ && (!was_active || force))
946 registrar_->DidActivateAnimationController(this); 962 registrar_->DidActivateAnimationController(this);
947 else if (!is_active_ && (was_active || force)) 963 else if (!is_active_ && (was_active || force))
948 registrar_->DidDeactivateAnimationController(this); 964 registrar_->DidDeactivateAnimationController(this);
949 } 965 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 value_observers_); 1054 value_observers_);
1039 LayerAnimationValueObserver* obs; 1055 LayerAnimationValueObserver* obs;
1040 while ((obs = it.GetNext()) != nullptr) 1056 while ((obs = it.GetNext()) != nullptr)
1041 if (obs->IsActive()) 1057 if (obs->IsActive())
1042 return true; 1058 return true;
1043 } 1059 }
1044 return false; 1060 return false;
1045 } 1061 }
1046 1062
1047 } // namespace cc 1063 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/layer_animation_controller.h ('k') | cc/animation/layer_animation_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698