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