OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "public/platform/WebTransformAnimationCurve.h" | 51 #include "public/platform/WebTransformAnimationCurve.h" |
52 #include "public/platform/WebTransformKeyframe.h" | 52 #include "public/platform/WebTransformKeyframe.h" |
53 | 53 |
54 #include <algorithm> | 54 #include <algorithm> |
55 #include <cmath> | 55 #include <cmath> |
56 | 56 |
57 namespace WebCore { | 57 namespace WebCore { |
58 | 58 |
59 namespace { | 59 namespace { |
60 | 60 |
61 void getKeyframeValuesForProperty(const KeyframeEffectModel* effect, CSSProperty
ID id, double scale, KeyframeVector& values) | 61 void getKeyframeValuesForProperty(const KeyframeEffectModel* effect, CSSProperty
ID id, double scale, bool reverse, KeyframeVector& values) |
62 { | 62 { |
63 ASSERT(values.isEmpty()); | 63 ASSERT(values.isEmpty()); |
64 const KeyframeVector& group = effect->getPropertySpecificKeyframes(id); | 64 const KeyframeVector& group = effect->getPropertySpecificKeyframes(id); |
65 | 65 |
66 for (size_t i = 0; i < group.size(); ++i) { | 66 if (reverse) { |
67 double offset = group[i]->offset() * scale; | 67 for (size_t i = group.size(); i--;) { |
68 values.append(group[i]->cloneWithOffset(offset)); | 68 double offset = (1 - group[i]->offset()) * scale; |
| 69 values.append(group[i]->cloneWithOffset(offset)); |
| 70 } |
| 71 } else { |
| 72 for (size_t i = 0; i < group.size(); ++i) { |
| 73 double offset = group[i]->offset() * scale; |
| 74 values.append(group[i]->cloneWithOffset(offset)); |
| 75 } |
69 } | 76 } |
70 } | 77 } |
71 | 78 |
72 } | 79 } |
73 | 80 |
74 // ----------------------------------------------------------------------- | 81 // ----------------------------------------------------------------------- |
| 82 // TimingFunctionReverser methods |
| 83 // ----------------------------------------------------------------------- |
| 84 |
| 85 PassRefPtr<TimingFunction> CompositorAnimationsTimingFunctionReverser::reverse(c
onst LinearTimingFunction* timefunc) |
| 86 { |
| 87 return const_cast<LinearTimingFunction*>(timefunc); |
| 88 } |
| 89 |
| 90 PassRefPtr<TimingFunction> CompositorAnimationsTimingFunctionReverser::reverse(c
onst CubicBezierTimingFunction* timefunc) |
| 91 { |
| 92 switch (timefunc->subType()) { |
| 93 case CubicBezierTimingFunction::EaseIn: |
| 94 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease
Out); |
| 95 case CubicBezierTimingFunction::EaseOut: |
| 96 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease
In); |
| 97 case CubicBezierTimingFunction::EaseInOut: |
| 98 return const_cast<CubicBezierTimingFunction*>(timefunc); |
| 99 case CubicBezierTimingFunction::Ease: // Ease is not symmetrical |
| 100 case CubicBezierTimingFunction::Custom: |
| 101 return CubicBezierTimingFunction::create(1 - timefunc->x2(), 1 - timefun
c->y2(), 1 - timefunc->x1(), 1 - timefunc->y1()); |
| 102 default: |
| 103 ASSERT_NOT_REACHED(); |
| 104 return PassRefPtr<TimingFunction>(); |
| 105 } |
| 106 } |
| 107 |
| 108 PassRefPtr<TimingFunction> CompositorAnimationsTimingFunctionReverser::reverse(c
onst TimingFunction* timefunc) |
| 109 { |
| 110 switch (timefunc->type()) { |
| 111 case TimingFunction::LinearFunction: { |
| 112 const LinearTimingFunction* linear = toLinearTimingFunction(timefunc); |
| 113 return reverse(linear); |
| 114 } |
| 115 case TimingFunction::CubicBezierFunction: { |
| 116 const CubicBezierTimingFunction* cubic = toCubicBezierTimingFunction(tim
efunc); |
| 117 return reverse(cubic); |
| 118 } |
| 119 |
| 120 // Steps function can not be reversed. |
| 121 case TimingFunction::StepsFunction: |
| 122 default: |
| 123 ASSERT_NOT_REACHED(); |
| 124 return PassRefPtr<TimingFunction>(); |
| 125 } |
| 126 } |
| 127 |
| 128 // ----------------------------------------------------------------------- |
75 // CompositorAnimations public API | 129 // CompositorAnimations public API |
76 // ----------------------------------------------------------------------- | 130 // ----------------------------------------------------------------------- |
77 | 131 |
78 bool CompositorAnimations::isCandidateForAnimationOnCompositor(const Timing& tim
ing, const AnimationEffect& effect) | 132 bool CompositorAnimations::isCandidateForAnimationOnCompositor(const Timing& tim
ing, const AnimationEffect& effect) |
79 { | 133 { |
80 const KeyframeEffectModel& keyframeEffect = *toKeyframeEffectModel(&effect); | 134 const KeyframeEffectModel& keyframeEffect = *toKeyframeEffectModel(&effect); |
81 | 135 |
82 // Are the keyframes convertible? | 136 // Are the keyframes convertible? |
83 const KeyframeEffectModel::KeyframeVector frames = keyframeEffect.getFrames(
); | 137 const KeyframeEffectModel::KeyframeVector frames = keyframeEffect.getFrames(
); |
84 for (size_t i = 0; i < frames.size(); ++i) { | 138 for (size_t i = 0; i < frames.size(); ++i) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // All directions are supported. | 309 // All directions are supported. |
256 | 310 |
257 // Now attempt an actual conversion | 311 // Now attempt an actual conversion |
258 out.scaledDuration = timing.iterationDuration; | 312 out.scaledDuration = timing.iterationDuration; |
259 ASSERT(out.scaledDuration > 0); | 313 ASSERT(out.scaledDuration > 0); |
260 | 314 |
261 double scaledStartDelay = timing.startDelay; | 315 double scaledStartDelay = timing.startDelay; |
262 if (scaledStartDelay > 0 && scaledStartDelay > out.scaledDuration * timing.i
terationCount) | 316 if (scaledStartDelay > 0 && scaledStartDelay > out.scaledDuration * timing.i
terationCount) |
263 return false; | 317 return false; |
264 | 318 |
265 out.direction = timing.direction; | 319 out.reverse = (timing.direction == Timing::PlaybackDirectionReverse |
| 320 || timing.direction == Timing::PlaybackDirectionAlternateReverse); |
| 321 out.alternate = (timing.direction == Timing::PlaybackDirectionAlternate |
| 322 || timing.direction == Timing::PlaybackDirectionAlternateReverse); |
266 | 323 |
267 if (!std::isfinite(timing.iterationCount)) { | 324 if (!std::isfinite(timing.iterationCount)) { |
268 out.adjustedIterationCount = -1; | 325 out.adjustedIterationCount = -1; |
269 } else { | 326 } else { |
270 out.adjustedIterationCount = std::floor(timing.iterationCount); | 327 out.adjustedIterationCount = std::floor(timing.iterationCount); |
271 ASSERT(out.adjustedIterationCount > 0); | 328 ASSERT(out.adjustedIterationCount > 0); |
272 } | 329 } |
273 | 330 |
274 // Compositor's time offset is positive for seeking into the animation. | 331 // Compositor's time offset is positive for seeking into the animation. |
275 out.scaledTimeOffset = -scaledStartDelay; | 332 out.scaledTimeOffset = -scaledStartDelay; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 384 |
328 case TimingFunction::StepsFunction: | 385 case TimingFunction::StepsFunction: |
329 default: | 386 default: |
330 ASSERT_NOT_REACHED(); | 387 ASSERT_NOT_REACHED(); |
331 return; | 388 return; |
332 } | 389 } |
333 } | 390 } |
334 | 391 |
335 } // namespace anoymous | 392 } // namespace anoymous |
336 | 393 |
337 void CompositorAnimationsImpl::addKeyframesToCurve(blink::WebAnimationCurve& cur
ve, const KeyframeVector& keyframes) | 394 void CompositorAnimationsImpl::addKeyframesToCurve(blink::WebAnimationCurve& cur
ve, const KeyframeVector& keyframes, bool reverse) |
338 { | 395 { |
339 for (size_t i = 0; i < keyframes.size(); i++) { | 396 for (size_t i = 0; i < keyframes.size(); i++) { |
| 397 RefPtr<TimingFunction> reversedTimingFunction; |
340 const TimingFunction* keyframeTimingFunction = 0; | 398 const TimingFunction* keyframeTimingFunction = 0; |
341 if (i < keyframes.size() - 1) { // Ignore timing function of last frame. | 399 if (i < keyframes.size() - 1) { // Ignore timing function of last frame. |
342 keyframeTimingFunction = keyframes[i]->easing(); | 400 if (reverse) { |
| 401 reversedTimingFunction = CompositorAnimationsTimingFunctionRever
ser::reverse(keyframes[i + 1]->easing()); |
| 402 keyframeTimingFunction = reversedTimingFunction.get(); |
| 403 } else { |
| 404 keyframeTimingFunction = keyframes[i]->easing(); |
| 405 } |
343 } | 406 } |
344 | 407 |
345 const AnimatableValue* value = keyframes[i]->value(); | 408 const AnimatableValue* value = keyframes[i]->value(); |
346 | 409 |
347 switch (curve.type()) { | 410 switch (curve.type()) { |
348 case blink::WebAnimationCurve::AnimationCurveTypeFilter: { | 411 case blink::WebAnimationCurve::AnimationCurveTypeFilter: { |
349 OwnPtr<blink::WebFilterOperations> ops = adoptPtr(blink::Platform::c
urrent()->compositorSupport()->createFilterOperations()); | 412 OwnPtr<blink::WebFilterOperations> ops = adoptPtr(blink::Platform::c
urrent()->compositorSupport()->createFilterOperations()); |
350 bool converted = toWebFilterOperations(toAnimatableFilterOperations(
value)->operations(), ops.get()); | 413 bool converted = toWebFilterOperations(toAnimatableFilterOperations(
value)->operations(), ops.get()); |
351 ASSERT_UNUSED(converted, converted); | 414 ASSERT_UNUSED(converted, converted); |
352 | 415 |
(...skipping 24 matching lines...) Expand all Loading... |
377 } | 440 } |
378 | 441 |
379 void CompositorAnimationsImpl::getAnimationOnCompositor(const Timing& timing, co
nst KeyframeEffectModel& effect, Vector<OwnPtr<blink::WebAnimation> >& animation
s) | 442 void CompositorAnimationsImpl::getAnimationOnCompositor(const Timing& timing, co
nst KeyframeEffectModel& effect, Vector<OwnPtr<blink::WebAnimation> >& animation
s) |
380 { | 443 { |
381 ASSERT(animations.isEmpty()); | 444 ASSERT(animations.isEmpty()); |
382 CompositorTiming compositorTiming; | 445 CompositorTiming compositorTiming; |
383 bool timingValid = convertTimingForCompositor(timing, compositorTiming); | 446 bool timingValid = convertTimingForCompositor(timing, compositorTiming); |
384 ASSERT_UNUSED(timingValid, timingValid); | 447 ASSERT_UNUSED(timingValid, timingValid); |
385 | 448 |
386 RefPtr<TimingFunction> timingFunction = timing.timingFunction; | 449 RefPtr<TimingFunction> timingFunction = timing.timingFunction; |
| 450 if (compositorTiming.reverse) |
| 451 timingFunction = CompositorAnimationsTimingFunctionReverser::reverse(tim
ingFunction.get()); |
387 | 452 |
388 PropertySet properties = effect.properties(); | 453 PropertySet properties = effect.properties(); |
389 ASSERT(!properties.isEmpty()); | 454 ASSERT(!properties.isEmpty()); |
390 for (PropertySet::iterator it = properties.begin(); it != properties.end();
++it) { | 455 for (PropertySet::iterator it = properties.begin(); it != properties.end();
++it) { |
391 | 456 |
392 KeyframeVector values; | 457 KeyframeVector values; |
393 getKeyframeValuesForProperty(&effect, *it, compositorTiming.scaledDurati
on, values); | 458 getKeyframeValuesForProperty(&effect, *it, compositorTiming.scaledDurati
on, compositorTiming.reverse, values); |
394 | 459 |
395 blink::WebAnimation::TargetProperty targetProperty; | 460 blink::WebAnimation::TargetProperty targetProperty; |
396 OwnPtr<blink::WebAnimationCurve> curve; | 461 OwnPtr<blink::WebAnimationCurve> curve; |
397 switch (*it) { | 462 switch (*it) { |
398 case CSSPropertyOpacity: { | 463 case CSSPropertyOpacity: { |
399 targetProperty = blink::WebAnimation::TargetPropertyOpacity; | 464 targetProperty = blink::WebAnimation::TargetPropertyOpacity; |
400 | 465 |
401 blink::WebFloatAnimationCurve* floatCurve = blink::Platform::current
()->compositorSupport()->createFloatAnimationCurve(); | 466 blink::WebFloatAnimationCurve* floatCurve = blink::Platform::current
()->compositorSupport()->createFloatAnimationCurve(); |
402 addKeyframesToCurve(*floatCurve, values); | 467 addKeyframesToCurve(*floatCurve, values, compositorTiming.reverse); |
403 curve = adoptPtr(floatCurve); | 468 curve = adoptPtr(floatCurve); |
404 break; | 469 break; |
405 } | 470 } |
406 case CSSPropertyWebkitFilter: { | 471 case CSSPropertyWebkitFilter: { |
407 targetProperty = blink::WebAnimation::TargetPropertyFilter; | 472 targetProperty = blink::WebAnimation::TargetPropertyFilter; |
408 blink::WebFilterAnimationCurve* filterCurve = blink::Platform::curre
nt()->compositorSupport()->createFilterAnimationCurve(); | 473 blink::WebFilterAnimationCurve* filterCurve = blink::Platform::curre
nt()->compositorSupport()->createFilterAnimationCurve(); |
409 addKeyframesToCurve(*filterCurve, values); | 474 addKeyframesToCurve(*filterCurve, values, compositorTiming.reverse); |
410 curve = adoptPtr(filterCurve); | 475 curve = adoptPtr(filterCurve); |
411 break; | 476 break; |
412 } | 477 } |
413 case CSSPropertyWebkitTransform: { | 478 case CSSPropertyWebkitTransform: { |
414 targetProperty = blink::WebAnimation::TargetPropertyTransform; | 479 targetProperty = blink::WebAnimation::TargetPropertyTransform; |
415 blink::WebTransformAnimationCurve* transformCurve = blink::Platform:
:current()->compositorSupport()->createTransformAnimationCurve(); | 480 blink::WebTransformAnimationCurve* transformCurve = blink::Platform:
:current()->compositorSupport()->createTransformAnimationCurve(); |
416 addKeyframesToCurve(*transformCurve, values); | 481 addKeyframesToCurve(*transformCurve, values, compositorTiming.revers
e); |
417 curve = adoptPtr(transformCurve); | 482 curve = adoptPtr(transformCurve); |
418 break; | 483 break; |
419 } | 484 } |
420 default: | 485 default: |
421 ASSERT_NOT_REACHED(); | 486 ASSERT_NOT_REACHED(); |
422 continue; | 487 continue; |
423 } | 488 } |
424 ASSERT(curve.get()); | 489 ASSERT(curve.get()); |
425 | 490 |
426 OwnPtr<blink::WebAnimation> animation = adoptPtr(blink::Platform::curren
t()->compositorSupport()->createAnimation(*curve, targetProperty)); | 491 OwnPtr<blink::WebAnimation> animation = adoptPtr(blink::Platform::curren
t()->compositorSupport()->createAnimation(*curve, targetProperty)); |
427 | 492 |
428 animation->setIterations(compositorTiming.adjustedIterationCount); | 493 animation->setIterations(compositorTiming.adjustedIterationCount); |
429 animation->setTimeOffset(compositorTiming.scaledTimeOffset); | 494 animation->setTimeOffset(compositorTiming.scaledTimeOffset); |
430 | 495 animation->setAlternatesDirection(compositorTiming.alternate); |
431 switch (compositorTiming.direction) { | |
432 case Timing::PlaybackDirectionNormal: | |
433 animation->setDirection(blink::WebAnimation::DirectionNormal); | |
434 break; | |
435 case Timing::PlaybackDirectionReverse: | |
436 animation->setDirection(blink::WebAnimation::DirectionReverse); | |
437 break; | |
438 case Timing::PlaybackDirectionAlternate: | |
439 animation->setDirection(blink::WebAnimation::DirectionAlternate); | |
440 break; | |
441 case Timing::PlaybackDirectionAlternateReverse: | |
442 animation->setDirection(blink::WebAnimation::DirectionAlternateRever
se); | |
443 break; | |
444 default: | |
445 ASSERT_NOT_REACHED(); | |
446 } | |
447 | 496 |
448 animations.append(animation.release()); | 497 animations.append(animation.release()); |
449 } | 498 } |
450 ASSERT(!animations.isEmpty()); | 499 ASSERT(!animations.isEmpty()); |
451 } | 500 } |
452 | 501 |
453 } // namespace WebCore | 502 } // namespace WebCore |
OLD | NEW |