Changeset 221916 in webkit


Ignore:
Timestamp:
Sep 12, 2017 8:31:41 AM (7 years ago)
Author:
Antti Koivisto
Message:

Remove RenderElement::isCSSAnimating boolean
https://bugs.webkit.org/show_bug.cgi?id=176779

Reviewed by Andreas Kling.

This optimization can be replaced with a simple style test that doesn't require keeping
two sources of truth in sync.

  • page/animation/CSSAnimationController.cpp:

(WebCore::CSSAnimationControllerPrivate::ensureCompositeAnimation):
(WebCore::CSSAnimationControllerPrivate::clear):

Can't test here as style might have become non-animating and we don't clear animation when that happens.
This is only called on renderer destruction so it is not an important optimization.

(WebCore::CSSAnimationControllerPrivate::isRunningAnimationOnRenderer const):
(WebCore::CSSAnimationControllerPrivate::isRunningAcceleratedAnimationOnRenderer const):
(WebCore::CSSAnimationControllerPrivate::getAnimatedStyleForRenderer):
(WebCore::CSSAnimationControllerPrivate::computeExtentOfAnimation const):
(WebCore::CSSAnimationController::cancelAnimations):
(WebCore::CSSAnimationController::getAnimatedStyleForRenderer):
(WebCore::CSSAnimationController::computeExtentOfAnimation const):
(WebCore::CSSAnimationController::isRunningAnimationOnRenderer const):
(WebCore::CSSAnimationController::isRunningAcceleratedAnimationOnRenderer const):

Test if the style has any animations. This is roughly equivalent of the old test.
(it is actually somewhat better as the boolean was never cleared on style changes)

  • rendering/RenderElement.cpp:

(WebCore::RenderElement::RenderElement):

  • rendering/RenderElement.h:

(WebCore::RenderElement::isCSSAnimating const): Deleted.
(WebCore::RenderElement::setIsCSSAnimating): Deleted.

  • rendering/style/RenderStyle.h:

(WebCore::RenderStyle::hasAnimationsOrTransitions const):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r221915 r221916  
     12017-09-12  Antti Koivisto  <antti@apple.com>
     2
     3        Remove RenderElement::isCSSAnimating boolean
     4        https://bugs.webkit.org/show_bug.cgi?id=176779
     5
     6        Reviewed by Andreas Kling.
     7
     8        This optimization can be replaced with a simple style test that doesn't require keeping
     9        two sources of truth in sync.
     10
     11        * page/animation/CSSAnimationController.cpp:
     12        (WebCore::CSSAnimationControllerPrivate::ensureCompositeAnimation):
     13        (WebCore::CSSAnimationControllerPrivate::clear):
     14
     15            Can't test here as style might have become non-animating and we don't clear animation when that happens.
     16            This is only called on renderer destruction so it is not an important optimization.
     17
     18        (WebCore::CSSAnimationControllerPrivate::isRunningAnimationOnRenderer const):
     19        (WebCore::CSSAnimationControllerPrivate::isRunningAcceleratedAnimationOnRenderer const):
     20        (WebCore::CSSAnimationControllerPrivate::getAnimatedStyleForRenderer):
     21        (WebCore::CSSAnimationControllerPrivate::computeExtentOfAnimation const):
     22        (WebCore::CSSAnimationController::cancelAnimations):
     23        (WebCore::CSSAnimationController::getAnimatedStyleForRenderer):
     24        (WebCore::CSSAnimationController::computeExtentOfAnimation const):
     25        (WebCore::CSSAnimationController::isRunningAnimationOnRenderer const):
     26        (WebCore::CSSAnimationController::isRunningAcceleratedAnimationOnRenderer const):
     27
     28            Test if the style has any animations. This is roughly equivalent of the old test.
     29            (it is actually somewhat better as the boolean was never cleared on style changes)
     30
     31        * rendering/RenderElement.cpp:
     32        (WebCore::RenderElement::RenderElement):
     33        * rendering/RenderElement.h:
     34        (WebCore::RenderElement::isCSSAnimating const): Deleted.
     35        (WebCore::RenderElement::setIsCSSAnimating): Deleted.
     36        * rendering/style/RenderStyle.h:
     37        (WebCore::RenderStyle::hasAnimationsOrTransitions const):
     38
    1392017-09-12  Ms2ger  <Ms2ger@igalia.com>
    240
  • trunk/Source/WebCore/page/animation/CSSAnimationController.cpp

    r217075 r221916  
    8686CompositeAnimation& CSSAnimationControllerPrivate::ensureCompositeAnimation(RenderElement& renderer)
    8787{
    88     auto result = m_compositeAnimations.add(&renderer, nullptr);
    89     if (result.isNewEntry) {
    90         result.iterator->value = CompositeAnimation::create(*this);
    91         renderer.setIsCSSAnimating(true);
    92     }
     88    auto result = m_compositeAnimations.ensure(&renderer, [&] {
     89        return CompositeAnimation::create(*this);
     90    });
    9391
    9492    if (animationsAreSuspendedForDocument(&renderer.document()))
     
    10098bool CSSAnimationControllerPrivate::clear(RenderElement& renderer)
    10199{
     100    auto it = m_compositeAnimations.find(&renderer);
     101    if (it == m_compositeAnimations.end())
     102        return false;
     103
    102104    LOG(Animations, "CSSAnimationControllerPrivate %p clear: %p", this, &renderer);
    103 
    104     ASSERT(renderer.isCSSAnimating());
    105     ASSERT(m_compositeAnimations.contains(&renderer));
    106105
    107106    Element* element = renderer.element();
     
    117116    // Return false if we didn't do anything OR we are suspended (so we don't try to
    118117    // do a invalidateStyleForSubtree() when suspended).
    119     RefPtr<CompositeAnimation> animation = m_compositeAnimations.take(&renderer);
    120     ASSERT(animation);
    121     renderer.setIsCSSAnimating(false);
    122     animation->clearRenderer();
    123     return animation->isSuspended();
     118    // FIXME: The code below does the opposite of what the comment above says regarding suspended state.
     119    auto& animation = *it->value;
     120    bool result = animation.isSuspended();
     121    animation.clearRenderer();
     122
     123    m_compositeAnimations.remove(it);
     124
     125    return result;
    124126}
    125127
     
    288290bool CSSAnimationControllerPrivate::isRunningAnimationOnRenderer(RenderElement& renderer, CSSPropertyID property, AnimationBase::RunningState runningState) const
    289291{
    290     ASSERT(renderer.isCSSAnimating());
    291     ASSERT(m_compositeAnimations.contains(&renderer));
    292     const CompositeAnimation& animation = *m_compositeAnimations.get(&renderer);
    293     return animation.isAnimatingProperty(property, false, runningState);
     292    auto* animation = m_compositeAnimations.get(&renderer);
     293    if (!animation)
     294        return false;
     295    return animation->isAnimatingProperty(property, false, runningState);
    294296}
    295297
    296298bool CSSAnimationControllerPrivate::isRunningAcceleratedAnimationOnRenderer(RenderElement& renderer, CSSPropertyID property, AnimationBase::RunningState runningState) const
    297299{
    298     ASSERT(renderer.isCSSAnimating());
    299     ASSERT(m_compositeAnimations.contains(&renderer));
    300     const CompositeAnimation& animation = *m_compositeAnimations.get(&renderer);
    301     return animation.isAnimatingProperty(property, true, runningState);
     300    auto* animation = m_compositeAnimations.get(&renderer);
     301    if (!animation)
     302        return false;
     303    return animation->isAnimatingProperty(property, true, runningState);
    302304}
    303305
     
    468470std::unique_ptr<RenderStyle> CSSAnimationControllerPrivate::getAnimatedStyleForRenderer(RenderElement& renderer)
    469471{
     472    auto* animation = m_compositeAnimations.get(&renderer);
     473    if (!animation)
     474        return RenderStyle::clonePtr(renderer.style());
     475
    470476    AnimationPrivateUpdateBlock animationUpdateBlock(*this);
    471477
    472     ASSERT(renderer.isCSSAnimating());
    473     ASSERT(m_compositeAnimations.contains(&renderer));
    474     const CompositeAnimation& rendererAnimations = *m_compositeAnimations.get(&renderer);
    475     std::unique_ptr<RenderStyle> animatingStyle = rendererAnimations.getAnimatedStyle();
     478    std::unique_ptr<RenderStyle> animatingStyle = animation->getAnimatedStyle();
    476479    if (!animatingStyle)
    477480        animatingStyle = RenderStyle::clonePtr(renderer.style());
     
    482485bool CSSAnimationControllerPrivate::computeExtentOfAnimation(RenderElement& renderer, LayoutRect& bounds) const
    483486{
    484     ASSERT(renderer.isCSSAnimating());
    485     ASSERT(m_compositeAnimations.contains(&renderer));
    486 
    487     const CompositeAnimation& rendererAnimations = *m_compositeAnimations.get(&renderer);
    488     if (!rendererAnimations.isAnimatingProperty(CSSPropertyTransform, false, AnimationBase::Running | AnimationBase::Paused))
     487    auto* animation = m_compositeAnimations.get(&renderer);
     488    if (!animation)
    489489        return true;
    490490
    491     return rendererAnimations.computeExtentOfTransformAnimation(bounds);
     491    if (!animation->isAnimatingProperty(CSSPropertyTransform, false, AnimationBase::Running | AnimationBase::Paused))
     492        return true;
     493
     494    return animation->computeExtentOfTransformAnimation(bounds);
    492495}
    493496
     
    631634void CSSAnimationController::cancelAnimations(RenderElement& renderer)
    632635{
    633     if (!renderer.isCSSAnimating())
    634         return;
    635 
    636636    if (!m_data->clear(renderer))
    637637        return;
     
    681681std::unique_ptr<RenderStyle> CSSAnimationController::getAnimatedStyleForRenderer(RenderElement& renderer)
    682682{
    683     if (!renderer.isCSSAnimating())
     683    if (!renderer.style().hasAnimationsOrTransitions())
    684684        return RenderStyle::clonePtr(renderer.style());
     685
    685686    return m_data->getAnimatedStyleForRenderer(renderer);
    686687}
     
    688689bool CSSAnimationController::computeExtentOfAnimation(RenderElement& renderer, LayoutRect& bounds) const
    689690{
    690     if (!renderer.isCSSAnimating())
     691    if (!renderer.style().hasAnimationsOrTransitions())
    691692        return true;
    692693
     
    722723bool CSSAnimationController::isRunningAnimationOnRenderer(RenderElement& renderer, CSSPropertyID property, AnimationBase::RunningState runningState) const
    723724{
    724     return renderer.isCSSAnimating() && m_data->isRunningAnimationOnRenderer(renderer, property, runningState);
     725    if (!renderer.style().hasAnimationsOrTransitions())
     726        return false;
     727    return m_data->isRunningAnimationOnRenderer(renderer, property, runningState);
    725728}
    726729
    727730bool CSSAnimationController::isRunningAcceleratedAnimationOnRenderer(RenderElement& renderer, CSSPropertyID property, AnimationBase::RunningState runningState) const
    728731{
    729     return renderer.isCSSAnimating() && m_data->isRunningAcceleratedAnimationOnRenderer(renderer, property, runningState);
     732    if (!renderer.style().hasAnimationsOrTransitions())
     733        return false;
     734    return m_data->isRunningAcceleratedAnimationOnRenderer(renderer, property, runningState);
    730735}
    731736
  • trunk/Source/WebCore/rendering/RenderElement.cpp

    r221147 r221916  
    108108    , m_hasPausedImageAnimations(false)
    109109    , m_hasCounterNodeMap(false)
    110     , m_isCSSAnimating(false)
    111110    , m_hasContinuation(false)
    112111    , m_hasValidCachedFirstLineStyle(false)
  • trunk/Source/WebCore/rendering/RenderElement.h

    r219876 r221916  
    204204    void setHasCounterNodeMap(bool f) { m_hasCounterNodeMap = f; }
    205205
    206     bool isCSSAnimating() const { return m_isCSSAnimating; }
    207     void setIsCSSAnimating(bool b) { m_isCSSAnimating = b; }
    208    
    209206    const RenderElement* enclosingRendererWithTextDecoration(TextDecoration, bool firstLine) const;
    210207    void drawLineForBoxSide(GraphicsContext&, const FloatRect&, BoxSide, Color, EBorderStyle, float adjacentWidth1, float adjacentWidth2, bool antialias = false) const;
     
    339336    unsigned m_hasPausedImageAnimations : 1;
    340337    unsigned m_hasCounterNodeMap : 1;
    341     unsigned m_isCSSAnimating : 1;
    342338    unsigned m_hasContinuation : 1;
    343339    mutable unsigned m_hasValidCachedFirstLineStyle : 1;
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r221467 r221916  
    663663    AnimationList* transitions() { return m_rareNonInheritedData->transitions.get(); }
    664664   
    665     bool hasAnimationsOrTransitions() const { return m_rareNonInheritedData->hasAnimationsOrTransitions(); }
     665    bool hasAnimationsOrTransitions() const { return hasAnimations() || hasTransitions(); }
    666666
    667667    AnimationList& ensureAnimations();
  • trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h

    r218793 r221916  
    9393    bool hasOpacity() const { return opacity < 1; }
    9494
    95     bool hasAnimationsOrTransitions() const { return animations || transitions; }
    96 
    9795    float opacity;
    9896
Note: See TracChangeset for help on using the changeset viewer.