Changeset 116554 in webkit


Ignore:
Timestamp:
May 9, 2012 1:27:03 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Add impl-thread support for fill-mode and direction css animation properties
https://bugs.webkit.org/show_bug.cgi?id=77662

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

Source/WebCore:

Adds support for accelerating css animations with -webkit-animation-fill-mode,
and -webkit-animation-direction properties.

Tested in:

CCActiveAnimationTest.TrimTimeAlternating
CCLayerAnimationControllerTest.createReversedAnimation
CCLayerAnimationControllerTest.createAlternatingAnimation
CCLayerAnimationControllerTest.createReversedAlternatingAnimation

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

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

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

(CCActiveAnimation):
(WebCore::CCActiveAnimation::alternatesDirection):
(WebCore::CCActiveAnimation::setAlternatesDirection):

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

Source/WebKit/chromium:

  • tests/CCActiveAnimationTest.cpp:

(WebCore::TEST):
(WebCore):

  • tests/CCLayerAnimationControllerTest.cpp:

(WebKitTests::TEST):
(WebKitTests):

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r116551 r116554  
     12012-05-09  Ian Vollick  <vollick@chromium.org>
     2
     3        [chromium] Add impl-thread support for fill-mode and direction css animation properties
     4        https://bugs.webkit.org/show_bug.cgi?id=77662
     5
     6        Reviewed by James Robinson.
     7
     8        Adds support for accelerating css animations with -webkit-animation-fill-mode,
     9        and -webkit-animation-direction properties.
     10
     11        Tested in:
     12          CCActiveAnimationTest.TrimTimeAlternating
     13          CCLayerAnimationControllerTest.createReversedAnimation
     14          CCLayerAnimationControllerTest.createAlternatingAnimation
     15          CCLayerAnimationControllerTest.createReversedAlternatingAnimation
     16
     17        * platform/graphics/chromium/cc/CCActiveAnimation.cpp:
     18        (WebCore::CCActiveAnimation::CCActiveAnimation):
     19        (WebCore::CCActiveAnimation::trimTimeToCurrentIteration):
     20        (WebCore::CCActiveAnimation::cloneForImplThread):
     21        * platform/graphics/chromium/cc/CCActiveAnimation.h:
     22        (CCActiveAnimation):
     23        (WebCore::CCActiveAnimation::alternatesDirection):
     24        (WebCore::CCActiveAnimation::setAlternatesDirection):
     25        * platform/graphics/chromium/cc/CCLayerAnimationController.cpp:
     26
    1272012-05-09  Ken Buchanan  <kenrb@chromium.org>
    228
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCActiveAnimation.cpp

    r115519 r116554  
    4646    , m_iterations(1)
    4747    , m_startTime(0)
     48    , m_alternatesDirection(false)
    4849    , m_timeOffset(0)
    4950    , m_needsSynchronizedStartTime(false)
     
    120121
    121122    // If greater than or equal to the total duration, return iteration duration.
    122     if (m_iterations >= 0 && trimmed >= m_curve->duration() * m_iterations)
     123    if (m_iterations >= 0 && trimmed >= m_curve->duration() * m_iterations) {
     124        if (m_alternatesDirection && !(m_iterations % 2))
     125            return 0;
    123126        return m_curve->duration();
     127    }
    124128
    125     // Finally, return x where trimmed = x + n * m_animation->duration() for some positive integer n.
    126     return fmod(trimmed, m_curve->duration());
     129    // We need to know the current iteration if we're alternating.
     130    int iteration = static_cast<int>(trimmed / m_curve->duration());
     131
     132    // Calculate x where trimmed = x + n * m_curve->duration() for some positive integer n.
     133    trimmed = fmod(trimmed, m_curve->duration());
     134
     135    // If we're alternating and on an odd iteration, reverse the direction.
     136    if (m_alternatesDirection && iteration % 2 == 1)
     137        return m_curve->duration() - trimmed;
     138
     139    return trimmed;
    127140}
    128141
     
    136149    toReturn->m_totalPausedTime = m_totalPausedTime;
    137150    toReturn->m_timeOffset = m_timeOffset;
     151    toReturn->m_alternatesDirection = m_alternatesDirection;
    138152    return toReturn.release();
    139153}
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCActiveAnimation.h

    r115519 r116554  
    9191    void resume(double monotonicTime);
    9292
     93    // If alternatesDirection is true, on odd numbered iterations we reverse the curve.
     94    bool alternatesDirection() const { return m_alternatesDirection; }
     95    void setAlternatesDirection(bool alternates) { m_alternatesDirection = alternates; }
     96
    9397    bool isFinishedAt(double monotonicTime) const;
    9498    bool isFinished() const { return m_runState == Finished || m_runState == Aborted; }
     
    129133    int m_iterations;
    130134    double m_startTime;
     135    bool m_alternatesDirection;
    131136
    132137    // The time offset effectively pushes the start of the animation back in time. This is
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationController.cpp

    r115519 r116554  
    5353PassOwnPtr<CCActiveAnimation> createActiveAnimation(const KeyframeValueList& valueList, const Animation* animation, size_t animationId, size_t groupId, double timeOffset, CCActiveAnimation::TargetProperty targetProperty)
    5454{
    55     // FIXME: add support for different directions.
    56     if (animation && animation->isDirectionSet() && animation->direction() != Animation::AnimationDirectionNormal)
    57         return nullptr;
    58 
    59     // FIXME: add support for fills forwards and fills backwards
    60     if (animation && animation->isFillModeSet() && (animation->fillsForwards() || animation->fillsBackwards()))
    61         return nullptr;
     55    bool alternate = false;
     56    bool reverse = false;
     57    if (animation && animation->isDirectionSet()) {
     58        Animation::AnimationDirection direction = animation->direction();
     59        if (direction == Animation::AnimationDirectionAlternate || direction == Animation::AnimationDirectionAlternateReverse)
     60            alternate = true;
     61        if (direction == Animation::AnimationDirectionReverse || direction == Animation::AnimationDirectionAlternateReverse)
     62            reverse = true;
     63    }
    6264
    6365    OwnPtr<Curve> curve = Curve::create();
     
    6567
    6668    for (size_t i = 0; i < valueList.size(); i++) {
    67         const Value* originalValue = static_cast<const Value*>(valueList.at(i));
     69        size_t index = reverse ? valueList.size() - i - 1 : i;
     70
     71        const Value* originalValue = static_cast<const Value*>(valueList.at(index));
    6872
    6973        OwnPtr<CCTimingFunction> timingFunction;
     
    9296
    9397        double duration = (animation && animation->isDurationSet()) ? animation->duration() : 1;
    94         appendKeyframe<Value, Keyframe, Curve>(*curve, originalValue->keyTime() * duration, originalValue, timingFunction.release());
     98        double keyTime = originalValue->keyTime() * duration;
     99        if (reverse)
     100            keyTime = duration - keyTime;
     101        appendKeyframe<Value, Keyframe, Curve>(*curve, keyTime, originalValue, timingFunction.release());
    95102    }
    96103
     
    102109        int iterations = (animation && animation->isIterationCountSet()) ? animation->iterationCount() : 1;
    103110        anim->setIterations(iterations);
     111        anim->setAlternatesDirection(alternate);
    104112    }
    105113
  • trunk/Source/WebKit/chromium/ChangeLog

    r116548 r116554  
     12012-05-09  Ian Vollick  <vollick@chromium.org>
     2
     3        [chromium] Add impl-thread support for fill-mode and direction css animation properties
     4        https://bugs.webkit.org/show_bug.cgi?id=77662
     5
     6        Reviewed by James Robinson.
     7
     8        * tests/CCActiveAnimationTest.cpp:
     9        (WebCore::TEST):
     10        (WebCore):
     11        * tests/CCLayerAnimationControllerTest.cpp:
     12        (WebKitTests::TEST):
     13        (WebKitTests):
     14
    1152012-05-09  Ojan Vafai  <ojan@chromium.org>
    216
  • trunk/Source/WebKit/chromium/tests/CCActiveAnimationTest.cpp

    r115519 r116554  
    7070}
    7171
     72TEST(CCActiveAnimationTest, TrimTimeAlternating)
     73{
     74    OwnPtr<CCActiveAnimation> anim(createActiveAnimation(-1));
     75    anim->setAlternatesDirection(true);
     76    EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0));
     77    EXPECT_EQ(0.5, anim->trimTimeToCurrentIteration(0.5));
     78    EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1));
     79    EXPECT_EQ(0.75, anim->trimTimeToCurrentIteration(1.25));
     80}
     81
    7282TEST(CCActiveAnimationTest, TrimTimeStartTime)
    7383{
  • trunk/Source/WebKit/chromium/tests/CCLayerAnimationControllerTest.cpp

    r115519 r116554  
    8787}
    8888
    89 TEST(CCLayerAnimationControllerTest, ignoreUnsupportedAnimationDirections)
    90 {
    91     FakeLayerAnimationControllerClient dummy;
    92     OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create(&dummy));
    93     const double duration = 1;
    94     WebCore::KeyframeValueList values(AnimatedPropertyOpacity);
    95     values.insert(new FloatAnimationValue(0, 0));
    96     values.insert(new FloatAnimationValue(duration, 1));
    97 
    98     RefPtr<Animation> animation = Animation::create();
    99     animation->setDuration(duration);
    100 
    101     IntSize boxSize;
    102 
    103     animation->setDirection(Animation::AnimationDirectionAlternate);
    104     EXPECT_FALSE(controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0));
    105 
    106     animation->setDirection(Animation::AnimationDirectionAlternateReverse);
    107     EXPECT_FALSE(controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0));
    108 
    109     animation->setDirection(Animation::AnimationDirectionReverse);
    110     EXPECT_FALSE(controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0));
    111 
    112     animation->setDirection(Animation::AnimationDirectionNormal);
    113     EXPECT_TRUE(controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0));
    114 }
    115 
    11689TEST(CCLayerAnimationControllerTest, createTransformAnimation)
    11790{
     
    150123    expectTranslateX(2, curve->getValue(0, boxSize));
    151124    expectTranslateX(4, curve->getValue(duration, boxSize));
     125}
     126
     127TEST(CCLayerAnimationControllerTest, createReversedAnimation)
     128{
     129    FakeLayerAnimationControllerClient dummy;
     130    OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create(&dummy));
     131    const double duration = 1;
     132    WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform);
     133
     134    TransformOperations operations1;
     135    operations1.operations().append(TranslateTransformOperation::create(Length(2, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X));
     136    values.insert(new TransformAnimationValue(0, &operations1));
     137
     138    TransformOperations operations2;
     139    operations2.operations().append(TranslateTransformOperation::create(Length(4, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X));
     140    values.insert(new TransformAnimationValue(duration, &operations2));
     141
     142    RefPtr<Animation> animation = Animation::create();
     143    animation->setDuration(duration);
     144    animation->setDirection(Animation::AnimationDirectionReverse);
     145
     146    IntSize boxSize;
     147    controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0);
     148
     149    EXPECT_TRUE(controller->hasActiveAnimation());
     150
     151    CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCActiveAnimation::Transform);
     152    EXPECT_TRUE(activeAnimation);
     153
     154    EXPECT_EQ(1, activeAnimation->iterations());
     155    EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty());
     156
     157    EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type());
     158
     159    const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransformAnimationCurve();
     160    EXPECT_TRUE(curve);
     161
     162    expectTranslateX(4, curve->getValue(0, boxSize));
     163    expectTranslateX(2, curve->getValue(duration, boxSize));
     164}
     165
     166TEST(CCLayerAnimationControllerTest, createAlternatingAnimation)
     167{
     168    FakeLayerAnimationControllerClient dummy;
     169    OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create(&dummy));
     170    const double duration = 1;
     171    WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform);
     172
     173    TransformOperations operations1;
     174    operations1.operations().append(TranslateTransformOperation::create(Length(2, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X));
     175    values.insert(new TransformAnimationValue(0, &operations1));
     176
     177    TransformOperations operations2;
     178    operations2.operations().append(TranslateTransformOperation::create(Length(4, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X));
     179    values.insert(new TransformAnimationValue(duration, &operations2));
     180
     181    RefPtr<Animation> animation = Animation::create();
     182    animation->setDuration(duration);
     183    animation->setDirection(Animation::AnimationDirectionAlternate);
     184    animation->setIterationCount(2);
     185
     186    IntSize boxSize;
     187    controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0);
     188
     189    EXPECT_TRUE(controller->hasActiveAnimation());
     190
     191    CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCActiveAnimation::Transform);
     192    EXPECT_TRUE(activeAnimation);
     193    EXPECT_TRUE(activeAnimation->alternatesDirection());
     194
     195    EXPECT_EQ(2, activeAnimation->iterations());
     196    EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty());
     197
     198    EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type());
     199
     200    const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransformAnimationCurve();
     201    EXPECT_TRUE(curve);
     202
     203    expectTranslateX(2, curve->getValue(0, boxSize));
     204    expectTranslateX(4, curve->getValue(duration, boxSize));
     205}
     206
     207TEST(CCLayerAnimationControllerTest, createReversedAlternatingAnimation)
     208{
     209    FakeLayerAnimationControllerClient dummy;
     210    OwnPtr<CCLayerAnimationController> controller(CCLayerAnimationController::create(&dummy));
     211    const double duration = 1;
     212    WebCore::KeyframeValueList values(AnimatedPropertyWebkitTransform);
     213
     214    TransformOperations operations1;
     215    operations1.operations().append(TranslateTransformOperation::create(Length(2, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X));
     216    values.insert(new TransformAnimationValue(0, &operations1));
     217
     218    TransformOperations operations2;
     219    operations2.operations().append(TranslateTransformOperation::create(Length(4, Fixed), Length(0, Fixed), TransformOperation::TRANSLATE_X));
     220    values.insert(new TransformAnimationValue(duration, &operations2));
     221
     222    RefPtr<Animation> animation = Animation::create();
     223    animation->setDuration(duration);
     224    animation->setDirection(Animation::AnimationDirectionAlternateReverse);
     225    animation->setIterationCount(2);
     226
     227    IntSize boxSize;
     228    controller->addAnimation(values, boxSize, animation.get(), 0, 0, 0);
     229
     230    EXPECT_TRUE(controller->hasActiveAnimation());
     231
     232    CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCActiveAnimation::Transform);
     233    EXPECT_TRUE(activeAnimation);
     234    EXPECT_TRUE(activeAnimation->alternatesDirection());
     235
     236    EXPECT_EQ(2, activeAnimation->iterations());
     237    EXPECT_EQ(CCActiveAnimation::Transform, activeAnimation->targetProperty());
     238
     239    EXPECT_EQ(CCAnimationCurve::Transform, activeAnimation->curve()->type());
     240
     241    const CCTransformAnimationCurve* curve = activeAnimation->curve()->toTransformAnimationCurve();
     242    EXPECT_TRUE(curve);
     243
     244    expectTranslateX(4, curve->getValue(0, boxSize));
     245    expectTranslateX(2, curve->getValue(duration, boxSize));
    152246}
    153247
Note: See TracChangeset for help on using the changeset viewer.