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

Unified Diff: Source/core/animation/css/CSSAnimations.cpp

Issue 1281493004: Make CSSAnimationUpdate stack-allocated (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 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/css/CSSAnimations.cpp
diff --git a/Source/core/animation/css/CSSAnimations.cpp b/Source/core/animation/css/CSSAnimations.cpp
index 493ae473deb86d8f27baadb9b1bd3d2361ffcc19..4b03769599730f18e2275d527ec91b6e2291afa1 100644
--- a/Source/core/animation/css/CSSAnimations.cpp
+++ b/Source/core/animation/css/CSSAnimations.cpp
@@ -202,17 +202,15 @@ bool CSSAnimations::isTransitionAnimationForInspector(const Animation& animation
return false;
}
-PassOwnPtrWillBeRawPtr<CSSAnimationUpdate> CSSAnimations::calculateUpdate(const Element* animatingElement, Element& element, const ComputedStyle& style, ComputedStyle* parentStyle, StyleResolver* resolver)
+void CSSAnimations::calculateUpdate(const Element* animatingElement, Element& element, const ComputedStyle& style, ComputedStyle* parentStyle, CSSAnimationUpdate& animationUpdate, StyleResolver* resolver)
{
- OwnPtrWillBeRawPtr<CSSAnimationUpdate> update = adoptPtrWillBeNoop(new CSSAnimationUpdate());
- calculateAnimationUpdate(update.get(), animatingElement, element, style, parentStyle, resolver);
- calculateAnimationActiveInterpolations(update.get(), animatingElement, element.document().timeline().currentTimeInternal());
- calculateTransitionUpdate(update.get(), animatingElement, style);
- calculateTransitionActiveInterpolations(update.get(), animatingElement, element.document().timeline().currentTimeInternal());
- return update->isEmpty() ? nullptr : update.release();
+ calculateAnimationUpdate(animationUpdate, animatingElement, element, style, parentStyle, resolver);
+ calculateAnimationActiveInterpolations(animationUpdate, animatingElement, element.document().timeline().currentTimeInternal());
+ calculateTransitionUpdate(animationUpdate, animatingElement, style);
+ calculateTransitionActiveInterpolations(animationUpdate, animatingElement, element.document().timeline().currentTimeInternal());
}
-void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const Element* animatingElement, Element& element, const ComputedStyle& style, ComputedStyle* parentStyle, StyleResolver* resolver)
+void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate& update, const Element* animatingElement, Element& element, const ComputedStyle& style, ComputedStyle* parentStyle, StyleResolver* resolver)
{
const ElementAnimations* elementAnimations = animatingElement ? animatingElement->elementAnimations() : nullptr;
@@ -262,7 +260,7 @@ void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E
if (keyframesRule != runningAnimation->styleRule || keyframesRule->version() != runningAnimation->styleRuleVersion || runningAnimation->specifiedTiming != specifiedTiming) {
ASSERT(!isAnimationStyleChange);
- update->updateAnimation(animationName, animation, InertEffect::create(
+ update.updateAnimation(animationName, animation, InertEffect::create(
createKeyframeEffectModel(resolver, animatingElement, element, &style, parentStyle, animationName, keyframeTimingFunction.get(), i),
timing, isPaused, animation->unlimitedCurrentTimeInternal()), specifiedTiming, keyframesRule);
} else if (!isAnimationStyleChange && animation->effect() && animation->effect()->isAnimation()) {
@@ -270,13 +268,13 @@ void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E
if (model && model->isKeyframeEffectModel()) {
KeyframeEffectModelBase* keyframeEffect = toKeyframeEffectModelBase(model);
if (keyframeEffect->hasSyntheticKeyframes())
- update->updateAnimationStyle(animation, keyframeEffect, animatingElement->layoutObject(), style);
+ update.updateAnimationStyle(animation, keyframeEffect, animatingElement->layoutObject(), style);
}
}
if (isPaused != animation->paused()) {
ASSERT(!isAnimationStyleChange);
- update->toggleAnimationPaused(animationName);
+ update.toggleAnimationPaused(animationName);
}
continue;
@@ -284,7 +282,7 @@ void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E
}
ASSERT(!isAnimationStyleChange);
- update->startAnimation(animationName, InertEffect::create(
+ update.startAnimation(animationName, InertEffect::create(
createKeyframeEffectModel(resolver, animatingElement, element, &style, parentStyle, animationName, keyframeTimingFunction.get(), i),
timing, isPaused, 0), specifiedTiming, keyframesRule);
}
@@ -293,33 +291,31 @@ void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E
ASSERT(inactive.isEmpty() || cssAnimations);
for (const AtomicString& animationName : inactive) {
ASSERT(!isAnimationStyleChange);
- update->cancelAnimation(animationName, *cssAnimations->m_animations.get(animationName)->animation);
+ update.cancelAnimation(animationName, *cssAnimations->m_animations.get(animationName)->animation);
}
}
void CSSAnimations::maybeApplyPendingUpdate(Element* element)
{
- if (!m_pendingUpdate) {
+ if (m_pendingUpdate.isEmpty()) {
m_previousActiveInterpolationsForAnimations.clear();
return;
}
- OwnPtrWillBeRawPtr<CSSAnimationUpdate> update = m_pendingUpdate.release();
-
- m_previousActiveInterpolationsForAnimations.swap(update->activeInterpolationsForAnimations());
+ m_previousActiveInterpolationsForAnimations.swap(m_pendingUpdate.activeInterpolationsForAnimations());
// FIXME: cancelling, pausing, unpausing animations all query compositingState, which is not necessarily up to date here
// since we call this from recalc style.
// https://code.google.com/p/chromium/issues/detail?id=339847
DisableCompositingQueryAsserts disabler;
- for (const AtomicString& animationName : update->cancelledAnimationNames()) {
+ for (const AtomicString& animationName : m_pendingUpdate.cancelledAnimationNames()) {
RefPtrWillBeRawPtr<Animation> animation = m_animations.take(animationName)->animation;
animation->cancel();
animation->update(TimingUpdateOnDemand);
}
- for (const AtomicString& animationName : update->animationsWithPauseToggled()) {
+ for (const AtomicString& animationName : m_pendingUpdate.animationsWithPauseToggled()) {
Animation* animation = m_animations.get(animationName)->animation.get();
if (animation->paused())
animation->unpause();
@@ -329,7 +325,7 @@ void CSSAnimations::maybeApplyPendingUpdate(Element* element)
animation->update(TimingUpdateOnDemand);
}
- for (const auto& styleUpdate : update->animationsWithStyleUpdates()) {
+ for (const auto& styleUpdate : m_pendingUpdate.animationsWithStyleUpdates()) {
styleUpdate.model->forEachInterpolation([](Interpolation& interpolation) {
if (interpolation.isStyleInterpolation() && toStyleInterpolation(interpolation).isDeferredLegacyStyleInterpolation())
toDeferredLegacyStyleInterpolation(toStyleInterpolation(interpolation)).underlyingStyleChanged();
@@ -348,7 +344,7 @@ void CSSAnimations::maybeApplyPendingUpdate(Element* element)
}
}
- for (const auto& entry : update->animationsWithUpdates()) {
+ for (const auto& entry : m_pendingUpdate.animationsWithUpdates()) {
KeyframeEffect* effect = toKeyframeEffect(entry.animation->effect());
effect->setModel(entry.effect->model());
@@ -357,7 +353,7 @@ void CSSAnimations::maybeApplyPendingUpdate(Element* element)
m_animations.find(entry.name)->value->update(entry);
}
- for (const auto& entry : update->newAnimations()) {
+ for (const auto& entry : m_pendingUpdate.newAnimations()) {
const InertEffect* inertAnimation = entry.effect.get();
OwnPtrWillBeRawPtr<AnimationEventDelegate> eventDelegate = adoptPtrWillBeNoop(new AnimationEventDelegate(element, entry.name));
RefPtrWillBeRawPtr<KeyframeEffect> effect = KeyframeEffect::create(element, inertAnimation->model(), inertAnimation->specifiedTiming(), KeyframeEffect::DefaultPriority, eventDelegate.release());
@@ -376,12 +372,12 @@ void CSSAnimations::maybeApplyPendingUpdate(Element* element)
// recalculation, we find these cases by searching for new transitions that
// have matching cancelled animation property IDs on the compositor.
WillBeHeapHashMap<CSSPropertyID, std::pair<RefPtrWillBeMember<KeyframeEffect>, double>> retargetedCompositorTransitions;
- for (CSSPropertyID id : update->cancelledTransitions()) {
+ for (CSSPropertyID id : m_pendingUpdate.cancelledTransitions()) {
ASSERT(m_transitions.contains(id));
RefPtrWillBeRawPtr<Animation> animation = m_transitions.take(id).animation;
KeyframeEffect* effect = toKeyframeEffect(animation->effect());
- if (effect->hasActiveAnimationsOnCompositor(id) && update->newTransitions().find(id) != update->newTransitions().end() && !animation->limited())
+ if (effect->hasActiveAnimationsOnCompositor(id) && m_pendingUpdate.newTransitions().find(id) != m_pendingUpdate.newTransitions().end() && !animation->limited())
retargetedCompositorTransitions.add(id, std::pair<RefPtrWillBeMember<KeyframeEffect>, double>(effect, animation->startTimeInternal()));
animation->cancel();
// after cancelation, transitions must be downgraded or they'll fail
@@ -392,7 +388,7 @@ void CSSAnimations::maybeApplyPendingUpdate(Element* element)
animation->update(TimingUpdateOnDemand);
}
- for (CSSPropertyID id : update->finishedTransitions()) {
+ for (CSSPropertyID id : m_pendingUpdate.finishedTransitions()) {
// This transition can also be cancelled and finished at the same time
if (m_transitions.contains(id)) {
RefPtrWillBeRawPtr<Animation> animation = m_transitions.take(id).animation;
@@ -402,7 +398,7 @@ void CSSAnimations::maybeApplyPendingUpdate(Element* element)
}
}
- for (const auto& entry : update->newTransitions()) {
+ for (const auto& entry : m_pendingUpdate.newTransitions()) {
const CSSAnimationUpdate::NewTransition& newTransition = entry.value;
RunningTransition runningTransition;
@@ -453,9 +449,11 @@ void CSSAnimations::maybeApplyPendingUpdate(Element* element)
ASSERT(id != CSSPropertyInvalid);
Platform::current()->histogramSparse("WebCore.Animation.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(id));
}
+
+ clearPendingUpdate();
}
-void CSSAnimations::calculateTransitionUpdateForProperty(CSSPropertyID id, const CSSTransitionData& transitionData, size_t transitionIndex, const ComputedStyle& oldStyle, const ComputedStyle& style, const TransitionMap* activeTransitions, CSSAnimationUpdate* update, const Element* element)
+void CSSAnimations::calculateTransitionUpdateForProperty(CSSPropertyID id, const CSSTransitionData& transitionData, size_t transitionIndex, const ComputedStyle& oldStyle, const ComputedStyle& style, const TransitionMap* activeTransitions, CSSAnimationUpdate& update, const Element* element)
{
RefPtrWillBeRawPtr<AnimatableValue> to = nullptr;
if (activeTransitions) {
@@ -465,7 +463,7 @@ void CSSAnimations::calculateTransitionUpdateForProperty(CSSPropertyID id, const
const AnimatableValue* activeTo = activeTransitionIter->value.to;
if (to->equals(activeTo))
return;
- update->cancelTransition(id);
+ update.cancelTransition(id);
ASSERT(!element->elementAnimations() || !element->elementAnimations()->isAnimationStyleChange());
}
}
@@ -512,11 +510,11 @@ void CSSAnimations::calculateTransitionUpdateForProperty(CSSPropertyID id, const
keyframes.append(endKeyframe);
RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> model = AnimatableValueKeyframeEffectModel::create(keyframes);
- update->startTransition(id, from.get(), to.get(), InertEffect::create(model, timing, false, 0));
+ update.startTransition(id, from.get(), to.get(), InertEffect::create(model, timing, false, 0));
ASSERT(!element->elementAnimations() || !element->elementAnimations()->isAnimationStyleChange());
}
-void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const Element* animatingElement, const ComputedStyle& style)
+void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate& update, const Element* animatingElement, const ComputedStyle& style)
{
if (!animatingElement)
return;
@@ -565,7 +563,7 @@ void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const
// FIXME: We should transition if an !important property changes even when an animation is running,
// but this is a bit hard to do with the current applyMatchedProperties system.
PropertyHandle property = PropertyHandle(id);
- if (!update->activeInterpolationsForAnimations().contains(property)
+ if (!update.activeInterpolationsForAnimations().contains(property)
&& (!elementAnimations || !elementAnimations->cssAnimations().m_previousActiveInterpolationsForAnimations.contains(property))) {
calculateTransitionUpdateForProperty(id, *transitionData, i, oldStyle, style, activeTransitions, update, animatingElement);
}
@@ -579,9 +577,9 @@ void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const
if (!anyTransitionHadTransitionAll && !animationStyleRecalc && !listedProperties.get(id)) {
// TODO: Figure out why this fails on Chrome OS login page. crbug.com/365507
// ASSERT(animation.playStateInternal() == Animation::Finished || !(elementAnimations && elementAnimations->isAnimationStyleChange()));
- update->cancelTransition(id);
+ update.cancelTransition(id);
} else if (entry.value.animation->finishedInternal()) {
- update->finishTransition(id);
+ update.finishTransition(id);
}
}
}
@@ -600,49 +598,48 @@ void CSSAnimations::cancel()
}
m_animations.clear();
- m_transitions.clear();
- m_pendingUpdate = nullptr;
+ clearPendingUpdate();
}
-void CSSAnimations::calculateAnimationActiveInterpolations(CSSAnimationUpdate* update, const Element* animatingElement, double timelineCurrentTime)
+void CSSAnimations::calculateAnimationActiveInterpolations(CSSAnimationUpdate& update, const Element* animatingElement, double timelineCurrentTime)
{
ElementAnimations* elementAnimations = animatingElement ? animatingElement->elementAnimations() : nullptr;
AnimationStack* animationStack = elementAnimations ? &elementAnimations->defaultStack() : nullptr;
- if (update->newAnimations().isEmpty() && update->suppressedAnimations().isEmpty()) {
+ if (update.newAnimations().isEmpty() && update.suppressedAnimations().isEmpty()) {
ActiveInterpolationMap activeInterpolationsForAnimations(AnimationStack::activeInterpolations(animationStack, 0, 0, KeyframeEffect::DefaultPriority, timelineCurrentTime));
- update->adoptActiveInterpolationsForAnimations(activeInterpolationsForAnimations);
+ update.adoptActiveInterpolationsForAnimations(activeInterpolationsForAnimations);
return;
}
WillBeHeapVector<RawPtrWillBeMember<InertEffect>> newEffects;
- for (const auto& newAnimation : update->newAnimations())
+ for (const auto& newAnimation : update.newAnimations())
newEffects.append(newAnimation.effect.get());
- for (const auto& updatedAnimation : update->animationsWithUpdates())
+ for (const auto& updatedAnimation : update.animationsWithUpdates())
newEffects.append(updatedAnimation.effect.get()); // Animations with updates use a temporary InertEffect for the current frame.
- ActiveInterpolationMap activeInterpolationsForAnimations(AnimationStack::activeInterpolations(animationStack, &newEffects, &update->suppressedAnimations(), KeyframeEffect::DefaultPriority, timelineCurrentTime));
- update->adoptActiveInterpolationsForAnimations(activeInterpolationsForAnimations);
+ ActiveInterpolationMap activeInterpolationsForAnimations(AnimationStack::activeInterpolations(animationStack, &newEffects, &update.suppressedAnimations(), KeyframeEffect::DefaultPriority, timelineCurrentTime));
+ update.adoptActiveInterpolationsForAnimations(activeInterpolationsForAnimations);
}
-void CSSAnimations::calculateTransitionActiveInterpolations(CSSAnimationUpdate* update, const Element* animatingElement, double timelineCurrentTime)
+void CSSAnimations::calculateTransitionActiveInterpolations(CSSAnimationUpdate& update, const Element* animatingElement, double timelineCurrentTime)
{
ElementAnimations* elementAnimations = animatingElement ? animatingElement->elementAnimations() : nullptr;
AnimationStack* animationStack = elementAnimations ? &elementAnimations->defaultStack() : nullptr;
ActiveInterpolationMap activeInterpolationsForTransitions;
- if (update->newTransitions().isEmpty() && update->cancelledTransitions().isEmpty()) {
+ if (update.newTransitions().isEmpty() && update.cancelledTransitions().isEmpty()) {
activeInterpolationsForTransitions = AnimationStack::activeInterpolations(animationStack, 0, 0, KeyframeEffect::TransitionPriority, timelineCurrentTime);
} else {
WillBeHeapVector<RawPtrWillBeMember<InertEffect>> newTransitions;
- for (const auto& entry : update->newTransitions())
+ for (const auto& entry : update.newTransitions())
newTransitions.append(entry.value.effect.get());
WillBeHeapHashSet<RawPtrWillBeMember<const Animation>> cancelledAnimations;
- if (!update->cancelledTransitions().isEmpty()) {
+ if (!update.cancelledTransitions().isEmpty()) {
ASSERT(elementAnimations);
const TransitionMap& transitionMap = elementAnimations->cssAnimations().m_transitions;
- for (CSSPropertyID id : update->cancelledTransitions()) {
+ for (CSSPropertyID id : update.cancelledTransitions()) {
ASSERT(transitionMap.contains(id));
cancelledAnimations.add(transitionMap.get(id).animation.get());
}
@@ -652,11 +649,11 @@ void CSSAnimations::calculateTransitionActiveInterpolations(CSSAnimationUpdate*
}
// Properties being animated by animations don't get values from transitions applied.
- if (!update->activeInterpolationsForAnimations().isEmpty() && !activeInterpolationsForTransitions.isEmpty()) {
- for (const auto& entry : update->activeInterpolationsForAnimations())
+ if (!update.activeInterpolationsForAnimations().isEmpty() && !activeInterpolationsForTransitions.isEmpty()) {
+ for (const auto& entry : update.activeInterpolationsForAnimations())
activeInterpolationsForTransitions.remove(entry.key);
}
- update->adoptActiveInterpolationsForTransitions(activeInterpolationsForTransitions);
+ update.adoptActiveInterpolationsForTransitions(activeInterpolationsForTransitions);
}
EventTarget* CSSAnimations::AnimationEventDelegate::eventTarget() const
@@ -800,17 +797,4 @@ DEFINE_TRACE(CSSAnimations)
#endif
}
-DEFINE_TRACE(CSSAnimationUpdate)
-{
-#if ENABLE(OILPAN)
- visitor->trace(m_newTransitions);
- visitor->trace(m_activeInterpolationsForAnimations);
- visitor->trace(m_activeInterpolationsForTransitions);
- visitor->trace(m_newAnimations);
- visitor->trace(m_suppressedAnimations);
- visitor->trace(m_animationsWithUpdates);
- visitor->trace(m_animationsWithStyleUpdates);
-#endif
-}
-
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698