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/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 Loading... |
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); |
| 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 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 "Animation is not playing"); | 786 "Animation is not playing"); |
784 } | 787 } |
785 | 788 |
786 if (std::isinf(EffectEnd()) && playback_rate_ < 0) { | 789 if (std::isinf(EffectEnd()) && playback_rate_ < 0) { |
787 return CompositorAnimations::FailureCode::Actionable( | 790 return CompositorAnimations::FailureCode::Actionable( |
788 "Accelerated animations do not support reversed infinite duration " | 791 "Accelerated animations do not support reversed infinite duration " |
789 "animations"); | 792 "animations"); |
790 } | 793 } |
791 | 794 |
792 // FIXME: Timeline playback rates should be compositable | 795 // FIXME: Timeline playback rates should be compositable |
793 if (timeline() && timeline()->PlaybackRate() != 1) { | 796 if (TimelineInternal() && TimelineInternal()->PlaybackRate() != 1) { |
794 return CompositorAnimations::FailureCode::NonActionable( | 797 return CompositorAnimations::FailureCode::NonActionable( |
795 "Accelerated animations do not support timelines with playback rates " | 798 "Accelerated animations do not support timelines with playback rates " |
796 "other than 1"); | 799 "other than 1"); |
797 } | 800 } |
798 | 801 |
799 if (!timeline_) { | 802 if (!timeline_) { |
800 return CompositorAnimations::FailureCode::Actionable( | 803 return CompositorAnimations::FailureCode::Actionable( |
801 "Animation is not attached to a timeline"); | 804 "Animation is not attached to a timeline"); |
802 } | 805 } |
803 if (!content_) { | 806 if (!content_) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 | 848 |
846 return CompositorAnimations::FailureCode::None(); | 849 return CompositorAnimations::FailureCode::None(); |
847 } | 850 } |
848 | 851 |
849 void Animation::StartAnimationOnCompositor( | 852 void Animation::StartAnimationOnCompositor( |
850 const Optional<CompositorElementIdSet>& composited_element_ids) { | 853 const Optional<CompositorElementIdSet>& composited_element_ids) { |
851 DCHECK(CheckCanStartAnimationOnCompositor(composited_element_ids).Ok()); | 854 DCHECK(CheckCanStartAnimationOnCompositor(composited_element_ids).Ok()); |
852 | 855 |
853 bool reversed = playback_rate_ < 0; | 856 bool reversed = playback_rate_ < 0; |
854 | 857 |
855 double start_time = timeline()->ZeroTime() + StartTimeInternal(); | 858 double start_time = TimelineInternal()->ZeroTime() + StartTimeInternal(); |
856 if (reversed) { | 859 if (reversed) { |
857 start_time -= EffectEnd() / fabs(playback_rate_); | 860 start_time -= EffectEnd() / fabs(playback_rate_); |
858 } | 861 } |
859 | 862 |
860 double time_offset = 0; | 863 double time_offset = 0; |
861 if (std::isnan(start_time)) { | 864 if (std::isnan(start_time)) { |
862 time_offset = | 865 time_offset = |
863 reversed ? EffectEnd() - CurrentTimeInternal() : CurrentTimeInternal(); | 866 reversed ? EffectEnd() - CurrentTimeInternal() : CurrentTimeInternal(); |
864 time_offset = time_offset / fabs(playback_rate_); | 867 time_offset = time_offset / fabs(playback_rate_); |
865 } | 868 } |
(...skipping 12 matching lines...) Expand all Loading... |
878 if (effect_changed && compositor_state_) { | 881 if (effect_changed && compositor_state_) { |
879 compositor_state_->effect_changed = true; | 882 compositor_state_->effect_changed = true; |
880 } | 883 } |
881 if (compositor_pending_ || is_paused_for_testing_) { | 884 if (compositor_pending_ || is_paused_for_testing_) { |
882 return; | 885 return; |
883 } | 886 } |
884 if (!compositor_state_ || compositor_state_->effect_changed || | 887 if (!compositor_state_ || compositor_state_->effect_changed || |
885 compositor_state_->playback_rate != playback_rate_ || | 888 compositor_state_->playback_rate != playback_rate_ || |
886 compositor_state_->start_time != start_time_) { | 889 compositor_state_->start_time != start_time_) { |
887 compositor_pending_ = true; | 890 compositor_pending_ = true; |
888 timeline()->GetDocument()->GetCompositorPendingAnimations().Add(this); | 891 TimelineInternal()->GetDocument()->GetCompositorPendingAnimations().Add( |
| 892 this); |
889 } | 893 } |
890 } | 894 } |
891 | 895 |
892 void Animation::CancelAnimationOnCompositor() { | 896 void Animation::CancelAnimationOnCompositor() { |
893 if (HasActiveAnimationsOnCompositor()) | 897 if (HasActiveAnimationsOnCompositor()) |
894 ToKeyframeEffectReadOnly(content_.Get())->CancelAnimationOnCompositor(); | 898 ToKeyframeEffectReadOnly(content_.Get())->CancelAnimationOnCompositor(); |
895 | 899 |
896 DestroyCompositorPlayer(); | 900 DestroyCompositorPlayer(); |
897 } | 901 } |
898 | 902 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 inherited_time = -1; | 938 inherited_time = -1; |
935 content_->UpdateInheritedTime(inherited_time, reason); | 939 content_->UpdateInheritedTime(inherited_time, reason); |
936 } | 940 } |
937 | 941 |
938 if ((idle || Limited()) && !finished_) { | 942 if ((idle || Limited()) && !finished_) { |
939 if (reason == kTimingUpdateForAnimationFrame && (idle || HasStartTime())) { | 943 if (reason == kTimingUpdateForAnimationFrame && (idle || HasStartTime())) { |
940 if (idle) { | 944 if (idle) { |
941 const AtomicString& event_type = EventTypeNames::cancel; | 945 const AtomicString& event_type = EventTypeNames::cancel; |
942 if (GetExecutionContext() && HasEventListeners(event_type)) { | 946 if (GetExecutionContext() && HasEventListeners(event_type)) { |
943 double event_current_time = NullValue(); | 947 double event_current_time = NullValue(); |
944 pending_cancelled_event_ = AnimationPlaybackEvent::Create( | 948 pending_cancelled_event_ = |
945 event_type, event_current_time, timeline()->currentTime()); | 949 AnimationPlaybackEvent::Create(event_type, event_current_time, |
| 950 TimelineInternal()->currentTime()); |
946 pending_cancelled_event_->SetTarget(this); | 951 pending_cancelled_event_->SetTarget(this); |
947 pending_cancelled_event_->SetCurrentTarget(this); | 952 pending_cancelled_event_->SetCurrentTarget(this); |
948 timeline_->GetDocument()->EnqueueAnimationFrameEvent( | 953 timeline_->GetDocument()->EnqueueAnimationFrameEvent( |
949 pending_cancelled_event_); | 954 pending_cancelled_event_); |
950 } | 955 } |
951 } else { | 956 } else { |
952 const AtomicString& event_type = EventTypeNames::finish; | 957 const AtomicString& event_type = EventTypeNames::finish; |
953 if (GetExecutionContext() && HasEventListeners(event_type)) { | 958 if (GetExecutionContext() && HasEventListeners(event_type)) { |
954 double event_current_time = CurrentTimeInternal() * 1000; | 959 double event_current_time = CurrentTimeInternal() * 1000; |
955 pending_finished_event_ = AnimationPlaybackEvent::Create( | 960 pending_finished_event_ = |
956 event_type, event_current_time, timeline()->currentTime()); | 961 AnimationPlaybackEvent::Create(event_type, event_current_time, |
| 962 TimelineInternal()->currentTime()); |
957 pending_finished_event_->SetTarget(this); | 963 pending_finished_event_->SetTarget(this); |
958 pending_finished_event_->SetCurrentTarget(this); | 964 pending_finished_event_->SetCurrentTarget(this); |
959 timeline_->GetDocument()->EnqueueAnimationFrameEvent( | 965 timeline_->GetDocument()->EnqueueAnimationFrameEvent( |
960 pending_finished_event_); | 966 pending_finished_event_); |
961 } | 967 } |
962 } | 968 } |
963 finished_ = true; | 969 finished_ = true; |
964 } | 970 } |
965 } | 971 } |
966 DCHECK(!outdated_); | 972 DCHECK(!outdated_); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 | 1064 |
1059 ToKeyframeEffectReadOnly(content_.Get())->AttachCompositedLayers(); | 1065 ToKeyframeEffectReadOnly(content_.Get())->AttachCompositedLayers(); |
1060 } | 1066 } |
1061 | 1067 |
1062 void Animation::DetachCompositedLayers() { | 1068 void Animation::DetachCompositedLayers() { |
1063 if (compositor_player_ && compositor_player_->Player()->IsElementAttached()) | 1069 if (compositor_player_ && compositor_player_->Player()->IsElementAttached()) |
1064 compositor_player_->Player()->DetachElement(); | 1070 compositor_player_->Player()->DetachElement(); |
1065 } | 1071 } |
1066 | 1072 |
1067 void Animation::NotifyAnimationStarted(double monotonic_time, int group) { | 1073 void Animation::NotifyAnimationStarted(double monotonic_time, int group) { |
1068 timeline() | 1074 TimelineInternal() |
1069 ->GetDocument() | 1075 ->GetDocument() |
1070 ->GetCompositorPendingAnimations() | 1076 ->GetCompositorPendingAnimations() |
1071 .NotifyCompositorAnimationStarted(monotonic_time, group); | 1077 .NotifyCompositorAnimationStarted(monotonic_time, group); |
1072 } | 1078 } |
1073 | 1079 |
1074 Animation::PlayStateUpdateScope::PlayStateUpdateScope( | 1080 Animation::PlayStateUpdateScope::PlayStateUpdateScope( |
1075 Animation& animation, | 1081 Animation& animation, |
1076 TimingUpdateReason reason, | 1082 TimingUpdateReason reason, |
1077 CompositorPendingChange compositor_pending_change) | 1083 CompositorPendingChange compositor_pending_change) |
1078 : animation_(animation), | 1084 : animation_(animation), |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 break; | 1168 break; |
1163 case kDoNotSetCompositorPending: | 1169 case kDoNotSetCompositorPending: |
1164 break; | 1170 break; |
1165 default: | 1171 default: |
1166 NOTREACHED(); | 1172 NOTREACHED(); |
1167 break; | 1173 break; |
1168 } | 1174 } |
1169 animation_->EndUpdatingState(); | 1175 animation_->EndUpdatingState(); |
1170 | 1176 |
1171 if (old_play_state != new_play_state) { | 1177 if (old_play_state != new_play_state) { |
1172 probe::animationPlayStateChanged(animation_->timeline()->GetDocument(), | 1178 probe::animationPlayStateChanged( |
1173 animation_, old_play_state, | 1179 animation_->TimelineInternal()->GetDocument(), animation_, |
1174 new_play_state); | 1180 old_play_state, new_play_state); |
1175 } | 1181 } |
1176 } | 1182 } |
1177 | 1183 |
1178 void Animation::AddedEventListener( | 1184 void Animation::AddedEventListener( |
1179 const AtomicString& event_type, | 1185 const AtomicString& event_type, |
1180 RegisteredEventListener& registered_listener) { | 1186 RegisteredEventListener& registered_listener) { |
1181 EventTargetWithInlineData::AddedEventListener(event_type, | 1187 EventTargetWithInlineData::AddedEventListener(event_type, |
1182 registered_listener); | 1188 registered_listener); |
1183 if (event_type == EventTypeNames::finish) | 1189 if (event_type == EventTypeNames::finish) |
1184 UseCounter::Count(GetExecutionContext(), WebFeature::kAnimationFinishEvent); | 1190 UseCounter::Count(GetExecutionContext(), WebFeature::kAnimationFinishEvent); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 DCHECK(!compositor_player_); | 1281 DCHECK(!compositor_player_); |
1276 } | 1282 } |
1277 | 1283 |
1278 void Animation::CompositorAnimationPlayerHolder::Detach() { | 1284 void Animation::CompositorAnimationPlayerHolder::Detach() { |
1279 DCHECK(compositor_player_); | 1285 DCHECK(compositor_player_); |
1280 compositor_player_->SetAnimationDelegate(nullptr); | 1286 compositor_player_->SetAnimationDelegate(nullptr); |
1281 animation_ = nullptr; | 1287 animation_ = nullptr; |
1282 compositor_player_.reset(); | 1288 compositor_player_.reset(); |
1283 } | 1289 } |
1284 } // namespace blink | 1290 } // namespace blink |
OLD | NEW |