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

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

Issue 2971503002: Transform animations should not collapse by default when interpolating (Closed)
Patch Set: . Created 3 years, 5 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/transform_animation_curve_adapter.h" 5 #include "ui/compositor/transform_animation_curve_adapter.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "cc/base/time_util.h" 8 #include "cc/base/time_util.h"
9 9
10 namespace ui { 10 namespace ui {
11 11
12 namespace {
13
14 static cc::TransformOperations WrapTransform(const gfx::Transform& transform) {
15 cc::TransformOperations operations;
16 operations.AppendMatrix(transform);
17 return operations;
18 }
19
20 } // namespace
21
12 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter( 22 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter(
13 gfx::Tween::Type tween_type, 23 gfx::Tween::Type tween_type,
14 gfx::Transform initial_value, 24 gfx::Transform initial_value,
15 gfx::Transform target_value, 25 gfx::Transform target_value,
16 base::TimeDelta duration) 26 base::TimeDelta duration)
17 : tween_type_(tween_type), 27 : tween_type_(tween_type),
18 initial_value_(initial_value), 28 initial_value_(initial_value),
29 initial_wrapped_value_(WrapTransform(initial_value)),
19 target_value_(target_value), 30 target_value_(target_value),
31 target_wrapped_value_(WrapTransform(target_value)),
20 duration_(duration) { 32 duration_(duration) {
21 gfx::DecomposeTransform(&decomposed_initial_value_, initial_value_); 33 gfx::DecomposeTransform(&decomposed_initial_value_, initial_value);
22 gfx::DecomposeTransform(&decomposed_target_value_, target_value_); 34 gfx::DecomposeTransform(&decomposed_target_value_, target_value);
23 } 35 }
24 36
25 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter( 37 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter(
26 const TransformAnimationCurveAdapter& other) = default; 38 const TransformAnimationCurveAdapter& other) = default;
27 39
28 TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() { 40 TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() {
29 } 41 }
30 42
31 base::TimeDelta TransformAnimationCurveAdapter::Duration() const { 43 base::TimeDelta TransformAnimationCurveAdapter::Duration() const {
32 return duration_; 44 return duration_;
33 } 45 }
34 46
35 std::unique_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::Clone() 47 std::unique_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::Clone()
36 const { 48 const {
37 return base::WrapUnique(new TransformAnimationCurveAdapter( 49 return base::WrapUnique(new TransformAnimationCurveAdapter(
38 tween_type_, initial_value_, target_value_, duration_)); 50 tween_type_, initial_value_, target_value_, duration_));
39 } 51 }
40 52
41 gfx::Transform TransformAnimationCurveAdapter::GetValue( 53 cc::TransformOperations TransformAnimationCurveAdapter::GetValue(
42 base::TimeDelta t) const { 54 base::TimeDelta t) const {
43 if (t >= duration_) 55 if (t >= duration_)
44 return target_value_; 56 return target_wrapped_value_;
45 if (t <= base::TimeDelta()) 57 if (t <= base::TimeDelta())
46 return initial_value_; 58 return initial_wrapped_value_;
47 double progress = cc::TimeUtil::Divide(t, duration_); 59 double progress = cc::TimeUtil::Divide(t, duration_);
48 60
49 gfx::DecomposedTransform to_return = gfx::BlendDecomposedTransforms( 61 gfx::DecomposedTransform to_return = gfx::BlendDecomposedTransforms(
50 decomposed_target_value_, decomposed_initial_value_, 62 decomposed_target_value_, decomposed_initial_value_,
51 gfx::Tween::CalculateValue(tween_type_, progress)); 63 gfx::Tween::CalculateValue(tween_type_, progress));
52 return gfx::ComposeTransform(to_return); 64
65 return WrapTransform(gfx::ComposeTransform(to_return));
53 } 66 }
54 67
55 bool TransformAnimationCurveAdapter::AnimatedBoundsForBox( 68 bool TransformAnimationCurveAdapter::AnimatedBoundsForBox(
56 const gfx::BoxF& box, 69 const gfx::BoxF& box,
57 gfx::BoxF* bounds) const { 70 gfx::BoxF* bounds) const {
58 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports 71 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
59 // computing bounds for TransformOperationMatrix, use that to compute 72 // computing bounds for TransformOperationMatrix, use that to compute
60 // the bounds we need here. 73 // the bounds we need here.
61 return false; 74 return false;
62 } 75 }
(...skipping 20 matching lines...) Expand all
83 float* max_scale) const { 96 float* max_scale) const {
84 return false; 97 return false;
85 } 98 }
86 99
87 InverseTransformCurveAdapter::InverseTransformCurveAdapter( 100 InverseTransformCurveAdapter::InverseTransformCurveAdapter(
88 TransformAnimationCurveAdapter base_curve, 101 TransformAnimationCurveAdapter base_curve,
89 gfx::Transform initial_value, 102 gfx::Transform initial_value,
90 base::TimeDelta duration) 103 base::TimeDelta duration)
91 : base_curve_(base_curve), 104 : base_curve_(base_curve),
92 initial_value_(initial_value), 105 initial_value_(initial_value),
106 initial_wrapped_value_(WrapTransform(initial_value)),
93 duration_(duration) { 107 duration_(duration) {
94 effective_initial_value_ = 108 effective_initial_value_ =
95 base_curve_.GetValue(base::TimeDelta()) * initial_value_; 109 base_curve_.GetValue(base::TimeDelta()).Apply() * initial_value_;
96 } 110 }
97 111
98 InverseTransformCurveAdapter::~InverseTransformCurveAdapter() { 112 InverseTransformCurveAdapter::~InverseTransformCurveAdapter() {
99 } 113 }
100 114
101 base::TimeDelta InverseTransformCurveAdapter::Duration() const { 115 base::TimeDelta InverseTransformCurveAdapter::Duration() const {
102 return duration_; 116 return duration_;
103 } 117 }
104 118
105 std::unique_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone() 119 std::unique_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone()
106 const { 120 const {
107 return base::WrapUnique( 121 return base::WrapUnique(
108 new InverseTransformCurveAdapter(base_curve_, initial_value_, duration_)); 122 new InverseTransformCurveAdapter(base_curve_, initial_value_, duration_));
109 } 123 }
110 124
111 gfx::Transform InverseTransformCurveAdapter::GetValue(base::TimeDelta t) const { 125 cc::TransformOperations InverseTransformCurveAdapter::GetValue(
126 base::TimeDelta t) const {
112 if (t <= base::TimeDelta()) 127 if (t <= base::TimeDelta())
113 return initial_value_; 128 return initial_wrapped_value_;
114 129
115 gfx::Transform base_transform = base_curve_.GetValue(t); 130 gfx::Transform base_transform = base_curve_.GetValue(t).Apply();
116 // Invert base 131 // Invert base
117 gfx::Transform to_return(gfx::Transform::kSkipInitialization); 132 gfx::Transform to_return(gfx::Transform::kSkipInitialization);
118 bool is_invertible = base_transform.GetInverse(&to_return); 133 bool is_invertible = base_transform.GetInverse(&to_return);
119 DCHECK(is_invertible); 134 DCHECK(is_invertible);
120 135
121 to_return.PreconcatTransform(effective_initial_value_); 136 to_return.PreconcatTransform(effective_initial_value_);
122 return to_return; 137
138 return WrapTransform(to_return);
123 } 139 }
124 140
125 bool InverseTransformCurveAdapter::AnimatedBoundsForBox( 141 bool InverseTransformCurveAdapter::AnimatedBoundsForBox(
126 const gfx::BoxF& box, 142 const gfx::BoxF& box,
127 gfx::BoxF* bounds) const { 143 gfx::BoxF* bounds) const {
128 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports 144 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
129 // computing bounds for TransformOperationMatrix, use that to compute 145 // computing bounds for TransformOperationMatrix, use that to compute
130 // the bounds we need here. 146 // the bounds we need here.
131 return false; 147 return false;
132 } 148 }
(...skipping 14 matching lines...) Expand all
147 float* start_scale) const { 163 float* start_scale) const {
148 return false; 164 return false;
149 } 165 }
150 166
151 bool InverseTransformCurveAdapter::MaximumTargetScale(bool forward_direction, 167 bool InverseTransformCurveAdapter::MaximumTargetScale(bool forward_direction,
152 float* max_scale) const { 168 float* max_scale) const {
153 return false; 169 return false;
154 } 170 }
155 171
156 } // namespace ui 172 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/transform_animation_curve_adapter.h ('k') | ui/compositor/transform_animation_curve_adapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698