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

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

Issue 851693007: Prepare for responsive CSS animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address comments 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 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 de5204762697c0dc7895916ffa8505a87129f882..f75578970cb5b779cb7d1add0ec1b7c8b4386e80 100644
--- a/Source/core/animation/css/CSSAnimations.cpp
+++ b/Source/core/animation/css/CSSAnimations.cpp
@@ -86,7 +86,7 @@ CSSPropertyID propertyForAnimation(CSSPropertyID property)
}
static void resolveKeyframes(StyleResolver* resolver, const Element* animatingElement, Element& element, const RenderStyle& style, RenderStyle* parentStyle, const AtomicString& name, TimingFunction* defaultTimingFunction,
- AnimatableValueKeyframeVector& keyframes)
+ StringKeyframeVector& keyframes)
{
// When the animating element is null, use its parent for scoping purposes.
const Element* elementForScoping = animatingElement ? animatingElement : &element;
@@ -101,7 +101,7 @@ static void resolveKeyframes(StyleResolver* resolver, const Element* animatingEl
for (size_t i = 0; i < styleKeyframes.size(); ++i) {
const StyleRuleKeyframe* styleKeyframe = styleKeyframes[i].get();
RefPtr<RenderStyle> keyframeStyle = resolver->styleForKeyframe(element, style, parentStyle, styleKeyframe, name);
- RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframe = AnimatableValueKeyframe::create();
+ RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create();
const Vector<double>& offsets = styleKeyframe->keys();
ASSERT(!offsets.isEmpty());
keyframe->setOffset(offsets[0]);
@@ -123,13 +123,13 @@ static void resolveKeyframes(StyleResolver* resolver, const Element* animatingEl
}
keyframe->setEasing(timingFunction.release());
} else if (CSSPropertyMetadata::isAnimatableProperty(property)) {
- keyframe->setPropertyValue(property, CSSAnimatableValueFactory::create(property, *keyframeStyle).get());
+ keyframe->setPropertyValue(property, properties.propertyAt(j).value());
}
}
keyframes.append(keyframe);
// The last keyframe specified at a given offset is used.
for (size_t j = 1; j < offsets.size(); ++j) {
- keyframes.append(toAnimatableValueKeyframe(keyframe->cloneWithOffset(offsets[j]).get()));
+ keyframes.append(toStringKeyframe(keyframe->cloneWithOffset(offsets[j]).get()));
}
}
@@ -154,16 +154,16 @@ static void resolveKeyframes(StyleResolver* resolver, const Element* animatingEl
keyframes.shrink(targetIndex + 1);
// Add 0% and 100% keyframes if absent.
- RefPtrWillBeRawPtr<AnimatableValueKeyframe> startKeyframe = keyframes.isEmpty() ? nullptr : keyframes[0];
+ RefPtrWillBeRawPtr<StringKeyframe> startKeyframe = keyframes.isEmpty() ? nullptr : keyframes[0];
if (!startKeyframe || keyframes[0]->offset() != 0) {
- startKeyframe = AnimatableValueKeyframe::create();
+ startKeyframe = StringKeyframe::create();
startKeyframe->setOffset(0);
startKeyframe->setEasing(defaultTimingFunction);
keyframes.prepend(startKeyframe);
}
- RefPtrWillBeRawPtr<AnimatableValueKeyframe> endKeyframe = keyframes[keyframes.size() - 1];
+ RefPtrWillBeRawPtr<StringKeyframe> endKeyframe = keyframes[keyframes.size() - 1];
if (endKeyframe->offset() != 1) {
- endKeyframe = AnimatableValueKeyframe::create();
+ endKeyframe = StringKeyframe::create();
endKeyframe->setOffset(1);
endKeyframe->setEasing(defaultTimingFunction);
keyframes.append(endKeyframe);
@@ -172,7 +172,7 @@ static void resolveKeyframes(StyleResolver* resolver, const Element* animatingEl
ASSERT(!keyframes.first()->offset());
ASSERT(keyframes.last()->offset() == 1);
- // Snapshot current property values for 0% and 100% if missing.
+ // FIXME: This is only used for use counting neutral keyframes running on the compositor.
PropertySet allProperties;
for (const auto& keyframe : keyframes) {
for (CSSPropertyID property : keyframe->properties())
@@ -188,19 +188,28 @@ static void resolveKeyframes(StyleResolver* resolver, const Element* animatingEl
bool endNeedsValue = missingEndValues && !endKeyframeProperties.contains(property);
if (!startNeedsValue && !endNeedsValue)
continue;
- RefPtrWillBeRawPtr<AnimatableValue> snapshotValue = CSSAnimatableValueFactory::create(property, style);
- if (startNeedsValue)
- startKeyframe->setPropertyValue(property, snapshotValue.get());
- if (endNeedsValue)
- endKeyframe->setPropertyValue(property, snapshotValue.get());
- if (property == CSSPropertyOpacity || property == CSSPropertyTransform)
+ if (CompositorAnimations::isCompositableProperty(property))
UseCounter::count(elementForScoping->document(), UseCounter::SyntheticKeyframesInCompositedCSSAnimation);
}
}
- ASSERT(startKeyframe->properties().size() == allProperties.size());
- ASSERT(endKeyframe->properties().size() == allProperties.size());
}
+CSSAnimationUpdate::UpdatedAnimationStyle::CompositableStyleSnapshot snapshotCompositableProperties(RenderObject *renderer, const RenderStyle &newStyle, const AnimationEffect *effect)
+{
+ CSSAnimationUpdate::UpdatedAnimationStyle::CompositableStyleSnapshot snapshot;
+ if (!renderer)
+ return snapshot;
+
+ const RenderStyle& oldStyle = *renderer->style();
+ if (!CSSPropertyEquality::propertiesEqual(CSSPropertyOpacity, oldStyle, newStyle) && effect->affects(CSSPropertyOpacity))
+ snapshot.opacity = CSSAnimatableValueFactory::create(CSSPropertyOpacity, newStyle);
+ if (!CSSPropertyEquality::propertiesEqual(CSSPropertyTransform, oldStyle, newStyle) && effect->affects(CSSPropertyTransform))
+ snapshot.transform = CSSAnimatableValueFactory::create(CSSPropertyTransform, newStyle);
+ if (!CSSPropertyEquality::propertiesEqual(CSSPropertyWebkitFilter, oldStyle, newStyle) && effect->affects(CSSPropertyWebkitFilter))
+ snapshot.webkitFilter = CSSAnimatableValueFactory::create(CSSPropertyWebkitFilter, newStyle);
+
+ return snapshot;
+}
} // namespace
CSSAnimations::CSSAnimations()
@@ -239,10 +248,12 @@ void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E
{
const ActiveAnimations* activeAnimations = animatingElement ? animatingElement->activeAnimations() : nullptr;
+ bool isAnimationStyleChange = activeAnimations && activeAnimations->isAnimationStyleChange();
+
#if !ENABLE(ASSERT)
// If we're in an animation style change, no animations can have started, been cancelled or changed play state.
// When ASSERT is enabled, we verify this optimization.
- if (activeAnimations && activeAnimations->isAnimationStyleChange())
+ if (isAnimationStyleChange)
return;
#endif
@@ -281,17 +292,28 @@ void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E
const RunningAnimation* runningAnimation = existing->value.get();
AnimationPlayer* player = runningAnimation->player.get();
- ASSERT(keyframesRule);
if (keyframesRule != runningAnimation->styleRule || keyframesRule->version() != runningAnimation->styleRuleVersion || runningAnimation->specifiedTiming != specifiedTiming) {
- AnimatableValueKeyframeVector resolvedKeyframes;
+ ASSERT(!isAnimationStyleChange);
+
+ StringKeyframeVector resolvedKeyframes;
resolveKeyframes(resolver, animatingElement, element, style, parentStyle, animationName, keyframeTimingFunction.get(), resolvedKeyframes);
- update->updateAnimation(animationName, player, InertAnimation::create(AnimatableValueKeyframeEffectModel::create(resolvedKeyframes),
- timing, isPaused, player->currentTimeInternal()), specifiedTiming, keyframesRule);
+ RefPtrWillBeRawPtr<StringKeyframeEffectModel> effect = StringKeyframeEffectModel::create(resolvedKeyframes);
+ effect->setNeutralKeyframeEasings(keyframeTimingFunction);
dstockwell 2015/02/05 23:04:52 Can this (302-304) be part of resolveKeyframes? It
shend 2015/02/06 03:16:25 Done.
+ effect->snapshotCompositableProperties(animatingElement, style); // FIXME: Remove this once CompositorAnimations no longer depends on AnimatableValues
+ effect->forceConversionsToAnimatableValues(&element); // FIXME: Remove this once LegacyStyleInterpolation is removed from StringKeyframe
+ update->updateAnimation(animationName, player, InertAnimation::create(effect, timing, isPaused, player->currentTimeInternal()), specifiedTiming, keyframesRule);
+ } else if (!isAnimationStyleChange && player->source()->isAnimation()) {
dstockwell 2015/02/05 23:04:52 && player->source() &&
shend 2015/02/06 03:16:25 Done.
+ AnimationEffect* effect = toAnimation(player->source())->effect();
+ if (effect && effect->isKeyframeEffectModel()) {
+ KeyframeEffectModelBase* keyframeEffect = toKeyframeEffectModelBase(effect);
+ if (keyframeEffect->hasSyntheticKeyframes())
+ update->updateAnimationStyle(player, keyframeEffect, snapshotCompositableProperties(animatingElement->renderer(), style, effect));
+ }
}
if (isPaused != player->paused()) {
- ASSERT(!activeAnimations || !activeAnimations->isAnimationStyleChange());
+ ASSERT(!isAnimationStyleChange);
update->toggleAnimationPaused(animationName);
}
@@ -299,18 +321,22 @@ void CSSAnimations::calculateAnimationUpdate(CSSAnimationUpdate* update, const E
}
}
- AnimatableValueKeyframeVector resolvedKeyframes;
+ StringKeyframeVector resolvedKeyframes;
resolveKeyframes(resolver, animatingElement, element, style, parentStyle, animationName, keyframeTimingFunction.get(), resolvedKeyframes);
- if (!resolvedKeyframes.isEmpty()) {
- ASSERT(!activeAnimations || !activeAnimations->isAnimationStyleChange());
- update->startAnimation(animationName, InertAnimation::create(AnimatableValueKeyframeEffectModel::create(resolvedKeyframes), timing, isPaused, 0), specifiedTiming, keyframesRule);
- }
+
+ ASSERT(!resolvedKeyframes.isEmpty());
+ ASSERT(!isAnimationStyleChange);
+ RefPtrWillBeRawPtr<StringKeyframeEffectModel> effect = StringKeyframeEffectModel::create(resolvedKeyframes);
+ effect->setNeutralKeyframeEasings(keyframeTimingFunction);
+ effect->snapshotCompositableProperties(animatingElement, style); // FIXME: Remove this once CompositorAnimations no longer depends on AnimatableValues
+ effect->forceConversionsToAnimatableValues(&element); // FIXME: Remove this once LegacyStyleInterpolation is removed from StringKeyframe
+ update->startAnimation(animationName, InertAnimation::create(effect, timing, isPaused, 0), specifiedTiming, keyframesRule);
}
}
ASSERT(inactive.isEmpty() || cssAnimations);
for (const AtomicString& animationName : inactive) {
- ASSERT(!activeAnimations || !activeAnimations->isAnimationStyleChange());
+ ASSERT(!isAnimationStyleChange);
update->cancelAnimation(animationName, *cssAnimations->m_animations.get(animationName)->player);
}
}
@@ -356,6 +382,17 @@ void CSSAnimations::maybeApplyPendingUpdate(Element* element)
m_animations.find(entry.name)->value->update(entry);
}
+ for (const auto& styleUpdate : update->animationsWithStyleUpdates()) {
+ styleUpdate.effect->setDeferredInterpolationsOutdated();
+ if (styleUpdate.snapshot.opacity || styleUpdate.snapshot.transform || styleUpdate.snapshot.webkitFilter) {
+ styleUpdate.effect->updateNeutralKeyframeAnimatableValues(CSSPropertyOpacity, styleUpdate.snapshot.opacity);
+ styleUpdate.effect->updateNeutralKeyframeAnimatableValues(CSSPropertyTransform, styleUpdate.snapshot.transform);
+ styleUpdate.effect->updateNeutralKeyframeAnimatableValues(CSSPropertyWebkitFilter, styleUpdate.snapshot.webkitFilter);
+ styleUpdate.player->setOutdated();
+ styleUpdate.player->setCompositorPending(true);
+ }
+ }
+
for (const auto& entry : update->newAnimations()) {
const InertAnimation* inertAnimation = entry.animation.get();
OwnPtrWillBeRawPtr<AnimationEventDelegate> eventDelegate = adoptPtrWillBeNoop(new AnimationEventDelegate(element, entry.name));
« Source/core/animation/StringKeyframe.cpp ('K') | « Source/core/animation/css/CSSAnimationUpdate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698