Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp |
| diff --git a/third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp b/third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp |
| index ca464ab93c3cb9394109bdd14c06d0e99660266c..e91a2a48f17ac7168265c8e1d5fcc2ee7c57a9d3 100644 |
| --- a/third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp |
| +++ b/third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp |
| @@ -8,41 +8,53 @@ |
| #include "core/layout/LayoutView.h" |
| #include "core/layout/svg/LayoutSVGModelObject.h" |
| #include "core/layout/svg/LayoutSVGRoot.h" |
| +#include "core/layout/svg/SVGLayoutSupport.h" |
| #include "core/paint/PaintLayer.h" |
| namespace blink { |
| -PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vector<LayoutObject*>& pendingDelayedPaintInvalidations, const PaintInvalidationState* ownerPaintInvalidationState) |
| +static LayoutSize computeViewPaintOffset(const LayoutView& layoutView, const LayoutBoxModelObject& paintInvalidationContainer) |
|
chrishtr
2016/03/24 00:53:52
computePaintOffsetFromViewToContainer.
Rename pai
Xianzhu
2016/03/25 16:35:54
Inlined this into the only call site after the oth
|
| +{ |
| + LayoutView::setViewClippingAndScrollOffsetDisabled(true); |
| + FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &paintInvalidationContainer, TraverseDocumentBoundaries); |
| + LayoutView::setViewClippingAndScrollOffsetDisabled(false); |
| + return LayoutSize(point.x(), point.y()); |
| +} |
| + |
| +static bool supportsCachedOffsets(const LayoutObject& object) |
| +{ |
| + // TODO(wangxianzhu): Move some conditions to fast path if possible. |
| + return !object.hasTransformRelatedProperty() |
| + && !object.hasReflection() |
| + && !object.hasFilter() |
| + && !object.isLayoutFlowThread(); |
| +} |
| + |
| +static bool supportsCachedOffsetsForChildren(const LayoutObject& object) |
|
chrishtr
2016/03/24 16:58:53
What's the purpose of distinguishing this from sup
Xianzhu
2016/03/25 16:35:54
The old code didn't separate paintOffset adjustmen
|
| +{ |
| + ASSERT(supportsCachedOffsets(object)); |
| + return !object.styleRef().isFlippedBlocksWritingMode(); |
| +} |
| + |
| +PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vector<LayoutObject*>& pendingDelayedPaintInvalidations) |
| : m_currentObject(layoutView) |
| , m_clipped(false) |
| , m_cachedOffsetsEnabled(true) |
| , m_forcedSubtreeInvalidationWithinContainer(false) |
| , m_forcedSubtreeInvalidationRectUpdateWithinContainer(false) |
| - , m_viewClippingAndScrollOffsetDisabled(false) |
| , m_paintInvalidationContainer(layoutView.containerForPaintInvalidation()) |
| , m_pendingDelayedPaintInvalidations(pendingDelayedPaintInvalidations) |
| , m_enclosingSelfPaintingLayer(*layoutView.layer()) |
| #if ENABLE(ASSERT) |
| - , m_didUpdatePaintOffsetAndClipForChildren(true) |
| + , m_didUpdateForChildren(false) |
| #endif |
| { |
| - ASSERT(!ownerPaintInvalidationState || ownerPaintInvalidationState->m_didUpdatePaintOffsetAndClipForChildren); |
| - |
| - bool establishesPaintInvalidationContainer = layoutView == m_paintInvalidationContainer; |
| - if (!establishesPaintInvalidationContainer) { |
| - if ((ownerPaintInvalidationState && !ownerPaintInvalidationState->m_cachedOffsetsEnabled) |
| - || !layoutView.supportsPaintInvalidationStateCachedOffsets()) { |
| - m_cachedOffsetsEnabled = false; |
| - return; |
| - } |
| - if (ownerPaintInvalidationState && ownerPaintInvalidationState->m_forcedSubtreeInvalidationWithinContainer) |
| - m_forcedSubtreeInvalidationWithinContainer = true; |
| - FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries); |
| - m_paintOffset = LayoutSize(point.x(), point.y()); |
| + if (!supportsCachedOffsets(layoutView)) { |
| + m_cachedOffsetsEnabled = false; |
| + return; |
| } |
| - m_clipRect = layoutView.viewRect(); |
| - m_clipRect.move(m_paintOffset); |
| - m_clipped = true; |
| + |
| + m_paintOffset = computeViewPaintOffset(layoutView, m_paintInvalidationContainer); |
| } |
| // TODO(wangxianzhu): This is temporary for positioned object whose paintInvalidationContainer is different from |
| @@ -53,7 +65,6 @@ PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par |
| , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) |
| , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInvalidationWithinContainer) |
| , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedSubtreeInvalidationRectUpdateWithinContainer) |
| - , m_viewClippingAndScrollOffsetDisabled(false) |
| , m_clipRect(parentState.m_clipRect) |
| , m_paintOffset(parentState.m_paintOffset) |
| , m_paintInvalidationContainer(paintInvalidationContainer) |
| @@ -61,10 +72,10 @@ PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par |
| , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalidationTargets()) |
| , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(currentObject)) |
| #if ENABLE(ASSERT) |
| - , m_didUpdatePaintOffsetAndClipForChildren(true) |
| + , m_didUpdateForChildren(true) |
| #endif |
| { |
| - ASSERT(parentState.m_didUpdatePaintOffsetAndClipForChildren); |
| + ASSERT(parentState.m_didUpdateForChildren); |
| ASSERT(!m_cachedOffsetsEnabled); |
| } |
| @@ -74,7 +85,6 @@ PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par |
| , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) |
| , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInvalidationWithinContainer) |
| , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedSubtreeInvalidationRectUpdateWithinContainer) |
| - , m_viewClippingAndScrollOffsetDisabled(false) |
| , m_clipRect(parentState.m_clipRect) |
| , m_paintOffset(parentState.m_paintOffset) |
| , m_paintInvalidationContainer(currentObject.isPaintInvalidationContainer() ? toLayoutBoxModelObject(currentObject) : parentState.m_paintInvalidationContainer) |
| @@ -82,35 +92,31 @@ PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par |
| , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalidationTargets()) |
| , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(currentObject)) |
| #if ENABLE(ASSERT) |
| - , m_didUpdatePaintOffsetAndClipForChildren(false) |
| + , m_didUpdateForChildren(false) |
| #endif |
| { |
| - ASSERT(parentState.m_didUpdatePaintOffsetAndClipForChildren); |
| -} |
| - |
| -void PaintInvalidationState::updatePaintOffsetAndClipForChildren() |
| -{ |
| + if (currentObject == parentState.m_currentObject) { |
| + // Sometimes we create a new PaintInvalidationState from parentState on the same object. |
|
chrishtr
2016/03/24 16:58:53
Are the cases the "horribly-slow" exceptions in La
Xianzhu
2016/03/25 16:35:54
Yes, and another case is LayoutView. FrameView/Lay
|
| + // TODO(wangxianzhu): Avoid this for RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled(). |
| #if ENABLE(ASSERT) |
| - ASSERT(!m_didUpdatePaintOffsetAndClipForChildren); |
| - m_didUpdatePaintOffsetAndClipForChildren = true; |
| + m_didUpdateForChildren = parentState.m_didUpdateForChildren; |
| #endif |
| + return; |
| + } |
| - bool establishesPaintInvalidationContainer = m_currentObject == m_paintInvalidationContainer; |
| + ASSERT(parentState.m_didUpdateForChildren); |
| - if (!m_currentObject.isBoxModelObject()) { |
| - // TODO(wangxianzhu): SVG could probably benefit from a stack-based optimization like html does. crbug.com/391054. |
| - ASSERT(m_currentObject.isSVG()); |
| - ASSERT(!establishesPaintInvalidationContainer); |
| - if (m_cachedOffsetsEnabled) |
| - m_svgTransform = AffineTransform(m_svgTransform * m_currentObject.localToSVGParentTransform()); |
| + if (!currentObject.isBoxModelObject() && !currentObject.isSVG()) |
| return; |
| - } |
| - bool fixed = m_currentObject.style()->position() == FixedPosition; |
| + if (m_cachedOffsetsEnabled) { |
|
chrishtr
2016/03/24 16:58:53
Can this just be (combining also logic from line 1
Xianzhu
2016/03/25 16:35:54
Rearranged the code to set m_svgTransform regardle
|
| + if (!supportsCachedOffsets(currentObject)) |
| + m_cachedOffsetsEnabled = false; |
| + else if (currentObject.isSVGRoot()) |
| + m_svgTransform = AffineTransform(toLayoutSVGRoot(currentObject).localToBorderBoxTransform()); |
| + } |
| - if (!m_currentObject.supportsPaintInvalidationStateCachedOffsets()) |
| - m_cachedOffsetsEnabled = false; |
| - if (establishesPaintInvalidationContainer) { |
| + if (currentObject == m_paintInvalidationContainer) { |
| // When we hit a new paint invalidation container, we don't need to |
| // continue forcing a check for paint invalidation, since we're |
| // descending into a different invalidation container. (For instance if |
| @@ -118,69 +124,165 @@ void PaintInvalidationState::updatePaintOffsetAndClipForChildren() |
| m_forcedSubtreeInvalidationWithinContainer = false; |
| m_forcedSubtreeInvalidationRectUpdateWithinContainer = false; |
| - m_clipped = false; // Will be updated in applyClipIfNeeded(). |
| + m_clipped = false; // Will be updated in updateForChildren(). |
| m_paintOffset = LayoutSize(); |
| - } else { |
| - if (m_cachedOffsetsEnabled) { |
| - if (fixed) { |
| - FloatPoint fixedOffset = m_currentObject.localToAncestorPoint(FloatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries); |
| - m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()); |
| - } else if (m_currentObject.isBox() && !m_currentObject.isTableRow()) { |
| - // We don't add locationOffset of table row because the child cells' location offsets include the row's location offset. |
| - m_paintOffset += toLayoutBox(m_currentObject).locationOffset(); |
| - } |
| - |
| - if (m_currentObject.isOutOfFlowPositioned() && !fixed) { |
| - if (LayoutObject* container = m_currentObject.container()) { |
| - if (container->isInFlowPositioned() && container->isLayoutInline()) |
| - m_paintOffset += toLayoutInline(container)->offsetForInFlowPositionedInline(toLayoutBox(m_currentObject)); |
| - } |
| - } |
| - |
| - if (m_currentObject.isInFlowPositioned() && m_currentObject.hasLayer()) |
| - m_paintOffset += toLayoutBoxModelObject(m_currentObject).layer()->offsetForInFlowPosition(); |
| + return; |
| + } |
| + |
| + if (!m_cachedOffsetsEnabled) |
| + return; |
| + |
| + if (currentObject.isSVG() && !currentObject.isSVGRoot()) { |
| + // TODO(wangxianzhu): SVG could probably benefit from a stack-based optimization like html does. crbug.com/391054. |
| + m_svgTransform = AffineTransform(m_svgTransform * currentObject.localToSVGParentTransform()); |
|
chrishtr
2016/03/24 01:05:42
How about a collection of unittests for all of the
chrishtr
2016/03/24 16:58:53
Another option: make this method a helper method,
Xianzhu
2016/03/25 16:35:54
Added ASSERTs in debug mode.
|
| + return; |
| + } |
| + |
| + if (currentObject.isLayoutView()) { |
| + m_paintOffset = computeViewPaintOffset(toLayoutView(currentObject), m_paintInvalidationContainer); |
|
chrishtr
2016/03/24 00:53:52
This is an O(tree depth) computation. Is there no
Xianzhu
2016/03/25 16:35:54
Done.
|
| + return; |
| + } |
| + |
| + if (currentObject.styleRef().position() == FixedPosition) { |
| + // TODO(wangxianzhu): Replace localToAncestorPoint with fast path. |
| + FloatPoint fixedOffset = currentObject.localToAncestorPoint(FloatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries); |
| + m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()); |
| + m_clipped = false; |
| + return; |
| + } |
| + |
| + if (currentObject.isBox()) { |
| + m_paintOffset += toLayoutBox(currentObject).locationOffset(); |
|
chrishtr
2016/03/24 16:58:53
This code looks different than the old code. The o
Xianzhu
2016/03/25 16:35:54
In this CL, paintOffset adjustment for the current
|
| + if (currentObject.isTableCell()) { |
| + // A table cell's locationOffset() includes its row's locationOffset(). |
| + m_paintOffset -= toLayoutBox(currentObject.parent())->locationOffset(); |
| } |
| + } |
| - m_clipped = !fixed && m_clipped; |
| + if (currentObject.styleRef().position() == AbsolutePosition) { |
| + if (LayoutObject* container = currentObject.container()) { |
| + if (container->isInFlowPositioned() && container->isLayoutInline()) |
| + m_paintOffset += toLayoutInline(container)->offsetForInFlowPositionedInline(toLayoutBox(currentObject)); |
| + } |
| + return; |
| } |
| - if (m_cachedOffsetsEnabled && m_currentObject.isSVGRoot()) { |
| + if (currentObject.isInFlowPositioned() && currentObject.hasLayer()) |
| + m_paintOffset += toLayoutBoxModelObject(currentObject).layer()->offsetForInFlowPosition(); |
| +} |
| + |
| +void PaintInvalidationState::updateForChildren() |
| +{ |
| +#if ENABLE(ASSERT) |
| + ASSERT(!m_didUpdateForChildren); |
| + m_didUpdateForChildren = true; |
| +#endif |
| + |
| + if (!m_cachedOffsetsEnabled) |
| + return; |
| + |
| + if (!supportsCachedOffsetsForChildren(m_currentObject)) { |
| + m_cachedOffsetsEnabled = false; |
| + return; |
| + } |
| + |
| + if (!m_currentObject.isBoxModelObject() && !m_currentObject.isSVG()) |
| + return; |
|
chrishtr
2016/03/24 16:58:53
The old code asserted that isSVG is true...why the
Xianzhu
2016/03/25 16:35:54
Previously we didn't create new PaintInvalidationS
|
| + |
| + if (m_currentObject.isLayoutView()) { |
| + if (m_currentObject != m_paintInvalidationContainer) { |
| + // TODO(wangxianzhu): Replace localToAncestorPoint with fast path. |
|
chrishtr
2016/03/24 00:53:52
Looks like this is referring to the fast path I su
Xianzhu
2016/03/25 16:35:54
Done.
|
| + FloatPoint viewOffset = m_currentObject.localToAncestorPoint(FloatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries); |
| + m_paintOffset = LayoutSize(viewOffset.x(), viewOffset.y()); |
| + m_clipRect = toLayoutView(m_currentObject).viewRect(); |
| + m_clipRect.move(m_paintOffset); |
| + m_clipped = true; |
| + return; |
| + } |
| + } else if (m_currentObject.isSVGRoot()) { |
| const LayoutSVGRoot& svgRoot = toLayoutSVGRoot(m_currentObject); |
| - m_svgTransform = AffineTransform(svgRoot.localToBorderBoxTransform()); |
| if (svgRoot.shouldApplyViewportClip()) |
| addClipRectRelativeToPaintOffset(LayoutSize(svgRoot.pixelSnappedSize())); |
| } |
| - applyClipIfNeeded(); |
| + if (!m_currentObject.hasOverflowClip()) |
| + return; |
| + |
| + const LayoutBox& box = toLayoutBox(m_currentObject); |
| + |
| + // Do not clip scroll layer contents because the compositor expects the whole layer |
| + // to be always invalidated in-time. |
| + if (box.usesCompositedScrolling()) |
| + ASSERT(!m_clipped); // The box should establish paint invalidation container, so no m_clipped inherited. |
| + else |
| + addClipRectRelativeToPaintOffset(LayoutSize(box.layer()->size())); |
| + |
| + m_paintOffset -= box.scrolledContentOffset(); |
| // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present. |
| } |
| -void PaintInvalidationState::mapObjectRectToAncestor(const LayoutObject& object, const LayoutBoxModelObject* ancestor, LayoutRect& rect) const |
| +LayoutPoint PaintInvalidationState::computePositionFromPaintInvalidationBacking() const |
| { |
| - ASSERT(canMapToAncestor(ancestor)); |
| - |
| - if (ancestor == &object) { |
| - if (object.isBox() && object.styleRef().isFlippedBlocksWritingMode()) |
| - toLayoutBox(object).flipForWritingMode(rect); |
| - return; |
| + FloatPoint point; |
| + if (m_paintInvalidationContainer != m_currentObject) { |
| + if (m_cachedOffsetsEnabled) { |
| + if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) |
| + point = m_svgTransform.mapPoint(point); |
| + point += FloatPoint(m_paintOffset); |
| + } else { |
| + // Fallback to slow path. |
| + point = m_currentObject.localToAncestorPoint(FloatPoint(), &m_paintInvalidationContainer); |
| + } |
| } |
| - if (object.hasLayer()) { |
| - if (const TransformationMatrix* transform = toLayoutBoxModelObject(object).layer()->transform()) |
| - rect = LayoutRect(transform->mapRect(pixelSnappedIntRect(rect))); |
| + if (m_paintInvalidationContainer.layer()->groupedMapping()) |
| + PaintLayer::mapPointInPaintInvalidationContainerToBacking(m_paintInvalidationContainer, point); |
| + |
| + return LayoutPoint(point); |
| +} |
| - if (object.isInFlowPositioned()) |
| - rect.move(toLayoutBoxModelObject(object).layer()->offsetForInFlowPosition()); |
| +LayoutRect PaintInvalidationState::computePaintInvalidationRectInBacking() const |
| +{ |
| + if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot()) |
| + return computePaintInvalidationRectInBackingForSVG(); |
| + |
| + LayoutRect rect = m_currentObject.localOverflowRectForPaintInvalidation(); |
| + mapLocalRectToPaintInvalidationBacking(rect); |
| + return rect; |
| +} |
| + |
| +LayoutRect PaintInvalidationState::computePaintInvalidationRectInBackingForSVG() const |
| +{ |
| + LayoutRect rect; |
| + if (m_cachedOffsetsEnabled) { |
| + FloatRect svgRect = SVGLayoutSupport::localOverflowRectForPaintInvalidation(m_currentObject); |
| + rect = SVGLayoutSupport::transformPaintInvalidationRect(m_currentObject, m_svgTransform, svgRect); |
| + rect.move(m_paintOffset); |
| + if (m_clipped) |
| + rect.intersect(m_clipRect); |
| + } else { |
| + rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation(m_currentObject, m_paintInvalidationContainer); |
| } |
| - if (object.isBox()) |
| - rect.moveBy(toLayoutBox(object).location()); |
| + if (m_paintInvalidationContainer.layer()->groupedMapping()) |
| + PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalidationContainer, rect); |
| + return rect; |
| +} |
| - rect.move(m_paintOffset); |
| +void PaintInvalidationState::mapLocalRectToPaintInvalidationBacking(LayoutRect& rect) const |
| +{ |
| + if (m_cachedOffsetsEnabled) { |
| + rect.move(m_paintOffset); |
| + if (m_clipped) |
| + rect.intersect(m_clipRect); |
| + } else { |
| + // Fallback to slow path. |
| + m_currentObject.mapToVisibleRectInAncestorSpace(&m_paintInvalidationContainer, rect); |
| + } |
| - if (m_clipped) |
| - rect.intersect(m_clipRect); |
| + if (m_paintInvalidationContainer.layer()->groupedMapping()) |
| + PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalidationContainer, rect); |
| } |
| void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutSize& clipSize) |
| @@ -194,23 +296,6 @@ void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutSize& |
| } |
| } |
| -void PaintInvalidationState::applyClipIfNeeded() |
| -{ |
| - if (!m_currentObject.hasOverflowClip()) |
| - return; |
| - |
| - const LayoutBox& box = toLayoutBox(m_currentObject); |
| - |
| - // Do not clip scroll layer contents because the compositor expects the whole layer |
| - // to be always invalidated in-time. |
| - if (box.usesCompositedScrolling()) |
| - ASSERT(!m_clipped); // The box should establish paint invalidation container, so no m_clipped inherited. |
| - else |
| - addClipRectRelativeToPaintOffset(LayoutSize(box.layer()->size())); |
| - |
| - m_paintOffset -= box.scrolledContentOffset(); |
| -} |
| - |
| PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObject& layoutObject) const |
| { |
| if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfPaintingLayer()) |