Changeset 108727 in webkit


Ignore:
Timestamp:
Feb 23, 2012 9:31:12 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Implement keyframed animations for the cc thread.
https://bugs.webkit.org/show_bug.cgi?id=77229

Patch by Ian Vollick <vollick@chromium.org> on 2012-02-23
Reviewed by James Robinson.

Source/WebCore:

  • WebCore.gypi:
  • platform/graphics/chromium/LayerChromium.cpp:

(WebCore::LayerChromium::hasActiveAnimation):
(WebCore):

  • platform/graphics/chromium/LayerChromium.h:

(LayerChromium):

  • platform/graphics/chromium/cc/CCActiveAnimation.cpp:

(WebCore::CCActiveAnimation::CCActiveAnimation):
(WebCore::CCActiveAnimation::isFinishedAt):
(WebCore::CCActiveAnimation::trimTimeToCurrentIteration):
(WebCore::CCActiveAnimation::cloneForImplThread):

  • platform/graphics/chromium/cc/CCActiveAnimation.h:

(WebCore::CCActiveAnimation::curve):
(CCActiveAnimation):

  • platform/graphics/chromium/cc/CCKeyframedAnimationCurve.cpp: Added.

(WebCore::CCKeyframedFloatAnimationCurve::create):
(WebCore):
(WebCore::CCKeyframedFloatAnimationCurve::CCKeyframedFloatAnimationCurve):
(WebCore::CCKeyframedFloatAnimationCurve::~CCKeyframedFloatAnimationCurve):
(WebCore::CCKeyframedFloatAnimationCurve::duration):
(WebCore::CCKeyframedFloatAnimationCurve::clone):
(WebCore::CCKeyframedFloatAnimationCurve::getValue):
(WebCore::CCKeyframedTransformAnimationCurve::create):
(WebCore::CCKeyframedTransformAnimationCurve::CCKeyframedTransformAnimationCurve):
(WebCore::CCKeyframedTransformAnimationCurve::~CCKeyframedTransformAnimationCurve):
(WebCore::CCKeyframedTransformAnimationCurve::duration):
(WebCore::CCKeyframedTransformAnimationCurve::clone):
(WebCore::CCKeyframedTransformAnimationCurve::getValue):

  • platform/graphics/chromium/cc/CCKeyframedAnimationCurve.h: Added.

(WebCore):
(WebCore::CCFloatKeyframe::CCFloatKeyframe):
(CCFloatKeyframe):
(WebCore::CCTransformKeyframe::CCTransformKeyframe):
(CCTransformKeyframe):
(CCKeyframedFloatAnimationCurve):
(CCKeyframedTransformAnimationCurve):

  • platform/graphics/chromium/cc/CCLayerAnimationController.cpp:

(WebCore::CCLayerAnimationController::addAnimation):

  • platform/graphics/chromium/cc/CCLayerAnimationController.h:

(WebCore::CCLayerAnimationController::hasActiveAnimation):
(CCLayerAnimationController):

  • platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.cpp:

(WebCore::CCLayerAnimationControllerImpl::tickAnimations):

Source/WebKit/chromium:

  • WebKit.gypi:
  • tests/CCAnimationTestCommon.cpp:

(WebCore):
(WebCore::addOpacityTransition):
(WebKitTests::addOpacityTransitionToController):
(WebKitTests::addOpacityTransitionToLayer):

  • tests/CCAnimationTestCommon.h:

(WebCore):
(WebKitTests):

  • tests/CCKeyframedAnimationCurveTest.cpp: Added.

(WebCore):
(WebCore::expectTranslateX):
(WebCore::TEST):

  • tests/CCLayerAnimationControllerTest.cpp:

(WebKitTests::expectTranslateX):
(WebKitTests):
(WebKitTests::TEST):

  • tests/CCLayerTreeHostTest.cpp:

(WTF::CCLayerTreeHostTest::dispatchAddAnimation):
(WTF::CCLayerTreeHostTest::doBeginTest):

Location:
trunk/Source
Files:
3 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r108726 r108727  
     12012-02-23  Ian Vollick  <vollick@chromium.org>
     2
     3        [chromium] Implement keyframed animations for the cc thread.
     4        https://bugs.webkit.org/show_bug.cgi?id=77229
     5
     6        Reviewed by James Robinson.
     7
     8        * WebCore.gypi:
     9        * platform/graphics/chromium/LayerChromium.cpp:
     10        (WebCore::LayerChromium::hasActiveAnimation):
     11        (WebCore):
     12        * platform/graphics/chromium/LayerChromium.h:
     13        (LayerChromium):
     14        * platform/graphics/chromium/cc/CCActiveAnimation.cpp:
     15        (WebCore::CCActiveAnimation::CCActiveAnimation):
     16        (WebCore::CCActiveAnimation::isFinishedAt):
     17        (WebCore::CCActiveAnimation::trimTimeToCurrentIteration):
     18        (WebCore::CCActiveAnimation::cloneForImplThread):
     19        * platform/graphics/chromium/cc/CCActiveAnimation.h:
     20        (WebCore::CCActiveAnimation::curve):
     21        (CCActiveAnimation):
     22        * platform/graphics/chromium/cc/CCKeyframedAnimationCurve.cpp: Added.
     23        (WebCore::CCKeyframedFloatAnimationCurve::create):
     24        (WebCore):
     25        (WebCore::CCKeyframedFloatAnimationCurve::CCKeyframedFloatAnimationCurve):
     26        (WebCore::CCKeyframedFloatAnimationCurve::~CCKeyframedFloatAnimationCurve):
     27        (WebCore::CCKeyframedFloatAnimationCurve::duration):
     28        (WebCore::CCKeyframedFloatAnimationCurve::clone):
     29        (WebCore::CCKeyframedFloatAnimationCurve::getValue):
     30        (WebCore::CCKeyframedTransformAnimationCurve::create):
     31        (WebCore::CCKeyframedTransformAnimationCurve::CCKeyframedTransformAnimationCurve):
     32        (WebCore::CCKeyframedTransformAnimationCurve::~CCKeyframedTransformAnimationCurve):
     33        (WebCore::CCKeyframedTransformAnimationCurve::duration):
     34        (WebCore::CCKeyframedTransformAnimationCurve::clone):
     35        (WebCore::CCKeyframedTransformAnimationCurve::getValue):
     36        * platform/graphics/chromium/cc/CCKeyframedAnimationCurve.h: Added.
     37        (WebCore):
     38        (WebCore::CCFloatKeyframe::CCFloatKeyframe):
     39        (CCFloatKeyframe):
     40        (WebCore::CCTransformKeyframe::CCTransformKeyframe):
     41        (CCTransformKeyframe):
     42        (CCKeyframedFloatAnimationCurve):
     43        (CCKeyframedTransformAnimationCurve):
     44        * platform/graphics/chromium/cc/CCLayerAnimationController.cpp:
     45        (WebCore::CCLayerAnimationController::addAnimation):
     46        * platform/graphics/chromium/cc/CCLayerAnimationController.h:
     47        (WebCore::CCLayerAnimationController::hasActiveAnimation):
     48        (CCLayerAnimationController):
     49        * platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.cpp:
     50        (WebCore::CCLayerAnimationControllerImpl::tickAnimations):
     51
    1522012-02-23  Raymond Toy  <rtoy@google.com>
    253
  • trunk/Source/WebCore/WebCore.gypi

    r108710 r108727  
    32693269            'platform/graphics/chromium/cc/CCHeadsUpDisplay.h',
    32703270            'platform/graphics/chromium/cc/CCInputHandler.h',
     3271            'platform/graphics/chromium/cc/CCKeyframedAnimationCurve.cpp',
     3272            'platform/graphics/chromium/cc/CCKeyframedAnimationCurve.h',
    32713273            'platform/graphics/chromium/cc/CCLayerAnimationController.h',
    32723274            'platform/graphics/chromium/cc/CCLayerAnimationController.cpp',
  • trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp

    r108698 r108727  
    137137}
    138138
     139bool LayerChromium::hasActiveAnimation() const
     140{
     141    return m_layerAnimationController->hasActiveAnimation();
     142}
     143
    139144void LayerChromium::setIsNonCompositedContent(bool isNonCompositedContent)
    140145{
  • trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.h

    r108698 r108727  
    225225    CCLayerAnimationController* layerAnimationController() { return m_layerAnimationController.get(); }
    226226    void setLayerAnimationController(PassOwnPtr<CCLayerAnimationController>);
     227    bool hasActiveAnimation() const;
    227228
    228229protected:
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCActiveAnimation.cpp

    r108581 r108727  
    3939
    4040CCActiveAnimation::CCActiveAnimation(PassOwnPtr<CCAnimationCurve> curve, int animationId, int groupId, TargetProperty targetProperty)
    41     : m_animationCurve(curve)
     41    : m_curve(curve)
    4242    , m_id(animationId)
    4343    , m_group(groupId)
     
    7171    return m_runState == Running
    7272        && m_iterations >= 0
    73         && m_iterations * m_animationCurve->duration() <= time - startTime() - m_totalPausedTime;
     73        && m_iterations * m_curve->duration() <= time - startTime() - m_totalPausedTime;
    7474}
    7575
     
    110110
    111111    // If less than an iteration duration, just return trimmed.
    112     if (trimmed < m_animationCurve->duration())
     112    if (trimmed < m_curve->duration())
    113113        return trimmed;
    114114
    115115    // If greater than or equal to the total duration, return iteration duration.
    116     if (m_iterations >= 0 && trimmed >= m_animationCurve->duration() * m_iterations)
    117         return m_animationCurve->duration();
     116    if (m_iterations >= 0 && trimmed >= m_curve->duration() * m_iterations)
     117        return m_curve->duration();
    118118
    119119    // Finally, return x where trimmed = x + n * m_animation->duration() for some positive integer n.
    120     return fmod(trimmed, m_animationCurve->duration());
     120    return fmod(trimmed, m_curve->duration());
    121121}
    122122
    123123PassOwnPtr<CCActiveAnimation> CCActiveAnimation::cloneForImplThread() const
    124124{
    125     OwnPtr<CCActiveAnimation> toReturn(adoptPtr(new CCActiveAnimation(m_animationCurve->clone(), m_id, m_group, m_targetProperty)));
     125    OwnPtr<CCActiveAnimation> toReturn(adoptPtr(new CCActiveAnimation(m_curve->clone(), m_id, m_group, m_targetProperty)));
    126126    toReturn->m_runState = m_runState;
    127127    toReturn->m_iterations = m_iterations;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCActiveAnimation.h

    r108581 r108727  
    9898    bool isRunningOrHasRun() const;
    9999
    100     CCAnimationCurve* animationCurve() { return m_animationCurve.get(); }
    101     const CCAnimationCurve* animationCurve() const { return m_animationCurve.get(); }
     100    CCAnimationCurve* curve() { return m_curve.get(); }
     101    const CCAnimationCurve* curve() const { return m_curve.get(); }
    102102
    103103    // Takes the given absolute time, and using the start time and the number
     
    114114    CCActiveAnimation(PassOwnPtr<CCAnimationCurve>, int animationId, int groupId, TargetProperty);
    115115
    116     OwnPtr<CCAnimationCurve> m_animationCurve;
     116    OwnPtr<CCAnimationCurve> m_curve;
    117117
    118118    // IDs are not necessarily unique.
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationController.cpp

    r108581 r108727  
    2929#include "GraphicsLayer.h" // for KeyframeValueList
    3030#include "cc/CCActiveAnimation.h"
     31#include "cc/CCKeyframedAnimationCurve.h"
    3132#include "cc/CCLayerAnimationControllerImpl.h"
     33#include <wtf/CurrentTime.h>
    3234#include <wtf/HashMap.h>
    3335
    3436namespace WebCore {
    3537
     38namespace {
     39
     40template <typename Keyframe, typename Value>
     41void appendKeyframe(Vector<Keyframe>& keyframes, double keyTime, const Value* value)
     42{
     43    keyframes.append(Keyframe(keyTime, value->value()));
     44}
     45
     46template <>
     47void appendKeyframe<CCTransformKeyframe, TransformAnimationValue>(Vector<CCTransformKeyframe>& keyframes, double keyTime, const TransformAnimationValue* value)
     48{
     49    keyframes.append(CCTransformKeyframe(keyTime, *value->value()));
     50}
     51
     52template <class Value, class Keyframe, class Curve>
     53PassOwnPtr<CCActiveAnimation> createActiveAnimation(const KeyframeValueList& valueList, const Animation* animation, size_t animationId, size_t groupId, double timeOffset, CCActiveAnimation::TargetProperty targetProperty)
     54{
     55    // FIXME: add support for different directions.
     56    if (animation && animation->isDirectionSet() && animation->direction() == Animation::AnimationDirectionAlternate)
     57        return nullptr;
     58
     59    // FIXME: add support for delay
     60    if (animation && animation->isDelaySet() && animation->delay() > 0)
     61        return nullptr;
     62
     63    // FIXME: add support for fills forwards and fills backwards
     64    if (animation && animation->isFillModeSet() && (animation->fillsForwards() || animation->fillsBackwards()))
     65        return nullptr;
     66
     67    Vector<Keyframe> keyframes;
     68
     69    for (size_t i = 0; i < valueList.size(); i++) {
     70        const Value* originalValue = static_cast<const Value*>(valueList.at(i));
     71
     72        // FIXME: add support for timing functions.
     73        if (originalValue->timingFunction() && originalValue->timingFunction()->type() != TimingFunction::LinearFunction)
     74            return nullptr;
     75
     76        double duration = (animation && animation->isDurationSet()) ? animation->duration() : 1;
     77        appendKeyframe(keyframes, originalValue->keyTime() * duration, originalValue);
     78    }
     79
     80    OwnPtr<Curve> curve = Curve::create(keyframes);
     81
     82    OwnPtr<CCActiveAnimation> anim = CCActiveAnimation::create(curve.release(), animationId, groupId, targetProperty);
     83
     84    ASSERT(anim.get());
     85
     86    if (anim.get()) {
     87        int iterations = (animation && animation->isIterationCountSet()) ? animation->iterationCount() : 1;
     88        anim->setIterations(iterations);
     89    }
     90
     91    return anim.release();
     92}
     93
     94} // namepace
     95
    3696CCLayerAnimationController::CCLayerAnimationController()
    3797{
     
    47107}
    48108
    49 bool CCLayerAnimationController::addAnimation(const KeyframeValueList& valueList,
    50                                               const IntSize&,
    51                                               const Animation* animation,
    52                                               int animationId,
    53                                               int groupId,
    54                                               double timeOffset)
    55 {
     109bool CCLayerAnimationController::addAnimation(const KeyframeValueList& valueList, const IntSize&, const Animation* animation, int animationId, int groupId, double timeOffset)
     110{
     111    if (!animation)
     112        return false;
     113
     114    OwnPtr<CCActiveAnimation> toAdd;
     115    if (valueList.property() == AnimatedPropertyWebkitTransform)
     116        toAdd = createActiveAnimation<TransformAnimationValue, CCTransformKeyframe, CCKeyframedTransformAnimationCurve>(valueList, animation, animationId, groupId, timeOffset, CCActiveAnimation::Transform);
     117    else if (valueList.property() == AnimatedPropertyOpacity)
     118        toAdd = createActiveAnimation<FloatAnimationValue, CCFloatKeyframe, CCKeyframedFloatAnimationCurve>(valueList, animation, animationId, groupId, timeOffset, CCActiveAnimation::Opacity);
     119
     120    if (toAdd.get()) {
     121        m_activeAnimations.append(toAdd.release());
     122        return true;
     123    }
     124
    56125    return false;
    57126}
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationController.h

    r108593 r108727  
    5757    virtual void synchronizeAnimations(CCLayerAnimationControllerImpl*);
    5858
    59     // This is for testing purposes only.
    60     Vector<OwnPtr<CCActiveAnimation> >& activeAnimations() { return m_activeAnimations; }
     59    bool hasActiveAnimation() const { return m_activeAnimations.size(); }
     60    CCActiveAnimation* getActiveAnimation(int groupId, CCActiveAnimation::TargetProperty);
    6161
    6262protected:
     
    6969    void pushAnimationProperties(CCLayerAnimationControllerImpl*);
    7070
    71     CCActiveAnimation* getActiveAnimation(int groupId, CCActiveAnimation::TargetProperty);
    7271    void remove(int groupId, CCActiveAnimation::TargetProperty);
    7372
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.cpp

    r108581 r108727  
    202202
    203203            case CCActiveAnimation::Transform: {
    204                 const CCTransformAnimationCurve* transformAnimationCurve = m_activeAnimations[i]->animationCurve()->toTransformAnimationCurve();
     204                const CCTransformAnimationCurve* transformAnimationCurve = m_activeAnimations[i]->curve()->toTransformAnimationCurve();
    205205                const TransformationMatrix matrix = transformAnimationCurve->getValue(trimmed, m_client->bounds());
    206206                if (m_activeAnimations[i]->isFinishedAt(now))
     
    212212
    213213            case CCActiveAnimation::Opacity: {
    214                 const CCFloatAnimationCurve* floatAnimationCurve = m_activeAnimations[i]->animationCurve()->toFloatAnimationCurve();
     214                const CCFloatAnimationCurve* floatAnimationCurve = m_activeAnimations[i]->curve()->toFloatAnimationCurve();
    215215                const float opacity = floatAnimationCurve->getValue(trimmed);
    216216                if (m_activeAnimations[i]->isFinishedAt(now))
  • trunk/Source/WebKit/chromium/ChangeLog

    r108706 r108727  
     12012-02-23  Ian Vollick  <vollick@chromium.org>
     2
     3        [chromium] Implement keyframed animations for the cc thread.
     4        https://bugs.webkit.org/show_bug.cgi?id=77229
     5
     6        Reviewed by James Robinson.
     7
     8        * WebKit.gypi:
     9        * tests/CCAnimationTestCommon.cpp:
     10        (WebCore):
     11        (WebCore::addOpacityTransition):
     12        (WebKitTests::addOpacityTransitionToController):
     13        (WebKitTests::addOpacityTransitionToLayer):
     14        * tests/CCAnimationTestCommon.h:
     15        (WebCore):
     16        (WebKitTests):
     17        * tests/CCKeyframedAnimationCurveTest.cpp: Added.
     18        (WebCore):
     19        (WebCore::expectTranslateX):
     20        (WebCore::TEST):
     21        * tests/CCLayerAnimationControllerTest.cpp:
     22        (WebKitTests::expectTranslateX):
     23        (WebKitTests):
     24        (WebKitTests::TEST):
     25        * tests/CCLayerTreeHostTest.cpp:
     26        (WTF::CCLayerTreeHostTest::dispatchAddAnimation):
     27        (WTF::CCLayerTreeHostTest::doBeginTest):
     28
    1292012-02-23  James Robinson  <jamesr@chromium.org>
    230
  • trunk/Source/WebKit/chromium/WebKit.gypi

    r108581 r108727  
    6767            'tests/CCDelayBasedTimeSourceTest.cpp',
    6868            'tests/CCFrameRateControllerTest.cpp',
     69            'tests/CCKeyframedAnimationCurveTest.cpp',
    6970            'tests/CCLayerAnimationControllerImplTest.cpp',
    7071            'tests/CCLayerAnimationControllerTest.cpp',
  • trunk/Source/WebKit/chromium/tests/CCAnimationTestCommon.cpp

    r108581 r108727  
    2929#include "GraphicsLayer.h"
    3030#include "LayerChromium.h"
     31#include "cc/CCLayerAnimationController.h"
    3132
    3233using namespace WebCore;
     34
     35namespace {
     36
     37template <class Target>
     38void addOpacityTransition(Target& target, double duration, float startOpacity, float endOpacity)
     39{
     40    WebCore::KeyframeValueList values(AnimatedPropertyOpacity);
     41    if (duration > 0)
     42        values.insert(new FloatAnimationValue(0, startOpacity));
     43    values.insert(new FloatAnimationValue(duration, endOpacity));
     44
     45    RefPtr<Animation> animation = Animation::create();
     46    animation->setDuration(duration);
     47
     48    IntSize boxSize;
     49
     50    target.addAnimation(values, boxSize, animation.get(), 0, 0, 0);
     51}
     52
     53} // namespace
    3354
    3455namespace WebKitTests {
     
    100121}
    101122
    102 void addOpacityTransition(WebCore::LayerChromium& layer, double duration, float startOpacity, float endOpacity)
     123void addOpacityTransitionToController(WebCore::CCLayerAnimationController& controller, double duration, float startOpacity, float endOpacity)
    103124{
    104     WebCore::KeyframeValueList values(AnimatedPropertyOpacity);
    105     if (duration > 0)
    106         values.insert(new FloatAnimationValue(0, startOpacity));
    107     values.insert(new FloatAnimationValue(duration, endOpacity));
     125    addOpacityTransition(controller, duration, startOpacity, endOpacity);
     126}
    108127
    109     RefPtr<Animation> animation = Animation::create();
    110     animation->setDuration(1);
    111 
    112     IntSize boxSize;
    113 
    114     layer.addAnimation(values, boxSize, animation.get(), 0, 0, 0);
     128void addOpacityTransitionToLayer(WebCore::LayerChromium& layer, double duration, float startOpacity, float endOpacity)
     129{
     130    addOpacityTransition(layer, duration, startOpacity, endOpacity);
    115131}
    116132
  • trunk/Source/WebKit/chromium/tests/CCAnimationTestCommon.h

    r108581 r108727  
    3232
    3333namespace WebCore {
     34class CCLayerAnimationController;
    3435class LayerChromium;
    3536}
     
    9596};
    9697
    97 void addOpacityTransition(WebCore::LayerChromium&, double duration, float startOpacity, float endOpacity);
     98void addOpacityTransitionToController(WebCore::CCLayerAnimationController&, double duration, float startOpacity, float endOpacity);
     99
     100void addOpacityTransitionToLayer(WebCore::LayerChromium&, double duration, float startOpacity, float endOpacity);
    98101
    99102} // namespace WebKitTests
  • trunk/Source/WebKit/chromium/tests/CCLayerAnimationControllerTest.cpp

    r108581 r108727  
    2828
    2929#include "CCAnimationTestCommon.h"
     30#include "GraphicsLayer.h"
     31#include "Length.h"
     32#include "TranslateTransformOperation.h"
     33#include "cc/CCActiveAnimation.h"
     34#include "cc/CCAnimationCurve.h"
     35
    3036#include <gmock/gmock.h>
    3137#include <gtest/gtest.h>
     
    3743namespace {
    3844
     45void expectTranslateX(double translateX, const TransformationMatrix& matrix)
     46{
     47    TransformationMatrix::DecomposedType decomposedType;
     48    matrix.decompose(decomposedType);
     49    EXPECT_FLOAT_EQ(translateX, decomposedType.translateX);
     50}
     51
    3952PassOwnPtr<CCActiveAnimation> createActiveAnimation(PassOwnPtr<CCAnimationCurve> curve, int id, CCActiveAnimation::TargetProperty property)
    4053{
     
    4255}
    4356
     57TEST(CCLayerAnimationControllerTest, createOpacityAnimation)
     58{
     59    OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create());
     60    const double duration = 1;
     61    WebCore::KeyframeValueList values(AnimatedPropertyOpacity);
     62    values.insert(new FloatAnimationValue(0, 0));
     63    values.insert(new FloatAnimationValue(duration, 1));
     64
     65    RefPtr<Animation> animation = Animation::create();
     66    animation->setDuration(duration);
     67
     68    IntSize boxSize;
     69    controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0);
     70
     71    EXPECT_TRUE(controller->hasActiveAnimation());
     72
     73    CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCActiveAnimation::Opacity);
     74    EXPECT_TRUE(activeAnimation);
     75
     76    EXPECT_EQ(1, activeAnimation->iterations());
     77    EXPECT_EQ(CCActiveAnimation::Opacity, activeAnimation->targetProperty());
     78
     79    EXPECT_EQ(CCAnimationCurve::Float, activeAnimation->curve()->type());
     80
     81    const CCFloatAnimationCurve* curve = activeAnimation->curve()->toFloatAnimationCurve();
     82    EXPECT_TRUE(curve);
     83
     84    EXPECT_EQ(0, curve->getValue(0));
     85    EXPECT_EQ(1, curve->getValue(duration));
     86}
     87
     88TEST(CCLayerAnimationControllerTest, createTransformAnimation)
     89{
     90    OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create());
     91    const double duration = 1;
     92    WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform);
     93
     94    TransformOperations operations1;
     95    operations1.operations().append(TranslateTransformOperation::create(Length(2, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X));
     96    values.insert(new TransformAnimationValue(0, &operations1));
     97
     98    TransformOperations operations2;
     99    operations2.operations().append(TranslateTransformOperation::create(Length(4, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X));
     100    values.insert(new TransformAnimationValue(duration, &operations2));
     101
     102    RefPtr<Animation> animation = Animation::create();
     103    animation->setDuration(duration);
     104
     105    IntSize boxSize;
     106    controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0);
     107
     108    EXPECT_TRUE(controller->hasActiveAnimation());
     109
     110    CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCActiveAnimation::Transform);
     111    EXPECT_TRUE(activeAnimation);
     112
     113    EXPECT_EQ(1, activeAnimation->iterations());
     114    EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty());
     115
     116    EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type());
     117
     118    const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransformAnimationCurve();
     119    EXPECT_TRUE(curve);
     120
     121    expectTranslateX(2, curve->getValue(0, boxSize));
     122    expectTranslateX(4, curve->getValue(duration, boxSize));
     123}
     124
    44125TEST(CCLayerAnimationControllerTest, syncNewAnimation)
    45126{
    46127    FakeLayerAnimationControllerImplClient dummy;
    47     OwnPtr<CCLayerAnimationControllerImpl> controllerImpl(
    48         CCLayerAnimationControllerImpl::create(&dummy));
    49     OwnPtr<CCLayerAnimationController> controller(
    50         CCLayerAnimationController::create());
    51 
    52     EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity));
    53 
    54     controller->activeAnimations().append(CCActiveAnimation::create(adoptPtr(new FakeFloatAnimationCurve()), 0, 0, CCActiveAnimation::Opacity));
     128    OwnPtr<CCLayerAnimationControllerImpl> controllerImpl(CCLayerAnimationControllerImpl::create(&dummy));
     129    OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create());
     130
     131    EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity));
     132
     133    addOpacityTransitionToController(*controller, 1, 0, 1);
    55134
    56135    controller->synchronizeAnimations(controllerImpl.get());
     
    63142{
    64143    FakeLayerAnimationControllerImplClient dummy;
    65     OwnPtr<CCLayerAnimationControllerImpl> controllerImpl(
    66         CCLayerAnimationControllerImpl::create(&dummy));
    67     OwnPtr<CCLayerAnimationController> controller(
    68         CCLayerAnimationController::create());
    69 
    70     EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity));
    71 
    72     controller->activeAnimations().append(CCActiveAnimation::create(adoptPtr(new FakeFloatAnimationCurve()), 0, 0, CCActiveAnimation::Opacity));
     144    OwnPtr<CCLayerAnimationControllerImpl> controllerImpl(CCLayerAnimationControllerImpl::create(&dummy));
     145    OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create());
     146
     147    EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity));
     148
     149    addOpacityTransitionToController(*controller, 1, 0, 1);
    73150
    74151    controller->synchronizeAnimations(controllerImpl.get());
     
    88165{
    89166    FakeLayerAnimationControllerImplClient dummy;
    90     OwnPtr<CCLayerAnimationControllerImpl> controllerImpl(
    91         CCLayerAnimationControllerImpl::create(&dummy));
    92     OwnPtr<CCLayerAnimationController> controller(
    93         CCLayerAnimationController::create());
    94 
    95     EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity));
    96 
    97     controller->activeAnimations().append(CCActiveAnimation::create(adoptPtr(new FakeFloatAnimationCurve()), 0, 0, CCActiveAnimation::Opacity));
     167    OwnPtr<CCLayerAnimationControllerImpl> controllerImpl(CCLayerAnimationControllerImpl::create(&dummy));
     168    OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create());
     169
     170    EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity));
     171
     172    addOpacityTransitionToController(*controller, 1, 0, 1);
    98173
    99174    controller->synchronizeAnimations(controllerImpl.get());
     
    113188{
    114189    FakeLayerAnimationControllerImplClient dummy;
    115     OwnPtr<CCLayerAnimationControllerImpl> controllerImpl(
    116         CCLayerAnimationControllerImpl::create(&dummy));
    117     OwnPtr<CCLayerAnimationController> controller(
    118         CCLayerAnimationController::create());
    119 
    120     EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity));
    121 
    122     controller->activeAnimations().append(CCActiveAnimation::create(adoptPtr(new FakeFloatAnimationCurve()), 0, 0, CCActiveAnimation::Opacity));
     190    OwnPtr<CCLayerAnimationControllerImpl> controllerImpl(CCLayerAnimationControllerImpl::create(&dummy));
     191    OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create());
     192
     193    EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity));
     194
     195    addOpacityTransitionToController(*controller, 1, 0, 1);
    123196
    124197    controller->synchronizeAnimations(controllerImpl.get());
     
    133206
    134207    EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity));
    135     EXPECT_EQ(size_t(1), controller->activeAnimations().size());
    136 
    137     controller->synchronizeAnimations(controllerImpl.get());
    138 
    139     EXPECT_EQ(size_t(0), controller->activeAnimations().size());
     208    EXPECT_TRUE(controller->hasActiveAnimation());
     209
     210    controller->synchronizeAnimations(controllerImpl.get());
     211
     212    EXPECT_FALSE(controller->hasActiveAnimation());
    140213}
    141214
  • trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp

    r108706 r108727  
    152152};
    153153
    154 // Adapts CCLayerAnimationController for test. Adds a dummy implementation of addAnimation that inserts a float animation.
    155 // FIXME: once CCLayerAnimationController::addAnimation is implemented, that function should be called directly and this
    156 // class can be removed.
    157 class MockLayerAnimationController : public CCLayerAnimationController {
    158 public:
    159     static PassOwnPtr<MockLayerAnimationController> create()
    160     {
    161         return adoptPtr(new MockLayerAnimationController);
    162     }
    163 
    164 private:
    165     virtual bool addAnimation(const KeyframeValueList&, const IntSize& boxSize, const Animation*, int animationId, int groupId, double timeOffset)
    166     {
    167         double duration = 0;
    168         activeAnimations().append(CCActiveAnimation::create(adoptPtr(new FakeFloatTransition(duration, 1, 0)), animationId, groupId, CCActiveAnimation::Opacity));
    169         return true;
    170     }
    171 };
    172 
    173154class CompositorFakeWebGraphicsContext3DWithTextureTracking : public CompositorFakeWebGraphicsContext3D {
    174155public:
     
    362343      ASSERT(test);
    363344      if (test->m_layerTreeHost && test->m_layerTreeHost->rootLayer())
    364           test->m_layerTreeHost->rootLayer()->addAnimation(KeyframeValueList(AnimatedPropertyOpacity), IntSize(), 0, 0, 0, 0.0);
     345          addOpacityTransitionToLayer(*test->m_layerTreeHost->rootLayer(), 0, 0, 1);
    365346    }
    366347
     
    515496    ASSERT_TRUE(m_layerTreeHost);
    516497    rootLayer->setLayerTreeHost(m_layerTreeHost.get());
    517     rootLayer->setLayerAnimationController(MockLayerAnimationController::create());
    518498
    519499    m_beginning = true;
Note: See TracChangeset for help on using the changeset viewer.