diff options
author | Feng Qian <> | 2009-04-10 18:11:29 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-10 18:11:29 -0700 |
commit | 8f72e70a9fd78eec56623b3a62e68f16b7b27e28 (patch) | |
tree | 181bf9a400c30a1bf34ea6d72560e8d00111d549 /WebCore/page/animation | |
parent | 7ed56f225e0ade046e1c2178977f72b2d896f196 (diff) | |
download | external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.zip external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.gz external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.bz2 |
AI 145796: Land the WebKit merge @r42026.
Automated import of CL 145796
Diffstat (limited to 'WebCore/page/animation')
-rw-r--r-- | WebCore/page/animation/AnimationBase.cpp | 183 | ||||
-rw-r--r-- | WebCore/page/animation/AnimationBase.h | 30 | ||||
-rw-r--r-- | WebCore/page/animation/AnimationController.cpp | 243 | ||||
-rw-r--r-- | WebCore/page/animation/AnimationController.h | 19 | ||||
-rw-r--r-- | WebCore/page/animation/AnimationControllerPrivate.h | 135 | ||||
-rw-r--r-- | WebCore/page/animation/CompositeAnimation.cpp | 139 | ||||
-rw-r--r-- | WebCore/page/animation/CompositeAnimation.h | 22 | ||||
-rw-r--r-- | WebCore/page/animation/ImplicitAnimation.cpp | 77 | ||||
-rw-r--r-- | WebCore/page/animation/ImplicitAnimation.h | 9 | ||||
-rw-r--r-- | WebCore/page/animation/KeyframeAnimation.cpp | 180 | ||||
-rw-r--r-- | WebCore/page/animation/KeyframeAnimation.h | 13 |
11 files changed, 752 insertions, 298 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 diff --git a/WebCore/page/animation/AnimationBase.h b/WebCore/page/animation/AnimationBase.h index ce16f93..da4341b 100644 --- a/WebCore/page/animation/AnimationBase.h +++ b/WebCore/page/animation/AnimationBase.h @@ -94,7 +94,10 @@ public: void updateStateMachine(AnimStateInput, double param); // Animation has actually started, at passed time - void onAnimationStartResponse(double startTime); + void onAnimationStartResponse(double startTime) + { + updateStateMachine(AnimationBase::AnimationStateInputStartTimeSet, startTime); + } // Called to change to or from paused state void updatePlayState(bool running); @@ -117,12 +120,12 @@ public: // "animating" means that something is running that requires a timer to keep firing // (e.g. a software animation) void setAnimating(bool inAnimating = true) { m_isAnimating = inAnimating; } - double willNeedService() const; + virtual double willNeedService(); double progress(double scale, double offset, const TimingFunction*) const; - virtual void animate(CompositeAnimation*, RenderObject*, const RenderStyle* /*currentStyle*/, - const RenderStyle* /*targetStyle*/, RefPtr<RenderStyle>& /*animatedStyle*/) { } + virtual void animate(CompositeAnimation*, RenderObject*, const RenderStyle* /*currentStyle*/, RenderStyle* /*targetStyle*/, RefPtr<RenderStyle>& /*animatedStyle*/) = 0; + virtual void getAnimatedStyle(RefPtr<RenderStyle>& /*animatedStyle*/) = 0; virtual bool shouldFireEvents() const { return false; } @@ -142,6 +145,9 @@ public: virtual bool affectsProperty(int /*property*/) const { return false; } bool isAnimatingProperty(int property, bool isRunningNow) const { + if (m_fallbackAnimating) + return false; + if (isRunningNow) return (!waitingToStart() && !postActive()) && affectsProperty(property); @@ -164,7 +170,11 @@ public: ASSERT(waitingForStyleAvailable()); updateStateMachine(AnimationBase::AnimationStateInputStyleAvailable, -1); } - + +#if USE(ACCELERATED_COMPOSITING) + static bool animationOfPropertyIsAccelerated(int prop); +#endif + protected: virtual void overrideAnimations() { } virtual void resumeOverriddenAnimations() { } @@ -176,23 +186,26 @@ protected: virtual void onAnimationIteration(double /*elapsedTime*/) { } virtual void onAnimationEnd(double /*elapsedTime*/) { } virtual bool startAnimation(double /*beginTime*/) { return false; } - virtual void endAnimation(bool /*reset*/) { } + virtual void endAnimation(bool /*reset*/, double /*forcePauseTime*/ = -1) { } void goIntoEndingOrLoopingState(); + bool isFallbackAnimating() const { return m_fallbackAnimating; } + static bool propertiesEqual(int prop, const RenderStyle* a, const RenderStyle* b); static int getPropertyAtIndex(int, bool& isShorthand); static int getNumProperties(); // Return true if we need to start software animation timers static bool blendProperties(const AnimationBase* anim, int prop, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress); - + static void setChanged(Node*); + + void getTimeToNextEvent(double& time, bool& isLooping) const; AnimState m_animState; bool m_isAnimating; // transition/animation requires continual timer firing - bool m_waitedForResponse; double m_startTime; double m_pauseTime; double m_requestedStartTime; @@ -200,6 +213,7 @@ protected: RefPtr<Animation> m_animation; CompositeAnimation* m_compAnim; + bool m_fallbackAnimating; // true when animating an accelerated property but have to fall back to software bool m_transformFunctionListValid; double m_totalDuration, m_nextIterationDuration; diff --git a/WebCore/page/animation/AnimationController.cpp b/WebCore/page/animation/AnimationController.cpp index f85e6c1..f9c9a47 100644 --- a/WebCore/page/animation/AnimationController.cpp +++ b/WebCore/page/animation/AnimationController.cpp @@ -28,84 +28,22 @@ #include "config.h" #include "AnimationController.h" + #include "AnimationBase.h" -#include "CompositeAnimation.h" +#include "AnimationControllerPrivate.h" #include "CSSParser.h" +#include "CompositeAnimation.h" #include "EventNames.h" #include "Frame.h" -#include "Timer.h" +#include "RenderObject.h" #include <wtf/CurrentTime.h> +#include <wtf/UnusedParam.h> namespace WebCore { static const double cAnimationTimerDelay = 0.025; static const double cBeginAnimationUpdateTimeNotSet = -1; -class AnimationControllerPrivate { -public: - AnimationControllerPrivate(Frame*); - ~AnimationControllerPrivate(); - - PassRefPtr<CompositeAnimation> accessCompositeAnimation(RenderObject*); - bool clear(RenderObject*); - - void animationTimerFired(Timer<AnimationControllerPrivate>*); - void updateAnimationTimer(bool callSetChanged = false); - - void updateRenderingDispatcherFired(Timer<AnimationControllerPrivate>*); - void startUpdateRenderingDispatcher(); - void addEventToDispatch(PassRefPtr<Element> element, const AtomicString& eventType, const String& name, double elapsedTime); - void addNodeChangeToDispatch(PassRefPtr<Node>); - - bool hasAnimations() const { return !m_compositeAnimations.isEmpty(); } - - void suspendAnimations(Document*); - void resumeAnimations(Document*); - - void styleAvailable(); - - bool isAnimatingPropertyOnRenderer(RenderObject*, int property, bool isRunningNow) const; - - bool pauseAnimationAtTime(RenderObject*, const String& name, double t); - bool pauseTransitionAtTime(RenderObject*, const String& property, double t); - unsigned numberOfActiveAnimations() const; - - double beginAnimationUpdateTime() - { - if (m_beginAnimationUpdateTime == cBeginAnimationUpdateTimeNotSet) - m_beginAnimationUpdateTime = currentTime(); - return m_beginAnimationUpdateTime; - } - - void setBeginAnimationUpdateTime(double t) { m_beginAnimationUpdateTime = t; } - - void addToStyleAvailableWaitList(AnimationBase*); - void removeFromStyleAvailableWaitList(AnimationBase*); - -private: - typedef HashMap<RenderObject*, RefPtr<CompositeAnimation> > RenderObjectAnimationMap; - - RenderObjectAnimationMap m_compositeAnimations; - Timer<AnimationControllerPrivate> m_animationTimer; - Timer<AnimationControllerPrivate> m_updateRenderingDispatcher; - Frame* m_frame; - - class EventToDispatch { - public: - RefPtr<Element> element; - AtomicString eventType; - String name; - double elapsedTime; - }; - - Vector<EventToDispatch> m_eventsToDispatch; - Vector<RefPtr<Node> > m_nodeChangesToDispatch; - - double m_beginAnimationUpdateTime; - AnimationBase* m_styleAvailableWaiters; - AnimationBase* m_lastStyleAvailableWaiter; -}; - AnimationControllerPrivate::AnimationControllerPrivate(Frame* frame) : m_animationTimer(this, &AnimationControllerPrivate::animationTimerFired) , m_updateRenderingDispatcher(this, &AnimationControllerPrivate::updateRenderingDispatcherFired) @@ -113,6 +51,9 @@ AnimationControllerPrivate::AnimationControllerPrivate(Frame* frame) , m_beginAnimationUpdateTime(cBeginAnimationUpdateTimeNotSet) , m_styleAvailableWaiters(0) , m_lastStyleAvailableWaiter(0) + , m_responseWaiters(0) + , m_lastResponseWaiter(0) + , m_waitingForAResponse(false) { } @@ -124,7 +65,7 @@ PassRefPtr<CompositeAnimation> AnimationControllerPrivate::accessCompositeAnimat { RefPtr<CompositeAnimation> animation = m_compositeAnimations.get(renderer); if (!animation) { - animation = CompositeAnimation::create(m_frame->animation()); + animation = CompositeAnimation::create(this); m_compositeAnimations.set(renderer, animation); } return animation; @@ -155,7 +96,7 @@ void AnimationControllerPrivate::updateAnimationTimer(bool callSetChanged/* = fa needsService = t; if (needsService == 0) { if (callSetChanged) { - Node* node = it->first->element(); + Node* node = it->first->node(); ASSERT(!node || (node->document() && !node->document()->inPageCache())); node->setChanged(AnimationStyleChange); calledSetChanged = true; @@ -209,7 +150,7 @@ void AnimationControllerPrivate::updateRenderingDispatcherFired(Timer<AnimationC m_nodeChangesToDispatch.clear(); - if (m_frame && m_frame->document()) + if (m_frame) m_frame->document()->updateRendering(); } @@ -233,6 +174,10 @@ void AnimationControllerPrivate::addEventToDispatch(PassRefPtr<Element> element, void AnimationControllerPrivate::addNodeChangeToDispatch(PassRefPtr<Node> node) { + ASSERT(!node || (node->document() && !node->document()->inPageCache())); + if (!node) + return; + m_nodeChangesToDispatch.append(node); startUpdateRenderingDispatcher(); } @@ -240,7 +185,7 @@ void AnimationControllerPrivate::addNodeChangeToDispatch(PassRefPtr<Node> node) void AnimationControllerPrivate::animationTimerFired(Timer<AnimationControllerPrivate>*) { // Make sure animationUpdateTime is updated, so that it is current even if no - // styleChange has happened (e.g. hardware animations) + // styleChange has happened (e.g. accelerated animations) setBeginAnimationUpdateTime(cBeginAnimationUpdateTimeNotSet); // When the timer fires, all we do is call setChanged on all DOM nodes with running animations and then do an immediate @@ -248,7 +193,7 @@ void AnimationControllerPrivate::animationTimerFired(Timer<AnimationControllerPr updateAnimationTimer(true); } -bool AnimationControllerPrivate::isAnimatingPropertyOnRenderer(RenderObject* renderer, int property, bool isRunningNow) const +bool AnimationControllerPrivate::isAnimatingPropertyOnRenderer(RenderObject* renderer, CSSPropertyID property, bool isRunningNow) const { RefPtr<CompositeAnimation> animation = m_compositeAnimations.get(renderer); if (!animation) @@ -294,6 +239,7 @@ bool AnimationControllerPrivate::pauseAnimationAtTime(RenderObject* renderer, co if (compAnim->pauseAnimationAtTime(name, t)) { renderer->node()->setChanged(AnimationStyleChange); + startUpdateRenderingDispatcher(); return true; } @@ -311,12 +257,39 @@ bool AnimationControllerPrivate::pauseTransitionAtTime(RenderObject* renderer, c if (compAnim->pauseTransitionAtTime(cssPropertyID(property), t)) { renderer->node()->setChanged(AnimationStyleChange); + startUpdateRenderingDispatcher(); return true; } return false; } +double AnimationControllerPrivate::beginAnimationUpdateTime() +{ + if (m_beginAnimationUpdateTime == cBeginAnimationUpdateTimeNotSet) + m_beginAnimationUpdateTime = currentTime(); + return m_beginAnimationUpdateTime; +} + +PassRefPtr<RenderStyle> AnimationControllerPrivate::getAnimatedStyleForRenderer(RenderObject* renderer) +{ + if (!renderer) + return 0; + + RefPtr<CompositeAnimation> rendererAnimations = m_compositeAnimations.get(renderer); + if (!rendererAnimations) + return renderer->style(); + + // Make sure animationUpdateTime is updated, so that it is current even if no + // styleChange has happened (e.g. accelerated animations). + setBeginAnimationUpdateTime(cBeginAnimationUpdateTimeNotSet); + RefPtr<RenderStyle> animatingStyle = rendererAnimations->getAnimatedStyle(); + if (!animatingStyle) + animatingStyle = renderer->style(); + + return animatingStyle.release(); +} + unsigned AnimationControllerPrivate::numberOfActiveAnimations() const { unsigned count = 0; @@ -364,13 +337,83 @@ void AnimationControllerPrivate::removeFromStyleAvailableWaitList(AnimationBase* void AnimationControllerPrivate::styleAvailable() { // Go through list of waiters and send them on their way - for (AnimationBase* animation = m_styleAvailableWaiters; animation; animation = animation->next()) + for (AnimationBase* animation = m_styleAvailableWaiters; animation; ) { + AnimationBase* nextAnimation = animation->next(); + animation->setNext(0); animation->styleAvailable(); + animation = nextAnimation; + } m_styleAvailableWaiters = 0; m_lastStyleAvailableWaiter = 0; } +void AnimationControllerPrivate::addToStartTimeResponseWaitList(AnimationBase* animation, bool willGetResponse) +{ + // If willGetResponse is true, it means this animation is actually waiting for a response + // (which will come in as a call to notifyAnimationStarted()). + // In that case we don't need to add it to this list. We just set a waitingForAResponse flag + // which says we are waiting for the response. If willGetResponse is false, this animation + // is not waiting for a response for itself, but rather for a notifyXXXStarted() call for + // another animation to which it will sync. + // + // When endAnimationUpdate() is called we check to see if the waitingForAResponse flag is + // true. If so, we just return and will do our work when the first notifyXXXStarted() call + // comes in. If it is false, we will not be getting a notifyXXXStarted() call, so we will + // do our work right away. In both cases we call the onAnimationStartResponse() method + // on each animation. In the first case we send in the time we got from notifyXXXStarted(). + // In the second case, we just pass in the beginAnimationUpdateTime(). + // + // This will synchronize all software and accelerated animations started in the same + // updateRendering cycle. + // + ASSERT(!animation->next()); + + if (willGetResponse) + m_waitingForAResponse = true; + + if (m_responseWaiters) + m_lastResponseWaiter->setNext(animation); + else + m_responseWaiters = animation; + + m_lastResponseWaiter = animation; + animation->setNext(0); +} + +void AnimationControllerPrivate::removeFromStartTimeResponseWaitList(AnimationBase* animationToRemove) +{ + AnimationBase* prevAnimation = 0; + for (AnimationBase* animation = m_responseWaiters; animation; animation = animation->next()) { + if (animation == animationToRemove) { + if (prevAnimation) + prevAnimation->setNext(animation->next()); + else + m_responseWaiters = animation->next(); + + if (m_lastResponseWaiter == animation) + m_lastResponseWaiter = prevAnimation; + + animationToRemove->setNext(0); + } + prevAnimation = animation; + } +} + +void AnimationControllerPrivate::startTimeResponse(double t) +{ + // Go through list of waiters and send them on their way + for (AnimationBase* animation = m_responseWaiters; animation; ) { + AnimationBase* nextAnimation = animation->next(); + animation->setNext(0); + animation->onAnimationStartResponse(t); + animation = nextAnimation; + } + + m_responseWaiters = 0; + m_lastResponseWaiter = 0; +} + AnimationController::AnimationController(Frame* frame) : m_data(new AnimationControllerPrivate(frame)) { @@ -387,7 +430,7 @@ void AnimationController::cancelAnimations(RenderObject* renderer) return; if (m_data->clear(renderer)) { - Node* node = renderer->element(); + Node* node = renderer->node(); ASSERT(!node || (node->document() && !node->document()->inPageCache())); node->setChanged(AnimationStyleChange); } @@ -408,7 +451,7 @@ PassRefPtr<RenderStyle> AnimationController::updateAnimations(RenderObject* rend // against the animations in the style and make sure we're in sync. If destination values // have changed, we reset the animation. We then do a blend to get new values and we return // a new style. - ASSERT(renderer->element()); // FIXME: We do not animate generated content yet. + ASSERT(renderer->node()); // FIXME: We do not animate generated content yet. RefPtr<CompositeAnimation> rendererAnimations = m_data->accessCompositeAnimation(renderer); RefPtr<RenderStyle> blendedStyle = rendererAnimations->animate(renderer, oldStyle, newStyle); @@ -425,16 +468,14 @@ PassRefPtr<RenderStyle> AnimationController::updateAnimations(RenderObject* rend return blendedStyle.release(); } -void AnimationController::setAnimationStartTime(RenderObject* renderer, double t) +PassRefPtr<RenderStyle> AnimationController::getAnimatedStyleForRenderer(RenderObject* renderer) { - RefPtr<CompositeAnimation> rendererAnimations = m_data->accessCompositeAnimation(renderer); - rendererAnimations->setAnimationStartTime(t); + return m_data->getAnimatedStyleForRenderer(renderer); } -void AnimationController::setTransitionStartTime(RenderObject* renderer, int property, double t) +void AnimationController::notifyAnimationStarted(RenderObject*, double startTime) { - RefPtr<CompositeAnimation> rendererAnimations = m_data->accessCompositeAnimation(renderer); - rendererAnimations->setTransitionStartTime(property, t); + m_data->receivedStartTimeResponse(startTime); } bool AnimationController::pauseAnimationAtTime(RenderObject* renderer, const String& name, double t) @@ -452,7 +493,7 @@ bool AnimationController::pauseTransitionAtTime(RenderObject* renderer, const St return m_data->pauseTransitionAtTime(renderer, property, t); } -bool AnimationController::isAnimatingPropertyOnRenderer(RenderObject* renderer, int property, bool isRunningNow) const +bool AnimationController::isAnimatingPropertyOnRenderer(RenderObject* renderer, CSSPropertyID property, bool isRunningNow) const { return m_data->isAnimatingPropertyOnRenderer(renderer, property, isRunningNow); } @@ -467,28 +508,6 @@ void AnimationController::resumeAnimations(Document* document) m_data->resumeAnimations(document); } -void AnimationController::startUpdateRenderingDispatcher() -{ - m_data->startUpdateRenderingDispatcher(); -} - -void AnimationController::addEventToDispatch(PassRefPtr<Element> element, const AtomicString& eventType, const String& name, double elapsedTime) -{ - m_data->addEventToDispatch(element, eventType, name, elapsedTime); -} - -void AnimationController::addNodeChangeToDispatch(PassRefPtr<Node> node) -{ - ASSERT(!node || (node->document() && !node->document()->inPageCache())); - if (node) - m_data->addNodeChangeToDispatch(node); -} - -double AnimationController::beginAnimationUpdateTime() -{ - return m_data->beginAnimationUpdateTime(); -} - void AnimationController::beginAnimationUpdate() { m_data->setBeginAnimationUpdateTime(cBeginAnimationUpdateTimeNotSet); @@ -496,17 +515,17 @@ void AnimationController::beginAnimationUpdate() void AnimationController::endAnimationUpdate() { - m_data->styleAvailable(); + m_data->endAnimationUpdate(); } -void AnimationController::addToStyleAvailableWaitList(AnimationBase* animation) +bool AnimationController::supportsAcceleratedAnimationOfProperty(CSSPropertyID property) { - m_data->addToStyleAvailableWaitList(animation); -} - -void AnimationController::removeFromStyleAvailableWaitList(AnimationBase* animation) -{ - m_data->removeFromStyleAvailableWaitList(animation); +#if USE(ACCELERATED_COMPOSITING) + return AnimationBase::animationOfPropertyIsAccelerated(property); +#else + UNUSED_PARAM(property); + return false; +#endif } } // namespace WebCore diff --git a/WebCore/page/animation/AnimationController.h b/WebCore/page/animation/AnimationController.h index 13ea1bd..db82618 100644 --- a/WebCore/page/animation/AnimationController.h +++ b/WebCore/page/animation/AnimationController.h @@ -29,6 +29,7 @@ #ifndef AnimationController_h #define AnimationController_h +#include "CSSPropertyNames.h" #include <wtf/Forward.h> namespace WebCore { @@ -51,30 +52,24 @@ public: void cancelAnimations(RenderObject*); PassRefPtr<RenderStyle> updateAnimations(RenderObject*, RenderStyle* newStyle); + PassRefPtr<RenderStyle> getAnimatedStyleForRenderer(RenderObject*); - void setAnimationStartTime(RenderObject*, double t); - void setTransitionStartTime(RenderObject*, int property, double t); + // This is called when an accelerated animation or transition has actually started to animate. + void notifyAnimationStarted(RenderObject*, double startTime); bool pauseAnimationAtTime(RenderObject*, const String& name, double t); // To be used only for testing bool pauseTransitionAtTime(RenderObject*, const String& property, double t); // To be used only for testing unsigned numberOfActiveAnimations() const; // To be used only for testing - bool isAnimatingPropertyOnRenderer(RenderObject*, int property, bool isRunningNow) const; + bool isAnimatingPropertyOnRenderer(RenderObject*, CSSPropertyID, bool isRunningNow = true) const; void suspendAnimations(Document*); void resumeAnimations(Document*); - void startUpdateRenderingDispatcher(); - void addEventToDispatch(PassRefPtr<Element>, const AtomicString& eventType, const String& name, double elapsedTime); - void addNodeChangeToDispatch(PassRefPtr<Node>); - - void addToStyleAvailableWaitList(AnimationBase*); - void removeFromStyleAvailableWaitList(AnimationBase*); - - double beginAnimationUpdateTime(); - void beginAnimationUpdate(); void endAnimationUpdate(); + + static bool supportsAcceleratedAnimationOfProperty(CSSPropertyID); private: AnimationControllerPrivate* m_data; diff --git a/WebCore/page/animation/AnimationControllerPrivate.h b/WebCore/page/animation/AnimationControllerPrivate.h new file mode 100644 index 0000000..f9a3405 --- /dev/null +++ b/WebCore/page/animation/AnimationControllerPrivate.h @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef AnimationControllerPrivate_h +#define AnimationControllerPrivate_h + +#include "AtomicString.h" +#include "CSSPropertyNames.h" +#include "PlatformString.h" +#include "Timer.h" +#include <wtf/HashMap.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> +#include <wtf/Vector.h> + +namespace WebCore { + +class AnimationBase; +class CompositeAnimation; +class Document; +class Element; +class Frame; +class Node; +class RenderObject; +class RenderStyle; + +class AnimationControllerPrivate { +public: + AnimationControllerPrivate(Frame*); + ~AnimationControllerPrivate(); + + PassRefPtr<CompositeAnimation> accessCompositeAnimation(RenderObject*); + bool clear(RenderObject*); + + void animationTimerFired(Timer<AnimationControllerPrivate>*); + void updateAnimationTimer(bool callSetChanged = false); + + void updateRenderingDispatcherFired(Timer<AnimationControllerPrivate>*); + void startUpdateRenderingDispatcher(); + void addEventToDispatch(PassRefPtr<Element> element, const AtomicString& eventType, const String& name, double elapsedTime); + void addNodeChangeToDispatch(PassRefPtr<Node>); + + bool hasAnimations() const { return !m_compositeAnimations.isEmpty(); } + + void suspendAnimations(Document*); + void resumeAnimations(Document*); + + bool isAnimatingPropertyOnRenderer(RenderObject*, CSSPropertyID, bool isRunningNow) const; + + bool pauseAnimationAtTime(RenderObject*, const String& name, double t); + bool pauseTransitionAtTime(RenderObject*, const String& property, double t); + unsigned numberOfActiveAnimations() const; + + PassRefPtr<RenderStyle> getAnimatedStyleForRenderer(RenderObject* renderer); + + double beginAnimationUpdateTime(); + void setBeginAnimationUpdateTime(double t) { m_beginAnimationUpdateTime = t; } + void endAnimationUpdate() + { + styleAvailable(); + if (!m_waitingForAResponse) + startTimeResponse(beginAnimationUpdateTime()); + } + + void receivedStartTimeResponse(double t) + { + m_waitingForAResponse = false; + startTimeResponse(t); + } + + void addToStyleAvailableWaitList(AnimationBase*); + void removeFromStyleAvailableWaitList(AnimationBase*); + + void addToStartTimeResponseWaitList(AnimationBase*, bool willGetResponse); + void removeFromStartTimeResponseWaitList(AnimationBase*); + void startTimeResponse(double t); + +private: + void styleAvailable(); + + typedef HashMap<RenderObject*, RefPtr<CompositeAnimation> > RenderObjectAnimationMap; + + RenderObjectAnimationMap m_compositeAnimations; + Timer<AnimationControllerPrivate> m_animationTimer; + Timer<AnimationControllerPrivate> m_updateRenderingDispatcher; + Frame* m_frame; + + class EventToDispatch { + public: + RefPtr<Element> element; + AtomicString eventType; + String name; + double elapsedTime; + }; + + Vector<EventToDispatch> m_eventsToDispatch; + Vector<RefPtr<Node> > m_nodeChangesToDispatch; + + double m_beginAnimationUpdateTime; + AnimationBase* m_styleAvailableWaiters; + AnimationBase* m_lastStyleAvailableWaiter; + + AnimationBase* m_responseWaiters; + AnimationBase* m_lastResponseWaiter; + bool m_waitingForAResponse; +}; + +} // namespace WebCore + +#endif // AnimationControllerPrivate_h diff --git a/WebCore/page/animation/CompositeAnimation.cpp b/WebCore/page/animation/CompositeAnimation.cpp index bf61b78..d386f1b 100644 --- a/WebCore/page/animation/CompositeAnimation.cpp +++ b/WebCore/page/animation/CompositeAnimation.cpp @@ -29,7 +29,7 @@ #include "config.h" #include "CompositeAnimation.h" -#include "AnimationController.h" +#include "AnimationControllerPrivate.h" #include "CSSPropertyNames.h" #include "ImplicitAnimation.h" #include "KeyframeAnimation.h" @@ -40,7 +40,7 @@ namespace WebCore { class CompositeAnimationPrivate { public: - CompositeAnimationPrivate(AnimationController* animationController, CompositeAnimation* compositeAnimation) + CompositeAnimationPrivate(AnimationControllerPrivate* animationController, CompositeAnimation* compositeAnimation) : m_isSuspended(false) , m_animationController(animationController) , m_compositeAnimation(compositeAnimation) @@ -53,8 +53,9 @@ public: void clearRenderer(); PassRefPtr<RenderStyle> animate(RenderObject*, RenderStyle* currentStyle, RenderStyle* targetStyle); + PassRefPtr<RenderStyle> getAnimatedStyle(); - AnimationController* animationController() { return m_animationController; } + AnimationControllerPrivate* animationControllerPriv() const { return m_animationController; } void setAnimating(bool); double willNeedService() const; @@ -63,9 +64,6 @@ public: void cleanupFinishedAnimations(RenderObject*); - void setAnimationStartTime(double t); - void setTransitionStartTime(int property, double t); - void suspendAnimations(); void resumeAnimations(); bool isSuspended() const { return m_isSuspended; } @@ -80,6 +78,9 @@ public: void addToStyleAvailableWaitList(AnimationBase*); void removeFromStyleAvailableWaitList(AnimationBase*); + void addToStartTimeResponseWaitList(AnimationBase*, bool willGetResponse); + void removeFromStartTimeResponseWaitList(AnimationBase*); + bool pauseAnimationAtTime(const AtomicString& name, double t); bool pauseTransitionAtTime(int property, double t); unsigned numberOfActiveAnimations() const; @@ -94,8 +95,9 @@ private: CSSPropertyTransitionsMap m_transitions; AnimationNameMap m_keyframeAnimations; + Vector<AtomicStringImpl*> m_keyframeAnimationOrderMap; bool m_isSuspended; - AnimationController* m_animationController; + AnimationControllerPrivate* m_animationController; CompositeAnimation* m_compositeAnimation; unsigned m_numStyleAvailableWaiters; }; @@ -126,9 +128,11 @@ void CompositeAnimationPrivate::clearRenderer() } } } - + void CompositeAnimationPrivate::updateTransitions(RenderObject* renderer, RenderStyle* currentStyle, RenderStyle* targetStyle) { + RefPtr<RenderStyle> modifiedCurrentStyle; + // If currentStyle is null, we don't do transitions if (!currentStyle || !targetStyle->transitions()) return; @@ -176,6 +180,16 @@ void CompositeAnimationPrivate::updateTransitions(RenderObject* renderer, Render // list. In this case, the latter one overrides the earlier one, so we // behave as though this is a running animation being replaced. if (!implAnim->isTargetPropertyEqual(prop, targetStyle)) { +#if USE(ACCELERATED_COMPOSITING) + // For accelerated animations we need to return a new RenderStyle with the _current_ value + // of the property, so that restarted transitions use the correct starting point. + if (AnimationBase::animationOfPropertyIsAccelerated(prop) && !implAnim->isFallbackAnimating()) { + if (!modifiedCurrentStyle) + modifiedCurrentStyle = RenderStyle::clone(currentStyle); + + implAnim->blendPropertyValueInStyle(prop, modifiedCurrentStyle.get()); + } +#endif m_transitions.remove(prop); equal = false; } @@ -186,7 +200,7 @@ void CompositeAnimationPrivate::updateTransitions(RenderObject* renderer, Render if (!equal) { // Add the new transition - m_transitions.set(prop, ImplicitAnimation::create(const_cast<Animation*>(anim), prop, renderer, m_compositeAnimation, fromStyle)); + m_transitions.set(prop, ImplicitAnimation::create(const_cast<Animation*>(anim), prop, renderer, m_compositeAnimation, modifiedCurrentStyle ? modifiedCurrentStyle.get() : fromStyle)); } // We only need one pass for the single prop case @@ -210,6 +224,9 @@ void CompositeAnimationPrivate::updateKeyframeAnimations(RenderObject* renderer, AnimationNameMap::const_iterator kfend = m_keyframeAnimations.end(); for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it) it->second->setIndex(-1); + + // Toss the animation order map + m_keyframeAnimationOrderMap.clear(); // Now mark any still active animations as active and add any new animations if (targetStyle->animations()) { @@ -237,6 +254,10 @@ void CompositeAnimationPrivate::updateKeyframeAnimations(RenderObject* renderer, keyframeAnim = KeyframeAnimation::create(const_cast<Animation*>(anim), renderer, i, m_compositeAnimation, currentStyle ? currentStyle : targetStyle); m_keyframeAnimations.set(keyframeAnim->name().impl(), keyframeAnim); } + + // Add this to the animation order map + if (keyframeAnim) + m_keyframeAnimationOrderMap.append(keyframeAnim->name().impl()); } } @@ -278,17 +299,10 @@ PassRefPtr<RenderStyle> CompositeAnimationPrivate::animate(RenderObject* rendere // Now that we have animation objects ready, let them know about the new goal state. We want them // to fill in a RenderStyle*& only if needed. - if (targetStyle->hasAnimations()) { - for (size_t i = 0; i < targetStyle->animations()->size(); ++i) { - const Animation* anim = targetStyle->animations()->animation(i); - - if (anim->isValidAnimation()) { - AtomicString animationName(anim->name()); - RefPtr<KeyframeAnimation> keyframeAnim = m_keyframeAnimations.get(animationName.impl()); - if (keyframeAnim) - keyframeAnim->animate(m_compositeAnimation, renderer, currentStyle, targetStyle, resultStyle); - } - } + for (Vector<AtomicStringImpl*>::const_iterator it = m_keyframeAnimationOrderMap.begin(); it != m_keyframeAnimationOrderMap.end(); ++it) { + RefPtr<KeyframeAnimation> keyframeAnim = m_keyframeAnimations.get(*it); + if (keyframeAnim) + keyframeAnim->animate(m_compositeAnimation, renderer, currentStyle, targetStyle, resultStyle); } cleanupFinishedAnimations(renderer); @@ -296,6 +310,24 @@ PassRefPtr<RenderStyle> CompositeAnimationPrivate::animate(RenderObject* rendere return resultStyle ? resultStyle.release() : targetStyle; } +PassRefPtr<RenderStyle> CompositeAnimationPrivate::getAnimatedStyle() +{ + RefPtr<RenderStyle> resultStyle; + CSSPropertyTransitionsMap::const_iterator end = m_transitions.end(); + for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); it != end; ++it) { + if (ImplicitAnimation* implicitAnimation = it->second.get()) + implicitAnimation->getAnimatedStyle(resultStyle); + } + + for (Vector<AtomicStringImpl*>::const_iterator it = m_keyframeAnimationOrderMap.begin(); it != m_keyframeAnimationOrderMap.end(); ++it) { + RefPtr<KeyframeAnimation> keyframeAnimation = m_keyframeAnimations.get(*it); + if (keyframeAnimation) + keyframeAnimation->getAnimatedStyle(resultStyle); + } + + return resultStyle; +} + // "animating" means that something is running that requires the timer to keep firing void CompositeAnimationPrivate::setAnimating(bool animating) { @@ -409,32 +441,6 @@ void CompositeAnimationPrivate::cleanupFinishedAnimations(RenderObject*) } } -void CompositeAnimationPrivate::setAnimationStartTime(double t) -{ - // Set start time on all animations waiting for it - if (!m_keyframeAnimations.isEmpty()) { - AnimationNameMap::const_iterator end = m_keyframeAnimations.end(); - for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != end; ++it) { - KeyframeAnimation* anim = it->second.get(); - if (anim && anim->waitingForStartTime()) - anim->updateStateMachine(AnimationBase::AnimationStateInputStartTimeSet, t); - } - } -} - -void CompositeAnimationPrivate::setTransitionStartTime(int property, double t) -{ - // Set the start time for given property transition - if (!m_transitions.isEmpty()) { - CSSPropertyTransitionsMap::const_iterator end = m_transitions.end(); - for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); it != end; ++it) { - ImplicitAnimation* anim = it->second.get(); - if (anim && anim->waitingForStartTime() && anim->animatingProperty() == property) - anim->updateStateMachine(AnimationBase::AnimationStateInputStartTimeSet, t); - } - } -} - void CompositeAnimationPrivate::suspendAnimations() { if (m_isSuspended) @@ -541,6 +547,16 @@ void CompositeAnimationPrivate::removeFromStyleAvailableWaitList(AnimationBase* m_animationController->removeFromStyleAvailableWaitList(animation); } +void CompositeAnimationPrivate::addToStartTimeResponseWaitList(AnimationBase* animation, bool willGetResponse) +{ + m_animationController->addToStartTimeResponseWaitList(animation, willGetResponse); +} + +void CompositeAnimationPrivate::removeFromStartTimeResponseWaitList(AnimationBase* animation) +{ + m_animationController->removeFromStartTimeResponseWaitList(animation); +} + bool CompositeAnimationPrivate::pauseAnimationAtTime(const AtomicString& name, double t) { if (!name) @@ -601,7 +617,7 @@ unsigned CompositeAnimationPrivate::numberOfActiveAnimations() const return count; } -CompositeAnimation::CompositeAnimation(AnimationController* animationController) +CompositeAnimation::CompositeAnimation(AnimationControllerPrivate* animationController) : m_data(new CompositeAnimationPrivate(animationController, this)) { } @@ -611,9 +627,9 @@ CompositeAnimation::~CompositeAnimation() delete m_data; } -AnimationController* CompositeAnimation::animationController() +AnimationControllerPrivate* CompositeAnimation::animationControllerPriv() const { - return m_data->animationController(); + return m_data->animationControllerPriv(); } void CompositeAnimation::clearRenderer() @@ -626,6 +642,11 @@ PassRefPtr<RenderStyle> CompositeAnimation::animate(RenderObject* renderer, Rend return m_data->animate(renderer, currentStyle, targetStyle); } +PassRefPtr<RenderStyle> CompositeAnimation::getAnimatedStyle() +{ + return m_data->getAnimatedStyle(); +} + double CompositeAnimation::willNeedService() const { return m_data->willNeedService(); @@ -641,6 +662,16 @@ void CompositeAnimation::removeFromStyleAvailableWaitList(AnimationBase* animati m_data->removeFromStyleAvailableWaitList(animation); } +void CompositeAnimation::addToStartTimeResponseWaitList(AnimationBase* animation, bool willGetResponse) +{ + m_data->addToStartTimeResponseWaitList(animation, willGetResponse); +} + +void CompositeAnimation::removeFromStartTimeResponseWaitList(AnimationBase* animation) +{ + m_data->removeFromStartTimeResponseWaitList(animation); +} + void CompositeAnimation::suspendAnimations() { m_data->suspendAnimations(); @@ -676,16 +707,6 @@ PassRefPtr<KeyframeAnimation> CompositeAnimation::getAnimationForProperty(int pr return m_data->getAnimationForProperty(property); } -void CompositeAnimation::setAnimationStartTime(double t) -{ - m_data->setAnimationStartTime(t); -} - -void CompositeAnimation::setTransitionStartTime(int property, double t) -{ - m_data->setTransitionStartTime(property, t); -} - void CompositeAnimation::overrideImplicitAnimations(int property) { m_data->overrideImplicitAnimations(property); diff --git a/WebCore/page/animation/CompositeAnimation.h b/WebCore/page/animation/CompositeAnimation.h index 3517b34..b5857aa 100644 --- a/WebCore/page/animation/CompositeAnimation.h +++ b/WebCore/page/animation/CompositeAnimation.h @@ -36,6 +36,7 @@ namespace WebCore { +class AnimationControllerPrivate; class CompositeAnimationPrivate; class AnimationBase; class AnimationController; @@ -47,7 +48,7 @@ class RenderStyle; // on a single RenderObject, such as a number of properties transitioning at once. class CompositeAnimation : public RefCounted<CompositeAnimation> { public: - static PassRefPtr<CompositeAnimation> create(AnimationController* animationController) + static PassRefPtr<CompositeAnimation> create(AnimationControllerPrivate* animationController) { return adoptRef(new CompositeAnimation(animationController)); }; @@ -57,9 +58,17 @@ public: void clearRenderer(); PassRefPtr<RenderStyle> animate(RenderObject*, RenderStyle* currentStyle, RenderStyle* targetStyle); + PassRefPtr<RenderStyle> getAnimatedStyle(); + double willNeedService() const; - AnimationController* animationController(); + AnimationControllerPrivate* animationControllerPriv() const; + + void addToStyleAvailableWaitList(AnimationBase*); + void removeFromStyleAvailableWaitList(AnimationBase*); + + void addToStartTimeResponseWaitList(AnimationBase*, bool willGetResponse); + void removeFromStartTimeResponseWaitList(AnimationBase*); void suspendAnimations(); void resumeAnimations(); @@ -72,10 +81,6 @@ public: PassRefPtr<KeyframeAnimation> getAnimationForProperty(int property); - - void setAnimationStartTime(double t); - void setTransitionStartTime(int property, double t); - void overrideImplicitAnimations(int property); void resumeOverriddenImplicitAnimations(int property); @@ -83,11 +88,8 @@ public: bool pauseTransitionAtTime(int property, double t); unsigned numberOfActiveAnimations() const; - void addToStyleAvailableWaitList(AnimationBase*); - void removeFromStyleAvailableWaitList(AnimationBase*); - private: - CompositeAnimation(AnimationController* animationController); + CompositeAnimation(AnimationControllerPrivate* animationController); CompositeAnimationPrivate* m_data; }; diff --git a/WebCore/page/animation/ImplicitAnimation.cpp b/WebCore/page/animation/ImplicitAnimation.cpp index f984909..8ec0be0 100644 --- a/WebCore/page/animation/ImplicitAnimation.cpp +++ b/WebCore/page/animation/ImplicitAnimation.cpp @@ -28,13 +28,15 @@ #include "config.h" -#include "AnimationController.h" +#include "AnimationControllerPrivate.h" #include "CompositeAnimation.h" #include "CSSPropertyNames.h" #include "EventNames.h" #include "ImplicitAnimation.h" #include "KeyframeAnimation.h" -#include "RenderObject.h" +#include "RenderLayer.h" +#include "RenderLayerBacking.h" +#include <wtf/UnusedParam.h> namespace WebCore { @@ -55,12 +57,12 @@ ImplicitAnimation::~ImplicitAnimation() updateStateMachine(AnimationStateInputEndAnimation, -1); } -bool ImplicitAnimation::shouldSendEventForListener(Document::ListenerType inListenerType) +bool ImplicitAnimation::shouldSendEventForListener(Document::ListenerType inListenerType) const { return m_object->document()->hasListenerType(inListenerType); } -void ImplicitAnimation::animate(CompositeAnimation*, RenderObject*, RenderStyle*, RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle) +void ImplicitAnimation::animate(CompositeAnimation*, RenderObject*, const RenderStyle*, RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle) { // If we get this far and the animation is done, it means we are cleaning up a just finished animation. // So just return. Everything is already all cleaned up. @@ -76,13 +78,58 @@ void ImplicitAnimation::animate(CompositeAnimation*, RenderObject*, RenderStyle* if (!animatedStyle) animatedStyle = RenderStyle::clone(targetStyle); - if (blendProperties(this, m_animatingProperty, animatedStyle.get(), m_fromStyle.get(), m_toStyle.get(), progress(1, 0, 0))) + bool needsAnim = blendProperties(this, m_animatingProperty, animatedStyle.get(), m_fromStyle.get(), m_toStyle.get(), progress(1, 0, 0)); + // FIXME: we also need to detect cases where we have to software animate for other reasons, + // such as a child using inheriting the transform. https://bugs.webkit.org/show_bug.cgi?id=23902 + if (needsAnim) setAnimating(); + else { +#if USE(ACCELERATED_COMPOSITING) + // If we are running an accelerated animation, set a flag in the style which causes the style + // to compare as different to any other style. This ensures that changes to the property + // that is animating are correctly detected during the animation (e.g. when a transition + // gets interrupted). + animatedStyle->setIsRunningAcceleratedAnimation(); +#endif + } // Fire the start timeout if needed fireAnimationEventsIfNeeded(); } +void ImplicitAnimation::getAnimatedStyle(RefPtr<RenderStyle>& animatedStyle) +{ + if (!animatedStyle) + animatedStyle = RenderStyle::clone(m_toStyle.get()); + + blendProperties(this, m_animatingProperty, animatedStyle.get(), m_fromStyle.get(), m_toStyle.get(), progress(1, 0, 0)); +} + +bool ImplicitAnimation::startAnimation(double beginTime) +{ +#if USE(ACCELERATED_COMPOSITING) + if (m_object && m_object->hasLayer()) { + RenderLayer* layer = toRenderBoxModelObject(m_object)->layer(); + if (layer->isComposited()) + return layer->backing()->startTransition(beginTime, m_animatingProperty, m_fromStyle.get(), m_toStyle.get()); + } +#else + UNUSED_PARAM(beginTime); +#endif + return false; +} + +void ImplicitAnimation::endAnimation(bool /*reset*/) +{ +#if USE(ACCELERATED_COMPOSITING) + if (m_object && m_object->hasLayer()) { + RenderLayer* layer = toRenderBoxModelObject(m_object)->layer(); + if (layer->isComposited()) + layer->backing()->transitionFinished(m_animatingProperty); + } +#endif +} + void ImplicitAnimation::onAnimationEnd(double elapsedTime) { // If we have a keyframe animation on this property, this transition is being overridden. The keyframe @@ -120,7 +167,7 @@ bool ImplicitAnimation::sendTransitionEvent(const AtomicString& eventType, doubl return false; // Schedule event handling - m_object->animation()->addEventToDispatch(element, eventType, propertyName, elapsedTime); + m_compAnim->animationControllerPriv()->addEventToDispatch(element, eventType, propertyName, elapsedTime); // Restore the original (unanimated) style if (eventType == eventNames().webkitTransitionEndEvent && element->renderer()) @@ -137,7 +184,6 @@ void ImplicitAnimation::reset(RenderStyle* to) { ASSERT(to); ASSERT(m_fromStyle); - m_toStyle = to; @@ -209,4 +255,21 @@ void ImplicitAnimation::validateTransformFunctionList() m_transformFunctionListValid = true; } +double ImplicitAnimation::willNeedService() +{ + double t = AnimationBase::willNeedService(); +#if USE(ACCELERATED_COMPOSITING) + if (t != 0 || preActive()) + return t; + + // A return value of 0 means we need service. But if this is an accelerated animation we + // only need service at the end of the transition. + if (animationOfPropertyIsAccelerated(m_animatingProperty) && !isFallbackAnimating()) { + bool isLooping; + getTimeToNextEvent(t, isLooping); + } +#endif + return t; +} + } // namespace WebCore diff --git a/WebCore/page/animation/ImplicitAnimation.h b/WebCore/page/animation/ImplicitAnimation.h index cf98bba..221c45e 100644 --- a/WebCore/page/animation/ImplicitAnimation.h +++ b/WebCore/page/animation/ImplicitAnimation.h @@ -47,8 +47,11 @@ public: int animatingProperty() const { return m_animatingProperty; } virtual void onAnimationEnd(double elapsedTime); + virtual bool startAnimation(double beginTime); + virtual void endAnimation(bool reset); - virtual void animate(CompositeAnimation*, RenderObject*, RenderStyle* currentStyle, RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle); + virtual void animate(CompositeAnimation*, RenderObject*, const RenderStyle* currentStyle, RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle); + virtual void getAnimatedStyle(RefPtr<RenderStyle>& animatedStyle); virtual void reset(RenderStyle* to); void setOverridden(bool); @@ -62,8 +65,10 @@ public: void blendPropertyValueInStyle(int, RenderStyle* currentStyle); + virtual double willNeedService(); + protected: - bool shouldSendEventForListener(Document::ListenerType); + bool shouldSendEventForListener(Document::ListenerType) const; bool sendTransitionEvent(const AtomicString&, double elapsedTime); void validateTransformFunctionList(); diff --git a/WebCore/page/animation/KeyframeAnimation.cpp b/WebCore/page/animation/KeyframeAnimation.cpp index 2efa578..88a5f6a 100644 --- a/WebCore/page/animation/KeyframeAnimation.cpp +++ b/WebCore/page/animation/KeyframeAnimation.cpp @@ -29,12 +29,14 @@ #include "config.h" #include "KeyframeAnimation.h" -#include "AnimationController.h" +#include "AnimationControllerPrivate.h" #include "CSSPropertyNames.h" #include "CSSStyleSelector.h" #include "CompositeAnimation.h" #include "EventNames.h" -#include "RenderObject.h" +#include "RenderLayer.h" +#include "RenderLayerBacking.h" +#include <wtf/UnusedParam.h> namespace WebCore { @@ -45,8 +47,8 @@ KeyframeAnimation::KeyframeAnimation(const Animation* animation, RenderObject* r , m_unanimatedStyle(unanimatedStyle) { // Get the keyframe RenderStyles - if (m_object && m_object->element() && m_object->element()->isElementNode()) - m_object->document()->styleSelector()->keyframeStylesForAnimation(static_cast<Element*>(m_object->element()), unanimatedStyle, m_keyframes); + if (m_object && m_object->node() && m_object->node()->isElementNode()) + m_object->document()->styleSelector()->keyframeStylesForAnimation(static_cast<Element*>(m_object->node()), unanimatedStyle, m_keyframes); // Update the m_transformFunctionListValid flag based on whether the function lists in the keyframes match. validateTransformFunctionList(); @@ -59,32 +61,8 @@ KeyframeAnimation::~KeyframeAnimation() updateStateMachine(AnimationStateInputEndAnimation, -1); } -void KeyframeAnimation::animate(CompositeAnimation*, RenderObject*, const RenderStyle*, const RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle) +void KeyframeAnimation::getKeyframeAnimationInterval(const RenderStyle*& fromStyle, const RenderStyle*& toStyle, double& prog) const { - // Fire the start timeout if needed - fireAnimationEventsIfNeeded(); - - // If we have not yet started, we will not have a valid start time, so just start the animation if needed. - if (isNew() && m_animation->playState() == AnimPlayStatePlaying) - updateStateMachine(AnimationStateInputStartAnimation, -1); - - // If we get this far and the animation is done, it means we are cleaning up a just finished animation. - // If so, we need to send back the targetStyle. - if (postActive()) { - if (!animatedStyle) - animatedStyle = const_cast<RenderStyle*>(targetStyle); - return; - } - - // If we are waiting for the start timer, we don't want to change the style yet. - // Special case - if the delay time is 0, then we do want to set the first frame of the - // animation right away. This avoids a flash when the animation starts. - if (waitingToStart() && m_animation->delay() > 0) - return; - - // FIXME: we need to be more efficient about determining which keyframes we are animating between. - // We should cache the last pair or something. - // Find the first key double elapsedTime = getElapsedTime(); @@ -94,8 +72,6 @@ void KeyframeAnimation::animate(CompositeAnimation*, RenderObject*, const Render if (m_animation->direction() && (i & 1)) t = 1 - t; - const RenderStyle* fromStyle = 0; - const RenderStyle* toStyle = 0; double scale = 1; double offset = 0; Vector<KeyframeValue>::const_iterator endKeyframes = m_keyframes.endKeyframes(); @@ -113,6 +89,48 @@ void KeyframeAnimation::animate(CompositeAnimation*, RenderObject*, const Render fromStyle = it->style(); } + if (!fromStyle || !toStyle) + return; + + const TimingFunction* timingFunction = 0; + if (fromStyle->animations() && fromStyle->animations()->size() > 0) + timingFunction = &(fromStyle->animations()->animation(0)->timingFunction()); + + prog = progress(scale, offset, timingFunction); +} + +void KeyframeAnimation::animate(CompositeAnimation*, RenderObject*, const RenderStyle*, RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle) +{ + // Fire the start timeout if needed + fireAnimationEventsIfNeeded(); + + // If we have not yet started, we will not have a valid start time, so just start the animation if needed. + if (isNew() && m_animation->playState() == AnimPlayStatePlaying) + updateStateMachine(AnimationStateInputStartAnimation, -1); + + // If we get this far and the animation is done, it means we are cleaning up a just finished animation. + // If so, we need to send back the targetStyle. + if (postActive()) { + if (!animatedStyle) + animatedStyle = const_cast<RenderStyle*>(targetStyle); + return; + } + + // If we are waiting for the start timer, we don't want to change the style yet. + // Special case - if the delay time is 0, then we do want to set the first frame of the + // animation right away. This avoids a flash when the animation starts. + if (waitingToStart() && m_animation->delay() > 0) + return; + + // FIXME: we need to be more efficient about determining which keyframes we are animating between. + // We should cache the last pair or something. + + // Get the from/to styles and progress between + const RenderStyle* fromStyle = 0; + const RenderStyle* toStyle = 0; + double progress; + getKeyframeAnimationInterval(fromStyle, toStyle, progress); + // If either style is 0 we have an invalid case, just stop the animation. if (!fromStyle || !toStyle) { updateStateMachine(AnimationStateInputEndAnimation, -1); @@ -124,19 +142,42 @@ void KeyframeAnimation::animate(CompositeAnimation*, RenderObject*, const Render if (!animatedStyle) animatedStyle = RenderStyle::clone(targetStyle); - const TimingFunction* timingFunction = 0; - if (fromStyle->animations() && fromStyle->animations()->size() > 0) - timingFunction = &(fromStyle->animations()->animation(0)->timingFunction()); - - double prog = progress(scale, offset, timingFunction); - HashSet<int>::const_iterator endProperties = m_keyframes.endProperties(); for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != endProperties; ++it) { - if (blendProperties(this, *it, animatedStyle.get(), fromStyle, toStyle, prog)) + bool needsAnim = blendProperties(this, *it, animatedStyle.get(), fromStyle, toStyle, progress); + if (needsAnim) setAnimating(); + else { +#if USE(ACCELERATED_COMPOSITING) + // If we are running an accelerated animation, set a flag in the style + // to indicate it. This can be used to make sure we get an updated + // style for hit testing, etc. + animatedStyle->setIsRunningAcceleratedAnimation(); +#endif + } } } +void KeyframeAnimation::getAnimatedStyle(RefPtr<RenderStyle>& animatedStyle) +{ + // Get the from/to styles and progress between + const RenderStyle* fromStyle = 0; + const RenderStyle* toStyle = 0; + double progress; + getKeyframeAnimationInterval(fromStyle, toStyle, progress); + + // If either style is 0 we have an invalid case + if (!fromStyle || !toStyle) + return; + + if (!animatedStyle) + animatedStyle = RenderStyle::clone(m_object->style()); + + HashSet<int>::const_iterator endProperties = m_keyframes.endProperties(); + for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != endProperties; ++it) + blendProperties(this, *it, animatedStyle.get(), fromStyle, toStyle, progress); +} + bool KeyframeAnimation::hasAnimationForProperty(int property) const { HashSet<int>::const_iterator end = m_keyframes.endProperties(); @@ -148,14 +189,38 @@ bool KeyframeAnimation::hasAnimationForProperty(int property) const return false; } -void KeyframeAnimation::endAnimation(bool) +bool KeyframeAnimation::startAnimation(double beginTime) +{ +#if USE(ACCELERATED_COMPOSITING) + if (m_object && m_object->hasLayer()) { + RenderLayer* layer = toRenderBoxModelObject(m_object)->layer(); + if (layer->isComposited()) + return layer->backing()->startAnimation(beginTime, m_animation.get(), m_keyframes); + } +#else + UNUSED_PARAM(beginTime); +#endif + return false; +} + +void KeyframeAnimation::endAnimation(bool reset) { - // Restore the original (unanimated) style - if (m_object) - setChanged(m_object->element()); + if (m_object) { +#if USE(ACCELERATED_COMPOSITING) + if (m_object->hasLayer()) { + RenderLayer* layer = toRenderBoxModelObject(m_object)->layer(); + if (layer->isComposited()) + layer->backing()->animationFinished(m_keyframes.animationName(), 0, reset); + } +#else + UNUSED_PARAM(reset); +#endif + // Restore the original (unanimated) style + setChanged(m_object->node()); + } } -bool KeyframeAnimation::shouldSendEventForListener(Document::ListenerType listenerType) +bool KeyframeAnimation::shouldSendEventForListener(Document::ListenerType listenerType) const { return m_object->document()->hasListenerType(listenerType); } @@ -201,7 +266,7 @@ bool KeyframeAnimation::sendAnimationEvent(const AtomicString& eventType, double return false; // Schedule event handling - m_object->animation()->addEventToDispatch(element, eventType, m_keyframes.animationName(), elapsedTime); + m_compAnim->animationControllerPriv()->addEventToDispatch(element, eventType, m_keyframes.animationName(), elapsedTime); // Restore the original (unanimated) style if (eventType == eventNames().webkitAnimationEndEvent && element->renderer()) @@ -287,4 +352,31 @@ void KeyframeAnimation::validateTransformFunctionList() m_transformFunctionListValid = true; } +double KeyframeAnimation::willNeedService() +{ + double t = AnimationBase::willNeedService(); +#if USE(ACCELERATED_COMPOSITING) + if (t != 0 || preActive()) + return t; + + // A return value of 0 means we need service. But if we only have accelerated animations we + // only need service at the end of the transition + HashSet<int>::const_iterator endProperties = m_keyframes.endProperties(); + bool acceleratedPropertiesOnly = true; + + for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != endProperties; ++it) { + if (!animationOfPropertyIsAccelerated(*it) || isFallbackAnimating()) { + acceleratedPropertiesOnly = false; + break; + } + } + + if (acceleratedPropertiesOnly) { + bool isLooping; + getTimeToNextEvent(t, isLooping); + } +#endif + return t; +} + } // namespace WebCore diff --git a/WebCore/page/animation/KeyframeAnimation.h b/WebCore/page/animation/KeyframeAnimation.h index 5c3176c..1090e5b 100644 --- a/WebCore/page/animation/KeyframeAnimation.h +++ b/WebCore/page/animation/KeyframeAnimation.h @@ -44,8 +44,9 @@ public: { return adoptRef(new KeyframeAnimation(animation, renderer, index, compositeAnimation, unanimatedStyle)); }; - - virtual void animate(CompositeAnimation*, RenderObject*, const RenderStyle* currentStyle, const RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle); + + virtual void animate(CompositeAnimation*, RenderObject*, const RenderStyle* currentStyle, RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle); + virtual void getAnimatedStyle(RefPtr<RenderStyle>& animatedStyle); const AtomicString& name() const { return m_keyframes.animationName(); } int index() const { return m_index; } @@ -56,16 +57,19 @@ public: void setUnanimatedStyle(PassRefPtr<RenderStyle> style) { m_unanimatedStyle = style; } RenderStyle* unanimatedStyle() const { return m_unanimatedStyle.get(); } + virtual double willNeedService(); + protected: virtual void onAnimationStart(double elapsedTime); virtual void onAnimationIteration(double elapsedTime); virtual void onAnimationEnd(double elapsedTime); + virtual bool startAnimation(double beginTime); virtual void endAnimation(bool reset); virtual void overrideAnimations(); virtual void resumeOverriddenAnimations(); - bool shouldSendEventForListener(Document::ListenerType inListenerType); + bool shouldSendEventForListener(Document::ListenerType inListenerType) const; bool sendAnimationEvent(const AtomicString&, double elapsedTime); virtual bool affectsProperty(int) const; @@ -76,6 +80,9 @@ private: KeyframeAnimation(const Animation* animation, RenderObject*, int index, CompositeAnimation*, RenderStyle* unanimatedStyle); virtual ~KeyframeAnimation(); + // Get the styles surrounding the current animation time and the progress between them + void getKeyframeAnimationInterval(const RenderStyle*& fromStyle, const RenderStyle*& toStyle, double& progress) const; + // The keyframes that we are blending. KeyframeList m_keyframes; |