diff options
Diffstat (limited to 'WebCore/page/animation/AnimationBase.cpp')
-rw-r--r-- | WebCore/page/animation/AnimationBase.cpp | 183 |
1 files changed, 142 insertions, 41 deletions
diff --git a/WebCore/page/animation/AnimationBase.cpp b/WebCore/page/animation/AnimationBase.cpp index 3e43f66..e500fe4 100644 --- a/WebCore/page/animation/AnimationBase.cpp +++ b/WebCore/page/animation/AnimationBase.cpp @@ -29,7 +29,7 @@ #include "config.h" #include "AnimationBase.h" -#include "AnimationController.h" +#include "AnimationControllerPrivate.h" #include "CSSMutableStyleDeclaration.h" #include "CSSPropertyLonghand.h" #include "CSSPropertyNames.h" @@ -43,10 +43,15 @@ #include "ImplicitAnimation.h" #include "KeyframeAnimation.h" #include "MatrixTransformOperation.h" -#include "RenderObject.h" +#include "Matrix3DTransformOperation.h" +#include "RenderBox.h" #include "RenderStyle.h" #include "UnitBezier.h" +#include <algorithm> + +using namespace std; + namespace WebCore { // The epsilon value we pass to UnitBezier::solve given that the animation is going to run over |dur| seconds. The longer the @@ -143,7 +148,7 @@ static inline TransformOperations blendFunc(const AnimationBase* anim, const Tra toT.blend(fromT, progress); // Append the result - result.operations().append(MatrixTransformOperation::create(toT.a(), toT.b(), toT.c(), toT.d(), toT.e(), toT.f())); + result.operations().append(Matrix3DTransformOperation::create(toT)); } return result; } @@ -180,6 +185,10 @@ public: int property() const { return m_prop; } +#if USE(ACCELERATED_COMPOSITING) + virtual bool animationIsAccelerated() const { return false; } +#endif + private: int m_prop; }; @@ -197,7 +206,7 @@ public: { // If the style pointers are the same, don't bother doing the test. // If either is null, return false. If both are null, return true. - if (!a && !b || a == b) + if ((!a && !b) || a == b) return true; if (!a || !b) return false; @@ -226,6 +235,41 @@ protected: void (RenderStyle::*m_setter)(T); }; +#if USE(ACCELERATED_COMPOSITING) +class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> { +public: + PropertyWrapperAcceleratedOpacity() + : PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity) + { + } + + virtual bool animationIsAccelerated() const { return true; } + + virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const + { + float fromOpacity = a->opacity(); + + // This makes sure we put the object being animated into a RenderLayer during the animation + dst->setOpacity(blendFunc(anim, (fromOpacity == 1) ? 0.999999f : fromOpacity, b->opacity(), progress)); + } +}; + +class PropertyWrapperAcceleratedTransform : public PropertyWrapper<const TransformOperations&> { +public: + PropertyWrapperAcceleratedTransform() + : PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform) + { + } + + virtual bool animationIsAccelerated() const { return true; } + + virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const + { + dst->setTransform(blendFunc(anim, a->transform(), b->transform(), progress)); + } +}; +#endif // USE(ACCELERATED_COMPOSITING) + class PropertyWrapperShadow : public PropertyWrapperGetter<ShadowData*> { public: PropertyWrapperShadow(int prop, ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(ShadowData*, bool)) @@ -239,7 +283,7 @@ public: ShadowData* shadowA = (a->*m_getter)(); ShadowData* shadowB = (b->*m_getter)(); - if (!shadowA && shadowB || shadowA && !shadowB) + if ((!shadowA && shadowB) || (shadowA && !shadowB)) return false; if (shadowA && shadowB && (*shadowA != *shadowB)) return false; @@ -368,7 +412,6 @@ static void ensurePropertyMap() gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyPaddingRight, &RenderStyle::paddingRight, &RenderStyle::setPaddingRight)); gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyPaddingTop, &RenderStyle::paddingTop, &RenderStyle::setPaddingTop)); gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyPaddingBottom, &RenderStyle::paddingBottom, &RenderStyle::setPaddingBottom)); - gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity)); gPropertyWrappers->append(new PropertyWrapper<const Color&>(CSSPropertyColor, &RenderStyle::color, &RenderStyle::setColor)); gPropertyWrappers->append(new PropertyWrapper<const Color&>(CSSPropertyBackgroundColor, &RenderStyle::backgroundColor, &RenderStyle::setBackgroundColor)); gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyFontSize, &RenderStyle::fontSize, &RenderStyle::setBlendedFontSize)); @@ -384,15 +427,27 @@ static void ensurePropertyMap() gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyOutlineWidth, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth)); gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyLetterSpacing, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing)); gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyWordSpacing, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing)); - gPropertyWrappers->append(new PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform)); + gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitPerspective, &RenderStyle::perspective, &RenderStyle::setPerspective)); + gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginX, &RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX)); + gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginY, &RenderStyle::perspectiveOriginY, &RenderStyle::setPerspectiveOriginY)); gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitTransformOriginX, &RenderStyle::transformOriginX, &RenderStyle::setTransformOriginX)); gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitTransformOriginY, &RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY)); + gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitTransformOriginZ, &RenderStyle::transformOriginZ, &RenderStyle::setTransformOriginZ)); gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyWebkitBorderTopLeftRadius, &RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius)); gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyWebkitBorderTopRightRadius, &RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius)); gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyWebkitBorderBottomLeftRadius, &RenderStyle::borderBottomLeftRadius, &RenderStyle::setBorderBottomLeftRadius)); gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyWebkitBorderBottomRightRadius, &RenderStyle::borderBottomRightRadius, &RenderStyle::setBorderBottomRightRadius)); gPropertyWrappers->append(new PropertyWrapper<EVisibility>(CSSPropertyVisibility, &RenderStyle::visibility, &RenderStyle::setVisibility)); gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyZoom, &RenderStyle::zoom, &RenderStyle::setZoom)); + +#if USE(ACCELERATED_COMPOSITING) + gPropertyWrappers->append(new PropertyWrapperAcceleratedOpacity()); + gPropertyWrappers->append(new PropertyWrapperAcceleratedTransform()); +#else + gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity)); + gPropertyWrappers->append(new PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform)); +#endif + gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyWebkitColumnRuleColor, &RenderStyle::columnRuleColor, &RenderStyle::setColumnRuleColor)); gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyWebkitTextStrokeColor, &RenderStyle::textStrokeColor, &RenderStyle::setTextStrokeColor)); gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyWebkitTextFillColor, &RenderStyle::textFillColor, &RenderStyle::setTextFillColor)); @@ -507,13 +562,13 @@ static PropertyWrapperBase* wrapperForProperty(int propertyID) AnimationBase::AnimationBase(const Animation* transition, RenderObject* renderer, CompositeAnimation* compAnim) : m_animState(AnimationStateNew) , m_isAnimating(false) - , m_waitedForResponse(false) , m_startTime(0) , m_pauseTime(-1) , m_requestedStartTime(0) , m_object(renderer) , m_animation(const_cast<Animation*>(transition)) , m_compAnim(compAnim) + , m_fallbackAnimating(false) , m_transformFunctionListValid(false) , m_nextIterationDuration(-1) , m_next(0) @@ -526,8 +581,8 @@ AnimationBase::AnimationBase(const Animation* transition, RenderObject* renderer AnimationBase::~AnimationBase() { - if (m_animState == AnimationStateStartWaitStyleAvailable) - m_compAnim->removeFromStyleAvailableWaitList(this); + m_compAnim->removeFromStyleAvailableWaitList(this); + m_compAnim->removeFromStartTimeResponseWaitList(this); } bool AnimationBase::propertiesEqual(int prop, const RenderStyle* a, const RenderStyle* b) @@ -575,12 +630,25 @@ bool AnimationBase::blendProperties(const AnimationBase* anim, int prop, RenderS PropertyWrapperBase* wrapper = wrapperForProperty(prop); if (wrapper) { wrapper->blend(anim, dst, a, b, progress); +#if USE(ACCELERATED_COMPOSITING) + return !wrapper->animationIsAccelerated() || anim->isFallbackAnimating(); +#else return true; +#endif } return false; } +#if USE(ACCELERATED_COMPOSITING) +bool AnimationBase::animationOfPropertyIsAccelerated(int prop) +{ + ensurePropertyMap(); + PropertyWrapperBase* wrapper = wrapperForProperty(prop); + return wrapper ? wrapper->animationIsAccelerated() : false; +} +#endif + void AnimationBase::setChanged(Node* node) { ASSERT(!node || (node->document() && !node->document()->inPageCache())); @@ -614,7 +682,6 @@ void AnimationBase::updateStateMachine(AnimStateInput input, double param) m_pauseTime = -1; m_requestedStartTime = 0; m_nextIterationDuration = -1; - m_waitedForResponse = false; endAnimation(false); return; } @@ -661,11 +728,10 @@ void AnimationBase::updateStateMachine(AnimStateInput input, double param) } // Execute state machine - switch(m_animState) { + switch (m_animState) { case AnimationStateNew: ASSERT(input == AnimationStateInputStartAnimation || input == AnimationStateInputPlayStateRunnning || input == AnimationStateInputPlayStatePaused); if (input == AnimationStateInputStartAnimation || input == AnimationStateInputPlayStateRunnning) { - m_waitedForResponse = false; m_requestedStartTime = beginAnimationUpdateTime(); m_animState = AnimationStateStartWaitTimer; } @@ -681,7 +747,7 @@ void AnimationBase::updateStateMachine(AnimStateInput input, double param) // Trigger a render so we can start the animation if (m_object) - m_object->animation()->addNodeChangeToDispatch(m_object->element()); + m_compAnim->animationControllerPriv()->addNodeChangeToDispatch(m_object->node()); } else { ASSERT(!paused()); // We're waiting for the start timer to fire and we got a pause. Cancel the timer, pause and wait @@ -701,12 +767,18 @@ void AnimationBase::updateStateMachine(AnimStateInput input, double param) onAnimationStart(0); // The elapsedTime is always 0 here // Start the animation - if (overridden() || !startAnimation(0)) { - // We're not going to get a startTime callback, so fire the start time here + if (overridden()) { + // We won't try to start accelerated animations if we are overridden and + // just move on to the next state. m_animState = AnimationStateStartWaitResponse; + m_fallbackAnimating = true; updateStateMachine(AnimationStateInputStartTimeSet, beginAnimationUpdateTime()); - } else - m_waitedForResponse = true; + } + else { + bool started = startAnimation(0); + m_compAnim->addToStartTimeResponseWaitList(this, started); + m_fallbackAnimating = !started; + } break; case AnimationStateStartWaitResponse: ASSERT(input == AnimationStateInputStartTimeSet || input == AnimationStateInputPlayStatePaused); @@ -722,7 +794,7 @@ void AnimationBase::updateStateMachine(AnimStateInput input, double param) // Dispatch updateRendering so we can start the animation if (m_object) - m_object->animation()->addNodeChangeToDispatch(m_object->element()); + m_compAnim->animationControllerPriv()->addNodeChangeToDispatch(m_object->node()); } else { // We are pausing while waiting for a start response. Cancel the animation and wait. When // we unpause, we will act as though the start timer just fired @@ -762,7 +834,7 @@ void AnimationBase::updateStateMachine(AnimStateInput input, double param) resumeOverriddenAnimations(); // Fire off another style change so we can set the final value - m_object->animation()->addNodeChangeToDispatch(m_object->element()); + m_compAnim->animationControllerPriv()->addNodeChangeToDispatch(m_object->node()); } } else { // We are pausing while running. Cancel the animation and wait @@ -789,8 +861,19 @@ void AnimationBase::updateStateMachine(AnimStateInput input, double param) // AnimationStatePausedWaitResponse, we don't yet have a valid startTime, so we send 0 to startAnimation. // When the AnimationStateInputStartTimeSet comes in and we were in AnimationStatePausedRun, we will notice // that we have already set the startTime and will ignore it. - ASSERT(input == AnimationStateInputPlayStateRunnning); + ASSERT(input == AnimationStateInputPlayStateRunnning || input == AnimationStateInputStartTimeSet); ASSERT(paused()); + + // If we are paused, but we get the callback that notifies us that an accelerated animation started, + // then we ignore the start time and just move into the paused-run state. + if (m_animState == AnimationStatePausedWaitResponse && input == AnimationStateInputStartTimeSet) { + m_animState = AnimationStatePausedRun; + ASSERT(m_startTime == 0); + m_startTime = param; + m_pauseTime += m_startTime; + break; + } + // Update the times if (m_animState == AnimationStatePausedRun) m_startTime += beginAnimationUpdateTime() - m_pauseTime; @@ -802,11 +885,16 @@ void AnimationBase::updateStateMachine(AnimStateInput input, double param) m_animState = AnimationStateStartWaitResponse; // Start the animation - if (overridden() || !startAnimation(m_startTime)) { - // We're not going to get a startTime callback, so fire the start time here + if (overridden()) { + // We won't try to start accelerated animations if we are overridden and + // just move on to the next state. updateStateMachine(AnimationStateInputStartTimeSet, beginAnimationUpdateTime()); - } else - m_waitedForResponse = true; + m_fallbackAnimating = true; + } else { + bool started = startAnimation(0); + m_compAnim->addToStartTimeResponseWaitList(this, started); + m_fallbackAnimating = !started; + } break; case AnimationStateDone: // We're done. Stay in this state until we are deleted @@ -835,14 +923,16 @@ void AnimationBase::fireAnimationEventsIfNeeded() } double elapsedDuration = beginAnimationUpdateTime() - m_startTime; - ASSERT(elapsedDuration >= 0); + // FIXME: we need to ensure that elapsedDuration is never < 0. If it is, this suggests that + // we had a recalcStyle() outside of beginAnimationUpdate()/endAnimationUpdate(). + // Also check in getTimeToNextEvent(). + elapsedDuration = max(elapsedDuration, 0.0); // Check for end timeout if (m_totalDuration >= 0 && elapsedDuration >= m_totalDuration) { // Fire an end event updateStateMachine(AnimationStateInputEndTimerFired, m_totalDuration); - } - else { + } else { // Check for iteration timeout if (m_nextIterationDuration < 0) { // Hasn't been set yet, set it @@ -868,18 +958,20 @@ void AnimationBase::updatePlayState(bool run) updateStateMachine(run ? AnimationStateInputPlayStateRunnning : AnimationStateInputPlayStatePaused, -1); } -double AnimationBase::willNeedService() const +double AnimationBase::willNeedService() { // Returns the time at which next service is required. -1 means no service is required. 0 means // service is required now, and > 0 means service is required that many seconds in the future. if (paused() || isNew()) return -1; - + if (m_animState == AnimationStateStartWaitTimer) { double timeFromNow = m_animation->delay() - (beginAnimationUpdateTime() - m_requestedStartTime); - return (float) ((timeFromNow > 0) ? timeFromNow : 0); + return max(timeFromNow, 0.0); } + fireAnimationEventsIfNeeded(); + // In all other cases, we need service right away. return 0; } @@ -926,31 +1018,40 @@ double AnimationBase::progress(double scale, double offset, const TimingFunction return result; } -void AnimationBase::goIntoEndingOrLoopingState() +void AnimationBase::getTimeToNextEvent(double& time, bool& isLooping) const { // Decide when the end or loop event needs to fire double totalDuration = -1; if (m_animation->iterationCount() > 0) totalDuration = m_animation->duration() * m_animation->iterationCount(); - const double elapsedDuration = beginAnimationUpdateTime() - m_startTime; - ASSERT(elapsedDuration >= 0); + const double elapsedDuration = max(beginAnimationUpdateTime() - m_startTime, 0.0); double durationLeft = 0; - double nextIterationTime = totalDuration; + double nextIterationTime = m_totalDuration; - if (totalDuration < 0 || elapsedDuration < totalDuration) { + if (m_totalDuration < 0 || elapsedDuration < m_totalDuration) { durationLeft = m_animation->duration() - fmod(elapsedDuration, m_animation->duration()); nextIterationTime = elapsedDuration + durationLeft; } - - if (totalDuration < 0 || nextIterationTime < totalDuration) { + + if (m_totalDuration < 0 || nextIterationTime < m_totalDuration) { // We are not at the end yet ASSERT(nextIterationTime > 0); - m_animState = AnimationStateLooping; + isLooping = true; } else { // We are at the end - m_animState = AnimationStateEnding; + isLooping = false; } + + time = durationLeft; +} + +void AnimationBase::goIntoEndingOrLoopingState() +{ + double t; + bool isLooping; + getTimeToNextEvent(t, isLooping); + m_animState = isLooping ? AnimationStateLooping : AnimationStateEnding; } void AnimationBase::pauseAtTime(double t) @@ -961,7 +1062,7 @@ void AnimationBase::pauseAtTime(double t) double AnimationBase::beginAnimationUpdateTime() const { - return m_compAnim->animationController()->beginAnimationUpdateTime(); + return m_compAnim->animationControllerPriv()->beginAnimationUpdateTime(); } double AnimationBase::getElapsedTime() const |