OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/compositor/layer_animation_element.h" | 5 #include "ui/compositor/layer_animation_element.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "cc/animation/animation.h" | 8 #include "cc/animation/animation.h" |
9 #include "cc/animation/animation_id_provider.h" | 9 #include "cc/animation/animation_id_provider.h" |
10 #include "ui/base/animation/tween.h" | |
11 #include "ui/compositor/float_animation_curve_adapter.h" | 10 #include "ui/compositor/float_animation_curve_adapter.h" |
12 #include "ui/compositor/layer.h" | 11 #include "ui/compositor/layer.h" |
13 #include "ui/compositor/layer_animation_delegate.h" | 12 #include "ui/compositor/layer_animation_delegate.h" |
14 #include "ui/compositor/layer_animator.h" | 13 #include "ui/compositor/layer_animator.h" |
15 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 14 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
16 #include "ui/compositor/transform_animation_curve_adapter.h" | 15 #include "ui/compositor/transform_animation_curve_adapter.h" |
| 16 #include "ui/gfx/animation/tween.h" |
17 #include "ui/gfx/interpolated_transform.h" | 17 #include "ui/gfx/interpolated_transform.h" |
18 | 18 |
19 namespace ui { | 19 namespace ui { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // The factor by which duration is scaled up or down when | 23 // The factor by which duration is scaled up or down when |
24 // ScopedAnimationDurationScaleMode::duration_scale_mode() is SLOW_DURATION or | 24 // ScopedAnimationDurationScaleMode::duration_scale_mode() is SLOW_DURATION or |
25 // FAST_DURATION. | 25 // FAST_DURATION. |
26 const int kSlowDurationScaleFactor = 4; | 26 const int kSlowDurationScaleFactor = 4; |
(...skipping 29 matching lines...) Expand all Loading... |
56 } | 56 } |
57 virtual ~TransformTransition() {} | 57 virtual ~TransformTransition() {} |
58 | 58 |
59 protected: | 59 protected: |
60 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 60 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
61 start_ = delegate->GetTransformForAnimation(); | 61 start_ = delegate->GetTransformForAnimation(); |
62 } | 62 } |
63 | 63 |
64 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 64 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
65 delegate->SetTransformFromAnimation( | 65 delegate->SetTransformFromAnimation( |
66 Tween::ValueBetween(t, start_, target_)); | 66 gfx::Tween::ValueBetween(t, start_, target_)); |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 70 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
71 target->transform = target_; | 71 target->transform = target_; |
72 } | 72 } |
73 | 73 |
74 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 74 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
75 | 75 |
76 private: | 76 private: |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 target_(target) { | 134 target_(target) { |
135 } | 135 } |
136 virtual ~BoundsTransition() {} | 136 virtual ~BoundsTransition() {} |
137 | 137 |
138 protected: | 138 protected: |
139 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 139 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
140 start_ = delegate->GetBoundsForAnimation(); | 140 start_ = delegate->GetBoundsForAnimation(); |
141 } | 141 } |
142 | 142 |
143 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 143 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
144 delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_)); | 144 delegate->SetBoundsFromAnimation( |
| 145 gfx::Tween::ValueBetween(t, start_, target_)); |
145 return true; | 146 return true; |
146 } | 147 } |
147 | 148 |
148 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 149 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
149 target->bounds = target_; | 150 target->bounds = target_; |
150 } | 151 } |
151 | 152 |
152 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 153 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
153 | 154 |
154 private: | 155 private: |
(...skipping 19 matching lines...) Expand all Loading... |
174 target_(target) { | 175 target_(target) { |
175 } | 176 } |
176 virtual ~OpacityTransition() {} | 177 virtual ~OpacityTransition() {} |
177 | 178 |
178 protected: | 179 protected: |
179 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 180 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
180 start_ = delegate->GetOpacityForAnimation(); | 181 start_ = delegate->GetOpacityForAnimation(); |
181 } | 182 } |
182 | 183 |
183 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 184 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
184 delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_)); | 185 delegate->SetOpacityFromAnimation( |
| 186 gfx::Tween::ValueBetween(t, start_, target_)); |
185 return true; | 187 return true; |
186 } | 188 } |
187 | 189 |
188 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 190 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
189 target->opacity = target_; | 191 target->opacity = target_; |
190 } | 192 } |
191 | 193 |
192 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 194 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
193 | 195 |
194 private: | 196 private: |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 257 } |
256 virtual ~BrightnessTransition() {} | 258 virtual ~BrightnessTransition() {} |
257 | 259 |
258 protected: | 260 protected: |
259 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 261 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
260 start_ = delegate->GetBrightnessForAnimation(); | 262 start_ = delegate->GetBrightnessForAnimation(); |
261 } | 263 } |
262 | 264 |
263 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 265 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
264 delegate->SetBrightnessFromAnimation( | 266 delegate->SetBrightnessFromAnimation( |
265 Tween::ValueBetween(t, start_, target_)); | 267 gfx::Tween::ValueBetween(t, start_, target_)); |
266 return true; | 268 return true; |
267 } | 269 } |
268 | 270 |
269 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 271 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
270 target->brightness = target_; | 272 target->brightness = target_; |
271 } | 273 } |
272 | 274 |
273 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 275 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
274 | 276 |
275 private: | 277 private: |
(...skipping 20 matching lines...) Expand all Loading... |
296 } | 298 } |
297 virtual ~GrayscaleTransition() {} | 299 virtual ~GrayscaleTransition() {} |
298 | 300 |
299 protected: | 301 protected: |
300 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 302 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
301 start_ = delegate->GetGrayscaleForAnimation(); | 303 start_ = delegate->GetGrayscaleForAnimation(); |
302 } | 304 } |
303 | 305 |
304 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 306 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
305 delegate->SetGrayscaleFromAnimation( | 307 delegate->SetGrayscaleFromAnimation( |
306 Tween::ValueBetween(t, start_, target_)); | 308 gfx::Tween::ValueBetween(t, start_, target_)); |
307 return true; | 309 return true; |
308 } | 310 } |
309 | 311 |
310 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 312 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
311 target->grayscale = target_; | 313 target->grayscale = target_; |
312 } | 314 } |
313 | 315 |
314 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 316 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
315 | 317 |
316 private: | 318 private: |
(...skipping 21 matching lines...) Expand all Loading... |
338 virtual ~ColorTransition() {} | 340 virtual ~ColorTransition() {} |
339 | 341 |
340 protected: | 342 protected: |
341 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 343 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
342 start_ = delegate->GetColorForAnimation(); | 344 start_ = delegate->GetColorForAnimation(); |
343 } | 345 } |
344 | 346 |
345 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 347 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
346 delegate->SetColorFromAnimation( | 348 delegate->SetColorFromAnimation( |
347 SkColorSetARGB( | 349 SkColorSetARGB( |
348 Tween::ValueBetween(t, | 350 gfx::Tween::ValueBetween(t, |
349 static_cast<int>(SkColorGetA(start_)), | 351 static_cast<int>(SkColorGetA(start_)), |
350 static_cast<int>(SkColorGetA(target_))), | 352 static_cast<int>(SkColorGetA(target_))), |
351 Tween::ValueBetween(t, | 353 gfx::Tween::ValueBetween(t, |
352 static_cast<int>(SkColorGetR(start_)), | 354 static_cast<int>(SkColorGetR(start_)), |
353 static_cast<int>(SkColorGetR(target_))), | 355 static_cast<int>(SkColorGetR(target_))), |
354 Tween::ValueBetween(t, | 356 gfx::Tween::ValueBetween(t, |
355 static_cast<int>(SkColorGetG(start_)), | 357 static_cast<int>(SkColorGetG(start_)), |
356 static_cast<int>(SkColorGetG(target_))), | 358 static_cast<int>(SkColorGetG(target_))), |
357 Tween::ValueBetween(t, | 359 gfx::Tween::ValueBetween(t, |
358 static_cast<int>(SkColorGetB(start_)), | 360 static_cast<int>(SkColorGetB(start_)), |
359 static_cast<int>(SkColorGetB(target_))))); | 361 static_cast<int>(SkColorGetB(target_))))); |
360 return true; | 362 return true; |
361 } | 363 } |
362 | 364 |
363 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 365 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
364 target->color = target_; | 366 target->color = target_; |
365 } | 367 } |
366 | 368 |
367 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 369 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
368 | 370 |
369 private: | 371 private: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 virtual ~ThreadedOpacityTransition() {} | 452 virtual ~ThreadedOpacityTransition() {} |
451 | 453 |
452 protected: | 454 protected: |
453 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 455 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
454 start_ = delegate->GetOpacityForAnimation(); | 456 start_ = delegate->GetOpacityForAnimation(); |
455 } | 457 } |
456 | 458 |
457 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { | 459 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { |
458 if (delegate && Started()) { | 460 if (delegate && Started()) { |
459 ThreadedLayerAnimationElement::OnAbort(delegate); | 461 ThreadedLayerAnimationElement::OnAbort(delegate); |
460 delegate->SetOpacityFromAnimation(Tween::ValueBetween( | 462 delegate->SetOpacityFromAnimation(gfx::Tween::ValueBetween( |
461 Tween::CalculateValue(tween_type(), last_progressed_fraction()), | 463 gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()), |
462 start_, | 464 start_, |
463 target_)); | 465 target_)); |
464 } | 466 } |
465 } | 467 } |
466 | 468 |
467 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE { | 469 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE { |
468 delegate->SetOpacityFromAnimation(target_); | 470 delegate->SetOpacityFromAnimation(target_); |
469 } | 471 } |
470 | 472 |
471 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { | 473 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { |
472 scoped_ptr<cc::AnimationCurve> animation_curve( | 474 scoped_ptr<cc::AnimationCurve> animation_curve( |
473 new FloatAnimationCurveAdapter(tween_type(), | 475 new FloatAnimationCurveAdapter(tween_type(), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 float device_scale_factor = delegate->GetDeviceScaleFactor(); | 518 float device_scale_factor = delegate->GetDeviceScaleFactor(); |
517 cc_start_ = Layer::ConvertTransformToCCTransform(start_, | 519 cc_start_ = Layer::ConvertTransformToCCTransform(start_, |
518 device_scale_factor); | 520 device_scale_factor); |
519 cc_target_ = Layer::ConvertTransformToCCTransform(target_, | 521 cc_target_ = Layer::ConvertTransformToCCTransform(target_, |
520 device_scale_factor); | 522 device_scale_factor); |
521 } | 523 } |
522 | 524 |
523 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { | 525 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { |
524 if (delegate && Started()) { | 526 if (delegate && Started()) { |
525 ThreadedLayerAnimationElement::OnAbort(delegate); | 527 ThreadedLayerAnimationElement::OnAbort(delegate); |
526 delegate->SetTransformFromAnimation(Tween::ValueBetween( | 528 delegate->SetTransformFromAnimation(gfx::Tween::ValueBetween( |
527 Tween::CalculateValue(tween_type(), last_progressed_fraction()), | 529 gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()), |
528 start_, | 530 start_, |
529 target_)); | 531 target_)); |
530 } | 532 } |
531 } | 533 } |
532 | 534 |
533 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE { | 535 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE { |
534 delegate->SetTransformFromAnimation(target_); | 536 delegate->SetTransformFromAnimation(target_); |
535 } | 537 } |
536 | 538 |
537 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { | 539 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 cc::Animation::Transform)); | 640 cc::Animation::Transform)); |
639 return animation.Pass(); | 641 return animation.Pass(); |
640 } | 642 } |
641 | 643 |
642 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 644 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
643 target->transform = computed_target_transform_; | 645 target->transform = computed_target_transform_; |
644 } | 646 } |
645 | 647 |
646 private: | 648 private: |
647 gfx::Transform ComputeCurrentTransform() const { | 649 gfx::Transform ComputeCurrentTransform() const { |
648 gfx::Transform base_current = Tween::ValueBetween( | 650 gfx::Transform base_current = gfx::Tween::ValueBetween( |
649 Tween::CalculateValue(tween_type(), last_progressed_fraction()), | 651 gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()), |
650 base_transform_, | 652 base_transform_, |
651 base_target_); | 653 base_target_); |
652 return ComputeWithBaseTransform(effective_start_, base_current); | 654 return ComputeWithBaseTransform(effective_start_, base_current); |
653 } | 655 } |
654 | 656 |
655 gfx::Transform ComputeWithBaseTransform(gfx::Transform start, | 657 gfx::Transform ComputeWithBaseTransform(gfx::Transform start, |
656 gfx::Transform target) const { | 658 gfx::Transform target) const { |
657 gfx::Transform to_return(gfx::Transform::kSkipInitialization); | 659 gfx::Transform to_return(gfx::Transform::kSkipInitialization); |
658 bool success = target.GetInverse(&to_return); | 660 bool success = target.GetInverse(&to_return); |
659 DCHECK(success) << "Target transform must be invertible."; | 661 DCHECK(success) << "Target transform must be invertible."; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 } | 715 } |
714 | 716 |
715 // LayerAnimationElement ------------------------------------------------------- | 717 // LayerAnimationElement ------------------------------------------------------- |
716 | 718 |
717 LayerAnimationElement::LayerAnimationElement( | 719 LayerAnimationElement::LayerAnimationElement( |
718 const AnimatableProperties& properties, | 720 const AnimatableProperties& properties, |
719 base::TimeDelta duration) | 721 base::TimeDelta duration) |
720 : first_frame_(true), | 722 : first_frame_(true), |
721 properties_(properties), | 723 properties_(properties), |
722 duration_(GetEffectiveDuration(duration)), | 724 duration_(GetEffectiveDuration(duration)), |
723 tween_type_(Tween::LINEAR), | 725 tween_type_(gfx::Tween::LINEAR), |
724 animation_id_(cc::AnimationIdProvider::NextAnimationId()), | 726 animation_id_(cc::AnimationIdProvider::NextAnimationId()), |
725 animation_group_id_(0), | 727 animation_group_id_(0), |
726 last_progressed_fraction_(0.0) { | 728 last_progressed_fraction_(0.0) { |
727 } | 729 } |
728 | 730 |
729 LayerAnimationElement::LayerAnimationElement( | 731 LayerAnimationElement::LayerAnimationElement( |
730 const LayerAnimationElement &element) | 732 const LayerAnimationElement &element) |
731 : first_frame_(element.first_frame_), | 733 : first_frame_(element.first_frame_), |
732 properties_(element.properties_), | 734 properties_(element.properties_), |
733 duration_(element.duration_), | 735 duration_(element.duration_), |
(...skipping 29 matching lines...) Expand all Loading... |
763 (now < effective_start_time_)) { | 765 (now < effective_start_time_)) { |
764 // This hasn't actually started yet. | 766 // This hasn't actually started yet. |
765 need_draw = false; | 767 need_draw = false; |
766 last_progressed_fraction_ = 0.0; | 768 last_progressed_fraction_ = 0.0; |
767 return need_draw; | 769 return need_draw; |
768 } | 770 } |
769 | 771 |
770 base::TimeDelta elapsed = now - effective_start_time_; | 772 base::TimeDelta elapsed = now - effective_start_time_; |
771 if ((duration_ > base::TimeDelta()) && (elapsed < duration_)) | 773 if ((duration_ > base::TimeDelta()) && (elapsed < duration_)) |
772 t = elapsed.InMillisecondsF() / duration_.InMillisecondsF(); | 774 t = elapsed.InMillisecondsF() / duration_.InMillisecondsF(); |
773 need_draw = OnProgress(Tween::CalculateValue(tween_type_, t), delegate); | 775 need_draw = OnProgress(gfx::Tween::CalculateValue(tween_type_, t), delegate); |
774 first_frame_ = t == 1.0; | 776 first_frame_ = t == 1.0; |
775 last_progressed_fraction_ = t; | 777 last_progressed_fraction_ = t; |
776 return need_draw; | 778 return need_draw; |
777 } | 779 } |
778 | 780 |
779 bool LayerAnimationElement::IsFinished(base::TimeTicks time, | 781 bool LayerAnimationElement::IsFinished(base::TimeTicks time, |
780 base::TimeDelta* total_duration) { | 782 base::TimeDelta* total_duration) { |
781 // If an effective start has been requested but the effective start time | 783 // If an effective start has been requested but the effective start time |
782 // hasn't yet been set, the animation is not finished, regardless of the | 784 // hasn't yet been set, the animation is not finished, regardless of the |
783 // value of |time|. | 785 // value of |time|. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 } | 930 } |
929 | 931 |
930 // static | 932 // static |
931 LayerAnimationElement* LayerAnimationElement::CreateColorElement( | 933 LayerAnimationElement* LayerAnimationElement::CreateColorElement( |
932 SkColor color, | 934 SkColor color, |
933 base::TimeDelta duration) { | 935 base::TimeDelta duration) { |
934 return new ColorTransition(color, duration); | 936 return new ColorTransition(color, duration); |
935 } | 937 } |
936 | 938 |
937 } // namespace ui | 939 } // namespace ui |
OLD | NEW |