| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "platform/animation/CompositorFilterAnimationCurve.h" | 47 #include "platform/animation/CompositorFilterAnimationCurve.h" |
| 48 #include "platform/animation/CompositorFilterKeyframe.h" | 48 #include "platform/animation/CompositorFilterKeyframe.h" |
| 49 #include "platform/animation/CompositorFloatAnimationCurve.h" | 49 #include "platform/animation/CompositorFloatAnimationCurve.h" |
| 50 #include "platform/animation/CompositorFloatKeyframe.h" | 50 #include "platform/animation/CompositorFloatKeyframe.h" |
| 51 #include "platform/animation/CompositorTransformAnimationCurve.h" | 51 #include "platform/animation/CompositorTransformAnimationCurve.h" |
| 52 #include "platform/animation/CompositorTransformKeyframe.h" | 52 #include "platform/animation/CompositorTransformKeyframe.h" |
| 53 #include "platform/geometry/FloatBox.h" | 53 #include "platform/geometry/FloatBox.h" |
| 54 #include "platform/graphics/CompositorFactory.h" | 54 #include "platform/graphics/CompositorFactory.h" |
| 55 #include "public/platform/Platform.h" | 55 #include "public/platform/Platform.h" |
| 56 #include "public/platform/WebCompositorSupport.h" | 56 #include "public/platform/WebCompositorSupport.h" |
| 57 | 57 #include "wtf/PtrUtil.h" |
| 58 #include <algorithm> | 58 #include <algorithm> |
| 59 #include <cmath> | 59 #include <cmath> |
| 60 #include <memory> |
| 60 | 61 |
| 61 namespace blink { | 62 namespace blink { |
| 62 | 63 |
| 63 namespace { | 64 namespace { |
| 64 | 65 |
| 65 void getKeyframeValuesForProperty(const KeyframeEffectModelBase* effect, Propert
yHandle property, double scale, PropertySpecificKeyframeVector& values) | 66 void getKeyframeValuesForProperty(const KeyframeEffectModelBase* effect, Propert
yHandle property, double scale, PropertySpecificKeyframeVector& values) |
| 66 { | 67 { |
| 67 ASSERT(values.isEmpty()); | 68 ASSERT(values.isEmpty()); |
| 68 | 69 |
| 69 for (const auto& keyframe : effect->getPropertySpecificKeyframes(property))
{ | 70 for (const auto& keyframe : effect->getPropertySpecificKeyframes(property))
{ |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 327 } |
| 327 | 328 |
| 328 void CompositorAnimations::startAnimationOnCompositor(const Element& element, in
t group, double startTime, double timeOffset, const Timing& timing, const Animat
ion& animation, const EffectModel& effect, Vector<int>& startedAnimationIds, dou
ble animationPlaybackRate) | 329 void CompositorAnimations::startAnimationOnCompositor(const Element& element, in
t group, double startTime, double timeOffset, const Timing& timing, const Animat
ion& animation, const EffectModel& effect, Vector<int>& startedAnimationIds, dou
ble animationPlaybackRate) |
| 329 { | 330 { |
| 330 ASSERT(startedAnimationIds.isEmpty()); | 331 ASSERT(startedAnimationIds.isEmpty()); |
| 331 ASSERT(isCandidateForAnimationOnCompositor(timing, element, &animation, effe
ct, animationPlaybackRate)); | 332 ASSERT(isCandidateForAnimationOnCompositor(timing, element, &animation, effe
ct, animationPlaybackRate)); |
| 332 ASSERT(canStartAnimationOnCompositor(element)); | 333 ASSERT(canStartAnimationOnCompositor(element)); |
| 333 | 334 |
| 334 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef
fect); | 335 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef
fect); |
| 335 | 336 |
| 336 Vector<OwnPtr<CompositorAnimation>> animations; | 337 Vector<std::unique_ptr<CompositorAnimation>> animations; |
| 337 getAnimationOnCompositor(timing, group, startTime, timeOffset, keyframeEffec
t, animations, animationPlaybackRate); | 338 getAnimationOnCompositor(timing, group, startTime, timeOffset, keyframeEffec
t, animations, animationPlaybackRate); |
| 338 ASSERT(!animations.isEmpty()); | 339 ASSERT(!animations.isEmpty()); |
| 339 for (auto& compositorAnimation : animations) { | 340 for (auto& compositorAnimation : animations) { |
| 340 int id = compositorAnimation->id(); | 341 int id = compositorAnimation->id(); |
| 341 CompositorAnimationPlayer* compositorPlayer = animation.compositorPlayer
(); | 342 CompositorAnimationPlayer* compositorPlayer = animation.compositorPlayer
(); |
| 342 ASSERT(compositorPlayer); | 343 ASSERT(compositorPlayer); |
| 343 compositorPlayer->addAnimation(compositorAnimation.leakPtr()); | 344 compositorPlayer->addAnimation(compositorAnimation.release()); |
| 344 startedAnimationIds.append(id); | 345 startedAnimationIds.append(id); |
| 345 } | 346 } |
| 346 ASSERT(!startedAnimationIds.isEmpty()); | 347 ASSERT(!startedAnimationIds.isEmpty()); |
| 347 } | 348 } |
| 348 | 349 |
| 349 void CompositorAnimations::cancelAnimationOnCompositor(const Element& element, c
onst Animation& animation, int id) | 350 void CompositorAnimations::cancelAnimationOnCompositor(const Element& element, c
onst Animation& animation, int id) |
| 350 { | 351 { |
| 351 if (!canStartAnimationOnCompositor(element)) { | 352 if (!canStartAnimationOnCompositor(element)) { |
| 352 // When an element is being detached, we cancel any associated | 353 // When an element is being detached, we cancel any associated |
| 353 // Animations for CSS animations. But by the time we get | 354 // Animations for CSS animations. But by the time we get |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 } | 505 } |
| 505 | 506 |
| 506 default: | 507 default: |
| 507 NOTREACHED(); | 508 NOTREACHED(); |
| 508 } | 509 } |
| 509 } | 510 } |
| 510 | 511 |
| 511 void addKeyframeToCurve(CompositorFilterAnimationCurve& curve, Keyframe::Propert
ySpecificKeyframe* keyframe, | 512 void addKeyframeToCurve(CompositorFilterAnimationCurve& curve, Keyframe::Propert
ySpecificKeyframe* keyframe, |
| 512 const AnimatableValue* value, const TimingFunction* keyframeTimingFunction) | 513 const AnimatableValue* value, const TimingFunction* keyframeTimingFunction) |
| 513 { | 514 { |
| 514 OwnPtr<CompositorFilterOperations> ops = adoptPtr(CompositorFactory::current
().createFilterOperations()); | 515 std::unique_ptr<CompositorFilterOperations> ops = wrapUnique(CompositorFacto
ry::current().createFilterOperations()); |
| 515 toCompositorFilterOperations(toAnimatableFilterOperations(value)->operations
(), ops.get()); | 516 toCompositorFilterOperations(toAnimatableFilterOperations(value)->operations
(), ops.get()); |
| 516 | 517 |
| 517 CompositorFilterKeyframe filterKeyframe(keyframe->offset(), std::move(ops)); | 518 CompositorFilterKeyframe filterKeyframe(keyframe->offset(), std::move(ops)); |
| 518 addCompositorKeyframeWithTimingFunction(curve, filterKeyframe, keyframeTimin
gFunction); | 519 addCompositorKeyframeWithTimingFunction(curve, filterKeyframe, keyframeTimin
gFunction); |
| 519 } | 520 } |
| 520 | 521 |
| 521 void addKeyframeToCurve(CompositorFloatAnimationCurve& curve, Keyframe::Property
SpecificKeyframe* keyframe, | 522 void addKeyframeToCurve(CompositorFloatAnimationCurve& curve, Keyframe::Property
SpecificKeyframe* keyframe, |
| 522 const AnimatableValue* value, const TimingFunction* keyframeTimingFunction) | 523 const AnimatableValue* value, const TimingFunction* keyframeTimingFunction) |
| 523 { | 524 { |
| 524 CompositorFloatKeyframe floatKeyframe(keyframe->offset(), toAnimatableDouble
(value)->toDouble()); | 525 CompositorFloatKeyframe floatKeyframe(keyframe->offset(), toAnimatableDouble
(value)->toDouble()); |
| 525 addCompositorKeyframeWithTimingFunction(curve, floatKeyframe, keyframeTiming
Function); | 526 addCompositorKeyframeWithTimingFunction(curve, floatKeyframe, keyframeTiming
Function); |
| 526 } | 527 } |
| 527 | 528 |
| 528 void addKeyframeToCurve(CompositorTransformAnimationCurve& curve, Keyframe::Prop
ertySpecificKeyframe* keyframe, | 529 void addKeyframeToCurve(CompositorTransformAnimationCurve& curve, Keyframe::Prop
ertySpecificKeyframe* keyframe, |
| 529 const AnimatableValue* value, const TimingFunction* keyframeTimingFunction) | 530 const AnimatableValue* value, const TimingFunction* keyframeTimingFunction) |
| 530 { | 531 { |
| 531 OwnPtr<CompositorTransformOperations> ops = adoptPtr(CompositorFactory::curr
ent().createTransformOperations()); | 532 std::unique_ptr<CompositorTransformOperations> ops = wrapUnique(CompositorFa
ctory::current().createTransformOperations()); |
| 532 toCompositorTransformOperations(toAnimatableTransform(value)->transformOpera
tions(), ops.get()); | 533 toCompositorTransformOperations(toAnimatableTransform(value)->transformOpera
tions(), ops.get()); |
| 533 | 534 |
| 534 CompositorTransformKeyframe transformKeyframe(keyframe->offset(), std::move(
ops)); | 535 CompositorTransformKeyframe transformKeyframe(keyframe->offset(), std::move(
ops)); |
| 535 addCompositorKeyframeWithTimingFunction(curve, transformKeyframe, keyframeTi
mingFunction); | 536 addCompositorKeyframeWithTimingFunction(curve, transformKeyframe, keyframeTi
mingFunction); |
| 536 } | 537 } |
| 537 | 538 |
| 538 template <typename PlatformAnimationCurveType> | 539 template <typename PlatformAnimationCurveType> |
| 539 void addKeyframesToCurve(PlatformAnimationCurveType& curve, const AnimatableValu
ePropertySpecificKeyframeVector& keyframes) | 540 void addKeyframesToCurve(PlatformAnimationCurveType& curve, const AnimatableValu
ePropertySpecificKeyframeVector& keyframes) |
| 540 { | 541 { |
| 541 auto* lastKeyframe = keyframes.last().get(); | 542 auto* lastKeyframe = keyframes.last().get(); |
| 542 for (const auto& keyframe : keyframes) { | 543 for (const auto& keyframe : keyframes) { |
| 543 const TimingFunction* keyframeTimingFunction = 0; | 544 const TimingFunction* keyframeTimingFunction = 0; |
| 544 if (keyframe != lastKeyframe) { // Ignore timing function of last frame. | 545 if (keyframe != lastKeyframe) { // Ignore timing function of last frame. |
| 545 keyframeTimingFunction = &keyframe->easing(); | 546 keyframeTimingFunction = &keyframe->easing(); |
| 546 } | 547 } |
| 547 | 548 |
| 548 // FIXME: This relies on StringKeyframes being eagerly evaluated, which
will | 549 // FIXME: This relies on StringKeyframes being eagerly evaluated, which
will |
| 549 // not happen eventually. Instead we should extract the CSSValue here | 550 // not happen eventually. Instead we should extract the CSSValue here |
| 550 // and convert using another set of toAnimatableXXXOperations functions. | 551 // and convert using another set of toAnimatableXXXOperations functions. |
| 551 const AnimatableValue* value = keyframe->getAnimatableValue().get(); | 552 const AnimatableValue* value = keyframe->getAnimatableValue().get(); |
| 552 | 553 |
| 553 addKeyframeToCurve(curve, keyframe.get(), value, keyframeTimingFunction)
; | 554 addKeyframeToCurve(curve, keyframe.get(), value, keyframeTimingFunction)
; |
| 554 } | 555 } |
| 555 } | 556 } |
| 556 | 557 |
| 557 } // namespace | 558 } // namespace |
| 558 | 559 |
| 559 void CompositorAnimations::getAnimationOnCompositor(const Timing& timing, int gr
oup, double startTime, double timeOffset, const KeyframeEffectModelBase& effect,
Vector<OwnPtr<CompositorAnimation>>& animations, double animationPlaybackRate) | 560 void CompositorAnimations::getAnimationOnCompositor(const Timing& timing, int gr
oup, double startTime, double timeOffset, const KeyframeEffectModelBase& effect,
Vector<std::unique_ptr<CompositorAnimation>>& animations, double animationPlayb
ackRate) |
| 560 { | 561 { |
| 561 ASSERT(animations.isEmpty()); | 562 ASSERT(animations.isEmpty()); |
| 562 CompositorTiming compositorTiming; | 563 CompositorTiming compositorTiming; |
| 563 bool timingValid = convertTimingForCompositor(timing, timeOffset, compositor
Timing, animationPlaybackRate); | 564 bool timingValid = convertTimingForCompositor(timing, timeOffset, compositor
Timing, animationPlaybackRate); |
| 564 ASSERT_UNUSED(timingValid, timingValid); | 565 ASSERT_UNUSED(timingValid, timingValid); |
| 565 | 566 |
| 566 PropertyHandleSet properties = effect.properties(); | 567 PropertyHandleSet properties = effect.properties(); |
| 567 ASSERT(!properties.isEmpty()); | 568 ASSERT(!properties.isEmpty()); |
| 568 for (const auto& property : properties) { | 569 for (const auto& property : properties) { |
| 569 PropertySpecificKeyframeVector values; | 570 PropertySpecificKeyframeVector values; |
| 570 // If the animation duration is infinite, it doesn't make sense to scale | 571 // If the animation duration is infinite, it doesn't make sense to scale |
| 571 // the keyframe offset, so use a scale of 1.0. This is connected to | 572 // the keyframe offset, so use a scale of 1.0. This is connected to |
| 572 // the known issue of how the Web Animations spec handles infinite | 573 // the known issue of how the Web Animations spec handles infinite |
| 573 // durations. See https://github.com/w3c/web-animations/issues/142 | 574 // durations. See https://github.com/w3c/web-animations/issues/142 |
| 574 double scale = compositorTiming.scaledDuration; | 575 double scale = compositorTiming.scaledDuration; |
| 575 if (!std::isfinite(scale)) | 576 if (!std::isfinite(scale)) |
| 576 scale = 1.0; | 577 scale = 1.0; |
| 577 getKeyframeValuesForProperty(&effect, property, scale, values); | 578 getKeyframeValuesForProperty(&effect, property, scale, values); |
| 578 | 579 |
| 579 CompositorTargetProperty::Type targetProperty; | 580 CompositorTargetProperty::Type targetProperty; |
| 580 OwnPtr<CompositorAnimationCurve> curve; | 581 std::unique_ptr<CompositorAnimationCurve> curve; |
| 581 switch (property.cssProperty()) { | 582 switch (property.cssProperty()) { |
| 582 case CSSPropertyOpacity: { | 583 case CSSPropertyOpacity: { |
| 583 targetProperty = CompositorTargetProperty::OPACITY; | 584 targetProperty = CompositorTargetProperty::OPACITY; |
| 584 | 585 |
| 585 CompositorFloatAnimationCurve* floatCurve = CompositorFactory::curre
nt().createFloatAnimationCurve(); | 586 CompositorFloatAnimationCurve* floatCurve = CompositorFactory::curre
nt().createFloatAnimationCurve(); |
| 586 addKeyframesToCurve(*floatCurve, values); | 587 addKeyframesToCurve(*floatCurve, values); |
| 587 setTimingFunctionOnCurve(*floatCurve, timing.timingFunction.get()); | 588 setTimingFunctionOnCurve(*floatCurve, timing.timingFunction.get()); |
| 588 curve = adoptPtr(floatCurve); | 589 curve = wrapUnique(floatCurve); |
| 589 break; | 590 break; |
| 590 } | 591 } |
| 591 case CSSPropertyWebkitFilter: | 592 case CSSPropertyWebkitFilter: |
| 592 case CSSPropertyBackdropFilter: { | 593 case CSSPropertyBackdropFilter: { |
| 593 targetProperty = CompositorTargetProperty::FILTER; | 594 targetProperty = CompositorTargetProperty::FILTER; |
| 594 CompositorFilterAnimationCurve* filterCurve = CompositorFactory::cur
rent().createFilterAnimationCurve(); | 595 CompositorFilterAnimationCurve* filterCurve = CompositorFactory::cur
rent().createFilterAnimationCurve(); |
| 595 addKeyframesToCurve(*filterCurve, values); | 596 addKeyframesToCurve(*filterCurve, values); |
| 596 setTimingFunctionOnCurve(*filterCurve, timing.timingFunction.get()); | 597 setTimingFunctionOnCurve(*filterCurve, timing.timingFunction.get()); |
| 597 curve = adoptPtr(filterCurve); | 598 curve = wrapUnique(filterCurve); |
| 598 break; | 599 break; |
| 599 } | 600 } |
| 600 case CSSPropertyRotate: | 601 case CSSPropertyRotate: |
| 601 case CSSPropertyScale: | 602 case CSSPropertyScale: |
| 602 case CSSPropertyTranslate: | 603 case CSSPropertyTranslate: |
| 603 case CSSPropertyTransform: { | 604 case CSSPropertyTransform: { |
| 604 targetProperty = CompositorTargetProperty::TRANSFORM; | 605 targetProperty = CompositorTargetProperty::TRANSFORM; |
| 605 CompositorTransformAnimationCurve* transformCurve = CompositorFactor
y::current().createTransformAnimationCurve(); | 606 CompositorTransformAnimationCurve* transformCurve = CompositorFactor
y::current().createTransformAnimationCurve(); |
| 606 addKeyframesToCurve(*transformCurve, values); | 607 addKeyframesToCurve(*transformCurve, values); |
| 607 setTimingFunctionOnCurve(*transformCurve, timing.timingFunction.get(
)); | 608 setTimingFunctionOnCurve(*transformCurve, timing.timingFunction.get(
)); |
| 608 curve = adoptPtr(transformCurve); | 609 curve = wrapUnique(transformCurve); |
| 609 break; | 610 break; |
| 610 } | 611 } |
| 611 default: | 612 default: |
| 612 ASSERT_NOT_REACHED(); | 613 ASSERT_NOT_REACHED(); |
| 613 continue; | 614 continue; |
| 614 } | 615 } |
| 615 ASSERT(curve.get()); | 616 ASSERT(curve.get()); |
| 616 | 617 |
| 617 OwnPtr<CompositorAnimation> animation = adoptPtr(CompositorFactory::curr
ent().createAnimation(*curve, targetProperty, group, 0)); | 618 std::unique_ptr<CompositorAnimation> animation = wrapUnique(CompositorFa
ctory::current().createAnimation(*curve, targetProperty, group, 0)); |
| 618 | 619 |
| 619 if (!std::isnan(startTime)) | 620 if (!std::isnan(startTime)) |
| 620 animation->setStartTime(startTime); | 621 animation->setStartTime(startTime); |
| 621 | 622 |
| 622 animation->setIterations(compositorTiming.adjustedIterationCount); | 623 animation->setIterations(compositorTiming.adjustedIterationCount); |
| 623 animation->setIterationStart(compositorTiming.iterationStart); | 624 animation->setIterationStart(compositorTiming.iterationStart); |
| 624 animation->setTimeOffset(compositorTiming.scaledTimeOffset); | 625 animation->setTimeOffset(compositorTiming.scaledTimeOffset); |
| 625 | 626 |
| 626 switch (compositorTiming.direction) { | 627 switch (compositorTiming.direction) { |
| 627 case Timing::PlaybackDirectionNormal: | 628 case Timing::PlaybackDirectionNormal: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 656 break; | 657 break; |
| 657 default: | 658 default: |
| 658 ASSERT_NOT_REACHED(); | 659 ASSERT_NOT_REACHED(); |
| 659 } | 660 } |
| 660 animations.append(std::move(animation)); | 661 animations.append(std::move(animation)); |
| 661 } | 662 } |
| 662 ASSERT(!animations.isEmpty()); | 663 ASSERT(!animations.isEmpty()); |
| 663 } | 664 } |
| 664 | 665 |
| 665 } // namespace blink | 666 } // namespace blink |
| OLD | NEW |