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

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: Implement layer attach/detach. Fix code review issues. 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..215feb8230bcf7d991999488fa0cf6398fa11d62 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 {
@@ -88,26 +92,34 @@ AnimationPlayer::AnimationPlayer(ExecutionContext* executionContext, AnimationTi
, m_compositorState(nullptr)
, m_compositorPending(false)
, m_compositorGroup(0)
+ , m_attachCompositorPlayerToElement(false)
, m_currentTimePending(false)
, m_stateIsBeingUpdated(false)
{
+ createCompositorPlayer();
+
if (m_content) {
if (m_content->player()) {
m_content->player()->cancel();
m_content->player()->setSource(0);
}
m_content->attach(this);
+ attachElementToPlayer();
}
}
AnimationPlayer::~AnimationPlayer()
{
#if !ENABLE(OILPAN)
- if (m_content)
+ if (m_content) {
+ detachElementFromPlayer();
m_content->detach();
+ }
if (m_timeline)
m_timeline->playerDestroyed(this);
#endif
+
+ destroyCompositorPlayer();
}
double AnimationPlayer::sourceEnd() const
@@ -433,8 +445,10 @@ void AnimationPlayer::setSource(AnimationNode* newSource)
PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand, SetCompositorPendingWithSourceChanged);
double storedCurrentTime = currentTimeInternal();
- if (m_content)
+ if (m_content) {
+ detachElementFromPlayer();
m_content->detach();
+ }
m_content = newSource;
if (newSource) {
// FIXME: This logic needs to be updated once groups are implemented
@@ -443,6 +457,7 @@ void AnimationPlayer::setSource(AnimationNode* newSource)
newSource->player()->setSource(0);
}
newSource->attach(this);
+ attachElementToPlayer();
setOutdated();
}
setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand);
@@ -830,6 +845,52 @@ void AnimationPlayer::endUpdatingState()
m_stateIsBeingUpdated = false;
}
+void AnimationPlayer::createCompositorPlayer()
+{
+ if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && Platform::current()->compositorSupport()) {
+ m_compositorPlayer = adoptPtr(Platform::current()->compositorSupport()->createAnimationPlayer());
+ ASSERT(m_compositorPlayer);
+ m_compositorPlayer->setAnimationDelegate(this);
+ }
+}
+
+void AnimationPlayer::destroyCompositorPlayer()
+{
+ if (m_compositorPlayer)
+ m_compositorPlayer->setAnimationDelegate(nullptr);
+ m_compositorPlayer.clear();
+}
+
+void AnimationPlayer::attachElementToPlayer()
+{
+ m_attachCompositorPlayerToElement = true;
+ updateCompositorPlayerToElementAttachment();
+}
+
+void AnimationPlayer::detachElementFromPlayer()
+{
+ m_attachCompositorPlayerToElement = false;
+ if (m_compositorPlayer && m_compositorPlayer->isLayerAttached())
+ m_compositorPlayer->detachLayer();
+}
+
+void AnimationPlayer::updateCompositorPlayerToElementAttachment()
+{
+ if (!RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() || !m_attachCompositorPlayerToElement)
+ return;
+ if (!m_compositorPlayer || !m_content || !m_content->isAnimation() || !toAnimation(m_content.get())->canAttachElementToCompositorPlayer())
+ return;
+
+ m_attachCompositorPlayerToElement = false;
+ toAnimation(m_content.get())->attachElementToCompositorPlayer();
+}
+
+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