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

Side by Side Diff: Source/core/animation/AnimationPlayer.cpp

Issue 946323002: Animations: Introduce compositor AnimationPlayer and AnimationTimeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rename. Create cc::AnimationPlayer on PreCommit if needed. Created 5 years, 9 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 21 matching lines...) Expand all
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())
79 , m_holdTime(0) 84 , m_holdTime(0)
80 , m_sequenceNumber(nextSequenceNumber()) 85 , m_sequenceNumber(nextSequenceNumber())
81 , m_content(content) 86 , m_content(content)
82 , m_timeline(&timeline) 87 , m_timeline(&timeline)
83 , m_paused(false) 88 , m_paused(false)
84 , m_held(true) 89 , m_held(true)
85 , m_isPausedForTesting(false) 90 , m_isPausedForTesting(false)
86 , m_outdated(false) 91 , m_outdated(false)
87 , m_finished(true) 92 , m_finished(true)
88 , m_compositorState(nullptr) 93 , m_compositorState(nullptr)
89 , m_compositorPending(false) 94 , m_compositorPending(false)
90 , m_compositorGroup(0) 95 , m_compositorGroup(0)
96 , m_attachCompositedLayers(false)
91 , m_currentTimePending(false) 97 , m_currentTimePending(false)
92 , m_stateIsBeingUpdated(false) 98 , m_stateIsBeingUpdated(false)
93 { 99 {
94 if (m_content) { 100 if (m_content) {
95 if (m_content->player()) { 101 if (m_content->player()) {
96 m_content->player()->cancel(); 102 m_content->player()->cancel();
97 m_content->player()->setSource(0); 103 m_content->player()->setSource(0);
98 } 104 }
99 m_content->attach(this); 105 m_content->attach(this);
100 } 106 }
101 } 107 }
102 108
103 AnimationPlayer::~AnimationPlayer() 109 AnimationPlayer::~AnimationPlayer()
104 { 110 {
105 #if !ENABLE(OILPAN) 111 #if !ENABLE(OILPAN)
106 if (m_content) 112 if (m_content) {
113 detachCompositedLayers();
107 m_content->detach(); 114 m_content->detach();
115 }
108 if (m_timeline) 116 if (m_timeline)
109 m_timeline->playerDestroyed(this); 117 m_timeline->playerDestroyed(this);
110 #endif 118 #endif
119
120 destroyCompositorPlayer();
111 } 121 }
112 122
113 double AnimationPlayer::sourceEnd() const 123 double AnimationPlayer::sourceEnd() const
114 { 124 {
115 return m_content ? m_content->endTimeInternal() : 0; 125 return m_content ? m_content->endTimeInternal() : 0;
116 } 126 }
117 127
118 bool AnimationPlayer::limited(double currentTime) const 128 bool AnimationPlayer::limited(double currentTime) const
119 { 129 {
120 return (m_playbackRate < 0 && currentTime <= 0) || (m_playbackRate > 0 && cu rrentTime >= sourceEnd()); 130 return (m_playbackRate < 0 && currentTime <= 0) || (m_playbackRate > 0 && cu rrentTime >= sourceEnd());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 273
264 ASSERT(!m_compositorState || !std::isnan(m_compositorState->startTime)); 274 ASSERT(!m_compositorState || !std::isnan(m_compositorState->startTime));
265 275
266 if (!shouldStart) { 276 if (!shouldStart) {
267 m_currentTimePending = false; 277 m_currentTimePending = false;
268 } 278 }
269 279
270 if (shouldStart) { 280 if (shouldStart) {
271 m_compositorGroup = compositorGroup; 281 m_compositorGroup = compositorGroup;
272 if (startOnCompositor) { 282 if (startOnCompositor) {
283 if (isCandidateForAnimationOnCompositor()) {
loyso (OOO) 2015/03/24 06:30:15 Do we need to delete it on cancellation? I'm afrai
dstockwell 2015/03/26 03:04:39 I think we should. We can revisit if necessary. I
loyso (OOO) 2015/03/26 23:36:13 Acknowledged.
284 createCompositorPlayer();
285 attachCompositedLayers();
286 }
287
273 if (maybeStartAnimationOnCompositor()) 288 if (maybeStartAnimationOnCompositor())
274 m_compositorState = adoptPtr(new CompositorState(*this)); 289 m_compositorState = adoptPtr(new CompositorState(*this));
275 else 290 else
276 cancelIncompatibleAnimationsOnCompositor(); 291 cancelIncompatibleAnimationsOnCompositor();
277 } 292 }
278 } 293 }
279 } 294 }
280 295
281 void AnimationPlayer::postCommit(double timelineTime) 296 void AnimationPlayer::postCommit(double timelineTime)
282 { 297 {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 } 441 }
427 442
428 void AnimationPlayer::setSource(AnimationNode* newSource) 443 void AnimationPlayer::setSource(AnimationNode* newSource)
429 { 444 {
430 if (m_content == newSource) 445 if (m_content == newSource)
431 return; 446 return;
432 447
433 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorP endingWithSourceChanged); 448 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorP endingWithSourceChanged);
434 449
435 double storedCurrentTime = currentTimeInternal(); 450 double storedCurrentTime = currentTimeInternal();
436 if (m_content) 451 if (m_content) {
452 detachCompositedLayers();
437 m_content->detach(); 453 m_content->detach();
454 }
438 m_content = newSource; 455 m_content = newSource;
439 if (newSource) { 456 if (newSource) {
440 // FIXME: This logic needs to be updated once groups are implemented 457 // FIXME: This logic needs to be updated once groups are implemented
441 if (newSource->player()) { 458 if (newSource->player()) {
442 newSource->player()->cancel(); 459 newSource->player()->cancel();
443 newSource->player()->setSource(0); 460 newSource->player()->setSource(0);
444 } 461 }
445 newSource->attach(this); 462 newSource->attach(this);
463 attachCompositedLayers();
dstockwell 2015/03/26 03:04:39 Is this really the correct time to do this? Compos
loyso (OOO) 2015/03/26 23:36:14 If compositing information isn't ready, the m_atta
446 setOutdated(); 464 setOutdated();
447 } 465 }
448 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); 466 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand);
449 } 467 }
450 468
451 const char* AnimationPlayer::playStateString(AnimationPlayState playState) 469 const char* AnimationPlayer::playStateString(AnimationPlayState playState)
452 { 470 {
453 switch (playState) { 471 switch (playState) {
454 case Idle: 472 case Idle:
455 return "idle"; 473 return "idle";
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); 680 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand);
663 } 681 }
664 682
665 void AnimationPlayer::setOutdated() 683 void AnimationPlayer::setOutdated()
666 { 684 {
667 m_outdated = true; 685 m_outdated = true;
668 if (m_timeline) 686 if (m_timeline)
669 m_timeline->setOutdatedAnimationPlayer(this); 687 m_timeline->setOutdatedAnimationPlayer(this);
670 } 688 }
671 689
672 bool AnimationPlayer::canStartAnimationOnCompositor() 690 bool AnimationPlayer::canStartAnimationOnCompositor() const
673 { 691 {
674 // FIXME: Timeline playback rates should be compositable 692 // FIXME: Timeline playback rates should be compositable
675 if (m_playbackRate == 0 || (std::isinf(sourceEnd()) && m_playbackRate < 0) | | (timeline() && timeline()->playbackRate() != 1)) 693 if (m_playbackRate == 0 || (std::isinf(sourceEnd()) && m_playbackRate < 0) | | (timeline() && timeline()->playbackRate() != 1))
676 return false; 694 return false;
677 695
678 return m_timeline && m_content && m_content->isAnimation() && playing(); 696 return m_timeline && m_content && m_content->isAnimation() && playing();
679 } 697 }
680 698
699 bool AnimationPlayer::isCandidateForAnimationOnCompositor() const
700 {
701 if (!canStartAnimationOnCompositor())
702 return false;
703
704 return toAnimation(m_content.get())->isCandidateForAnimationOnCompositor(m_p laybackRate);
705 }
706
681 bool AnimationPlayer::maybeStartAnimationOnCompositor() 707 bool AnimationPlayer::maybeStartAnimationOnCompositor()
682 { 708 {
683 if (!canStartAnimationOnCompositor()) 709 if (!canStartAnimationOnCompositor())
684 return false; 710 return false;
685 711
686 bool reversed = m_playbackRate < 0; 712 bool reversed = m_playbackRate < 0;
687 713
688 double startTime = timeline()->zeroTime() + startTimeInternal(); 714 double startTime = timeline()->zeroTime() + startTimeInternal();
689 if (reversed) { 715 if (reversed) {
690 startTime -= sourceEnd() / fabs(m_playbackRate); 716 startTime -= sourceEnd() / fabs(m_playbackRate);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 ASSERT(!m_stateIsBeingUpdated); 849 ASSERT(!m_stateIsBeingUpdated);
824 m_stateIsBeingUpdated = true; 850 m_stateIsBeingUpdated = true;
825 } 851 }
826 852
827 void AnimationPlayer::endUpdatingState() 853 void AnimationPlayer::endUpdatingState()
828 { 854 {
829 ASSERT(m_stateIsBeingUpdated); 855 ASSERT(m_stateIsBeingUpdated);
830 m_stateIsBeingUpdated = false; 856 m_stateIsBeingUpdated = false;
831 } 857 }
832 858
859 void AnimationPlayer::createCompositorPlayer()
860 {
861 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && !m_comp ositorPlayer && Platform::current()->compositorSupport()) {
862 m_compositorPlayer = adoptPtr(Platform::current()->compositorSupport()-> createAnimationPlayer());
863 ASSERT(m_compositorPlayer);
864 m_compositorPlayer->setAnimationDelegate(this);
865 attachCompositorTimeline();
866 }
867 }
868
869 void AnimationPlayer::destroyCompositorPlayer()
870 {
871 if (m_compositorPlayer) {
872 detachCompositorTimeline();
873 m_compositorPlayer->setAnimationDelegate(nullptr);
874 }
875 m_compositorPlayer.clear();
876 }
877
878 void AnimationPlayer::attachCompositorTimeline()
879 {
880 if (m_compositorPlayer) {
881 WebCompositorAnimationTimeline* timeline = m_timeline ? m_timeline->comp ositorTimeline() : nullptr;
882 if (timeline)
883 timeline->playerAttached(*this);
884 }
885 }
886
887 void AnimationPlayer::detachCompositorTimeline()
888 {
889 if (m_compositorPlayer) {
890 WebCompositorAnimationTimeline* timeline = m_timeline ? m_timeline->comp ositorTimeline() : nullptr;
891 if (timeline)
892 timeline->playerDestroyed(*this);
893 }
894 }
895
896 void AnimationPlayer::attachCompositedLayers()
897 {
898 m_attachCompositedLayers = true;
dstockwell 2015/03/26 03:04:39 m_compositedLayersAttached
loyso (OOO) 2015/03/26 23:36:14 It's a command, or 'dirty' flag. Not a sign that e
dstockwell 2015/03/27 00:27:22 It seems wrong that this method is called attachCo
loyso (OOO) 2015/03/30 02:47:19 UPDATE: Simplified it so not applicable.
899 updateCompositedLayersAttachment();
dstockwell 2015/03/27 00:27:22 So, why do we need to attempt do the attachment at
loyso (OOO) 2015/03/27 01:02:42 Preface: we had to attach the layer too early in a
900 }
901
902 void AnimationPlayer::detachCompositedLayers()
903 {
904 m_attachCompositedLayers = false;
905 if (m_compositorPlayer && m_compositorPlayer->isLayerAttached())
906 m_compositorPlayer->detachLayer();
907 }
908
909 void AnimationPlayer::updateCompositedLayersAttachment()
910 {
911 if (!RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() || !m_att achCompositedLayers)
912 return;
913 if (!m_compositorPlayer || !m_content || !m_content->isAnimation() || !toAni mation(m_content.get())->canAttachCompositedLayers())
914 return;
915
916 m_attachCompositedLayers = false;
917 toAnimation(m_content.get())->attachCompositedLayers();
918 }
919
920 void AnimationPlayer::notifyAnimationStarted(double monotonicTime, int group)
921 {
922 ASSERT(RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled());
923 timeline()->document()->compositorPendingAnimations().notifyCompositorAnimat ionStarted(monotonicTime, group);
924 }
925
833 AnimationPlayer::PlayStateUpdateScope::PlayStateUpdateScope(AnimationPlayer& pla yer, TimingUpdateReason reason, CompositorPendingChange compositorPendingChange) 926 AnimationPlayer::PlayStateUpdateScope::PlayStateUpdateScope(AnimationPlayer& pla yer, TimingUpdateReason reason, CompositorPendingChange compositorPendingChange)
834 : m_player(player) 927 : m_player(player)
835 , m_initialPlayState(m_player->playStateInternal()) 928 , m_initialPlayState(m_player->playStateInternal())
836 , m_compositorPendingChange(compositorPendingChange) 929 , m_compositorPendingChange(compositorPendingChange)
837 { 930 {
838 m_player->beginUpdatingState(); 931 m_player->beginUpdatingState();
839 m_player->updateCurrentTimingState(reason); 932 m_player->updateCurrentTimingState(reason);
840 } 933 }
841 934
842 AnimationPlayer::PlayStateUpdateScope::~PlayStateUpdateScope() 935 AnimationPlayer::PlayStateUpdateScope::~PlayStateUpdateScope()
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 visitor->trace(m_content); 1029 visitor->trace(m_content);
937 visitor->trace(m_timeline); 1030 visitor->trace(m_timeline);
938 visitor->trace(m_pendingFinishedEvent); 1031 visitor->trace(m_pendingFinishedEvent);
939 visitor->trace(m_finishedPromise); 1032 visitor->trace(m_finishedPromise);
940 visitor->trace(m_readyPromise); 1033 visitor->trace(m_readyPromise);
941 EventTargetWithInlineData::trace(visitor); 1034 EventTargetWithInlineData::trace(visitor);
942 ActiveDOMObject::trace(visitor); 1035 ActiveDOMObject::trace(visitor);
943 } 1036 }
944 1037
945 } // namespace 1038 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698