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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/animation/AnimationPlayer.cpp
diff --git a/Source/core/animation/AnimationPlayer.cpp b/Source/core/animation/AnimationPlayer.cpp
index cc3f3065687c5a0124970b678301de9cecce50ba..ef155a64b466ef21486784e1098260f765569a41 100644
--- a/Source/core/animation/AnimationPlayer.cpp
+++ b/Source/core/animation/AnimationPlayer.cpp
@@ -39,7 +39,11 @@
#include "core/frame/UseCounter.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/inspector/InspectorTraceEvents.h"
+#include "platform/RuntimeEnabledFeatures.h"
#include "platform/TraceEvent.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebCompositorAnimationPlayer.h"
+#include "public/platform/WebCompositorSupport.h"
#include "wtf/MathExtras.h"
namespace blink {
@@ -66,6 +70,7 @@ PassRefPtrWillBeRawPtr<AnimationPlayer> AnimationPlayer::create(AnimationNode* s
if (timeline) {
timeline->playerAttached(*player);
+ player->attachCompositorTimeline();
}
return player.release();
@@ -88,6 +93,7 @@ AnimationPlayer::AnimationPlayer(ExecutionContext* executionContext, AnimationTi
, m_compositorState(nullptr)
, m_compositorPending(false)
, m_compositorGroup(0)
+ , m_attachCompositedLayers(false)
, m_currentTimePending(false)
, m_stateIsBeingUpdated(false)
{
@@ -103,11 +109,15 @@ AnimationPlayer::AnimationPlayer(ExecutionContext* executionContext, AnimationTi
AnimationPlayer::~AnimationPlayer()
{
#if !ENABLE(OILPAN)
- if (m_content)
+ if (m_content) {
+ detachCompositedLayers();
m_content->detach();
+ }
if (m_timeline)
m_timeline->playerDestroyed(this);
#endif
+
+ destroyCompositorPlayer();
}
double AnimationPlayer::sourceEnd() const
@@ -270,6 +280,11 @@ void AnimationPlayer::preCommit(int compositorGroup, bool startOnCompositor)
if (shouldStart) {
m_compositorGroup = compositorGroup;
if (startOnCompositor) {
+ 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.
+ createCompositorPlayer();
+ attachCompositedLayers();
+ }
+
if (maybeStartAnimationOnCompositor())
m_compositorState = adoptPtr(new CompositorState(*this));
else
@@ -433,8 +448,10 @@ void AnimationPlayer::setSource(AnimationNode* newSource)
PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorPendingWithSourceChanged);
double storedCurrentTime = currentTimeInternal();
- if (m_content)
+ if (m_content) {
+ detachCompositedLayers();
m_content->detach();
+ }
m_content = newSource;
if (newSource) {
// FIXME: This logic needs to be updated once groups are implemented
@@ -443,6 +460,7 @@ void AnimationPlayer::setSource(AnimationNode* newSource)
newSource->player()->setSource(0);
}
newSource->attach(this);
+ 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
setOutdated();
}
setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand);
@@ -669,7 +687,7 @@ void AnimationPlayer::setOutdated()
m_timeline->setOutdatedAnimationPlayer(this);
}
-bool AnimationPlayer::canStartAnimationOnCompositor()
+bool AnimationPlayer::canStartAnimationOnCompositor() const
{
// FIXME: Timeline playback rates should be compositable
if (m_playbackRate == 0 || (std::isinf(sourceEnd()) && m_playbackRate < 0) || (timeline() && timeline()->playbackRate() != 1))
@@ -678,6 +696,14 @@ bool AnimationPlayer::canStartAnimationOnCompositor()
return m_timeline && m_content && m_content->isAnimation() && playing();
}
+bool AnimationPlayer::isCandidateForAnimationOnCompositor() const
+{
+ if (!canStartAnimationOnCompositor())
+ return false;
+
+ return toAnimation(m_content.get())->isCandidateForAnimationOnCompositor(m_playbackRate);
+}
+
bool AnimationPlayer::maybeStartAnimationOnCompositor()
{
if (!canStartAnimationOnCompositor())
@@ -830,6 +856,73 @@ void AnimationPlayer::endUpdatingState()
m_stateIsBeingUpdated = false;
}
+void AnimationPlayer::createCompositorPlayer()
+{
+ if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && !m_compositorPlayer && Platform::current()->compositorSupport()) {
+ m_compositorPlayer = adoptPtr(Platform::current()->compositorSupport()->createAnimationPlayer());
+ ASSERT(m_compositorPlayer);
+ m_compositorPlayer->setAnimationDelegate(this);
+ attachCompositorTimeline();
+ }
+}
+
+void AnimationPlayer::destroyCompositorPlayer()
+{
+ if (m_compositorPlayer) {
+ detachCompositorTimeline();
+ m_compositorPlayer->setAnimationDelegate(nullptr);
+ }
+ m_compositorPlayer.clear();
+}
+
+void AnimationPlayer::attachCompositorTimeline()
+{
+ if (m_compositorPlayer) {
+ WebCompositorAnimationTimeline* timeline = m_timeline ? m_timeline->compositorTimeline() : nullptr;
+ if (timeline)
+ timeline->playerAttached(*this);
+ }
+}
+
+void AnimationPlayer::detachCompositorTimeline()
+{
+ if (m_compositorPlayer) {
+ WebCompositorAnimationTimeline* timeline = m_timeline ? m_timeline->compositorTimeline() : nullptr;
+ if (timeline)
+ timeline->playerDestroyed(*this);
+ }
+}
+
+void AnimationPlayer::attachCompositedLayers()
+{
+ 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.
+ 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
+}
+
+void AnimationPlayer::detachCompositedLayers()
+{
+ m_attachCompositedLayers = false;
+ if (m_compositorPlayer && m_compositorPlayer->isLayerAttached())
+ m_compositorPlayer->detachLayer();
+}
+
+void AnimationPlayer::updateCompositedLayersAttachment()
+{
+ if (!RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() || !m_attachCompositedLayers)
+ return;
+ if (!m_compositorPlayer || !m_content || !m_content->isAnimation() || !toAnimation(m_content.get())->canAttachCompositedLayers())
+ return;
+
+ m_attachCompositedLayers = false;
+ toAnimation(m_content.get())->attachCompositedLayers();
+}
+
+void AnimationPlayer::notifyAnimationStarted(double monotonicTime, int group)
+{
+ ASSERT(RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled());
+ timeline()->document()->compositorPendingAnimations().notifyCompositorAnimationStarted(monotonicTime, group);
+}
+
AnimationPlayer::PlayStateUpdateScope::PlayStateUpdateScope(AnimationPlayer& player, TimingUpdateReason reason, CompositorPendingChange compositorPendingChange)
: m_player(player)
, m_initialPlayState(m_player->playStateInternal())

Powered by Google App Engine
This is Rietveld 408576698