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"
7 #include "cc/base/time_util.h"
11 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter(
12 gfx::Tween::Type tween_type
,
13 gfx::Transform initial_value
,
14 gfx::Transform target_value
,
15 base::TimeDelta duration
)
16 : tween_type_(tween_type
),
17 initial_value_(initial_value
),
18 target_value_(target_value
),
20 gfx::DecomposeTransform(&decomposed_initial_value_
, initial_value_
);
21 gfx::DecomposeTransform(&decomposed_target_value_
, target_value_
);
24 TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() {
27 base::TimeDelta
TransformAnimationCurveAdapter::Duration() const {
31 scoped_ptr
<cc::AnimationCurve
> TransformAnimationCurveAdapter::Clone() const {
32 return make_scoped_ptr(new TransformAnimationCurveAdapter(
33 tween_type_
, initial_value_
, target_value_
, duration_
));
36 gfx::Transform
TransformAnimationCurveAdapter::GetValue(
37 base::TimeDelta t
) const {
40 if (t
<= base::TimeDelta())
41 return initial_value_
;
42 double progress
= cc::TimeUtil::Divide(t
, duration_
);
44 gfx::DecomposedTransform to_return
;
45 gfx::BlendDecomposedTransforms(&to_return
,
46 decomposed_target_value_
,
47 decomposed_initial_value_
,
48 gfx::Tween::CalculateValue(tween_type_
,
50 return gfx::ComposeTransform(to_return
);
53 bool TransformAnimationCurveAdapter::AnimatedBoundsForBox(
55 gfx::BoxF
* bounds
) const {
56 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
57 // computing bounds for TransformOperationMatrix, use that to compute
58 // the bounds we need here.
62 bool TransformAnimationCurveAdapter::AffectsScale() const {
63 return !initial_value_
.IsIdentityOrTranslation() ||
64 !target_value_
.IsIdentityOrTranslation();
67 bool TransformAnimationCurveAdapter::IsTranslation() const {
68 return initial_value_
.IsIdentityOrTranslation() &&
69 target_value_
.IsIdentityOrTranslation();
72 bool TransformAnimationCurveAdapter::MaximumTargetScale(
73 bool forward_direction
,
74 float* max_scale
) const {
78 InverseTransformCurveAdapter::InverseTransformCurveAdapter(
79 TransformAnimationCurveAdapter base_curve
,
80 gfx::Transform initial_value
,
81 base::TimeDelta duration
)
82 : base_curve_(base_curve
),
83 initial_value_(initial_value
),
85 effective_initial_value_
=
86 base_curve_
.GetValue(base::TimeDelta()) * initial_value_
;
89 InverseTransformCurveAdapter::~InverseTransformCurveAdapter() {
92 base::TimeDelta
InverseTransformCurveAdapter::Duration() const {
96 scoped_ptr
<cc::AnimationCurve
> InverseTransformCurveAdapter::Clone() const {
97 return make_scoped_ptr(
98 new InverseTransformCurveAdapter(base_curve_
, initial_value_
, duration_
));
101 gfx::Transform
InverseTransformCurveAdapter::GetValue(base::TimeDelta t
) const {
102 if (t
<= base::TimeDelta())
103 return initial_value_
;
105 gfx::Transform base_transform
= base_curve_
.GetValue(t
);
107 gfx::Transform
to_return(gfx::Transform::kSkipInitialization
);
108 bool is_invertible
= base_transform
.GetInverse(&to_return
);
109 DCHECK(is_invertible
);
111 to_return
.PreconcatTransform(effective_initial_value_
);
115 bool InverseTransformCurveAdapter::AnimatedBoundsForBox(
116 const gfx::BoxF
& box
,
117 gfx::BoxF
* bounds
) const {
118 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
119 // computing bounds for TransformOperationMatrix, use that to compute
120 // the bounds we need here.
124 bool InverseTransformCurveAdapter::AffectsScale() const {
125 return !initial_value_
.IsIdentityOrTranslation() ||
126 base_curve_
.AffectsScale();
129 bool InverseTransformCurveAdapter::IsTranslation() const {
130 return initial_value_
.IsIdentityOrTranslation() &&
131 base_curve_
.IsTranslation();
134 bool InverseTransformCurveAdapter::MaximumTargetScale(bool forward_direction
,
135 float* max_scale
) const {