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

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

Issue 881183003: Animation: Cancel same-property animations on compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add manual test. Improve code a bit. Created 5 years, 10 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
« no previous file with comments | « Source/core/animation/AnimationPlayer.h ('k') | Source/core/animation/CompositorAnimations.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 cancelAnimationOnCompositor(); 239 cancelAnimationOnCompositor();
240 m_compositorState = nullptr; 240 m_compositorState = nullptr;
241 } 241 }
242 242
243 if (!shouldStart) { 243 if (!shouldStart) {
244 m_currentTimePending = false; 244 m_currentTimePending = false;
245 } 245 }
246 246
247 if (shouldStart) { 247 if (shouldStart) {
248 m_compositorGroup = compositorGroup; 248 m_compositorGroup = compositorGroup;
249 if (startOnCompositor && maybeStartAnimationOnCompositor()) { 249 if (startOnCompositor) {
250 m_compositorState = adoptPtr(new CompositorState(*this)); 250 if (maybeStartAnimationOnCompositor())
251 m_compositorState = adoptPtr(new CompositorState(*this));
252 else
253 cancelIncompatibleAnimationsOnCompositor();
251 } 254 }
252 } 255 }
253 } 256 }
254 257
255 void AnimationPlayer::postCommit(double timelineTime) 258 void AnimationPlayer::postCommit(double timelineTime)
256 { 259 {
257 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, DoNotSetCompos itorPending); 260 PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, DoNotSetCompos itorPending);
258 261
259 m_compositorPending = false; 262 m_compositorPending = false;
260 263
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 327 }
325 328
326 // FIXME: This avoids marking this player as outdated needlessly when a start time 329 // FIXME: This avoids marking this player as outdated needlessly when a start time
327 // is notified, but we should refactor how outdating works to avoid this . 330 // is notified, but we should refactor how outdating works to avoid this .
328 m_outdated = false; 331 m_outdated = false;
329 332
330 m_currentTimePending = false; 333 m_currentTimePending = false;
331 } 334 }
332 } 335 }
333 336
337 bool AnimationPlayer::affects(const Element& element, CSSPropertyID property) co nst
338 {
339 if (!m_content || !m_content->isAnimation())
340 return false;
341
342 const Animation* animation = toAnimation(m_content.get());
343 return (animation->target() == &element) && animation->affects(property);
344 }
345
334 double AnimationPlayer::calculateStartTime(double currentTime) const 346 double AnimationPlayer::calculateStartTime(double currentTime) const
335 { 347 {
336 return m_timeline->effectiveTime() - currentTime / m_playbackRate; 348 return m_timeline->effectiveTime() - currentTime / m_playbackRate;
337 } 349 }
338 350
339 double AnimationPlayer::calculateCurrentTime() const 351 double AnimationPlayer::calculateCurrentTime() const
340 { 352 {
341 ASSERT(!m_held); 353 ASSERT(!m_held);
342 if (isNull(m_startTime) || !m_timeline) 354 if (isNull(m_startTime) || !m_timeline)
343 return 0; 355 return 0;
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 } 695 }
684 696
685 if (sourceChanged || !m_compositorState 697 if (sourceChanged || !m_compositorState
686 || !playing() || m_compositorState->playbackRate != m_playbackRate 698 || !playing() || m_compositorState->playbackRate != m_playbackRate
687 || m_compositorState->startTime != m_startTime) { 699 || m_compositorState->startTime != m_startTime) {
688 m_compositorPending = true; 700 m_compositorPending = true;
689 timeline()->document()->compositorPendingAnimations().add(this); 701 timeline()->document()->compositorPendingAnimations().add(this);
690 } 702 }
691 } 703 }
692 704
705 void AnimationPlayer::cancelAnimationOnCompositor()
706 {
707 if (hasActiveAnimationsOnCompositor())
708 toAnimation(m_content.get())->cancelAnimationOnCompositor();
709 }
710
711 void AnimationPlayer::cancelIncompatibleAnimationsOnCompositor()
712 {
713 if (m_content && m_content->isAnimation())
714 toAnimation(m_content.get())->cancelIncompatibleAnimationsOnCompositor() ;
715 }
716
693 bool AnimationPlayer::hasActiveAnimationsOnCompositor() 717 bool AnimationPlayer::hasActiveAnimationsOnCompositor()
694 { 718 {
695 if (!m_content || !m_content->isAnimation()) 719 if (!m_content || !m_content->isAnimation())
696 return false; 720 return false;
697 721
698 return toAnimation(m_content.get())->hasActiveAnimationsOnCompositor(); 722 return toAnimation(m_content.get())->hasActiveAnimationsOnCompositor();
699 } 723 }
700 724
701 void AnimationPlayer::cancelAnimationOnCompositor()
702 {
703 if (hasActiveAnimationsOnCompositor())
704 toAnimation(m_content.get())->cancelAnimationOnCompositor();
705 }
706
707 bool AnimationPlayer::update(TimingUpdateReason reason) 725 bool AnimationPlayer::update(TimingUpdateReason reason)
708 { 726 {
709 if (!m_timeline) 727 if (!m_timeline)
710 return false; 728 return false;
711 729
712 PlayStateUpdateScope updateScope(*this, reason, DoNotSetCompositorPending); 730 PlayStateUpdateScope updateScope(*this, reason, DoNotSetCompositorPending);
713 731
714 m_outdated = false; 732 m_outdated = false;
715 bool idle = playStateInternal() == Idle; 733 bool idle = playStateInternal() == Idle;
716 734
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 817
800 AnimationPlayer::PlayStateUpdateScope::~PlayStateUpdateScope() 818 AnimationPlayer::PlayStateUpdateScope::~PlayStateUpdateScope()
801 { 819 {
802 AnimationPlayState oldPlayState = m_initialPlayState; 820 AnimationPlayState oldPlayState = m_initialPlayState;
803 AnimationPlayState newPlayState = m_player->calculatePlayState(); 821 AnimationPlayState newPlayState = m_player->calculatePlayState();
804 822
805 m_player->m_playState = newPlayState; 823 m_player->m_playState = newPlayState;
806 if (oldPlayState != newPlayState) { 824 if (oldPlayState != newPlayState) {
807 bool wasActive = oldPlayState == Pending || oldPlayState == Running; 825 bool wasActive = oldPlayState == Pending || oldPlayState == Running;
808 bool isActive = newPlayState == Pending || newPlayState == Running; 826 bool isActive = newPlayState == Pending || newPlayState == Running;
809
810 if (!wasActive && isActive) 827 if (!wasActive && isActive)
811 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1("blink.animations," TRACE_DISABLED _BY_DEFAULT("devtools.timeline"), "Animation", m_player, "data", InspectorAnimat ionEvent::data(*m_player)); 828 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1("blink.animations," TRACE_DISABLED _BY_DEFAULT("devtools.timeline"), "Animation", m_player, "data", InspectorAnimat ionEvent::data(*m_player));
812 else if (wasActive && !isActive) 829 else if (wasActive && !isActive)
813 TRACE_EVENT_NESTABLE_ASYNC_END1("blink.animations," TRACE_DISABLED_B Y_DEFAULT("devtools.timeline"), "Animation", m_player, "endData", InspectorAnima tionStateEvent::data(*m_player)); 830 TRACE_EVENT_NESTABLE_ASYNC_END1("blink.animations," TRACE_DISABLED_B Y_DEFAULT("devtools.timeline"), "Animation", m_player, "endData", InspectorAnima tionStateEvent::data(*m_player));
814 else 831 else
815 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1("blink.animations," TRACE_DISABL ED_BY_DEFAULT("devtools.timeline"), "Animation", m_player, "data", InspectorAnim ationStateEvent::data(*m_player)); 832 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1("blink.animations," TRACE_DISABL ED_BY_DEFAULT("devtools.timeline"), "Animation", m_player, "data", InspectorAnim ationStateEvent::data(*m_player));
816 } 833 }
817 834
818 // Ordering is important, the ready promise should resolve/reject before 835 // Ordering is important, the ready promise should resolve/reject before
819 // the finished promise. 836 // the finished promise.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 visitor->trace(m_content); 918 visitor->trace(m_content);
902 visitor->trace(m_timeline); 919 visitor->trace(m_timeline);
903 visitor->trace(m_pendingFinishedEvent); 920 visitor->trace(m_pendingFinishedEvent);
904 visitor->trace(m_finishedPromise); 921 visitor->trace(m_finishedPromise);
905 visitor->trace(m_readyPromise); 922 visitor->trace(m_readyPromise);
906 EventTargetWithInlineData::trace(visitor); 923 EventTargetWithInlineData::trace(visitor);
907 ActiveDOMObject::trace(visitor); 924 ActiveDOMObject::trace(visitor);
908 } 925 }
909 926
910 } // namespace 927 } // namespace
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationPlayer.h ('k') | Source/core/animation/CompositorAnimations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698