Changeset 268483 in webkit


Ignore:
Timestamp:
Oct 14, 2020 1:37:54 PM (4 years ago)
Author:
graouts@webkit.org
Message:

Simplify management of LayerPropertyAnimation instances in GraphicsLayerCA
https://bugs.webkit.org/show_bug.cgi?id=217707
<rdar://problem/70291140>

Reviewed by Dean Jackson.

The management of LayerPropertyAnimation instances in GraphicsLayerCA spread
those animations between different data structures. We now simplify this to
be a single Vector<LayerPropertyAnimation> with three new properties.

The m_playState property indicates:

  • whether the animation has been added to the list but awaiting the next commit

to be played (PlayPending)

  • whether the animation has been committed and playing (Playing)
  • whether the animation has been marked to be paused but awaiting the next commit

to be paused (PausePending)

  • whether the animation has been committed and paused (Paused)

The m_pendingRemoval property indicates whether the animation has been marked for
removal upon the next commit.

The m_beginTime property indicates the time at which the animation was first added,
ensuring that the animation can be removed and re-added while preserving the same
begin time.

As such, when GraphicsLayerCA::updateAnimations() is called we remove all animations
from the layer, filter m_animations to only have animations that are not marked
as pending removal, and add the now-current list of animations to the layer.

No new test since this change is refactoring only and should not have any change
in behavior.

  • platform/graphics/ca/GraphicsLayerCA.cpp:

(WebCore::GraphicsLayerCA::moveOrCopyAnimations):
(WebCore::GraphicsLayerCA::animationIsRunning const):
(WebCore::animationCanBeAccelerated):
(WebCore::GraphicsLayerCA::pauseAnimation):
(WebCore::GraphicsLayerCA::removeAnimation):
(WebCore::GraphicsLayerCA::platformCALayerAnimationStarted):
(WebCore::GraphicsLayerCA::updateAnimations):
(WebCore::GraphicsLayerCA::isRunningTransformAnimation const):
(WebCore::GraphicsLayerCA::setAnimationOnLayer):
(WebCore::GraphicsLayerCA::removeCAAnimationFromLayer):
(WebCore::GraphicsLayerCA::pauseCAAnimationOnLayer):
(WebCore::GraphicsLayerCA::createAnimationFromKeyframes):
(WebCore::GraphicsLayerCA::appendToUncommittedAnimations):
(WebCore::GraphicsLayerCA::createTransformAnimationsFromKeyframes):
(WebCore::animationIdentifier): Deleted.
(WebCore::GraphicsLayerCA::animationCanBeAccelerated const): Deleted.
(WebCore::GraphicsLayerCA::addProcessingActionForAnimation): Deleted.
(WebCore::GraphicsLayerCA::ensureLayerAnimations): Deleted.

  • platform/graphics/ca/GraphicsLayerCA.h:

(WebCore::GraphicsLayerCA::hasAnimations const):
(WebCore::GraphicsLayerCA::LayerPropertyAnimation::animationIdentifier const):
(WebCore::GraphicsLayerCA::moveAnimations):
(WebCore::GraphicsLayerCA::copyAnimations):
(WebCore::GraphicsLayerCA::animationIsRunning const): Deleted.
(WebCore::GraphicsLayerCA::AnimationProcessingAction::AnimationProcessingAction): Deleted.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r268477 r268483  
     12020-10-14  Antoine Quint  <graouts@webkit.org>
     2
     3        Simplify management of LayerPropertyAnimation instances in GraphicsLayerCA
     4        https://bugs.webkit.org/show_bug.cgi?id=217707
     5        <rdar://problem/70291140>
     6
     7        Reviewed by Dean Jackson.
     8
     9        The management of LayerPropertyAnimation instances in GraphicsLayerCA spread
     10        those animations between different data structures. We now simplify this to
     11        be a single Vector<LayerPropertyAnimation> with three new properties.
     12
     13        The m_playState property indicates:
     14
     15        - whether the animation has been added to the list but awaiting the next commit
     16        to be played (PlayPending)
     17        - whether the animation has been committed and playing (Playing)
     18        - whether the animation has been marked to be paused but awaiting the next commit
     19        to be paused (PausePending)
     20        - whether the animation has been committed and paused (Paused)
     21
     22        The m_pendingRemoval property indicates whether the animation has been marked for
     23        removal upon the next commit.
     24
     25        The m_beginTime property indicates the time at which the animation was first added,
     26        ensuring that the animation can be removed and re-added while preserving the same
     27        begin time.
     28
     29        As such, when GraphicsLayerCA::updateAnimations() is called we remove all animations
     30        from the layer, filter m_animations to only have animations that are not marked
     31        as pending removal, and add the now-current list of animations to the layer.
     32
     33        No new test since this change is refactoring only and should not have any change
     34        in behavior.
     35
     36        * platform/graphics/ca/GraphicsLayerCA.cpp:
     37        (WebCore::GraphicsLayerCA::moveOrCopyAnimations):
     38        (WebCore::GraphicsLayerCA::animationIsRunning const):
     39        (WebCore::animationCanBeAccelerated):
     40        (WebCore::GraphicsLayerCA::pauseAnimation):
     41        (WebCore::GraphicsLayerCA::removeAnimation):
     42        (WebCore::GraphicsLayerCA::platformCALayerAnimationStarted):
     43        (WebCore::GraphicsLayerCA::updateAnimations):
     44        (WebCore::GraphicsLayerCA::isRunningTransformAnimation const):
     45        (WebCore::GraphicsLayerCA::setAnimationOnLayer):
     46        (WebCore::GraphicsLayerCA::removeCAAnimationFromLayer):
     47        (WebCore::GraphicsLayerCA::pauseCAAnimationOnLayer):
     48        (WebCore::GraphicsLayerCA::createAnimationFromKeyframes):
     49        (WebCore::GraphicsLayerCA::appendToUncommittedAnimations):
     50        (WebCore::GraphicsLayerCA::createTransformAnimationsFromKeyframes):
     51        (WebCore::animationIdentifier): Deleted.
     52        (WebCore::GraphicsLayerCA::animationCanBeAccelerated const): Deleted.
     53        (WebCore::GraphicsLayerCA::addProcessingActionForAnimation): Deleted.
     54        (WebCore::GraphicsLayerCA::ensureLayerAnimations): Deleted.
     55        * platform/graphics/ca/GraphicsLayerCA.h:
     56        (WebCore::GraphicsLayerCA::hasAnimations const):
     57        (WebCore::GraphicsLayerCA::LayerPropertyAnimation::animationIdentifier const):
     58        (WebCore::GraphicsLayerCA::moveAnimations):
     59        (WebCore::GraphicsLayerCA::copyAnimations):
     60        (WebCore::GraphicsLayerCA::animationIsRunning const): Deleted.
     61        (WebCore::GraphicsLayerCA::AnimationProcessingAction::AnimationProcessingAction): Deleted.
     62
    1632020-10-14  Youenn Fablet  <youenn@apple.com>
    264
  • trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp

    r267188 r268483  
    271271}
    272272
    273 static String animationIdentifier(const String& animationName, AnimatedPropertyID property, int index, int subIndex)
    274 {
    275     return makeString(animationName, '_', static_cast<unsigned>(property), '_', index, '_', subIndex);
    276 }
    277 
    278273static bool animationHasStepsTimingFunction(const KeyframeValueList& valueList, const Animation* anim)
    279274{
     
    694689void GraphicsLayerCA::moveOrCopyAnimations(MoveOrCopy operation, PlatformCALayer *fromLayer, PlatformCALayer *toLayer)
    695690{
    696     if (!hasAnimations())
    697         return;
    698 
    699     // Look for running animations affecting this property.
    700     for (const auto& it : m_animations->runningAnimations) {
    701         const auto& propertyAnimations = it.value;
    702         size_t numAnimations = propertyAnimations.size();
    703         for (size_t i = 0; i < numAnimations; ++i) {
    704             const LayerPropertyAnimation& currAnimation = propertyAnimations[i];
    705 
    706             if (currAnimation.m_property == AnimatedPropertyTransform
    707                 || currAnimation.m_property == AnimatedPropertyOpacity
    708                 || currAnimation.m_property == AnimatedPropertyBackgroundColor
    709                 || currAnimation.m_property == AnimatedPropertyFilter)
    710                 moveOrCopyLayerAnimation(operation, animationIdentifier(currAnimation.m_name, currAnimation.m_property, currAnimation.m_index, currAnimation.m_subIndex), fromLayer, toLayer);
    711         }
     691    for (auto& animation : m_animations) {
     692        if ((animation.m_property == AnimatedPropertyTransform
     693            || animation.m_property == AnimatedPropertyOpacity
     694            || animation.m_property == AnimatedPropertyBackgroundColor
     695            || animation.m_property == AnimatedPropertyFilter)
     696            && (animation.m_playState == PlayState::Playing || animation.m_playState == PlayState::Paused))
     697            moveOrCopyLayerAnimation(operation, animation.animationIdentifier(), fromLayer, toLayer);
    712698    }
    713699}
     
    10271013}
    10281014
    1029 bool GraphicsLayerCA::animationCanBeAccelerated(const KeyframeValueList& valueList, const Animation* anim) const
     1015bool GraphicsLayerCA::animationIsRunning(const String& animationName) const
     1016{
     1017    auto index = m_animations.findMatching([&](LayerPropertyAnimation animation) {
     1018        return animation.m_name == animationName;
     1019    });
     1020    return index != notFound && m_animations[index].m_playState == PlayState::Playing;
     1021}
     1022
     1023static bool animationCanBeAccelerated(const KeyframeValueList& valueList, const Animation* anim)
    10301024{
    10311025    if (anim->playbackRate() != 1 || !anim->directionIsForwards())
     
    10391033
    10401034    return true;
    1041 }
    1042 
    1043 void GraphicsLayerCA::addProcessingActionForAnimation(const String& animationName, AnimationProcessingAction processingAction)
    1044 {
    1045     ensureLayerAnimations();
    1046 
    1047     auto& processingActions = m_animations->animationsToProcess.ensure(animationName, [] {
    1048         return Vector<AnimationProcessingAction> { };
    1049     }).iterator->value;
    1050 
    1051     if (!processingActions.isEmpty() && processingActions.last().action == Remove)
    1052         return;
    1053 
    1054     processingActions.append(processingAction);
    10551035}
    10561036
     
    10901070    LOG_WITH_STREAM(Animations, stream << "GraphicsLayerCA " << this << " id " << primaryLayerID() << " pauseAnimation " << animationName << " (is running " << animationIsRunning(animationName) << ")");
    10911071
    1092     // Call add since if there is already a Remove in there, we don't want to overwrite it with a Pause.
    1093     addProcessingActionForAnimation(animationName, AnimationProcessingAction { Pause, Seconds { timeOffset } });
     1072    auto index = m_animations.findMatching([&](LayerPropertyAnimation animation) {
     1073        return animation.m_name == animationName && !animation.m_pendingRemoval;
     1074    });
     1075
     1076    if (index == notFound)
     1077        return;
     1078
     1079    auto& animation = m_animations[index];
     1080    animation.m_playState = PlayState::PausePending;
     1081    animation.m_timeOffset = Seconds { timeOffset };
    10941082
    10951083    noteLayerPropertyChanged(AnimationChanged);
     
    11001088    LOG_WITH_STREAM(Animations, stream << "GraphicsLayerCA " << this << " id " << primaryLayerID() << " removeAnimation " << animationName << " (is running " << animationIsRunning(animationName) << ")");
    11011089
    1102     if (!animationIsRunning(animationName)) {
    1103         removeFromUncommittedAnimations(animationName);
    1104         return;
    1105     }
    1106 
    1107     addProcessingActionForAnimation(animationName, AnimationProcessingAction(Remove));
     1090    auto index = m_animations.findMatching([&](LayerPropertyAnimation animation) {
     1091        return animation.m_name == animationName && !animation.m_pendingRemoval;
     1092    });
     1093
     1094    if (index == notFound)
     1095        return;
     1096
     1097    m_animations[index].m_pendingRemoval = true;
     1098
    11081099    noteLayerPropertyChanged(AnimationChanged | CoverageRectChanged);
    11091100}
     
    11121103{
    11131104    LOG_WITH_STREAM(Animations, stream << "GraphicsLayerCA " << this << " id " << primaryLayerID() << " platformCALayerAnimationStarted " << animationKey);
     1105
     1106    auto index = m_animations.findMatching([&](LayerPropertyAnimation animation) {
     1107        return animation.animationIdentifier() == animationKey && !animation.m_beginTime;
     1108    });
     1109
     1110    if (index != notFound)
     1111        m_animations[index].m_beginTime = startTime.secondsSinceEpoch();
     1112
    11141113    client().notifyAnimationStarted(this, animationKey, startTime);
    11151114}
     
    28532852void GraphicsLayerCA::updateAnimations()
    28542853{
    2855     if (!hasAnimations())
    2856         return;
    2857 
    2858     size_t numAnimations;
    2859     if ((numAnimations = m_animations->uncomittedAnimations.size())) {
    2860         for (size_t i = 0; i < numAnimations; ++i) {
    2861             const LayerPropertyAnimation& pendingAnimation = m_animations->uncomittedAnimations[i];
    2862             setAnimationOnLayer(*pendingAnimation.m_animation, pendingAnimation.m_property, pendingAnimation.m_name, pendingAnimation.m_index, pendingAnimation.m_subIndex, pendingAnimation.m_timeOffset);
    2863 
    2864             AnimationsMap::iterator it = m_animations->runningAnimations.find(pendingAnimation.m_name);
    2865             if (it == m_animations->runningAnimations.end()) {
    2866                 Vector<LayerPropertyAnimation> animations;
    2867                 animations.append(pendingAnimation);
    2868                 m_animations->runningAnimations.add(pendingAnimation.m_name, animations);
    2869             } else {
    2870                 Vector<LayerPropertyAnimation>& animations = it->value;
    2871                 animations.append(pendingAnimation);
    2872             }
    2873         }
    2874         m_animations->uncomittedAnimations.clear();
    2875     }
    2876 
    2877     if (m_animations->animationsToProcess.size()) {
    2878         for (const auto& it : m_animations->animationsToProcess) {
    2879             const String& currentAnimationName = it.key;
    2880             auto animationIterator = m_animations->runningAnimations.find(currentAnimationName);
    2881             if (animationIterator == m_animations->runningAnimations.end())
    2882                 continue;
    2883 
    2884             for (const auto& processingInfo : it.value) {
    2885                 const Vector<LayerPropertyAnimation>& animations = animationIterator->value;
    2886                 for (const auto& currentAnimation : animations) {
    2887                     switch (processingInfo.action) {
    2888                     case Remove:
    2889                         removeCAAnimationFromLayer(currentAnimation.m_property, currentAnimationName, currentAnimation.m_index, currentAnimation.m_subIndex);
    2890                         break;
    2891                     case Pause:
    2892                         pauseCAAnimationOnLayer(currentAnimation.m_property, currentAnimationName, currentAnimation.m_index, currentAnimation.m_subIndex, processingInfo.timeOffset);
    2893                         break;
    2894                     }
    2895                 }
    2896 
    2897                 if (processingInfo.action == Remove)
    2898                     m_animations->runningAnimations.remove(currentAnimationName);
    2899             }
    2900         }
    2901 
    2902         m_animations->animationsToProcess.clear();
     2854    // Remove all animations so far.
     2855    for (auto& animation : m_animations)
     2856        removeCAAnimationFromLayer(animation);
     2857
     2858    // Remove all animations from the list that were pending removal.
     2859    m_animations.removeAllMatching([&](LayerPropertyAnimation animation) {
     2860        return animation.m_pendingRemoval;
     2861    });
     2862
     2863    // Add all remaining animations.
     2864    for (auto& animation : m_animations) {
     2865        setAnimationOnLayer(animation);
     2866        if (animation.m_playState == PlayState::PausePending || animation.m_playState == PlayState::Paused) {
     2867            pauseCAAnimationOnLayer(animation);
     2868            animation.m_playState = PlayState::Paused;
     2869        } else
     2870            animation.m_playState = PlayState::Playing;
    29032871    }
    29042872}
     
    29062874bool GraphicsLayerCA::isRunningTransformAnimation() const
    29072875{
    2908     if (!hasAnimations())
    2909         return false;
    2910 
    2911     for (const auto& it : m_animations->runningAnimations) {
    2912         const auto& propertyAnimations = it.value;
    2913         size_t numAnimations = propertyAnimations.size();
    2914         for (size_t i = 0; i < numAnimations; ++i) {
    2915             const LayerPropertyAnimation& currAnimation = propertyAnimations[i];
    2916             if (currAnimation.m_property == AnimatedPropertyTransform)
    2917                 return true;
    2918         }
    2919     }
    2920     return false;
    2921 }
    2922 
    2923 void GraphicsLayerCA::ensureLayerAnimations()
    2924 {
    2925     if (!m_animations)
    2926         m_animations = makeUnique<LayerAnimations>();
    2927 }
    2928 
    2929 void GraphicsLayerCA::setAnimationOnLayer(PlatformCAAnimation& caAnim, AnimatedPropertyID property, const String& animationName, int index, int subIndex, Seconds timeOffset)
    2930 {
     2876    return m_animations.findMatching([&](LayerPropertyAnimation animation) {
     2877        return animation.m_property == AnimatedPropertyTransform && animation.m_playState == PlayState::Playing;
     2878    }) != notFound;
     2879}
     2880
     2881void GraphicsLayerCA::setAnimationOnLayer(LayerPropertyAnimation& animation)
     2882{
     2883    auto property = animation.m_property;
    29312884    PlatformCALayer* layer = animatedLayer(property);
    29322885
    2933     if (timeOffset)
    2934         caAnim.setBeginTime(CACurrentMediaTime() - timeOffset.seconds());
    2935 
    2936     String animationID = animationIdentifier(animationName, property, index, subIndex);
     2886    auto& caAnim = *animation.m_animation;
     2887
     2888    if (animation.m_timeOffset) {
     2889        // In case we have an offset, we need to record the beginTime now since we have to pass in an explicit
     2890        // value in the first place.
     2891        if (!animation.m_beginTime)
     2892            animation.m_beginTime = Seconds(CACurrentMediaTime());
     2893        caAnim.setBeginTime((animation.m_beginTime - animation.m_timeOffset).seconds());
     2894    } else if (animation.m_beginTime) {
     2895        // If we already have a begin time, then we already started in the past and must ensure we use that same
     2896        // begin time. Any other case will get use the CA transaction's time as its begin time and will be recorded
     2897        // in platformCALayerAnimationStarted().
     2898        caAnim.setBeginTime(animation.m_beginTime.seconds());
     2899    }
     2900
     2901    String animationID = animation.animationIdentifier();
    29372902
    29382903    layer->removeAnimationForKey(animationID);
     
    29652930}
    29662931
    2967 bool GraphicsLayerCA::removeCAAnimationFromLayer(AnimatedPropertyID property, const String& animationName, int index, int subIndex)
    2968 {
    2969     PlatformCALayer* layer = animatedLayer(property);
    2970 
    2971     String animationID = animationIdentifier(animationName, property, index, subIndex);
     2932bool GraphicsLayerCA::removeCAAnimationFromLayer(LayerPropertyAnimation& animation)
     2933{
     2934    PlatformCALayer* layer = animatedLayer(animation.m_property);
     2935
     2936    String animationID = animation.animationIdentifier();
    29722937
    29732938    if (!layer->animationForKey(animationID))
     
    29772942    bug7311367Workaround(m_structuralLayer.get(), transform());
    29782943
    2979     if (LayerMap* layerCloneMap = animatedLayerClones(property)) {
     2944    if (LayerMap* layerCloneMap = animatedLayerClones(animation.m_property)) {
    29802945        for (auto& clone : *layerCloneMap) {
    29812946            // Skip immediate replicas, since they move with the original.
     
    29892954}
    29902955
    2991 void GraphicsLayerCA::pauseCAAnimationOnLayer(AnimatedPropertyID property, const String& animationName, int index, int subIndex, Seconds timeOffset)
    2992 {
    2993     PlatformCALayer* layer = animatedLayer(property);
    2994 
    2995     String animationID = animationIdentifier(animationName, property, index, subIndex);
     2956void GraphicsLayerCA::pauseCAAnimationOnLayer(LayerPropertyAnimation& animation)
     2957{
     2958    PlatformCALayer* layer = animatedLayer(animation.m_property);
     2959
     2960    String animationID = animation.animationIdentifier();
    29962961
    29972962    RefPtr<PlatformCAAnimation> curAnim = layer->animationForKey(animationID);
     
    30032968
    30042969    newAnim->setSpeed(0);
    3005     newAnim->setTimeOffset(timeOffset.seconds());
     2970    newAnim->setTimeOffset(animation.m_timeOffset.seconds());
    30062971
    30072972    layer->addAnimationForKey(animationID, *newAnim); // This will replace the running animation.
    30082973
    30092974    // Pause the animations on the clones too.
    3010     if (LayerMap* layerCloneMap = animatedLayerClones(property)) {
     2975    if (LayerMap* layerCloneMap = animatedLayerClones(animation.m_property)) {
    30112976        for (auto& clone : *layerCloneMap) {
    30122977            // Skip immediate replicas, since they move with the original.
     
    30693034        return false;
    30703035
    3071     appendToUncommittedAnimations(LayerPropertyAnimation(caAnimation.releaseNonNull(), animationName, valueList.property(), animationIndex, 0, timeOffset));
     3036    m_animations.append(LayerPropertyAnimation(caAnimation.releaseNonNull(), animationName, valueList.property(), animationIndex, 0, timeOffset));
    30723037
    30733038    return true;
     
    31003065        return false;
    31013066
    3102     appendToUncommittedAnimations(LayerPropertyAnimation(caAnimation.releaseNonNull(), animationName, valueList.property(), animationIndex, 0, timeOffset));
     3067    m_animations.append(LayerPropertyAnimation(caAnimation.releaseNonNull(), animationName, valueList.property(), animationIndex, 0, timeOffset));
    31033068    return true;
    31043069}
     
    31603125        ASSERT(valuesOK);
    31613126
    3162         appendToUncommittedAnimations(LayerPropertyAnimation(caAnimation.releaseNonNull(), animationName, valueList.property(), animationIndex, internalFilterPropertyIndex, timeOffset));
     3127        m_animations.append(LayerPropertyAnimation(caAnimation.releaseNonNull(), animationName, valueList.property(), animationIndex, internalFilterPropertyIndex, timeOffset));
    31633128    }
    31643129
    31653130    return true;
    3166 }
    3167 
    3168 void GraphicsLayerCA::appendToUncommittedAnimations(LayerPropertyAnimation&& animation)
    3169 {
    3170     ensureLayerAnimations();
    3171 
    3172     // Since we're adding a new animation, make sure we clear any pending AnimationProcessingAction for this animation
    3173     // as these are applied after we've committed new animations. However, we want to check if we had a pending removal
    3174     // such that removing an animation prior to adding a new one for the same name works.
    3175     auto processingInfoIterator = m_animations->animationsToProcess.find(animation.m_name);
    3176     if (processingInfoIterator != m_animations->animationsToProcess.end()) {
    3177         auto animationIterator = m_animations->runningAnimations.find(animation.m_name);
    3178         if (animationIterator != m_animations->runningAnimations.end()) {
    3179             auto& animations = animationIterator->value;
    3180             for (const auto& processingInfo : processingInfoIterator->value) {
    3181                 if (processingInfo.action == Remove) {
    3182                     for (const auto& currentAnimation : animations)
    3183                         removeCAAnimationFromLayer(currentAnimation.m_property, animation.m_name, currentAnimation.m_index, currentAnimation.m_subIndex);
    3184                     m_animations->runningAnimations.remove(animationIterator);
    3185                     break;
    3186                 }
    3187             }
    3188         }
    3189         m_animations->animationsToProcess.remove(processingInfoIterator);
    3190     }
    3191 
    3192     m_animations->uncomittedAnimations.append(WTFMove(animation));
    3193 }
    3194 
    3195 void GraphicsLayerCA::removeFromUncommittedAnimations(const String& animationName)
    3196 {
    3197     if (!m_animations)
    3198         return;
    3199 
    3200     m_animations->uncomittedAnimations.removeFirstMatching([&animationName] (auto& current) {
    3201         return current.m_name == animationName;
    3202     });
    32033131}
    32043132
     
    43094237    Vector<std::pair<String, double>> animations;
    43104238
    4311     if (hasAnimations()) {
    4312         for (auto it : m_animations->runningAnimations) {
    4313             auto& propertyAnimations = it.value;
    4314             size_t numAnimations = propertyAnimations.size();
    4315             for (size_t i = 0; i < numAnimations; ++i) {
    4316                 const LayerPropertyAnimation& currAnimation = propertyAnimations[i];
    4317                 auto caAnimation = animatedLayer(currAnimation.m_property)->animationForKey(animationIdentifier(currAnimation.m_name, currAnimation.m_property, currAnimation.m_index, currAnimation.m_subIndex));
    4318                 animations.append({ animatedPropertyIDAsString(currAnimation.m_property), caAnimation->speed() });
    4319             }
    4320         }
     4239    for (auto& animation : m_animations) {
     4240        auto caAnimation = animatedLayer(animation.m_property)->animationForKey(animation.animationIdentifier());
     4241        animations.append({ animatedPropertyIDAsString(animation.m_property), caAnimation->speed() });
    43214242    }
    43224243
  • trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h

    r266342 r268483  
    184184    WEBCORE_EXPORT void setOpacityInternal(float) override;
    185185   
    186     WEBCORE_EXPORT bool animationCanBeAccelerated(const KeyframeValueList&, const Animation*) const;
    187 
    188186private:
    189187    bool isGraphicsLayerCA() const override { return true; }
     
    276274    WEBCORE_EXPORT bool backingStoreAttachedForTesting() const override;
    277275
    278     bool hasAnimations() const { return m_animations.get(); }
    279     bool animationIsRunning(const String& animationName) const
    280     {
    281         return m_animations && m_animations->runningAnimations.contains(animationName);
    282     }
     276    bool hasAnimations() const { return !m_animations.isEmpty(); }
     277    bool animationIsRunning(const String& animationName) const;
    283278
    284279    void commitLayerChangesBeforeSublayers(CommitState&, float pageScaleFactor, const FloatPoint& positionRelativeToBase, bool& layerTypeChanged);
     
    453448    bool ensureStructuralLayer(StructuralLayerPurpose);
    454449    StructuralLayerPurpose structuralLayerPurpose() const;
    455    
    456     void ensureLayerAnimations();
    457 
    458     void setAnimationOnLayer(PlatformCAAnimation&, AnimatedPropertyID, const String& animationName, int index, int subIndex, Seconds timeOffset);
    459     bool removeCAAnimationFromLayer(AnimatedPropertyID, const String& animationName, int index, int subINdex);
    460     void pauseCAAnimationOnLayer(AnimatedPropertyID, const String& animationName, int index, int subIndex, Seconds timeOffset);
    461 
    462     enum MoveOrCopy { Move, Copy };
    463     static void moveOrCopyLayerAnimation(MoveOrCopy, const String& animationIdentifier, PlatformCALayer *fromLayer, PlatformCALayer *toLayer);
    464     void moveOrCopyAnimations(MoveOrCopy, PlatformCALayer* fromLayer, PlatformCALayer* toLayer);
    465 
    466     void moveAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
    467     {
    468         moveOrCopyAnimations(Move, fromLayer, toLayer);
    469     }
    470     void copyAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
    471     {
    472         moveOrCopyAnimations(Copy, fromLayer, toLayer);
    473     }
    474450
    475451    // This represents the animation of a single property. There may be multiple transform animations for
    476452    // a single transition or keyframe animation, so index is used to distinguish these.
     453    enum class PlayState { Playing, PlayPending, Paused, PausePending };
    477454    struct LayerPropertyAnimation {
    478455        LayerPropertyAnimation(Ref<PlatformCAAnimation>&& caAnimation, const String& animationName, AnimatedPropertyID property, int index, int subIndex, Seconds timeOffset)
     
    485462        { }
    486463
     464        String animationIdentifier() const { return makeString(m_name, '_', static_cast<unsigned>(m_property), '_', m_index, '_', m_subIndex); }
     465
    487466        RefPtr<PlatformCAAnimation> m_animation;
    488467        String m_name;
     
    490469        int m_index;
    491470        int m_subIndex;
    492         Seconds m_timeOffset;
     471        Seconds m_timeOffset { 0_s };
     472        Seconds m_beginTime { 0_s };
     473        PlayState m_playState { PlayState::PlayPending };
     474        bool m_pendingRemoval { false };
    493475    };
     476
     477    void setAnimationOnLayer(LayerPropertyAnimation&);
     478    bool removeCAAnimationFromLayer(LayerPropertyAnimation&);
     479    void pauseCAAnimationOnLayer(LayerPropertyAnimation&);
     480
     481    enum MoveOrCopy { Move, Copy };
     482    static void moveOrCopyLayerAnimation(MoveOrCopy, const String& animationIdentifier, PlatformCALayer *fromLayer, PlatformCALayer *toLayer);
     483    void moveOrCopyAnimations(MoveOrCopy, PlatformCALayer* fromLayer, PlatformCALayer* toLayer);
     484
     485    void moveAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
     486    {
     487        moveOrCopyAnimations(Move, fromLayer, toLayer);
     488    }
     489    void copyAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
     490    {
     491        moveOrCopyAnimations(Copy, fromLayer, toLayer);
     492    }
    494493
    495494    bool appendToUncommittedAnimations(const KeyframeValueList&, const TransformOperations*, const Animation*, const String& animationName, const FloatSize& boxSize, int animationIndex, Seconds timeOffset, bool isMatrixAnimation);
    496495    bool appendToUncommittedAnimations(const KeyframeValueList&, const FilterOperation*, const Animation*, const String& animationName, int animationIndex, Seconds timeOffset);
    497     void appendToUncommittedAnimations(LayerPropertyAnimation&&);
    498     void removeFromUncommittedAnimations(const String&);
    499496
    500497    enum LayerChange : uint64_t {
     
    560557    void repaintLayerDirtyRects();
    561558
    562     enum Action { Remove, Pause };
    563     struct AnimationProcessingAction {
    564         AnimationProcessingAction(Action action = Remove, Seconds timeOffset = 0_s)
    565             : action(action)
    566             , timeOffset(timeOffset)
    567         {
    568         }
    569         Action action;
    570         Seconds timeOffset; // Only used for pause.
    571     };
    572     void addProcessingActionForAnimation(const String&, AnimationProcessingAction);
    573 
    574559    LayerChangeFlags m_uncommittedChanges { 0 };
    575560
     
    612597    RetainPtr<CGImageRef> m_pendingContentsImage;
    613598   
    614     typedef HashMap<String, Vector<AnimationProcessingAction>> AnimationsToProcessMap;
    615     typedef HashMap<String, Vector<LayerPropertyAnimation>> AnimationsMap;
    616     struct LayerAnimations {
    617         WTF_MAKE_STRUCT_FAST_ALLOCATED;
    618         Vector<LayerPropertyAnimation> uncomittedAnimations;
    619         AnimationsToProcessMap animationsToProcess;
    620         AnimationsMap runningAnimations;
    621     };
    622    
    623     std::unique_ptr<LayerAnimations> m_animations;
     599    Vector<LayerPropertyAnimation> m_animations;
    624600
    625601    Vector<FloatRect> m_dirtyRects;
Note: See TracChangeset for help on using the changeset viewer.