| 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" |
| 46 #include "core/paint/PaintPropertyTreeBuilder.h" |
| 45 #include "platform/RuntimeEnabledFeatures.h" | 47 #include "platform/RuntimeEnabledFeatures.h" |
| 46 #include "platform/WebTaskRunner.h" | 48 #include "platform/WebTaskRunner.h" |
| 47 #include "platform/animation/CompositorAnimationPlayer.h" | 49 #include "platform/animation/CompositorAnimationPlayer.h" |
| 48 #include "platform/heap/Persistent.h" | 50 #include "platform/heap/Persistent.h" |
| 49 #include "platform/instrumentation/tracing/TraceEvent.h" | 51 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 50 #include "public/platform/Platform.h" | 52 #include "public/platform/Platform.h" |
| 51 #include "public/platform/WebCompositorSupport.h" | 53 #include "public/platform/WebCompositorSupport.h" |
| 52 #include "wtf/MathExtras.h" | 54 #include "wtf/MathExtras.h" |
| 53 #include "wtf/PtrUtil.h" | 55 #include "wtf/PtrUtil.h" |
| 54 | 56 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 248 |
| 247 double Animation::unlimitedCurrentTimeInternal() const { | 249 double Animation::unlimitedCurrentTimeInternal() const { |
| 248 #if DCHECK_IS_ON() | 250 #if DCHECK_IS_ON() |
| 249 currentTimeInternal(); | 251 currentTimeInternal(); |
| 250 #endif | 252 #endif |
| 251 return playStateInternal() == Paused || isNull(m_startTime) | 253 return playStateInternal() == Paused || isNull(m_startTime) |
| 252 ? currentTimeInternal() | 254 ? currentTimeInternal() |
| 253 : calculateCurrentTime(); | 255 : calculateCurrentTime(); |
| 254 } | 256 } |
| 255 | 257 |
| 256 bool Animation::preCommit(int compositorGroup, bool startOnCompositor) { | 258 bool Animation::preCommit( |
| 259 int compositorGroup, |
| 260 const Optional<CompositorElementIdSet>& compositedElementIds, |
| 261 bool startOnCompositor) { |
| 257 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, | 262 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, |
| 258 DoNotSetCompositorPending); | 263 DoNotSetCompositorPending); |
| 259 | 264 |
| 260 bool softChange = | 265 bool softChange = |
| 261 m_compositorState && | 266 m_compositorState && |
| 262 (paused() || m_compositorState->playbackRate != m_playbackRate); | 267 (paused() || m_compositorState->playbackRate != m_playbackRate); |
| 263 bool hardChange = | 268 bool hardChange = |
| 264 m_compositorState && (m_compositorState->effectChanged || | 269 m_compositorState && (m_compositorState->effectChanged || |
| 265 m_compositorState->startTime != m_startTime); | 270 m_compositorState->startTime != m_startTime); |
| 266 | 271 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 284 | 289 |
| 285 DCHECK(!m_compositorState || !std::isnan(m_compositorState->startTime)); | 290 DCHECK(!m_compositorState || !std::isnan(m_compositorState->startTime)); |
| 286 | 291 |
| 287 if (!shouldStart) { | 292 if (!shouldStart) { |
| 288 m_currentTimePending = false; | 293 m_currentTimePending = false; |
| 289 } | 294 } |
| 290 | 295 |
| 291 if (shouldStart) { | 296 if (shouldStart) { |
| 292 m_compositorGroup = compositorGroup; | 297 m_compositorGroup = compositorGroup; |
| 293 if (startOnCompositor) { | 298 if (startOnCompositor) { |
| 294 if (isCandidateForAnimationOnCompositor()) | 299 if (isCandidateForAnimationOnCompositor(compositedElementIds)) |
| 295 createCompositorPlayer(); | 300 createCompositorPlayer(); |
| 296 | 301 |
| 297 if (maybeStartAnimationOnCompositor()) | 302 if (maybeStartAnimationOnCompositor(compositedElementIds)) |
| 298 m_compositorState = WTF::wrapUnique(new CompositorState(*this)); | 303 m_compositorState = WTF::wrapUnique(new CompositorState(*this)); |
| 299 else | 304 else |
| 300 cancelIncompatibleAnimationsOnCompositor(); | 305 cancelIncompatibleAnimationsOnCompositor(); |
| 301 } | 306 } |
| 302 } | 307 } |
| 303 | 308 |
| 304 return true; | 309 return true; |
| 305 } | 310 } |
| 306 | 311 |
| 307 void Animation::postCommit(double timelineTime) { | 312 void Animation::postCommit(double timelineTime) { |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 return; | 720 return; |
| 716 m_outdated = true; | 721 m_outdated = true; |
| 717 if (m_timeline) | 722 if (m_timeline) |
| 718 m_timeline->setOutdatedAnimation(this); | 723 m_timeline->setOutdatedAnimation(this); |
| 719 } | 724 } |
| 720 | 725 |
| 721 void Animation::forceServiceOnNextFrame() { | 726 void Animation::forceServiceOnNextFrame() { |
| 722 m_timeline->wake(); | 727 m_timeline->wake(); |
| 723 } | 728 } |
| 724 | 729 |
| 725 bool Animation::canStartAnimationOnCompositor() const { | 730 bool Animation::canStartAnimationOnCompositor( |
| 731 const Optional<CompositorElementIdSet>& compositedElementIds) 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; |
| 739 // If the optional element id set has no value we must be in SPv1 mode in |
| 740 // which case we trust the compositing logic will create a layer if needed. |
| 741 if (compositedElementIds.has_value()) { |
| 742 const KeyframeEffectReadOnly* effect = |
| 743 toKeyframeEffectReadOnly(m_content.get()); |
| 744 CompositorElementId targetElementId = |
| 745 createCompositorElementId(DOMNodeIds::idForNode(effect->target()), |
| 746 CompositorSubElementId::Primary); |
| 747 if (!compositedElementIds->contains(targetElementId)) |
| 748 return false; |
| 749 } |
| 733 | 750 |
| 734 return m_timeline && m_content && m_content->isKeyframeEffectReadOnly() && | 751 return m_timeline && m_content && m_content->isKeyframeEffectReadOnly() && |
| 735 playing(); | 752 playing(); |
| 736 } | 753 } |
| 737 | 754 |
| 738 bool Animation::isCandidateForAnimationOnCompositor() const { | 755 bool Animation::isCandidateForAnimationOnCompositor( |
| 739 if (!canStartAnimationOnCompositor()) | 756 const Optional<CompositorElementIdSet>& compositedElementIds) const { |
| 757 if (!canStartAnimationOnCompositor(compositedElementIds)) |
| 740 return false; | 758 return false; |
| 741 | 759 |
| 742 return toKeyframeEffectReadOnly(m_content.get()) | 760 return toKeyframeEffectReadOnly(m_content.get()) |
| 743 ->isCandidateForAnimationOnCompositor(m_playbackRate); | 761 ->isCandidateForAnimationOnCompositor(m_playbackRate); |
| 744 } | 762 } |
| 745 | 763 |
| 746 bool Animation::maybeStartAnimationOnCompositor() { | 764 bool Animation::maybeStartAnimationOnCompositor( |
| 747 if (!canStartAnimationOnCompositor()) | 765 const Optional<CompositorElementIdSet>& compositedElementIds) { |
| 766 if (!canStartAnimationOnCompositor(compositedElementIds)) |
| 748 return false; | 767 return false; |
| 749 | 768 |
| 750 bool reversed = m_playbackRate < 0; | 769 bool reversed = m_playbackRate < 0; |
| 751 | 770 |
| 752 double startTime = timeline()->zeroTime() + startTimeInternal(); | 771 double startTime = timeline()->zeroTime() + startTimeInternal(); |
| 753 if (reversed) { | 772 if (reversed) { |
| 754 startTime -= effectEnd() / fabs(m_playbackRate); | 773 startTime -= effectEnd() / fabs(m_playbackRate); |
| 755 } | 774 } |
| 756 | 775 |
| 757 double timeOffset = 0; | 776 double timeOffset = 0; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 DCHECK(!m_compositorPlayer); | 1168 DCHECK(!m_compositorPlayer); |
| 1150 } | 1169 } |
| 1151 | 1170 |
| 1152 void Animation::CompositorAnimationPlayerHolder::detach() { | 1171 void Animation::CompositorAnimationPlayerHolder::detach() { |
| 1153 DCHECK(m_compositorPlayer); | 1172 DCHECK(m_compositorPlayer); |
| 1154 m_compositorPlayer->setAnimationDelegate(nullptr); | 1173 m_compositorPlayer->setAnimationDelegate(nullptr); |
| 1155 m_animation = nullptr; | 1174 m_animation = nullptr; |
| 1156 m_compositorPlayer.reset(); | 1175 m_compositorPlayer.reset(); |
| 1157 } | 1176 } |
| 1158 } // namespace blink | 1177 } // namespace blink |
| OLD | NEW |