| 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 21 matching lines...) Expand all Loading... |
| 32 #include "core/animation/AnimationPlayer.h" | 32 #include "core/animation/AnimationPlayer.h" |
| 33 | 33 |
| 34 #include "core/animation/Animation.h" | 34 #include "core/animation/Animation.h" |
| 35 #include "core/animation/AnimationTimeline.h" | 35 #include "core/animation/AnimationTimeline.h" |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/dom/ExceptionCode.h" | 37 #include "core/dom/ExceptionCode.h" |
| 38 #include "core/events/AnimationPlayerEvent.h" | 38 #include "core/events/AnimationPlayerEvent.h" |
| 39 #include "core/frame/UseCounter.h" | 39 #include "core/frame/UseCounter.h" |
| 40 #include "core/inspector/InspectorInstrumentation.h" | 40 #include "core/inspector/InspectorInstrumentation.h" |
| 41 #include "core/inspector/InspectorTraceEvents.h" | 41 #include "core/inspector/InspectorTraceEvents.h" |
| 42 #include "platform/RuntimeEnabledFeatures.h" |
| 42 #include "platform/TraceEvent.h" | 43 #include "platform/TraceEvent.h" |
| 44 #include "public/platform/Platform.h" |
| 45 #include "public/platform/WebCompositorAnimationPlayer.h" |
| 46 #include "public/platform/WebCompositorSupport.h" |
| 43 #include "wtf/MathExtras.h" | 47 #include "wtf/MathExtras.h" |
| 44 | 48 |
| 45 namespace blink { | 49 namespace blink { |
| 46 | 50 |
| 47 namespace { | 51 namespace { |
| 48 | 52 |
| 49 static unsigned nextSequenceNumber() | 53 static unsigned nextSequenceNumber() |
| 50 { | 54 { |
| 51 static unsigned next = 0; | 55 static unsigned next = 0; |
| 52 return ++next; | 56 return ++next; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 81 , m_content(content) | 85 , m_content(content) |
| 82 , m_timeline(&timeline) | 86 , m_timeline(&timeline) |
| 83 , m_paused(false) | 87 , m_paused(false) |
| 84 , m_held(true) | 88 , m_held(true) |
| 85 , m_isPausedForTesting(false) | 89 , m_isPausedForTesting(false) |
| 86 , m_outdated(false) | 90 , m_outdated(false) |
| 87 , m_finished(true) | 91 , m_finished(true) |
| 88 , m_compositorState(nullptr) | 92 , m_compositorState(nullptr) |
| 89 , m_compositorPending(false) | 93 , m_compositorPending(false) |
| 90 , m_compositorGroup(0) | 94 , m_compositorGroup(0) |
| 95 , m_attachCompositorPlayerToElement(false) |
| 91 , m_currentTimePending(false) | 96 , m_currentTimePending(false) |
| 92 , m_stateIsBeingUpdated(false) | 97 , m_stateIsBeingUpdated(false) |
| 93 { | 98 { |
| 99 createCompositorPlayer(); |
| 100 |
| 94 if (m_content) { | 101 if (m_content) { |
| 95 if (m_content->player()) { | 102 if (m_content->player()) { |
| 96 m_content->player()->cancel(); | 103 m_content->player()->cancel(); |
| 97 m_content->player()->setSource(0); | 104 m_content->player()->setSource(0); |
| 98 } | 105 } |
| 99 m_content->attach(this); | 106 m_content->attach(this); |
| 107 attachElementToPlayer(); |
| 100 } | 108 } |
| 101 } | 109 } |
| 102 | 110 |
| 103 AnimationPlayer::~AnimationPlayer() | 111 AnimationPlayer::~AnimationPlayer() |
| 104 { | 112 { |
| 105 #if !ENABLE(OILPAN) | 113 #if !ENABLE(OILPAN) |
| 106 if (m_content) | 114 if (m_content) { |
| 115 detachElementFromPlayer(); |
| 107 m_content->detach(); | 116 m_content->detach(); |
| 117 } |
| 108 if (m_timeline) | 118 if (m_timeline) |
| 109 m_timeline->playerDestroyed(this); | 119 m_timeline->playerDestroyed(this); |
| 110 #endif | 120 #endif |
| 121 |
| 122 destroyCompositorPlayer(); |
| 111 } | 123 } |
| 112 | 124 |
| 113 double AnimationPlayer::sourceEnd() const | 125 double AnimationPlayer::sourceEnd() const |
| 114 { | 126 { |
| 115 return m_content ? m_content->endTimeInternal() : 0; | 127 return m_content ? m_content->endTimeInternal() : 0; |
| 116 } | 128 } |
| 117 | 129 |
| 118 bool AnimationPlayer::limited(double currentTime) const | 130 bool AnimationPlayer::limited(double currentTime) const |
| 119 { | 131 { |
| 120 return (m_playbackRate < 0 && currentTime <= 0) || (m_playbackRate > 0 && cu
rrentTime >= sourceEnd()); | 132 return (m_playbackRate < 0 && currentTime <= 0) || (m_playbackRate > 0 && cu
rrentTime >= sourceEnd()); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 } | 438 } |
| 427 | 439 |
| 428 void AnimationPlayer::setSource(AnimationNode* newSource) | 440 void AnimationPlayer::setSource(AnimationNode* newSource) |
| 429 { | 441 { |
| 430 if (m_content == newSource) | 442 if (m_content == newSource) |
| 431 return; | 443 return; |
| 432 | 444 |
| 433 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorP
endingWithSourceChanged); | 445 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorP
endingWithSourceChanged); |
| 434 | 446 |
| 435 double storedCurrentTime = currentTimeInternal(); | 447 double storedCurrentTime = currentTimeInternal(); |
| 436 if (m_content) | 448 if (m_content) { |
| 449 detachElementFromPlayer(); |
| 437 m_content->detach(); | 450 m_content->detach(); |
| 451 } |
| 438 m_content = newSource; | 452 m_content = newSource; |
| 439 if (newSource) { | 453 if (newSource) { |
| 440 // FIXME: This logic needs to be updated once groups are implemented | 454 // FIXME: This logic needs to be updated once groups are implemented |
| 441 if (newSource->player()) { | 455 if (newSource->player()) { |
| 442 newSource->player()->cancel(); | 456 newSource->player()->cancel(); |
| 443 newSource->player()->setSource(0); | 457 newSource->player()->setSource(0); |
| 444 } | 458 } |
| 445 newSource->attach(this); | 459 newSource->attach(this); |
| 460 attachElementToPlayer(); |
| 446 setOutdated(); | 461 setOutdated(); |
| 447 } | 462 } |
| 448 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); | 463 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); |
| 449 } | 464 } |
| 450 | 465 |
| 451 const char* AnimationPlayer::playStateString(AnimationPlayState playState) | 466 const char* AnimationPlayer::playStateString(AnimationPlayState playState) |
| 452 { | 467 { |
| 453 switch (playState) { | 468 switch (playState) { |
| 454 case Idle: | 469 case Idle: |
| 455 return "idle"; | 470 return "idle"; |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 ASSERT(!m_stateIsBeingUpdated); | 838 ASSERT(!m_stateIsBeingUpdated); |
| 824 m_stateIsBeingUpdated = true; | 839 m_stateIsBeingUpdated = true; |
| 825 } | 840 } |
| 826 | 841 |
| 827 void AnimationPlayer::endUpdatingState() | 842 void AnimationPlayer::endUpdatingState() |
| 828 { | 843 { |
| 829 ASSERT(m_stateIsBeingUpdated); | 844 ASSERT(m_stateIsBeingUpdated); |
| 830 m_stateIsBeingUpdated = false; | 845 m_stateIsBeingUpdated = false; |
| 831 } | 846 } |
| 832 | 847 |
| 848 void AnimationPlayer::createCompositorPlayer() |
| 849 { |
| 850 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && Platfor
m::current()->compositorSupport()) { |
| 851 m_compositorPlayer = adoptPtr(Platform::current()->compositorSupport()->
createAnimationPlayer()); |
| 852 ASSERT(m_compositorPlayer); |
| 853 m_compositorPlayer->setAnimationDelegate(this); |
| 854 } |
| 855 } |
| 856 |
| 857 void AnimationPlayer::destroyCompositorPlayer() |
| 858 { |
| 859 if (m_compositorPlayer) |
| 860 m_compositorPlayer->setAnimationDelegate(nullptr); |
| 861 m_compositorPlayer.clear(); |
| 862 } |
| 863 |
| 864 void AnimationPlayer::attachElementToPlayer() |
| 865 { |
| 866 m_attachCompositorPlayerToElement = true; |
| 867 updateCompositorPlayerToElementAttachment(); |
| 868 } |
| 869 |
| 870 void AnimationPlayer::detachElementFromPlayer() |
| 871 { |
| 872 m_attachCompositorPlayerToElement = false; |
| 873 if (m_compositorPlayer && m_compositorPlayer->isLayerAttached()) |
| 874 m_compositorPlayer->detachLayer(); |
| 875 } |
| 876 |
| 877 void AnimationPlayer::updateCompositorPlayerToElementAttachment() |
| 878 { |
| 879 if (!RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() || !m_att
achCompositorPlayerToElement) |
| 880 return; |
| 881 if (!m_compositorPlayer || !m_content || !m_content->isAnimation() || !toAni
mation(m_content.get())->canAttachElementToCompositorPlayer()) |
| 882 return; |
| 883 |
| 884 m_attachCompositorPlayerToElement = false; |
| 885 toAnimation(m_content.get())->attachElementToCompositorPlayer(); |
| 886 } |
| 887 |
| 888 void AnimationPlayer::notifyAnimationStarted(double monotonicTime, int group) |
| 889 { |
| 890 ASSERT(RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled()); |
| 891 timeline()->document()->compositorPendingAnimations().notifyCompositorAnimat
ionStarted(monotonicTime, group); |
| 892 } |
| 893 |
| 833 AnimationPlayer::PlayStateUpdateScope::PlayStateUpdateScope(AnimationPlayer& pla
yer, TimingUpdateReason reason, CompositorPendingChange compositorPendingChange) | 894 AnimationPlayer::PlayStateUpdateScope::PlayStateUpdateScope(AnimationPlayer& pla
yer, TimingUpdateReason reason, CompositorPendingChange compositorPendingChange) |
| 834 : m_player(player) | 895 : m_player(player) |
| 835 , m_initialPlayState(m_player->playStateInternal()) | 896 , m_initialPlayState(m_player->playStateInternal()) |
| 836 , m_compositorPendingChange(compositorPendingChange) | 897 , m_compositorPendingChange(compositorPendingChange) |
| 837 { | 898 { |
| 838 m_player->beginUpdatingState(); | 899 m_player->beginUpdatingState(); |
| 839 m_player->updateCurrentTimingState(reason); | 900 m_player->updateCurrentTimingState(reason); |
| 840 } | 901 } |
| 841 | 902 |
| 842 AnimationPlayer::PlayStateUpdateScope::~PlayStateUpdateScope() | 903 AnimationPlayer::PlayStateUpdateScope::~PlayStateUpdateScope() |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 visitor->trace(m_content); | 997 visitor->trace(m_content); |
| 937 visitor->trace(m_timeline); | 998 visitor->trace(m_timeline); |
| 938 visitor->trace(m_pendingFinishedEvent); | 999 visitor->trace(m_pendingFinishedEvent); |
| 939 visitor->trace(m_finishedPromise); | 1000 visitor->trace(m_finishedPromise); |
| 940 visitor->trace(m_readyPromise); | 1001 visitor->trace(m_readyPromise); |
| 941 EventTargetWithInlineData::trace(visitor); | 1002 EventTargetWithInlineData::trace(visitor); |
| 942 ActiveDOMObject::trace(visitor); | 1003 ActiveDOMObject::trace(visitor); |
| 943 } | 1004 } |
| 944 | 1005 |
| 945 } // namespace | 1006 } // namespace |
| OLD | NEW |