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

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

Issue 2966793002: NOT FOR REVIEW - convert to cc animation
Patch Set: switch to transform operations 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 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/animation/keyframed_animation_curve.h" 5 #include "cc/animation/keyframed_animation_curve.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return value_; 197 return value_;
198 } 198 }
199 199
200 std::unique_ptr<FilterKeyframe> FilterKeyframe::Clone() const { 200 std::unique_ptr<FilterKeyframe> FilterKeyframe::Clone() const {
201 std::unique_ptr<TimingFunction> func; 201 std::unique_ptr<TimingFunction> func;
202 if (timing_function()) 202 if (timing_function())
203 func = timing_function()->Clone(); 203 func = timing_function()->Clone();
204 return FilterKeyframe::Create(Time(), Value(), std::move(func)); 204 return FilterKeyframe::Create(Time(), Value(), std::move(func));
205 } 205 }
206 206
207 std::unique_ptr<SizeKeyframe> SizeKeyframe::Create(
208 base::TimeDelta time,
209 const gfx::SizeF& value,
210 std::unique_ptr<TimingFunction> timing_function) {
211 return base::WrapUnique(
212 new SizeKeyframe(time, value, std::move(timing_function)));
213 }
214
215 SizeKeyframe::SizeKeyframe(base::TimeDelta time,
216 const gfx::SizeF& value,
217 std::unique_ptr<TimingFunction> timing_function)
218 : Keyframe(time, std::move(timing_function)), value_(value) {}
219
220 SizeKeyframe::~SizeKeyframe() {}
221
222 const gfx::SizeF& SizeKeyframe::Value() const {
223 return value_;
224 }
225
226 std::unique_ptr<SizeKeyframe> SizeKeyframe::Clone() const {
227 std::unique_ptr<TimingFunction> func;
228 if (timing_function())
229 func = timing_function()->Clone();
230 return SizeKeyframe::Create(Time(), Value(), std::move(func));
231 }
232
207 std::unique_ptr<KeyframedColorAnimationCurve> 233 std::unique_ptr<KeyframedColorAnimationCurve>
208 KeyframedColorAnimationCurve::Create() { 234 KeyframedColorAnimationCurve::Create() {
209 return base::WrapUnique(new KeyframedColorAnimationCurve); 235 return base::WrapUnique(new KeyframedColorAnimationCurve);
210 } 236 }
211 237
212 KeyframedColorAnimationCurve::KeyframedColorAnimationCurve() 238 KeyframedColorAnimationCurve::KeyframedColorAnimationCurve()
213 : scaled_duration_(1.0) {} 239 : scaled_duration_(1.0) {}
214 240
215 KeyframedColorAnimationCurve::~KeyframedColorAnimationCurve() {} 241 KeyframedColorAnimationCurve::~KeyframedColorAnimationCurve() {}
216 242
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 t = TransformedAnimationTime(keyframes_, timing_function_, scaled_duration(), 274 t = TransformedAnimationTime(keyframes_, timing_function_, scaled_duration(),
249 t); 275 t);
250 size_t i = GetActiveKeyframe(keyframes_, scaled_duration(), t); 276 size_t i = GetActiveKeyframe(keyframes_, scaled_duration(), t);
251 double progress = 277 double progress =
252 TransformedKeyframeProgress(keyframes_, scaled_duration(), t, i); 278 TransformedKeyframeProgress(keyframes_, scaled_duration(), t, i);
253 279
254 return gfx::Tween::ColorValueBetween( 280 return gfx::Tween::ColorValueBetween(
255 progress, keyframes_[i]->Value(), keyframes_[i + 1]->Value()); 281 progress, keyframes_[i]->Value(), keyframes_[i + 1]->Value());
256 } 282 }
257 283
258 // KeyframedFloatAnimationCurve
259
260 std::unique_ptr<KeyframedFloatAnimationCurve> 284 std::unique_ptr<KeyframedFloatAnimationCurve>
261 KeyframedFloatAnimationCurve::Create() { 285 KeyframedFloatAnimationCurve::Create() {
262 return base::WrapUnique(new KeyframedFloatAnimationCurve); 286 return base::WrapUnique(new KeyframedFloatAnimationCurve);
263 } 287 }
264 288
265 KeyframedFloatAnimationCurve::KeyframedFloatAnimationCurve() 289 KeyframedFloatAnimationCurve::KeyframedFloatAnimationCurve()
266 : scaled_duration_(1.0) {} 290 : scaled_duration_(1.0) {}
267 291
268 KeyframedFloatAnimationCurve::~KeyframedFloatAnimationCurve() {} 292 KeyframedFloatAnimationCurve::~KeyframedFloatAnimationCurve() {}
269 293
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 to_return->AddKeyframe(keyframes_[i]->Clone()); 360 to_return->AddKeyframe(keyframes_[i]->Clone());
337 361
338 if (timing_function_) 362 if (timing_function_)
339 to_return->SetTimingFunction(timing_function_->Clone()); 363 to_return->SetTimingFunction(timing_function_->Clone());
340 364
341 to_return->set_scaled_duration(scaled_duration()); 365 to_return->set_scaled_duration(scaled_duration());
342 366
343 return std::move(to_return); 367 return std::move(to_return);
344 } 368 }
345 369
346 gfx::Transform KeyframedTransformAnimationCurve::GetValue( 370 TransformOperations KeyframedTransformAnimationCurve::GetValue(
347 base::TimeDelta t) const { 371 base::TimeDelta t) const {
348 if (t <= TimeUtil::Scale(keyframes_.front()->Time(), scaled_duration())) 372 if (t <= TimeUtil::Scale(keyframes_.front()->Time(), scaled_duration()))
349 return keyframes_.front()->Value().Apply(); 373 return keyframes_.front()->Value();
350 374
351 if (t >= TimeUtil::Scale(keyframes_.back()->Time(), scaled_duration())) 375 if (t >= TimeUtil::Scale(keyframes_.back()->Time(), scaled_duration()))
352 return keyframes_.back()->Value().Apply(); 376 return keyframes_.back()->Value();
353 377
354 t = TransformedAnimationTime(keyframes_, timing_function_, scaled_duration(), 378 t = TransformedAnimationTime(keyframes_, timing_function_, scaled_duration(),
355 t); 379 t);
356 size_t i = GetActiveKeyframe(keyframes_, scaled_duration(), t); 380 size_t i = GetActiveKeyframe(keyframes_, scaled_duration(), t);
357 double progress = 381 double progress =
358 TransformedKeyframeProgress(keyframes_, scaled_duration(), t, i); 382 TransformedKeyframeProgress(keyframes_, scaled_duration(), t, i);
359 383
360 return keyframes_[i + 1]->Value().Blend(keyframes_[i]->Value(), progress); 384 return keyframes_[i + 1]->Value().Blend(keyframes_[i]->Value(), progress);
361 } 385 }
362 386
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 512
489 bool KeyframedFilterAnimationCurve::HasFilterThatMovesPixels() const { 513 bool KeyframedFilterAnimationCurve::HasFilterThatMovesPixels() const {
490 for (size_t i = 0; i < keyframes_.size(); ++i) { 514 for (size_t i = 0; i < keyframes_.size(); ++i) {
491 if (keyframes_[i]->Value().HasFilterThatMovesPixels()) { 515 if (keyframes_[i]->Value().HasFilterThatMovesPixels()) {
492 return true; 516 return true;
493 } 517 }
494 } 518 }
495 return false; 519 return false;
496 } 520 }
497 521
522 std::unique_ptr<KeyframedSizeAnimationCurve>
523 KeyframedSizeAnimationCurve::Create() {
524 return base::WrapUnique(new KeyframedSizeAnimationCurve);
525 }
526
527 KeyframedSizeAnimationCurve::KeyframedSizeAnimationCurve()
528 : scaled_duration_(1.0) {}
529
530 KeyframedSizeAnimationCurve::~KeyframedSizeAnimationCurve() {}
531
532 void KeyframedSizeAnimationCurve::AddKeyframe(
533 std::unique_ptr<SizeKeyframe> keyframe) {
534 InsertKeyframe(std::move(keyframe), &keyframes_);
535 }
536
537 base::TimeDelta KeyframedSizeAnimationCurve::Duration() const {
538 return TimeUtil::Scale(keyframes_.back()->Time() - keyframes_.front()->Time(),
539 scaled_duration());
540 }
541
542 std::unique_ptr<AnimationCurve> KeyframedSizeAnimationCurve::Clone() const {
543 std::unique_ptr<KeyframedSizeAnimationCurve> to_return =
544 KeyframedSizeAnimationCurve::Create();
545 for (size_t i = 0; i < keyframes_.size(); ++i)
546 to_return->AddKeyframe(keyframes_[i]->Clone());
547
548 if (timing_function_)
549 to_return->SetTimingFunction(timing_function_->Clone());
550
551 to_return->set_scaled_duration(scaled_duration());
552
553 return std::move(to_return);
554 }
555
556 gfx::SizeF KeyframedSizeAnimationCurve::GetValue(base::TimeDelta t) const {
557 if (t <= TimeUtil::Scale(keyframes_.front()->Time(), scaled_duration()))
558 return keyframes_.front()->Value();
559
560 if (t >= TimeUtil::Scale(keyframes_.back()->Time(), scaled_duration()))
561 return keyframes_.back()->Value();
562
563 t = TransformedAnimationTime(keyframes_, timing_function_, scaled_duration(),
564 t);
565 size_t i = GetActiveKeyframe(keyframes_, scaled_duration(), t);
566 double progress =
567 TransformedKeyframeProgress(keyframes_, scaled_duration(), t, i);
568
569 return gfx::Tween::SizeValueBetween(progress, keyframes_[i]->Value(),
570 keyframes_[i + 1]->Value());
571 }
572
498 } // namespace cc 573 } // 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