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

Side by Side Diff: cc/animation/keyframed_animation_curve.cc

Issue 719453007: Make Keyframe use TimeTicks/TimeDelta to represent time instead of double. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "cc/animation/keyframed_animation_curve.h" 7 #include "cc/animation/keyframed_animation_curve.h"
8 #include "cc/base/time_util.h"
8 #include "ui/gfx/animation/tween.h" 9 #include "ui/gfx/animation/tween.h"
9 #include "ui/gfx/geometry/box_f.h" 10 #include "ui/gfx/geometry/box_f.h"
10 11
11 namespace cc { 12 namespace cc {
12 13
13 namespace { 14 namespace {
14 15
15 template <class KeyframeType> 16 template <class KeyframeType>
16 void InsertKeyframe(scoped_ptr<KeyframeType> keyframe, 17 void InsertKeyframe(scoped_ptr<KeyframeType> keyframe,
17 ScopedPtrVector<KeyframeType>* keyframes) { 18 ScopedPtrVector<KeyframeType>* keyframes) {
18 // Usually, the keyframes will be added in order, so this loop would be 19 // Usually, the keyframes will be added in order, so this loop would be
19 // unnecessary and we should skip it if possible. 20 // unnecessary and we should skip it if possible.
20 if (!keyframes->empty() && keyframe->Time() < keyframes->back()->Time()) { 21 if (!keyframes->empty() && keyframe->Time() < keyframes->back()->Time()) {
21 for (size_t i = 0; i < keyframes->size(); ++i) { 22 for (size_t i = 0; i < keyframes->size(); ++i) {
22 if (keyframe->Time() < keyframes->at(i)->Time()) { 23 if (keyframe->Time() < keyframes->at(i)->Time()) {
23 keyframes->insert(keyframes->begin() + i, keyframe.Pass()); 24 keyframes->insert(keyframes->begin() + i, keyframe.Pass());
24 return; 25 return;
25 } 26 }
26 } 27 }
27 } 28 }
28 29
29 keyframes->push_back(keyframe.Pass()); 30 keyframes->push_back(keyframe.Pass());
30 } 31 }
31 32
32 template <typename KeyframeType> 33 template <typename KeyframeType>
33 double TransformedAnimationTime( 34 base::TimeDelta TransformedAnimationTime(
34 const ScopedPtrVector<KeyframeType>& keyframes, 35 const ScopedPtrVector<KeyframeType>& keyframes,
35 const scoped_ptr<TimingFunction>& timing_function, 36 const scoped_ptr<TimingFunction>& timing_function,
36 double time) { 37 base::TimeDelta time) {
37 if (timing_function) { 38 if (timing_function) {
38 double start_time = keyframes.front()->Time(); 39 base::TimeDelta start_time = keyframes.front()->Time();
39 double duration = keyframes.back()->Time() - start_time; 40 base::TimeDelta duration =
40 double progress = (time - start_time) / duration; 41 keyframes.back()->Time() - keyframes.front()->Time();
42 double progress = TimeUtil::Divide(time - start_time, duration);
41 43
42 time = timing_function->GetValue(progress) * duration + start_time; 44 time = TimeUtil::Scale(duration, timing_function->GetValue(progress)) +
45 start_time;
43 } 46 }
44 47
45 return time; 48 return time;
46 } 49 }
47 50
48 template <typename KeyframeType> 51 template <typename KeyframeType>
49 size_t GetActiveKeyframe(const ScopedPtrVector<KeyframeType>& keyframes, 52 size_t GetActiveKeyframe(const ScopedPtrVector<KeyframeType>& keyframes,
50 double time) { 53 base::TimeDelta time) {
51 DCHECK_GE(keyframes.size(), 2ul); 54 DCHECK_GE(keyframes.size(), 2ul);
52 size_t i = 0; 55 size_t i = 0;
53 for (; i < keyframes.size() - 2; ++i) { // Last keyframe is never active. 56 for (; i < keyframes.size() - 2; ++i) { // Last keyframe is never active.
54 if (time < keyframes[i + 1]->Time()) 57 if (time < keyframes[i + 1]->Time())
55 break; 58 break;
56 } 59 }
57 60
58 return i; 61 return i;
59 } 62 }
60 63
61 template <typename KeyframeType> 64 template <typename KeyframeType>
62 double TransformedKeyframeProgress( 65 double TransformedKeyframeProgress(
63 const ScopedPtrVector<KeyframeType>& keyframes, 66 const ScopedPtrVector<KeyframeType>& keyframes,
64 double time, 67 base::TimeDelta time,
65 size_t i) { 68 size_t i) {
66 double progress = (time - keyframes[i]->Time()) / 69 double progress =
67 (keyframes[i + 1]->Time() - keyframes[i]->Time()); 70 TimeUtil::Divide(time - keyframes[i]->Time(),
71 keyframes[i + 1]->Time() - keyframes[i]->Time());
68 72
69 if (keyframes[i]->timing_function()) { 73 if (keyframes[i]->timing_function()) {
70 progress = keyframes[i]->timing_function()->GetValue(progress); 74 progress = keyframes[i]->timing_function()->GetValue(progress);
71 } 75 }
72 76
73 return progress; 77 return progress;
74 } 78 }
75 79
76 } // namespace 80 } // namespace
77 81
78 Keyframe::Keyframe(double time, scoped_ptr<TimingFunction> timing_function) 82 Keyframe::Keyframe(base::TimeDelta time,
79 : time_(time), 83 scoped_ptr<TimingFunction> timing_function)
80 timing_function_(timing_function.Pass()) {} 84 : time_(time), timing_function_(timing_function.Pass()) {
85 }
81 86
82 Keyframe::~Keyframe() {} 87 Keyframe::~Keyframe() {}
83 88
84 double Keyframe::Time() const { 89 base::TimeDelta Keyframe::Time() const {
85 return time_; 90 return time_;
86 } 91 }
87 92
88 scoped_ptr<ColorKeyframe> ColorKeyframe::Create( 93 scoped_ptr<ColorKeyframe> ColorKeyframe::Create(
89 double time, 94 base::TimeDelta time,
90 SkColor value, 95 SkColor value,
91 scoped_ptr<TimingFunction> timing_function) { 96 scoped_ptr<TimingFunction> timing_function) {
92 return make_scoped_ptr( 97 return make_scoped_ptr(
93 new ColorKeyframe(time, value, timing_function.Pass())); 98 new ColorKeyframe(time, value, timing_function.Pass()));
94 } 99 }
95 100
96 ColorKeyframe::ColorKeyframe(double time, 101 ColorKeyframe::ColorKeyframe(base::TimeDelta time,
97 SkColor value, 102 SkColor value,
98 scoped_ptr<TimingFunction> timing_function) 103 scoped_ptr<TimingFunction> timing_function)
99 : Keyframe(time, timing_function.Pass()), 104 : Keyframe(time, timing_function.Pass()), value_(value) {
100 value_(value) {} 105 }
101 106
102 ColorKeyframe::~ColorKeyframe() {} 107 ColorKeyframe::~ColorKeyframe() {}
103 108
104 SkColor ColorKeyframe::Value() const { return value_; } 109 SkColor ColorKeyframe::Value() const { return value_; }
105 110
106 scoped_ptr<ColorKeyframe> ColorKeyframe::Clone() const { 111 scoped_ptr<ColorKeyframe> ColorKeyframe::Clone() const {
107 scoped_ptr<TimingFunction> func; 112 scoped_ptr<TimingFunction> func;
108 if (timing_function()) 113 if (timing_function())
109 func = timing_function()->Clone(); 114 func = timing_function()->Clone();
110 return ColorKeyframe::Create(Time(), Value(), func.Pass()); 115 return ColorKeyframe::Create(Time(), Value(), func.Pass());
111 } 116 }
112 117
113 scoped_ptr<FloatKeyframe> FloatKeyframe::Create( 118 scoped_ptr<FloatKeyframe> FloatKeyframe::Create(
114 double time, 119 base::TimeDelta time,
115 float value, 120 float value,
116 scoped_ptr<TimingFunction> timing_function) { 121 scoped_ptr<TimingFunction> timing_function) {
117 return make_scoped_ptr( 122 return make_scoped_ptr(
118 new FloatKeyframe(time, value, timing_function.Pass())); 123 new FloatKeyframe(time, value, timing_function.Pass()));
119 } 124 }
120 125
121 FloatKeyframe::FloatKeyframe(double time, 126 FloatKeyframe::FloatKeyframe(base::TimeDelta time,
122 float value, 127 float value,
123 scoped_ptr<TimingFunction> timing_function) 128 scoped_ptr<TimingFunction> timing_function)
124 : Keyframe(time, timing_function.Pass()), 129 : Keyframe(time, timing_function.Pass()), value_(value) {
125 value_(value) {} 130 }
126 131
127 FloatKeyframe::~FloatKeyframe() {} 132 FloatKeyframe::~FloatKeyframe() {}
128 133
129 float FloatKeyframe::Value() const { 134 float FloatKeyframe::Value() const {
130 return value_; 135 return value_;
131 } 136 }
132 137
133 scoped_ptr<FloatKeyframe> FloatKeyframe::Clone() const { 138 scoped_ptr<FloatKeyframe> FloatKeyframe::Clone() const {
134 scoped_ptr<TimingFunction> func; 139 scoped_ptr<TimingFunction> func;
135 if (timing_function()) 140 if (timing_function())
136 func = timing_function()->Clone(); 141 func = timing_function()->Clone();
137 return FloatKeyframe::Create(Time(), Value(), func.Pass()); 142 return FloatKeyframe::Create(Time(), Value(), func.Pass());
138 } 143 }
139 144
140 scoped_ptr<TransformKeyframe> TransformKeyframe::Create( 145 scoped_ptr<TransformKeyframe> TransformKeyframe::Create(
141 double time, 146 base::TimeDelta time,
142 const TransformOperations& value, 147 const TransformOperations& value,
143 scoped_ptr<TimingFunction> timing_function) { 148 scoped_ptr<TimingFunction> timing_function) {
144 return make_scoped_ptr( 149 return make_scoped_ptr(
145 new TransformKeyframe(time, value, timing_function.Pass())); 150 new TransformKeyframe(time, value, timing_function.Pass()));
146 } 151 }
147 152
148 TransformKeyframe::TransformKeyframe(double time, 153 TransformKeyframe::TransformKeyframe(base::TimeDelta time,
149 const TransformOperations& value, 154 const TransformOperations& value,
150 scoped_ptr<TimingFunction> timing_function) 155 scoped_ptr<TimingFunction> timing_function)
151 : Keyframe(time, timing_function.Pass()), 156 : Keyframe(time, timing_function.Pass()), value_(value) {
152 value_(value) {} 157 }
153 158
154 TransformKeyframe::~TransformKeyframe() {} 159 TransformKeyframe::~TransformKeyframe() {}
155 160
156 const TransformOperations& TransformKeyframe::Value() const { 161 const TransformOperations& TransformKeyframe::Value() const {
157 return value_; 162 return value_;
158 } 163 }
159 164
160 scoped_ptr<TransformKeyframe> TransformKeyframe::Clone() const { 165 scoped_ptr<TransformKeyframe> TransformKeyframe::Clone() const {
161 scoped_ptr<TimingFunction> func; 166 scoped_ptr<TimingFunction> func;
162 if (timing_function()) 167 if (timing_function())
163 func = timing_function()->Clone(); 168 func = timing_function()->Clone();
164 return TransformKeyframe::Create(Time(), Value(), func.Pass()); 169 return TransformKeyframe::Create(Time(), Value(), func.Pass());
165 } 170 }
166 171
167 scoped_ptr<FilterKeyframe> FilterKeyframe::Create( 172 scoped_ptr<FilterKeyframe> FilterKeyframe::Create(
168 double time, 173 base::TimeDelta time,
169 const FilterOperations& value, 174 const FilterOperations& value,
170 scoped_ptr<TimingFunction> timing_function) { 175 scoped_ptr<TimingFunction> timing_function) {
171 return make_scoped_ptr( 176 return make_scoped_ptr(
172 new FilterKeyframe(time, value, timing_function.Pass())); 177 new FilterKeyframe(time, value, timing_function.Pass()));
173 } 178 }
174 179
175 FilterKeyframe::FilterKeyframe(double time, 180 FilterKeyframe::FilterKeyframe(base::TimeDelta time,
176 const FilterOperations& value, 181 const FilterOperations& value,
177 scoped_ptr<TimingFunction> timing_function) 182 scoped_ptr<TimingFunction> timing_function)
178 : Keyframe(time, timing_function.Pass()), 183 : Keyframe(time, timing_function.Pass()), value_(value) {
179 value_(value) {} 184 }
180 185
181 FilterKeyframe::~FilterKeyframe() {} 186 FilterKeyframe::~FilterKeyframe() {}
182 187
183 const FilterOperations& FilterKeyframe::Value() const { 188 const FilterOperations& FilterKeyframe::Value() const {
184 return value_; 189 return value_;
185 } 190 }
186 191
187 scoped_ptr<FilterKeyframe> FilterKeyframe::Clone() const { 192 scoped_ptr<FilterKeyframe> FilterKeyframe::Clone() const {
188 scoped_ptr<TimingFunction> func; 193 scoped_ptr<TimingFunction> func;
189 if (timing_function()) 194 if (timing_function())
190 func = timing_function()->Clone(); 195 func = timing_function()->Clone();
191 return FilterKeyframe::Create(Time(), Value(), func.Pass()); 196 return FilterKeyframe::Create(Time(), Value(), func.Pass());
192 } 197 }
193 198
194 scoped_ptr<KeyframedColorAnimationCurve> KeyframedColorAnimationCurve:: 199 scoped_ptr<KeyframedColorAnimationCurve> KeyframedColorAnimationCurve::
195 Create() { 200 Create() {
196 return make_scoped_ptr(new KeyframedColorAnimationCurve); 201 return make_scoped_ptr(new KeyframedColorAnimationCurve);
197 } 202 }
198 203
199 KeyframedColorAnimationCurve::KeyframedColorAnimationCurve() {} 204 KeyframedColorAnimationCurve::KeyframedColorAnimationCurve() {}
200 205
201 KeyframedColorAnimationCurve::~KeyframedColorAnimationCurve() {} 206 KeyframedColorAnimationCurve::~KeyframedColorAnimationCurve() {}
202 207
203 void KeyframedColorAnimationCurve::AddKeyframe( 208 void KeyframedColorAnimationCurve::AddKeyframe(
204 scoped_ptr<ColorKeyframe> keyframe) { 209 scoped_ptr<ColorKeyframe> keyframe) {
205 InsertKeyframe(keyframe.Pass(), &keyframes_); 210 InsertKeyframe(keyframe.Pass(), &keyframes_);
206 } 211 }
207 212
208 base::TimeDelta KeyframedColorAnimationCurve::Duration() const { 213 base::TimeDelta KeyframedColorAnimationCurve::Duration() const {
209 return base::TimeDelta::FromSecondsD(keyframes_.back()->Time() - 214 return keyframes_.back()->Time() - keyframes_.front()->Time();
210 keyframes_.front()->Time());
211 } 215 }
212 216
213 scoped_ptr<AnimationCurve> KeyframedColorAnimationCurve::Clone() const { 217 scoped_ptr<AnimationCurve> KeyframedColorAnimationCurve::Clone() const {
214 scoped_ptr<KeyframedColorAnimationCurve> to_return = 218 scoped_ptr<KeyframedColorAnimationCurve> to_return =
215 KeyframedColorAnimationCurve::Create(); 219 KeyframedColorAnimationCurve::Create();
216 for (size_t i = 0; i < keyframes_.size(); ++i) 220 for (size_t i = 0; i < keyframes_.size(); ++i)
217 to_return->AddKeyframe(keyframes_[i]->Clone()); 221 to_return->AddKeyframe(keyframes_[i]->Clone());
218 222
219 if (timing_function_) 223 if (timing_function_)
220 to_return->SetTimingFunction(timing_function_->Clone()); 224 to_return->SetTimingFunction(timing_function_->Clone());
221 225
222 return to_return.Pass(); 226 return to_return.Pass();
223 } 227 }
224 228
225 SkColor KeyframedColorAnimationCurve::GetValue(double t) const { 229 SkColor KeyframedColorAnimationCurve::GetValue(base::TimeDelta t) const {
226 if (t <= keyframes_.front()->Time()) 230 if (t <= keyframes_.front()->Time())
227 return keyframes_.front()->Value(); 231 return keyframes_.front()->Value();
228 232
229 if (t >= keyframes_.back()->Time()) 233 if (t >= keyframes_.back()->Time())
230 return keyframes_.back()->Value(); 234 return keyframes_.back()->Value();
231 235
232 t = TransformedAnimationTime(keyframes_, timing_function_, t); 236 t = TransformedAnimationTime(keyframes_, timing_function_, t);
233 size_t i = GetActiveKeyframe(keyframes_, t); 237 size_t i = GetActiveKeyframe(keyframes_, t);
234 double progress = TransformedKeyframeProgress(keyframes_, t, i); 238 double progress = TransformedKeyframeProgress(keyframes_, t, i);
235 239
(...skipping 11 matching lines...) Expand all
247 KeyframedFloatAnimationCurve::KeyframedFloatAnimationCurve() {} 251 KeyframedFloatAnimationCurve::KeyframedFloatAnimationCurve() {}
248 252
249 KeyframedFloatAnimationCurve::~KeyframedFloatAnimationCurve() {} 253 KeyframedFloatAnimationCurve::~KeyframedFloatAnimationCurve() {}
250 254
251 void KeyframedFloatAnimationCurve::AddKeyframe( 255 void KeyframedFloatAnimationCurve::AddKeyframe(
252 scoped_ptr<FloatKeyframe> keyframe) { 256 scoped_ptr<FloatKeyframe> keyframe) {
253 InsertKeyframe(keyframe.Pass(), &keyframes_); 257 InsertKeyframe(keyframe.Pass(), &keyframes_);
254 } 258 }
255 259
256 base::TimeDelta KeyframedFloatAnimationCurve::Duration() const { 260 base::TimeDelta KeyframedFloatAnimationCurve::Duration() const {
257 return base::TimeDelta::FromSecondsD(keyframes_.back()->Time() - 261 return keyframes_.back()->Time() - keyframes_.front()->Time();
258 keyframes_.front()->Time());
259 } 262 }
260 263
261 scoped_ptr<AnimationCurve> KeyframedFloatAnimationCurve::Clone() const { 264 scoped_ptr<AnimationCurve> KeyframedFloatAnimationCurve::Clone() const {
262 scoped_ptr<KeyframedFloatAnimationCurve> to_return = 265 scoped_ptr<KeyframedFloatAnimationCurve> to_return =
263 KeyframedFloatAnimationCurve::Create(); 266 KeyframedFloatAnimationCurve::Create();
264 for (size_t i = 0; i < keyframes_.size(); ++i) 267 for (size_t i = 0; i < keyframes_.size(); ++i)
265 to_return->AddKeyframe(keyframes_[i]->Clone()); 268 to_return->AddKeyframe(keyframes_[i]->Clone());
266 269
267 if (timing_function_) 270 if (timing_function_)
268 to_return->SetTimingFunction(timing_function_->Clone()); 271 to_return->SetTimingFunction(timing_function_->Clone());
269 272
270 return to_return.Pass(); 273 return to_return.Pass();
271 } 274 }
272 275
273 float KeyframedFloatAnimationCurve::GetValue(double t) const { 276 float KeyframedFloatAnimationCurve::GetValue(base::TimeDelta t) const {
274 if (t <= keyframes_.front()->Time()) 277 if (t <= keyframes_.front()->Time())
275 return keyframes_.front()->Value(); 278 return keyframes_.front()->Value();
276 279
277 if (t >= keyframes_.back()->Time()) 280 if (t >= keyframes_.back()->Time())
278 return keyframes_.back()->Value(); 281 return keyframes_.back()->Value();
279 282
280 t = TransformedAnimationTime(keyframes_, timing_function_, t); 283 t = TransformedAnimationTime(keyframes_, timing_function_, t);
281 size_t i = GetActiveKeyframe(keyframes_, t); 284 size_t i = GetActiveKeyframe(keyframes_, t);
282 double progress = TransformedKeyframeProgress(keyframes_, t, i); 285 double progress = TransformedKeyframeProgress(keyframes_, t, i);
283 286
284 return keyframes_[i]->Value() + 287 return keyframes_[i]->Value() +
285 (keyframes_[i+1]->Value() - keyframes_[i]->Value()) * progress; 288 (keyframes_[i+1]->Value() - keyframes_[i]->Value()) * progress;
286 } 289 }
287 290
288 scoped_ptr<KeyframedTransformAnimationCurve> KeyframedTransformAnimationCurve:: 291 scoped_ptr<KeyframedTransformAnimationCurve> KeyframedTransformAnimationCurve::
289 Create() { 292 Create() {
290 return make_scoped_ptr(new KeyframedTransformAnimationCurve); 293 return make_scoped_ptr(new KeyframedTransformAnimationCurve);
291 } 294 }
292 295
293 KeyframedTransformAnimationCurve::KeyframedTransformAnimationCurve() {} 296 KeyframedTransformAnimationCurve::KeyframedTransformAnimationCurve() {}
294 297
295 KeyframedTransformAnimationCurve::~KeyframedTransformAnimationCurve() {} 298 KeyframedTransformAnimationCurve::~KeyframedTransformAnimationCurve() {}
296 299
297 void KeyframedTransformAnimationCurve::AddKeyframe( 300 void KeyframedTransformAnimationCurve::AddKeyframe(
298 scoped_ptr<TransformKeyframe> keyframe) { 301 scoped_ptr<TransformKeyframe> keyframe) {
299 InsertKeyframe(keyframe.Pass(), &keyframes_); 302 InsertKeyframe(keyframe.Pass(), &keyframes_);
300 } 303 }
301 304
302 base::TimeDelta KeyframedTransformAnimationCurve::Duration() const { 305 base::TimeDelta KeyframedTransformAnimationCurve::Duration() const {
303 return base::TimeDelta::FromSecondsD(keyframes_.back()->Time() - 306 return keyframes_.back()->Time() - keyframes_.front()->Time();
304 keyframes_.front()->Time());
305 } 307 }
306 308
307 scoped_ptr<AnimationCurve> KeyframedTransformAnimationCurve::Clone() const { 309 scoped_ptr<AnimationCurve> KeyframedTransformAnimationCurve::Clone() const {
308 scoped_ptr<KeyframedTransformAnimationCurve> to_return = 310 scoped_ptr<KeyframedTransformAnimationCurve> to_return =
309 KeyframedTransformAnimationCurve::Create(); 311 KeyframedTransformAnimationCurve::Create();
310 for (size_t i = 0; i < keyframes_.size(); ++i) 312 for (size_t i = 0; i < keyframes_.size(); ++i)
311 to_return->AddKeyframe(keyframes_[i]->Clone()); 313 to_return->AddKeyframe(keyframes_[i]->Clone());
312 314
313 if (timing_function_) 315 if (timing_function_)
314 to_return->SetTimingFunction(timing_function_->Clone()); 316 to_return->SetTimingFunction(timing_function_->Clone());
315 317
316 return to_return.Pass(); 318 return to_return.Pass();
317 } 319 }
318 320
319 gfx::Transform KeyframedTransformAnimationCurve::GetValue(double t) const { 321 gfx::Transform KeyframedTransformAnimationCurve::GetValue(
322 base::TimeDelta t) const {
320 if (t <= keyframes_.front()->Time()) 323 if (t <= keyframes_.front()->Time())
321 return keyframes_.front()->Value().Apply(); 324 return keyframes_.front()->Value().Apply();
322 325
323 if (t >= keyframes_.back()->Time()) 326 if (t >= keyframes_.back()->Time())
324 return keyframes_.back()->Value().Apply(); 327 return keyframes_.back()->Value().Apply();
325 328
326 t = TransformedAnimationTime(keyframes_, timing_function_, t); 329 t = TransformedAnimationTime(keyframes_, timing_function_, t);
327 size_t i = GetActiveKeyframe(keyframes_, t); 330 size_t i = GetActiveKeyframe(keyframes_, t);
328 double progress = TransformedKeyframeProgress(keyframes_, t, i); 331 double progress = TransformedKeyframeProgress(keyframes_, t, i);
329 332
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 KeyframedFilterAnimationCurve::KeyframedFilterAnimationCurve() {} 408 KeyframedFilterAnimationCurve::KeyframedFilterAnimationCurve() {}
406 409
407 KeyframedFilterAnimationCurve::~KeyframedFilterAnimationCurve() {} 410 KeyframedFilterAnimationCurve::~KeyframedFilterAnimationCurve() {}
408 411
409 void KeyframedFilterAnimationCurve::AddKeyframe( 412 void KeyframedFilterAnimationCurve::AddKeyframe(
410 scoped_ptr<FilterKeyframe> keyframe) { 413 scoped_ptr<FilterKeyframe> keyframe) {
411 InsertKeyframe(keyframe.Pass(), &keyframes_); 414 InsertKeyframe(keyframe.Pass(), &keyframes_);
412 } 415 }
413 416
414 base::TimeDelta KeyframedFilterAnimationCurve::Duration() const { 417 base::TimeDelta KeyframedFilterAnimationCurve::Duration() const {
415 return base::TimeDelta::FromSecondsD(keyframes_.back()->Time() - 418 return keyframes_.back()->Time() - keyframes_.front()->Time();
416 keyframes_.front()->Time());
417 } 419 }
418 420
419 scoped_ptr<AnimationCurve> KeyframedFilterAnimationCurve::Clone() const { 421 scoped_ptr<AnimationCurve> KeyframedFilterAnimationCurve::Clone() const {
420 scoped_ptr<KeyframedFilterAnimationCurve> to_return = 422 scoped_ptr<KeyframedFilterAnimationCurve> to_return =
421 KeyframedFilterAnimationCurve::Create(); 423 KeyframedFilterAnimationCurve::Create();
422 for (size_t i = 0; i < keyframes_.size(); ++i) 424 for (size_t i = 0; i < keyframes_.size(); ++i)
423 to_return->AddKeyframe(keyframes_[i]->Clone()); 425 to_return->AddKeyframe(keyframes_[i]->Clone());
424 426
425 if (timing_function_) 427 if (timing_function_)
426 to_return->SetTimingFunction(timing_function_->Clone()); 428 to_return->SetTimingFunction(timing_function_->Clone());
427 429
428 return to_return.Pass(); 430 return to_return.Pass();
429 } 431 }
430 432
431 FilterOperations KeyframedFilterAnimationCurve::GetValue(double t) const { 433 FilterOperations KeyframedFilterAnimationCurve::GetValue(
434 base::TimeDelta t) const {
432 if (t <= keyframes_.front()->Time()) 435 if (t <= keyframes_.front()->Time())
433 return keyframes_.front()->Value(); 436 return keyframes_.front()->Value();
434 437
435 if (t >= keyframes_.back()->Time()) 438 if (t >= keyframes_.back()->Time())
436 return keyframes_.back()->Value(); 439 return keyframes_.back()->Value();
437 440
438 t = TransformedAnimationTime(keyframes_, timing_function_, t); 441 t = TransformedAnimationTime(keyframes_, timing_function_, t);
439 size_t i = GetActiveKeyframe(keyframes_, t); 442 size_t i = GetActiveKeyframe(keyframes_, t);
440 double progress = TransformedKeyframeProgress(keyframes_, t, i); 443 double progress = TransformedKeyframeProgress(keyframes_, t, i);
441 444
442 return keyframes_[i + 1]->Value().Blend(keyframes_[i]->Value(), progress); 445 return keyframes_[i + 1]->Value().Blend(keyframes_[i]->Value(), progress);
443 } 446 }
444 447
445 bool KeyframedFilterAnimationCurve::HasFilterThatMovesPixels() const { 448 bool KeyframedFilterAnimationCurve::HasFilterThatMovesPixels() const {
446 for (size_t i = 0; i < keyframes_.size(); ++i) { 449 for (size_t i = 0; i < keyframes_.size(); ++i) {
447 if (keyframes_[i]->Value().HasFilterThatMovesPixels()) { 450 if (keyframes_[i]->Value().HasFilterThatMovesPixels()) {
448 return true; 451 return true;
449 } 452 }
450 } 453 }
451 return false; 454 return false;
452 } 455 }
453 456
454 } // namespace cc 457 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/keyframed_animation_curve.h ('k') | cc/animation/keyframed_animation_curve_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698