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

Side by Side Diff: sky/engine/core/animation/AnimationPlayer.cpp

Issue 772673002: Fix Animations, Remove Compostior Animations. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: cleanup Created 6 years 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 , m_startTime(nullValue()) 63 , m_startTime(nullValue())
64 , m_holdTime(0) 64 , m_holdTime(0)
65 , m_sequenceNumber(nextSequenceNumber()) 65 , m_sequenceNumber(nextSequenceNumber())
66 , m_content(content) 66 , m_content(content)
67 , m_timeline(&timeline) 67 , m_timeline(&timeline)
68 , m_paused(false) 68 , m_paused(false)
69 , m_held(true) 69 , m_held(true)
70 , m_isPausedForTesting(false) 70 , m_isPausedForTesting(false)
71 , m_outdated(true) 71 , m_outdated(true)
72 , m_finished(false) 72 , m_finished(false)
73 , m_compositorState(nullptr)
74 , m_compositorPending(true) 73 , m_compositorPending(true)
75 , m_currentTimePending(false) 74 , m_currentTimePending(false)
76 { 75 {
77 if (m_content) { 76 if (m_content) {
78 if (m_content->player()) 77 if (m_content->player())
79 m_content->player()->cancel(); 78 m_content->player()->cancel();
80 m_content->attach(this); 79 m_content->attach(this);
81 } 80 }
82 } 81 }
83 82
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 double AnimationPlayer::currentTimeInternal() 155 double AnimationPlayer::currentTimeInternal()
157 { 156 {
158 updateCurrentTimingState(TimingUpdateOnDemand); 157 updateCurrentTimingState(TimingUpdateOnDemand);
159 if (m_held) 158 if (m_held)
160 return m_holdTime; 159 return m_holdTime;
161 return calculateCurrentTime(); 160 return calculateCurrentTime();
162 } 161 }
163 162
164 void AnimationPlayer::preCommit(bool startOnCompositor) 163 void AnimationPlayer::preCommit(bool startOnCompositor)
165 { 164 {
166 if (m_compositorState && m_compositorState->pendingAction == Start) { 165 if (!playing()) {
167 // Still waiting for a start time.
168 return;
169 }
170
171 bool softChange = m_compositorState && (paused() || m_compositorState->playb ackRate != m_playbackRate);
172 bool hardChange = m_compositorState && (m_compositorState->sourceChanged || (m_compositorState->startTime != m_startTime && !std::isnan(m_compositorState->s tartTime) && !std::isnan(m_startTime)));
173
174 // FIXME: softChange && !hardChange should generate a Pause/ThenStart,
175 // not a Cancel, but we can't communicate these to the compositor yet.
176
177 bool changed = softChange || hardChange;
178 bool shouldCancel = (!playing() && m_compositorState) || changed;
179 bool shouldStart = playing() && (!m_compositorState || changed);
180
181 if (shouldCancel) {
182 cancelAnimationOnCompositor();
183 m_compositorState = nullptr;
184
185 }
186
187 if (!shouldStart) {
188 m_currentTimePending = false; 166 m_currentTimePending = false;
189 } 167 }
190
191 if (shouldStart && startOnCompositor && maybeStartAnimationOnCompositor()) {
192 m_compositorState = adoptPtr(new CompositorState(*this));
193 }
194 } 168 }
195 169
196 void AnimationPlayer::postCommit(double timelineTime) 170 void AnimationPlayer::postCommit(double timelineTime)
197 { 171 {
198 m_compositorPending = false; 172 m_compositorPending = false;
199
200 if (!m_compositorState || m_compositorState->pendingAction == None)
201 return;
202
203 switch (m_compositorState->pendingAction) {
204 case Start:
205 if (!std::isnan(m_compositorState->startTime)) {
206 ASSERT(m_startTime == m_compositorState->startTime);
207 m_compositorState->pendingAction = None;
208 }
209 break;
210 case Pause:
211 case PauseThenStart:
212 ASSERT(std::isnan(m_startTime));
213 m_compositorState->pendingAction = None;
214 setCurrentTimeInternal((timelineTime - m_compositorState->startTime) * m _playbackRate, TimingUpdateForAnimationFrame);
215 m_currentTimePending = false;
216 break;
217 default:
218 ASSERT_NOT_REACHED();
219 }
220 } 173 }
221 174
222 void AnimationPlayer::notifyCompositorStartTime(double timelineTime) 175 void AnimationPlayer::notifyCompositorStartTime(double timelineTime)
223 { 176 {
224 if (m_compositorState) {
225 ASSERT(m_compositorState->pendingAction == Start);
226 ASSERT(std::isnan(m_compositorState->startTime));
227
228 double initialCompositorHoldTime = m_compositorState->holdTime;
229 m_compositorState->pendingAction = None;
230 m_compositorState->startTime = timelineTime;
231
232 if (paused() || m_compositorState->playbackRate != m_playbackRate || m_c ompositorState->sourceChanged) {
233 // Paused state, playback rate, or source changed while starting.
234 setCompositorPending();
235 }
236
237 if (m_startTime == timelineTime) {
238 // The start time was set to the incoming compositor start time.
239 // Unlikely, but possible.
240 // FIXME: Depending on what changed above this might still be pendin g.
241 // Maybe...
242 m_currentTimePending = false;
243 return;
244 }
245
246 if (!std::isnan(m_startTime) || currentTimeInternal() != initialComposit orHoldTime) {
247 // A new start time or current time was set while starting.
248 setCompositorPending();
249 return;
250 }
251 }
252
253 if (playing()) { 177 if (playing()) {
254 ASSERT(std::isnan(m_startTime)); 178 ASSERT(std::isnan(m_startTime));
255 ASSERT(m_held); 179 ASSERT(m_held);
256 180
257 if (m_playbackRate == 0) { 181 if (m_playbackRate == 0) {
258 setStartTimeInternal(timelineTime); 182 setStartTimeInternal(timelineTime);
259 } else { 183 } else {
260 setStartTimeInternal(timelineTime + currentTimeInternal() / -m_playb ackRate); 184 setStartTimeInternal(timelineTime + currentTimeInternal() / -m_playb ackRate);
261 } 185 }
262 186
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); 452 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand);
529 } 453 }
530 454
531 void AnimationPlayer::setOutdated() 455 void AnimationPlayer::setOutdated()
532 { 456 {
533 m_outdated = true; 457 m_outdated = true;
534 if (m_timeline) 458 if (m_timeline)
535 m_timeline->setOutdatedAnimationPlayer(this); 459 m_timeline->setOutdatedAnimationPlayer(this);
536 } 460 }
537 461
538 bool AnimationPlayer::canStartAnimationOnCompositor()
539 {
540 // FIXME: Need compositor support for playback rate != 1.
541 if (playbackRate() != 1)
542 return false;
543
544 return m_timeline && m_content && m_content->isAnimation() && playing();
545 }
546
547 bool AnimationPlayer::maybeStartAnimationOnCompositor()
548 {
549 if (!canStartAnimationOnCompositor())
550 return false;
551
552 double startTime = timeline()->zeroTime() + startTimeInternal();
553 double timeOffset = 0;
554 if (std::isnan(startTime)) {
555 timeOffset = currentTimeInternal();
556 }
557 return toAnimation(m_content.get())->maybeStartAnimationOnCompositor(startTi me, timeOffset);
558 }
559
560 void AnimationPlayer::setCompositorPending(bool sourceChanged) 462 void AnimationPlayer::setCompositorPending(bool sourceChanged)
561 { 463 {
562 // FIXME: Animation could notify this directly?
563 if (!hasActiveAnimationsOnCompositor()) {
564 m_compositorState.release();
565 }
566 if (!m_compositorPending) { 464 if (!m_compositorPending) {
567 m_compositorPending = true; 465 m_compositorPending = true;
568 if (sourceChanged && m_compositorState)
569 m_compositorState->sourceChanged = true;
570 timeline()->document()->compositorPendingAnimations().add(this); 466 timeline()->document()->compositorPendingAnimations().add(this);
571 } 467 }
572 } 468 }
573 469
574 bool AnimationPlayer::hasActiveAnimationsOnCompositor()
575 {
576 if (!m_content || !m_content->isAnimation())
577 return false;
578
579 return toAnimation(m_content.get())->hasActiveAnimationsOnCompositor();
580 }
581
582 void AnimationPlayer::cancelAnimationOnCompositor()
583 {
584 if (hasActiveAnimationsOnCompositor())
585 toAnimation(m_content.get())->cancelAnimationOnCompositor();
586 }
587
588 bool AnimationPlayer::update(TimingUpdateReason reason) 470 bool AnimationPlayer::update(TimingUpdateReason reason)
589 { 471 {
590 if (!m_timeline) 472 if (!m_timeline)
591 return false; 473 return false;
592 474
593 updateCurrentTimingState(reason); 475 updateCurrentTimingState(reason);
594 m_outdated = false; 476 m_outdated = false;
595 477
596 if (m_content) { 478 if (m_content) {
597 double inheritedTime = isNull(m_timeline->currentTimeInternal()) ? nullV alue() : currentTimeInternal(); 479 double inheritedTime = isNull(m_timeline->currentTimeInternal()) ? nullV alue() : currentTimeInternal();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef(); 519 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef();
638 } 520 }
639 521
640 bool AnimationPlayer::addEventListener(const AtomicString& eventType, PassRefPtr <EventListener> listener, bool useCapture) 522 bool AnimationPlayer::addEventListener(const AtomicString& eventType, PassRefPtr <EventListener> listener, bool useCapture)
641 { 523 {
642 if (eventType == EventTypeNames::finish) 524 if (eventType == EventTypeNames::finish)
643 UseCounter::count(executionContext(), UseCounter::AnimationPlayerFinishE vent); 525 UseCounter::count(executionContext(), UseCounter::AnimationPlayerFinishE vent);
644 return EventTargetWithInlineData::addEventListener(eventType, listener, useC apture); 526 return EventTargetWithInlineData::addEventListener(eventType, listener, useC apture);
645 } 527 }
646 528
647 void AnimationPlayer::pauseForTesting(double pauseTime)
648 {
649 RELEASE_ASSERT(!paused());
650 setCurrentTimeInternal(pauseTime, TimingUpdateOnDemand);
651 if (hasActiveAnimationsOnCompositor())
652 toAnimation(m_content.get())->pauseAnimationForTestingOnCompositor(curre ntTimeInternal());
653 m_isPausedForTesting = true;
654 pause();
655 }
656
657 } // namespace 529 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698