| 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 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/animation/Animation.h" | 31 #include "core/animation/Animation.h" |
| 32 | 32 |
| 33 #include "core/animation/AnimationTimeline.h" | 33 #include "core/animation/AnimationTimeline.h" |
| 34 #include "core/animation/CompositorPendingAnimations.h" | 34 #include "core/animation/CompositorPendingAnimations.h" |
| 35 #include "core/animation/KeyframeEffectReadOnly.h" | 35 #include "core/animation/KeyframeEffectReadOnly.h" |
| 36 #include "core/animation/css/CSSAnimations.h" | 36 #include "core/animation/css/CSSAnimations.h" |
| 37 #include "core/dom/DOMNodeIds.h" |
| 37 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
| 38 #include "core/dom/ExceptionCode.h" | 39 #include "core/dom/ExceptionCode.h" |
| 39 #include "core/dom/StyleChangeReason.h" | 40 #include "core/dom/StyleChangeReason.h" |
| 40 #include "core/dom/TaskRunnerHelper.h" | 41 #include "core/dom/TaskRunnerHelper.h" |
| 41 #include "core/events/AnimationPlaybackEvent.h" | 42 #include "core/events/AnimationPlaybackEvent.h" |
| 42 #include "core/frame/UseCounter.h" | 43 #include "core/frame/UseCounter.h" |
| 43 #include "core/inspector/InspectorInstrumentation.h" | 44 #include "core/inspector/InspectorInstrumentation.h" |
| 44 #include "core/inspector/InspectorTraceEvents.h" | 45 #include "core/inspector/InspectorTraceEvents.h" |
| 45 #include "platform/RuntimeEnabledFeatures.h" | 46 #include "platform/RuntimeEnabledFeatures.h" |
| 46 #include "platform/WebTaskRunner.h" | 47 #include "platform/WebTaskRunner.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 247 |
| 247 double Animation::unlimitedCurrentTimeInternal() const { | 248 double Animation::unlimitedCurrentTimeInternal() const { |
| 248 #if DCHECK_IS_ON() | 249 #if DCHECK_IS_ON() |
| 249 currentTimeInternal(); | 250 currentTimeInternal(); |
| 250 #endif | 251 #endif |
| 251 return playStateInternal() == Paused || isNull(m_startTime) | 252 return playStateInternal() == Paused || isNull(m_startTime) |
| 252 ? currentTimeInternal() | 253 ? currentTimeInternal() |
| 253 : calculateCurrentTime(); | 254 : calculateCurrentTime(); |
| 254 } | 255 } |
| 255 | 256 |
| 256 bool Animation::preCommit(int compositorGroup, bool startOnCompositor) { | 257 bool Animation::preCommit( |
| 258 int compositorGroup, |
| 259 const Optional<CompositorElementIdSet>& compositedAnimationElementIds, |
| 260 bool startOnCompositor) { |
| 257 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, | 261 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, |
| 258 DoNotSetCompositorPending); | 262 DoNotSetCompositorPending); |
| 259 | 263 |
| 260 bool softChange = | 264 bool softChange = |
| 261 m_compositorState && | 265 m_compositorState && |
| 262 (paused() || m_compositorState->playbackRate != m_playbackRate); | 266 (paused() || m_compositorState->playbackRate != m_playbackRate); |
| 263 bool hardChange = | 267 bool hardChange = |
| 264 m_compositorState && (m_compositorState->effectChanged || | 268 m_compositorState && (m_compositorState->effectChanged || |
| 265 m_compositorState->startTime != m_startTime); | 269 m_compositorState->startTime != m_startTime); |
| 266 | 270 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 284 | 288 |
| 285 DCHECK(!m_compositorState || !std::isnan(m_compositorState->startTime)); | 289 DCHECK(!m_compositorState || !std::isnan(m_compositorState->startTime)); |
| 286 | 290 |
| 287 if (!shouldStart) { | 291 if (!shouldStart) { |
| 288 m_currentTimePending = false; | 292 m_currentTimePending = false; |
| 289 } | 293 } |
| 290 | 294 |
| 291 if (shouldStart) { | 295 if (shouldStart) { |
| 292 m_compositorGroup = compositorGroup; | 296 m_compositorGroup = compositorGroup; |
| 293 if (startOnCompositor) { | 297 if (startOnCompositor) { |
| 294 if (isCandidateForAnimationOnCompositor()) | 298 if (isCandidateForAnimationOnCompositor(compositedAnimationElementIds)) |
| 295 createCompositorPlayer(); | 299 createCompositorPlayer(); |
| 296 | 300 |
| 297 if (maybeStartAnimationOnCompositor()) | 301 if (maybeStartAnimationOnCompositor(compositedAnimationElementIds)) |
| 298 m_compositorState = WTF::wrapUnique(new CompositorState(*this)); | 302 m_compositorState = WTF::wrapUnique(new CompositorState(*this)); |
| 299 else | 303 else |
| 300 cancelIncompatibleAnimationsOnCompositor(); | 304 cancelIncompatibleAnimationsOnCompositor(); |
| 301 } | 305 } |
| 302 } | 306 } |
| 303 | 307 |
| 304 return true; | 308 return true; |
| 305 } | 309 } |
| 306 | 310 |
| 307 void Animation::postCommit(double timelineTime) { | 311 void Animation::postCommit(double timelineTime) { |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 return; | 719 return; |
| 716 m_outdated = true; | 720 m_outdated = true; |
| 717 if (m_timeline) | 721 if (m_timeline) |
| 718 m_timeline->setOutdatedAnimation(this); | 722 m_timeline->setOutdatedAnimation(this); |
| 719 } | 723 } |
| 720 | 724 |
| 721 void Animation::forceServiceOnNextFrame() { | 725 void Animation::forceServiceOnNextFrame() { |
| 722 m_timeline->wake(); | 726 m_timeline->wake(); |
| 723 } | 727 } |
| 724 | 728 |
| 725 bool Animation::canStartAnimationOnCompositor() const { | 729 bool Animation::canStartAnimationOnCompositor( |
| 730 const Optional<CompositorElementIdSet>& compositedAnimationElementIds) |
| 731 const { |
| 726 if (m_isCompositedAnimationDisabledForTesting || effectSuppressed()) | 732 if (m_isCompositedAnimationDisabledForTesting || effectSuppressed()) |
| 727 return false; | 733 return false; |
| 728 | 734 |
| 729 // FIXME: Timeline playback rates should be compositable | 735 // FIXME: Timeline playback rates should be compositable |
| 730 if (m_playbackRate == 0 || (std::isinf(effectEnd()) && m_playbackRate < 0) || | 736 if (m_playbackRate == 0 || (std::isinf(effectEnd()) && m_playbackRate < 0) || |
| 731 (timeline() && timeline()->playbackRate() != 1)) | 737 (timeline() && timeline()->playbackRate() != 1)) |
| 732 return false; | 738 return false; |
| 733 | 739 |
| 740 // TODO(wkorman): Share logic in |
| 741 // PaintPropertyTreeBuilder::createDomNodeBasedCompositorElementId and |
| 742 // consider caching in animation or otherwise somehow if expensive. |
| 743 const KeyframeEffectReadOnly* effect = |
| 744 toKeyframeEffectReadOnly(m_content.get()); |
| 745 CompositorElementId targetCompositorElementId = createCompositorElementId( |
| 746 DOMNodeIds::idForNode(effect->target()), CompositorSubElementId::Primary); |
| 747 // If the optional element id set has no value we must be in SPv1 mode in |
| 748 // which case we trust the compositing logic will create a layer if needed. |
| 749 bool hasLayer = |
| 750 !compositedAnimationElementIds.has_value() || |
| 751 compositedAnimationElementIds->contains(targetCompositorElementId); |
| 752 if (!hasLayer) |
| 753 return false; |
| 754 |
| 734 return m_timeline && m_content && m_content->isKeyframeEffectReadOnly() && | 755 return m_timeline && m_content && m_content->isKeyframeEffectReadOnly() && |
| 735 playing(); | 756 playing(); |
| 736 } | 757 } |
| 737 | 758 |
| 738 bool Animation::isCandidateForAnimationOnCompositor() const { | 759 bool Animation::isCandidateForAnimationOnCompositor( |
| 739 if (!canStartAnimationOnCompositor()) | 760 const Optional<CompositorElementIdSet>& compositedAnimationElementIds) |
| 761 const { |
| 762 if (!canStartAnimationOnCompositor(compositedAnimationElementIds)) |
| 740 return false; | 763 return false; |
| 741 | 764 |
| 742 return toKeyframeEffectReadOnly(m_content.get()) | 765 return toKeyframeEffectReadOnly(m_content.get()) |
| 743 ->isCandidateForAnimationOnCompositor(m_playbackRate); | 766 ->isCandidateForAnimationOnCompositor(m_playbackRate); |
| 744 } | 767 } |
| 745 | 768 |
| 746 bool Animation::maybeStartAnimationOnCompositor() { | 769 bool Animation::maybeStartAnimationOnCompositor( |
| 747 if (!canStartAnimationOnCompositor()) | 770 const Optional<CompositorElementIdSet>& compositedAnimationElementIds) { |
| 771 if (!canStartAnimationOnCompositor(compositedAnimationElementIds)) |
| 748 return false; | 772 return false; |
| 749 | 773 |
| 750 bool reversed = m_playbackRate < 0; | 774 bool reversed = m_playbackRate < 0; |
| 751 | 775 |
| 752 double startTime = timeline()->zeroTime() + startTimeInternal(); | 776 double startTime = timeline()->zeroTime() + startTimeInternal(); |
| 753 if (reversed) { | 777 if (reversed) { |
| 754 startTime -= effectEnd() / fabs(m_playbackRate); | 778 startTime -= effectEnd() / fabs(m_playbackRate); |
| 755 } | 779 } |
| 756 | 780 |
| 757 double timeOffset = 0; | 781 double timeOffset = 0; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 DCHECK(!m_compositorPlayer); | 1173 DCHECK(!m_compositorPlayer); |
| 1150 } | 1174 } |
| 1151 | 1175 |
| 1152 void Animation::CompositorAnimationPlayerHolder::detach() { | 1176 void Animation::CompositorAnimationPlayerHolder::detach() { |
| 1153 DCHECK(m_compositorPlayer); | 1177 DCHECK(m_compositorPlayer); |
| 1154 m_compositorPlayer->setAnimationDelegate(nullptr); | 1178 m_compositorPlayer->setAnimationDelegate(nullptr); |
| 1155 m_animation = nullptr; | 1179 m_animation = nullptr; |
| 1156 m_compositorPlayer.reset(); | 1180 m_compositorPlayer.reset(); |
| 1157 } | 1181 } |
| 1158 } // namespace blink | 1182 } // namespace blink |
| OLD | NEW |