OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/test/animation_test_common.h" | 5 #include "cc/test/animation_test_common.h" |
6 | 6 |
7 #include "cc/animation/animation_id_provider.h" | 7 #include "cc/animation/animation_id_provider.h" |
8 #include "cc/animation/keyframed_animation_curve.h" | 8 #include "cc/animation/keyframed_animation_curve.h" |
9 #include "cc/animation/layer_animation_controller.h" | 9 #include "cc/animation/layer_animation_controller.h" |
10 #include "cc/animation/transform_operations.h" | 10 #include "cc/animation/transform_operations.h" |
| 11 #include "cc/base/time_util.h" |
11 #include "cc/layers/layer.h" | 12 #include "cc/layers/layer.h" |
12 #include "cc/layers/layer_impl.h" | 13 #include "cc/layers/layer_impl.h" |
13 | 14 |
14 using cc::Animation; | 15 using cc::Animation; |
15 using cc::AnimationCurve; | 16 using cc::AnimationCurve; |
16 using cc::EaseTimingFunction; | 17 using cc::EaseTimingFunction; |
17 using cc::FloatKeyframe; | 18 using cc::FloatKeyframe; |
18 using cc::KeyframedFloatAnimationCurve; | 19 using cc::KeyframedFloatAnimationCurve; |
19 using cc::KeyframedTransformAnimationCurve; | 20 using cc::KeyframedTransformAnimationCurve; |
20 using cc::TimingFunction; | 21 using cc::TimingFunction; |
21 using cc::TransformKeyframe; | 22 using cc::TransformKeyframe; |
22 | 23 |
23 namespace cc { | 24 namespace cc { |
24 | 25 |
25 template <class Target> | 26 template <class Target> |
26 int AddOpacityTransition(Target* target, | 27 int AddOpacityTransition(Target* target, |
27 double duration, | 28 double duration, |
28 float start_opacity, | 29 float start_opacity, |
29 float end_opacity, | 30 float end_opacity, |
30 bool use_timing_function) { | 31 bool use_timing_function) { |
31 scoped_ptr<KeyframedFloatAnimationCurve> | 32 scoped_ptr<KeyframedFloatAnimationCurve> |
32 curve(KeyframedFloatAnimationCurve::Create()); | 33 curve(KeyframedFloatAnimationCurve::Create()); |
33 | 34 |
34 scoped_ptr<TimingFunction> func; | 35 scoped_ptr<TimingFunction> func; |
35 if (!use_timing_function) | 36 if (!use_timing_function) |
36 func = EaseTimingFunction::Create(); | 37 func = EaseTimingFunction::Create(); |
37 if (duration > 0.0) | 38 if (duration > 0.0) |
38 curve->AddKeyframe(FloatKeyframe::Create(0.0, start_opacity, func.Pass())); | 39 curve->AddKeyframe( |
39 curve->AddKeyframe(FloatKeyframe::Create(duration, end_opacity, nullptr)); | 40 FloatKeyframe::Create(base::TimeDelta(), start_opacity, func.Pass())); |
| 41 curve->AddKeyframe(FloatKeyframe::Create( |
| 42 base::TimeDelta::FromSecondsD(duration), end_opacity, nullptr)); |
40 | 43 |
41 int id = AnimationIdProvider::NextAnimationId(); | 44 int id = AnimationIdProvider::NextAnimationId(); |
42 | 45 |
43 scoped_ptr<Animation> animation( | 46 scoped_ptr<Animation> animation( |
44 Animation::Create(curve.Pass(), | 47 Animation::Create(curve.Pass(), |
45 id, | 48 id, |
46 AnimationIdProvider::NextGroupId(), | 49 AnimationIdProvider::NextGroupId(), |
47 Animation::Opacity)); | 50 Animation::Opacity)); |
48 animation->set_needs_synchronized_start_time(true); | 51 animation->set_needs_synchronized_start_time(true); |
49 | 52 |
50 target->AddAnimation(animation.Pass()); | 53 target->AddAnimation(animation.Pass()); |
51 return id; | 54 return id; |
52 } | 55 } |
53 | 56 |
54 template <class Target> | 57 template <class Target> |
55 int AddAnimatedTransform(Target* target, | 58 int AddAnimatedTransform(Target* target, |
56 double duration, | 59 double duration, |
57 TransformOperations start_operations, | 60 TransformOperations start_operations, |
58 TransformOperations operations) { | 61 TransformOperations operations) { |
59 scoped_ptr<KeyframedTransformAnimationCurve> | 62 scoped_ptr<KeyframedTransformAnimationCurve> |
60 curve(KeyframedTransformAnimationCurve::Create()); | 63 curve(KeyframedTransformAnimationCurve::Create()); |
61 | 64 |
62 if (duration > 0.0) { | 65 if (duration > 0.0) { |
63 curve->AddKeyframe( | 66 curve->AddKeyframe(TransformKeyframe::Create(base::TimeDelta(), |
64 TransformKeyframe::Create(0.0, start_operations, nullptr)); | 67 start_operations, nullptr)); |
65 } | 68 } |
66 | 69 |
67 curve->AddKeyframe(TransformKeyframe::Create(duration, operations, nullptr)); | 70 curve->AddKeyframe(TransformKeyframe::Create( |
| 71 base::TimeDelta::FromSecondsD(duration), operations, nullptr)); |
68 | 72 |
69 int id = AnimationIdProvider::NextAnimationId(); | 73 int id = AnimationIdProvider::NextAnimationId(); |
70 | 74 |
71 scoped_ptr<Animation> animation( | 75 scoped_ptr<Animation> animation( |
72 Animation::Create(curve.Pass(), | 76 Animation::Create(curve.Pass(), |
73 id, | 77 id, |
74 AnimationIdProvider::NextGroupId(), | 78 AnimationIdProvider::NextGroupId(), |
75 Animation::Transform)); | 79 Animation::Transform)); |
76 animation->set_needs_synchronized_start_time(true); | 80 animation->set_needs_synchronized_start_time(true); |
77 | 81 |
(...skipping 21 matching lines...) Expand all Loading... |
99 double duration, | 103 double duration, |
100 float start_brightness, | 104 float start_brightness, |
101 float end_brightness) { | 105 float end_brightness) { |
102 scoped_ptr<KeyframedFilterAnimationCurve> | 106 scoped_ptr<KeyframedFilterAnimationCurve> |
103 curve(KeyframedFilterAnimationCurve::Create()); | 107 curve(KeyframedFilterAnimationCurve::Create()); |
104 | 108 |
105 if (duration > 0.0) { | 109 if (duration > 0.0) { |
106 FilterOperations start_filters; | 110 FilterOperations start_filters; |
107 start_filters.Append( | 111 start_filters.Append( |
108 FilterOperation::CreateBrightnessFilter(start_brightness)); | 112 FilterOperation::CreateBrightnessFilter(start_brightness)); |
109 curve->AddKeyframe(FilterKeyframe::Create(0.0, start_filters, nullptr)); | 113 curve->AddKeyframe( |
| 114 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
110 } | 115 } |
111 | 116 |
112 FilterOperations filters; | 117 FilterOperations filters; |
113 filters.Append(FilterOperation::CreateBrightnessFilter(end_brightness)); | 118 filters.Append(FilterOperation::CreateBrightnessFilter(end_brightness)); |
114 curve->AddKeyframe(FilterKeyframe::Create(duration, filters, nullptr)); | 119 curve->AddKeyframe(FilterKeyframe::Create( |
| 120 base::TimeDelta::FromSecondsD(duration), filters, nullptr)); |
115 | 121 |
116 int id = AnimationIdProvider::NextAnimationId(); | 122 int id = AnimationIdProvider::NextAnimationId(); |
117 | 123 |
118 scoped_ptr<Animation> animation(Animation::Create( | 124 scoped_ptr<Animation> animation(Animation::Create( |
119 curve.Pass(), id, AnimationIdProvider::NextGroupId(), Animation::Filter)); | 125 curve.Pass(), id, AnimationIdProvider::NextGroupId(), Animation::Filter)); |
120 animation->set_needs_synchronized_start_time(true); | 126 animation->set_needs_synchronized_start_time(true); |
121 | 127 |
122 target->AddAnimation(animation.Pass()); | 128 target->AddAnimation(animation.Pass()); |
123 return id; | 129 return id; |
124 } | 130 } |
125 | 131 |
126 FakeFloatAnimationCurve::FakeFloatAnimationCurve() | 132 FakeFloatAnimationCurve::FakeFloatAnimationCurve() |
127 : duration_(base::TimeDelta::FromSecondsD(1.0)) { | 133 : duration_(base::TimeDelta::FromSecondsD(1.0)) { |
128 } | 134 } |
129 | 135 |
130 FakeFloatAnimationCurve::FakeFloatAnimationCurve(double duration) | 136 FakeFloatAnimationCurve::FakeFloatAnimationCurve(double duration) |
131 : duration_(base::TimeDelta::FromSecondsD(duration)) { | 137 : duration_(base::TimeDelta::FromSecondsD(duration)) { |
132 } | 138 } |
133 | 139 |
134 FakeFloatAnimationCurve::~FakeFloatAnimationCurve() {} | 140 FakeFloatAnimationCurve::~FakeFloatAnimationCurve() {} |
135 | 141 |
136 base::TimeDelta FakeFloatAnimationCurve::Duration() const { | 142 base::TimeDelta FakeFloatAnimationCurve::Duration() const { |
137 return duration_; | 143 return duration_; |
138 } | 144 } |
139 | 145 |
140 float FakeFloatAnimationCurve::GetValue(double now) const { | 146 float FakeFloatAnimationCurve::GetValue(base::TimeDelta now) const { |
141 return 0.0f; | 147 return 0.0f; |
142 } | 148 } |
143 | 149 |
144 scoped_ptr<AnimationCurve> FakeFloatAnimationCurve::Clone() const { | 150 scoped_ptr<AnimationCurve> FakeFloatAnimationCurve::Clone() const { |
145 return make_scoped_ptr(new FakeFloatAnimationCurve); | 151 return make_scoped_ptr(new FakeFloatAnimationCurve); |
146 } | 152 } |
147 | 153 |
148 FakeTransformTransition::FakeTransformTransition(double duration) | 154 FakeTransformTransition::FakeTransformTransition(double duration) |
149 : duration_(base::TimeDelta::FromSecondsD(duration)) { | 155 : duration_(base::TimeDelta::FromSecondsD(duration)) { |
150 } | 156 } |
151 | 157 |
152 FakeTransformTransition::~FakeTransformTransition() {} | 158 FakeTransformTransition::~FakeTransformTransition() {} |
153 | 159 |
154 base::TimeDelta FakeTransformTransition::Duration() const { | 160 base::TimeDelta FakeTransformTransition::Duration() const { |
155 return duration_; | 161 return duration_; |
156 } | 162 } |
157 | 163 |
158 gfx::Transform FakeTransformTransition::GetValue(double time) const { | 164 gfx::Transform FakeTransformTransition::GetValue(base::TimeDelta time) const { |
159 return gfx::Transform(); | 165 return gfx::Transform(); |
160 } | 166 } |
161 | 167 |
162 bool FakeTransformTransition::AnimatedBoundsForBox(const gfx::BoxF& box, | 168 bool FakeTransformTransition::AnimatedBoundsForBox(const gfx::BoxF& box, |
163 gfx::BoxF* bounds) const { | 169 gfx::BoxF* bounds) const { |
164 return false; | 170 return false; |
165 } | 171 } |
166 | 172 |
167 bool FakeTransformTransition::AffectsScale() const { return false; } | 173 bool FakeTransformTransition::AffectsScale() const { return false; } |
168 | 174 |
(...skipping 12 matching lines...) Expand all Loading... |
181 FakeFloatTransition::FakeFloatTransition(double duration, float from, float to) | 187 FakeFloatTransition::FakeFloatTransition(double duration, float from, float to) |
182 : duration_(base::TimeDelta::FromSecondsD(duration)), from_(from), to_(to) { | 188 : duration_(base::TimeDelta::FromSecondsD(duration)), from_(from), to_(to) { |
183 } | 189 } |
184 | 190 |
185 FakeFloatTransition::~FakeFloatTransition() {} | 191 FakeFloatTransition::~FakeFloatTransition() {} |
186 | 192 |
187 base::TimeDelta FakeFloatTransition::Duration() const { | 193 base::TimeDelta FakeFloatTransition::Duration() const { |
188 return duration_; | 194 return duration_; |
189 } | 195 } |
190 | 196 |
191 float FakeFloatTransition::GetValue(double time) const { | 197 float FakeFloatTransition::GetValue(base::TimeDelta time) const { |
192 time /= duration_.InSecondsF(); | 198 double progress = TimeUtil::Divide(time, duration_); |
193 if (time >= 1.0) | 199 if (progress >= 1.0) |
194 time = 1.0; | 200 progress = 1.0; |
195 return (1.0 - time) * from_ + time * to_; | 201 return (1.0 - progress) * from_ + progress * to_; |
196 } | 202 } |
197 | 203 |
198 FakeLayerAnimationValueObserver::FakeLayerAnimationValueObserver() | 204 FakeLayerAnimationValueObserver::FakeLayerAnimationValueObserver() |
199 : opacity_(0.0f), | 205 : opacity_(0.0f), |
200 animation_waiting_for_deletion_(false) {} | 206 animation_waiting_for_deletion_(false) {} |
201 | 207 |
202 FakeLayerAnimationValueObserver::~FakeLayerAnimationValueObserver() {} | 208 FakeLayerAnimationValueObserver::~FakeLayerAnimationValueObserver() {} |
203 | 209 |
204 void FakeLayerAnimationValueObserver::OnFilterAnimated( | 210 void FakeLayerAnimationValueObserver::OnFilterAnimated( |
205 const FilterOperations& filters) { | 211 const FilterOperations& filters) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 double duration, | 346 double duration, |
341 float start_brightness, | 347 float start_brightness, |
342 float end_brightness) { | 348 float end_brightness) { |
343 return AddAnimatedFilter(layer->layer_animation_controller(), | 349 return AddAnimatedFilter(layer->layer_animation_controller(), |
344 duration, | 350 duration, |
345 start_brightness, | 351 start_brightness, |
346 end_brightness); | 352 end_brightness); |
347 } | 353 } |
348 | 354 |
349 } // namespace cc | 355 } // namespace cc |
OLD | NEW |