⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 272178 in webkit


Ignore:
Timestamp:
Feb 1, 2021, 2:56:01 PM (6 years ago)
Author:
graouts@webkit.org
Message:

Allow support for CAAnimationGroup
​https://bugs.webkit.org/show_bug.cgi?id=221209

Reviewed by Dean Jackson, Sam Weinig and Simon Fraser.

In order to fix bug 219894, we need to use Core Animation's CAAnimationGroup and its
Source/WebCore:

setAnimations() method. This patch adds a new "Group" type to PlatformCAAnimation and
platform-specific integration for Windows and Cocoa ports.

  • platform/graphics/ca/PlatformCAAnimation.cpp:

(WebCore::operator<<):

  • platform/graphics/ca/PlatformCAAnimation.h:
  • platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.h:
  • platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm:

(WebCore::PlatformCAAnimationCocoa::PlatformCAAnimationCocoa):
(WebCore::PlatformCAAnimationCocoa::keyPath const):
(WebCore::PlatformCAAnimationCocoa::setTimingFunction):
(WebCore::PlatformCAAnimationCocoa::isAdditive const):
(WebCore::PlatformCAAnimationCocoa::setAdditive):
(WebCore::PlatformCAAnimationCocoa::valueFunction const):
(WebCore::PlatformCAAnimationCocoa::setValueFunction):
(WebCore::PlatformCAAnimationCocoa::setFromValue):
(WebCore::PlatformCAAnimationCocoa::copyFromValueFrom):
(WebCore::PlatformCAAnimationCocoa::setToValue):
(WebCore::PlatformCAAnimationCocoa::copyToValueFrom):
(WebCore::PlatformCAAnimationCocoa::setValues):
(WebCore::PlatformCAAnimationCocoa::copyValuesFrom):
(WebCore::PlatformCAAnimationCocoa::setKeyTimes):
(WebCore::PlatformCAAnimationCocoa::copyKeyTimesFrom):
(WebCore::PlatformCAAnimationCocoa::setTimingFunctions):
(WebCore::PlatformCAAnimationCocoa::copyTimingFunctionsFrom):
(WebCore::PlatformCAAnimationCocoa::setAnimations):
(WebCore::PlatformCAAnimationCocoa::copyAnimationsFrom):

  • platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:

(WebCore::PlatformCALayerCocoa::addAnimationForKey):
(WebCore::PlatformCALayerCocoa::animationForKey):

  • platform/graphics/ca/win/PlatformCAAnimationWin.cpp:

(PlatformCAAnimationWin::PlatformCAAnimationWin):
(PlatformCAAnimationWin::setAnimations):
(PlatformCAAnimationWin::copyAnimationsFrom):

  • platform/graphics/ca/win/PlatformCAAnimationWin.h:

Source/WebKit:

setAnimations() method. Add support for the new "Group" PlatformCAAnimation type for
the remote animations.

  • WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.h:
  • WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:

(WebKit::PlatformCAAnimationRemote::Properties::encode const):
(WebKit::PlatformCAAnimationRemote::Properties::decode):
(WebKit::PlatformCAAnimationRemote::copy const):
(WebKit::PlatformCAAnimationRemote::setAnimations):
(WebKit::PlatformCAAnimationRemote::copyAnimationsFrom):
(WebKit::createAnimation):
(WebKit::addAnimationToLayer):
(WebKit::operator<<):

Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r272174 r272178  
     12021-02-01  Antoine Quint  <graouts@webkit.org>
     2
     3        Allow support for CAAnimationGroup
     4        https://bugs.webkit.org/show_bug.cgi?id=221209
     5
     6        Reviewed by Dean Jackson, Sam Weinig and Simon Fraser.
     7
     8        In order to fix bug 219894, we need to use Core Animation's CAAnimationGroup and its
     9        setAnimations() method. This patch adds a new "Group" type to PlatformCAAnimation and
     10        platform-specific integration for Windows and Cocoa ports.
     11
     12        * platform/graphics/ca/PlatformCAAnimation.cpp:
     13        (WebCore::operator<<):
     14        * platform/graphics/ca/PlatformCAAnimation.h:
     15        * platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.h:
     16        * platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm:
     17        (WebCore::PlatformCAAnimationCocoa::PlatformCAAnimationCocoa):
     18        (WebCore::PlatformCAAnimationCocoa::keyPath const):
     19        (WebCore::PlatformCAAnimationCocoa::setTimingFunction):
     20        (WebCore::PlatformCAAnimationCocoa::isAdditive const):
     21        (WebCore::PlatformCAAnimationCocoa::setAdditive):
     22        (WebCore::PlatformCAAnimationCocoa::valueFunction const):
     23        (WebCore::PlatformCAAnimationCocoa::setValueFunction):
     24        (WebCore::PlatformCAAnimationCocoa::setFromValue):
     25        (WebCore::PlatformCAAnimationCocoa::copyFromValueFrom):
     26        (WebCore::PlatformCAAnimationCocoa::setToValue):
     27        (WebCore::PlatformCAAnimationCocoa::copyToValueFrom):
     28        (WebCore::PlatformCAAnimationCocoa::setValues):
     29        (WebCore::PlatformCAAnimationCocoa::copyValuesFrom):
     30        (WebCore::PlatformCAAnimationCocoa::setKeyTimes):
     31        (WebCore::PlatformCAAnimationCocoa::copyKeyTimesFrom):
     32        (WebCore::PlatformCAAnimationCocoa::setTimingFunctions):
     33        (WebCore::PlatformCAAnimationCocoa::copyTimingFunctionsFrom):
     34        (WebCore::PlatformCAAnimationCocoa::setAnimations):
     35        (WebCore::PlatformCAAnimationCocoa::copyAnimationsFrom):
     36        * platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:
     37        (WebCore::PlatformCALayerCocoa::addAnimationForKey):
     38        (WebCore::PlatformCALayerCocoa::animationForKey):
     39        * platform/graphics/ca/win/PlatformCAAnimationWin.cpp:
     40        (PlatformCAAnimationWin::PlatformCAAnimationWin):
     41        (PlatformCAAnimationWin::setAnimations):
     42        (PlatformCAAnimationWin::copyAnimationsFrom):
     43        * platform/graphics/ca/win/PlatformCAAnimationWin.h:
     44
    1452021-02-01  Saam Barati  <sbarati@apple.com>
    246
  • trunk/Source/WebCore/platform/graphics/ca/PlatformCAAnimation.cpp

    r220503 r272178  
    3535    switch (type) {
    3636    case PlatformCAAnimation::Basic: ts << "basic"; break;
     37    case PlatformCAAnimation::Group: ts << "group"; break;
    3738    case PlatformCAAnimation::Keyframe: ts << "keyframe"; break;
    3839    case PlatformCAAnimation::Spring: ts << "spring"; break;
  • trunk/Source/WebCore/platform/graphics/ca/PlatformCAAnimation.h

    r262933 r272178  
    4343class PlatformCAAnimation : public RefCounted<PlatformCAAnimation> {
    4444public:
    45     enum AnimationType { Basic, Keyframe, Spring };
     45    enum AnimationType { Basic, Group, Keyframe, Spring };
    4646    enum FillModeType { NoFillMode, Forwards, Backwards, Both };
    4747    enum ValueFunctionType { NoValueFunction, RotateX, RotateY, RotateZ, ScaleX, ScaleY, ScaleZ, Scale, TranslateX, TranslateY, TranslateZ, Translate };
    … …  
    120120    virtual void copyTimingFunctionsFrom(const PlatformCAAnimation&) = 0;
    121121
     122    // Animation group properties.
     123    virtual void setAnimations(const Vector<RefPtr<PlatformCAAnimation>>&) = 0;
     124    virtual void copyAnimationsFrom(const PlatformCAAnimation&) = 0;
     125
    122126    void setActualStartTimeIfNeeded(CFTimeInterval t)
    123127    {
    … …  
    127131
    128132    bool isBasicAnimation() const;
    129    
     133
    130134protected:
    131135    PlatformCAAnimation(AnimationType type = Basic)
    … …  
    157161        WebCore::PlatformCAAnimation::AnimationType,
    158162        WebCore::PlatformCAAnimation::AnimationType::Basic,
     163        WebCore::PlatformCAAnimation::AnimationType::Group,
    159164        WebCore::PlatformCAAnimation::AnimationType::Keyframe,
    160165        WebCore::PlatformCAAnimation::AnimationType::Spring
  • trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.h

    r260415 r272178  
    3636OBJC_CLASS NSString;
    3737
    38 typedef CAPropertyAnimation* PlatformAnimationRef;
     38typedef CAAnimation* PlatformAnimationRef;
    3939
    4040namespace WebCore {
    … …  
    124124    void copyTimingFunctionsFrom(const PlatformCAAnimation&) override;
    125125
     126    // Animation group properties.
     127    void setAnimations(const Vector<RefPtr<PlatformCAAnimation>>&) final;
     128    void copyAnimationsFrom(const PlatformCAAnimation&) final;
     129
    126130private:
    127131    PlatformCAAnimationCocoa(AnimationType, const String& keyPath);
    128132    PlatformCAAnimationCocoa(PlatformAnimationRef);
    129133
    130     RetainPtr<CAPropertyAnimation> m_animation;
     134    RetainPtr<CAAnimation> m_animation;
    131135};
    132136
  • trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm

    r263941 r272178  
    168168        m_animation = [CABasicAnimation animationWithKeyPath:keyPath];
    169169        break;
     170    case Group:
     171        m_animation = [CAAnimationGroup animation];
     172        break;
    170173    case Keyframe:
    171174        m_animation = [CAKeyframeAnimation animationWithKeyPath:keyPath];
    … …  
    179182PlatformCAAnimationCocoa::PlatformCAAnimationCocoa(PlatformAnimationRef animation)
    180183{
    181     if ([static_cast<CAAnimation*>(animation) isKindOfClass:[CABasicAnimation class]]) {
    182         if ([static_cast<CAAnimation*>(animation) isKindOfClass:[CASpringAnimation class]])
     184    auto caAnimation = static_cast<CAAnimation *>(animation);
     185    if ([caAnimation isKindOfClass:[CABasicAnimation class]]) {
     186        if ([caAnimation isKindOfClass:[CASpringAnimation class]])
    183187            setType(Spring);
    184188        else
    185189            setType(Basic);
    186     } else if ([static_cast<CAAnimation*>(animation) isKindOfClass:[CAKeyframeAnimation class]])
     190    } else if ([caAnimation isKindOfClass:[CAKeyframeAnimation class]])
    187191        setType(Keyframe);
     192    else if ([caAnimation isKindOfClass:[CAAnimationGroup class]])
     193        setType(Group);
    188194    else {
    189195        ASSERT_NOT_REACHED();
    … …  
    191197    }
    192198   
    193     m_animation = static_cast<CAPropertyAnimation*>(animation);
     199    m_animation = caAnimation;
    194200}
    195201
    … …  
    236242String PlatformCAAnimationCocoa::keyPath() const
    237243{
    238     return [m_animation keyPath];
     244    if (animationType() == Group)
     245        return emptyString();
     246
     247    ASSERT([static_cast<CAAnimation *>(m_animation.get()) isKindOfClass:[CAPropertyAnimation class]]);
     248    return [static_cast<CAPropertyAnimation *>(m_animation.get()) keyPath];
    239249}
    240250
    … …  
    334344        }
    335345        break;
     346    case Group:
     347        break;
    336348    }
    337349}
    … …  
    354366bool PlatformCAAnimationCocoa::isAdditive() const
    355367{
    356     return [m_animation isAdditive];
     368    if (animationType() == Group)
     369        return false;
     370
     371    ASSERT([static_cast<CAAnimation *>(m_animation.get()) isKindOfClass:[CAPropertyAnimation class]]);
     372    return [static_cast<CAPropertyAnimation *>(m_animation.get()) isAdditive];
    357373}
    358374
    359375void PlatformCAAnimationCocoa::setAdditive(bool value)
    360376{
    361     [m_animation setAdditive:value];
     377    if (animationType() == Group)
     378        return;
     379
     380    ASSERT([static_cast<CAAnimation *>(m_animation.get()) isKindOfClass:[CAPropertyAnimation class]]);
     381    return [static_cast<CAPropertyAnimation *>(m_animation.get()) setAdditive:value];
    362382}
    363383
    364384PlatformCAAnimation::ValueFunctionType PlatformCAAnimationCocoa::valueFunction() const
    365385{
    366     return fromCAValueFunctionType([[m_animation valueFunction] name]);
     386    if (animationType() == Group)
     387        return NoValueFunction;
     388
     389    ASSERT([static_cast<CAAnimation *>(m_animation.get()) isKindOfClass:[CAPropertyAnimation class]]);
     390    return fromCAValueFunctionType([[static_cast<CAPropertyAnimation *>(m_animation.get()) valueFunction] name]);
    367391}
    368392
    369393void PlatformCAAnimationCocoa::setValueFunction(ValueFunctionType value)
    370394{
    371     [m_animation setValueFunction:[CAValueFunction functionWithName:toCAValueFunctionType(value)]];
     395    if (animationType() == Group)
     396        return;
     397
     398    ASSERT([static_cast<CAAnimation *>(m_animation.get()) isKindOfClass:[CAPropertyAnimation class]]);
     399    return [static_cast<CAPropertyAnimation *>(m_animation.get()) setValueFunction:[CAValueFunction functionWithName:toCAValueFunctionType(value)]];
    372400}
    373401
    … …  
    376404    if (!isBasicAnimation())
    377405        return;
    378     [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:@(value)];
     406    [static_cast<CABasicAnimation *>(m_animation.get()) setFromValue:@(value)];
    379407}
    380408
    … …  
    383411    if (!isBasicAnimation())
    384412        return;
    385     [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:[NSValue valueWithCATransform3D:value]];
     413    [static_cast<CABasicAnimation *>(m_animation.get()) setFromValue:[NSValue valueWithCATransform3D:value]];
    386414}
    387415
    … …  
    390418    if (!isBasicAnimation())
    391419        return;
    392     [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:@[ @(value.x()), @(value.y()), @(value.z()) ]];
     420    [static_cast<CABasicAnimation *>(m_animation.get()) setFromValue:@[ @(value.x()), @(value.y()), @(value.z()) ]];
    393421}
    394422
    … …  
    398426        return;
    399427    auto [r, g, b, a] = value.toSRGBALossy<uint8_t>();
    400     [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:@[@(r), @(g), @(b), @(a)]];
     428    [static_cast<CABasicAnimation *>(m_animation.get()) setFromValue:@[@(r), @(g), @(b), @(a)]];
    401429}
    402430
    … …  
    404432{
    405433    auto value = PlatformCAFilters::filterValueForOperation(operation, internalFilterPropertyIndex);
    406     [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:value.get()];
     434    [static_cast<CABasicAnimation *>(m_animation.get()) setFromValue:value.get()];
    407435}
    408436
    … …  
    411439    if (!isBasicAnimation() || !value.isBasicAnimation())
    412440        return;
    413     auto otherAnimation = static_cast<CABasicAnimation*>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get());
    414     [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:[otherAnimation fromValue]];
     441    auto otherAnimation = static_cast<CABasicAnimation *>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get());
     442    [static_cast<CABasicAnimation *>(m_animation.get()) setFromValue:[otherAnimation fromValue]];
    415443}
    416444
    … …  
    419447    if (!isBasicAnimation())
    420448        return;
    421     [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:@(value)];
     449    [static_cast<CABasicAnimation *>(m_animation.get()) setToValue:@(value)];
    422450}
    423451
    … …  
    426454    if (!isBasicAnimation())
    427455        return;
    428     [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:[NSValue valueWithCATransform3D:value]];
     456    [static_cast<CABasicAnimation *>(m_animation.get()) setToValue:[NSValue valueWithCATransform3D:value]];
    429457}
    430458
    … …  
    433461    if (!isBasicAnimation())
    434462        return;
    435     [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:@[ @(value.x()), @(value.y()), @(value.z()) ]];
     463    [static_cast<CABasicAnimation *>(m_animation.get()) setToValue:@[ @(value.x()), @(value.y()), @(value.z()) ]];
    436464}
    437465
    … …  
    441469        return;
    442470    auto [r, g, b, a] = value.toSRGBALossy<uint8_t>();
    443     [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:@[@(r), @(g), @(b), @(a)]];
     471    [static_cast<CABasicAnimation *>(m_animation.get()) setToValue:@[@(r), @(g), @(b), @(a)]];
    444472}
    445473
    … …  
    447475{
    448476    auto value = PlatformCAFilters::filterValueForOperation(operation, internalFilterPropertyIndex);
    449     [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:value.get()];
     477    [static_cast<CABasicAnimation *>(m_animation.get()) setToValue:value.get()];
    450478}
    451479
    … …  
    455483        return;
    456484
    457     auto otherAnimation = static_cast<CABasicAnimation*>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get());
    458     [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:[otherAnimation toValue]];
     485    auto otherAnimation = static_cast<CABasicAnimation *>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get());
     486    [static_cast<CABasicAnimation *>(m_animation.get()) setToValue:[otherAnimation toValue]];
    459487}
    460488
    … …  
    466494        return;
    467495
    468     [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:createNSArray(value, [] (float number) {
     496    [static_cast<CAKeyframeAnimation *>(m_animation.get()) setValues:createNSArray(value, [] (float number) {
    469497        return @(number);
    470498    }).get()];
    … …  
    476504        return;
    477505
    478     [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:createNSArray(value, [] (auto& matrix) {
     506    [static_cast<CAKeyframeAnimation *>(m_animation.get()) setValues:createNSArray(value, [] (auto& matrix) {
    479507        return [NSValue valueWithCATransform3D:matrix];
    480508    }).get()];
    … …  
    486514        return;
    487515
    488     [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:createNSArray(value, [] (auto& point) {
     516    [static_cast<CAKeyframeAnimation *>(m_animation.get()) setValues:createNSArray(value, [] (auto& point) {
    489517        return @[@(point.x()), @(point.y()), @(point.z())];
    490518    }).get()];
    … …  
    496524        return;
    497525
    498     [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:createNSArray(value, [] (auto& color) {
     526    [static_cast<CAKeyframeAnimation *>(m_animation.get()) setValues:createNSArray(value, [] (auto& color) {
    499527        auto [r, g, b, a] = color.template toSRGBALossy<uint8_t>();
    500528        return @[@(r), @(g), @(b), @(a)];
    … …  
    507535        return;
    508536
    509     [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:createNSArray(values, [&] (auto& value) {
     537    [static_cast<CAKeyframeAnimation *>(m_animation.get()) setValues:createNSArray(values, [&] (auto& value) {
    510538        return PlatformCAFilters::filterValueForOperation(value.get(), internalFilterPropertyIndex);
    511539    }).get()];
    … …  
    517545        return;
    518546
    519     auto otherAnimation = static_cast<CAKeyframeAnimation*>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get());
    520     [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:[otherAnimation values]];
     547    auto otherAnimation = static_cast<CAKeyframeAnimation *>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get());
     548    [static_cast<CAKeyframeAnimation *>(m_animation.get()) setValues:[otherAnimation values]];
    521549}
    522550
    523551void PlatformCAAnimationCocoa::setKeyTimes(const Vector<float>& value)
    524552{
    525     [static_cast<CAKeyframeAnimation*>(m_animation.get()) setKeyTimes:createNSArray(value, [] (float time) {
     553    [static_cast<CAKeyframeAnimation *>(m_animation.get()) setKeyTimes:createNSArray(value, [] (float time) {
    526554        return @(time);
    527555    }).get()];
    … …  
    530558void PlatformCAAnimationCocoa::copyKeyTimesFrom(const PlatformCAAnimation& value)
    531559{
    532     auto other = static_cast<CAKeyframeAnimation*>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get());
    533     [static_cast<CAKeyframeAnimation*>(m_animation.get()) setKeyTimes:[other keyTimes]];
     560    auto other = static_cast<CAKeyframeAnimation *>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get());
     561    [static_cast<CAKeyframeAnimation *>(m_animation.get()) setKeyTimes:[other keyTimes]];
    534562}
    535563
    536564void PlatformCAAnimationCocoa::setTimingFunctions(const Vector<const TimingFunction*>& value, bool reverse)
    537565{
    538     [static_cast<CAKeyframeAnimation*>(m_animation.get()) setTimingFunctions:createNSArray(value, [&] (auto& function) {
     566    [static_cast<CAKeyframeAnimation *>(m_animation.get()) setTimingFunctions:createNSArray(value, [&] (auto& function) {
    539567        return toCAMediaTimingFunction(function, reverse);
    540568    }).get()];
    … …  
    543571void PlatformCAAnimationCocoa::copyTimingFunctionsFrom(const PlatformCAAnimation& value)
    544572{
    545     auto other = static_cast<CAKeyframeAnimation*>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get());
    546     [static_cast<CAKeyframeAnimation*>(m_animation.get()) setTimingFunctions:[other timingFunctions]];
     573    auto other = static_cast<CAKeyframeAnimation *>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get());
     574    [static_cast<CAKeyframeAnimation *>(m_animation.get()) setTimingFunctions:[other timingFunctions]];
     575}
     576
     577void PlatformCAAnimationCocoa::setAnimations(const Vector<RefPtr<PlatformCAAnimation>>& value)
     578{
     579    ASSERT(animationType() == Group);
     580    ASSERT([static_cast<CAAnimation *>(m_animation.get()) isKindOfClass:[CAAnimationGroup class]]);
     581
     582    [static_cast<CAAnimationGroup *>(m_animation.get()) setAnimations:createNSArray(value, [&] (auto& animation) -> CAAnimation * {
     583        if (is<PlatformCAAnimationCocoa>(animation.get()))
     584            return downcast<PlatformCAAnimationCocoa>(animation.get())->m_animation.get();
     585        return nil;
     586    }).get()];
     587}
     588
     589void PlatformCAAnimationCocoa::copyAnimationsFrom(const PlatformCAAnimation& value)
     590{
     591    ASSERT(animationType() == Group);
     592    ASSERT(value.animationType() == Group);
     593    ASSERT([static_cast<CAAnimation *>(m_animation.get()) isKindOfClass:[CAAnimationGroup class]]);
     594    ASSERT([static_cast<CAAnimation *>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get()) isKindOfClass:[CAAnimationGroup class]]);
     595
     596    auto other = static_cast<CAAnimationGroup *>(downcast<PlatformCAAnimationCocoa>(value).m_animation.get());
     597    [static_cast<CAAnimationGroup *>(m_animation.get()) setAnimations:[other animations]];
    547598}
    548599
  • trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm

    r271699 r272178  
    512512    }
    513513   
    514     CAPropertyAnimation* propertyAnimation = static_cast<CAPropertyAnimation*>(downcast<PlatformCAAnimationCocoa>(animation).platformAnimation());
     514    CAAnimation *propertyAnimation = static_cast<CAAnimation *>(downcast<PlatformCAAnimationCocoa>(animation).platformAnimation());
    515515    if (![propertyAnimation delegate])
    516516        [propertyAnimation setDelegate:static_cast<id>(m_delegate.get())];
    … …  
    530530RefPtr<PlatformCAAnimation> PlatformCALayerCocoa::animationForKey(const String& key)
    531531{
    532     CAPropertyAnimation* propertyAnimation = static_cast<CAPropertyAnimation*>([m_layer animationForKey:key]);
     532    CAAnimation *propertyAnimation = static_cast<CAAnimation *>([m_layer animationForKey:key]);
    533533    if (!propertyAnimation)
    534534        return nullptr;
  • trunk/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp

    r263941 r272178  
    158158    if (type == Basic)
    159159        m_animation = adoptCF(CACFAnimationCreate(kCACFBasicAnimation));
    160     else
     160    else if (type == Keyframe)
    161161        m_animation = adoptCF(CACFAnimationCreate(kCACFKeyframeAnimation));
     162    else if (type == Group)
     163        m_animation = adoptCF(CACFAnimationCreate(kCACFAnimationGroup));
    162164   
    163165    CACFAnimationSetKeyPath(m_animation.get(), keyPath.createCFString().get());
    … …  
    170172    else if (CACFAnimationGetClass(animation) == kCACFKeyframeAnimation)
    171173        setType(Keyframe);
     174    else if (CACFAnimationGetClass(animation) == kCACFAnimationGroup)
     175        setType(Group);
    172176    else {
    173177        ASSERT_NOT_REACHED();
    … …  
    554558}
    555559
     560void PlatformCAAnimationWin::setAnimations(const Vector<RefPtr<PlatformCAAnimation>>& value)
     561{
     562    auto array = adoptCF(CFArrayCreateMutable(0, value.size(), &kCFTypeArrayCallBacks));
     563    for (auto& animation : value) {
     564        if (is<PlatformCAAnimationWin>(animation.get()))
     565            CFArrayAppendValue(array.get(), downcast<PlatformCAAnimationWin>(*animation).m_animation.get());
     566    }
     567
     568    CACFAnimationSetAnimations(m_animation.get(), array.get());
     569}
     570
     571void PlatformCAAnimationWin::copyAnimationsFrom(const PlatformCAAnimation& value)
     572{
     573    CACFAnimationSetAnimations(m_animation.get(), CACFAnimationGetAnimations(downcast<PlatformCAAnimationWin>(value).platformAnimation()));
     574}
     575
    556576#endif // PLATFORM(WIN)
  • trunk/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.h

    r260415 r272178  
    114114    void copyTimingFunctionsFrom(const PlatformCAAnimation&) override;
    115115
     116    // Animation group properties.
     117    void setAnimations(const Vector<RefPtr<PlatformCAAnimation>>&) final;
     118    void copyAnimationsFrom(const PlatformCAAnimation&) final;
     119
    116120private:
    117121    PlatformCAAnimationWin(AnimationType, const String& keyPath);
  • trunk/Source/WebKit/ChangeLog

    r272175 r272178  
     12021-02-01  Antoine Quint  <graouts@webkit.org>
     2
     3        Allow support for CAAnimationGroup
     4        https://bugs.webkit.org/show_bug.cgi?id=221209
     5
     6        Reviewed by Dean Jackson, Sam Weinig and Simon Fraser.
     7
     8        In order to fix bug 219894, we need to use Core Animation's CAAnimationGroup and its
     9        setAnimations() method. Add support for the new "Group" PlatformCAAnimation type for
     10        the remote animations.
     11
     12        * WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.h:
     13        * WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:
     14        (WebKit::PlatformCAAnimationRemote::Properties::encode const):
     15        (WebKit::PlatformCAAnimationRemote::Properties::decode):
     16        (WebKit::PlatformCAAnimationRemote::copy const):
     17        (WebKit::PlatformCAAnimationRemote::setAnimations):
     18        (WebKit::PlatformCAAnimationRemote::copyAnimationsFrom):
     19        (WebKit::createAnimation):
     20        (WebKit::addAnimationToLayer):
     21        (WebKit::operator<<):
     22
    1232021-02-01  Wenson Hsieh  <wenson_hsieh@apple.com>
    224
  • trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.h

    r265098 r272178  
    120120    void copyTimingFunctionsFrom(const WebCore::PlatformCAAnimation&) override;
    121121
     122    // Animation group properties.
     123    void setAnimations(const Vector<RefPtr<PlatformCAAnimation>>&) final;
     124    void copyAnimationsFrom(const PlatformCAAnimation&) final;
     125
    122126    AnimationType animationType() const { return m_properties.animationType; }
    123127    void setHasExplicitBeginTime(bool hasExplicitBeginTime) { m_properties.hasExplicitBeginTime = hasExplicitBeginTime; }
    … …  
    290294        Vector<float> keyTimes;
    291295        Vector<RefPtr<WebCore::TimingFunction>> timingFunctions;
     296
     297        Vector<Properties> animations;
    292298    };
    293299
  • trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm

    r265932 r272178  
    242242    for (const auto& timingFunction : timingFunctions)
    243243        encodeTimingFunction(encoder, timingFunction.get());
     244
     245    encoder << animations;
    244246}
    245247
    … …  
    320322        }
    321323    }
     324
     325    if (!decoder.decode(properties.animations))
     326        return WTF::nullopt;
    322327
    323328    return WTFMove(properties);
    … …  
    356361        animation->copyToValueFrom(*this);
    357362    }
    358    
     363
     364    animation->copyAnimationsFrom(*this);
     365
    359366    return animation;
    360367}
    … …  
    710717    m_properties.timingFunctions = other.m_properties.timingFunctions;
    711718    m_properties.reverseTimingFunctions = other.m_properties.reverseTimingFunctions;
     719}
     720
     721void PlatformCAAnimationRemote::setAnimations(const Vector<RefPtr<PlatformCAAnimation>>& values)
     722{
     723    m_properties.animations = values.map([](auto& value) {
     724        return downcast<PlatformCAAnimationRemote>(value.get())->properties();
     725    });
     726}
     727
     728void PlatformCAAnimationRemote::copyAnimationsFrom(const PlatformCAAnimation& value)
     729{
     730    const PlatformCAAnimationRemote& other = downcast<PlatformCAAnimationRemote>(value);
     731    m_properties.animations = other.m_properties.animations;
    712732}
    713733
    … …  
    735755}
    736756
    737 static void addAnimationToLayer(CALayer *layer, RemoteLayerTreeHost* layerTreeHost, const String& key, const PlatformCAAnimationRemote::Properties& properties)
    738 {
    739     RetainPtr<CAPropertyAnimation> caAnimation;
     757static RetainPtr<CAAnimation> createAnimation(CALayer *layer, RemoteLayerTreeHost* layerTreeHost, const PlatformCAAnimationRemote::Properties& properties)
     758{
     759    RetainPtr<CAAnimation> caAnimation;
    740760    switch (properties.animationType) {
    741761    case PlatformCAAnimation::Basic: {
    742762        auto basicAnimation = [CABasicAnimation animationWithKeyPath:properties.keyPath];
    743        
     763
    744764        if (properties.keyValues.size() > 1) {
    745765            [basicAnimation setFromValue:animationValueFromKeyframeValue(properties.keyValues[0])];
    … …  
    751771
    752772        caAnimation = basicAnimation;
     773        break;
     774    }
     775    case PlatformCAAnimation::Group: {
     776        auto animationGroup = [CAAnimationGroup animation];
     777
     778        if (properties.animations.size()) {
     779            [animationGroup setAnimations:createNSArray(properties.animations, [&] (auto& animationProperties) {
     780                return createAnimation(layer, layerTreeHost, animationProperties).get();
     781            }).get()];
     782        }
     783
     784        caAnimation = animationGroup;
    753785        break;
    754786    }
    … …  
    776808            }).get()];
    777809        }
    778        
     810
    779811        caAnimation = keyframeAnimation;
    780812        break;
    … …  
    782814    case PlatformCAAnimation::Spring: {
    783815        auto springAnimation = [CASpringAnimation animationWithKeyPath:properties.keyPath];
    784        
     816
    785817        if (properties.keyValues.size() > 1) {
    786818            [springAnimation setFromValue:animationValueFromKeyframeValue(properties.keyValues[0])];
    787819            [springAnimation setToValue:animationValueFromKeyframeValue(properties.keyValues[1])];
    788820        }
    789        
     821
    790822        if (properties.timingFunctions.size()) {
    791823            auto& timingFunction = properties.timingFunctions[0];
    … …  
    802834    }
    803835    }
    804    
     836
    805837    [caAnimation setBeginTime:properties.beginTime];
    806838    [caAnimation setDuration:properties.duration];
    … …  
    810842    [caAnimation setAutoreverses:properties.autoReverses];
    811843    [caAnimation setRemovedOnCompletion:properties.removedOnCompletion];
    812     [caAnimation setAdditive:properties.additive];
    813    
     844
     845    if ([caAnimation isKindOfClass:[CAPropertyAnimation class]]) {
     846        [(CAPropertyAnimation *)caAnimation setAdditive:properties.additive];
     847        if (properties.valueFunction != PlatformCAAnimation::NoValueFunction)
     848            [(CAPropertyAnimation *)caAnimation setValueFunction:[CAValueFunction functionWithName:toCAValueFunctionType(properties.valueFunction)]];
     849    }
     850
    814851    if (properties.fillMode != PlatformCAAnimation::NoFillMode)
    815852        [caAnimation setFillMode:toCAFillModeType(properties.fillMode)];
    816853
    817     if (properties.valueFunction != PlatformCAAnimation::NoValueFunction)
    818         [caAnimation setValueFunction:[CAValueFunction functionWithName:toCAValueFunctionType(properties.valueFunction)]];
    819    
    820854    if (properties.hasExplicitBeginTime)
    821855        [caAnimation setValue:@YES forKey:WKExplicitBeginTimeFlag];
    822    
     856
    823857    if (layerTreeHost) {
    824858        GraphicsLayer::PlatformLayerID layerID = RemoteLayerTreeNode::layerID(layer);
    825    
     859
    826860        RetainPtr<WKAnimationDelegate>& delegate = layerTreeHost->animationDelegates().add(layerID, nullptr).iterator->value;
    827861        if (!delegate)
    … …  
    830864        [caAnimation setDelegate:delegate.get()];
    831865    }
    832    
    833     [layer addAnimation:caAnimation.get() forKey:key];
     866
     867    return caAnimation;
     868}
     869
     870static void addAnimationToLayer(CALayer *layer, RemoteLayerTreeHost* layerTreeHost, const String& key, const PlatformCAAnimationRemote::Properties& properties)
     871{
     872    [layer addAnimation:createAnimation(layer, layerTreeHost, properties).get() forKey:key];
    834873}
    835874
    … …  
    944983    ts.decreaseIndent();
    945984
     985    if (!animation.animations.isEmpty()) {
     986        ts << "\n";
     987        ts.increaseIndent();
     988        ts.writeIndent();
     989        ts << "(" << "animations";
     990        ts.increaseIndent();
     991
     992        for (auto& childAnimation : animation.animations) {
     993            ts << "\n";
     994            ts.writeIndent();
     995            ts << "(animation " << childAnimation;
     996            ts << ")";
     997        }
     998
     999        ts.decreaseIndent();
     1000        ts.decreaseIndent();
     1001    }
     1002
    9461003    return ts;
    9471004}
Note: See TracChangeset for help on using the changeset viewer.