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