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

Side by Side Diff: ui/compositor/layer_animation_element.cc

Issue 12226080: Thread ui transform animations (Closed) Base URL: http://git.chromium.org/chromium/src.git@DefineThreadedLayerAnimationElements
Patch Set: Fix WebContentsViewAuraTest.QuickOverscrollDirectionChange Created 7 years, 9 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 (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.h" 8 #include "cc/animation.h"
9 #include "cc/animation_id_provider.h" 9 #include "cc/animation_id_provider.h"
10 #include "ui/base/animation/tween.h" 10 #include "ui/base/animation/tween.h"
11 #include "ui/compositor/float_animation_curve_adapter.h" 11 #include "ui/compositor/float_animation_curve_adapter.h"
12 #include "ui/compositor/layer.h"
12 #include "ui/compositor/layer_animation_delegate.h" 13 #include "ui/compositor/layer_animation_delegate.h"
13 #include "ui/compositor/layer_animator.h" 14 #include "ui/compositor/layer_animator.h"
15 #include "ui/compositor/transform_animation_curve_adapter.h"
14 #include "ui/gfx/interpolated_transform.h" 16 #include "ui/gfx/interpolated_transform.h"
15 17
16 namespace ui { 18 namespace ui {
17 19
18 namespace { 20 namespace {
19 21
20 // Pause ----------------------------------------------------------------------- 22 // Pause -----------------------------------------------------------------------
21 class Pause : public LayerAnimationElement { 23 class Pause : public LayerAnimationElement {
22 public: 24 public:
23 Pause(const AnimatableProperties& properties, base::TimeDelta duration) 25 Pause(const AnimatableProperties& properties, base::TimeDelta duration)
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 properties.insert(LayerAnimationElement::OPACITY); 481 properties.insert(LayerAnimationElement::OPACITY);
480 return properties; 482 return properties;
481 } 483 }
482 484
483 float start_; 485 float start_;
484 const float target_; 486 const float target_;
485 487
486 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition); 488 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition);
487 }; 489 };
488 490
491 // ThreadedTransformTransition -------------------------------------------------
492
493 class ThreadedTransformTransition : public ThreadedLayerAnimationElement {
494 public:
495 ThreadedTransformTransition(const gfx::Transform& target,
496 base::TimeDelta duration)
497 : ThreadedLayerAnimationElement(GetProperties(), duration),
498 target_(target) {
499 }
500 virtual ~ThreadedTransformTransition() {}
501
502 protected:
503 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
504 gfx::Transform start_ = delegate->GetTransformForAnimation();
505 gfx::Rect bounds = delegate->GetBoundsForAnimation();
506 float device_scale_factor = delegate->GetDeviceScaleFactor();
507 cc_start_ = Layer::ConvertTransformToCCTransform(start_,
508 bounds,
509 device_scale_factor);
510 cc_target_ = Layer::ConvertTransformToCCTransform(target_,
511 bounds,
512 device_scale_factor);
513 }
514
515 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
516 if (delegate && animation_id()) {
517 ThreadedLayerAnimationElement::OnAbort(delegate);
518 delegate->SetTransformFromAnimation(Tween::ValueBetween(
519 Tween::CalculateValue(tween_type(), last_progressed_fraction()),
520 start_,
521 target_));
522 }
523 }
524
525 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE {
526 delegate->SetTransformFromAnimation(target_);
527 }
528
529 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE {
530 scoped_ptr<cc::AnimationCurve> animation_curve(
531 new TransformAnimationCurveAdapter(tween_type(),
532 cc_start_,
533 cc_target_,
534 duration()));
535 scoped_ptr<cc::Animation> animation(
536 cc::Animation::create(animation_curve.Pass(),
537 animation_id(),
538 animation_group_id(),
539 cc::Animation::Transform));
540 return animation.Pass();
541 }
542
543 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
544 target->transform = target_;
545 }
546
547 private:
548 static AnimatableProperties GetProperties() {
549 AnimatableProperties properties;
550 properties.insert(LayerAnimationElement::TRANSFORM);
551 return properties;
552 }
553
554 gfx::Transform start_;
555 gfx::Transform cc_start_;
556 const gfx::Transform target_;
557 gfx::Transform cc_target_;
558
559 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition);
560 };
561
489 } // namespace 562 } // namespace
490 563
491 // LayerAnimationElement::TargetValue ------------------------------------------ 564 // LayerAnimationElement::TargetValue ------------------------------------------
492 565
493 LayerAnimationElement::TargetValue::TargetValue() 566 LayerAnimationElement::TargetValue::TargetValue()
494 : opacity(0.0f), 567 : opacity(0.0f),
495 visibility(false), 568 visibility(false),
496 brightness(0.0f), 569 brightness(0.0f),
497 grayscale(0.0f), 570 grayscale(0.0f),
498 color(SK_ColorBLACK) { 571 color(SK_ColorBLACK) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 if (LayerAnimator::slow_animation_mode()) 707 if (LayerAnimator::slow_animation_mode())
635 return duration * LayerAnimator::slow_animation_scale_factor(); 708 return duration * LayerAnimator::slow_animation_scale_factor();
636 709
637 return duration; 710 return duration;
638 } 711 }
639 712
640 // static 713 // static
641 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( 714 LayerAnimationElement* LayerAnimationElement::CreateTransformElement(
642 const gfx::Transform& transform, 715 const gfx::Transform& transform,
643 base::TimeDelta duration) { 716 base::TimeDelta duration) {
644 return new TransformTransition(transform, duration); 717 return new ThreadedTransformTransition(transform, duration);
645 } 718 }
646 719
647 // static 720 // static
648 LayerAnimationElement* 721 LayerAnimationElement*
649 LayerAnimationElement::CreateInterpolatedTransformElement( 722 LayerAnimationElement::CreateInterpolatedTransformElement(
650 InterpolatedTransform* interpolated_transform, 723 InterpolatedTransform* interpolated_transform,
651 base::TimeDelta duration) { 724 base::TimeDelta duration) {
652 return new InterpolatedTransformTransition(interpolated_transform, duration); 725 return new InterpolatedTransformTransition(interpolated_transform, duration);
653 } 726 }
654 727
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 } 768 }
696 769
697 // static 770 // static
698 LayerAnimationElement* LayerAnimationElement::CreateColorElement( 771 LayerAnimationElement* LayerAnimationElement::CreateColorElement(
699 SkColor color, 772 SkColor color,
700 base::TimeDelta duration) { 773 base::TimeDelta duration) {
701 return new ColorTransition(color, duration); 774 return new ColorTransition(color, duration);
702 } 775 }
703 776
704 } // namespace ui 777 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698