Changeset 239965 in webkit


Ignore:
Timestamp:
Jan 14, 2019 5:31:48 PM (5 years ago)
Author:
Simon Fraser
Message:

Animation and other code is too aggressive about invalidating layer composition
https://bugs.webkit.org/show_bug.cgi?id=193343

Reviewed by Antoine Quint.

Source/WebCore:

We used to have the concept of a "SyntheticStyleChange", which was used to trigger
style updates for animation, and also to get compositing updated.

That morphed into a call to Element::invalidateStyleAndLayerComposition(), which causes
a style update to result in a "RecompositeLayer" diff, which in turn triggers compositing work,
and dirties DOM touch event regions (which can be expensive to update).

However, not all the callers of Element::invalidateStyleAndLayerComposition() need to trigger
compositing, and doing so from animations caused excessive touch event regions on yahoo.com,
which has several visibility:hidden elements with background-position animation.

So fix callers of invalidateStyleAndLayerComposition() which don't care about compositing to instead
call just invalidateStyle().

Also fix KeyframeAnimation::animate to correctly return true when animation state changes—it failed to
do so, because fireAnimationEventsIfNeeded() can run the state machine and change state.

  • animation/KeyframeEffect.cpp:

(WebCore::invalidateElement):

  • page/animation/AnimationBase.cpp:

(WebCore::AnimationBase::setNeedsStyleRecalc):

  • page/animation/CSSAnimationController.cpp:

(WebCore::CSSAnimationControllerPrivate::updateAnimations):
(WebCore::CSSAnimationControllerPrivate::fireEventsAndUpdateStyle):
(WebCore::CSSAnimationControllerPrivate::pauseAnimationAtTime):
(WebCore::CSSAnimationControllerPrivate::pauseTransitionAtTime):
(WebCore::CSSAnimationController::cancelAnimations):

  • page/animation/KeyframeAnimation.cpp:

(WebCore::KeyframeAnimation::animate):

  • rendering/RenderImage.cpp:

(WebCore::RenderImage::imageChanged):

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::calculateClipRects const):

  • rendering/svg/SVGResourcesCache.cpp:

(WebCore::SVGResourcesCache::clientStyleChanged):

  • style/StyleTreeResolver.cpp:

(WebCore::Style::TreeResolver::createAnimatedElementUpdate):

  • svg/SVGAnimateElementBase.cpp:

(WebCore::applyCSSPropertyToTarget):
(WebCore::removeCSSPropertyFromTarget):

LayoutTests:

This test was clobbering the 'box' class on the animating element and therefore making it disappear.

  • legacy-animation-engine/compositing/animation/animation-compositing.html:
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r239959 r239965  
     12019-01-14  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Animation and other code is too aggressive about invalidating layer composition
     4        https://bugs.webkit.org/show_bug.cgi?id=193343
     5
     6        Reviewed by Antoine Quint.
     7       
     8        This test was clobbering the 'box' class on the animating element and therefore making it disappear.
     9
     10        * legacy-animation-engine/compositing/animation/animation-compositing.html:
     11
    1122019-01-14  Charles Vazac  <cvazac@akamai.com>
    213
  • trunk/LayoutTests/legacy-animation-engine/compositing/animation/animation-compositing.html

    r235960 r239965  
    4040        }
    4141      }, false);
    42       document.getElementById('box').className = 'spinning';
     42      document.getElementById('box').classList.add('spinning');
    4343    }
    4444
  • trunk/Source/WebCore/ChangeLog

    r239960 r239965  
     12019-01-14  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Animation and other code is too aggressive about invalidating layer composition
     4        https://bugs.webkit.org/show_bug.cgi?id=193343
     5
     6        Reviewed by Antoine Quint.
     7       
     8        We used to have the concept of a "SyntheticStyleChange", which was used to trigger
     9        style updates for animation, and also to get compositing updated.
     10       
     11        That morphed into a call to Element::invalidateStyleAndLayerComposition(), which causes
     12        a style update to result in a "RecompositeLayer" diff, which in turn triggers compositing work,
     13        and dirties DOM touch event regions (which can be expensive to update).
     14       
     15        However, not all the callers of Element::invalidateStyleAndLayerComposition() need to trigger
     16        compositing, and doing so from animations caused excessive touch event regions on yahoo.com,
     17        which has several visibility:hidden elements with background-position animation.
     18       
     19        So fix callers of invalidateStyleAndLayerComposition() which don't care about compositing to instead
     20        call just invalidateStyle().
     21       
     22        Also fix KeyframeAnimation::animate to correctly return true when animation state changes—it failed to
     23        do so, because fireAnimationEventsIfNeeded() can run the state machine and change state.
     24
     25        * animation/KeyframeEffect.cpp:
     26        (WebCore::invalidateElement):
     27        * page/animation/AnimationBase.cpp:
     28        (WebCore::AnimationBase::setNeedsStyleRecalc):
     29        * page/animation/CSSAnimationController.cpp:
     30        (WebCore::CSSAnimationControllerPrivate::updateAnimations):
     31        (WebCore::CSSAnimationControllerPrivate::fireEventsAndUpdateStyle):
     32        (WebCore::CSSAnimationControllerPrivate::pauseAnimationAtTime):
     33        (WebCore::CSSAnimationControllerPrivate::pauseTransitionAtTime):
     34        (WebCore::CSSAnimationController::cancelAnimations):
     35        * page/animation/KeyframeAnimation.cpp:
     36        (WebCore::KeyframeAnimation::animate):
     37        * rendering/RenderImage.cpp:
     38        (WebCore::RenderImage::imageChanged):
     39        * rendering/RenderLayer.cpp:
     40        (WebCore::RenderLayer::calculateClipRects const):
     41        * rendering/svg/SVGResourcesCache.cpp:
     42        (WebCore::SVGResourcesCache::clientStyleChanged):
     43        * style/StyleTreeResolver.cpp:
     44        (WebCore::Style::TreeResolver::createAnimatedElementUpdate):
     45        * svg/SVGAnimateElementBase.cpp:
     46        (WebCore::applyCSSPropertyToTarget):
     47        (WebCore::removeCSSPropertyFromTarget):
     48
    1492019-01-14  Sihui Liu  <sihui_liu@apple.com>
    250
  • trunk/Source/WebCore/animation/KeyframeEffect.cpp

    r239820 r239965  
    6161{
    6262    if (element)
    63         element->invalidateStyleAndLayerComposition();
     63        element->invalidateStyle();
    6464}
    6565
  • trunk/Source/WebCore/page/animation/AnimationBase.cpp

    r239461 r239965  
    9191
    9292    ASSERT(element->document().pageCacheState() == Document::NotInPageCache);
    93     element->invalidateStyleAndLayerComposition();
     93    element->invalidateStyle();
    9494}
    9595
  • trunk/Source/WebCore/page/animation/CSSAnimationController.cpp

    r239461 r239965  
    144144                if (callSetChanged != CallSetChanged)
    145145                    break;
     146               
    146147                Element& element = *compositeAnimation.key;
    147148                ASSERT(element.document().pageCacheState() == Document::NotInPageCache);
    148                 element.invalidateStyleAndLayerComposition();
     149                element.invalidateStyle();
    149150                calledSetChanged = true;
    150151            }
     
    226227
    227228    for (auto& change : m_elementChangesToDispatch)
    228         change->invalidateStyleAndLayerComposition();
     229        change->invalidateStyle();
    229230
    230231    m_elementChangesToDispatch.clear();
     
    413414    CompositeAnimation& compositeAnimation = ensureCompositeAnimation(element);
    414415    if (compositeAnimation.pauseAnimationAtTime(name, t)) {
    415         element.invalidateStyleAndLayerComposition();
     416        element.invalidateStyle();
    416417        startUpdateStyleIfNeededDispatcher();
    417418        return true;
     
    425426    CompositeAnimation& compositeAnimation = ensureCompositeAnimation(element);
    426427    if (compositeAnimation.pauseTransitionAtTime(cssPropertyID(property), t)) {
    427         element.invalidateStyleAndLayerComposition();
     428        element.invalidateStyle();
    428429        startUpdateStyleIfNeededDispatcher();
    429430        return true;
     
    608609        return;
    609610    ASSERT(element.document().pageCacheState() == Document::NotInPageCache);
    610     element.invalidateStyleAndLayerComposition();
     611    element.invalidateStyle();
    611612}
    612613
  • trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp

    r239427 r239965  
    159159bool KeyframeAnimation::animate(CompositeAnimation& compositeAnimation, const RenderStyle& targetStyle, std::unique_ptr<RenderStyle>& animatedStyle, bool& didBlendStyle)
    160160{
    161     // Fire the start timeout if needed
     161    AnimationState oldState = state();
     162
     163    // Update state and fire the start timeout if needed (FIXME: this function needs a better name).
    162164    fireAnimationEventsIfNeeded();
    163    
     165
    164166    // If we have not yet started, we will not have a valid start time, so just start the animation if needed.
    165167    if (isNew()) {
     
    191193        return false;
    192194    }
    193 
    194     // FIXME: the code below never changes the state, so this function always returns false.
    195     AnimationState oldState = state();
    196195
    197196    // Run a cycle of animation.
  • trunk/Source/WebCore/rendering/RenderImage.cpp

    r239173 r239965  
    285285            if (element()) {
    286286                m_needsToSetSizeForAltText = true;
    287                 element()->invalidateStyleAndLayerComposition();
     287                element()->invalidateStyle();
    288288            }
    289289            return;
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r239661 r239965  
    66006600{
    66016601    // We use the enclosing element so that we recalculate style for the ancestor of an anonymous object.
    6602     if (Element* element = enclosingElement())
     6602    if (Element* element = enclosingElement()) {
     6603        // FIXME: This really shouldn't have to invalidate layer composition, but tests like css3/filters/effect-reference-delete.html fail if that doesn't happen.
    66036604        element->invalidateStyleAndLayerComposition();
     6605    }
    66046606    renderer().repaint();
    66056607}
  • trunk/Source/WebCore/rendering/svg/SVGResourcesCache.cpp

    r232018 r239965  
    117117
    118118    if (renderer.element() && !renderer.element()->isSVGElement())
    119         renderer.element()->invalidateStyleAndLayerComposition();
     119        renderer.element()->invalidateStyle();
    120120}
    121121
  • trunk/Source/WebCore/style/StyleTreeResolver.cpp

    r238097 r239965  
    307307
    308308        auto animationUpdate = animationController.updateAnimations(element, *newStyle, oldStyle);
    309         shouldRecompositeLayer = animationUpdate.stateChanged;
     309        shouldRecompositeLayer = animationUpdate.stateChanged; // FIXME: constrain this to just property animations triggering acceleration.
    310310
    311311        if (animationUpdate.style)
  • trunk/Source/WebCore/svg/SVGAnimateElementBase.cpp

    r239090 r239965  
    250250        return;
    251251
    252     targetElement.invalidateStyleAndLayerComposition();
     252    targetElement.invalidateStyle();
    253253}
    254254
     
    257257    ASSERT(!targetElement.m_deletionHasBegun);
    258258    targetElement.ensureAnimatedSMILStyleProperties().removeProperty(id);
    259     targetElement.invalidateStyleAndLayerComposition();
     259    targetElement.invalidateStyle();
    260260}
    261261
Note: See TracChangeset for help on using the changeset viewer.