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/transform_animation_curve_adapter.h"
9 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter(
10 gfx::Tween::Type tween_type,
11 gfx::Transform initial_value,
12 gfx::Transform target_value,
13 base::TimeDelta duration)
14 : tween_type_(tween_type),
15 initial_value_(initial_value),
16 target_value_(target_value),
18 gfx::DecomposeTransform(&decomposed_initial_value_, initial_value_);
19 gfx::DecomposeTransform(&decomposed_target_value_, target_value_);
22 TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() {
25 double TransformAnimationCurveAdapter::Duration() const {
26 return duration_.InSecondsF();
29 scoped_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::Clone() const {
30 scoped_ptr<TransformAnimationCurveAdapter> to_return(
31 new TransformAnimationCurveAdapter(tween_type_,
35 return to_return.PassAs<cc::AnimationCurve>();
38 gfx::Transform TransformAnimationCurveAdapter::GetValue(
40 if (t >= duration_.InSecondsF())
43 return initial_value_;
44 double progress = t / duration_.InSecondsF();
46 gfx::DecomposedTransform to_return;
47 gfx::BlendDecomposedTransforms(&to_return,
48 decomposed_target_value_,
49 decomposed_initial_value_,
50 gfx::Tween::CalculateValue(tween_type_,
52 return gfx::ComposeTransform(to_return);
55 bool TransformAnimationCurveAdapter::AnimatedBoundsForBox(
57 gfx::BoxF* bounds) const {
58 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
59 // computing bounds for TransformOperationMatrix, use that to compute
60 // the bounds we need here.
64 bool TransformAnimationCurveAdapter::AffectsScale() const {
65 return !initial_value_.IsIdentityOrTranslation() ||
66 !target_value_.IsIdentityOrTranslation();
69 bool TransformAnimationCurveAdapter::IsTranslation() const {
70 return initial_value_.IsIdentityOrTranslation() &&
71 target_value_.IsIdentityOrTranslation();
74 bool TransformAnimationCurveAdapter::MaximumTargetScale(
75 bool forward_direction,
76 float* max_scale) const {
80 InverseTransformCurveAdapter::InverseTransformCurveAdapter(
81 TransformAnimationCurveAdapter base_curve,
82 gfx::Transform initial_value,
83 base::TimeDelta duration)
84 : base_curve_(base_curve),
85 initial_value_(initial_value),
87 effective_initial_value_ = base_curve_.GetValue(0.0) * initial_value_;
90 InverseTransformCurveAdapter::~InverseTransformCurveAdapter() {
93 double InverseTransformCurveAdapter::Duration() const {
94 return duration_.InSeconds();
97 scoped_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone() const {
98 scoped_ptr<InverseTransformCurveAdapter> to_return(
99 new InverseTransformCurveAdapter(base_curve_,
102 return to_return.PassAs<cc::AnimationCurve>();
105 gfx::Transform InverseTransformCurveAdapter::GetValue(
108 return initial_value_;
110 gfx::Transform base_transform = base_curve_.GetValue(t);
112 gfx::Transform to_return(gfx::Transform::kSkipInitialization);
113 bool is_invertible = base_transform.GetInverse(&to_return);
114 DCHECK(is_invertible);
116 to_return.PreconcatTransform(effective_initial_value_);
120 bool InverseTransformCurveAdapter::AnimatedBoundsForBox(
121 const gfx::BoxF& box,
122 gfx::BoxF* bounds) const {
123 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
124 // computing bounds for TransformOperationMatrix, use that to compute
125 // the bounds we need here.
129 bool InverseTransformCurveAdapter::AffectsScale() const {
130 return !initial_value_.IsIdentityOrTranslation() ||
131 base_curve_.AffectsScale();
134 bool InverseTransformCurveAdapter::IsTranslation() const {
135 return initial_value_.IsIdentityOrTranslation() &&
136 base_curve_.IsTranslation();
139 bool InverseTransformCurveAdapter::MaximumTargetScale(bool forward_direction,
140 float* max_scale) const {