Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: third_party/WebKit/Source/core/animation/Animation.cpp

Issue 2944423003: Implement new AnimationTimeline superclass (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/DocumentTimeline.h" 35 #include "core/animation/DocumentTimeline.h"
36 #include "core/animation/KeyframeEffectReadOnly.h" 36 #include "core/animation/KeyframeEffectReadOnly.h"
37 #include "core/animation/SuperAnimationTimeline.h"
37 #include "core/animation/css/CSSAnimations.h" 38 #include "core/animation/css/CSSAnimations.h"
38 #include "core/dom/DOMNodeIds.h" 39 #include "core/dom/DOMNodeIds.h"
39 #include "core/dom/Document.h" 40 #include "core/dom/Document.h"
40 #include "core/dom/ExceptionCode.h" 41 #include "core/dom/ExceptionCode.h"
41 #include "core/dom/ExecutionContext.h" 42 #include "core/dom/ExecutionContext.h"
42 #include "core/dom/StyleChangeReason.h" 43 #include "core/dom/StyleChangeReason.h"
43 #include "core/dom/TaskRunnerHelper.h" 44 #include "core/dom/TaskRunnerHelper.h"
44 #include "core/events/AnimationPlaybackEvent.h" 45 #include "core/events/AnimationPlaybackEvent.h"
45 #include "core/frame/UseCounter.h" 46 #include "core/frame/UseCounter.h"
46 #include "core/inspector/InspectorTraceEvents.h" 47 #include "core/inspector/InspectorTraceEvents.h"
(...skipping 14 matching lines...) Expand all
61 62
62 namespace { 63 namespace {
63 64
64 static unsigned NextSequenceNumber() { 65 static unsigned NextSequenceNumber() {
65 static unsigned next = 0; 66 static unsigned next = 0;
66 return ++next; 67 return ++next;
67 } 68 }
68 } 69 }
69 70
70 Animation* Animation::Create(AnimationEffectReadOnly* effect, 71 Animation* Animation::Create(AnimationEffectReadOnly* effect,
71 AnimationTimeline* timeline) { 72 SuperAnimationTimeline* timeline) {
72 if (!timeline) { 73 if (!timeline || !timeline->IsAnimationTimeline()) {
73 // FIXME: Support creating animations without a timeline. 74 // FIXME: Support creating animations without a timeline.
74 NOTREACHED(); 75 NOTREACHED();
75 return nullptr; 76 return nullptr;
76 } 77 }
77 78
79 AnimationTimeline* subtimeline = ToAnimationTimeline(timeline);
alancutter (OOO until 2018) 2017/06/21 05:36:17 Add TODO to remove the dependency on (future) Docu
80
78 Animation* animation = new Animation( 81 Animation* animation = new Animation(
79 timeline->GetDocument()->ContextDocument(), *timeline, effect); 82 subtimeline->GetDocument()->ContextDocument(), *subtimeline, effect);
80 83
81 if (timeline) { 84 if (subtimeline) {
82 timeline->AnimationAttached(*animation); 85 subtimeline->AnimationAttached(*animation);
83 animation->AttachCompositorTimeline(); 86 animation->AttachCompositorTimeline();
84 } 87 }
85 88
86 return animation; 89 return animation;
87 } 90 }
88 91
89 Animation* Animation::Create(ExecutionContext* execution_context, 92 Animation* Animation::Create(ExecutionContext* execution_context,
90 AnimationEffectReadOnly* effect, 93 AnimationEffectReadOnly* effect,
91 ExceptionState& exception_state) { 94 ExceptionState& exception_state) {
92 DCHECK(RuntimeEnabledFeatures::WebAnimationsAPIEnabled()); 95 DCHECK(RuntimeEnabledFeatures::WebAnimationsAPIEnabled());
93 96
94 Document* document = ToDocument(execution_context); 97 Document* document = ToDocument(execution_context);
95 return Create(effect, &document->Timeline()); 98 return Create(effect, &document->Timeline());
96 } 99 }
97 100
98 Animation* Animation::Create(ExecutionContext* execution_context, 101 Animation* Animation::Create(ExecutionContext* execution_context,
99 AnimationEffectReadOnly* effect, 102 AnimationEffectReadOnly* effect,
100 AnimationTimeline* timeline, 103 SuperAnimationTimeline* timeline,
101 ExceptionState& exception_state) { 104 ExceptionState& exception_state) {
102 DCHECK(RuntimeEnabledFeatures::WebAnimationsAPIEnabled()); 105 DCHECK(RuntimeEnabledFeatures::WebAnimationsAPIEnabled());
103 106
104 if (!timeline) { 107 if (!timeline) {
105 return Create(execution_context, effect, exception_state); 108 return Create(execution_context, effect, exception_state);
106 } 109 }
107 110
108 return Create(effect, timeline); 111 return Create(effect, timeline);
109 } 112 }
110 113
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 ->CanStartAnimationOnCompositor(playback_rate_); 765 ->CanStartAnimationOnCompositor(playback_rate_);
763 } 766 }
764 767
765 bool Animation::CanStartAnimationOnCompositorInternal( 768 bool Animation::CanStartAnimationOnCompositorInternal(
766 const Optional<CompositorElementIdSet>& composited_element_ids) const { 769 const Optional<CompositorElementIdSet>& composited_element_ids) const {
767 if (is_composited_animation_disabled_for_testing_ || EffectSuppressed()) 770 if (is_composited_animation_disabled_for_testing_ || EffectSuppressed())
768 return false; 771 return false;
769 772
770 // FIXME: Timeline playback rates should be compositable 773 // FIXME: Timeline playback rates should be compositable
771 if (playback_rate_ == 0 || (std::isinf(EffectEnd()) && playback_rate_ < 0) || 774 if (playback_rate_ == 0 || (std::isinf(EffectEnd()) && playback_rate_ < 0) ||
772 (timeline() && timeline()->PlaybackRate() != 1)) 775 (TimelineInternal() && TimelineInternal()->PlaybackRate() != 1))
773 return false; 776 return false;
774 777
775 if (!timeline_ || !content_ || !content_->IsKeyframeEffectReadOnly()) 778 if (!timeline_ || !content_ || !content_->IsKeyframeEffectReadOnly())
776 return false; 779 return false;
777 780
778 // If the optional element id set has no value we must be in SPv1 mode in 781 // If the optional element id set has no value we must be in SPv1 mode in
779 // which case we trust the compositing logic will create a layer if needed. 782 // which case we trust the compositing logic will create a layer if needed.
780 if (composited_element_ids.has_value()) { 783 if (composited_element_ids.has_value()) {
781 DCHECK(RuntimeEnabledFeatures::SlimmingPaintV2Enabled()); 784 DCHECK(RuntimeEnabledFeatures::SlimmingPaintV2Enabled());
782 Element* target_element = 785 Element* target_element =
(...skipping 21 matching lines...) Expand all
804 807
805 return true; 808 return true;
806 } 809 }
807 810
808 void Animation::StartAnimationOnCompositor( 811 void Animation::StartAnimationOnCompositor(
809 const Optional<CompositorElementIdSet>& composited_element_ids) { 812 const Optional<CompositorElementIdSet>& composited_element_ids) {
810 DCHECK(CanStartAnimationOnCompositor(composited_element_ids)); 813 DCHECK(CanStartAnimationOnCompositor(composited_element_ids));
811 814
812 bool reversed = playback_rate_ < 0; 815 bool reversed = playback_rate_ < 0;
813 816
814 double start_time = timeline()->ZeroTime() + StartTimeInternal(); 817 double start_time = TimelineInternal()->ZeroTime() + StartTimeInternal();
815 if (reversed) { 818 if (reversed) {
816 start_time -= EffectEnd() / fabs(playback_rate_); 819 start_time -= EffectEnd() / fabs(playback_rate_);
817 } 820 }
818 821
819 double time_offset = 0; 822 double time_offset = 0;
820 if (std::isnan(start_time)) { 823 if (std::isnan(start_time)) {
821 time_offset = 824 time_offset =
822 reversed ? EffectEnd() - CurrentTimeInternal() : CurrentTimeInternal(); 825 reversed ? EffectEnd() - CurrentTimeInternal() : CurrentTimeInternal();
823 time_offset = time_offset / fabs(playback_rate_); 826 time_offset = time_offset / fabs(playback_rate_);
824 } 827 }
(...skipping 12 matching lines...) Expand all
837 if (effect_changed && compositor_state_) { 840 if (effect_changed && compositor_state_) {
838 compositor_state_->effect_changed = true; 841 compositor_state_->effect_changed = true;
839 } 842 }
840 if (compositor_pending_ || is_paused_for_testing_) { 843 if (compositor_pending_ || is_paused_for_testing_) {
841 return; 844 return;
842 } 845 }
843 if (!compositor_state_ || compositor_state_->effect_changed || 846 if (!compositor_state_ || compositor_state_->effect_changed ||
844 compositor_state_->playback_rate != playback_rate_ || 847 compositor_state_->playback_rate != playback_rate_ ||
845 compositor_state_->start_time != start_time_) { 848 compositor_state_->start_time != start_time_) {
846 compositor_pending_ = true; 849 compositor_pending_ = true;
847 timeline()->GetDocument()->GetCompositorPendingAnimations().Add(this); 850 TimelineInternal()->GetDocument()->GetCompositorPendingAnimations().Add(
851 this);
848 } 852 }
849 } 853 }
850 854
851 void Animation::CancelAnimationOnCompositor() { 855 void Animation::CancelAnimationOnCompositor() {
852 if (HasActiveAnimationsOnCompositor()) 856 if (HasActiveAnimationsOnCompositor())
853 ToKeyframeEffectReadOnly(content_.Get())->CancelAnimationOnCompositor(); 857 ToKeyframeEffectReadOnly(content_.Get())->CancelAnimationOnCompositor();
854 858
855 DestroyCompositorPlayer(); 859 DestroyCompositorPlayer();
856 } 860 }
857 861
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 inherited_time = -1; 897 inherited_time = -1;
894 content_->UpdateInheritedTime(inherited_time, reason); 898 content_->UpdateInheritedTime(inherited_time, reason);
895 } 899 }
896 900
897 if ((idle || Limited()) && !finished_) { 901 if ((idle || Limited()) && !finished_) {
898 if (reason == kTimingUpdateForAnimationFrame && (idle || HasStartTime())) { 902 if (reason == kTimingUpdateForAnimationFrame && (idle || HasStartTime())) {
899 if (idle) { 903 if (idle) {
900 const AtomicString& event_type = EventTypeNames::cancel; 904 const AtomicString& event_type = EventTypeNames::cancel;
901 if (GetExecutionContext() && HasEventListeners(event_type)) { 905 if (GetExecutionContext() && HasEventListeners(event_type)) {
902 double event_current_time = NullValue(); 906 double event_current_time = NullValue();
903 pending_cancelled_event_ = AnimationPlaybackEvent::Create( 907 pending_cancelled_event_ =
904 event_type, event_current_time, timeline()->currentTime()); 908 AnimationPlaybackEvent::Create(event_type, event_current_time,
909 TimelineInternal()->currentTime());
905 pending_cancelled_event_->SetTarget(this); 910 pending_cancelled_event_->SetTarget(this);
906 pending_cancelled_event_->SetCurrentTarget(this); 911 pending_cancelled_event_->SetCurrentTarget(this);
907 timeline_->GetDocument()->EnqueueAnimationFrameEvent( 912 timeline_->GetDocument()->EnqueueAnimationFrameEvent(
908 pending_cancelled_event_); 913 pending_cancelled_event_);
909 } 914 }
910 } else { 915 } else {
911 const AtomicString& event_type = EventTypeNames::finish; 916 const AtomicString& event_type = EventTypeNames::finish;
912 if (GetExecutionContext() && HasEventListeners(event_type)) { 917 if (GetExecutionContext() && HasEventListeners(event_type)) {
913 double event_current_time = CurrentTimeInternal() * 1000; 918 double event_current_time = CurrentTimeInternal() * 1000;
914 pending_finished_event_ = AnimationPlaybackEvent::Create( 919 pending_finished_event_ =
915 event_type, event_current_time, timeline()->currentTime()); 920 AnimationPlaybackEvent::Create(event_type, event_current_time,
921 TimelineInternal()->currentTime());
916 pending_finished_event_->SetTarget(this); 922 pending_finished_event_->SetTarget(this);
917 pending_finished_event_->SetCurrentTarget(this); 923 pending_finished_event_->SetCurrentTarget(this);
918 timeline_->GetDocument()->EnqueueAnimationFrameEvent( 924 timeline_->GetDocument()->EnqueueAnimationFrameEvent(
919 pending_finished_event_); 925 pending_finished_event_);
920 } 926 }
921 } 927 }
922 finished_ = true; 928 finished_ = true;
923 } 929 }
924 } 930 }
925 DCHECK(!outdated_); 931 DCHECK(!outdated_);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 1023
1018 ToKeyframeEffectReadOnly(content_.Get())->AttachCompositedLayers(); 1024 ToKeyframeEffectReadOnly(content_.Get())->AttachCompositedLayers();
1019 } 1025 }
1020 1026
1021 void Animation::DetachCompositedLayers() { 1027 void Animation::DetachCompositedLayers() {
1022 if (compositor_player_ && compositor_player_->Player()->IsElementAttached()) 1028 if (compositor_player_ && compositor_player_->Player()->IsElementAttached())
1023 compositor_player_->Player()->DetachElement(); 1029 compositor_player_->Player()->DetachElement();
1024 } 1030 }
1025 1031
1026 void Animation::NotifyAnimationStarted(double monotonic_time, int group) { 1032 void Animation::NotifyAnimationStarted(double monotonic_time, int group) {
1027 timeline() 1033 TimelineInternal()
1028 ->GetDocument() 1034 ->GetDocument()
1029 ->GetCompositorPendingAnimations() 1035 ->GetCompositorPendingAnimations()
1030 .NotifyCompositorAnimationStarted(monotonic_time, group); 1036 .NotifyCompositorAnimationStarted(monotonic_time, group);
1031 } 1037 }
1032 1038
1033 Animation::PlayStateUpdateScope::PlayStateUpdateScope( 1039 Animation::PlayStateUpdateScope::PlayStateUpdateScope(
1034 Animation& animation, 1040 Animation& animation,
1035 TimingUpdateReason reason, 1041 TimingUpdateReason reason,
1036 CompositorPendingChange compositor_pending_change) 1042 CompositorPendingChange compositor_pending_change)
1037 : animation_(animation), 1043 : animation_(animation),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 break; 1127 break;
1122 case kDoNotSetCompositorPending: 1128 case kDoNotSetCompositorPending:
1123 break; 1129 break;
1124 default: 1130 default:
1125 NOTREACHED(); 1131 NOTREACHED();
1126 break; 1132 break;
1127 } 1133 }
1128 animation_->EndUpdatingState(); 1134 animation_->EndUpdatingState();
1129 1135
1130 if (old_play_state != new_play_state) { 1136 if (old_play_state != new_play_state) {
1131 probe::animationPlayStateChanged(animation_->timeline()->GetDocument(), 1137 probe::animationPlayStateChanged(
1132 animation_, old_play_state, 1138 animation_->TimelineInternal()->GetDocument(), animation_,
1133 new_play_state); 1139 old_play_state, new_play_state);
1134 } 1140 }
1135 } 1141 }
1136 1142
1137 void Animation::AddedEventListener( 1143 void Animation::AddedEventListener(
1138 const AtomicString& event_type, 1144 const AtomicString& event_type,
1139 RegisteredEventListener& registered_listener) { 1145 RegisteredEventListener& registered_listener) {
1140 EventTargetWithInlineData::AddedEventListener(event_type, 1146 EventTargetWithInlineData::AddedEventListener(event_type,
1141 registered_listener); 1147 registered_listener);
1142 if (event_type == EventTypeNames::finish) 1148 if (event_type == EventTypeNames::finish)
1143 UseCounter::Count(GetExecutionContext(), WebFeature::kAnimationFinishEvent); 1149 UseCounter::Count(GetExecutionContext(), WebFeature::kAnimationFinishEvent);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 DCHECK(!compositor_player_); 1240 DCHECK(!compositor_player_);
1235 } 1241 }
1236 1242
1237 void Animation::CompositorAnimationPlayerHolder::Detach() { 1243 void Animation::CompositorAnimationPlayerHolder::Detach() {
1238 DCHECK(compositor_player_); 1244 DCHECK(compositor_player_);
1239 compositor_player_->SetAnimationDelegate(nullptr); 1245 compositor_player_->SetAnimationDelegate(nullptr);
1240 animation_ = nullptr; 1246 animation_ = nullptr;
1241 compositor_player_.reset(); 1247 compositor_player_.reset();
1242 } 1248 }
1243 } // namespace blink 1249 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698