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; |
53 } | 57 } |
54 | 58 |
55 } | 59 } |
56 | 60 |
57 PassRefPtrWillBeRawPtr<AnimationPlayer> AnimationPlayer::create(AnimationNode* s
ource, AnimationTimeline* timeline) | 61 PassRefPtrWillBeRawPtr<AnimationPlayer> AnimationPlayer::create(AnimationNode* s
ource, AnimationTimeline* timeline) |
58 { | 62 { |
59 if (!timeline) { | 63 if (!timeline) { |
60 // FIXME: Support creating players without a timeline. | 64 // FIXME: Support creating players without a timeline. |
61 return nullptr; | 65 return nullptr; |
62 } | 66 } |
63 | 67 |
64 RefPtrWillBeRawPtr<AnimationPlayer> player = adoptRefWillBeNoop(new Animatio
nPlayer(timeline->document()->contextDocument().get(), *timeline, source)); | 68 RefPtrWillBeRawPtr<AnimationPlayer> player = adoptRefWillBeNoop(new Animatio
nPlayer(timeline->document()->contextDocument().get(), *timeline, source)); |
65 player->suspendIfNeeded(); | 69 player->suspendIfNeeded(); |
66 | 70 |
67 if (timeline) { | 71 if (timeline) { |
68 timeline->playerAttached(*player); | 72 timeline->playerAttached(*player); |
| 73 player->attachCompositorTimeline(); |
69 } | 74 } |
70 | 75 |
71 return player.release(); | 76 return player.release(); |
72 } | 77 } |
73 | 78 |
74 AnimationPlayer::AnimationPlayer(ExecutionContext* executionContext, AnimationTi
meline& timeline, AnimationNode* content) | 79 AnimationPlayer::AnimationPlayer(ExecutionContext* executionContext, AnimationTi
meline& timeline, AnimationNode* content) |
75 : ActiveDOMObject(executionContext) | 80 : ActiveDOMObject(executionContext) |
76 , m_playState(Idle) | 81 , m_playState(Idle) |
77 , m_playbackRate(1) | 82 , m_playbackRate(1) |
78 , m_startTime(nullValue()) | 83 , m_startTime(nullValue()) |
(...skipping 22 matching lines...) Expand all Loading... |
101 } | 106 } |
102 | 107 |
103 AnimationPlayer::~AnimationPlayer() | 108 AnimationPlayer::~AnimationPlayer() |
104 { | 109 { |
105 #if !ENABLE(OILPAN) | 110 #if !ENABLE(OILPAN) |
106 if (m_content) | 111 if (m_content) |
107 m_content->detach(); | 112 m_content->detach(); |
108 if (m_timeline) | 113 if (m_timeline) |
109 m_timeline->playerDestroyed(this); | 114 m_timeline->playerDestroyed(this); |
110 #endif | 115 #endif |
| 116 |
| 117 destroyCompositorPlayer(); |
111 } | 118 } |
112 | 119 |
113 double AnimationPlayer::sourceEnd() const | 120 double AnimationPlayer::sourceEnd() const |
114 { | 121 { |
115 return m_content ? m_content->endTimeInternal() : 0; | 122 return m_content ? m_content->endTimeInternal() : 0; |
116 } | 123 } |
117 | 124 |
118 bool AnimationPlayer::limited(double currentTime) const | 125 bool AnimationPlayer::limited(double currentTime) const |
119 { | 126 { |
120 return (m_playbackRate < 0 && currentTime <= 0) || (m_playbackRate > 0 && cu
rrentTime >= sourceEnd()); | 127 return (m_playbackRate < 0 && currentTime <= 0) || (m_playbackRate > 0 && cu
rrentTime >= sourceEnd()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 266 |
260 ASSERT(!m_compositorState || !std::isnan(m_compositorState->startTime)); | 267 ASSERT(!m_compositorState || !std::isnan(m_compositorState->startTime)); |
261 | 268 |
262 if (!shouldStart) { | 269 if (!shouldStart) { |
263 m_currentTimePending = false; | 270 m_currentTimePending = false; |
264 } | 271 } |
265 | 272 |
266 if (shouldStart) { | 273 if (shouldStart) { |
267 m_compositorGroup = compositorGroup; | 274 m_compositorGroup = compositorGroup; |
268 if (startOnCompositor) { | 275 if (startOnCompositor) { |
| 276 if (isCandidateForAnimationOnCompositor()) |
| 277 createCompositorPlayer(); |
| 278 |
269 if (maybeStartAnimationOnCompositor()) | 279 if (maybeStartAnimationOnCompositor()) |
270 m_compositorState = adoptPtr(new CompositorState(*this)); | 280 m_compositorState = adoptPtr(new CompositorState(*this)); |
271 else | 281 else |
272 cancelIncompatibleAnimationsOnCompositor(); | 282 cancelIncompatibleAnimationsOnCompositor(); |
273 } | 283 } |
274 } | 284 } |
275 } | 285 } |
276 | 286 |
277 void AnimationPlayer::postCommit(double timelineTime) | 287 void AnimationPlayer::postCommit(double timelineTime) |
278 { | 288 { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 // Even though this player is not outdated, time to effect change is | 427 // Even though this player is not outdated, time to effect change is |
418 // infinity until start time is set. | 428 // infinity until start time is set. |
419 m_timeline->wake(); | 429 m_timeline->wake(); |
420 } | 430 } |
421 } | 431 } |
422 | 432 |
423 void AnimationPlayer::setSource(AnimationNode* newSource) | 433 void AnimationPlayer::setSource(AnimationNode* newSource) |
424 { | 434 { |
425 if (m_content == newSource) | 435 if (m_content == newSource) |
426 return; | 436 return; |
427 | |
428 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorP
endingWithSourceChanged); | 437 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorP
endingWithSourceChanged); |
429 | 438 |
430 double storedCurrentTime = currentTimeInternal(); | 439 double storedCurrentTime = currentTimeInternal(); |
431 if (m_content) | 440 if (m_content) |
432 m_content->detach(); | 441 m_content->detach(); |
433 m_content = newSource; | 442 m_content = newSource; |
434 if (newSource) { | 443 if (newSource) { |
435 // FIXME: This logic needs to be updated once groups are implemented | 444 // FIXME: This logic needs to be updated once groups are implemented |
436 if (newSource->player()) { | 445 if (newSource->player()) { |
437 newSource->player()->cancel(); | 446 newSource->player()->cancel(); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); | 667 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); |
659 } | 668 } |
660 | 669 |
661 void AnimationPlayer::setOutdated() | 670 void AnimationPlayer::setOutdated() |
662 { | 671 { |
663 m_outdated = true; | 672 m_outdated = true; |
664 if (m_timeline) | 673 if (m_timeline) |
665 m_timeline->setOutdatedAnimationPlayer(this); | 674 m_timeline->setOutdatedAnimationPlayer(this); |
666 } | 675 } |
667 | 676 |
668 bool AnimationPlayer::canStartAnimationOnCompositor() | 677 bool AnimationPlayer::canStartAnimationOnCompositor() const |
669 { | 678 { |
670 // FIXME: Timeline playback rates should be compositable | 679 // FIXME: Timeline playback rates should be compositable |
671 if (m_playbackRate == 0 || (std::isinf(sourceEnd()) && m_playbackRate < 0) |
| (timeline() && timeline()->playbackRate() != 1)) | 680 if (m_playbackRate == 0 || (std::isinf(sourceEnd()) && m_playbackRate < 0) |
| (timeline() && timeline()->playbackRate() != 1)) |
672 return false; | 681 return false; |
673 | 682 |
674 return m_timeline && m_content && m_content->isAnimation() && playing(); | 683 return m_timeline && m_content && m_content->isAnimation() && playing(); |
675 } | 684 } |
676 | 685 |
| 686 bool AnimationPlayer::isCandidateForAnimationOnCompositor() const |
| 687 { |
| 688 if (!canStartAnimationOnCompositor()) |
| 689 return false; |
| 690 |
| 691 return toAnimation(m_content.get())->isCandidateForAnimationOnCompositor(m_p
laybackRate); |
| 692 } |
| 693 |
677 bool AnimationPlayer::maybeStartAnimationOnCompositor() | 694 bool AnimationPlayer::maybeStartAnimationOnCompositor() |
678 { | 695 { |
679 if (!canStartAnimationOnCompositor()) | 696 if (!canStartAnimationOnCompositor()) |
680 return false; | 697 return false; |
681 | 698 |
682 bool reversed = m_playbackRate < 0; | 699 bool reversed = m_playbackRate < 0; |
683 | 700 |
684 double startTime = timeline()->zeroTime() + startTimeInternal(); | 701 double startTime = timeline()->zeroTime() + startTimeInternal(); |
685 if (reversed) { | 702 if (reversed) { |
686 startTime -= sourceEnd() / fabs(m_playbackRate); | 703 startTime -= sourceEnd() / fabs(m_playbackRate); |
687 } | 704 } |
688 | 705 |
689 double timeOffset = 0; | 706 double timeOffset = 0; |
690 if (std::isnan(startTime)) { | 707 if (std::isnan(startTime)) { |
691 timeOffset = reversed ? sourceEnd() - currentTimeInternal() : currentTim
eInternal(); | 708 timeOffset = reversed ? sourceEnd() - currentTimeInternal() : currentTim
eInternal(); |
692 timeOffset = timeOffset / fabs(m_playbackRate); | 709 timeOffset = timeOffset / fabs(m_playbackRate); |
693 } | 710 } |
694 ASSERT(m_compositorGroup != 0); | 711 ASSERT(m_compositorGroup != 0); |
695 return toAnimation(m_content.get())->maybeStartAnimationOnCompositor(m_compo
sitorGroup, startTime, timeOffset, m_playbackRate); | 712 return toAnimation(m_content.get())->maybeStartAnimationOnCompositor(m_compo
sitorGroup, startTime, timeOffset, m_playbackRate); |
696 } | 713 } |
697 | 714 |
698 void AnimationPlayer::setCompositorPending(bool sourceChanged) | 715 void AnimationPlayer::setCompositorPending(bool sourceChanged) |
699 { | 716 { |
700 // FIXME: Animation could notify this directly? | 717 // FIXME: Animation could notify this directly? |
701 if (!hasActiveAnimationsOnCompositor()) { | 718 if (!hasActiveAnimationsOnCompositor()) { |
| 719 destroyCompositorPlayer(); |
702 m_compositorState.release(); | 720 m_compositorState.release(); |
703 } | 721 } |
704 if (sourceChanged && m_compositorState) { | 722 if (sourceChanged && m_compositorState) { |
705 m_compositorState->sourceChanged = true; | 723 m_compositorState->sourceChanged = true; |
706 } | 724 } |
707 if (m_compositorPending || m_isPausedForTesting) { | 725 if (m_compositorPending || m_isPausedForTesting) { |
708 return; | 726 return; |
709 } | 727 } |
710 | 728 |
711 if (sourceChanged || !m_compositorState | 729 if (sourceChanged || !m_compositorState |
712 || !playing() || m_compositorState->playbackRate != m_playbackRate | 730 || !playing() || m_compositorState->playbackRate != m_playbackRate |
713 || m_compositorState->startTime != m_startTime) { | 731 || m_compositorState->startTime != m_startTime) { |
714 m_compositorPending = true; | 732 m_compositorPending = true; |
715 timeline()->document()->compositorPendingAnimations().add(this); | 733 timeline()->document()->compositorPendingAnimations().add(this); |
716 } | 734 } |
717 } | 735 } |
718 | 736 |
719 void AnimationPlayer::cancelAnimationOnCompositor() | 737 void AnimationPlayer::cancelAnimationOnCompositor() |
720 { | 738 { |
721 if (hasActiveAnimationsOnCompositor()) | 739 if (hasActiveAnimationsOnCompositor()) |
722 toAnimation(m_content.get())->cancelAnimationOnCompositor(); | 740 toAnimation(m_content.get())->cancelAnimationOnCompositor(); |
| 741 |
| 742 destroyCompositorPlayer(); |
723 } | 743 } |
724 | 744 |
725 void AnimationPlayer::restartAnimationOnCompositor() | 745 void AnimationPlayer::restartAnimationOnCompositor() |
726 { | 746 { |
727 if (hasActiveAnimationsOnCompositor()) | 747 if (hasActiveAnimationsOnCompositor()) |
728 toAnimation(m_content.get())->restartAnimationOnCompositor(); | 748 toAnimation(m_content.get())->restartAnimationOnCompositor(); |
729 } | 749 } |
730 | 750 |
731 void AnimationPlayer::cancelIncompatibleAnimationsOnCompositor() | 751 void AnimationPlayer::cancelIncompatibleAnimationsOnCompositor() |
732 { | 752 { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 ASSERT(!m_stateIsBeingUpdated); | 835 ASSERT(!m_stateIsBeingUpdated); |
816 m_stateIsBeingUpdated = true; | 836 m_stateIsBeingUpdated = true; |
817 } | 837 } |
818 | 838 |
819 void AnimationPlayer::endUpdatingState() | 839 void AnimationPlayer::endUpdatingState() |
820 { | 840 { |
821 ASSERT(m_stateIsBeingUpdated); | 841 ASSERT(m_stateIsBeingUpdated); |
822 m_stateIsBeingUpdated = false; | 842 m_stateIsBeingUpdated = false; |
823 } | 843 } |
824 | 844 |
| 845 void AnimationPlayer::createCompositorPlayer() |
| 846 { |
| 847 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && !m_comp
ositorPlayer && Platform::current()->compositorSupport()) { |
| 848 m_compositorPlayer = adoptPtr(Platform::current()->compositorSupport()->
createAnimationPlayer()); |
| 849 ASSERT(m_compositorPlayer); |
| 850 m_compositorPlayer->setAnimationDelegate(this); |
| 851 attachCompositorTimeline(); |
| 852 } |
| 853 |
| 854 attachCompositedLayers(); |
| 855 } |
| 856 |
| 857 void AnimationPlayer::destroyCompositorPlayer() |
| 858 { |
| 859 detachCompositedLayers(); |
| 860 |
| 861 if (m_compositorPlayer) { |
| 862 detachCompositorTimeline(); |
| 863 m_compositorPlayer->setAnimationDelegate(nullptr); |
| 864 } |
| 865 m_compositorPlayer.clear(); |
| 866 } |
| 867 |
| 868 void AnimationPlayer::attachCompositorTimeline() |
| 869 { |
| 870 if (m_compositorPlayer) { |
| 871 WebCompositorAnimationTimeline* timeline = m_timeline ? m_timeline->comp
ositorTimeline() : nullptr; |
| 872 if (timeline) |
| 873 timeline->playerAttached(*this); |
| 874 } |
| 875 } |
| 876 |
| 877 void AnimationPlayer::detachCompositorTimeline() |
| 878 { |
| 879 if (m_compositorPlayer) { |
| 880 WebCompositorAnimationTimeline* timeline = m_timeline ? m_timeline->comp
ositorTimeline() : nullptr; |
| 881 if (timeline) |
| 882 timeline->playerDestroyed(*this); |
| 883 } |
| 884 } |
| 885 |
| 886 void AnimationPlayer::attachCompositedLayers() |
| 887 { |
| 888 if (!RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() || !m_com
positorPlayer) |
| 889 return; |
| 890 |
| 891 ASSERT(m_content); |
| 892 ASSERT(m_content->isAnimation()); |
| 893 |
| 894 if (toAnimation(m_content.get())->canAttachCompositedLayers()) |
| 895 toAnimation(m_content.get())->attachCompositedLayers(); |
| 896 } |
| 897 |
| 898 void AnimationPlayer::detachCompositedLayers() |
| 899 { |
| 900 if (m_compositorPlayer && m_compositorPlayer->isLayerAttached()) |
| 901 m_compositorPlayer->detachLayer(); |
| 902 } |
| 903 |
| 904 void AnimationPlayer::notifyAnimationStarted(double monotonicTime, int group) |
| 905 { |
| 906 ASSERT(RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled()); |
| 907 timeline()->document()->compositorPendingAnimations().notifyCompositorAnimat
ionStarted(monotonicTime, group); |
| 908 } |
| 909 |
825 AnimationPlayer::PlayStateUpdateScope::PlayStateUpdateScope(AnimationPlayer& pla
yer, TimingUpdateReason reason, CompositorPendingChange compositorPendingChange) | 910 AnimationPlayer::PlayStateUpdateScope::PlayStateUpdateScope(AnimationPlayer& pla
yer, TimingUpdateReason reason, CompositorPendingChange compositorPendingChange) |
826 : m_player(player) | 911 : m_player(player) |
827 , m_initialPlayState(m_player->playStateInternal()) | 912 , m_initialPlayState(m_player->playStateInternal()) |
828 , m_compositorPendingChange(compositorPendingChange) | 913 , m_compositorPendingChange(compositorPendingChange) |
829 { | 914 { |
830 m_player->beginUpdatingState(); | 915 m_player->beginUpdatingState(); |
831 m_player->updateCurrentTimingState(reason); | 916 m_player->updateCurrentTimingState(reason); |
832 } | 917 } |
833 | 918 |
834 AnimationPlayer::PlayStateUpdateScope::~PlayStateUpdateScope() | 919 AnimationPlayer::PlayStateUpdateScope::~PlayStateUpdateScope() |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 visitor->trace(m_content); | 1013 visitor->trace(m_content); |
929 visitor->trace(m_timeline); | 1014 visitor->trace(m_timeline); |
930 visitor->trace(m_pendingFinishedEvent); | 1015 visitor->trace(m_pendingFinishedEvent); |
931 visitor->trace(m_finishedPromise); | 1016 visitor->trace(m_finishedPromise); |
932 visitor->trace(m_readyPromise); | 1017 visitor->trace(m_readyPromise); |
933 EventTargetWithInlineData::trace(visitor); | 1018 EventTargetWithInlineData::trace(visitor); |
934 ActiveDOMObject::trace(visitor); | 1019 ActiveDOMObject::trace(visitor); |
935 } | 1020 } |
936 | 1021 |
937 } // namespace | 1022 } // namespace |
OLD | NEW |