Skip to content

Commit

Permalink
Replace LayoutObject::skipInvalidationWhenLaidOutChildren() with pain…
Browse files Browse the repository at this point in the history
…tedOutputOfObjectHasNoEffect

We don't need to check if the layout is laid out because of children,
but just check if it will paint anything and if its painting is
affected by geometry change.

Removed neededLayoutBecauseOfChildren logic and replaced
skipInvalidationWhenLaiedOutChildren() with
paintedOutputOfObjectHasNoEffect().

Also cleaned up selection paint invalidation.

BUG=451090

Review-Url: https://codereview.chromium.org/2203933002
Cr-Commit-Position: refs/heads/master@{#409965}
  • Loading branch information
wangxianzhu authored and Commit bot committed Aug 5, 2016
1 parent 3a6cbe4 commit bdd41f4
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 73 deletions.
94 changes: 93 additions & 1 deletion third_party/WebKit/LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,97 @@ crbug.com/619060 imported/wpt/pointerevents/pointerevent_pointerleave_after_poin
crbug.com/619060 imported/wpt/pointerevents/pointerevent_pointerleave_after_pointerup_nohover-manual.html [ Skip ]
crbug.com/619060 imported/wpt/pointerevents/pointerevent_pointerleave_touch-manual.html [ Skip ]

crbug.com/451090 compositing/squashing/remove-squashed-layer-plus-move.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/abspos-shift-image-incorrect-repaint.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/align-content-change.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/align-content-distribution-change-grid.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/align-content-position-change-grid.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/align-self-change-grid.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/align-self-overflow-change.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/background-generated.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/background-resize-height.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/background-shorthand-with-gradient-and-height-changes.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/background-size-auto-with-gradient-and-height-changes.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/block-shift-repaint.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/border-radius-repaint-2.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/box-inline-resize.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/box-shadow-dynamic.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/clipped-overflow-visible-subtree.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/clipped-relative.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/content-into-overflow.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/crbug-371640-2.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/crbug-371640-3.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/crbug-371640-4.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/crbug-371640.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/dynamic-table-vertical-alignment-change.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/erase-overflow.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/fixed-and-absolute-position-scrolled.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/float-move-during-layout.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/float-overflow-right.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/float-overflow.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/intermediate-layout-position.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/justify-content-change.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/justify-content-distribution-change-grid.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/justify-content-position-change-grid.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/justify-content-position-change.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/justify-self-change.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/justify-self-overflow-change.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/layout-state-only-positioned.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/offset-change-wrong-invalidation-with-float.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/outline-child-repaint.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/overflow-into-content.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/paint-invalidation-with-reparent-across-frame-boundaries.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/percent-size-image-resize-container.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/positioned-document-element.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/positioned-great-grandparent-change-location.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/positioned-list-offset-change-repaint.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/reflection-repaint-test.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/relative-margin-change-repaint.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/repaint-descandant-on-ancestor-layer-move.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/repaint-resized-overflow.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/repaint-table-row-in-composited-document.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/replaced-clipped-positioned-not-wrong-incremental-repainting.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/resize-child-within-overflow.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/scrollbar-damage-and-full-viewport-repaint.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/selection-after-remove.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/selection-change-in-iframe-with-relative-parent.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/selection-clear.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/shift-relative-positioned-container-with-image-addition.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/shift-relative-positioned-container-with-image-removal.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/table-cell-move.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/table-section-overflow.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/table-section-repaint.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/table-shrink-row-repaint.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/text-selection-rect-in-overflow.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/text-selection-rect-in-overflow-2.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/transform-disable-layoutstate.html [ NeedsRebaseline ]
crbug.com/451090 fast/repaint/window-resize-vertical-writing-mode.html [ NeedsRebaseline ]
crbug.com/451090 fast/table/border-collapsing/cached-change-cell-border-width.html [ NeedsRebaseline ]
crbug.com/451090 fast/table/border-collapsing/cached-change-col-border-width.html [ NeedsRebaseline ]
crbug.com/451090 fast/table/border-collapsing/cached-change-row-border-width.html [ NeedsRebaseline ]
crbug.com/451090 fast/table/border-collapsing/cached-change-tbody-border-width.html [ NeedsRebaseline ]
crbug.com/451090 fast/table/resize-table-repaint-percent-size-cell.html [ NeedsRebaseline ]
crbug.com/451090 fast/table/resize-table-repaint-vertical-align-cell.html [ NeedsRebaseline ]
crbug.com/451090 fast/table/resize-table-row-repaint.html [ NeedsRebaseline ]
crbug.com/451090 paint/selection/invalidation-rect-includes-newline-for-rtl.html [ NeedsRebaseline ]
crbug.com/451090 paint/selection/invalidation-rect-with-br-includes-newline.html [ NeedsRebaseline ]
crbug.com/451090 svg/as-object/deep-nested-embedded-svg-size-changes-no-layout-triggers-1.html [ NeedsRebaseline ]
crbug.com/451090 svg/as-object/deep-nested-embedded-svg-size-changes-no-layout-triggers-2.html [ NeedsRebaseline ]
crbug.com/451090 svg/as-object/nested-embedded-svg-size-changes-no-layout-triggers-1.html [ NeedsRebaseline ]
crbug.com/451090 svg/as-object/nested-embedded-svg-size-changes-no-layout-triggers-2.html [ NeedsRebaseline ]
crbug.com/451090 svg/custom/object-sizing-no-width-height-change-content-box-size.xhtml [ NeedsRebaseline ]
crbug.com/451090 svg/custom/resource-client-removal.svg [ NeedsRebaseline ]
crbug.com/451090 svg/filters/filter-refresh.svg [ NeedsRebaseline ]
crbug.com/451090 svg/repaint/filter-child-repaint.svg [ NeedsRebaseline ]
crbug.com/451090 svg/repaint/image-with-clip-path.svg [ NeedsRebaseline ]
crbug.com/451090 svg/repaint/inner-svg-change-viewPort-relative.svg [ NeedsRebaseline ]
crbug.com/451090 svg/repaint/paintorder-filtered.svg [ NeedsRebaseline ]
crbug.com/451090 svg/repaint/text-pattern-update-2.html [ NeedsRebaseline ]
crbug.com/451090 svg/repaint/text-pattern-update.html [ NeedsRebaseline ]
crbug.com/451090 svg/repaint/tspan-pattern-update.html [ NeedsRebaseline ]
crbug.com/451090 svg/text/text-rescale.html [ NeedsRebaseline ]
crbug.com/451090 svg/text/text-viewbox-rescale.html [ NeedsManualRebaseline ]

crbug.com/627341 imported/wpt/pointerevents/pointerevent_suppress_compat_events_on_click.html [ Skip ]
crbug.com/627341 imported/wpt/pointerevents/pointerevent_suppress_compat_events_on_drag_mouse.html [ Skip ]
crbug.com/627341 imported/wpt/pointerevents/pointerevent_touch-action-inherit_child-auto-child-none_touch-manual.html [ Skip ]
Expand Down Expand Up @@ -1111,7 +1202,8 @@ crbug.com/619103 paint/invalidation/invalidate-after-composited-scroll-of-window
crbug.com/619103 paint/invalidation/animated-gif.html [ Pass Failure ]
crbug.com/619103 paint/invalidation/animated-gif-background.html [ Pass Failure ]
crbug.com/619103 paint/invalidation/animated-gif-background-offscreen.html [ Pass Failure ]
crbug.com/619103 [ Win ] svg/text/text-viewbox-rescale.html [ Pass Failure ]
# TODO(wangxianzhu): Restore the following line after manual rebaseline.
# crbug.com/619103 [ Win ] svg/text/text-viewbox-rescale.html [ Pass Failure ]
crbug.com/619103 paint/overflow/interest-rect-change-scroll-down.html [ Failure ]
crbug.com/619103 paint/selection/text-selection-newline-mixed-ltr-rtl.html [ Failure ]
crbug.com/619103 paint/selection/text-selection-newline-rtl-double-linebreak.html [ Failure ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
.child {
height: 20px;
width: 20px;
background-color: green;
}
</style>
</head>
<body>
<div style="display: flex; flex-direction: column; height: 100%">
<div style="display: flex; flex-direction: column; height: 100%; background-color: blue">
<div style="flex: 1"></div>
<div class='nested-row-flexbox'>
<div class="child"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
.child {
height: 20px;
width: 20px;
background-color: green;
}
</style>
</head>
<body onload="runRepaintAndPixelTest()">
<div style="display: flex; flex-direction: column; height: 100%">
<div style="display: flex; flex-direction: column; height: 100%; background-color: blue">
<div style="flex: 1"></div>
<div class='nested-row-flexbox'>
<div class="child"></div>
Expand Down
1 change: 1 addition & 0 deletions third_party/WebKit/Source/core/layout/LayoutBlockFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class CORE_EXPORT LayoutBlockFlow : public LayoutBlock {

void addOutlineRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, IncludeBlockVisualOverflowOrNot) const override;

bool paintedOutputOfObjectHasNoEffect() const override;
PaintInvalidationReason invalidatePaintIfNeeded(const PaintInvalidationState&) override;

Node* nodeForHitTest() const final;
Expand Down
9 changes: 9 additions & 0 deletions third_party/WebKit/Source/core/layout/LayoutBlockFlowLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,15 @@ void LayoutBlockFlow::setShouldDoFullPaintInvalidationForFirstLine()
firstRootBox->setShouldDoFullPaintInvalidationRecursively();
}

bool LayoutBlockFlow::paintedOutputOfObjectHasNoEffect() const
{
// LayoutBlockFlow is in charge of paint invalidation of the first line.
if (firstLineBox())
return false;

return LayoutBlock::paintedOutputOfObjectHasNoEffect();
}

PaintInvalidationReason LayoutBlockFlow::invalidatePaintIfNeeded(const PaintInvalidationState& paintInvalidationState)
{
if (containsFloats())
Expand Down
22 changes: 22 additions & 0 deletions third_party/WebKit/Source/core/layout/LayoutBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,28 @@ bool LayoutBox::needsForcedBreakBefore(EBreak previousBreakAfterValue) const
return isForcedFragmentainerBreakValue(classABreakPointValue(previousBreakAfterValue));
}

bool LayoutBox::paintedOutputOfObjectHasNoEffect() const
{
// In case scrollbars got repositioned (which will typically happen if the box got
// resized), we cannot skip invalidation.
if (hasNonCompositedScrollbars())
return false;

// Cannot skip paint invalidation if the box has real things to paint.
if (getSelectionState() != SelectionNone || hasBoxDecorationBackground() || styleRef().hasVisualOverflowingEffect())
return false;

// If the box has clip, we need issue a paint invalidation to cover the changed part of
// children because of change of clip when the box got resized. In theory the children
// should invalidate themselves when ancestor clip changes, but for now this is missing
// and ensuring it may hurt performance.
// TODO(wangxianzhu): Paint invalidation for clip change will be different in spv2.
if (hasClipRelatedProperty() || hasControlClip())
return false;

return true;
}

LayoutRect LayoutBox::localOverflowRectForPaintInvalidation() const
{
if (style()->visibility() != VISIBLE)
Expand Down
1 change: 1 addition & 0 deletions third_party/WebKit/Source/core/layout/LayoutBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject {
// break, we also need to know the break-after value of the previous in-flow sibling.
bool needsForcedBreakBefore(EBreak previousBreakAfterValue) const;

bool paintedOutputOfObjectHasNoEffect() const override;
LayoutRect localOverflowRectForPaintInvalidation() const override;
bool mapToVisualRectInAncestorSpace(const LayoutBoxModelObject* ancestor, LayoutRect&, VisualRectFlags = DefaultVisualRectFlags) const override;
virtual void invalidatePaintForOverhangingFloats(bool paintAllDescendants);
Expand Down
41 changes: 6 additions & 35 deletions third_party/WebKit/Source/core/layout/LayoutObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,28 +684,6 @@ LayoutFlowThread* LayoutObject::locateFlowThreadContainingBlock() const
return LayoutFlowThread::locateFlowThreadContainingBlockOf(*this);
}

bool LayoutObject::skipInvalidationWhenLaidOutChildren() const
{
if (!m_bitfields.neededLayoutBecauseOfChildren())
return false;

// SVG layoutObjects need to be invalidated when their children are laid out.
// LayoutBlocks with line boxes are responsible to invalidate them so we can't ignore them.
if (isSVG() || (isLayoutBlockFlow() && toLayoutBlockFlow(this)->firstLineBox()))
return false;

// In case scrollbars got repositioned (which will typically happen if the layout object got
// resized), we cannot skip invalidation.
if (hasNonCompositedScrollbars())
return false;

// We can't detect whether a plugin has box effects, so disable this optimization for that case.
if (isEmbeddedObject())
return false;

return !hasBoxEffect();
}

static inline bool objectIsRelayoutBoundary(const LayoutObject* object)
{
// FIXME: In future it may be possible to broaden these conditions in order to improve performance.
Expand Down Expand Up @@ -1330,7 +1308,6 @@ void LayoutObject::setPreviousSelectionRectForPaintInvalidation(const LayoutRect
selectionPaintInvalidationMap->set(this, selectionRect);
}

// TODO(wangxianzhu): Remove this for slimming paint v2 because we won't care about paint invalidation rects.
inline void LayoutObject::invalidateSelectionIfNeeded(const LayoutBoxModelObject& paintInvalidationContainer, const PaintInvalidationState& paintInvalidationState, PaintInvalidationReason invalidationReason)
{
// Update selection rect when we are doing full invalidation (in case that the object is moved, composite status changed, etc.)
Expand All @@ -1354,11 +1331,10 @@ inline void LayoutObject::invalidateSelectionIfNeeded(const LayoutBoxModelObject

setPreviousSelectionRectForPaintInvalidation(newSelectionRect);

// TODO(wangxianzhu): Combine the following two conditions when removing LayoutView::doingFullPaintInvalidation().
if (!fullInvalidation)
if (!fullInvalidation) {
fullyInvalidatePaint(paintInvalidationContainer, PaintInvalidationSelection, oldSelectionRect, newSelectionRect);
if (shouldInvalidateSelection())
invalidateDisplayItemClientsWithPaintInvalidationState(paintInvalidationState, PaintInvalidationSelection);
}
}

PaintInvalidationReason LayoutObject::invalidatePaintIfNeeded(const PaintInvalidationState& paintInvalidationState)
Expand Down Expand Up @@ -1423,7 +1399,7 @@ PaintInvalidationReason LayoutObject::invalidatePaintIfNeeded(const PaintInvalid
// invalidation is issued. See crbug.com/508383 and crbug.com/515977.
// This is a workaround to force display items to update paint offset.
if (!RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled() && paintInvalidationState.forcedSubtreeInvalidationCheckingWithinContainer())
invalidateDisplayItemClientsWithPaintInvalidationState(paintInvalidationState, invalidationReason);
invalidateDisplayItemClientsWithPaintInvalidationState(paintInvalidationState, PaintInvalidationLocationChange);

return invalidationReason;
}
Expand All @@ -1447,6 +1423,9 @@ PaintInvalidationReason LayoutObject::getPaintInvalidationReason(const PaintInva
if (shouldDoFullPaintInvalidation())
return m_bitfields.fullPaintInvalidationReason();

if (paintedOutputOfObjectHasNoEffect())
return PaintInvalidationNone;

// The outline may change shape because of position change of descendants. For simplicity,
// just force full paint invalidation if this object is marked for checking paint invalidation
// for any reason.
Expand All @@ -1465,13 +1444,6 @@ PaintInvalidationReason LayoutObject::getPaintInvalidationReason(const PaintInva
if (newBounds.location() != oldBounds.location())
return PaintInvalidationBoundsChange;

// This covers the case where we mark containing blocks for layout
// and they change size but don't have anything to paint. This is
// a pretty common case for <body> as we add / remove children
// (and the default background is done by FrameView).
if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled() && skipInvalidationWhenLaidOutChildren())
return PaintInvalidationNone;

// If the size is zero on one of our bounds then we know we're going to have
// to do a full invalidation of either old bounds or new bounds. If we fall
// into the incremental invalidation we'll issue two invalidations instead
Expand Down Expand Up @@ -3458,7 +3430,6 @@ void LayoutObject::clearPaintInvalidationFlags(const PaintInvalidationState& pai
ASSERT(!shouldCheckForPaintInvalidationRegardlessOfPaintInvalidationState() || paintInvalidationStateIsDirty());
clearShouldDoFullPaintInvalidation();
m_bitfields.setChildShouldCheckForPaintInvalidation(false);
m_bitfields.setNeededLayoutBecauseOfChildren(false);
m_bitfields.setMayNeedPaintInvalidation(false);
m_bitfields.setMayNeedPaintInvalidationSubtree(false);
m_bitfields.setShouldInvalidateSelection(false);
Expand Down
Loading

0 comments on commit bdd41f4

Please sign in to comment.