mac: Add the flag "-gline-tables-only" to reduce dSYM size. (attempt #2)
[chromium-blink-merge.git] / ui / compositor / layer_animation_element.cc
blob9a528e5509a553bc153c66a9011464bcc5ad9aff
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
3 // found in the LICENSE file.
5 #include "ui/compositor/layer_animation_element.h"
7 #include "base/compiler_specific.h"
8 #include "cc/animation/animation.h"
9 #include "cc/animation/animation_id_provider.h"
10 #include "ui/compositor/float_animation_curve_adapter.h"
11 #include "ui/compositor/layer.h"
12 #include "ui/compositor/layer_animation_delegate.h"
13 #include "ui/compositor/layer_animator.h"
14 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
15 #include "ui/compositor/transform_animation_curve_adapter.h"
16 #include "ui/gfx/animation/tween.h"
17 #include "ui/gfx/interpolated_transform.h"
19 namespace ui {
21 namespace {
23 // The factor by which duration is scaled up or down when using
24 // ScopedAnimationDurationScaleMode.
25 const int kSlowDurationScaleMultiplier = 4;
26 const int kFastDurationScaleDivisor = 4;
27 const int kNonZeroDurationScaleDivisor = 20;
29 // Pause -----------------------------------------------------------------------
30 class Pause : public LayerAnimationElement {
31 public:
32 Pause(AnimatableProperties properties, base::TimeDelta duration)
33 : LayerAnimationElement(properties, duration) {
35 ~Pause() override {}
37 private:
38 void OnStart(LayerAnimationDelegate* delegate) override {}
39 bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
40 return false;
42 void OnGetTarget(TargetValue* target) const override {}
43 void OnAbort(LayerAnimationDelegate* delegate) override {}
45 DISALLOW_COPY_AND_ASSIGN(Pause);
48 // TransformTransition ---------------------------------------------------------
50 class TransformTransition : public LayerAnimationElement {
51 public:
52 TransformTransition(const gfx::Transform& target, base::TimeDelta duration)
53 : LayerAnimationElement(TRANSFORM, duration),
54 target_(target) {
56 ~TransformTransition() override {}
58 protected:
59 void OnStart(LayerAnimationDelegate* delegate) override {
60 start_ = delegate->GetTransformForAnimation();
63 bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
64 delegate->SetTransformFromAnimation(
65 gfx::Tween::TransformValueBetween(t, start_, target_));
66 return true;
69 void OnGetTarget(TargetValue* target) const override {
70 target->transform = target_;
73 void OnAbort(LayerAnimationDelegate* delegate) override {}
75 private:
76 gfx::Transform start_;
77 const gfx::Transform target_;
79 DISALLOW_COPY_AND_ASSIGN(TransformTransition);
82 // InterpolatedTransformTransition ---------------------------------------------
84 class InterpolatedTransformTransition : public LayerAnimationElement {
85 public:
86 InterpolatedTransformTransition(InterpolatedTransform* interpolated_transform,
87 base::TimeDelta duration)
88 : LayerAnimationElement(TRANSFORM, duration),
89 interpolated_transform_(interpolated_transform) {
91 ~InterpolatedTransformTransition() override {}
93 protected:
94 void OnStart(LayerAnimationDelegate* delegate) override {}
96 bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
97 delegate->SetTransformFromAnimation(
98 interpolated_transform_->Interpolate(static_cast<float>(t)));
99 return true;
102 void OnGetTarget(TargetValue* target) const override {
103 target->transform = interpolated_transform_->Interpolate(1.0f);
106 void OnAbort(LayerAnimationDelegate* delegate) override {}
108 private:
109 scoped_ptr<InterpolatedTransform> interpolated_transform_;
111 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformTransition);
114 // BoundsTransition ------------------------------------------------------------
116 class BoundsTransition : public LayerAnimationElement {
117 public:
118 BoundsTransition(const gfx::Rect& target, base::TimeDelta duration)
119 : LayerAnimationElement(BOUNDS, duration),
120 target_(target) {
122 ~BoundsTransition() override {}
124 protected:
125 void OnStart(LayerAnimationDelegate* delegate) override {
126 start_ = delegate->GetBoundsForAnimation();
129 bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
130 delegate->SetBoundsFromAnimation(
131 gfx::Tween::RectValueBetween(t, start_, target_));
132 return true;
135 void OnGetTarget(TargetValue* target) const override {
136 target->bounds = target_;
139 void OnAbort(LayerAnimationDelegate* delegate) override {}
141 private:
142 gfx::Rect start_;
143 const gfx::Rect target_;
145 DISALLOW_COPY_AND_ASSIGN(BoundsTransition);
148 // OpacityTransition -----------------------------------------------------------
150 class OpacityTransition : public LayerAnimationElement {
151 public:
152 OpacityTransition(float target, base::TimeDelta duration)
153 : LayerAnimationElement(OPACITY, duration),
154 start_(0.0f),
155 target_(target) {
157 ~OpacityTransition() override {}
159 protected:
160 void OnStart(LayerAnimationDelegate* delegate) override {
161 start_ = delegate->GetOpacityForAnimation();
164 bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
165 delegate->SetOpacityFromAnimation(
166 gfx::Tween::FloatValueBetween(t, start_, target_));
167 return true;
170 void OnGetTarget(TargetValue* target) const override {
171 target->opacity = target_;
174 void OnAbort(LayerAnimationDelegate* delegate) override {}
176 private:
177 float start_;
178 const float target_;
180 DISALLOW_COPY_AND_ASSIGN(OpacityTransition);
183 // VisibilityTransition --------------------------------------------------------
185 class VisibilityTransition : public LayerAnimationElement {
186 public:
187 VisibilityTransition(bool target, base::TimeDelta duration)
188 : LayerAnimationElement(VISIBILITY, duration),
189 start_(false),
190 target_(target) {
192 ~VisibilityTransition() override {}
194 protected:
195 void OnStart(LayerAnimationDelegate* delegate) override {
196 start_ = delegate->GetVisibilityForAnimation();
199 bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
200 delegate->SetVisibilityFromAnimation(t == 1.0 ? target_ : start_);
201 return t == 1.0;
204 void OnGetTarget(TargetValue* target) const override {
205 target->visibility = target_;
208 void OnAbort(LayerAnimationDelegate* delegate) override {}
210 private:
211 bool start_;
212 const bool target_;
214 DISALLOW_COPY_AND_ASSIGN(VisibilityTransition);
217 // BrightnessTransition --------------------------------------------------------
219 class BrightnessTransition : public LayerAnimationElement {
220 public:
221 BrightnessTransition(float target, base::TimeDelta duration)
222 : LayerAnimationElement(BRIGHTNESS, duration),
223 start_(0.0f),
224 target_(target) {
226 ~BrightnessTransition() override {}
228 protected:
229 void OnStart(LayerAnimationDelegate* delegate) override {
230 start_ = delegate->GetBrightnessForAnimation();
233 bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
234 delegate->SetBrightnessFromAnimation(
235 gfx::Tween::FloatValueBetween(t, start_, target_));
236 return true;
239 void OnGetTarget(TargetValue* target) const override {
240 target->brightness = target_;
243 void OnAbort(LayerAnimationDelegate* delegate) override {}
245 private:
246 float start_;
247 const float target_;
249 DISALLOW_COPY_AND_ASSIGN(BrightnessTransition);
252 // GrayscaleTransition ---------------------------------------------------------
254 class GrayscaleTransition : public LayerAnimationElement {
255 public:
256 GrayscaleTransition(float target, base::TimeDelta duration)
257 : LayerAnimationElement(GRAYSCALE, duration),
258 start_(0.0f),
259 target_(target) {
261 ~GrayscaleTransition() override {}
263 protected:
264 void OnStart(LayerAnimationDelegate* delegate) override {
265 start_ = delegate->GetGrayscaleForAnimation();
268 bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
269 delegate->SetGrayscaleFromAnimation(
270 gfx::Tween::FloatValueBetween(t, start_, target_));
271 return true;
274 void OnGetTarget(TargetValue* target) const override {
275 target->grayscale = target_;
278 void OnAbort(LayerAnimationDelegate* delegate) override {}
280 private:
281 float start_;
282 const float target_;
284 DISALLOW_COPY_AND_ASSIGN(GrayscaleTransition);
287 // ColorTransition -------------------------------------------------------------
289 class ColorTransition : public LayerAnimationElement {
290 public:
291 ColorTransition(SkColor target, base::TimeDelta duration)
292 : LayerAnimationElement(COLOR, duration),
293 start_(SK_ColorBLACK),
294 target_(target) {
296 ~ColorTransition() override {}
298 protected:
299 void OnStart(LayerAnimationDelegate* delegate) override {
300 start_ = delegate->GetColorForAnimation();
303 bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
304 delegate->SetColorFromAnimation(
305 gfx::Tween::ColorValueBetween(t, start_, target_));
306 return true;
309 void OnGetTarget(TargetValue* target) const override {
310 target->color = target_;
313 void OnAbort(LayerAnimationDelegate* delegate) override {}
315 private:
316 SkColor start_;
317 const SkColor target_;
319 DISALLOW_COPY_AND_ASSIGN(ColorTransition);
322 // ThreadedLayerAnimationElement -----------------------------------------------
324 class ThreadedLayerAnimationElement : public LayerAnimationElement {
325 public:
326 ThreadedLayerAnimationElement(AnimatableProperties properties,
327 base::TimeDelta duration)
328 : LayerAnimationElement(properties, duration) {
330 ~ThreadedLayerAnimationElement() override {}
332 bool IsThreaded() const override { return (duration() != base::TimeDelta()); }
334 protected:
335 explicit ThreadedLayerAnimationElement(const LayerAnimationElement& element)
336 : LayerAnimationElement(element) {
339 bool OnProgress(double t, LayerAnimationDelegate* delegate) override {
340 if (t < 1.0)
341 return false;
343 if (Started()) {
344 delegate->RemoveThreadedAnimation(animation_id());
347 OnEnd(delegate);
348 return true;
351 void OnAbort(LayerAnimationDelegate* delegate) override {
352 if (delegate && Started()) {
353 delegate->RemoveThreadedAnimation(animation_id());
357 void RequestEffectiveStart(LayerAnimationDelegate* delegate) override {
358 DCHECK(animation_group_id());
359 if (duration() == base::TimeDelta()) {
360 set_effective_start_time(requested_start_time());
361 return;
363 set_effective_start_time(base::TimeTicks());
364 scoped_ptr<cc::Animation> animation = CreateCCAnimation();
365 animation->set_needs_synchronized_start_time(true);
366 delegate->AddThreadedAnimation(animation.Pass());
369 virtual void OnEnd(LayerAnimationDelegate* delegate) = 0;
371 virtual scoped_ptr<cc::Animation> CreateCCAnimation() = 0;
373 private:
374 DISALLOW_COPY_AND_ASSIGN(ThreadedLayerAnimationElement);
377 // ThreadedOpacityTransition ---------------------------------------------------
379 class ThreadedOpacityTransition : public ThreadedLayerAnimationElement {
380 public:
381 ThreadedOpacityTransition(float target, base::TimeDelta duration)
382 : ThreadedLayerAnimationElement(OPACITY, duration),
383 start_(0.0f),
384 target_(target) {
386 ~ThreadedOpacityTransition() override {}
388 protected:
389 void OnStart(LayerAnimationDelegate* delegate) override {
390 start_ = delegate->GetOpacityForAnimation();
393 void OnAbort(LayerAnimationDelegate* delegate) override {
394 if (delegate && Started()) {
395 ThreadedLayerAnimationElement::OnAbort(delegate);
396 delegate->SetOpacityFromAnimation(gfx::Tween::FloatValueBetween(
397 gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()),
398 start_,
399 target_));
403 void OnEnd(LayerAnimationDelegate* delegate) override {
404 delegate->SetOpacityFromAnimation(target_);
407 scoped_ptr<cc::Animation> CreateCCAnimation() override {
408 scoped_ptr<cc::AnimationCurve> animation_curve(
409 new FloatAnimationCurveAdapter(tween_type(),
410 start_,
411 target_,
412 duration()));
413 scoped_ptr<cc::Animation> animation(
414 cc::Animation::Create(animation_curve.Pass(), animation_id(),
415 animation_group_id(), cc::Animation::OPACITY));
416 return animation.Pass();
419 void OnGetTarget(TargetValue* target) const override {
420 target->opacity = target_;
423 private:
424 float start_;
425 const float target_;
427 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition);
430 // ThreadedTransformTransition -------------------------------------------------
432 class ThreadedTransformTransition : public ThreadedLayerAnimationElement {
433 public:
434 ThreadedTransformTransition(const gfx::Transform& target,
435 base::TimeDelta duration)
436 : ThreadedLayerAnimationElement(TRANSFORM, duration),
437 target_(target) {
439 ~ThreadedTransformTransition() override {}
441 protected:
442 void OnStart(LayerAnimationDelegate* delegate) override {
443 start_ = delegate->GetTransformForAnimation();
446 void OnAbort(LayerAnimationDelegate* delegate) override {
447 if (delegate && Started()) {
448 ThreadedLayerAnimationElement::OnAbort(delegate);
449 delegate->SetTransformFromAnimation(gfx::Tween::TransformValueBetween(
450 gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()),
451 start_,
452 target_));
456 void OnEnd(LayerAnimationDelegate* delegate) override {
457 delegate->SetTransformFromAnimation(target_);
460 scoped_ptr<cc::Animation> CreateCCAnimation() override {
461 scoped_ptr<cc::AnimationCurve> animation_curve(
462 new TransformAnimationCurveAdapter(tween_type(),
463 start_,
464 target_,
465 duration()));
466 scoped_ptr<cc::Animation> animation(
467 cc::Animation::Create(animation_curve.Pass(), animation_id(),
468 animation_group_id(), cc::Animation::TRANSFORM));
469 return animation.Pass();
472 void OnGetTarget(TargetValue* target) const override {
473 target->transform = target_;
476 private:
477 gfx::Transform start_;
478 const gfx::Transform target_;
480 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition);
483 // InverseTransformTransision --------------------------------------------------
485 class InverseTransformTransition : public ThreadedLayerAnimationElement {
486 public:
487 InverseTransformTransition(const gfx::Transform& base_transform,
488 const LayerAnimationElement* uninverted_transition)
489 : ThreadedLayerAnimationElement(*uninverted_transition),
490 base_transform_(base_transform),
491 uninverted_transition_(
492 CheckAndCast<const ThreadedTransformTransition*>(
493 uninverted_transition)) {
495 ~InverseTransformTransition() override {}
497 static InverseTransformTransition* Clone(const LayerAnimationElement* other) {
498 const InverseTransformTransition* other_inverse =
499 CheckAndCast<const InverseTransformTransition*>(other);
500 return new InverseTransformTransition(
501 other_inverse->base_transform_, other_inverse->uninverted_transition_);
504 protected:
505 void OnStart(LayerAnimationDelegate* delegate) override {
506 gfx::Transform start(delegate->GetTransformForAnimation());
507 effective_start_ = base_transform_ * start;
509 TargetValue target;
510 uninverted_transition_->GetTargetValue(&target);
511 base_target_ = target.transform;
513 set_tween_type(uninverted_transition_->tween_type());
515 TransformAnimationCurveAdapter base_curve(tween_type(),
516 base_transform_,
517 base_target_,
518 duration());
520 animation_curve_.reset(new InverseTransformCurveAdapter(
521 base_curve, start, duration()));
522 computed_target_transform_ = ComputeWithBaseTransform(effective_start_,
523 base_target_);
526 void OnAbort(LayerAnimationDelegate* delegate) override {
527 if (delegate && Started()) {
528 ThreadedLayerAnimationElement::OnAbort(delegate);
529 delegate->SetTransformFromAnimation(ComputeCurrentTransform());
533 void OnEnd(LayerAnimationDelegate* delegate) override {
534 delegate->SetTransformFromAnimation(computed_target_transform_);
537 scoped_ptr<cc::Animation> CreateCCAnimation() override {
538 scoped_ptr<cc::Animation> animation(
539 cc::Animation::Create(animation_curve_->Clone(), animation_id(),
540 animation_group_id(), cc::Animation::TRANSFORM));
541 return animation.Pass();
544 void OnGetTarget(TargetValue* target) const override {
545 target->transform = computed_target_transform_;
548 private:
549 gfx::Transform ComputeCurrentTransform() const {
550 gfx::Transform base_current = gfx::Tween::TransformValueBetween(
551 gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()),
552 base_transform_,
553 base_target_);
554 return ComputeWithBaseTransform(effective_start_, base_current);
557 gfx::Transform ComputeWithBaseTransform(gfx::Transform start,
558 gfx::Transform target) const {
559 gfx::Transform to_return(gfx::Transform::kSkipInitialization);
560 bool success = target.GetInverse(&to_return);
561 DCHECK(success) << "Target transform must be invertible.";
563 to_return.PreconcatTransform(start);
564 return to_return;
567 template <typename T>
568 static T CheckAndCast(const LayerAnimationElement* element) {
569 AnimatableProperties properties = element->properties();
570 DCHECK(properties & TRANSFORM);
571 return static_cast<T>(element);
574 gfx::Transform effective_start_;
575 gfx::Transform computed_target_transform_;
577 const gfx::Transform base_transform_;
578 gfx::Transform base_target_;
580 scoped_ptr<cc::AnimationCurve> animation_curve_;
582 const ThreadedTransformTransition* const uninverted_transition_;
584 DISALLOW_COPY_AND_ASSIGN(InverseTransformTransition);
587 } // namespace
589 // LayerAnimationElement::TargetValue ------------------------------------------
591 LayerAnimationElement::TargetValue::TargetValue()
592 : opacity(0.0f),
593 visibility(false),
594 brightness(0.0f),
595 grayscale(0.0f),
596 color(SK_ColorBLACK) {
599 LayerAnimationElement::TargetValue::TargetValue(
600 const LayerAnimationDelegate* delegate)
601 : bounds(delegate ? delegate->GetBoundsForAnimation() : gfx::Rect()),
602 transform(delegate ?
603 delegate->GetTransformForAnimation() : gfx::Transform()),
604 opacity(delegate ? delegate->GetOpacityForAnimation() : 0.0f),
605 visibility(delegate ? delegate->GetVisibilityForAnimation() : false),
606 brightness(delegate ? delegate->GetBrightnessForAnimation() : 0.0f),
607 grayscale(delegate ? delegate->GetGrayscaleForAnimation() : 0.0f),
608 color(delegate ? delegate->GetColorForAnimation() : 0.0f) {
611 // LayerAnimationElement -------------------------------------------------------
613 LayerAnimationElement::LayerAnimationElement(
614 AnimatableProperties properties, base::TimeDelta duration)
615 : first_frame_(true),
616 properties_(properties),
617 duration_(GetEffectiveDuration(duration)),
618 tween_type_(gfx::Tween::LINEAR),
619 animation_id_(cc::AnimationIdProvider::NextAnimationId()),
620 animation_group_id_(0),
621 last_progressed_fraction_(0.0),
622 weak_ptr_factory_(this) {
625 LayerAnimationElement::LayerAnimationElement(
626 const LayerAnimationElement &element)
627 : first_frame_(element.first_frame_),
628 properties_(element.properties_),
629 duration_(element.duration_),
630 tween_type_(element.tween_type_),
631 animation_id_(cc::AnimationIdProvider::NextAnimationId()),
632 animation_group_id_(element.animation_group_id_),
633 last_progressed_fraction_(element.last_progressed_fraction_),
634 weak_ptr_factory_(this) {
637 LayerAnimationElement::~LayerAnimationElement() {
640 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate,
641 int animation_group_id) {
642 DCHECK(requested_start_time_ != base::TimeTicks());
643 DCHECK(first_frame_);
644 animation_group_id_ = animation_group_id;
645 last_progressed_fraction_ = 0.0;
646 OnStart(delegate);
647 RequestEffectiveStart(delegate);
648 first_frame_ = false;
651 bool LayerAnimationElement::Progress(base::TimeTicks now,
652 LayerAnimationDelegate* delegate) {
653 DCHECK(requested_start_time_ != base::TimeTicks());
654 DCHECK(!first_frame_);
656 bool need_draw;
657 double t = 1.0;
659 if ((effective_start_time_ == base::TimeTicks()) ||
660 (now < effective_start_time_)) {
661 // This hasn't actually started yet.
662 need_draw = false;
663 last_progressed_fraction_ = 0.0;
664 return need_draw;
667 base::TimeDelta elapsed = now - effective_start_time_;
668 if ((duration_ > base::TimeDelta()) && (elapsed < duration_))
669 t = elapsed.InMillisecondsF() / duration_.InMillisecondsF();
670 base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr());
671 need_draw = OnProgress(gfx::Tween::CalculateValue(tween_type_, t), delegate);
672 if (!alive)
673 return need_draw;
674 first_frame_ = t == 1.0;
675 last_progressed_fraction_ = t;
676 return need_draw;
679 bool LayerAnimationElement::IsFinished(base::TimeTicks time,
680 base::TimeDelta* total_duration) {
681 // If an effective start has been requested but the effective start time
682 // hasn't yet been set, the animation is not finished, regardless of the
683 // value of |time|.
684 if (!first_frame_ && (effective_start_time_ == base::TimeTicks()))
685 return false;
687 base::TimeDelta queueing_delay;
688 if (!first_frame_)
689 queueing_delay = effective_start_time_ - requested_start_time_;
691 base::TimeDelta elapsed = time - requested_start_time_;
692 if (elapsed >= duration_ + queueing_delay) {
693 *total_duration = duration_ + queueing_delay;
694 return true;
696 return false;
699 bool LayerAnimationElement::ProgressToEnd(LayerAnimationDelegate* delegate) {
700 if (first_frame_)
701 OnStart(delegate);
702 base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr());
703 bool need_draw = OnProgress(1.0, delegate);
704 if (!alive)
705 return need_draw;
706 last_progressed_fraction_ = 1.0;
707 first_frame_ = true;
708 return need_draw;
711 void LayerAnimationElement::GetTargetValue(TargetValue* target) const {
712 OnGetTarget(target);
715 bool LayerAnimationElement::IsThreaded() const {
716 return false;
719 void LayerAnimationElement::Abort(LayerAnimationDelegate* delegate) {
720 OnAbort(delegate);
721 first_frame_ = true;
724 void LayerAnimationElement::RequestEffectiveStart(
725 LayerAnimationDelegate* delegate) {
726 DCHECK(requested_start_time_ != base::TimeTicks());
727 effective_start_time_ = requested_start_time_;
730 // static
731 LayerAnimationElement::AnimatableProperty
732 LayerAnimationElement::ToAnimatableProperty(
733 cc::Animation::TargetProperty property) {
734 switch (property) {
735 case cc::Animation::TRANSFORM:
736 return TRANSFORM;
737 case cc::Animation::OPACITY:
738 return OPACITY;
739 default:
740 NOTREACHED();
741 return AnimatableProperty();
745 // static
746 base::TimeDelta LayerAnimationElement::GetEffectiveDuration(
747 const base::TimeDelta& duration) {
748 switch (ScopedAnimationDurationScaleMode::duration_scale_mode()) {
749 case ScopedAnimationDurationScaleMode::NORMAL_DURATION:
750 return duration;
751 case ScopedAnimationDurationScaleMode::FAST_DURATION:
752 return duration / kFastDurationScaleDivisor;
753 case ScopedAnimationDurationScaleMode::SLOW_DURATION:
754 return duration * kSlowDurationScaleMultiplier;
755 case ScopedAnimationDurationScaleMode::NON_ZERO_DURATION:
756 return duration / kNonZeroDurationScaleDivisor;
757 case ScopedAnimationDurationScaleMode::ZERO_DURATION:
758 return base::TimeDelta();
759 default:
760 NOTREACHED();
761 return base::TimeDelta();
765 // static
766 LayerAnimationElement* LayerAnimationElement::CreateTransformElement(
767 const gfx::Transform& transform,
768 base::TimeDelta duration) {
769 return new ThreadedTransformTransition(transform, duration);
772 // static
773 LayerAnimationElement* LayerAnimationElement::CreateInverseTransformElement(
774 const gfx::Transform& base_transform,
775 const LayerAnimationElement* uninverted_transition) {
776 return new InverseTransformTransition(base_transform, uninverted_transition);
779 // static
780 LayerAnimationElement* LayerAnimationElement::CloneInverseTransformElement(
781 const LayerAnimationElement* other) {
782 return InverseTransformTransition::Clone(other);
785 // static
786 LayerAnimationElement*
787 LayerAnimationElement::CreateInterpolatedTransformElement(
788 InterpolatedTransform* interpolated_transform,
789 base::TimeDelta duration) {
790 return new InterpolatedTransformTransition(interpolated_transform, duration);
793 // static
794 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement(
795 const gfx::Rect& bounds,
796 base::TimeDelta duration) {
797 return new BoundsTransition(bounds, duration);
800 // static
801 LayerAnimationElement* LayerAnimationElement::CreateOpacityElement(
802 float opacity,
803 base::TimeDelta duration) {
804 return new ThreadedOpacityTransition(opacity, duration);
807 // static
808 LayerAnimationElement* LayerAnimationElement::CreateVisibilityElement(
809 bool visibility,
810 base::TimeDelta duration) {
811 return new VisibilityTransition(visibility, duration);
814 // static
815 LayerAnimationElement* LayerAnimationElement::CreateBrightnessElement(
816 float brightness,
817 base::TimeDelta duration) {
818 return new BrightnessTransition(brightness, duration);
821 // static
822 LayerAnimationElement* LayerAnimationElement::CreateGrayscaleElement(
823 float grayscale,
824 base::TimeDelta duration) {
825 return new GrayscaleTransition(grayscale, duration);
828 // static
829 LayerAnimationElement* LayerAnimationElement::CreatePauseElement(
830 AnimatableProperties properties,
831 base::TimeDelta duration) {
832 return new Pause(properties, duration);
835 // static
836 LayerAnimationElement* LayerAnimationElement::CreateColorElement(
837 SkColor color,
838 base::TimeDelta duration) {
839 return new ColorTransition(color, duration);
842 } // namespace ui