| Index: Source/core/rendering/RenderLayerBacking.cpp
|
| diff --git a/Source/core/rendering/RenderLayerBacking.cpp b/Source/core/rendering/RenderLayerBacking.cpp
|
| index 0bdbeee8dcee8da880d2c8410ae031bce4b44b50..9e93113fb62a5b3cc53a79e3b05d4519363cc7fa 100644
|
| --- a/Source/core/rendering/RenderLayerBacking.cpp
|
| +++ b/Source/core/rendering/RenderLayerBacking.cpp
|
| @@ -40,7 +40,6 @@
|
| #include "core/page/Settings.h"
|
| #include "core/page/animation/AnimationController.h"
|
| #include "core/page/scrolling/ScrollingCoordinator.h"
|
| -#include "core/platform/animation/KeyframeValueList.h"
|
| #include "core/platform/graphics/FontCache.h"
|
| #include "core/platform/graphics/GraphicsContext.h"
|
| #include "core/platform/graphics/GraphicsLayer.h"
|
| @@ -53,6 +52,7 @@
|
| #include "core/rendering/RenderLayerCompositor.h"
|
| #include "core/rendering/RenderVideo.h"
|
| #include "core/rendering/RenderView.h"
|
| +#include "core/rendering/animation/WebAnimationProvider.h"
|
| #include "core/rendering/style/KeyframeList.h"
|
| #include "wtf/CurrentTime.h"
|
| #include "wtf/text/StringBuilder.h"
|
| @@ -152,6 +152,7 @@ static ScrollingCoordinator* scrollingCoordinatorFromLayer(RenderLayer* layer)
|
|
|
| RenderLayerBacking::RenderLayerBacking(RenderLayer* layer)
|
| : m_owningLayer(layer)
|
| + , m_animationProvider(adoptPtr(new WebAnimationProvider))
|
| , m_artificiallyInflatedBounds(false)
|
| , m_boundsConstrainedByClipping(false)
|
| , m_isMainFrameRenderViewLayer(false)
|
| @@ -1674,49 +1675,20 @@ void RenderLayerBacking::verifyNotPainting()
|
|
|
| bool RenderLayerBacking::startAnimation(double timeOffset, const CSSAnimationData* anim, const KeyframeList& keyframes)
|
| {
|
| - bool hasOpacity = keyframes.containsProperty(CSSPropertyOpacity);
|
| bool hasTransform = renderer()->isBox() && keyframes.containsProperty(CSSPropertyWebkitTransform);
|
| - bool hasFilter = keyframes.containsProperty(CSSPropertyWebkitFilter);
|
| -
|
| - if (!hasOpacity && !hasTransform && !hasFilter)
|
| + IntSize boxSize;
|
| + if (hasTransform)
|
| + boxSize = toRenderBox(renderer())->pixelSnappedBorderBoxRect().size();
|
| + WebAnimations animations(m_animationProvider->startAnimation(timeOffset, anim, keyframes, hasTransform, boxSize));
|
| + if (animations.isEmpty())
|
| return false;
|
|
|
| - KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
|
| - KeyframeValueList opacityVector(AnimatedPropertyOpacity);
|
| - KeyframeValueList filterVector(AnimatedPropertyWebkitFilter);
|
| -
|
| - size_t numKeyframes = keyframes.size();
|
| - for (size_t i = 0; i < numKeyframes; ++i) {
|
| - const KeyframeValue& currentKeyframe = keyframes[i];
|
| - const RenderStyle* keyframeStyle = currentKeyframe.style();
|
| - double key = currentKeyframe.key();
|
| -
|
| - if (!keyframeStyle)
|
| - continue;
|
| -
|
| - // Get timing function.
|
| - RefPtr<TimingFunction> tf = currentKeyframe.timingFunction(keyframes.animationName());
|
| -
|
| - bool isFirstOrLastKeyframe = key == 0 || key == 1;
|
| - if ((hasTransform && isFirstOrLastKeyframe) || currentKeyframe.containsProperty(CSSPropertyWebkitTransform))
|
| - transformVector.insert(adoptPtr(new TransformAnimationValue(key, &(keyframeStyle->transform()), tf)));
|
| -
|
| - if ((hasOpacity && isFirstOrLastKeyframe) || currentKeyframe.containsProperty(CSSPropertyOpacity))
|
| - opacityVector.insert(adoptPtr(new FloatAnimationValue(key, keyframeStyle->opacity(), tf)));
|
| -
|
| - if ((hasFilter && isFirstOrLastKeyframe) || currentKeyframe.containsProperty(CSSPropertyWebkitFilter))
|
| - filterVector.insert(adoptPtr(new FilterAnimationValue(key, &(keyframeStyle->filter()), tf)));
|
| - }
|
| -
|
| bool didAnimate = false;
|
| -
|
| - if (hasTransform && m_graphicsLayer->addAnimation(transformVector, toRenderBox(renderer())->pixelSnappedBorderBoxRect().size(), anim, keyframes.animationName(), timeOffset))
|
| + if (animations.m_transformAnimation && m_graphicsLayer->addAnimation(animations.m_transformAnimation.get()))
|
| didAnimate = true;
|
| -
|
| - if (hasOpacity && m_graphicsLayer->addAnimation(opacityVector, IntSize(), anim, keyframes.animationName(), timeOffset))
|
| + if (animations.m_opacityAnimation && m_graphicsLayer->addAnimation(animations.m_opacityAnimation.get()))
|
| didAnimate = true;
|
| -
|
| - if (hasFilter && m_graphicsLayer->addAnimation(filterVector, IntSize(), anim, keyframes.animationName(), timeOffset))
|
| + if (animations.m_filterAnimation && m_graphicsLayer->addAnimation(animations.m_filterAnimation.get()))
|
| didAnimate = true;
|
|
|
| return didAnimate;
|
| @@ -1724,61 +1696,49 @@ bool RenderLayerBacking::startAnimation(double timeOffset, const CSSAnimationDat
|
|
|
| void RenderLayerBacking::animationPaused(double timeOffset, const String& animationName)
|
| {
|
| - m_graphicsLayer->pauseAnimation(animationName, timeOffset);
|
| + int animationId = m_animationProvider->getWebAnimationId(animationName);
|
| + if (animationId)
|
| + m_graphicsLayer->pauseAnimation(animationId, timeOffset);
|
| }
|
|
|
| void RenderLayerBacking::animationFinished(const String& animationName)
|
| {
|
| - m_graphicsLayer->removeAnimation(animationName);
|
| + int animationId = m_animationProvider->getWebAnimationId(animationName);
|
| + if (animationId)
|
| + m_graphicsLayer->removeAnimation(animationId);
|
| }
|
|
|
| bool RenderLayerBacking::startTransition(double timeOffset, CSSPropertyID property, const RenderStyle* fromStyle, const RenderStyle* toStyle)
|
| {
|
| - bool didAnimate = false;
|
| -
|
| ASSERT(property != CSSPropertyInvalid);
|
| -
|
| + IntSize boxSize;
|
| + if (property == CSSPropertyWebkitTransform && m_owningLayer->hasTransform()) {
|
| + ASSERT(renderer()->isBox());
|
| + boxSize = toRenderBox(renderer())->pixelSnappedBorderBoxRect().size();
|
| + }
|
| + float fromOpacity = 0;
|
| + float toOpacity = 0;
|
| if (property == CSSPropertyOpacity) {
|
| - const CSSAnimationData* opacityAnim = toStyle->transitionForProperty(CSSPropertyOpacity);
|
| - if (opacityAnim && !opacityAnim->isEmptyOrZeroDuration()) {
|
| - KeyframeValueList opacityVector(AnimatedPropertyOpacity);
|
| - opacityVector.insert(adoptPtr(new FloatAnimationValue(0, compositingOpacity(fromStyle->opacity()))));
|
| - opacityVector.insert(adoptPtr(new FloatAnimationValue(1, compositingOpacity(toStyle->opacity()))));
|
| - // The boxSize param is only used for transform animations (which can only run on RenderBoxes), so we pass an empty size here.
|
| - if (m_graphicsLayer->addAnimation(opacityVector, IntSize(), opacityAnim, GraphicsLayer::animationNameForTransition(AnimatedPropertyOpacity), timeOffset)) {
|
| - // To ensure that the correct opacity is visible when the animation ends, also set the final opacity.
|
| - updateOpacity(toStyle);
|
| - didAnimate = true;
|
| - }
|
| - }
|
| + fromOpacity = compositingOpacity(fromStyle->opacity());
|
| + toOpacity = compositingOpacity(toStyle->opacity());
|
| }
|
| -
|
| - if (property == CSSPropertyWebkitTransform && m_owningLayer->hasTransform()) {
|
| - const CSSAnimationData* transformAnim = toStyle->transitionForProperty(CSSPropertyWebkitTransform);
|
| - if (transformAnim && !transformAnim->isEmptyOrZeroDuration()) {
|
| - KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
|
| - transformVector.insert(adoptPtr(new TransformAnimationValue(0, &fromStyle->transform())));
|
| - transformVector.insert(adoptPtr(new TransformAnimationValue(1, &toStyle->transform())));
|
| - if (m_graphicsLayer->addAnimation(transformVector, toRenderBox(renderer())->pixelSnappedBorderBoxRect().size(), transformAnim, GraphicsLayer::animationNameForTransition(AnimatedPropertyWebkitTransform), timeOffset)) {
|
| - // To ensure that the correct transform is visible when the animation ends, also set the final transform.
|
| - updateTransform(toStyle);
|
| - didAnimate = true;
|
| - }
|
| - }
|
| + WebAnimations animations(m_animationProvider->startTransition(timeOffset, property, fromStyle,
|
| + toStyle, m_owningLayer->hasTransform(), m_owningLayer->hasFilter(), boxSize, fromOpacity, toOpacity));
|
| + bool didAnimate = false;
|
| + if (animations.m_transformAnimation && m_graphicsLayer->addAnimation(animations.m_transformAnimation.get())) {
|
| + // To ensure that the correct transform is visible when the animation ends, also set the final transform.
|
| + updateTransform(toStyle);
|
| + didAnimate = true;
|
| }
|
| -
|
| - if (property == CSSPropertyWebkitFilter && m_owningLayer->hasFilter()) {
|
| - const CSSAnimationData* filterAnim = toStyle->transitionForProperty(CSSPropertyWebkitFilter);
|
| - if (filterAnim && !filterAnim->isEmptyOrZeroDuration()) {
|
| - KeyframeValueList filterVector(AnimatedPropertyWebkitFilter);
|
| - filterVector.insert(adoptPtr(new FilterAnimationValue(0, &fromStyle->filter())));
|
| - filterVector.insert(adoptPtr(new FilterAnimationValue(1, &toStyle->filter())));
|
| - if (m_graphicsLayer->addAnimation(filterVector, IntSize(), filterAnim, GraphicsLayer::animationNameForTransition(AnimatedPropertyWebkitFilter), timeOffset)) {
|
| - // To ensure that the correct filter is visible when the animation ends, also set the final filter.
|
| - updateFilters(toStyle);
|
| - didAnimate = true;
|
| - }
|
| - }
|
| + if (animations.m_opacityAnimation && m_graphicsLayer->addAnimation(animations.m_opacityAnimation.get())) {
|
| + // To ensure that the correct opacity is visible when the animation ends, also set the final opacity.
|
| + updateOpacity(toStyle);
|
| + didAnimate = true;
|
| + }
|
| + if (animations.m_filterAnimation && m_graphicsLayer->addAnimation(animations.m_filterAnimation.get())) {
|
| + // To ensure that the correct filter is visible when the animation ends, also set the final filter.
|
| + updateFilters(toStyle);
|
| + didAnimate = true;
|
| }
|
|
|
| return didAnimate;
|
| @@ -1786,16 +1746,16 @@ bool RenderLayerBacking::startTransition(double timeOffset, CSSPropertyID proper
|
|
|
| void RenderLayerBacking::transitionPaused(double timeOffset, CSSPropertyID property)
|
| {
|
| - AnimatedPropertyID animatedProperty = cssToGraphicsLayerProperty(property);
|
| - if (animatedProperty != AnimatedPropertyInvalid)
|
| - m_graphicsLayer->pauseAnimation(GraphicsLayer::animationNameForTransition(animatedProperty), timeOffset);
|
| + int animationId = m_animationProvider->getWebAnimationId(property);
|
| + if (animationId)
|
| + m_graphicsLayer->pauseAnimation(animationId, timeOffset);
|
| }
|
|
|
| void RenderLayerBacking::transitionFinished(CSSPropertyID property)
|
| {
|
| - AnimatedPropertyID animatedProperty = cssToGraphicsLayerProperty(property);
|
| - if (animatedProperty != AnimatedPropertyInvalid)
|
| - m_graphicsLayer->removeAnimation(GraphicsLayer::animationNameForTransition(animatedProperty));
|
| + int animationId = m_animationProvider->getWebAnimationId(property);
|
| + if (animationId)
|
| + m_graphicsLayer->removeAnimation(animationId);
|
| }
|
|
|
| void RenderLayerBacking::notifyAnimationStarted(const GraphicsLayer*, double time)
|
| @@ -1824,46 +1784,6 @@ void RenderLayerBacking::setCompositedBounds(const IntRect& bounds)
|
| m_compositedBounds = bounds;
|
| }
|
|
|
| -CSSPropertyID RenderLayerBacking::graphicsLayerToCSSProperty(AnimatedPropertyID property)
|
| -{
|
| - CSSPropertyID cssProperty = CSSPropertyInvalid;
|
| - switch (property) {
|
| - case AnimatedPropertyWebkitTransform:
|
| - cssProperty = CSSPropertyWebkitTransform;
|
| - break;
|
| - case AnimatedPropertyOpacity:
|
| - cssProperty = CSSPropertyOpacity;
|
| - break;
|
| - case AnimatedPropertyBackgroundColor:
|
| - cssProperty = CSSPropertyBackgroundColor;
|
| - break;
|
| - case AnimatedPropertyWebkitFilter:
|
| - cssProperty = CSSPropertyWebkitFilter;
|
| - break;
|
| - case AnimatedPropertyInvalid:
|
| - ASSERT_NOT_REACHED();
|
| - }
|
| - return cssProperty;
|
| -}
|
| -
|
| -AnimatedPropertyID RenderLayerBacking::cssToGraphicsLayerProperty(CSSPropertyID cssProperty)
|
| -{
|
| - switch (cssProperty) {
|
| - case CSSPropertyWebkitTransform:
|
| - return AnimatedPropertyWebkitTransform;
|
| - case CSSPropertyOpacity:
|
| - return AnimatedPropertyOpacity;
|
| - case CSSPropertyBackgroundColor:
|
| - return AnimatedPropertyBackgroundColor;
|
| - case CSSPropertyWebkitFilter:
|
| - return AnimatedPropertyWebkitFilter;
|
| - default:
|
| - // It's fine if we see other css properties here; they are just not accelerated.
|
| - break;
|
| - }
|
| - return AnimatedPropertyInvalid;
|
| -}
|
| -
|
| CompositingLayerType RenderLayerBacking::compositingLayerType() const
|
| {
|
| if (m_graphicsLayer->hasContentsLayer())
|
|
|