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

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: Speed up animations in 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"
14 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 15 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
16 #include "ui/compositor/transform_animation_curve_adapter.h"
15 #include "ui/gfx/interpolated_transform.h" 17 #include "ui/gfx/interpolated_transform.h"
16 18
17 namespace ui { 19 namespace ui {
18 20
19 namespace { 21 namespace {
20 22
21 // The factor by which duration is scaled up or down when 23 // The factor by which duration is scaled up or down when
22 // ScopedAnimationDurationScaleMode::duration_scale_mode() is SLOW_DURATION or 24 // ScopedAnimationDurationScaleMode::duration_scale_mode() is SLOW_DURATION or
23 // FAST_DURATION. 25 // FAST_DURATION.
24 const int kSlowDurationScaleFactor = 4; 26 const int kSlowDurationScaleFactor = 4;
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 properties.insert(LayerAnimationElement::OPACITY); 488 properties.insert(LayerAnimationElement::OPACITY);
487 return properties; 489 return properties;
488 } 490 }
489 491
490 float start_; 492 float start_;
491 const float target_; 493 const float target_;
492 494
493 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition); 495 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition);
494 }; 496 };
495 497
498 // ThreadedTransformTransition -------------------------------------------------
499
500 class ThreadedTransformTransition : public ThreadedLayerAnimationElement {
501 public:
502 ThreadedTransformTransition(const gfx::Transform& target,
503 base::TimeDelta duration)
504 : ThreadedLayerAnimationElement(GetProperties(), duration),
505 target_(target) {
506 }
507 virtual ~ThreadedTransformTransition() {}
508
509 protected:
510 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
511 gfx::Transform start_ = delegate->GetTransformForAnimation();
512 gfx::Rect bounds = delegate->GetBoundsForAnimation();
513 float device_scale_factor = delegate->GetDeviceScaleFactor();
514 cc_start_ = Layer::ConvertTransformToCCTransform(start_,
515 bounds,
516 device_scale_factor);
517 cc_target_ = Layer::ConvertTransformToCCTransform(target_,
518 bounds,
519 device_scale_factor);
520 }
521
522 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
523 if (delegate && animation_id()) {
524 ThreadedLayerAnimationElement::OnAbort(delegate);
525 delegate->SetTransformFromAnimation(Tween::ValueBetween(
526 Tween::CalculateValue(tween_type(), last_progressed_fraction()),
527 start_,
528 target_));
529 }
530 }
531
532 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE {
533 delegate->SetTransformFromAnimation(target_);
534 }
535
536 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE {
537 scoped_ptr<cc::AnimationCurve> animation_curve(
538 new TransformAnimationCurveAdapter(tween_type(),
539 cc_start_,
540 cc_target_,
541 duration()));
542 scoped_ptr<cc::Animation> animation(
543 cc::Animation::Create(animation_curve.Pass(),
544 animation_id(),
545 animation_group_id(),
546 cc::Animation::Transform));
547 return animation.Pass();
548 }
549
550 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
551 target->transform = target_;
552 }
553
554 private:
555 static AnimatableProperties GetProperties() {
556 AnimatableProperties properties;
557 properties.insert(LayerAnimationElement::TRANSFORM);
558 return properties;
559 }
560
561 gfx::Transform start_;
562 gfx::Transform cc_start_;
563 const gfx::Transform target_;
564 gfx::Transform cc_target_;
565
566 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition);
567 };
568
496 } // namespace 569 } // namespace
497 570
498 // LayerAnimationElement::TargetValue ------------------------------------------ 571 // LayerAnimationElement::TargetValue ------------------------------------------
499 572
500 LayerAnimationElement::TargetValue::TargetValue() 573 LayerAnimationElement::TargetValue::TargetValue()
501 : opacity(0.0f), 574 : opacity(0.0f),
502 visibility(false), 575 visibility(false),
503 brightness(0.0f), 576 brightness(0.0f),
504 grayscale(0.0f), 577 grayscale(0.0f),
505 color(SK_ColorBLACK) { 578 color(SK_ColorBLACK) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 default: 720 default:
648 NOTREACHED(); 721 NOTREACHED();
649 return base::TimeDelta(); 722 return base::TimeDelta();
650 } 723 }
651 } 724 }
652 725
653 // static 726 // static
654 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( 727 LayerAnimationElement* LayerAnimationElement::CreateTransformElement(
655 const gfx::Transform& transform, 728 const gfx::Transform& transform,
656 base::TimeDelta duration) { 729 base::TimeDelta duration) {
657 return new TransformTransition(transform, duration); 730 return new ThreadedTransformTransition(transform, duration);
658 } 731 }
659 732
660 // static 733 // static
661 LayerAnimationElement* 734 LayerAnimationElement*
662 LayerAnimationElement::CreateInterpolatedTransformElement( 735 LayerAnimationElement::CreateInterpolatedTransformElement(
663 InterpolatedTransform* interpolated_transform, 736 InterpolatedTransform* interpolated_transform,
664 base::TimeDelta duration) { 737 base::TimeDelta duration) {
665 return new InterpolatedTransformTransition(interpolated_transform, duration); 738 return new InterpolatedTransformTransition(interpolated_transform, duration);
666 } 739 }
667 740
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 } 781 }
709 782
710 // static 783 // static
711 LayerAnimationElement* LayerAnimationElement::CreateColorElement( 784 LayerAnimationElement* LayerAnimationElement::CreateColorElement(
712 SkColor color, 785 SkColor color,
713 base::TimeDelta duration) { 786 base::TimeDelta duration) {
714 return new ColorTransition(color, duration); 787 return new ColorTransition(color, duration);
715 } 788 }
716 789
717 } // namespace ui 790 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_animation_element.h ('k') | ui/compositor/layer_animation_element_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698